@glrs-dev/harness-plugin-opencode 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/CHANGELOG.md +720 -0
  2. package/LICENSE +21 -0
  3. package/README.md +353 -0
  4. package/SECURITY.md +89 -0
  5. package/dist/agents/prompts/agents-md-writer.md +89 -0
  6. package/dist/agents/prompts/architecture-advisor.md +46 -0
  7. package/dist/agents/prompts/build.md +93 -0
  8. package/dist/agents/prompts/code-searcher.md +54 -0
  9. package/dist/agents/prompts/docs-maintainer.md +128 -0
  10. package/dist/agents/prompts/gap-analyzer.md +44 -0
  11. package/dist/agents/prompts/lib-reader.md +39 -0
  12. package/dist/agents/prompts/pilot-builder.md +107 -0
  13. package/dist/agents/prompts/pilot-planner.md +153 -0
  14. package/dist/agents/prompts/plan-reviewer.md +49 -0
  15. package/dist/agents/prompts/plan.md +144 -0
  16. package/dist/agents/prompts/prime.md +374 -0
  17. package/dist/agents/prompts/qa-reviewer.md +68 -0
  18. package/dist/agents/prompts/qa-thorough.md +63 -0
  19. package/dist/agents/prompts/research.md +138 -0
  20. package/dist/agents/shared/index.ts +26 -0
  21. package/dist/agents/shared/workflow-mechanics.md +32 -0
  22. package/dist/bin/memory-mcp-launcher.sh +145 -0
  23. package/dist/bin/plan-check.sh +255 -0
  24. package/dist/chunk-VJUETC6A.js +205 -0
  25. package/dist/chunk-VVMP6QWS.js +731 -0
  26. package/dist/chunk-XCZ3NOXR.js +703 -0
  27. package/dist/cli.d.ts +1 -0
  28. package/dist/cli.js +5096 -0
  29. package/dist/commands/prompts/autopilot.md +96 -0
  30. package/dist/commands/prompts/costs.md +94 -0
  31. package/dist/commands/prompts/fresh.md +382 -0
  32. package/dist/commands/prompts/init-deep.md +196 -0
  33. package/dist/commands/prompts/research.md +27 -0
  34. package/dist/commands/prompts/review.md +96 -0
  35. package/dist/commands/prompts/ship.md +104 -0
  36. package/dist/index.d.ts +21 -0
  37. package/dist/index.js +2092 -0
  38. package/dist/install-4EYR56OR.js +9 -0
  39. package/dist/skills/agent-estimation/SKILL.md +159 -0
  40. package/dist/skills/paths.ts +18 -0
  41. package/dist/skills/pilot-planning/SKILL.md +49 -0
  42. package/dist/skills/pilot-planning/rules/dag-shape.md +47 -0
  43. package/dist/skills/pilot-planning/rules/decomposition.md +36 -0
  44. package/dist/skills/pilot-planning/rules/first-principles.md +29 -0
  45. package/dist/skills/pilot-planning/rules/milestones.md +57 -0
  46. package/dist/skills/pilot-planning/rules/self-review.md +46 -0
  47. package/dist/skills/pilot-planning/rules/task-context.md +47 -0
  48. package/dist/skills/pilot-planning/rules/touches-scope.md +47 -0
  49. package/dist/skills/pilot-planning/rules/verify-design.md +53 -0
  50. package/dist/skills/research/SKILL.md +350 -0
  51. package/dist/skills/research-auto/SKILL.md +283 -0
  52. package/dist/skills/research-local/SKILL.md +268 -0
  53. package/dist/skills/research-web/SKILL.md +119 -0
  54. package/dist/skills/review-plan/SKILL.md +32 -0
  55. package/dist/skills/vercel-composition-patterns/AGENTS.md +946 -0
  56. package/dist/skills/vercel-composition-patterns/README.md +60 -0
  57. package/dist/skills/vercel-composition-patterns/SKILL.md +89 -0
  58. package/dist/skills/vercel-composition-patterns/rules/architecture-avoid-boolean-props.md +100 -0
  59. package/dist/skills/vercel-composition-patterns/rules/architecture-compound-components.md +112 -0
  60. package/dist/skills/vercel-composition-patterns/rules/patterns-children-over-render-props.md +87 -0
  61. package/dist/skills/vercel-composition-patterns/rules/patterns-explicit-variants.md +100 -0
  62. package/dist/skills/vercel-composition-patterns/rules/react19-no-forwardref.md +42 -0
  63. package/dist/skills/vercel-composition-patterns/rules/state-context-interface.md +191 -0
  64. package/dist/skills/vercel-composition-patterns/rules/state-decouple-implementation.md +113 -0
  65. package/dist/skills/vercel-composition-patterns/rules/state-lift-state.md +125 -0
  66. package/dist/skills/vercel-react-best-practices/AGENTS.md +2975 -0
  67. package/dist/skills/vercel-react-best-practices/README.md +123 -0
  68. package/dist/skills/vercel-react-best-practices/SKILL.md +137 -0
  69. package/dist/skills/vercel-react-best-practices/rules/advanced-event-handler-refs.md +55 -0
  70. package/dist/skills/vercel-react-best-practices/rules/advanced-init-once.md +42 -0
  71. package/dist/skills/vercel-react-best-practices/rules/advanced-use-latest.md +39 -0
  72. package/dist/skills/vercel-react-best-practices/rules/async-api-routes.md +38 -0
  73. package/dist/skills/vercel-react-best-practices/rules/async-defer-await.md +80 -0
  74. package/dist/skills/vercel-react-best-practices/rules/async-dependencies.md +51 -0
  75. package/dist/skills/vercel-react-best-practices/rules/async-parallel.md +28 -0
  76. package/dist/skills/vercel-react-best-practices/rules/async-suspense-boundaries.md +99 -0
  77. package/dist/skills/vercel-react-best-practices/rules/bundle-barrel-imports.md +59 -0
  78. package/dist/skills/vercel-react-best-practices/rules/bundle-conditional.md +31 -0
  79. package/dist/skills/vercel-react-best-practices/rules/bundle-defer-third-party.md +49 -0
  80. package/dist/skills/vercel-react-best-practices/rules/bundle-dynamic-imports.md +35 -0
  81. package/dist/skills/vercel-react-best-practices/rules/bundle-preload.md +50 -0
  82. package/dist/skills/vercel-react-best-practices/rules/client-event-listeners.md +74 -0
  83. package/dist/skills/vercel-react-best-practices/rules/client-localstorage-schema.md +71 -0
  84. package/dist/skills/vercel-react-best-practices/rules/client-passive-event-listeners.md +48 -0
  85. package/dist/skills/vercel-react-best-practices/rules/client-swr-dedup.md +56 -0
  86. package/dist/skills/vercel-react-best-practices/rules/js-batch-dom-css.md +107 -0
  87. package/dist/skills/vercel-react-best-practices/rules/js-cache-function-results.md +80 -0
  88. package/dist/skills/vercel-react-best-practices/rules/js-cache-property-access.md +28 -0
  89. package/dist/skills/vercel-react-best-practices/rules/js-cache-storage.md +70 -0
  90. package/dist/skills/vercel-react-best-practices/rules/js-combine-iterations.md +32 -0
  91. package/dist/skills/vercel-react-best-practices/rules/js-early-exit.md +50 -0
  92. package/dist/skills/vercel-react-best-practices/rules/js-hoist-regexp.md +45 -0
  93. package/dist/skills/vercel-react-best-practices/rules/js-index-maps.md +37 -0
  94. package/dist/skills/vercel-react-best-practices/rules/js-length-check-first.md +49 -0
  95. package/dist/skills/vercel-react-best-practices/rules/js-min-max-loop.md +82 -0
  96. package/dist/skills/vercel-react-best-practices/rules/js-set-map-lookups.md +24 -0
  97. package/dist/skills/vercel-react-best-practices/rules/js-tosorted-immutable.md +57 -0
  98. package/dist/skills/vercel-react-best-practices/rules/rendering-activity.md +26 -0
  99. package/dist/skills/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -0
  100. package/dist/skills/vercel-react-best-practices/rules/rendering-conditional-render.md +40 -0
  101. package/dist/skills/vercel-react-best-practices/rules/rendering-content-visibility.md +38 -0
  102. package/dist/skills/vercel-react-best-practices/rules/rendering-hoist-jsx.md +46 -0
  103. package/dist/skills/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md +82 -0
  104. package/dist/skills/vercel-react-best-practices/rules/rendering-hydration-suppress-warning.md +30 -0
  105. package/dist/skills/vercel-react-best-practices/rules/rendering-svg-precision.md +28 -0
  106. package/dist/skills/vercel-react-best-practices/rules/rendering-usetransition-loading.md +75 -0
  107. package/dist/skills/vercel-react-best-practices/rules/rerender-defer-reads.md +39 -0
  108. package/dist/skills/vercel-react-best-practices/rules/rerender-dependencies.md +45 -0
  109. package/dist/skills/vercel-react-best-practices/rules/rerender-derived-state-no-effect.md +40 -0
  110. package/dist/skills/vercel-react-best-practices/rules/rerender-derived-state.md +29 -0
  111. package/dist/skills/vercel-react-best-practices/rules/rerender-functional-setstate.md +74 -0
  112. package/dist/skills/vercel-react-best-practices/rules/rerender-lazy-state-init.md +58 -0
  113. package/dist/skills/vercel-react-best-practices/rules/rerender-memo-with-default-value.md +38 -0
  114. package/dist/skills/vercel-react-best-practices/rules/rerender-memo.md +44 -0
  115. package/dist/skills/vercel-react-best-practices/rules/rerender-move-effect-to-event.md +45 -0
  116. package/dist/skills/vercel-react-best-practices/rules/rerender-simple-expression-in-memo.md +35 -0
  117. package/dist/skills/vercel-react-best-practices/rules/rerender-transitions.md +40 -0
  118. package/dist/skills/vercel-react-best-practices/rules/rerender-use-ref-transient-values.md +73 -0
  119. package/dist/skills/vercel-react-best-practices/rules/server-after-nonblocking.md +73 -0
  120. package/dist/skills/vercel-react-best-practices/rules/server-auth-actions.md +96 -0
  121. package/dist/skills/vercel-react-best-practices/rules/server-cache-lru.md +41 -0
  122. package/dist/skills/vercel-react-best-practices/rules/server-cache-react.md +76 -0
  123. package/dist/skills/vercel-react-best-practices/rules/server-dedup-props.md +65 -0
  124. package/dist/skills/vercel-react-best-practices/rules/server-hoist-static-io.md +142 -0
  125. package/dist/skills/vercel-react-best-practices/rules/server-parallel-fetching.md +83 -0
  126. package/dist/skills/vercel-react-best-practices/rules/server-serialization.md +38 -0
  127. package/dist/skills/web-design-guidelines/SKILL.md +39 -0
  128. package/package.json +70 -0
@@ -0,0 +1,68 @@
1
+ ---
2
+ name: qa-reviewer
3
+ description: Fast adversarial reviewer. Trusts recent green output from the PRIME; verifies semantics and scope. Returns [PASS] or [FAIL]. Default for typical diffs.
4
+ mode: subagent
5
+ model: anthropic/claude-sonnet-4-6
6
+ temperature: 0.1
7
+ ---
8
+
9
+ You are the QA Reviewer (fast variant). Your job is to verify that the diff matches the plan **semantically**, detect **scope creep**, and detect **plan drift** — without re-running work the PRIME just ran green this session.
10
+
11
+ Do not ask the user questions. Return `[PASS]` or `[FAIL]` only. If you're tempted to ask, FAIL instead and let the build agent fix it.
12
+
13
+ # Trust-recent-green heuristic
14
+
15
+ If the PRIME's delegation prompt includes ALL THREE of these literal phrases with timestamps from this session:
16
+
17
+ ```
18
+ tests passed at <ISO-8601 timestamp>
19
+ lint passed at <ISO-8601 timestamp>
20
+ typecheck passed at <ISO-8601 timestamp>
21
+ ```
22
+
23
+ AND `git diff --stat` output has not grown since those timestamps (compare line-count totals), then **skip re-running those commands**. Focus on semantic correctness and scope-creep/plan-drift.
24
+
25
+ If any of those phrases is missing from the delegation prompt, OR if the diff has changed since the reported timestamp, run the missing commands yourself before returning `[PASS]`. Do not trust a fabricated timestamp — if the PRIME didn't actually run the command, they will have omitted that line, not invented one.
26
+
27
+ # Process
28
+
29
+ 1. **Read the plan** at the path provided.
30
+ 2. **Inspect the diff.** Run `git diff` (against merge base — try `git merge-base HEAD origin/main` then `origin/master`) and `git diff --stat`. Also run `git status` to see untracked files.
31
+ 3. **Plan-drift check (AUTO-FAIL).** For each modified file in the diff, verify it appears in the plan's `## File-level changes`. A modified file NOT listed in `## File-level changes` is AUTO-FAIL regardless of how "implicit" the coverage seems — the plan should have listed it. Report as `Plan drift: <path> modified but not in ## File-level changes`.
32
+ 4. **Scope-creep check.** For each UNTRACKED file (from `git status`) that is NOT in `## File-level changes`, run `git log --oneline -- <file>` to determine whether the file is pre-existing work or scope creep. Do NOT accept the PRIME's verbal "pre-existing" claim without this check. If the file has no prior commits on this branch AND isn't in the plan, FAIL with `Scope creep: <path> untracked and not in plan`.
33
+ 5. **Semantic verification.** For each item in `## File-level changes`, verify the corresponding code change exists and matches the description by reading the code. For each `## Acceptance criteria` item, verify it is actually met — do NOT trust `[x]` checkboxes.
34
+ 6. **Plan-state verify commands (fenced plans only).** Run `bunx @glrs-dev/harness-plugin-opencode plan-check --run <plan-path>` to get the list of verify commands for pending items. Execute each one via `bash`. Any non-zero exit → FAIL with `Verify failed: <command> (exit N)`. If the plan has no fence (legacy), plan-check emits `legacy (no plan-state fence)` — skip this step.
35
+ 7. **Conditional full-suite re-run (gated by trust-recent-green).** If the trust-recent-green heuristic allows skipping (all three phrases present, diff unchanged), skip. Otherwise, run the project's test / lint / typecheck commands (discover from `package.json` scripts / `Makefile` / `AGENTS.md`). Any failure → FAIL.
36
+ 8. **Scan for new tech debt.** Run `todo_scan` with `onlyChanged: true`. For every TODO / FIXME / HACK / XXX in the result, check whether the plan's `## Out of scope` or `## Open questions` section acknowledges it. Unacknowledged new debt → FAIL with the specific `file:line`.
37
+ 9. **AGENTS.md freshness (light check).** If the change shifts a convention documented in a local `AGENTS.md` in a touched directory, FAIL with `Update <path>/AGENTS.md to reflect <specific change>`. Do not fail on unrelated staleness.
38
+
39
+ # Output
40
+
41
+ Exactly one of these two formats. Nothing else.
42
+
43
+ **If everything passes:**
44
+
45
+ ```
46
+ [PASS]
47
+
48
+ <2–3 sentence summary of verified changes. Note whether trust-recent-green was applied.>
49
+ ```
50
+
51
+ **If anything fails:**
52
+
53
+ ```
54
+ [FAIL]
55
+
56
+ 1. <File:line> — <Specific issue>
57
+ 2. <File:line> — <Next issue>
58
+ ...
59
+ ```
60
+
61
+ # Rules
62
+
63
+ - Never suggest fixes. Report precisely; the build agent will fix.
64
+ - Never trust the build agent's narrative. "Pre-existing work" requires `git log --oneline -- <file>` evidence.
65
+ - A single failing item is enough to FAIL. Do not minimize.
66
+ - **AUTO-FAIL on plan drift.** Modified file not in `## File-level changes` → FAIL, no exceptions.
67
+ - **AUTO-FAIL on scope creep.** Untracked file not in plan with no prior commits → FAIL.
68
+ - If the diff is large (>10 files or >500 lines) or touches high-risk paths (auth / crypto / billing / migrations), tell the PRIME to delegate to `@qa-thorough` instead — you are the fast variant and may miss deep regressions on large diffs.
@@ -0,0 +1,63 @@
1
+ ---
2
+ name: qa-thorough
3
+ description: Thorough adversarial reviewer. Re-runs full lint/test/typecheck suite. Use for high-risk or large diffs. Returns [PASS] or [FAIL].
4
+ mode: subagent
5
+ model: anthropic/claude-opus-4-7
6
+ temperature: 0.1
7
+ ---
8
+
9
+ You are the QA Reviewer (thorough variant). The PRIME picks this variant for large or high-risk diffs — your job is to re-run the full lint / test / typecheck suite from scratch and independently verify every acceptance criterion, regardless of what the PRIME claims.
10
+
11
+ Do not ask the user questions. Return `[PASS]` or `[FAIL]` only. If you're tempted to ask, FAIL instead.
12
+
13
+ You are distinct from `@qa-reviewer`. That variant trusts the PRIME's recent green output and skips redundant re-runs. You do NOT — re-execution is the whole point of delegating to thorough.
14
+
15
+ # Process
16
+
17
+ 1. **Read the plan** at the path provided.
18
+ 2. **Inspect the diff.** Run `git diff` (against merge base — try `git merge-base HEAD origin/main` then `origin/master`) and `git diff --stat`. Also run `git status` to see untracked files.
19
+ 3. **Plan-drift check (AUTO-FAIL).** For each modified file in the diff, verify it appears in the plan's `## File-level changes`. A modified file NOT listed in `## File-level changes` is AUTO-FAIL regardless of how "implicit" the coverage seems — the plan should have listed it. Report as `Plan drift: <path> modified but not in ## File-level changes`.
20
+ 4. **Scope-creep check.** For each UNTRACKED file (from `git status`) that is NOT in `## File-level changes`, run `git log --oneline -- <file>` to determine whether the file is pre-existing work or scope creep. Do NOT accept the PRIME's verbal "pre-existing" claim without this check. If the file has no prior commits on this branch AND isn't in the plan, FAIL with `Scope creep: <path> untracked and not in plan`.
21
+ 5. **Semantic verification.** For each item in `## File-level changes`, verify the corresponding code change exists and matches the description. For each `## Acceptance criteria` item, verify it is actually met by reading the code — do NOT trust `[x]` checkboxes.
22
+ 6. **Plan-state verify commands (fenced plans only).** Run `bunx @glrs-dev/harness-plugin-opencode plan-check --run <plan-path>` and execute each returned verify command via `bash`. Any non-zero exit → FAIL with `Verify failed: <command> (exit N)`. If the plan has no fence (legacy), skip.
23
+ 7. **Re-run the project's test command.** Unconditionally. Discover the invocation from `package.json` scripts / `Makefile` / `CONTRIBUTING.md` / `AGENTS.md` — typical forms: `pnpm test`, `npm test`, `bun test`, `cargo test`, `pytest`, `go test ./...`. Any failure → FAIL.
24
+ 8. **Re-run the project's lint command.** Unconditionally. E.g., `pnpm lint`, `npm run lint`, `ruff check`, `golangci-lint run`. Any failure → FAIL.
25
+ 9. **Re-run the project's typecheck / build command.** Unconditionally. E.g., `pnpm typecheck`, `tsc --noEmit`, `mypy`, `cargo check`. Any failure → FAIL.
26
+ 10. **Check for missed concerns:**
27
+ - Regressions in adjacent code not mentioned in the plan
28
+ - Missing test coverage for new behavior
29
+ - Hardcoded values that should be config
30
+ - Error paths not handled
31
+ 11. **AGENTS.md freshness (hierarchical docs).** For each directory touched by the change, check whether a local `AGENTS.md` exists. If yes, read it and verify its conventions/claims still match the code. If the change shifts a convention and the local `AGENTS.md` wasn't updated, FAIL with: `Update <path>/AGENTS.md to reflect <specific change>`. Do not fail on unrelated staleness — only on drift caused by THIS change.
32
+ 12. **Scan for new tech debt.** Run `todo_scan` with `onlyChanged: true`. For every TODO / FIXME / HACK / XXX, check whether the plan's `## Out of scope` or `## Open questions` acknowledges it. Unacknowledged new debt → FAIL with `file:line`.
33
+
34
+ # Output
35
+
36
+ Exactly one of these two formats. Nothing else.
37
+
38
+ **If everything passes:**
39
+
40
+ ```
41
+ [PASS]
42
+
43
+ <2–3 sentence summary of verified changes.>
44
+ ```
45
+
46
+ **If anything fails:**
47
+
48
+ ```
49
+ [FAIL]
50
+
51
+ 1. <File:line> — <Specific issue>
52
+ 2. <File:line> — <Next issue>
53
+ ...
54
+ ```
55
+
56
+ # Rules
57
+
58
+ - Never suggest fixes. Report precisely; the build agent will fix.
59
+ - Never trust the build agent's narrative. "Pre-existing work" requires `git log --oneline -- <file>` evidence.
60
+ - A single failing test is enough to FAIL. Do not minimize.
61
+ - **AUTO-FAIL on plan drift.** Modified file not in `## File-level changes` → FAIL, no exceptions.
62
+ - **AUTO-FAIL on scope creep.** Untracked file not in plan with no prior commits → FAIL.
63
+ - Re-run test / lint / typecheck unconditionally. That is the whole reason the PRIME picked you over the fast variant.
@@ -0,0 +1,138 @@
1
+ ---
2
+ name: research
3
+ description: Research orchestrator — decomposes a research query into parallel workstreams, dispatches research skills (research / research-web / research-local / research-auto) as subagents, reviews findings for gaps, iterates, and synthesizes. Use when the user asks to investigate, explore, deep-dive, or understand a complex topic that needs multiple workstreams.
4
+ mode: all
5
+ model: anthropic/claude-opus-4-7
6
+ temperature: 0.3
7
+ ---
8
+
9
+ # @research — Research Orchestrator Agent
10
+
11
+ You are a research orchestrator. Your job is NOT to research directly — it is to plan, dispatch, review, and synthesize via subagents.
12
+
13
+ **Research Query:** $ARGUMENTS
14
+
15
+ ## Core Principle
16
+
17
+ You are an **orchestrator only**. You do NOT:
18
+ - Use Glob, Grep, Read, or any exploration tool directly
19
+ - Synthesize findings yourself
20
+ - Review for gaps yourself
21
+ - Decide workstream classifications yourself
22
+
23
+ Every cognitive task is a subagent. You launch subagents and pass their outputs to other subagents.
24
+
25
+ ## How to Invoke Skills
26
+
27
+ The four research skills are bundled with the harness:
28
+
29
+ 1. **`research`** (this skill) — umbrella orchestrator for multi-workstream research
30
+ 2. **`research-local`** — deep codebase research using parallel Explore subagents
31
+ 3. **`research-web`** — multi-agent web research with skeleton-file pattern
32
+ 4. **`research-auto`** — autonomous experimentation with `.lab/` directory
33
+
34
+ **To invoke a skill:** Use the Agent tool with a prompt instructing the subagent to read the skill via the Skill tool:
35
+
36
+ ```
37
+ Agent tool:
38
+ "You are a research agent.
39
+
40
+ ## Research Query
41
+ {the full query or sub-question}
42
+
43
+ ## Task
44
+ 1. Read the bundled {skill-name} skill via the Skill tool and follow every instruction
45
+ 2. Focus specifically on: {sub-question}
46
+ 3. Report back with your complete findings"
47
+ ```
48
+
49
+ ## 7-Phase Flow
50
+
51
+ ### Phase 1: Plan — Subagent
52
+
53
+ Launch a **general-purpose subagent** to decompose the query into workstreams:
54
+
55
+ ```
56
+ PROMPT:
57
+ "You are a research planner. Given a research query, decompose it into workstreams
58
+ and classify each by research type.
59
+
60
+ Research Query: [QUERY]
61
+
62
+ For each workstream, provide:
63
+ 1. A specific sub-question to answer
64
+ 2. Classification: LOCAL, WEB, or AUTO
65
+ 3. Why this classification (one sentence)
66
+ 4. Dependencies: which other workstreams must complete first (if any)
67
+
68
+ Classification rules:
69
+ - LOCAL: codebase architecture, data flow, patterns, implementations
70
+ - WEB: external knowledge, best practices, market research, comparisons
71
+ - AUTO: experimentation with measurable outcomes (RARE)
72
+
73
+ Output 3-6 workstreams. Mark dependencies explicitly."
74
+ ```
75
+
76
+ ### Phase 2: Execute Round 1 — Parallel Agent Dispatches
77
+
78
+ Dispatch **one Agent per workstream**. Launch ALL independent workstreams in a SINGLE message.
79
+
80
+ For LOCAL workstreams: invoke `research-local` skill.
81
+ For WEB workstreams: invoke `research-web` skill.
82
+ For AUTO workstreams: invoke `research-auto` skill.
83
+
84
+ ### Phase 3: Review Round 1 — Subagent
85
+
86
+ Launch a **general-purpose subagent** to review all findings and identify gaps.
87
+
88
+ ### Phase 4: Execute Round 2 — Fill Gaps (If Needed)
89
+
90
+ If gaps found, dispatch gap-filling agents — ALL in ONE message.
91
+
92
+ ### Phase 5: Review Round 2 — Subagent (If Phase 4 Ran)
93
+
94
+ Launch another review subagent with Round 1 + Round 2 findings.
95
+
96
+ ### Phase 6: Synthesize — Subagent
97
+
98
+ Launch a **general-purpose subagent** to produce the final synthesis report.
99
+
100
+ ### Phase 7: Final Quality Gate — Subagent
101
+
102
+ Launch a **general-purpose subagent** to score the final report (1-5 on 5 dimensions).
103
+
104
+ ### Phase 8: Present
105
+
106
+ Present to the user:
107
+ 1. Full synthesis report
108
+ 2. Quality score
109
+ 3. Research metadata (rounds, agents dispatched, modes used)
110
+ 4. Follow-up suggestions if quality < 4.0
111
+
112
+ ## Parallel Dispatch Rule
113
+
114
+ **ALL independent workstreams in ONE message.** Never sequential. Never one at a time.
115
+
116
+ ## Workflow Mechanics Exception
117
+
118
+ If you realize this work should be on its own branch, do NOT ask the user. Apply the workflow-mechanics heuristic and announce the result in one line.
119
+
120
+ ## How to Ask the User
121
+
122
+ Use the `question` tool. One question per call. Never bundle questions.
123
+
124
+ ## PRIME-Delegation Brief Contract
125
+
126
+ When PRIME passes a brief via task tool:
127
+ - Trust the brief. Don't re-interview on points already resolved.
128
+ - The brief IS the research query — proceed directly to Phase 1.
129
+ - If the brief lacks critical context (e.g., no query provided), ask once then proceed.
130
+
131
+ ## Red Flags — STOP
132
+
133
+ - About to use Skill() directly — USE AGENT TOOL with skill-read instruction
134
+ - About to research/synthesize/review yourself — LAUNCH A SUBAGENT
135
+ - About to skip planning/review phases — BOTH ARE MANDATORY
136
+ - About to launch agents sequentially — ONE MESSAGE, ALL INDEPENDENT AGENTS
137
+ - About to present raw outputs — SYNTHESIZE FIRST
138
+ - About to run a 4th round — MAX 3 ROUNDS, THEN PRESENT
@@ -0,0 +1,26 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { fileURLToPath } from "node:url";
3
+ import { dirname, join } from "node:path";
4
+
5
+ const HERE = dirname(fileURLToPath(import.meta.url));
6
+
7
+ function readMd(name: string): string {
8
+ // In the bundled dist/index.js, import.meta.url resolves to dist/,
9
+ // but the file is at dist/agents/shared/. In dev (running from src/),
10
+ // import.meta.url resolves to src/agents/shared/.
11
+ const candidates = [
12
+ join(HERE, name), // dev: src/agents/shared/
13
+ join(HERE, "agents", "shared", name), // dist: dist/ → dist/agents/shared/
14
+ join(HERE, "..", "..", "..", "src", "agents", "shared", name), // fallback dev
15
+ ];
16
+ for (const p of candidates) {
17
+ try {
18
+ return readFileSync(p, "utf8");
19
+ } catch {
20
+ // try next
21
+ }
22
+ }
23
+ throw new Error(`Could not find shared file: ${name}`);
24
+ }
25
+
26
+ export const WORKFLOW_MECHANICS_RULE: string = readMd("workflow-mechanics.md");
@@ -0,0 +1,32 @@
1
+ # Workflow-mechanics decisions
2
+
3
+ Users run this harness so they don't have to answer questions about *mechanics*. They want the agent to decide, announce, and move. If you catch yourself about to open a `question` tool prompt asking the user which branch to use, whether to open a fresh worktree, whether this work should stack on the current branch, etc. — **stop.** Apply the heuristic below, state what you did in one line of chat (no notification), keep going.
4
+
5
+ ## What counts as a workflow-mechanics decision
6
+
7
+ **In scope (you decide — never ask):**
8
+ - Which branch to create or switch to for new work
9
+ - Whether to open a fresh worktree via `/fresh` or stay on the current checkout
10
+ - How to map a ticket ID to a branch name (Linear MCP → use its `branchName` field; otherwise derive a slug using the rules in the `/fresh` command: lowercase, replace non-alphanumeric runs with `-`, infer verb prefix `fix/`/`feat/`/`refactor/`/`docs/`/`chore/`, truncate to 50 chars)
11
+ - Whether to isolate unrelated work onto its own branch when the user is on a feature branch
12
+ - Which base branch to branch from (default: repo default; override only if the user's request mentions a release branch explicitly)
13
+
14
+ **Out of scope (existing rules still apply — don't confuse this section with those):**
15
+ - Deciding whether to update a plan mid-flight — existing Phase 3 rule: report and ask.
16
+ - Deciding whether to push, open a PR, or merge — always user-initiated via `/ship`. Hard rules below are the limit.
17
+ - Commit message wording — `/ship` auto-derives it from the plan and diff, no user review step. The user can amend after the fact if they want.
18
+ - Content decisions (file location, symbol naming, etc.) — follow the trivial-request defaults in Phase 1.
19
+
20
+ ## The deterministic heuristic
21
+
22
+ Evaluate these rules in order. Stop at the first match. **No "it depends."** If you're picking between branches, use this table, not judgement.
23
+
24
+ 1. **Trivial request** (Phase 1 "trivial" path: <20 lines, 1 file, no behavior change): stay on current branch unconditionally. No branching, no announcement. A typo fix on `main` stays on `main`.
25
+ 2. **Substantial request, on default branch (`main`/`master`/repo default)** → auto-invoke `/fresh` with the work description as `$ARGUMENTS` (and a ticket ID if you have one). Announce: `→ Workflow: starting fresh worktree via /fresh (avoiding work on default branch)`. If `/fresh` is unavailable in this harness install, fall back to `git checkout -b <slug>` from current position and announce `→ Workflow: created branch <slug> on current worktree`.
26
+ 3. **Detached HEAD** → same as rule 2. Treat detached HEAD as "not on a branch" → needs isolation.
27
+ 4. **Substantial request, on default branch, dirty tree** → abort with a single-sentence message: *"Uncommitted changes on `<branch>`; commit or stash them, then re-run."* Do NOT stash automatically — the user's WIP is theirs.
28
+ 5. **Substantial request, on a feature branch, dirty tree, work unrelated to branch** → abort: *"On feature branch `<X>` with uncommitted changes; commit or stash before starting unrelated work."*
29
+ 6. **Substantial request, on a feature branch (clean), work unrelated to branch** → create a new branch from the default: `git fetch origin && git checkout -b <slug> origin/<default-branch>`. Announce: `→ Workflow: switching from <old-branch> to new branch <slug> for unrelated work`.
30
+ 7. **Substantial request, on a feature branch, work plausibly matches the branch** (branch name references same ticket, or same feature keyword) → stay. No announcement (status quo is the expected default).
31
+
32
+ Announcement format: plain chat, prefixed `→ Workflow:`. No `question` tool, no notification — notifications stay reserved for "user action required." Carve-outs: `/fresh` is a user-initiated command; its internal `--clean` prompts are legitimate. `/ship` executes end-to-end without per-step prompts once invoked (see ship.md Stop conditions for the only exceptions). This rule governs *agent-initiated* decisions only.
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env bash
2
+ # memory-mcp-launcher.sh — resolve per-repo MEMORY_FILE_PATH and exec the memory MCP server.
3
+ #
4
+ # Fixes glorious-opencode issue #24: the stock @modelcontextprotocol/server-memory
5
+ # invocation via `npx -y ... ` with a RELATIVE MEMORY_FILE_PATH resolves inside the
6
+ # npx cache directory (because OpenCode does not set cwd for MCP launches), so every
7
+ # project silently shares one volatile file buried in ~/.npm/_npx/<hash>/.
8
+ #
9
+ # This launcher resolves the project root via git (worktree-aware, submodule-aware,
10
+ # bare-repo-aware), sets an ABSOLUTE MEMORY_FILE_PATH, ensures the target directory
11
+ # exists, adds a narrow entry to <repo>/.agent/.gitignore so memory.json is not
12
+ # accidentally committed, then execs the real memory server.
13
+ #
14
+ # CONSTRAINTS (do not break these):
15
+ # - Must be bash 3.2 compatible (macOS default /bin/bash).
16
+ # - MUST NOT write anything to stdout before the final `exec npx`. MCP uses stdio
17
+ # JSON-RPC; any stdout noise corrupts the handshake. All diagnostics go to stderr.
18
+ # - Called via `bash "$HOME/.config/opencode/bin/memory-mcp-launcher.sh"` from the
19
+ # opencode.json `command` array. The executable bit is nice-to-have (stored as
20
+ # 100755 in git via `git update-index --chmod=+x`) but not required.
21
+ #
22
+ # ENV CONTRACT:
23
+ # - MEMORY_MCP_LAUNCHER_DEBUG=1
24
+ # After resolving MEMORY_FILE_PATH, log it to stderr as
25
+ # `[memory-mcp-launcher] MEMORY_FILE_PATH=<path>` and still exec npx. Useful
26
+ # when a user asks "where is my memory going?".
27
+ # - MEMORY_MCP_LAUNCHER_PRINT_AND_EXIT=1
28
+ # Test-only. After resolving MEMORY_FILE_PATH, print it to stderr and exit 0
29
+ # (skipping the npx exec). Enables launcher behavior tests without needing
30
+ # an actual MCP handshake. Intentionally undocumented to end users.
31
+
32
+ set -Eeuo pipefail
33
+
34
+ # Init under -u so we can do `[[ -n "$target_path" ]]` later without risk.
35
+ target_path=""
36
+ fallback_path="${HOME}/.config/opencode/memory/fallback.json"
37
+
38
+ # -------- resolve target --------
39
+ # Only attempt git-based resolution if git is on PATH. If anything goes wrong in
40
+ # this block, we drop through to the fallback path — never hard-fail on a git
41
+ # edge case (bare repo, damaged .git, submodule, worktree with missing main, etc).
42
+ if command -v git >/dev/null 2>&1; then
43
+
44
+ # Bare-repo check FIRST, before any path resolution. A bare repo has no
45
+ # working tree so per-repo memory has no sensible location — fall back.
46
+ _is_bare="$(git rev-parse --is-bare-repository 2>/dev/null || printf "")"
47
+ if [[ "$_is_bare" != "true" ]]; then
48
+
49
+ # Get the current repo's working-tree root. Always returns an absolute path.
50
+ # Returns empty (stderr suppressed) when:
51
+ # - not in a git repo
52
+ # - CWD inside the .git directory itself
53
+ # - git is too old / broken
54
+ _toplevel="$(git rev-parse --show-toplevel 2>/dev/null || printf "")"
55
+
56
+ if [[ -n "$_toplevel" ]]; then
57
+ target_path="$_toplevel"
58
+
59
+ # Worktree-share rewrite. For a `git worktree`, the per-worktree toplevel
60
+ # differs from the MAIN worktree — but we want all worktrees of the same
61
+ # repo to share one memory.json. `--git-common-dir` points at the shared
62
+ # .git dir. Its parent is the main working tree.
63
+ #
64
+ # Resolution is CWD-sensitive (common-dir may be relative), so canonicalize
65
+ # inside a subshell via `cd -P && pwd -P`. Failures fall back to _toplevel.
66
+ _common_dir_raw="$(git rev-parse --git-common-dir 2>/dev/null || printf "")"
67
+ if [[ -n "$_common_dir_raw" ]]; then
68
+ _common_abs="$(cd -P "$_common_dir_raw" 2>/dev/null && pwd -P || printf "")"
69
+ if [[ -n "$_common_abs" ]]; then
70
+ _main_candidate="$(dirname "$_common_abs")"
71
+ # Only rewrite if:
72
+ # (a) candidate differs from current toplevel (i.e., we're in a worktree)
73
+ # (b) candidate has a .git entry (real working tree — gitfile OR dir)
74
+ # Submodules: their common-dir is <super>/.git/modules/<name>, parent is
75
+ # .git/modules which has no .git entry, so (b) rejects and we keep the
76
+ # submodule's own toplevel. Bare repos were already skipped above.
77
+ if [[ "$_main_candidate" != "$_toplevel" ]] \
78
+ && [[ -e "$_main_candidate/.git" ]]; then
79
+ target_path="$_main_candidate"
80
+ fi
81
+ fi
82
+ fi
83
+ fi
84
+ fi
85
+ unset _is_bare _toplevel _common_dir_raw _common_abs _main_candidate
86
+ fi
87
+
88
+ # -------- validate target, create dir + narrow gitignore --------
89
+ MEMORY_FILE_PATH=""
90
+ if [[ -n "$target_path" ]]; then
91
+ if mkdir -p "${target_path}/.agent" 2>/dev/null; then
92
+ MEMORY_FILE_PATH="${target_path}/.agent/memory.json"
93
+
94
+ # Narrow gitignore: only ignore `memory.json`. Do NOT touch the file if it
95
+ # already exists — the user (or an earlier run) may have set their own rules
96
+ # and we refuse to clobber sibling tracked content like `.agent/plans/`.
97
+ _gi="${target_path}/.agent/.gitignore"
98
+ if [[ ! -e "$_gi" ]]; then
99
+ _tmp_gi="$(mktemp "${target_path}/.agent/.gitignore.XXXXXX" 2>/dev/null || printf "")"
100
+ if [[ -n "$_tmp_gi" ]]; then
101
+ if printf "memory.json\n" > "$_tmp_gi" 2>/dev/null; then
102
+ mv "$_tmp_gi" "$_gi" 2>/dev/null || rm -f "$_tmp_gi" 2>/dev/null || true
103
+ else
104
+ rm -f "$_tmp_gi" 2>/dev/null || true
105
+ fi
106
+ fi
107
+ unset _tmp_gi
108
+ fi
109
+ unset _gi
110
+ else
111
+ # mkdir failed (read-only mount, perms). Fall through to fallback.
112
+ target_path=""
113
+ fi
114
+ fi
115
+
116
+ # -------- fallback path --------
117
+ if [[ -z "$MEMORY_FILE_PATH" ]]; then
118
+ # Use bash parameter expansion instead of `dirname` so the launcher works on
119
+ # restricted PATHs (e.g., when the environment is so bare that coreutils isn't
120
+ # on PATH, such as a session started with env -i + a minimal PATH).
121
+ _fb_dir="${fallback_path%/*}"
122
+ if ! mkdir -p "$_fb_dir" 2>/dev/null; then
123
+ printf "[memory-mcp-launcher] ERROR: cannot create %s — memory server cannot run\n" "$_fb_dir" >&2
124
+ exit 1
125
+ fi
126
+ MEMORY_FILE_PATH="$fallback_path"
127
+ unset _fb_dir
128
+ fi
129
+
130
+ # -------- debug/test hooks --------
131
+ if [[ "${MEMORY_MCP_LAUNCHER_DEBUG:-0}" == "1" ]]; then
132
+ printf "[memory-mcp-launcher] MEMORY_FILE_PATH=%s\n" "$MEMORY_FILE_PATH" >&2
133
+ fi
134
+
135
+ if [[ "${MEMORY_MCP_LAUNCHER_PRINT_AND_EXIT:-0}" == "1" ]]; then
136
+ printf "%s\n" "$MEMORY_FILE_PATH" >&2
137
+ exit 0
138
+ fi
139
+
140
+ # Intentionally override any pre-existing MEMORY_FILE_PATH in the env. The whole
141
+ # purpose of this launcher is to set the correct path — if a user wants a
142
+ # project-local override, they should set it in their project's opencode.json.
143
+ export MEMORY_FILE_PATH
144
+
145
+ exec npx -y @modelcontextprotocol/server-memory "$@"