feat(skills): bundle and harden personal maintenance workflows

This commit is contained in:
Turtle
2026-07-27 17:53:31 +08:00
parent 8452ff222b
commit 5d2329e207
16 changed files with 274 additions and 32 deletions
+18 -7
View File
@@ -32,6 +32,7 @@ const PROJECT_AGENTS_RANK = 200
const CUSTOM_RANK = 300
const USER_DSH_RANK = 400
const USER_AGENTS_RANK = 500
const BUNDLED_RANK = 600
export const name = 'skill-local'
export const inject = ['skills']
@@ -44,12 +45,15 @@ export interface Config {
agentsHome?: string
/** Additional skill roots scanned after project roots and before user roots. */
customSkillDirs?: string[]
/** Bundled skill root; defaults to `$DSH_BUNDLED_SKILL_DIR`, otherwise mounts none. */
bundledSkillDir?: string
}
export const Config: Schema<Config> = z.object({
dshHome: z.string(),
agentsHome: z.string(),
customSkillDirs: z.array(z.string()).default([]),
bundledSkillDir: z.string(),
})
interface SkillRoot {
@@ -57,6 +61,7 @@ interface SkillRoot {
source: SkillSource
rank: number
skipSystem?: boolean
trustedHost?: boolean
}
interface SkillRootEntry {
@@ -91,11 +96,14 @@ export class LocalSkillProvider implements SkillProvider {
private readonly dshHome: string
private readonly agentsHome: string
private readonly customSkillDirs: string[]
private readonly bundledSkillDir: string | undefined
constructor(private readonly ctx: Context, config: Config = {}) {
this.dshHome = resolveDshHome(config.dshHome)
this.agentsHome = resolve(config.agentsHome ?? process.env.DSH_AGENTS_HOME ?? join(homedir(), '.agents'))
this.customSkillDirs = (config.customSkillDirs ?? []).map(root => resolve(root))
const bundledSkillDir = config.bundledSkillDir ?? process.env.DSH_BUNDLED_SKILL_DIR
this.bundledSkillDir = bundledSkillDir === undefined ? undefined : resolve(bundledSkillDir)
}
/**
@@ -122,7 +130,7 @@ export class LocalSkillProvider implements SkillProvider {
*/
async get(candidate: SkillCandidate, options: SkillLookupOptions): Promise<SkillDefinition | undefined> {
const locator = candidate.locator as LocalLocator
const parsed = await parseSkillFile(locator.path, this.ctx, options.signal)
const parsed = await parseSkillFile(locator.path, this.ctx, options.signal, candidate.source === 'bundled')
if (parsed === undefined) return undefined
return {
name: parsed.name,
@@ -151,6 +159,9 @@ export class LocalSkillProvider implements SkillProvider {
...this.customSkillDirs.map(path => ({ path, source: 'custom' as const, rank: CUSTOM_RANK })),
{ path: join(this.dshHome, 'skills'), source: 'user-dsh', rank: USER_DSH_RANK, skipSystem: true },
{ path: join(this.agentsHome, 'skills'), source: 'user-agents', rank: USER_AGENTS_RANK },
...this.bundledSkillDir === undefined
? []
: [{ path: this.bundledSkillDir, source: 'bundled' as const, rank: BUNDLED_RANK, trustedHost: true }],
)
return roots
}
@@ -167,7 +178,7 @@ async function discoverRoot(root: SkillRoot, ctx: Context): Promise<SkillCandida
? { path: entry.path, directory: root.path }
: undefined
if (locator === undefined) continue
const parsed = await parseSkillFile(locator.path, ctx)
const parsed = await parseSkillFile(locator.path, ctx, undefined, root.trustedHost === true)
if (parsed === undefined) continue
skills.push({
name: parsed.name,
@@ -188,7 +199,7 @@ async function discoverRoot(root: SkillRoot, ctx: Context): Promise<SkillCandida
async function listSkillRootEntries(root: SkillRoot, ctx: Context): Promise<SkillRootEntry[]> {
const fs = optionalFileSystem(ctx)
if (fs !== undefined) return await listSkillRootEntriesFromFileSystem(root, fs)
if (fs !== undefined && root.trustedHost !== true) return await listSkillRootEntriesFromFileSystem(root, fs)
return await listSkillRootEntriesFromNode(root, ctx)
}
@@ -225,8 +236,8 @@ async function listSkillRootEntriesFromNode(root: SkillRoot, ctx: Context): Prom
return result
}
async function parseSkillFile(path: string, ctx: Context, signal?: AbortSignal): Promise<ParsedSkill | undefined> {
const raw = await readSkillText(ctx, path, signal)
async function parseSkillFile(path: string, ctx: Context, signal?: AbortSignal, trustedHost = false): Promise<ParsedSkill | undefined> {
const raw = await readSkillText(ctx, path, signal, trustedHost)
signal?.throwIfAborted()
if (raw === undefined) {
return undefined
@@ -266,10 +277,10 @@ function optionalFileSystem(ctx: Context): FileSystem | undefined {
return ctx.get('fs')
}
async function readSkillText(ctx: Context, path: string, signal?: AbortSignal): Promise<string | undefined> {
async function readSkillText(ctx: Context, path: string, signal?: AbortSignal, trustedHost = false): Promise<string | undefined> {
signal?.throwIfAborted()
const fs = optionalFileSystem(ctx)
if (fs !== undefined) {
if (fs !== undefined && !trustedHost) {
return await readSkillTextFromFileSystem(ctx, fs, path, signal)
}
try {