Update skills UI components for managed skills (#165)

* ralph: ralph-repo-level-skills-dialog-skillseditor-fix completed after 4 iterations

* Remove parent session notification and child session tracking from Ralph loops

Sending promptAsync to parent sessions on loop completion could resume
work in previously inactive sessions. Removed parentSessionId from
RalphState, child session tracking maps, and all related event handling.
Watchdog stall detection still works via the session status API.

* Migrate global skills to workspace path

* Add skill injection to scheduled job prompts

* Refactor schedules UI with MultiSelect and tab menu

* Update skills UI components for managed skills
This commit is contained in:
Chris Scott authored and GitHub committed 2026-03-22 14:52:32 -04:00
1 parent 4bd0940ab9
commit c3cba72b51
22 files changed
+981 -337

No files matched your search

+64 -1
View File
@@ -107,6 +107,69 @@ function buildSessionTitle(job: ScheduleJob): string {
return `Scheduled: ${job.name}`
}
type SkillInfo = {
name: string
description: string
location: string
content: string
}
async function fetchSkillContent(slugs: string[], repoPath: string): Promise<string[]> {
try {
const response = await proxyToOpenCodeWithDirectory('/skill', 'GET', repoPath)
if (!response.ok) {
logger.warn(`Failed to fetch skills from OpenCode (${response.status}), falling back to name-only injection`)
return []
}
const skills = await response.json() as SkillInfo[]
const skillBlocks = slugs
.map((slug) => {
const skill = skills.find((s) => s.name === slug || s.name.endsWith(`/${slug}`) || s.name.endsWith(`-${slug}`))
if (!skill) {
logger.warn(`Skill "${slug}" not found in OpenCode skill list`)
return null
}
return [
`<skill_content name="${skill.name}">`,
`# Skill: ${skill.name}`,
'',
skill.content.trim(),
'</skill_content>',
].join('\n')
})
.filter((block): block is string => block !== null)
const foundCount = skillBlocks.length
if (foundCount < slugs.length) {
logger.warn(`Only ${foundCount} of ${slugs.length} requested skills were found`)
}
return skillBlocks
} catch (error) {
logger.warn('Error fetching skills from OpenCode, falling back to name-only injection:', error)
return []
}
}
async function buildPromptWithSkills(
prompt: string,
skillMetadata: ScheduleJob['skillMetadata'],
repoPath: string
): Promise<string> {
if (!skillMetadata || !skillMetadata.skillSlugs || skillMetadata.skillSlugs.length === 0) return prompt
const skillBlocks = await fetchSkillContent(skillMetadata.skillSlugs, repoPath)
const notesLine = skillMetadata.notes ? `\nSkill notes: ${skillMetadata.notes}` : ''
if (skillBlocks.length === 0) {
const skillList = skillMetadata.skillSlugs.join(', ')
return `${prompt}\n\nFor this task, use the following skills: ${skillList}${notesLine}`
}
return `${prompt}\n\nThe following skills have been loaded for this task:\n\n${skillBlocks.join('\n\n')}${notesLine}`
}
function buildRunLog(input: {
job: ScheduleJob
triggerSource: ScheduleRunTriggerSource
@@ -578,7 +641,7 @@ export class ScheduleService {
'POST',
repo.fullPath,
JSON.stringify({
parts: [{ type: 'text', text: input.job.prompt }],
parts: [{ type: 'text', text: await buildPromptWithSkills(input.job.prompt, input.job.skillMetadata, repo.fullPath) }],
model: input.model,
}),
)
+85 -4
View File
@@ -3,11 +3,70 @@ import path from 'path'
import type { Database } from 'bun:sqlite'
import type { SkillFileInfo, SkillScope, CreateSkillRequest, UpdateSkillRequest } from '@opencode-manager/shared'
import { SKILL_NAME_REGEX } from '@opencode-manager/shared'
import { getRepoById } from '../db/queries'
import { getWorkspacePath } from '@opencode-manager/shared/config/env'
import { getRepoById, listRepos } from '../db/queries'
import { ensureDirectoryExists, fileExists, readFileContent, writeFileContent, deletePath, listDirectory } from './file-operations'
import { logger } from '../utils/logger'
const GLOBAL_SKILLS_PATH = path.join(os.homedir(), '.config', 'opencode', 'skills')
function getGlobalSkillsPath(): string {
return path.join(getWorkspacePath(), '.config', 'opencode', 'skills')
}
function getOldGlobalSkillsPath(): string {
return path.join(os.homedir(), '.config', 'opencode', 'skills')
}
export async function migrateGlobalSkills(): Promise<void> {
const oldSkillsPath = getOldGlobalSkillsPath()
const newSkillsPath = getGlobalSkillsPath()
const oldSkillsExist = await fileExists(oldSkillsPath)
if (!oldSkillsExist) {
logger.debug('No old global skills found to migrate')
return
}
const entries = await listDirectory(oldSkillsPath)
const skillDirs = entries.filter(entry => entry.isDirectory)
if (skillDirs.length === 0) {
logger.debug('No skill directories found in old location')
return
}
let migratedCount = 0
let skippedCount = 0
for (const entry of skillDirs) {
const oldSkillPath = path.join(entry.path, 'SKILL.md')
const newSkillPath = path.join(newSkillsPath, entry.name, 'SKILL.md')
const alreadyMigrated = await fileExists(newSkillPath)
if (alreadyMigrated) {
skippedCount++
continue
}
const skillExists = await fileExists(oldSkillPath)
if (!skillExists) {
logger.warn(`Skill ${entry.name} has no SKILL.md file, skipping`)
continue
}
try {
const content = await readFileContent(oldSkillPath)
await writeFileContent(newSkillPath, content)
logger.info(`Migrated skill ${entry.name} from ${oldSkillsPath} to ${newSkillsPath}`)
migratedCount++
} catch (error) {
logger.error(`Failed to migrate skill ${entry.name}:`, error)
}
}
if (migratedCount > 0 || skippedCount > 0) {
logger.info(`Skill migration complete: ${migratedCount} migrated, ${skippedCount} skipped (already existed)`)
}
}
interface ParsedSkillFile {
frontmatter: {
@@ -115,7 +174,7 @@ function generateSkillFrontmatter(
function getSkillDirectoryPath(db: Database, scope: SkillScope, repoId?: number): string {
if (scope === 'global') {
return GLOBAL_SKILLS_PATH
return getGlobalSkillsPath()
}
if (!repoId) {
@@ -145,7 +204,7 @@ function getSkillFilePath(db: Database, scope: SkillScope, name: string, repoId?
export async function listManagedSkills(db: Database, repoId?: number): Promise<SkillFileInfo[]> {
const skills: SkillFileInfo[] = []
const globalSkillsDir = GLOBAL_SKILLS_PATH
const globalSkillsDir = getGlobalSkillsPath()
const globalSkillsExist = await fileExists(globalSkillsDir)
if (globalSkillsExist) {
@@ -186,6 +245,28 @@ export async function listManagedSkills(db: Database, repoId?: number): Promise<
}
}
}
} else {
const allRepos = listRepos(db)
for (const repo of allRepos) {
const projectSkillsDir = path.join(repo.fullPath, '.opencode', 'skills')
const projectSkillsExist = await fileExists(projectSkillsDir)
if (projectSkillsExist) {
const entries = await listDirectory(projectSkillsDir)
for (const entry of entries) {
if (entry.isDirectory) {
const skillPath = path.join(entry.path, 'SKILL.md')
const skillExists = await fileExists(skillPath)
if (skillExists) {
const skillInfo = await readSkillFile(db, 'project', entry.name, repo.id)
if (skillInfo) {
skills.push(skillInfo)
}
}
}
}
}
}
}
return skills