Commit graph

69 commits

Author SHA1 Message Date
johba
1675e17502 fix: replace PRODUCT-TRUTH.md/ARCHITECTURE.md refs with AGENTS.md
These docs never existed — gardener and review-pr referenced them
as if they did. AGENTS.md tree is now the single architecture
reference for all agents.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 17:41:10 +01:00
johba
71aa49afbb docs: add AGENTS.md seeding instructions to BOOTSTRAP.md
Explains how to seed the AGENTS.md tree with watermarks before the
first planner run to avoid the first-run flood. Also adds planner
to cron schedule and lifecycle diagram.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 17:01:04 +01:00
johba
7f41048aea fix: remove dead STATE.md code, restore matrix notify, targeted git add (Closes #13, Closes #14)
- Remove STATE_FILE variable and all STATE.md references from phase 2
- Restore matrix_send for gap analysis issue creation
- Replace broad `git add -A "*.md"` with targeted `find -name AGENTS.md`

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 16:53:33 +01:00
johba
3bb75f18be feat: planner uses Claude tool access to navigate AGENTS.md tree (Closes #12)
Phase 1 rewritten:
- Claude gets --dangerously-skip-permissions to navigate code, read
  diffs, and update AGENTS.md files directly
- Per-file <!-- last-reviewed: SHA --> watermarks replace global marker
- Sub-directory AGENTS.md files discovered and updated independently
- ~200 line convention enforced via prompt
- Changes committed on branch and PR'd

Phase 2 now reads AGENTS.md tree + STATE.md for gap analysis.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 16:33:47 +01:00
openhands
679c62e7cb refactor: planner maintains AGENTS.md instead of STATE.md
STATE.md was a machine-generated system description that was always
worse than the human-curated AGENTS.md. Killed STATE.md entirely.

Phase 1: Reviews recent git history against AGENTS.md, suggests
updates via PR to keep the file tree, conventions, and architecture
descriptions current.

Phase 2: Gap analysis — compares AGENTS.md + VISION.md + open issues,
creates backlog issues for missing capabilities.
2026-03-15 15:13:41 +00:00
johba
e1101894d6 fix: clean stale git worktrees in P4 housekeeping (Closes #11)
Add unconditional worktree cleanup to factory supervisor:
- Remove review + dev worktrees older than 2h with no active agent
- Use git worktree remove --force instead of rm -rf
- Run git worktree prune every poll to clear dangling refs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 16:05:38 +01:00
openhands
5c6293fdab fix: strip non-bullet preamble from planner output
Sonnet prepends narration before the actual bullets. Strip everything
before the first '- ' line instead of rejecting the whole output.
2026-03-15 15:02:53 +00:00
openhands
af75c0eccf fix: even stronger output-only instruction for Sonnet
Sonnet keeps narrating. Made the constraint explicitly say 'starts
with - on the very first character' and 'will be rejected'.
2026-03-15 14:59:42 +00:00
openhands
ff50d28645 feat: planner reads project docs for architectural understanding
Feeds AGENTS.md, PRODUCT-TRUTH.md, ARCHITECTURE.md, UX-DECISIONS.md
into the prompt so the planner understands the system at a conceptual
level. Rewritten prompt emphasizes describing the system, not the
changes. Good/bad examples guide output style.
2026-03-15 14:58:10 +00:00
openhands
240ba62b28 factory: learned — False Positive: 'Waiting for CI + Review' Alert 2026-03-15 14:52:58 +00:00
openhands
0a0d5e8e24 fix: inline merge+rebase in recovery path (do_merge not yet defined)
do_merge() is defined at line 876, but recovery mode calls it at
line ~498. Bash requires functions to be defined before use.
Inlined the merge→rebase→re-approve→retry logic directly.
2026-03-15 14:10:21 +00:00
openhands
2c527cef4a fix: dev-agent handles approved+stuck PRs in recovery mode
1. Recovery mode: if PR already has approval + green CI, try merge
   immediately instead of entering the review wait loop forever.
2. do_merge: on 405/merge failure, rebase → force push → wait CI →
   re-approve via review_bot → retry merge. Covers the stale-approval
   dismissal problem end-to-end.
3. Codeberg mergeable field is unreliable — rebase on any merge failure.
2026-03-15 14:09:33 +00:00
openhands
a114f638ef fix: planner validates bullet output, rejects meta-commentary
Sonnet sometimes narrates what it did instead of outputting the actual
STATE.md. Added validation that first line starts with '- ' and
strengthened the output-only instruction.
2026-03-15 12:51:59 +00:00
openhands
4b95d32a0c fix: planner PR lookup filters by head.ref client-side
Codeberg head= query param is unreliable — filter with jq instead.
2026-03-15 12:49:22 +00:00
openhands
17053f8559 fix: planner creates PR instead of direct push to protected master
Also removes local keyword from top-level scope.
2026-03-15 12:47:50 +00:00
openhands
335ea0d48d fix: remove local keyword outside function in planner 2026-03-15 12:42:12 +00:00
openhands
efa6eab352 fix: planner GIT_RANGE newline bug from pipefail + head -1
set -o pipefail causes head -1 to fail the pipeline when git log
is still producing output. The || fallback then appends a second
line. Fix: capture first SHA separately with || true.
2026-03-15 12:41:50 +00:00
johba
1a9afa9f9c Merge pull request 'docs: add BOOTSTRAP.md for onboarding new projects' (#9) from docs/bootstrap into main
Reviewed-on: https://codeberg.org/johba/dark-factory/pulls/9
2026-03-15 13:34:44 +01:00
johba
70dddc3162 docs: add BOOTSTRAP.md for onboarding new projects
Project-agnostic guide covering .env config, target repo prep,
issue conventions, cron setup, verification, and troubleshooting.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 13:34:35 +01:00
openhands
c5fdd8ac50 fix: always rebase on merge failure, don't trust mergeable field
Codeberg's mergeable field flickers between true/false — unreliable
for deciding whether to rebase. Just attempt rebase on any non-200/204.
Worst case it's a no-op. Also added git fetch before rebase.
2026-03-15 10:51:09 +00:00
johba
9b0c1e6c30 feat: add planner-agent, remove STATE.md append from dev-agent
- Remove write_state_entry/append_state_log from dev-agent (#10)
- Add planner-agent.sh: rebuilds STATE.md from git history + closed
  issues, then gap-analyses against VISION.md to create backlog
  issues (#6, #7)
- Add planner-poll.sh: cron wrapper with lock + memory guard

STATE.md is now solely owned by the planner — one compact snapshot
rebuilt each run, not an ever-growing append log.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 11:45:16 +01:00
openhands
c22f1acbdf fix: add matrix notifications for silent failure paths
dev-poll.sh:
- Merge conflicts (rebase attempt + outcome)
- Non-conflict merge failures (HTTP code)
- Low memory skip
- New issue launch

review-poll.sh:
- Review script failure
2026-03-15 10:27:23 +00:00
openhands
b4d14c4c98 fix: auto-rebase on merge conflict (mergeable=false)
When merge returns non-200, check mergeable flag. If false,
rebase the PR branch onto master via worktree. If rebase fails,
spawn dev-agent to resolve. Prevents infinite 405 retry loops.

Extracted try_merge_or_rebase() helper used at all 3 merge points.
2026-03-15 10:21:40 +00:00
johba
996d197401 fix: supervisor only kills factory-spawned claude, not interactive sessions
pgrep matched all claude processes including manual screen sessions.
Narrow to "claude -p" so only non-interactive (factory-spawned) processes
get reaped by the stale-process cleanup.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 10:39:40 +01:00
johba
7bba97b0d6 fix: add ~/.local/bin to PATH for claude binary
Dev-agent failed with exit 127 (command not found) because claude
is installed in ~/.local/bin which wasn't in the PATH set by env.sh.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 17:18:15 +01:00
johba
f215fbe3cf feat: add Matrix coordination channel, replace openclaw (Closes #8)
Add matrix_send() to lib/env.sh and matrix_listener.sh daemon for
real-time notifications, threaded escalations, and human-in-the-loop
replies. All agents now notify via Matrix instead of openclaw.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 16:25:33 +01:00
johba
90ef03a304 refactor: make all scripts multi-project via env vars
Replace hardcoded harb references across the entire codebase:
- HARB_REPO_ROOT → PROJECT_REPO_ROOT (with deprecated alias)
- Derive PROJECT_NAME from CODEBERG_REPO slug
- Add PRIMARY_BRANCH (master/main), WOODPECKER_REPO_ID env vars
- Parameterize worktree prefixes, docker container names, branch refs
- Genericize agent prompts (gardener, factory supervisor)
- Update best-practices docs to use $-vars, prefix harb lessons

All project-specific values now flow from .env → lib/env.sh → scripts.
Backward-compatible: existing harb setups work without .env changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 13:49:09 +01:00
johba
f16df6c53e docs: update README for multi-project vision, add gardener, expand setup
- Remove harb-specific framing — describe as project-agnostic factory
- Add gardener agent (was missing from docs entirely)
- New Prerequisites section with required vs optional dependencies
- Expand Setup with full annotated .env example
- Add Agents summary table
- Add "project-agnostic" design principle

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 13:38:38 +01:00
openhands
2b3c488f1c fix: STATE.md entries without status prefix — reads as done once merged 2026-03-14 12:14:42 +00:00
openhands
a3f0f7f6f3 fix: stuck PR issue extraction — check title, body (Closes #N), log skip
PRs #684 and #710 had no issue number in branch name or title.
Now also checks PR body for 'Closes #NNN'. If still no issue found,
logs a skip (dev-agent requires an issue number to work).
2026-03-14 12:01:36 +00:00
openhands
30b31c76aa fix: stuck PR detection only matched fix/issue-NNN branches
PRs with custom branch names (fix/fitness-factory-address,
chore/seed-consolidation) were invisible to priority 1.5.
Now also extracts issue number from PR title (#NNN) as fallback.
2026-03-14 11:12:27 +00:00
openhands
7fd913596b fix: write_state_entry defined after call site — crashes dev-agent
Function was defined at line 867 but called at line 550. Bash requires
functions to be defined before invocation. Moved to top with other
helpers. Also removed duplicate definition.
2026-03-14 11:01:05 +00:00
openhands
c3f24460a7 fix: gardener must ACTION or ESCALATE every tech-debt issue, never skip
Claude was silently skipping ambiguous issues instead of escalating.
Made output format mandatory and explicit: every issue in the list
must result in ACTION (promoted) or ESCALATE (needs decision).
2026-03-14 08:40:19 +00:00
openhands
0f979fd6c9 fix: stuck PRs priority + STATE.md in first commit + 405 bug in dev-poll
1. PRIORITY 1.5 in dev-poll: scan ALL open PRs for REQUEST_CHANGES or CI
   failure before picking new backlog issues. Stuck PRs get fixed first
   to avoid complex rebases piling up.

2. STATE.md written in worktree before claude starts (included in first
   commit, not a separate push that dismisses stale approvals).

3. Removed HTTP 405 from merge success check in dev-poll.sh (was fixed
   in dev-agent.sh but not here — 2 occurrences).
2026-03-14 07:34:47 +00:00
openhands
793dafdb8a fix: gardener uses curl+CODEBERG_TOKEN instead of codeberg_api function
codeberg_api is a bash function in the gardener script's own process,
not available to claude-p's tool execution environment. Claude was
silently failing to call it and returning CLEAN.

Switch to curl commands with $CODEBERG_TOKEN env var that claude-p
can actually execute via its bash tool.
2026-03-13 22:35:30 +00:00
openhands
a6dea87de0 factory: learned — keccak-derived FEE_DEST requires anvil_setBalance before impersonation 2026-03-13 22:34:44 +00:00
openhands
d137862813 fix: gardener tech-debt promotion not surfaced as problem
Tech-debt→backlog promotion was only in prompt text, not in the
problem list. Claude focused on detected problems (dupes, thin issues)
and printed CLEAN, ignoring the primary mission.

Fix: explicitly list up to 10 tech-debt issues in the problem list
so claude sees them as actionable items.

Also bumped --max-turns from 10 to 30 — promoting issues requires
reading + editing + relabeling via API, needs more turns.
2026-03-13 20:50:16 +00:00
openhands
2f14d12032 factory: learned — False Positive: Status Unchanged Alert 2026-03-13 20:21:54 +00:00
openhands
8e3b72d13f feat: dev-agent auto-rebase before merge
When PR has merge conflicts (mergeable=false), attempt git rebase
before merge. If rebase fails, abort and escalate via notify.

Flow: approval → check mergeable → rebase if needed → wait CI → merge

Resolves the serial seed PR bottleneck where append-only files
(manifest.jsonl) create trivial conflicts that block the pipeline.
2026-03-13 19:56:12 +00:00
openhands
0132c7acc4 fix: 405 treated as merge success + STATE.md push dismissed approvals
Root cause: Two bugs combined to silently close PRs without merging.

1. HTTP 405 ('not allowed to merge') was in the success condition
   alongside 200/204. Codeberg returns 405 when branch protection
   blocks the merge (e.g., stale approvals).

2. append_state_log pushed a new commit AFTER review_bot approved,
   but BEFORE the merge attempt. With dismiss_stale_approvals=true,
   the new commit automatically dismissed the approval → 405.

Impact: 6 PRs (#683, #688, #692, #695, #696, #699) were 'merged'
(logged as success, branch deleted, issue closed) but never actually
merged into master. All work was lost.

Fixes:
- Remove 405 from merge success check
- Move STATE.md append out of pre-merge path
2026-03-13 17:41:10 +00:00
openhands
f7531d6ee9 Revert "lesson: fork safety — ERC-4337 code, impersonation, chain addresses, docker perms"
This reverts commit 0d0838bea0.
2026-03-13 16:16:47 +00:00
openhands
0d0838bea0 lesson: fork safety — ERC-4337 code, impersonation, chain addresses, docker perms 2026-03-13 16:13:01 +00:00
openhands
4362f58a16 factory: learned — FEE_DEST address must match DeployLocal.sol 2026-03-13 15:53:45 +00:00
openhands
36fe3c8575 lesson: dep resolution — trust closed state, don't hunt for PRs 2026-03-13 11:26:52 +00:00
openhands
98210cc302 fix: dep check — trust closed state, drop merged-PR search
The merged-PR search was over-engineered and caused false negatives
(couldn't match PR to issue when title/body didn't contain #NNN).
Issue closed = dep satisfied. Factory only closes after merging.
2026-03-13 11:25:35 +00:00
openhands
d61dead3f1 fix: dep check fallback — also check PR with same number as issue
Codeberg uses shared issue/PR numbering. When a PR IS the dep issue
(e.g. PR #665 fixes issue #665), the title search misses it.
Fallback checks if pulls/{dep_num} is merged.
2026-03-13 11:24:14 +00:00
openhands
b8097f1144 fix: gitignore *.log.old, *.log.*, escalations.jsonl 2026-03-13 10:43:37 +00:00
openhands
499f6d8828 feat: STATE.md append before merge, lives in harb repo
Moved from dark-factory to harb. Dev-agent appends one line to
STATE.md on the PR branch right before merge — goes through
review like any other change.
2026-03-13 10:27:10 +00:00
openhands
f10e0a1545 state: seed with current reality snapshot 2026-03-13 10:25:23 +00:00
openhands
ed58874890 feat: STATE.md append on merge (dark-factory#5)
After each successful PR merge, dev-agent appends one line to
STATE.md: - [date] what now exists (#PR)

Lives in dark-factory repo (harb master is protected).
Planner will collapse this into a compact snapshot later.
2026-03-13 10:25:00 +00:00