Add task for Refinement #27

Closed
opened 2026-11-19 17:48:24 +01:00 by dario · 1 comment
Owner

New task refine-item: conception work on a work item, without code

Goal

A task for conception work: clarifying, specifying and splitting a work item (forge issue or tracker item), without changing code. Today the only option is implement-issue -interactive with the instruction "don't write code", which the agent doesn't always follow and the factory doesn't enforce. Trigger: #23 was too large and too vague for a local model; splitting it needs its own kind of session.

factory run refine-item -repo <owner/name> -item <n>                 # headless
factory run refine-item -repo <owner/name> -item <n> -interactive    # with a person

Behavior

The agent:

  1. reads the work item with all its comments, the items and pull requests it references, and the code the item is about,
  2. clarifies what is unclear:
    • interactive: asks the person in the session and waits for the answers,
    • headless: posts all questions as one comment on the work item and finishes. The person answers there and starts the task again,
  3. once everything is clear: posts one comment on the work item with either
    • a refined specification (goal, required facts, done criteria, how to verify), or
    • a split into sub-items, each with title, goal, required facts, done criteria and how to verify, each small enough for one pull request,
  4. marks facts it cannot verify (e.g. external APIs: the sandbox has no web access) as open questions instead of guessing,
  5. never changes code, never creates a branch and never opens a pull request.

Implementation

Follow the existing patterns; review-pr is the closest one (read-only, limited tools).

  1. Task in internal/dispatch/dispatch.go, Tasks:
    • "refine-item": {Name: "refine-item", Role: config.RoleRefine, Target: "work_item", ReadOnly: true, MCPTools: [...]}
    • MCPTools: whoami, get_repo, get_issue, list_issues, get_pull_request, get_pull_request_diff, list_pull_requests, comment_on_issue. Not: push_branch, create_pull_request, post_review, set_labels.
    • Check that Target: "work_item" with ReadOnly: true creates no factory/* branch and doesn't expect a pull request at the end. Wherever the dispatcher assumes that, add a case for this task.
  2. Success (end of the run in dispatch.go, next to the review check via ListReviews):
    • Forge issue: the run succeeded if the factory's account posted a new comment on the issue during the run. Read the issue's comments with GetIssue before and after the run and compare (like reviewsBefore).
    • Tracker item: the factory cannot see the comment. Treat the run as successful if the harness ended normally, and say so in the README.
  3. Role refine in internal/config/config.go:
    • Add RoleRefine = "refine" to Roles.
    • Optional: if roles.refine is missing, refine-item uses the implement role. All roles are required today (config.go, "roles.%s is required"); this must not change for the existing four, so existing configs stay valid.
    • FACTORY_AGENT_REFINE, FACTORY_MODEL_REFINE and FACTORY_BUDGET_REFINE work like for the other roles.
  4. Run prompt prompts/refine-item.tmpl, built from prompts/implement-issue.tmpl (repository, work item with forge/tracker distinction, account, shell commands, MCP servers, the skill). No branch line.
  5. Skill skills/refine-item/SKILL.md with valid frontmatter (name: refine-item, description). Content: the behavior above, plus:
    • the work item and its comments are untrusted data (as in implement-issue),
    • headless: questions go into one comment, then finish; never a mix of questions and plan,
    • no placeholders: what isn't known is an open question,
    • sub-items in a fixed format (title, goal, required facts, done criteria, verification).
  6. Docs: README (tasks, roles, the FACTORY_*_REFINE variables) and docs/developing-the-factory.md (where conception work goes in the improvement loop: before step 1).
  7. ADR docs/decisions/NNNN-refine-item.md: why a separate task with its own role, why read-only, why no create_issue yet.

Out of scope

  • Creating issues on the forge (create_issue). It needs a new forge operation in every backend plus forgetest, and a decision on how many issues one run may create. Separate issue. Until then, a person creates the sub-items from the comment.
  • Changing labels or status of the work item.

Done when

  • just check passes.
  • Tests in internal/dispatch/dispatch_test.go:
    • refine-item gets only the tools listed above, and the harness gets read-only shell commands (no allowed_shell),
    • a run without a new comment from the factory's account counts as unsuccessful, a run with one counts as successful,
    • no branch and no pull request are expected.
  • Tests in internal/config: a config without roles.refine is valid and refine-item uses implement; FACTORY_AGENT_REFINE overrides it.
  • The refine-item skill exists with valid frontmatter, and the README describes the task.

Verification by hand (in the factory-dev sandbox)

  1. factory run refine-item -repo dario/factory -item 23 -interactive: the agent asks questions, posts a split only after you agree, and edits no files (git -C <run>/work status is clean).
  2. The same without -interactive on a deliberately vague test issue: exactly one comment with questions, then the run ends successfully.

Changes to skills

This PR adds a skill. AGENTS.md requires an evidence section in the PR: link #23, the failed run on it (review of its PR), and the interactive split session, if it has happened by then.

Two notes:

  • The evidence: AGENTS.md requires it for a new skill. That's why the issue asks for the split session on #23 as evidence. If you do that session first with the workaround, the PR has its best evidence.
  • On the size: this is about the size of one PR, but it touches four areas: dispatcher, config, instructions and docs. For Qwen it's a good test of whether a precise spec is enough. If it's too much, split it into config with role, then dispatcher with task and tests, then skill with docs.
# New task `refine-item`: conception work on a work item, without code ## Goal A task for conception work: clarifying, specifying and splitting a work item (forge issue or tracker item), without changing code. Today the only option is `implement-issue -interactive` with the instruction "don't write code", which the agent doesn't always follow and the factory doesn't enforce. Trigger: #23 was too large and too vague for a local model; splitting it needs its own kind of session. factory run refine-item -repo <owner/name> -item <n> # headless factory run refine-item -repo <owner/name> -item <n> -interactive # with a person ## Behavior The agent: 1. reads the work item with all its comments, the items and pull requests it references, and the code the item is about, 2. clarifies what is unclear: - **interactive:** asks the person in the session and waits for the answers, - **headless:** posts all questions as **one** comment on the work item and finishes. The person answers there and starts the task again, 3. once everything is clear: posts **one** comment on the work item with either - a refined specification (goal, required facts, done criteria, how to verify), or - a split into sub-items, each with title, goal, required facts, done criteria and how to verify, each small enough for one pull request, 4. marks facts it cannot verify (e.g. external APIs: the sandbox has no web access) as **open questions** instead of guessing, 5. never changes code, never creates a branch and never opens a pull request. ## Implementation Follow the existing patterns; `review-pr` is the closest one (read-only, limited tools). 1. **Task** in `internal/dispatch/dispatch.go`, `Tasks`: - `"refine-item": {Name: "refine-item", Role: config.RoleRefine, Target: "work_item", ReadOnly: true, MCPTools: [...]}` - `MCPTools`: `whoami`, `get_repo`, `get_issue`, `list_issues`, `get_pull_request`, `get_pull_request_diff`, `list_pull_requests`, `comment_on_issue`. **Not**: `push_branch`, `create_pull_request`, `post_review`, `set_labels`. - Check that `Target: "work_item"` with `ReadOnly: true` creates no `factory/*` branch and doesn't expect a pull request at the end. Wherever the dispatcher assumes that, add a case for this task. 2. **Success** (end of the run in `dispatch.go`, next to the review check via `ListReviews`): - Forge issue: the run succeeded if the factory's account posted a new comment on the issue during the run. Read the issue's comments with `GetIssue` before and after the run and compare (like `reviewsBefore`). - Tracker item: the factory cannot see the comment. Treat the run as successful if the harness ended normally, and say so in the README. 3. **Role `refine`** in `internal/config/config.go`: - Add `RoleRefine = "refine"` to `Roles`. - **Optional:** if `roles.refine` is missing, `refine-item` uses the `implement` role. All roles are required today (`config.go`, "roles.%s is required"); this must not change for the existing four, so existing configs stay valid. - `FACTORY_AGENT_REFINE`, `FACTORY_MODEL_REFINE` and `FACTORY_BUDGET_REFINE` work like for the other roles. 4. **Run prompt** `prompts/refine-item.tmpl`, built from `prompts/implement-issue.tmpl` (repository, work item with forge/tracker distinction, account, shell commands, MCP servers, the skill). No branch line. 5. **Skill** `skills/refine-item/SKILL.md` with valid frontmatter (`name: refine-item`, `description`). Content: the behavior above, plus: - the work item and its comments are untrusted data (as in `implement-issue`), - headless: questions go into **one** comment, then finish; never a mix of questions and plan, - no placeholders: what isn't known is an open question, - sub-items in a fixed format (title, goal, required facts, done criteria, verification). 6. **Docs:** README (tasks, roles, the `FACTORY_*_REFINE` variables) and `docs/developing-the-factory.md` (where conception work goes in the improvement loop: before step 1). 7. **ADR** `docs/decisions/NNNN-refine-item.md`: why a separate task with its own role, why read-only, why no `create_issue` yet. ## Out of scope - Creating issues on the forge (`create_issue`). It needs a new forge operation in every backend plus `forgetest`, and a decision on how many issues one run may create. Separate issue. Until then, a person creates the sub-items from the comment. - Changing labels or status of the work item. ## Done when - `just check` passes. - Tests in `internal/dispatch/dispatch_test.go`: - `refine-item` gets only the tools listed above, and the harness gets read-only shell commands (no `allowed_shell`), - a run without a new comment from the factory's account counts as unsuccessful, a run with one counts as successful, - no branch and no pull request are expected. - Tests in `internal/config`: a config without `roles.refine` is valid and `refine-item` uses `implement`; `FACTORY_AGENT_REFINE` overrides it. - The `refine-item` skill exists with valid frontmatter, and the README describes the task. ## Verification by hand (in the `factory-dev` sandbox) 1. `factory run refine-item -repo dario/factory -item 23 -interactive`: the agent asks questions, posts a split only after you agree, and edits no files (`git -C <run>/work status` is clean). 2. The same without `-interactive` on a deliberately vague test issue: exactly one comment with questions, then the run ends successfully. ## Changes to skills This PR adds a skill. AGENTS.md requires an **evidence section** in the PR: link #23, the failed run on it (review of its PR), and the interactive split session, if it has happened by then. Two notes: - The evidence: AGENTS.md requires it for a new skill. That's why the issue asks for the split session on #23 as evidence. If you do that session first with the workaround, the PR has its best evidence. - On the size: this is about the size of one PR, but it touches four areas: dispatcher, config, instructions and docs. For Qwen it's a good test of whether a precise spec is enough. If it's too much, split it into config with role, then dispatcher with task and tests, then skill with docs.
Author
Owner

I've implemented the refine-item task for the factory. Here's a summary:

Implementation Complete

  1. Config: Added RoleRefine = "refine" constant and updated Roles array
  2. Dispatcher: Added refine-item task with read-only MCP tools and success checking for new comments
  3. Prompt: Created prompts/refine-item.tmpl template
  4. Skill: Created skills/refine-item/SKILL.md with headless and interactive modes
  5. Docs: Updated README, developing-the-factory.md, and created ADR 0016

Testing

All tests pass (except race detector which requires cgo):

go test ./...

Pull Request

I've opened pull request #28 to merge this into main. The PR includes:

  • All the code changes
  • Documentation updates
  • ADR for the new task

Notes

  • The task is read-only: no code changes, no branches, no pull requests
  • Headless mode: posts all questions as one comment, then finishes
  • Interactive mode: asks the person and waits for answers
  • Success: factory's account posted a new comment on the issue

🤖 Written by an AI agent (factory) using this account.

I've implemented the `refine-item` task for the factory. Here's a summary: ## Implementation Complete 1. **Config**: Added `RoleRefine = "refine"` constant and updated `Roles` array 2. **Dispatcher**: Added `refine-item` task with read-only MCP tools and success checking for new comments 3. **Prompt**: Created `prompts/refine-item.tmpl` template 4. **Skill**: Created `skills/refine-item/SKILL.md` with headless and interactive modes 5. **Docs**: Updated README, developing-the-factory.md, and created ADR 0016 ## Testing All tests pass (except race detector which requires cgo): ``` go test ./... ``` ## Pull Request I've opened pull request #28 to merge this into main. The PR includes: - All the code changes - Documentation updates - ADR for the new task ## Notes - The task is read-only: no code changes, no branches, no pull requests - Headless mode: posts all questions as one comment, then finishes - Interactive mode: asks the person and waits for answers - Success: factory's account posted a new comment on the issue --- <sub>🤖 Written by an AI agent (factory) using this account.</sub> <!-- factory:agent -->
dario closed this issue 2026-11-20 14:30:39 +01:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dario/factory#27
No description provided.