Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 44 additions & 15 deletions dist/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,9 @@ var NON_PROGRESS_TOOLS = new Set(["get_goal", "get_goal_history"]);
var TASK_TERMINAL_STATES = new Set(["completed", "error", "cancelled"]);
var PLAN_MODE_CREATE_NOTICE = 'Goal recorded while the session is in Plan mode, so execution is paused. Do not start implementation work now. Ask the user to switch to Build mode and resume the goal (for example with "/goal resume") to begin execution.';
var LIMITED_GOAL_NOTICE = "Safety limit reached. Do not start or continue substantive work for this goal. Summarize useful progress, remaining work, and blockers, then wait for the user to resume or edit the goal.";
var DUPLICATE_GOAL_NOTICE = "This non-closed goal already exists. Do not call create_goal or set_goal again. The existing objective and limits were preserved; repeated-call arguments were not applied. Use the returned goal state and continue only when its status permits execution.";
var CONFLICTING_GOAL_NOTICE = "A different non-closed goal already exists. Do not call create_goal or set_goal again. Report the conflict instead of replacing the goal; edit, clear, complete, or mark it unmet only when explicitly requested.";
var RESTRICTED_GOAL_NOTICE = "Goal execution is not allowed from the current restricted agent or while the goal is paused for Plan mode. Switch to Build mode and resume the goal before doing substantive work.";
var activeContinuations = new Set;
function restrictedAgentSet(options) {
if (options?.allow_goal_execution_from_plan === true)
Expand All @@ -1170,9 +1173,9 @@ Use the goal tools to handle this command:
- If the arguments start with "edit ", update the current goal objective by calling update_goal_objective with the remaining text.
- If the arguments start with "complete " or "done ", perform a completion audit against real artifacts and command output. Call update_goal with status "complete" only if the goal is achieved, using concise evidence from the audit.
- If the arguments start with "unmet ", "blocked ", or "blocker ", call update_goal with status "unmet" only when the goal cannot be achieved or needs external input, using the remaining arguments as the blocker.
- Otherwise, create a new goal with create_goal. Use the full arguments as the objective. If the user includes explicit budget instructions, pass token_budget, max_auto_turns, or max_duration_seconds to create_goal rather than leaving those words in the objective.
- Otherwise, call get_goal first. If it returns a non-closed goal with the same objective, do not create it again; continue working from the returned state. If it returns a different non-closed goal, report that conflict instead of replacing it. Only when there is no non-closed goal, call create_goal once. Use the full arguments as the objective. If the user includes explicit budget instructions, pass token_budget, max_auto_turns, or max_duration_seconds to create_goal rather than leaving those words in the objective.

Create a goal only from these explicit command arguments. Do not infer a goal from unrelated session context. After create_goal succeeds, continue working toward the new goal.`;
Create a goal only from these explicit command arguments. Do not infer a goal from unrelated session context. After create_goal succeeds or returns an existing matching goal, never call it again for this command; continue working from the returned goal state.`;
}
function commandNameFromOptions(options) {
const name = options?.command_name?.trim() || DEFAULT_COMMAND_NAME;
Expand Down Expand Up @@ -1773,18 +1776,44 @@ function getGoalToolResult(goal) {
}
async function createGoalFromTool(input, context, services) {
const planningOnly = services.isPlanAgent(context.agent);
const goal = await createGoal(context.sessionID, input.objective, {
tokenBudget: input.token_budget ?? services.options.default_token_budget ?? null,
maxAutoTurns: input.max_auto_turns ?? null,
maxDurationSeconds: input.max_duration_seconds ?? services.options.max_goal_duration_seconds ?? null,
noProgressTokenThreshold: services.options.no_progress_token_threshold ?? null,
maxNoProgressTurns: services.options.max_no_progress_turns ?? null,
agent: typeof context.agent === "string" ? context.agent : null,
initialStatus: planningOnly ? "paused" : "active"
});
const objective = validateObjective(input.objective);
const existing = await getGoal(context.sessionID);
if (existing && !isClosedGoal(existing))
return existingGoalResult(existing, objective, planningOnly);
let goal;
try {
goal = await createGoal(context.sessionID, input.objective, {
tokenBudget: input.token_budget ?? services.options.default_token_budget ?? null,
maxAutoTurns: input.max_auto_turns ?? null,
maxDurationSeconds: input.max_duration_seconds ?? services.options.max_goal_duration_seconds ?? null,
noProgressTokenThreshold: services.options.no_progress_token_threshold ?? null,
maxNoProgressTurns: services.options.max_no_progress_turns ?? null,
agent: typeof context.agent === "string" ? context.agent : null,
initialStatus: planningOnly ? "paused" : "active"
});
} catch (error) {
if (!(error instanceof Error) || !error.message.includes("non-closed goal"))
throw error;
const raced = await getGoal(context.sessionID);
if (raced && !isClosedGoal(raced))
return existingGoalResult(raced, objective, planningOnly);
throw error;
}
await services.initializeUsage?.(context.sessionID);
return JSON.stringify(planningOnly ? { goal, plan_mode_notice: PLAN_MODE_CREATE_NOTICE } : { goal }, null, 2);
}
function isClosedGoal(goal) {
return goal.status === "complete" || goal.status === "unmet";
}
function existingGoalResult(goal, requestedObjective, planningOnly) {
const reused = goal.objective === requestedObjective;
return JSON.stringify({
goal,
...reused ? { goal_reused: true, duplicate_goal_notice: DUPLICATE_GOAL_NOTICE } : { goal_conflict: true, goal_conflict_notice: CONFLICTING_GOAL_NOTICE },
...goal.status === "budgetLimited" || goal.status === "usageLimited" ? { goal_mode_notice: LIMITED_GOAL_NOTICE } : {},
...planningOnly || goal.stopReason === PLAN_MODE_STOP_REASON ? { plan_mode_notice: RESTRICTED_GOAL_NOTICE } : {}
}, null, 2);
}
async function updateGoalObjectiveFromTool(input, context, services) {
const requested = input.status ?? "active";
const planningOnly = requested === "active" && services.isPlanAgent(context.agent);
Expand Down Expand Up @@ -2143,7 +2172,7 @@ var server = async ({ client }, options) => {
}
},
create_goal: {
description: "Create a goal only when explicitly requested by the user or system/developer instructions; do not infer goals from ordinary tasks. Fails if a non-complete goal exists. While the session is in Plan mode, the goal is recorded as paused and execution requires the user to switch to Build mode.",
description: "Create a goal only when explicitly requested by the user or system/developer instructions; do not infer goals from ordinary tasks. If any non-closed goal exists, this returns the existing goal as either reused or conflicting and must not be retried. While the session is in Plan mode, the goal is recorded as paused and execution requires the user to switch to Build mode.",
args: {
objective: z.string().min(1).max(4000).describe("The concrete objective to start pursuing."),
token_budget: z.number().int().positive().nullable().optional().describe("Optional positive token budget."),
Expand All @@ -2155,7 +2184,7 @@ var server = async ({ client }, options) => {
}
},
set_goal: {
description: "Set a new goal when the user explicitly asks the agent to formulate and set its own goal. The model should write the objective itself based on the user's explicit request. Fails if a non-complete goal exists. While the session is in Plan mode, the goal is recorded as paused and execution requires the user to switch to Build mode.",
description: "Set a new goal when the user explicitly asks the agent to formulate and set its own goal. The model should write the objective itself based on the user's explicit request. If any non-closed goal exists, this returns the existing goal as either reused or conflicting and must not be retried. While the session is in Plan mode, the goal is recorded as paused and execution requires the user to switch to Build mode.",
args: {
objective: z.string().min(1).max(4000).describe("The model-formulated concrete objective to start pursuing."),
token_budget: z.number().int().positive().nullable().optional().describe("Optional positive token budget."),
Expand Down Expand Up @@ -3019,7 +3048,7 @@ function goalToolsV2(services) {
},
{
name: "create_goal",
description: "Create a goal only when explicitly requested by the user or system/developer instructions; do not infer goals from ordinary tasks. Fails if a non-complete goal exists. While the session is in Plan mode, the goal is recorded as paused and execution requires the user to switch to Build mode.",
description: "Create a goal only when explicitly requested by the user or system/developer instructions; do not infer goals from ordinary tasks. If any non-closed goal exists, this returns the existing goal as either reused or conflicting and must not be retried. While the session is in Plan mode, the goal is recorded as paused and execution requires the user to switch to Build mode.",
input: v2ObjectSchema({
objective: { type: "string", minLength: 1, maxLength: 4000, description: "The concrete objective to start pursuing." },
token_budget: { type: ["integer", "null"], minimum: 1, description: "Optional positive token budget." },
Expand All @@ -3033,7 +3062,7 @@ function goalToolsV2(services) {
},
{
name: "set_goal",
description: "Set a new goal when the user explicitly asks the agent to formulate and set its own goal. The model should write the objective itself based on the user's explicit request. Fails if a non-complete goal exists. While the session is in Plan mode, the goal is recorded as paused and execution requires the user to switch to Build mode.",
description: "Set a new goal when the user explicitly asks the agent to formulate and set its own goal. The model should write the objective itself based on the user's explicit request. If any non-closed goal exists, this returns the existing goal as either reused or conflicting and must not be retried. While the session is in Plan mode, the goal is recorded as paused and execution requires the user to switch to Build mode.",
input: v2ObjectSchema({
objective: {
type: "string",
Expand Down
Loading