Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(verify): add `lh verify init` to pull the verify skill to disk (#16164)

Arvin Xufa2d9660db37
diff --git a/apps/cli/src/commands/verify.test.ts b/apps/cli/src/commands/verify.test.ts
index d7667012ffb..84e2d0439ca 100644
--- a/apps/cli/src/commands/verify.test.ts
+++ b/apps/cli/src/commands/verify.test.ts
@@ -1,3 +1,7 @@
+import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import path from 'node:path';
+
import { Command } from 'commander';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
@@ -8,6 +12,7 @@ const { mockTrpcClient } = vi.hoisted(() => ({
verify: {
createRubric: { mutate: vi.fn() },
getRubric: { query: vi.fn() },
+ getSkillBundle: { query: vi.fn() },
updateRubric: { mutate: vi.fn() },
},
},
@@ -130,3 +135,71 @@ describe('verify evidence upload command', () => {
expect(mockGetTrpcClient).not.toHaveBeenCalled();
});
});
+
+describe('verify init command', () => {
+ let consoleSpy: ReturnType<typeof vi.spyOn>;
+ let dir: string;
+
+ beforeEach(() => {
+ consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
+ mockGetTrpcClient.mockResolvedValue(mockTrpcClient);
+ mockTrpcClient.verify.getSkillBundle.query.mockReset().mockResolvedValue({
+ content: '# Verify SKILL',
+ files: { 'references/plan-format.md': 'plan', 'surfaces/cli.md': 'cli' },
+ identifier: 'verify',
+ name: 'Verify',
+ });
+ dir = mkdtempSync(path.join(tmpdir(), 'verify-init-'));
+ });
+
+ afterEach(() => {
+ consoleSpy.mockRestore();
+ rmSync(dir, { force: true, recursive: true });
+ });
+
+ const run = async (args: string[]) => {
+ const program = new Command();
+ program.exitOverride();
+ registerVerifyCommand(program);
+ await program.parseAsync(['node', 'lh', 'verify', ...args]);
+ };
+
+ it('writes SKILL.md and resource files into .claude/skills/verify', async () => {
+ await run(['init', '--dir', dir]);
+
+ expect(mockTrpcClient.verify.getSkillBundle.query).toHaveBeenCalledWith({
+ identifier: 'verify',
+ });
+ const skillDir = path.join(dir, '.claude', 'skills', 'verify');
+ expect(readFileSync(path.join(skillDir, 'SKILL.md'), 'utf8')).toBe('# Verify SKILL');
+ expect(readFileSync(path.join(skillDir, 'references/plan-format.md'), 'utf8')).toBe('plan');
+ expect(readFileSync(path.join(skillDir, 'surfaces/cli.md'), 'utf8')).toBe('cli');
+ });
+
+ it('skips existing files without --force and overwrites with it', async () => {
+ const skillFile = path.join(dir, '.claude', 'skills', 'verify', 'SKILL.md');
+ await run(['init', '--dir', dir]);
+
+ // server now serves updated content
+ mockTrpcClient.verify.getSkillBundle.query.mockResolvedValue({
+ content: '# Updated SKILL',
+ files: {},
+ identifier: 'verify',
+ name: 'Verify',
+ });
+
+ await run(['init', '--dir', dir]); // no --force β†’ keep existing
+ expect(readFileSync(skillFile, 'utf8')).toBe('# Verify SKILL');
+
+ await run(['init', '--dir', dir, '--force']); // --force β†’ overwrite
+ expect(readFileSync(skillFile, 'utf8')).toBe('# Updated SKILL');
+ });
+
+ it('reports the written/skipped counts as JSON', async () => {
+ await run(['init', '--dir', dir, '--json']);
+ const out = JSON.parse(consoleSpy.mock.calls.map((c) => String(c[0])).join(''));
+ expect(out.skill).toBe('verify');
+ expect(out.written).toContain('SKILL.md');
+ expect(existsSync(path.join(out.dir, 'SKILL.md'))).toBe(true);
+ });
+});
diff --git a/apps/cli/src/commands/verify.ts b/apps/cli/src/commands/verify.ts
index 64eb2a0e698..7651fa3477f 100644
--- a/apps/cli/src/commands/verify.ts
+++ b/apps/cli/src/commands/verify.ts
@@ -1,4 +1,4 @@
-import { existsSync, readFileSync } from 'node:fs';
+import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import type { Command } from 'commander';
@@ -73,6 +73,63 @@ export function registerVerifyCommand(program: Command) {
.command('verify')
.description('Manage the Agent Run delivery checker (criteria, rubrics, plans, results)');
+ // ════════════ init (materialize the portable verify skill) ════════════
+ verify
+ .command('init')
+ .description('Write the portable verify skill into a working dir (.claude/skills/verify)')
+ .option('--dir <path>', 'Target working directory (default: current dir)')
+ .option('--skill <id>', 'Skill identifier to pull', 'verify')
+ .option('--force', 'Overwrite existing skill files')
+ .option('--json [fields]', 'Output JSON')
+ .action(
+ async (options: {
+ dir?: string;
+ force?: boolean;
+ json?: boolean | string;
+ skill: string;
+ }) => {
+ const client = await getTrpcClient();
+ // Pulled live from the server's deployed builtin-skills β€” always the latest.
+ const bundle = await client.verify.getSkillBundle.query({ identifier: options.skill });
+
+ const baseDir = options.dir ? path.resolve(options.dir) : process.cwd();
+ const skillDir = path.join(baseDir, '.claude', 'skills', bundle.identifier);
+
+ // path β†’ content for SKILL.md plus every resource file.
+ const entries: [string, string][] = [
+ ['SKILL.md', bundle.content],
+ ...Object.entries(bundle.files),
+ ];
+
+ const written: string[] = [];
+ const skipped: string[] = [];
+ for (const [rel, content] of entries) {
+ const dest = path.join(skillDir, rel);
+ if (existsSync(dest) && !options.force) {
+ skipped.push(rel);
+ continue;
+ }
+ mkdirSync(path.dirname(dest), { recursive: true });
+ writeFileSync(dest, content, 'utf8');
+ written.push(rel);
+ }
+
+ const result = { dir: skillDir, skill: bundle.identifier, skipped, written };
+ if (options.json !== undefined) {
+ outputJson(result, typeof options.json === 'string' ? options.json : undefined);
+ return;
+ }
+ console.log(
+ `${pc.green('βœ“')} ${pc.bold(bundle.name)} skill β†’ ${pc.dim(path.relative(process.cwd(), skillDir) || skillDir)}`,
+ );
+ console.log(
+ ` ${written.length} written${skipped.length ? `, ${skipped.length} skipped` : ''}`,
+ );
+ if (skipped.length > 0)
+ console.log(pc.dim(` (skipped existing β€” pass --force to overwrite)`));
+ },
+ );
+
// ════════════ criteria ════════════
const criterion = verify.command('criterion').description('Reusable pass/fail standards');
diff --git a/apps/server/src/routers/lambda/verify.ts b/apps/server/src/routers/lambda/verify.ts
index 717fe5a4874..025fc2344cd 100644
--- a/apps/server/src/routers/lambda/verify.ts
+++ b/apps/server/src/routers/lambda/verify.ts
@@ -1,3 +1,4 @@
+import { VerifySkill } from '@lobechat/builtin-skills';
import { TRPCError } from '@trpc/server';
import { asc, eq } from 'drizzle-orm';
import { z } from 'zod';
@@ -28,6 +29,17 @@ import {
VerifyReporterService,
} from '@/server/services/verify';
+/**
+ * Skills that `verify.getSkillBundle` will materialize to a builder's disk via
+ * `lh verify init`. Keyed by identifier; add future pullable skills here. The
+ * portable verify skill lives in @lobechat/builtin-skills but is intentionally
+ * NOT in its `builtinSkills` runtime array (kept out of the homogeneous agent
+ * runtime / tool picker), so it is referenced directly here.
+ */
+const PULLABLE_SKILLS: Record<string, typeof VerifySkill> = {
+ [VerifySkill.identifier]: VerifySkill,
+};
+
const verifierTypeSchema = z.enum(['program', 'agent', 'llm']);
const onFailSchema = z.enum(['manual', 'auto_repair']);
const decisionSchema = z.enum(['accepted', 'rejected', 'overridden']);
@@ -306,6 +318,31 @@ export const verifyRouter = router({
};
}),
+ /**
+ * Serve a pullable skill bundle (`SKILL.md` + inline resource files) by
+ * identifier so `lh verify init` can materialize it into a builder's working
+ * directory. Dynamic-by-design: the source is the server's deployed
+ * `@lobechat/builtin-skills`, so updating the skill + redeploying reaches every
+ * builder on the next pull β€” no CLI re-release. Auth-gated (verifyProcedure);
+ * returns NOT_FOUND for any identifier not in the pullable registry.
+ */
+ getSkillBundle: verifyProcedure.input(z.object({ identifier: z.string() })).query(({ input }) => {
+ const skill = PULLABLE_SKILLS[input.identifier];
+ if (!skill)
+ throw new TRPCError({
+ code: 'NOT_FOUND',
+ message: `No pullable skill with identifier "${input.identifier}"`,
+ });
+ return {
+ content: skill.content,
+ files: Object.fromEntries(
+ Object.entries(skill.resources ?? {}).map(([path, meta]) => [path, meta.content ?? '']),
+ ),
+ identifier: skill.identifier,
+ name: skill.name,
+ };
+ }),
+
getVerifyState: verifyProcedure
.input(z.object({ operationId: z.string() }))
.query(async ({ ctx, input }) => ctx.runModel.getStateByOperation(input.operationId)),