Skip to content

Commit 116570e

Browse files
igorcostaAutohand Evolve
andcommitted
Merge goal continuation into type_v7
Integrate automatic continuation for active persistent goals with its unit, built-terminal, and documentation coverage. Co-authored-by: Autohand Evolve <code-noreply@autohand.ai>
2 parents a8cdd4e + 585bf83 commit 116570e

9 files changed

Lines changed: 157 additions & 9 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ See [Agent Skills Documentation](docs/agent-skills.md) for creating custom skill
349349
| `/publish-research`| Preview and publish a saved research report with explicit confirmation |
350350
| `/automode` | Manage auto-mode |
351351
| `/autoresearch` | Run replayable benchmark loops with history, replay, comparison, and Pareto analysis |
352-
| `/goal` | Set, review, or refine the current session goal |
352+
| `/goal` | Set a persistent goal and continue automatically until it reaches a terminal state |
353353
| `/goal writer` | Draft one or more well-specified goals with the built-in `$goal-writer` skill |
354354
| `/squad` | Open/manage the local Autohand Squad runtime |
355355
| `/go` | Pair this session with the Autohand Code iOS app |

‎docs/features.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ The `/settings` command opens an interactive settings editor directly in the ter
101101
| `/share` | Share current session |
102102
| `/sync` | Sync settings |
103103
| `/add-dir` | Add directories to workspace |
104-
| `/goal` | Set, review, or refine a persistent session goal |
104+
| `/goal` | Set a persistent goal and continue successful auto-mode turns until it reaches a terminal state |
105105
| `/goal writer` | Draft one or more well-specified goals with the built-in `$goal-writer` skill |
106106
| `/automode` | Start autonomous coding mode |
107107
| `/autoresearch` | Run replayable benchmark loops with adaptive decisions, history, replay, comparison, and Pareto analysis |

‎src/commands/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Each command is a separate TypeScript file that exports:
2727
| `/agents definitions` | `agents.ts` | List configured sub-agents |
2828
| `/tools` | `tools.ts` | Manage persisted meta-tools |
2929
| `/experiments` | `features.ts` | List and toggle experiments |
30-
| `/goal` | `goal.ts` | Manage persistent goals, budgets, templates, and queued goal work. Requires `slash_goal`. |
30+
| `/goal` | `goal.ts` | Manage persistent goals, budgets, templates, and queued goal work; active goals continue across successful auto-mode turns until terminal. Requires `slash_goal`. |
3131
| `/squad` | `squad.ts` | Open/manage the standalone Autohand Squad runtime. |
3232
| `/usage` | `usage.ts` | Show Autohand plan limits and project token activity |
3333
| `/statusline` | `statusline.ts` | Configure composer status-line fields |

‎src/commands/goal.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
import chalk from 'chalk';
7-
import { GoalManager } from '../goals/GoalManager.js';
7+
import { buildGoalContinuationInstruction, GoalManager } from '../goals/GoalManager.js';
88
import type { SlashCommand, SlashCommandContext } from '../core/slashCommandTypes.js';
99
import type { GoalMutationResult, GoalSnapshot } from '../goals/types.js';
1010
import { GOAL_FEATURE_DISABLED_MESSAGE, resolveGoalFeatureEnabled } from '../goals/feature.js';
@@ -155,11 +155,7 @@ async function handleQueue(manager: GoalManager, rest: string): Promise<string>
155155

156156
function queueGoalContinuation(ctx: SlashCommandContext, objective: string): void {
157157
ctx.setInteractionMode?.('automode');
158-
ctx.queueInstruction?.([
159-
`Active goal: ${objective}`,
160-
'Continue working toward this persistent goal until it is complete, blocked, paused, cleared, or budget-limited.',
161-
'Use get_goal or update_goal when you need to inspect or modify the goal state.',
162-
].join('\n'));
158+
ctx.queueInstruction?.(buildGoalContinuationInstruction(objective));
163159
}
164160

165161
function formatMutation(result: GoalMutationResult): string {

‎src/core/agent/AgentLifecycleRunner.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { shouldForceAgentIdleLogout } from './AgentSessionAccounting.js';
3838
import { consumeAgentInkSubmittedInstructionEcho } from './AgentUIRuntime.js';
3939
import {
4040
createQueuedAgentInstruction,
41+
resolveActiveGoalContinuation,
4142
unpackQueuedAgentInstruction,
4243
type PendingPostTurnAction,
4344
type SequencedQueuedAgentInstruction,
@@ -1695,6 +1696,18 @@ export async function runAgentInteractiveLoop(host: AgentLifecycleHost): Promise
16951696
console.log(renderTerminalMarkdown(publicationResult));
16961697
}
16971698
}
1699+
const goalContinuation = await resolveActiveGoalContinuation(
1700+
{
1701+
runtime: host.runtime,
1702+
shouldExit: host.shouldExit,
1703+
interactiveAutomodeEnabled: host.interactiveAutomodeEnabled,
1704+
runtimeResourceShutdownController: host.runtimeResourceShutdownController,
1705+
},
1706+
turnSucceeded,
1707+
);
1708+
if (goalContinuation) {
1709+
host.pendingInkInstructions.push(createQueuedAgentInstruction({ text: goalContinuation }));
1710+
}
16981711
host.flushMcpStartupSummaryIfPending();
16991712

17001713
// Start generating next-step suggestion in background.

‎src/core/agent/PostTurnActionCoordinator.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
import { readDeepResearchRun } from '../../deepResearch/session.js';
7+
import { buildGoalContinuationInstruction, GoalManager } from '../../goals/GoalManager.js';
78
import type { MobileComposerCommandExecutionOutcome } from '../../mobile/MobileHandoffClient.js';
89
import type { MobileComposerExecutableCommand } from '../../mobile/MobileCommandPolicy.js';
910
import type { MobileClaimedTurnContext } from '../../mobile/MobileRelay.js';
@@ -70,6 +71,15 @@ export interface PostTurnActionHost {
7071
requestResearchPublication(reportPath: string): Promise<string>;
7172
}
7273

74+
export interface ActiveGoalContinuationHost {
75+
runtime: {
76+
workspaceRoot: string;
77+
};
78+
shouldExit: boolean;
79+
interactiveAutomodeEnabled: boolean;
80+
runtimeResourceShutdownController?: AbortController;
81+
}
82+
7383
export function unpackQueuedAgentInstruction(
7484
value: PendingAgentInstruction,
7585
): SequencedQueuedAgentInstruction {
@@ -124,6 +134,30 @@ export async function executePendingPostTurnAction(
124134
return host.requestResearchPublication(action.reportPath);
125135
}
126136

137+
export async function resolveActiveGoalContinuation(
138+
host: ActiveGoalContinuationHost,
139+
turnSucceeded: boolean,
140+
): Promise<string | null> {
141+
if (
142+
!turnSucceeded
143+
|| !host.interactiveAutomodeEnabled
144+
|| host.shouldExit
145+
|| host.runtimeResourceShutdownController?.signal.aborted
146+
) {
147+
return null;
148+
}
149+
150+
try {
151+
const snapshot = await new GoalManager(host.runtime.workspaceRoot).getSnapshot();
152+
if (snapshot.goal?.status !== 'active') {
153+
return null;
154+
}
155+
return buildGoalContinuationInstruction(snapshot.goal.objective);
156+
} catch {
157+
return null;
158+
}
159+
}
160+
127161
function currentPostTurnEnvironment(): PostTurnEnvironment {
128162
const ci = process.env.CI?.toLowerCase();
129163
return {

‎src/goals/GoalManager.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ import type {
2323
const GOAL_STATE_FILE = 'goals.local.json';
2424
const MAX_OBJECTIVE_LENGTH = 80_000;
2525

26+
export function buildGoalContinuationInstruction(objective: string): string {
27+
return [
28+
`Active goal: ${objective}`,
29+
'Continue working toward this persistent goal until it is complete, blocked, paused, cleared, or budget-limited.',
30+
'Use get_goal or update_goal when you need to inspect or modify the goal state.',
31+
].join('\n');
32+
}
33+
2634
export class GoalManager {
2735
constructor(private readonly workspaceRoot: string) {}
2836

‎tests/core/agent/PostTurnActionCoordinator.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ import path from 'node:path';
99
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
1010
import {
1111
executePendingPostTurnAction,
12+
resolveActiveGoalContinuation,
1213
unpackQueuedAgentInstruction,
14+
type ActiveGoalContinuationHost,
1315
type PostTurnActionHost,
1416
type PostTurnEnvironment,
1517
} from '../../../src/core/agent/PostTurnActionCoordinator.js';
18+
import { GoalManager } from '../../../src/goals/GoalManager.js';
1619

1720
const interactiveEnvironment: PostTurnEnvironment = {
1821
stdinIsTTY: true,
@@ -147,3 +150,46 @@ describe('post-turn research publication', () => {
147150
expect(requestResearchPublication).not.toHaveBeenCalled();
148151
});
149152
});
153+
154+
describe('post-turn active goal continuation', () => {
155+
let workspaceRoot: string;
156+
let host: ActiveGoalContinuationHost;
157+
158+
beforeEach(async () => {
159+
workspaceRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'autohand-goal-continuation-'));
160+
await new GoalManager(workspaceRoot).createGoal({ objective: 'Finish the browser game' });
161+
host = {
162+
runtime: { workspaceRoot },
163+
shouldExit: false,
164+
interactiveAutomodeEnabled: true,
165+
};
166+
});
167+
168+
afterEach(async () => {
169+
await fs.remove(workspaceRoot);
170+
});
171+
172+
it('continues a successful auto-mode turn while the goal remains active', async () => {
173+
const continuation = await resolveActiveGoalContinuation(host, true);
174+
175+
expect(continuation).toContain('Active goal: Finish the browser game');
176+
expect(continuation).toContain('until it is complete, blocked, paused, cleared, or budget-limited');
177+
});
178+
179+
it.each([
180+
['the turn failed', false, true, false],
181+
['auto mode is disabled', true, false, false],
182+
['the session is exiting', true, true, true],
183+
])('does not continue when %s', async (_label, turnSucceeded, autoMode, shouldExit) => {
184+
host.interactiveAutomodeEnabled = autoMode;
185+
host.shouldExit = shouldExit;
186+
187+
await expect(resolveActiveGoalContinuation(host, turnSucceeded)).resolves.toBeNull();
188+
});
189+
190+
it('stops scheduling after the goal reaches a terminal state', async () => {
191+
await new GoalManager(workspaceRoot).updateGoal({ status: 'complete' });
192+
193+
await expect(resolveActiveGoalContinuation(host, true)).resolves.toBeNull();
194+
});
195+
});

‎tests/tuistory/built-cli.tuistory.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,57 @@ describe('interactive built CLI Tuistory tests', () => {
972972
await exitInteractive(session);
973973
});
974974

975+
it('continues an active goal after a non-terminal model response', async () => {
976+
const openRouterServer = await createMockOpenRouterSequenceServer([
977+
JSON.stringify({
978+
thought: 'The goal needs implementation work after this planning turn.',
979+
toolCalls: [],
980+
finalResponse: 'FIRST_GOAL_TURN_FINISHED',
981+
}),
982+
JSON.stringify({
983+
thought: 'The implementation is now complete, so the persistent goal can be completed.',
984+
toolCalls: [{ tool: 'update_goal', args: { status: 'complete' } }],
985+
}),
986+
JSON.stringify({
987+
toolCalls: [],
988+
finalResponse: 'GOAL_CONTINUATION_FINISHED',
989+
}),
990+
]);
991+
mockServers.push(openRouterServer);
992+
const session = await launchInteractive({
993+
config: {
994+
openrouter: { baseUrl: openRouterServer.baseUrl },
995+
features: { slashGoal: true },
996+
agent: { autoMemory: false, maxIterations: 4, sessionRetryLimit: 0 },
997+
network: { maxRetries: 0, retryDelay: 0 },
998+
ui: {
999+
promptSuggestions: false,
1000+
showCompletionNotification: false,
1001+
terminalBell: false,
1002+
},
1003+
},
1004+
});
1005+
1006+
await waitForComposer(session);
1007+
await session.type('/goal build a toddler-friendly browser game');
1008+
await session.press('enter');
1009+
await session.waitForText('Goal created.', { timeout: 10_000 });
1010+
await session.waitForText('FIRST_GOAL_TURN_FINISHED', { timeout: 15_000 });
1011+
await session.waitForText('GOAL_CONTINUATION_FINISHED', { timeout: 5_000 });
1012+
1013+
await waitForComposer(session);
1014+
await session.type('/goal');
1015+
await session.press('enter');
1016+
await session.waitForText('Status: complete', { timeout: 5_000 });
1017+
1018+
const output = session.readAll();
1019+
expect(output).toContain('Interactive auto mode active');
1020+
expect(output).toContain('GOAL_CONTINUATION_FINISHED');
1021+
expect(output.match(/GOAL_CONTINUATION_FINISHED/gu)).toHaveLength(1);
1022+
1023+
await exitInteractive(session);
1024+
}, 45_000);
1025+
9751026
it('starts device auth from the startup auth gate', async () => {
9761027
const state = await createTempAutohandHome({
9771028
config: {

0 commit comments

Comments
 (0)