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(goal): edit a goal's requirement from the CLI, and surface lh goal to agents (#20568)

Arvin Xu1f277abfc09a
diff --git a/apps/cli/src/commands/goal/configuration.test.ts b/apps/cli/src/commands/goal/configuration.test.ts
new file mode 100644
index 00000000000..0c9add6af76
--- /dev/null
+++ b/apps/cli/src/commands/goal/configuration.test.ts
@@ -0,0 +1,116 @@
+import { Command } from 'commander';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { registerGoalConfigurationCommands } from './configuration';
+
+const mocks = vi.hoisted(() => ({
+ getTrpcClient: vi.fn(),
+ setBudget: vi.fn(),
+ updateRequirement: vi.fn(),
+}));
+
+vi.mock('../../api/client', () => ({ getTrpcClient: mocks.getTrpcClient }));
+vi.mock('../../utils/logger', () => ({
+ log: { debug: vi.fn(), error: vi.fn(), info: vi.fn(), warn: vi.fn() },
+}));
+vi.mock('node:fs/promises', () => ({
+ readFile: async (path: string) =>
+ // `set-requirement --file` reads plain markdown, unlike the JSON payloads
+ // the rest of the goal commands hand to readFile.
+ path === 'requirement.md'
+ ? '# What counts as done\n- Ship the migration with real evidence'
+ : JSON.stringify({ action: 'verify', reason: 'Ready' }),
+}));
+
+const run = async (...args: string[]) => {
+ const program = new Command();
+ program.exitOverride();
+ registerGoalConfigurationCommands(program.command('goal'));
+ await program.parseAsync(['node', 'test', 'goal', ...args]);
+};
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ mocks.getTrpcClient.mockResolvedValue({
+ goal: {
+ setBudget: { mutate: mocks.setBudget },
+ updateRequirement: { mutate: mocks.updateRequirement },
+ },
+ });
+});
+
+afterEach(() => {
+ vi.restoreAllMocks();
+});
+
+describe('goal set-budget command', () => {
+ it('edits the limits a goal was created with, so it can continue instead of being copied', async () => {
+ mocks.setBudget.mockResolvedValue({ message: 'Goal budget updated' });
+
+ await run(
+ 'set-budget',
+ 'goal-1',
+ '--max-manager-turns',
+ '60',
+ '--max-concurrent-tasks',
+ '1',
+ '--max-attempts-per-task',
+ '5',
+ '--max-steps-per-run',
+ 'none',
+ );
+
+ expect(mocks.setBudget).toHaveBeenCalledWith(
+ expect.objectContaining({
+ id: 'goal-1',
+ maxAttemptsPerTask: 5,
+ maxConcurrentTasks: 1,
+ maxManagerTurns: 60,
+ maxStepsPerRun: null,
+ }),
+ );
+ });
+});
+
+describe('goal set-requirement command', () => {
+ beforeEach(() => {
+ mocks.updateRequirement.mockResolvedValue({ data: { id: 'goal-1' }, success: true });
+ });
+
+ it('replaces the requirement from --requirement, trimming the surplus whitespace', async () => {
+ await run(
+ 'set-requirement',
+ 'goal-1',
+ '-r',
+ ' Done only when the dashboard reads from the merged backend ',
+ );
+
+ expect(mocks.updateRequirement).toHaveBeenCalledWith({
+ id: 'goal-1',
+ requirement: 'Done only when the dashboard reads from the merged backend',
+ });
+ });
+
+ it('reads a long, multi-line requirement from --file instead of the command line', async () => {
+ await run('set-requirement', 'goal-1', '--file', 'requirement.md');
+
+ expect(mocks.updateRequirement).toHaveBeenCalledWith({
+ id: 'goal-1',
+ requirement: '# What counts as done\n- Ship the migration with real evidence',
+ });
+ });
+
+ it('refuses an empty edit rather than blanking the acceptance bar', async () => {
+ await expect(run('set-requirement', 'goal-1')).rejects.toThrow('Provide the requirement');
+
+ expect(mocks.updateRequirement).not.toHaveBeenCalled();
+ });
+
+ it('refuses to guess when an inline requirement and a file are both passed', async () => {
+ await expect(
+ run('set-requirement', 'goal-1', '-r', 'inline text', '--file', 'requirement.md'),
+ ).rejects.toThrow('not both');
+
+ expect(mocks.updateRequirement).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/cli/src/commands/goal/configuration.ts b/apps/cli/src/commands/goal/configuration.ts
new file mode 100644
index 00000000000..bb2e9f64ae0
--- /dev/null
+++ b/apps/cli/src/commands/goal/configuration.ts
@@ -0,0 +1,105 @@
+import { readFile } from 'node:fs/promises';
+
+import type { Command } from 'commander';
+
+import { getTrpcClient } from '../../api/client';
+import { log } from '../../utils/logger';
+
+/**
+ * Rewrite an existing goal's own configuration β€” the limits it runs under and the
+ * acceptance bar it is judged against. Mirrors the server's grouping of the same
+ * mutations (`routers/lambda/goal/configuration.ts`), and lives outside `index.ts`
+ * because that file is already past the size limit.
+ */
+export const registerGoalConfigurationCommands = (goal: Command) => {
+ goal
+ .command('set-budget <id>')
+ .description(
+ 'Update limits; --max-rounds, --max-cost, --max-concurrent-tasks and --max-steps-per-run also accept "none" to remove that limit',
+ )
+ .option('--max-rounds <n>')
+ .option('--max-cost <usd>')
+ .option('--max-experiments <n>', 'Exploration experiment cap (1–200)')
+ .option(
+ '--max-manager-turns <n>',
+ 'Main Agent turn cap (1–100); raising it resumes a goal it paused',
+ )
+ .option(
+ '--max-concurrent-tasks <n>',
+ 'Tasks allowed to run at once (1–10; "none" restores the default)',
+ )
+ .option('--max-attempts-per-task <n>', 'Attempts per Task before opening a decision gate')
+ .option('--max-steps-per-run <n>', 'Agent step cap per Task run ("none" removes it)')
+ .action(
+ async (
+ id: string,
+ options: {
+ maxAttemptsPerTask?: string;
+ maxConcurrentTasks?: string;
+ maxCost?: string;
+ maxExperiments?: string;
+ maxManagerTurns?: string;
+ maxRounds?: string;
+ maxStepsPerRun?: string;
+ },
+ ) => {
+ const parseLimit = (value: string | undefined, integer = false) =>
+ value === undefined
+ ? undefined
+ : value === 'none'
+ ? null
+ : integer
+ ? Number.parseInt(value, 10)
+ : Number.parseFloat(value);
+ const result = await (
+ await getTrpcClient()
+ ).goal.setBudget.mutate({
+ id,
+ maxAttemptsPerTask:
+ options.maxAttemptsPerTask === undefined
+ ? undefined
+ : Number.parseInt(options.maxAttemptsPerTask, 10),
+ maxConcurrentTasks: parseLimit(options.maxConcurrentTasks, true),
+ maxExperiments:
+ options.maxExperiments === undefined ? undefined : Number(options.maxExperiments),
+ maxManagerTurns:
+ options.maxManagerTurns === undefined
+ ? undefined
+ : Number.parseInt(options.maxManagerTurns, 10),
+ maxRounds: parseLimit(options.maxRounds, true),
+ maxStepsPerRun: parseLimit(options.maxStepsPerRun, true),
+ maxTotalCost: parseLimit(options.maxCost),
+ });
+ log.info(result.message);
+ },
+ );
+
+ goal
+ .command('set-requirement <id>')
+ .description(
+ "Replace the goal's requirement β€” the acceptance bar its tasks and terminal review read",
+ )
+ .option('-r, --requirement <text>', 'New requirement text')
+ .option(
+ '-f, --file <path>',
+ 'Read the requirement from a file β€” use this for the long, multi-line document the goal page holds',
+ )
+ .action(async (id: string, options: { file?: string; requirement?: string }) => {
+ // These are alternatives, not a precedence order: a caller that passed both
+ // meant one of them, and silently picking one would rewrite the goal's
+ // acceptance bar on a guess.
+ if (options.file && options.requirement !== undefined) {
+ throw new Error('Pass either --requirement <text> or --file <path>, not both');
+ }
+ const requirement = (
+ options.file ? await readFile(options.file, 'utf8') : (options.requirement ?? '')
+ ).trim();
+ if (!requirement) {
+ throw new Error('Provide the requirement with --requirement <text> or --file <path>');
+ }
+ const result = await (
+ await getTrpcClient()
+ ).goal.updateRequirement.mutate({ id, requirement });
+ log.info(`Updated the requirement of goal ${result.data.id}`);
+ });
+};
diff --git a/apps/cli/src/commands/goal/index.test.ts b/apps/cli/src/commands/goal/index.test.ts
index 7a53b3737ad..15fdcf262b0 100644
--- a/apps/cli/src/commands/goal/index.test.ts
+++ b/apps/cli/src/commands/goal/index.test.ts
@@ -28,7 +28,6 @@ const { mockClient } = vi.hoisted(() => ({
graph: { query: vi.fn() },
resume: { mutate: vi.fn() },
retireNodes: { mutate: vi.fn() },
- setBudget: { mutate: vi.fn() },
supervision: { query: vi.fn() },
tick: { mutate: vi.fn() },
},
@@ -703,43 +702,6 @@ describe('goal supervision command', () => {
});
});
-describe('goal set-budget command', () => {
- beforeEach(() => {
- vi.clearAllMocks();
- vi.spyOn(log, 'info').mockImplementation(() => {});
- });
-
- it('edits the limits a goal was created with, so it can continue instead of being copied', async () => {
- mockClient.goal.setBudget.mutate.mockResolvedValue({ message: 'Goal budget updated' });
-
- await createProgram().parseAsync([
- 'node',
- 'test',
- 'goal',
- 'set-budget',
- 'goal-1',
- '--max-manager-turns',
- '60',
- '--max-concurrent-tasks',
- '1',
- '--max-attempts-per-task',
- '5',
- '--max-steps-per-run',
- 'none',
- ]);
-
- expect(mockClient.goal.setBudget.mutate).toHaveBeenCalledWith(
- expect.objectContaining({
- id: 'goal-1',
- maxAttemptsPerTask: 5,
- maxConcurrentTasks: 1,
- maxManagerTurns: 60,
- maxStepsPerRun: null,
- }),
- );
- });
-});
-
describe('goal delete', () => {
beforeEach(() => {
vi.clearAllMocks();
diff --git a/apps/cli/src/commands/goal/index.ts b/apps/cli/src/commands/goal/index.ts
index a9426f12712..dd7ab2bef9b 100644
--- a/apps/cli/src/commands/goal/index.ts
+++ b/apps/cli/src/commands/goal/index.ts
@@ -26,6 +26,7 @@ import {
parseGoalModelConfig,
registerGoalAssignmentCommands,
} from './assignment';
+import { registerGoalConfigurationCommands } from './configuration';
import { registerGoalGraphEditCommands } from './graphEdit';
import {
type GoalMetricState,
@@ -1127,69 +1128,10 @@ export function registerGoalCommand(program: Command) {
log.info(result.message);
});
- goal
- .command('set-budget <id>')
- .description('Update limits; pass "none" to remove a limit')
- .option('--max-rounds <n>')
- .option('--max-cost <usd>')
- .option('--max-experiments <n>', 'Exploration experiment cap (1–200)')
- .option(
- '--max-manager-turns <n>',
- 'Main Agent turn cap (1–100); raising it resumes a goal it paused',
- )
- .option(
- '--max-concurrent-tasks <n>',
- 'Tasks allowed to run at once (1–10; "none" restores the default)',
- )
- .option('--max-attempts-per-task <n>', 'Attempts per Task before opening a decision gate')
- .option('--max-steps-per-run <n>', 'Agent step cap per Task run ("none" removes it)')
- .action(
- async (
- id: string,
- options: {
- maxAttemptsPerTask?: string;
- maxConcurrentTasks?: string;
- maxCost?: string;
- maxExperiments?: string;
- maxManagerTurns?: string;
- maxRounds?: string;
- maxStepsPerRun?: string;
- },
- ) => {
- const parseLimit = (value: string | undefined, integer = false) =>
- value === undefined
- ? undefined
- : value === 'none'
- ? null
- : integer
- ? Number.parseInt(value, 10)
- : Number.parseFloat(value);
- const result = await (
- await getTrpcClient()
- ).goal.setBudget.mutate({
- id,
- maxAttemptsPerTask:
- options.maxAttemptsPerTask === undefined
- ? undefined
- : Number.parseInt(options.maxAttemptsPerTask, 10),
- maxConcurrentTasks: parseLimit(options.maxConcurrentTasks, true),
- maxExperiments:
- options.maxExperiments === undefined ? undefined : Number(options.maxExperiments),
- maxManagerTurns:
- options.maxManagerTurns === undefined
- ? undefined
- : Number.parseInt(options.maxManagerTurns, 10),
- maxRounds: parseLimit(options.maxRounds, true),
- maxStepsPerRun: parseLimit(options.maxStepsPerRun, true),
- maxTotalCost: parseLimit(options.maxCost),
- });
- log.info(result.message);
- },
- );
-
registerGoalAccessCommands(goal);
registerGoalArchiveCommands(goal);
registerGoalAssignmentCommands(goal);
+ registerGoalConfigurationCommands(goal);
goal
.command('bind-topic <id>')