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
11 changes: 6 additions & 5 deletions docs/hooks/tools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -840,12 +840,13 @@ If a value is too large for the environment or contains a NUL byte, Xum omits it
</details>

<details>
<summary>task_remove (2)</summary>
<summary>task_remove (3)</summary>

| Env var | JSON path | Type | Description |
| --------------------------------- | ------------------- | ------ | ------------------------------------------------------------------- |
| `XUM_TOOL_INPUT_TASK_IDS_<INDEX>` | `task_ids[<INDEX>]` | string | Inactive child task IDs to remove. |
| `XUM_TOOL_INPUT_TASK_IDS_COUNT` | `task_ids.length` | number | Number of elements in task_ids (Inactive child task IDs to remove.) |
| Env var | JSON path | Type | Description |
| --------------------------------- | ------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `XUM_TOOL_INPUT_FORCE` | `force` | boolean | Remove even if the child holds unsaved work, and delete that work. Set only when the user asked for cleanup or the work is provably saved (pushed, merged, or in an applied patch). |
| `XUM_TOOL_INPUT_TASK_IDS_<INDEX>` | `task_ids[<INDEX>]` | string | Inactive child task IDs to remove. |
| `XUM_TOOL_INPUT_TASK_IDS_COUNT` | `task_ids.length` | number | Number of elements in task_ids (Inactive child task IDs to remove.) |

</details>

Expand Down
22 changes: 22 additions & 0 deletions src/browser/features/Tools/TaskStopRemoveToolCall.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,26 @@ describe("TaskStopToolCall and TaskRemoveToolCall", () => {
expect(rowB.textContent).toContain("Uncommitted changes.");
expect(rowB.textContent).not.toContain(paths[0]);
});

test("task_remove shows what a forced removal deleted on the removed row only", () => {
const deletedWork = "Deleted 2 commit(s). Checkout: /worktrees/task-a. Branch: task-a.";
const view = renderTool(
"task_remove",
{ ...args, force: true },
{
status: "completed",
result: {
results: [
{ status: "removed", taskId: "task-a", deletedWork, paths: ["notes.txt"] },
{ status: "removed", taskId: "task-b" },
],
} satisfies TaskRemoveToolSuccessResult,
}
);
fireEvent.click(view.getByText("task_remove"));

expect(rowOf(view, "task-a").textContent).toContain(deletedWork);
expect(rowOf(view, "task-a").textContent).toContain("notes.txt");
expect(rowOf(view, "task-b").textContent).not.toContain("Deleted");
});
});
51 changes: 50 additions & 1 deletion src/browser/features/Tools/TaskToolCall.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TaskStopToolCall,
TaskToolCall,
} from "@/browser/features/Tools/TaskToolCall";
import { lightweightMeta } from "@/browser/stories/meta.js";
import { lightweightMeta, PIXEL_DISABLED } from "@/browser/stories/meta.js";

const meta = {
...lightweightMeta,
Expand Down Expand Up @@ -240,6 +240,55 @@ export const TaskNarrowLongModelId: Story = {
},
};

/** a forced task_remove lists what it deleted; long paths and the checkout path must stay in a 375px card */
export const TaskRemoveForcedNarrow: Story = {
// The play function asserts the layout; the Pixel snapshot budget is at its cap.
parameters: { pixel: PIXEL_DISABLED },
render: () => (
<div data-testid="forced-remove-card" className="bg-background w-[375px] p-2">
<TaskRemoveToolCall
args={{ task_ids: ["obsolete-reviewer", "clean-reviewer"], force: true }}
result={{
results: [
{
status: "removed",
taskId: "obsolete-reviewer",
workspaceId: "obsolete-reviewer",
deletedWork:
"Deleted the uncommitted or untracked files listed in paths and 2 commit(s) not captured by a ready patch artifact. Checkout: /home/user/.xum/src/project/obsolete-reviewer-with-a-long-name. Branch: obsolete-reviewer-with-a-long-name.",
paths: ["src/node/services/someVeryLongFileNameThatNeverBreaksAnywhereAtAll.ts"],
},
{ status: "removed", taskId: "clean-reviewer", workspaceId: "clean-reviewer" },
],
}}
status="completed"
/>
</div>
),
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
canvas.getByText("task_remove").click();
const deletedWork = await waitFor(() => canvas.getByText(/^Deleted the uncommitted/));
await new Promise<void>((resolve) =>
requestAnimationFrame(() => requestAnimationFrame(() => resolve()))
);
const container = canvasElement.querySelector('[data-testid="forced-remove-card"]');
if (!(container instanceof HTMLElement)) {
throw new Error("forced task_remove card container not found");
}
// Right-edge containment, not scrollWidth: ancestors clip overflow, which would hide it.
const containerRight = container.getBoundingClientRect().right;
for (const element of [deletedWork, canvas.getByText(/someVeryLongFileName/)]) {
const overflow = element.getBoundingClientRect().right - containerRight;
if (overflow > 1) {
throw new Error(
`forced task_remove text overflowed the 375px card by ${Math.round(overflow)}px`
);
}
}
},
};

/** task_apply_git_patch states: executing, dry-run, success, and failure */
export const TaskApplyGitPatchStates: Story = {
render: () => (
Expand Down
50 changes: 32 additions & 18 deletions src/browser/features/Tools/TaskToolCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1958,6 +1958,35 @@ export const TaskStopToolCall: React.FC<TaskStopToolCallProps> = (props) => {
);
};

interface TaskRemoveResultRowProps {
result: {
taskId: string;
status?: string;
error?: string;
paths?: string[];
/** What a forced removal deleted. */
deletedWork?: string;
};
}

const TaskRemoveResultRow: React.FC<TaskRemoveResultRowProps> = (props) => (
<div className="bg-code-bg rounded-sm p-2">
<TaskId id={props.result.taskId} />
{props.result.status != null && <TaskStatusBadge status={props.result.status} />}
{props.result.error != null && (
<div className="text-danger mt-1 text-[11px]">{props.result.error}</div>
)}
{props.result.deletedWork != null && (
<div className="text-secondary mt-1 text-[11px] break-words">{props.result.deletedWork}</div>
)}
{props.result.paths?.map((filePath) => (
<div key={filePath} className="text-secondary font-mono text-[11px] break-all">
{filePath}
</div>
))}
</div>
);

interface TaskRemoveToolCallProps {
args: TaskRemoveToolArgs;
result?: TaskRemoveToolSuccessResult;
Expand All @@ -1967,12 +1996,8 @@ interface TaskRemoveToolCallProps {
export const TaskRemoveToolCall: React.FC<TaskRemoveToolCallProps> = (props) => {
const { expanded, toggleExpanded } = useToolExpansion(false);
const results = props.result?.results ?? [];
const displayResults: Array<{
taskId: string;
status?: string;
error?: string;
paths?: string[];
}> = results.length > 0 ? results : props.args.task_ids.map((taskId) => ({ taskId }));
const displayResults: Array<TaskRemoveResultRowProps["result"]> =
results.length > 0 ? results : props.args.task_ids.map((taskId) => ({ taskId }));
const removed = results.filter((result) => result.status === "removed").length;
return (
<ToolContainer expanded={expanded}>
Expand All @@ -1991,18 +2016,7 @@ export const TaskRemoveToolCall: React.FC<TaskRemoveToolCallProps> = (props) =>
<ToolDetails>
<div className="task-surface mt-1 space-y-2 rounded-md p-3">
{displayResults.map((result, index) => (
<div key={result.taskId ?? index} className="bg-code-bg rounded-sm p-2">
<TaskId id={result.taskId} />
{result.status != null && <TaskStatusBadge status={result.status} />}
{result.error != null && (
<div className="text-danger mt-1 text-[11px]">{result.error}</div>
)}
{result.paths?.map((filePath) => (
<div key={filePath} className="text-secondary font-mono text-[11px] break-all">
{filePath}
</div>
))}
</div>
<TaskRemoveResultRow key={result.taskId ?? index} result={result} />
))}
</div>
</ToolDetails>
Expand Down
13 changes: 12 additions & 1 deletion src/common/utils/tools/toolDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,13 @@ export const TaskStopToolResultSchema = z
export const TaskRemoveToolArgsSchema = z
.object({
task_ids: z.array(z.string().min(1)).min(1).describe("Inactive child task IDs to remove."),
force: z
.boolean()
.nullish()
.describe(
"Remove even if the child holds unsaved work, and delete that work. " +
"Set only when the user asked for cleanup or the work is provably saved (pushed, merged, or in an applied patch)."
),
})
.strict();

Expand All @@ -1221,6 +1228,8 @@ const TaskRemoveToolBaseResultSchema = z.object({
workspaceId: z.string().optional(),
descendantTaskIds: z.array(z.string()).optional(),
paths: z.array(z.string()).optional(),
/** What a forced removal deleted: the work, the checkout and the branch. */
deletedWork: z.string().optional(),
error: z.string().optional(),
});

Expand Down Expand Up @@ -1406,6 +1415,8 @@ const TaskWorkspaceLifecycleBaseResultSchema = z.object({
workspaceId: z.string().optional(),
displayName: z.string().optional(),
paths: z.array(z.string()).optional(),
/** What a forced removal deleted: the work, the checkout and the branch. */
deletedWork: z.string().optional(),
activeTaskIds: z.array(z.string()).optional(),
descendantTaskIds: z.array(z.string()).optional(),
note: z.string().optional(),
Expand Down Expand Up @@ -3031,7 +3042,7 @@ export const TOOL_DEFINITIONS = {
task_remove: {
resultSchema: TaskRemoveToolResultSchema,
description:
"Irreversibly remove inactive child workspaces you own; they cannot be restored or reawakened. Use it only for consumed best-of candidates, overlapping or obsolete roles, a bench over its limit, or a user request, not as routine cleanup. Remove descendants first. A child with uncommitted or untracked work, or commits without a ready patch artifact, is refused; only the user can discard that work.",
"Irreversibly remove inactive child workspaces you own; they cannot be restored or reawakened. Use it only for consumed best-of candidates, overlapping or obsolete roles, a bench over its limit, or a user request, not as routine cleanup. Remove descendants first. A child with uncommitted or untracked work, or commits without a ready patch artifact, is refused unless you set force, which deletes that work and reports it. Set force only when the user asked for cleanup or the work is provably saved.",
schema: TaskRemoveToolArgsSchema,
},
task_workspace_lifecycle: {
Expand Down
11 changes: 6 additions & 5 deletions src/node/services/agentSkills/builtInSkillContent.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8623,12 +8623,13 @@ export const BUILTIN_SKILL_FILES: Record<string, Record<string, string>> = {
"</details>",
"",
"<details>",
"<summary>task_remove (2)</summary>",
"<summary>task_remove (3)</summary>",
"",
"| Env var | JSON path | Type | Description |",
"| --------------------------------- | ------------------- | ------ | ------------------------------------------------------------------- |",
"| `XUM_TOOL_INPUT_TASK_IDS_<INDEX>` | `task_ids[<INDEX>]` | string | Inactive child task IDs to remove. |",
"| `XUM_TOOL_INPUT_TASK_IDS_COUNT` | `task_ids.length` | number | Number of elements in task_ids (Inactive child task IDs to remove.) |",
"| Env var | JSON path | Type | Description |",
"| --------------------------------- | ------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |",
"| `XUM_TOOL_INPUT_FORCE` | `force` | boolean | Remove even if the child holds unsaved work, and delete that work. Set only when the user asked for cleanup or the work is provably saved (pushed, merged, or in an applied patch). |",
"| `XUM_TOOL_INPUT_TASK_IDS_<INDEX>` | `task_ids[<INDEX>]` | string | Inactive child task IDs to remove. |",
"| `XUM_TOOL_INPUT_TASK_IDS_COUNT` | `task_ids.length` | number | Number of elements in task_ids (Inactive child task IDs to remove.) |",
"",
"</details>",
"",
Expand Down
6 changes: 4 additions & 2 deletions src/node/services/subagentRemovalWorkCheck.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* Finds work that removing a sub-agent checkout would destroy and nothing preserves (#4723). Only
* model-driven task_remove consults it; user-confirmed and automatic removals keep force-removing.
* Finds work that removing a sub-agent checkout would destroy and nothing preserves (#4723).
* Model-driven task_remove consults it: by default a finding refuses the removal, and with the
* tool's `force` flag the removal goes on and reports the finding as what it deleted.
* User-confirmed and automatic removals keep force-removing without consulting it.
*/
import assert from "node:assert/strict";

Expand Down
Loading
Loading