🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(cli): add `lh goal delete` command (#20135)
Arvin Xud5442306ec02
diff --git a/apps/cli/src/commands/goal.test.ts b/apps/cli/src/commands/goal.test.tsindex 216d8919e7c..4d0f1296c0c 100644--- a/apps/cli/src/commands/goal.test.ts+++ b/apps/cli/src/commands/goal.test.ts@@ -1,6 +1,8 @@import { Command } from 'commander';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import type * as FormatModule from '../utils/format';+import { confirm } from '../utils/format';import { log } from '../utils/logger';import { registerGoalCommand } from './goal';@@ -8,6 +10,7 @@ const { mockClient } = vi.hoisted(() => ({mockClient: {goal: {create: { mutate: vi.fn() },+ delete: { mutate: vi.fn() },submitPlan: { mutate: vi.fn() },submitOperationPlan: { mutate: vi.fn() },graph: { query: vi.fn() },@@ -22,6 +25,11 @@ vi.mock('node:fs/promises', () => ({readFile: async () => JSON.stringify({ action: 'verify', reason: 'Ready' }),}));+vi.mock('../utils/format', async (importOriginal) => ({+ ...(await importOriginal<typeof FormatModule>()),+ confirm: vi.fn(),+}));+vi.mock('../api/client', () => ({ getTrpcClient: vi.fn().mockResolvedValue(mockClient) }));// Building the app URL otherwise resolves a workspace and a server, which needs// a real login; the link's shape is what this file is asserting, not its host.@@ -527,3 +535,33 @@ describe('goal set-budget command', () => {);});});++describe('goal delete', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ vi.spyOn(console, 'log').mockImplementation(() => {});+ vi.spyOn(log, 'info').mockImplementation(() => {});+ });++ afterEach(() => {+ vi.restoreAllMocks();+ });++ it('deletes the goal without prompting when --yes is passed', async () => {+ mockClient.goal.delete.mutate.mockResolvedValue({ message: 'Goal deleted', success: true });++ await createProgram().parseAsync(['node', 'test', 'goal', 'delete', 'goal-1', '--yes']);++ expect(mockClient.goal.delete.mutate).toHaveBeenCalledWith({ id: 'goal-1' });+ expect(log.info).toHaveBeenCalledWith('Goal deleted');+ });++ it('keeps the goal when the confirmation is declined', async () => {+ vi.mocked(confirm).mockResolvedValue(false);++ await createProgram().parseAsync(['node', 'test', 'goal', 'delete', 'goal-1']);++ expect(confirm).toHaveBeenCalledOnce();+ expect(mockClient.goal.delete.mutate).not.toHaveBeenCalled();+ });+});diff --git a/apps/cli/src/commands/goal.ts b/apps/cli/src/commands/goal.tsindex 52019b00fcd..4cb2ffd4854 100644--- a/apps/cli/src/commands/goal.ts+++ b/apps/cli/src/commands/goal.ts@@ -11,7 +11,7 @@ import type { Command } from 'commander';import pc from 'picocolors';import { getTrpcClient } from '../api/client';-import { outputJson, printTable, truncate } from '../utils/format';+import { confirm, outputJson, printTable, truncate } from '../utils/format';import { log } from '../utils/logger';import { resolveAppUrlBuilder } from './task/url';@@ -527,6 +527,20 @@ export function registerGoalCommand(program: Command) {});}+ goal+ .command('delete <id>')+ .description('Delete a goal and its graph')+ .option('--yes', 'Skip confirmation prompt')+ .action(async (id: string, options: { yes?: boolean }) => {+ if (!options.yes && !(await confirm(`Delete goal ${id}? This cannot be undone.`))) {+ console.log('Cancelled.');+ return;+ }+ const client = await getTrpcClient();+ const result = await client.goal.delete.mutate({ id });+ log.info(result.message);+ });+goal.command('set-budget <id>').description('Update limits; pass "none" to remove a limit')