---
engine: devin
cwd: /Users/sd9235/code/mygh/learning_ai_devops_tools
yolo: true
lock: devops-tools
timeout: 3h
---

ROLE: Senior engineer. Implement Phase 1 — Slice 2 (Profiles + deps/DAG, single host).

SOURCE OF TRUTH: agent-queue/docs/GIGAFACTORY/GIGAFACTORY_ROADMAP.md (read §5 deps, §6 profiles,
§14 Phase 1). This slice implements ONLY the items below.

PREREQUISITE / BRANCHING:
- Slice 1 (manifest/priority/capabilities/engine-class/idempotency) AND Slice 3
  (resilience: orphan recovery, WIP checkpoint/resume, retry, insights) are BOTH
  already merged into `main`. Branch off the CURRENT `main`.
- Do NOT duplicate, revert, or break any Slice 1 or Slice 3 code or tests — the
  existing selftest cases (34 checks) MUST stay green (regression).
- New branch: feat/gigafactory-p1-slice2. Push + open a PR. DO NOT merge.

STRICT SCOPE:
- Edit ONLY under agent-queue/ (agent-queue.sh, selftest.sh, README.md, new
  profiles/ dir, docs/GIGAFACTORY/GIGAFACTORY_ROADMAP.md). No other repo.
- DO NOT modify/delete anything under agent-queue/queue/ (live jobs). DO NOT run
  `agent-queue.sh run`. selftest.sh uses its own temp AGENT_QUEUE_ROOT only.
- bash, single host. No service/Cosmos work (that is Phase 2).

A. PROFILES (§6)
1. Create agent-queue/profiles/ with a starter catalog as profiles/<name>.md:
   developer, backend-engineer, frontend-engineer, ux-designer, ui-designer, qa,
   reviewer, docs-writer (and a reserved `planner`). Each has frontmatter:
   name, persona (multi-line block), capabilities, default-verify, engine-class,
   prefers-engine, allowed-scope, review-policy.
2. Profile resolution: when a job sets `profile: X`, inherit any of
   {verify, capabilities, engine-class, prefers-engine, allowed-scope,
   review-policy} that the job OMITS. Job-level fields ALWAYS override the profile.
   Resolution runs BEFORE the capability gate + engine resolution so inherited
   caps/engine-class take effect.
3. Persona injection: prepend the profile's persona to the job body in the
   stripped body file fed to the engine. Never write secrets to logs.
4. allowed-scope guardrail — WARN-ONLY this phase: after the run, if cwd is a git
   repo, compute changed paths and log a WARNING for any path outside the
   allowed-scope globs. Non-blocking (do NOT fail the job). Expose the scope-check
   as a unit-testable function.
5. Document the resolution precedence (job > profile > built-in default).

B. DEPS / DAG — single host (§5)
6. deps reference other jobs by `idempotency-key` (stable, author-controlled). A
   dep is satisfied when a job with that key is in shipped/ (default), or in
   shipped/ OR testing/ when the dependent job sets `deps-mode: soft`.
7. A job with unmet deps is BLOCKED: not selected to run, surfaced in `status` as
   "blocked (waiting on <keys>)". Implement as a skip-with-reason in inbox
   selection (like the busy-lock skip) — do NOT launch, do NOT move to failed.
   Re-evaluated every run loop; becomes runnable once deps are satisfied.
8. Submit-time cycle detection on `add`: build the dep graph from idempotency-keys
   across inbox + active stages; reject (die, nonzero) if the new job would create
   a cycle.
9. No cross-machine deps (that is P2).

TESTS (selftest.sh — tests are sacred; only ADD):
- profile inherit verify: a profile whose default-verify is `false` → a job using
  it (no own verify) routes to failed/; a profile with default-verify `true` →
  testing/.
- persona injection (golden): the body fed to the engine begins with the profile
  persona (capture via a stub that copies its --prompt-file to a sentinel).
- profile caps inheritance: job omitting capabilities inherits the profile's →
  unmet → failed/ result=capability_mismatch.
- allowed-scope warn: an out-of-scope change logs a WARNING and the job still
  succeeds (or assert the scope-check function directly).
- deps block→run: job B deps:[keyA] stays blocked while A is unshipped; once A is
  in shipped/, B becomes runnable and completes.
- deps-mode soft: dep satisfied when the dependency is in testing/.
- cycle detection: adding A deps:[keyB] while B deps:[keyA] is rejected.

DOCS:
- README: profiles section (catalog + resolution precedence) + deps/blocked
  semantics.
- docs/GIGAFACTORY/GIGAFACTORY_ROADMAP.md: tick the §6 boxes you fully completed and the §5
  `deps` box; bump §0 Phase 1 %.

CONSTRAINTS: bash style consistent with the existing script; no new runtime deps;
macOS + Linux safe; no emojis in code; no leftover debug noise; conventional
commits.

VERIFY GATE (must pass):
- bash agent-queue/selftest.sh → fully green (existing + new).
- bash -n agent-queue/agent-queue.sh ; node --check agent-queue/dashboard.mjs.

FINAL OUTPUT — print the implementation report in EXACTLY this format:

## Implementation Report — Phase 1 Slice 2
### Branch & commits
- branch / based-on: <name> (based on main | feat/gigafactory-p1-slice1)
- commits: <sha> <message> (one per line)
- PR: <url or "opened, not merged">
### Files changed
- <path>: <one-line summary>
### What was implemented (A1-5, B6-9)
- <item>: <how, key functions added/changed>
### Tests added
- <test name>: <what it asserts>  (plus selftest.sh PASS/FAIL summary)
### Verify gate results
- selftest.sh: <PASS/FAIL + counts>
- bash -n / node --check: <result>
### Deviations / assumptions
- <anything changed from spec and why>
### Suggested next slice
- <what should come next (likely: tracker adapter aq from-tracker/to-tracker)>
