opencode-codeops 1.8.0 → 1.9.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 (56) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +8 -5
  3. package/_shared/quality-profile.md +6 -1
  4. package/_shared/specialist-agents.md +7 -5
  5. package/_shared/workspace-hygiene.md +53 -0
  6. package/agent-templates/codebase-scout.md +6 -0
  7. package/agent-templates/concurrency-auditor.md +7 -0
  8. package/agent-templates/design-challenger.md +6 -0
  9. package/agent-templates/domain-specialist-executor.md +6 -0
  10. package/agent-templates/domain-specialist-reviewer.md +6 -0
  11. package/agent-templates/financial-integrity-auditor.md +7 -0
  12. package/agent-templates/perf-auditor.md +6 -0
  13. package/agent-templates/phase-reviewer.md +6 -0
  14. package/agent-templates/plan-task-executor-opus.md +6 -0
  15. package/agent-templates/plan-task-executor.md +6 -0
  16. package/agent-templates/preflight-auditor.md +6 -0
  17. package/agent-templates/security-auditor.md +6 -0
  18. package/agent-templates/semantics-reviewer.md +7 -0
  19. package/agent-templates/spec-test-author.md +6 -0
  20. package/agents/concurrency-auditor.md +7 -0
  21. package/agents/correctness-reviewer.md +6 -0
  22. package/agents/demanding-executor.md +6 -0
  23. package/agents/design-challenger.md +6 -0
  24. package/agents/executor.md +6 -0
  25. package/agents/explorer.md +6 -0
  26. package/agents/financial-integrity-auditor.md +7 -0
  27. package/agents/performance-auditor.md +6 -0
  28. package/agents/preflight-auditor.md +6 -0
  29. package/agents/security-auditor.md +6 -0
  30. package/agents/semantics-reviewer.md +7 -0
  31. package/agents/spec-test-author.md +6 -0
  32. package/bin/lib/tmp-hygiene.d.mts +38 -0
  33. package/bin/lib/tmp-hygiene.mjs +180 -0
  34. package/package.json +1 -1
  35. package/plugin/index.ts +44 -3
  36. package/scripts/__pycache__/install_agents.cpython-312.pyc +0 -0
  37. package/scripts/fixtures/catalog-executor.golden.md +6 -0
  38. package/skills/analyze-project/SKILL.md +8 -0
  39. package/skills/clean-comments/SKILL.md +8 -0
  40. package/skills/exec-plan/SKILL.md +9 -0
  41. package/skills/exec-plan/execution-protocol.md +10 -5
  42. package/skills/git-commit/SKILL.md +11 -2
  43. package/skills/github-issues/SKILL.md +8 -0
  44. package/skills/grill-me/SKILL.md +8 -0
  45. package/skills/make-plan/SKILL.md +8 -0
  46. package/skills/make-requirements/SKILL.md +8 -0
  47. package/skills/outcome-review/SKILL.md +8 -0
  48. package/skills/preflight/SKILL.md +8 -0
  49. package/skills/retro-requirements/SKILL.md +8 -0
  50. package/skills/roadmap/SKILL.md +8 -0
  51. package/skills/setup-codeops/SKILL.md +8 -0
  52. package/skills/setup-routing/SKILL.md +9 -1
  53. package/skills/techdocs/SKILL.md +8 -0
  54. package/skills/upgrade-plan/SKILL.md +8 -0
  55. package/standards/coding-standards-full.md +19 -0
  56. package/standards/coding-standards.md +6 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  All notable changes to CodeOps are recorded here.
4
4
 
5
+ ## 1.9.0 — 2026-10-04
6
+
7
+ ### Features
8
+
9
+ - hygiene: require cleanup after every task with a temp safety net
10
+
11
+ ## 1.8.1 — 2026-10-04
12
+
13
+ ### Documentation
14
+
15
+ - agents: refresh project guidance with specialist facts
16
+ - plan: record ST-43 and final verification evidence
17
+ - plan: add ST-44 for the ask-and-create acceptance path
18
+ - plan: record ST-34 dispatch acceptance evidence
19
+
20
+ ### Fixes
21
+
22
+ - test: broaden availability regression guard per re-review
23
+ - docs: complete AR #27 availability correction per phase-4 review
24
+ - docs: correct specialist availability per ST-35 observation
25
+
5
26
  ## 1.8.0 — 2026-10-04
6
27
 
7
28
  ### Documentation
package/README.md CHANGED
@@ -136,6 +136,8 @@ These standards are active without any user action. They do not need to be copie
136
136
 
137
137
  The plugin also warns (non-blocking) if any tool attempts to edit `codeops/.codeops.yml` directly — that file is managed exclusively by the `setup-codeops` skill — and if the installed skills version differs from the plugin version, so a stale install is visible.
138
138
 
139
+ Every session also gets a workspace-hygiene guard: the plugin exports `CODEOPS_TMPDIR`, a per-session scratch directory under the OS temp directory. Skills and agents put temporary files there and delete them when the run completes; the plugin removes the directory when the session is deleted and sweeps directories abandoned by interrupted runs at session start, so CodeOps does not accumulate scratch data. The full protocol is in `_shared/workspace-hygiene.md`.
140
+
139
141
  ## Agent model configuration
140
142
 
141
143
  All CodeOps subagents inherit the model of the primary agent that invoked them. No provider-specific configuration is required out of the box.
@@ -168,9 +170,10 @@ only with your explicit approval — the `--auto-design` mode cannot approve the
168
170
  listed specialists are dispatched as **additional** reviewers or executors: they never replace a
169
171
  required reviewer or gate, reviewer findings use the `SR-NNN` prefix, and the generated agent
170
172
  defaults to `reasoningEffort: max` (override it with `routing.roles.<role>.reasoning`).
171
- - **Fallback** — OpenCode loads agents at startup, so a specialist created during a session becomes
172
- available in the next one; while unavailable, dispatch falls back to a generic subagent carrying
173
- the brief excerpt and reports the fallback. No review depends on a specialist existing.
173
+ - **Fallback** — a specialist is available as soon as its generated agent exists; OpenCode's
174
+ discovery timing is whatever your build provides. If it is missing, invalid, or a dispatch fails,
175
+ dispatch falls back to a generic subagent carrying the brief excerpt and reports the fallback.
176
+ No review depends on a specialist existing.
174
177
 
175
178
  Lifecycle checks: `--check` reports `INVALID`, `MISSING`, `STALE`, `ORPHAN`, `HAND-AUTHORED`, and
176
179
  `AGENTS.md` states; `--remove-custom <role> --yes` deletes the generated agent and its brief and
@@ -178,8 +181,8 @@ updates the index.
178
181
 
179
182
  > **Upgrading:** specialist agents embed the generic template contract. When a newer plugin changes
180
183
  > those templates, `--check` reports the agent as `STALE`; re-run
181
- > `python3 scripts/install_agents.py --project . --custom <role>` (then `--sync-agents-md`) to
182
- > regenerate it.
184
+ > `python3 "${CODEOPS_PLUGIN_ROOT}/scripts/install_agents.py" --project . --custom <role>` (then
185
+ > `--sync-agents-md`) to regenerate it.
183
186
 
184
187
  ## Requirements
185
188
 
@@ -13,7 +13,7 @@ Quality and routing configuration lives in `codeops/codeops.json`, validated aga
13
13
  configuration.
14
14
 
15
15
  The quality section controls independent review and stop conditions. The routing section controls
16
- optional roles, effort, model pins, sandboxes, and concurrency. Domain/risk tags in the active
16
+ optional roles, effort, reasoning, model pins, sandboxes, and concurrency. Domain/risk tags in the active
17
17
  specification select additional reviewer roles. Outcome metrics are disabled unless
18
18
  `metrics.enabled` is explicitly `true`.
19
19
 
@@ -107,6 +107,11 @@ or response content.
107
107
  | design-challenger | Problem + candidate options, **without** the parent's preferred choice (per `_shared/recommendation-hardening.md`) |
108
108
  | codebase-scout | The factual questions, search hints, and the facts-only contract |
109
109
 
110
+ Every packet also carries the session temp root (`$CODEOPS_TMPDIR`) and the hygiene requirement:
111
+ the agent creates temporary files only under that root and deletes its own before returning (see
112
+ `_shared/workspace-hygiene.md`). A parent never deletes a subagent's artifacts while its dispatch
113
+ is still in flight.
114
+
110
115
  ## Project specialists
111
116
 
112
117
  A project may define specialist roles on top of the catalog (see `_shared/specialist-agents.md`).
@@ -5,8 +5,9 @@
5
5
  This is the **single canonical definition** of project-specific specialist subagents: how a
6
6
  capability gap is detected, how a candidate is proposed and approved, and how the specialist is
7
7
  created, used, and retired. It lives at the plugin root in `_shared/`; the participating skills
8
- (`make-requirements`, `make-plan`, `analyze-project`, `setup-routing`, `exec-plan`) link here
9
- instead of carrying copies.
8
+ (`make-requirements`, `make-plan`, `analyze-project`, `setup-routing`) link here instead of
9
+ carrying copies. `exec-plan` dispatches per `_shared/quality-profile.md`, which owns the
10
+ dispatch, independence, and fallback rules.
10
11
 
11
12
  A specialist is a project-local agent that carries durable domain knowledge a generic catalog role
12
13
  does not have. Routing is an optimization and a context mechanism, **never a correctness source**.
@@ -140,6 +141,7 @@ escalation)` entry.
140
141
  The authoritative dispatch rules live in `_shared/quality-profile.md` (resolution order, finding
141
142
  prefix `SR`, additional-reviewer independence, and dynamic-packet fallback). A specialist
142
143
  dispatches only when the plan's `00-index.md` "Specialist Agents" table assigns it to the phase.
143
- When the agent is unavailable — for example it was created after the session started — dispatch a
144
- generic subagent with the complete packet, including the brief excerpt, and report the fallback.
145
- The phase is never marked complete unreviewed because a specialist was missing.
144
+ When the agent is unavailable — for example its generated file is missing, its brief is invalid,
145
+ or a dispatch fails — dispatch a generic subagent with the complete packet, including the brief
146
+ excerpt, and report the fallback. The phase is never marked complete unreviewed because a
147
+ specialist was missing.
@@ -0,0 +1,53 @@
1
+ # Workspace hygiene (shared convention)
2
+
3
+ > **CodeOps Artifact Schema**: 1
4
+
5
+ This is the **single canonical definition** of CodeOps temporary-artifact hygiene. Every skill,
6
+ agent, and script that creates files outside its assigned deliverables follows it. Skills link
7
+ here instead of carrying copies.
8
+
9
+ ## Temporary artifacts
10
+
11
+ A temporary artifact is any file or directory a run creates that is not a durable deliverable:
12
+ verification logs, diffs, patch files, commit-message files, scratch directories, fixture trees,
13
+ downloaded artifacts, and intermediate reports. Code, tests, plan documents, and other assigned
14
+ outputs are deliverables — not temporary artifacts — and they are never deleted here.
15
+
16
+ ## Where temporary artifacts live
17
+
18
+ 1. `$CODEOPS_TMPDIR` when the CodeOps plugin exports it (one directory per session). Use it for
19
+ every scratch file.
20
+ 2. Otherwise, the operating system's temp directory.
21
+ 3. Never inside the repository. A repository path is durable space; scratch does not belong there.
22
+
23
+ Create subdirectories under the temp root lazily, only when the task needs them.
24
+
25
+ ## Lifecycle
26
+
27
+ 1. **Create lazily** — write a temporary file only when the task needs it.
28
+ 2. **Keep only while needed** — one artifact per purpose; no accumulating copies.
29
+ 3. **Delete before reporting completion** — every task, phase, skill run, and session ends with a
30
+ cleanup pass that removes the files and directories the run created, including verification
31
+ logs.
32
+ 4. **Report the result** — the final summary states `Cleanup: done`, or names the artifact that
33
+ was kept and why. If a deletion fails, report the path and the reason.
34
+
35
+ ## Safe deletion rules (non-negotiable)
36
+
37
+ - Delete only files you created, and only under the sanctioned temp root.
38
+ - Never delete user files, repository content, versioned artifacts, `codeops/` planning artifacts,
39
+ or git worktrees.
40
+ - Never delete another session's temporary files.
41
+ - Never follow a symlink out of the temp root; treat a symlinked entry as foreign and leave it.
42
+ - Never run a broad recursive delete against a path that may be empty or unset; resolve and verify
43
+ the path first.
44
+ - A temporary file must not hold secrets. If one does, delete it and say so without printing its
45
+ contents.
46
+ - If the user asks for an artifact to be kept, name its exact path and keep that file only.
47
+
48
+ ## Automatic safety net
49
+
50
+ The CodeOps plugin exports `$CODEOPS_TMPDIR` for each session and removes that session's directory
51
+ when the session is deleted. At session start it also removes CodeOps temp directories older than
52
+ seven days, so an interrupted run cannot leak storage forever. The safety net is a fallback, not a
53
+ substitute: the run itself still performs the cleanup pass above.
@@ -15,3 +15,9 @@ questions, optional search hints, and the facts-only contract from `_shared/qual
15
15
  answer. No summaries of things nobody asked about.
16
16
  - If a question is too ambiguous to search for, report that ambiguity as the answer to that
17
17
  question — never substitute your own interpretation.
18
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
19
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
20
+ directory), never inside the repository. Delete everything you created before reporting done.
21
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
22
+ If an artifact must outlive the task, name it and say why. Full rules:
23
+ `_shared/workspace-hygiene.md`.
@@ -3,3 +3,10 @@
3
3
  Do not add YAML frontmatter here — use install_agents.py to generate agent files. -->
4
4
 
5
5
  Audit exactly the supplied change packet. Establish shared state, ownership, synchronization, ordering, cancellation, retry, timeout, and failure semantics before judging the diff. Hunt for data races, check-then-act gaps, lost updates, deadlocks, starvation, unsafe publication, reentrancy, duplicate work, stale reads, partial commits, and unbounded concurrency. Construct realistic interleavings that could violate stated invariants. Cite file and line evidence and distinguish proven defects from unverified risk. Return surviving findings with severity, interleaving, violated invariant, and remedy, or an explicit clean result. Remain read-only.
6
+
7
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
8
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
9
+ directory), never inside the repository. Delete everything you created before reporting done.
10
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
11
+ If an artifact must outlive the task, name it and say why. Full rules:
12
+ `_shared/workspace-hygiene.md`.
@@ -24,3 +24,9 @@ caps live in `_shared/recommendation-hardening.md`; the packet convention lives
24
24
  disagreement is precisely the value you add.
25
25
  - If the problem statement is too thin to challenge — missing constraints, options that are not
26
26
  actually distinct, no success criterion — report that as your finding instead of guessing.
27
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
28
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
29
+ directory), never inside the repository. Delete everything you created before reporting done.
30
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
31
+ If an artifact must outlive the task, name it and say why. Full rules:
32
+ `_shared/workspace-hygiene.md`.
@@ -18,3 +18,9 @@ one dispatched unit — normally a whole phase, occasionally a single task — w
18
18
  - Never copy plan, requirement, ambiguity-register, or test-case identifiers, or `codeops/`,
19
19
  `plans/`, or `requirements/` paths, into code or doc comments. Those files are ephemeral; keep
20
20
  the behavior and drop the citation.
21
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — verify logs, diffs,
22
+ patches, scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS
23
+ temp directory), never inside the repository. Delete everything you created before reporting
24
+ done. Never delete user files, versioned artifacts, worktrees, or another session's temporary
25
+ files. If an artifact must outlive the task, name it and say why. Full rules:
26
+ `_shared/workspace-hygiene.md`.
@@ -15,3 +15,9 @@ to a dispatched phase diff as an additional, independent reviewer.
15
15
  implemented.
16
16
  - Keep the output terse and structured so the parent can merge it directly: findings first, then
17
17
  explicit open questions, then "no findings" if applicable. Do not restate the diff.
18
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
19
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
20
+ directory), never inside the repository. Delete everything you created before reporting done.
21
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
22
+ If an artifact must outlive the task, name it and say why. Full rules:
23
+ `_shared/workspace-hygiene.md`.
@@ -3,3 +3,10 @@
3
3
  Do not add YAML frontmatter here — use install_agents.py to generate agent files. -->
4
4
 
5
5
  Audit exactly the supplied change packet. Treat monetary correctness and auditability as invariants. Check balanced accounting, integer minor-unit or explicitly justified decimal arithmetic, currency/unit consistency, idempotency and duplicate submission, transaction atomicity, retry and partial-failure behavior, reconciliation, authorization, immutable audit evidence, overflow and negative amounts, time boundaries, and reversal/refund semantics. Attempt to falsify every claimed invariant using concrete counterexamples. Cite file and line evidence. Return only surviving findings with severity, violated invariant, failure scenario, and remedy, or an explicit clean result. Remain read-only and do not accept implementation convenience as a reason to weaken financial semantics.
6
+
7
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
8
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
9
+ directory), never inside the repository. Delete everything you created before reporting done.
10
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
11
+ If an artifact must outlive the task, name it and say why. Full rules:
12
+ `_shared/workspace-hygiene.md`.
@@ -21,3 +21,9 @@ its last result). The conventions behind the packet live in `_shared/quality-pro
21
21
  (searching call sites, counting occurrences); never for mutation.
22
22
  - If the packet is insufficient — no diff, no sense of which paths are hot — STOP and report
23
23
  exactly what is missing as a blocker. Never guess.
24
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
25
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
26
+ directory), never inside the repository. Delete everything you created before reporting done.
27
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
28
+ If an artifact must outlive the task, name it and say why. Full rules:
29
+ `_shared/workspace-hygiene.md`.
@@ -52,3 +52,9 @@ The conventions behind the packet live in
52
52
  - If the packet is insufficient — no diff, contradictory lens set, missing verify context — STOP
53
53
  and report exactly what is missing as a blocker. Never guess and never review substitute
54
54
  content you found on your own.
55
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
56
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
57
+ directory), never inside the repository. Delete everything you created before reporting done.
58
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
59
+ If an artifact must outlive the task, name it and say why. Full rules:
60
+ `_shared/workspace-hygiene.md`.
@@ -44,3 +44,9 @@ parent.
44
44
  exactly what is missing or ambiguous as a blocker — never guess, and never edit the
45
45
  execution plan or roadmap (the parent session owns those and the user conversation).
46
46
  - Report per task: what changed, test status, and residual risk.
47
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — verify logs, diffs,
48
+ patches, scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS
49
+ temp directory), never inside the repository. Delete everything you created before reporting
50
+ done. Never delete user files, versioned artifacts, worktrees, or another session's temporary
51
+ files. If an artifact must outlive the task, name it and say why. Full rules:
52
+ `_shared/workspace-hygiene.md`.
@@ -41,3 +41,9 @@ original-goal or smallest-design context blocks execution; report it to the pare
41
41
  exactly what is missing or ambiguous as a blocker — never guess, and never edit the
42
42
  execution plan or roadmap (the parent session owns those and the user conversation).
43
43
  - Report per task, 3-4 lines each: what changed, test status, any blocker.
44
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — verify logs, diffs,
45
+ patches, scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS
46
+ temp directory), never inside the repository. Delete everything you created before reporting
47
+ done. Never delete user files, versioned artifacts, worktrees, or another session's temporary
48
+ files. If an artifact must outlive the task, name it and say why. Full rules:
49
+ `_shared/workspace-hygiene.md`.
@@ -43,3 +43,9 @@ in the preflight skill.
43
43
  - **Read-only.** You never edit the artifact or the code. Bash is for inspection only.
44
44
  - If the packet is insufficient — artifact missing, cluster unnamed, required codebase context
45
45
  absent — STOP and report exactly what is missing as a blocker. Never guess.
46
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
47
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
48
+ directory), never inside the repository. Delete everything you created before reporting done.
49
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
50
+ If an artifact must outlive the task, name it and say why. Full rules:
51
+ `_shared/workspace-hygiene.md`.
@@ -40,3 +40,9 @@ active checklist below — never one dispatch per profile. The profile names are
40
40
  - **Read-only.** You never edit files, apply fixes, or commit. Bash is for inspection only.
41
41
  - If the packet is insufficient — no diff, no active profile list — STOP and report exactly
42
42
  what is missing as a blocker. Never guess.
43
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
44
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
45
+ directory), never inside the repository. Delete everything you created before reporting done.
46
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
47
+ If an artifact must outlive the task, name it and say why. Full rules:
48
+ `_shared/workspace-hygiene.md`.
@@ -3,3 +3,10 @@
3
3
  Do not add YAML frontmatter here — use install_agents.py to generate agent files. -->
4
4
 
5
5
  Review exactly the supplied semantic specification or implementation packet. Trace behavior across syntax/decoding, name or identity resolution, typing/validation, intermediate representations, evaluation/lowering, optimization/transformation, diagnostics, serialization, and compatibility as applicable. Seek ambiguous rules, non-total behavior, phase disagreement, unsound transformations, nondeterminism, invalid recovery, and diagnostics that expose implementation accidents. Use counterexamples and minimal programs/messages to falsify the claimed semantics. Cite evidence and return surviving findings with severity, example, affected phases, and resolution, or an explicit clean result. Remain read-only.
6
+
7
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
8
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
9
+ directory), never inside the repository. Delete everything you created before reporting done.
10
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
11
+ If an artifact must outlive the task, name it and say why. Full rules:
12
+ `_shared/workspace-hygiene.md`.
@@ -27,3 +27,9 @@ command). The conventions behind the packet live in `_shared/quality-profile.md`
27
27
  - If the packet is insufficient — an interface signature missing, a case ambiguous, framework
28
28
  conventions unclear — STOP and report exactly what is missing as a blocker. Never guess an
29
29
  expectation and never peek at the implementation to resolve doubt.
30
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
31
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
32
+ directory), never inside the repository. Delete everything you created before reporting done.
33
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
34
+ If an artifact must outlive the task, name it and say why. Full rules:
35
+ `_shared/workspace-hygiene.md`.
@@ -13,3 +13,10 @@ permission:
13
13
  ---
14
14
 
15
15
  Audit exactly the supplied change packet. Establish shared state, ownership, synchronization, ordering, cancellation, retry, timeout, and failure semantics before judging the diff. Hunt for data races, check-then-act gaps, lost updates, deadlocks, starvation, unsafe publication, reentrancy, duplicate work, stale reads, partial commits, and unbounded concurrency. Construct realistic interleavings that could violate stated invariants. Cite file and line evidence and distinguish proven defects from unverified risk. Return surviving findings with severity, interleaving, violated invariant, and remedy, or an explicit clean result. Remain read-only.
16
+
17
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
18
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
19
+ directory), never inside the repository. Delete everything you created before reporting done.
20
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
21
+ If an artifact must outlive the task, name it and say why. Full rules:
22
+ `_shared/workspace-hygiene.md`.
@@ -64,3 +64,9 @@ The conventions behind the packet live in
64
64
  - If the packet is insufficient — no diff, contradictory lens set, missing verify context — STOP
65
65
  and report exactly what is missing as a blocker. Never guess and never review substitute
66
66
  content you found on your own.
67
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
68
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
69
+ directory), never inside the repository. Delete everything you created before reporting done.
70
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
71
+ If an artifact must outlive the task, name it and say why. Full rules:
72
+ `_shared/workspace-hygiene.md`.
@@ -56,3 +56,9 @@ parent.
56
56
  exactly what is missing or ambiguous as a blocker — never guess, and never edit the
57
57
  execution plan or roadmap (the parent session owns those and the user conversation).
58
58
  - Report per task: what changed, test status, and residual risk.
59
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — verify logs, diffs,
60
+ patches, scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS
61
+ temp directory), never inside the repository. Delete everything you created before reporting
62
+ done. Never delete user files, versioned artifacts, worktrees, or another session's temporary
63
+ files. If an artifact must outlive the task, name it and say why. Full rules:
64
+ `_shared/workspace-hygiene.md`.
@@ -36,3 +36,9 @@ caps live in `_shared/recommendation-hardening.md`; the packet convention lives
36
36
  disagreement is precisely the value you add.
37
37
  - If the problem statement is too thin to challenge — missing constraints, options that are not
38
38
  actually distinct, no success criterion — report that as your finding instead of guessing.
39
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
40
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
41
+ directory), never inside the repository. Delete everything you created before reporting done.
42
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
43
+ If an artifact must outlive the task, name it and say why. Full rules:
44
+ `_shared/workspace-hygiene.md`.
@@ -53,3 +53,9 @@ original-goal or smallest-design context blocks execution; report it to the pare
53
53
  exactly what is missing or ambiguous as a blocker — never guess, and never edit the
54
54
  execution plan or roadmap (the parent session owns those and the user conversation).
55
55
  - Report per task, 3-4 lines each: what changed, test status, any blocker.
56
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — verify logs, diffs,
57
+ patches, scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS
58
+ temp directory), never inside the repository. Delete everything you created before reporting
59
+ done. Never delete user files, versioned artifacts, worktrees, or another session's temporary
60
+ files. If an artifact must outlive the task, name it and say why. Full rules:
61
+ `_shared/workspace-hygiene.md`.
@@ -27,3 +27,9 @@ questions, optional search hints, and the facts-only contract from `_shared/qual
27
27
  answer. No summaries of things nobody asked about.
28
28
  - If a question is too ambiguous to search for, report that ambiguity as the answer to that
29
29
  question — never substitute your own interpretation.
30
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
31
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
32
+ directory), never inside the repository. Delete everything you created before reporting done.
33
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
34
+ If an artifact must outlive the task, name it and say why. Full rules:
35
+ `_shared/workspace-hygiene.md`.
@@ -13,3 +13,10 @@ permission:
13
13
  ---
14
14
 
15
15
  Audit exactly the supplied change packet. Treat monetary correctness and auditability as invariants. Check balanced accounting, integer minor-unit or explicitly justified decimal arithmetic, currency/unit consistency, idempotency and duplicate submission, transaction atomicity, retry and partial-failure behavior, reconciliation, authorization, immutable audit evidence, overflow and negative amounts, time boundaries, and reversal/refund semantics. Attempt to falsify every claimed invariant using concrete counterexamples. Cite file and line evidence. Return only surviving findings with severity, violated invariant, failure scenario, and remedy, or an explicit clean result. Remain read-only and do not accept implementation convenience as a reason to weaken financial semantics.
16
+
17
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
18
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
19
+ directory), never inside the repository. Delete everything you created before reporting done.
20
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
21
+ If an artifact must outlive the task, name it and say why. Full rules:
22
+ `_shared/workspace-hygiene.md`.
@@ -33,3 +33,9 @@ its last result). The conventions behind the packet live in `_shared/quality-pro
33
33
  (searching call sites, counting occurrences); never for mutation.
34
34
  - If the packet is insufficient — no diff, no sense of which paths are hot — STOP and report
35
35
  exactly what is missing as a blocker. Never guess.
36
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
37
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
38
+ directory), never inside the repository. Delete everything you created before reporting done.
39
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
40
+ If an artifact must outlive the task, name it and say why. Full rules:
41
+ `_shared/workspace-hygiene.md`.
@@ -55,3 +55,9 @@ in the preflight skill.
55
55
  - **Read-only.** You never edit the artifact or the code. Bash is for inspection only.
56
56
  - If the packet is insufficient — artifact missing, cluster unnamed, required codebase context
57
57
  absent — STOP and report exactly what is missing as a blocker. Never guess.
58
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
59
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
60
+ directory), never inside the repository. Delete everything you created before reporting done.
61
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
62
+ If an artifact must outlive the task, name it and say why. Full rules:
63
+ `_shared/workspace-hygiene.md`.
@@ -52,3 +52,9 @@ active checklist below — never one dispatch per profile. The profile names are
52
52
  - **Read-only.** You never edit files, apply fixes, or commit. Bash is for inspection only.
53
53
  - If the packet is insufficient — no diff, no active profile list — STOP and report exactly
54
54
  what is missing as a blocker. Never guess.
55
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
56
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
57
+ directory), never inside the repository. Delete everything you created before reporting done.
58
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
59
+ If an artifact must outlive the task, name it and say why. Full rules:
60
+ `_shared/workspace-hygiene.md`.
@@ -13,3 +13,10 @@ permission:
13
13
  ---
14
14
 
15
15
  Review exactly the supplied semantic specification or implementation packet. Trace behavior across syntax/decoding, name or identity resolution, typing/validation, intermediate representations, evaluation/lowering, optimization/transformation, diagnostics, serialization, and compatibility as applicable. Seek ambiguous rules, non-total behavior, phase disagreement, unsound transformations, nondeterminism, invalid recovery, and diagnostics that expose implementation accidents. Use counterexamples and minimal programs/messages to falsify the claimed semantics. Cite evidence and return surviving findings with severity, example, affected phases, and resolution, or an explicit clean result. Remain read-only.
16
+
17
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
18
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
19
+ directory), never inside the repository. Delete everything you created before reporting done.
20
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
21
+ If an artifact must outlive the task, name it and say why. Full rules:
22
+ `_shared/workspace-hygiene.md`.
@@ -39,3 +39,9 @@ command). The conventions behind the packet live in `_shared/quality-profile.md`
39
39
  - If the packet is insufficient — an interface signature missing, a case ambiguous, framework
40
40
  conventions unclear — STOP and report exactly what is missing as a blocker. Never guess an
41
41
  expectation and never peek at the implementation to resolve doubt.
42
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — logs, diffs, patches,
43
+ scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS temp
44
+ directory), never inside the repository. Delete everything you created before reporting done.
45
+ Never delete user files, versioned artifacts, worktrees, or another session's temporary files.
46
+ If an artifact must outlive the task, name it and say why. Full rules:
47
+ `_shared/workspace-hygiene.md`.
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Type declarations for the CodeOps temporary-directory lifecycle helper.
3
+ *
4
+ * The helper is plain JavaScript so `node --test` can exercise it directly;
5
+ * these declarations give the TypeScript plugin entry point typed access.
6
+ */
7
+
8
+ /** Age after which a session directory is treated as abandoned. */
9
+ export declare const DEFAULT_MAX_AGE_MS: number
10
+
11
+ /** Directory name used when no usable session identifier exists. */
12
+ export declare const SHARED_SESSION_NAME: string
13
+
14
+ /** Resolve the CodeOps-owned temp root under a base temp directory. */
15
+ export declare function codeopsTmpRoot(base?: string): string
16
+
17
+ /** Reduce a session identifier to a safe single path segment. */
18
+ export declare function sanitizeSessionId(sessionID?: string): string
19
+
20
+ /** Compute the temp directory for one session. */
21
+ export declare function sessionTmpDir(sessionID?: string, base?: string): string
22
+
23
+ /** Create the session temp directory when it does not exist yet. */
24
+ export declare function ensureSessionTmpDir(sessionID?: string, base?: string): string
25
+
26
+ /** Inputs for a stale-directory sweep. */
27
+ export interface CleanStaleTmpDirsOptions {
28
+ sessionID?: string
29
+ base?: string
30
+ maxAgeMs?: number
31
+ now?: number
32
+ }
33
+
34
+ /** Remove session directories abandoned by interrupted or crashed runs. */
35
+ export declare function cleanStaleTmpDirs(options?: CleanStaleTmpDirsOptions): string[]
36
+
37
+ /** Remove exactly one session's temp directory. */
38
+ export declare function removeSessionTmpDir(sessionID?: string, base?: string): boolean
@@ -0,0 +1,180 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Temporary-directory lifecycle for CodeOps sessions.
4
+ *
5
+ * The workspace-hygiene protocol asks every skill and agent to put scratch
6
+ * files under `$CODEOPS_TMPDIR` and delete them when the run completes. This
7
+ * module provides the safety net around that protocol:
8
+ *
9
+ * - it computes the per-session directory the plugin exports as
10
+ * `$CODEOPS_TMPDIR`, under a CodeOps-owned root inside the OS temp directory;
11
+ * - it sweeps directories abandoned by interrupted runs once they are older
12
+ * than a safety cap; and
13
+ * - it removes exactly one session's directory when that session is deleted.
14
+ *
15
+ * Safety is the whole point: every path derives from a sanitized session
16
+ * identifier, the sweep walks only the CodeOps-owned root, symlinked entries
17
+ * are treated as foreign, and cleanup is best effort so a failure never breaks
18
+ * a session.
19
+ *
20
+ * @module lib/tmp-hygiene
21
+ */
22
+
23
+ import { lstatSync, mkdirSync, readdirSync, rmSync } from "node:fs"
24
+ import { tmpdir } from "node:os"
25
+ import { join, resolve, sep } from "node:path"
26
+
27
+ /**
28
+ * Age after which a session directory is treated as abandoned.
29
+ *
30
+ * A crashed or interrupted run leaves its directory behind; once it is this
31
+ * old, no live session can still need it, so the next sweep may remove it.
32
+ */
33
+ export const DEFAULT_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000
34
+
35
+ /** Directory name used when no usable session identifier exists. */
36
+ export const SHARED_SESSION_NAME = "shared"
37
+
38
+ /**
39
+ * Resolve the CodeOps-owned temp root under a base temp directory.
40
+ *
41
+ * The plugin owns this subtree and nothing else under the system temp
42
+ * directory; keeping all CodeOps scratch under one root is what makes the
43
+ * automatic sweep safe.
44
+ *
45
+ * @param base - Base temp directory (injectable for tests)
46
+ * @returns Path to the CodeOps temp root
47
+ */
48
+ export function codeopsTmpRoot(base = tmpdir()) {
49
+ return join(base, "opencode", "codeops")
50
+ }
51
+
52
+ /**
53
+ * Reduce a session identifier to a safe single path segment.
54
+ *
55
+ * Session identifiers come from the host and must never influence the path
56
+ * shape: every character outside `A-Z`, `a-z`, `0-9`, `_`, and `-` is removed,
57
+ * so a value like `../../etc` cannot escape the temp root. An empty result
58
+ * falls back to a shared directory name.
59
+ *
60
+ * @param sessionID - Raw session identifier (may be missing)
61
+ * @returns A safe directory name
62
+ */
63
+ export function sanitizeSessionId(sessionID) {
64
+ const cleaned = String(sessionID ?? "").replace(/[^A-Za-z0-9_-]/g, "")
65
+ return cleaned.length > 0 ? cleaned : SHARED_SESSION_NAME
66
+ }
67
+
68
+ /**
69
+ * Compute the temp directory for one session.
70
+ *
71
+ * @param sessionID - Raw session identifier (may be missing)
72
+ * @param base - Base temp directory (injectable for tests)
73
+ * @returns Path to the session's temp directory
74
+ */
75
+ export function sessionTmpDir(sessionID, base = tmpdir()) {
76
+ return join(codeopsTmpRoot(base), sanitizeSessionId(sessionID))
77
+ }
78
+
79
+ /**
80
+ * Create the session temp directory when it does not exist yet.
81
+ *
82
+ * Called while exporting the shell environment, so the directory is ready
83
+ * before the first command needs it.
84
+ *
85
+ * @param sessionID - Raw session identifier (may be missing)
86
+ * @param base - Base temp directory (injectable for tests)
87
+ * @returns Path to the session's temp directory
88
+ * @throws {Error} When the directory cannot be created
89
+ */
90
+ export function ensureSessionTmpDir(sessionID, base = tmpdir()) {
91
+ const dir = sessionTmpDir(sessionID, base)
92
+ mkdirSync(dir, { recursive: true })
93
+ return dir
94
+ }
95
+
96
+ /**
97
+ * Remove session directories abandoned by interrupted or crashed runs.
98
+ *
99
+ * Only direct children of the CodeOps temp root are considered. Fresh
100
+ * directories, the current session's directory, plain files, and symlinks are
101
+ * left untouched; a symlink is never followed, so a link planted inside the
102
+ * root can never redirect a delete outside it. Failures are swallowed because
103
+ * a sweep is maintenance, not a task requirement.
104
+ *
105
+ * @param options - Sweep inputs
106
+ * @param options.sessionID - Current session identifier to preserve
107
+ * @param options.base - Base temp directory (injectable for tests)
108
+ * @param options.maxAgeMs - Abandonment age in milliseconds
109
+ * @param options.now - Current time in milliseconds (injectable for tests)
110
+ * @returns Paths of the directories that were removed
111
+ */
112
+ export function cleanStaleTmpDirs({
113
+ sessionID,
114
+ base = tmpdir(),
115
+ maxAgeMs = DEFAULT_MAX_AGE_MS,
116
+ now = Date.now(),
117
+ } = {}) {
118
+ const root = codeopsTmpRoot(base)
119
+ const keep = resolve(sessionTmpDir(sessionID, base))
120
+ const removed = []
121
+
122
+ let entries
123
+ try {
124
+ entries = readdirSync(root, { withFileTypes: true })
125
+ } catch {
126
+ return removed
127
+ }
128
+
129
+ for (const entry of entries) {
130
+ // Directory entries are lstat-based, so a symlink to a directory reports
131
+ // as a symlink and is skipped here.
132
+ if (!entry.isDirectory()) continue
133
+
134
+ const full = join(root, entry.name)
135
+ if (resolve(full) === keep) continue
136
+
137
+ try {
138
+ const info = lstatSync(full)
139
+ if (!info.isDirectory()) continue
140
+ if (now - info.mtimeMs < maxAgeMs) continue
141
+ rmSync(full, { recursive: true, force: true })
142
+ removed.push(full)
143
+ } catch {
144
+ // Best effort: a directory that vanished mid-sweep is already gone.
145
+ }
146
+ }
147
+
148
+ return removed
149
+ }
150
+
151
+ /**
152
+ * Remove exactly one session's temp directory.
153
+ *
154
+ * Used when a session is deleted: its scratch can no longer be needed. The
155
+ * removal refuses anything that is not a regular directory strictly inside
156
+ * the CodeOps temp root, so a symlink or an unexpected path is left alone.
157
+ *
158
+ * @param sessionID - Session identifier whose directory should be removed
159
+ * @param base - Base temp directory (injectable for tests)
160
+ * @returns True when the directory was removed
161
+ */
162
+ export function removeSessionTmpDir(sessionID, base = tmpdir()) {
163
+ const root = resolve(codeopsTmpRoot(base))
164
+ const dir = sessionTmpDir(sessionID, base)
165
+
166
+ if (!resolve(dir).startsWith(root + sep)) return false
167
+
168
+ try {
169
+ if (!lstatSync(dir).isDirectory()) return false
170
+ } catch {
171
+ return false
172
+ }
173
+
174
+ try {
175
+ rmSync(dir, { recursive: true, force: true })
176
+ return true
177
+ } catch {
178
+ return false
179
+ }
180
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-codeops",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "Specification-first engineering for complex systems — CodeOps plugin for OpenCode",
5
5
  "type": "module",
6
6
  "engines": {
package/plugin/index.ts CHANGED
@@ -4,6 +4,12 @@ import { homedir } from "node:os"
4
4
  import { join, dirname } from "node:path"
5
5
  import { fileURLToPath } from "node:url"
6
6
 
7
+ import {
8
+ cleanStaleTmpDirs,
9
+ ensureSessionTmpDir,
10
+ removeSessionTmpDir,
11
+ } from "../bin/lib/tmp-hygiene.mjs"
12
+
7
13
  // ---------------------------------------------------------------------------
8
14
  // Package root — resolved at module load time so it is always the plugin's
9
15
  // installed directory, regardless of the working directory at event time.
@@ -43,6 +49,28 @@ const outputStyle = readFileSync(
43
49
  )
44
50
  const standardsText = `${codingStandards}\n\n${outputStyle}`
45
51
 
52
+ // ---------------------------------------------------------------------------
53
+ // Workspace hygiene — the plugin owns one temp directory per session (exported
54
+ // as CODEOPS_TMPDIR) and sweeps directories abandoned by earlier interrupted
55
+ // runs. The sweep runs at most once per plugin process, so spawning many child
56
+ // sessions does not repeat the directory walk.
57
+ // ---------------------------------------------------------------------------
58
+ let sweptStaleTmpDirs = false
59
+
60
+ /**
61
+ * Sweep temp directories abandoned by earlier interrupted runs, once per
62
+ * process. Cleanup is best effort: a failure must never block a session.
63
+ */
64
+ function sweepStaleTmpDirsOnce(): void {
65
+ if (sweptStaleTmpDirs) return
66
+ sweptStaleTmpDirs = true
67
+ try {
68
+ cleanStaleTmpDirs()
69
+ } catch {
70
+ // Best effort only.
71
+ }
72
+ }
73
+
46
74
  // ---------------------------------------------------------------------------
47
75
  // Helper — inject standards into a session without triggering an AI reply.
48
76
  // Uses client.session.prompt with noReply: true (confirmed from OpenCode SDK).
@@ -120,12 +148,18 @@ export const CodeOpsPlugin: Plugin = async ({ client, directory }) => {
120
148
  // Both are dispatched via the generic event hook.
121
149
  // session.created → new session (Codex: startup)
122
150
  // session.compacted → after compact (Codex: resume|compact)
151
+ // Also the hygiene lifecycle: a new top-level session sweeps abandoned
152
+ // temp directories once, and a deleted session's temp directory is removed.
123
153
  // -----------------------------------------------------------------------
124
154
  event: async ({ event }) => {
125
155
  if (event.type === "session.created") {
126
- const sessionId: string = (event.properties as { info: { id: string } }).info.id
127
- await injectStandards(client, sessionId)
156
+ const info = (event.properties as { info: { id: string; parentID?: string } }).info
157
+ await injectStandards(client, info.id)
128
158
  await warnOnVersionSkew(client, directory)
159
+ if (!info.parentID) sweepStaleTmpDirsOnce()
160
+ } else if (event.type === "session.deleted") {
161
+ const info = (event.properties as { info: { id: string } }).info
162
+ removeSessionTmpDir(info.id)
129
163
  } else if (event.type === "session.compacted") {
130
164
  const sessionId: string = (event.properties as { sessionID: string }).sessionID
131
165
  await injectStandards(client, sessionId)
@@ -148,9 +182,16 @@ export const CodeOpsPlugin: Plugin = async ({ client, directory }) => {
148
182
  // scripts as: python3 "${CODEOPS_PLUGIN_ROOT}/scripts/codeops_plan.py"
149
183
  // The value is the package root (parent of this plugin/ directory), which
150
184
  // is where skills/, scripts/, and the other shipped assets live.
185
+ // CODEOPS_TMPDIR is the session's directory under the CodeOps temp root;
186
+ // skills and agents put every scratch file there and delete it when done.
151
187
  // -----------------------------------------------------------------------
152
- "shell.env": async (_input, output) => {
188
+ "shell.env": async (input, output) => {
153
189
  output.env.CODEOPS_PLUGIN_ROOT = PACKAGE_ROOT
190
+ try {
191
+ output.env.CODEOPS_TMPDIR = ensureSessionTmpDir(input.sessionID)
192
+ } catch {
193
+ // Best effort: a temp-directory failure must never block a shell.
194
+ }
154
195
  },
155
196
 
156
197
  // -----------------------------------------------------------------------
@@ -57,3 +57,9 @@ original-goal or smallest-design context blocks execution; report it to the pare
57
57
  exactly what is missing or ambiguous as a blocker — never guess, and never edit the
58
58
  execution plan or roadmap (the parent session owns those and the user conversation).
59
59
  - Report per task, 3-4 lines each: what changed, test status, any blocker.
60
+ - **Workspace hygiene (non-negotiable).** Temporary artifacts you create — verify logs, diffs,
61
+ patches, scratch directories — belong under `$CODEOPS_TMPDIR` when it is set (otherwise the OS
62
+ temp directory), never inside the repository. Delete everything you created before reporting
63
+ done. Never delete user files, versioned artifacts, worktrees, or another session's temporary
64
+ files. If an artifact must outlive the task, name it and say why. Full rules:
65
+ `_shared/workspace-hygiene.md`.
@@ -27,3 +27,11 @@ description: Analyze the current repository and create or refresh concise CodeOp
27
27
  10. When a specialization signal is strong and no specialist covers it, report the candidate with evidence and recommend the `setup-routing` creation flow ([../../_shared/specialist-agents.md](../../_shared/specialist-agents.md)); never write agent files here. Preserve the `<!-- CODEOPS-SPECIALISTS:START -->` / `<!-- CODEOPS-SPECIALISTS:END -->` block byte-for-byte when refreshing the managed section.
28
28
 
29
29
  Keep `AGENTS.md` small. Operational routing belongs in `codeops/codeops.json` or `opencode.json`, not prose.
30
+
31
+ ---
32
+
33
+ > **Workspace hygiene (non-negotiable):** put every temporary artifact this run creates in
34
+ > `$CODEOPS_TMPDIR` (fallback: the OS temp directory), never in the repository, and delete them
35
+ > all before reporting completion. Never delete user files, versioned artifacts, worktrees, or
36
+ > another session's temporary files. Full rules:
37
+ > [_shared/workspace-hygiene.md](../../_shared/workspace-hygiene.md).
@@ -20,3 +20,11 @@ This is a comment-only workflow. Never alter executable tokens, declarations, ty
20
20
  7. Review the diff to prove only comments changed. Run the repository's normal formatter and verification command.
21
21
 
22
22
  Documentation explains the shipped system, not the temporary process that produced it.
23
+
24
+ ---
25
+
26
+ > **Workspace hygiene (non-negotiable):** put every temporary artifact this run creates in
27
+ > `$CODEOPS_TMPDIR` (fallback: the OS temp directory), never in the repository, and delete them
28
+ > all before reporting completion. Never delete user files, versioned artifacts, worktrees, or
29
+ > another session's temporary files. Full rules:
30
+ > [_shared/workspace-hygiene.md](../../_shared/workspace-hygiene.md).
@@ -267,3 +267,12 @@ Brief rules for verification failure, plan deviation, and mid-task interruption
267
267
  files and use only facts you can read — do not invent settings.
268
268
  - Commit using the `git-commit` skill (commit only) or the `git-commit` skill in push mode (commit + push), or a normal git commit.
269
269
  - Related skills: make-plan (creation), upgrade-plan (outdated plans), preflight, roadmap, techdocs.
270
+ - Cleanup is part of session wrap-up: delete the run's verify logs and scratch per
271
+ [../../_shared/workspace-hygiene.md](../../_shared/workspace-hygiene.md) and report
272
+ `Cleanup: done` in the session summary.
273
+
274
+ > **Workspace hygiene (non-negotiable):** put every temporary artifact this run creates in
275
+ > `$CODEOPS_TMPDIR` (fallback: the OS temp directory), never in the repository, and delete them
276
+ > all before reporting completion. Never delete user files, versioned artifacts, worktrees, or
277
+ > another session's temporary files. Full rules:
278
+ > [_shared/workspace-hygiene.md](../../_shared/workspace-hygiene.md).
@@ -225,7 +225,8 @@ red-phase, green-phase, session wrap-up — executes with output captured to a t
225
225
  <verify command> > "$VERIFY_LOG" 2>&1
226
226
  ```
227
227
 
228
- (`$VERIFY_LOG` = a file in the session temp/scratchpad dir, e.g. `verify-<task-id>.log`.)
228
+ (`$VERIFY_LOG` = a file under `$CODEOPS_TMPDIR` — or the OS temp directory when it is unset —
229
+ e.g. `verify-<task-id>.log`.)
229
230
 
230
231
  - **PASS** → surface ONE line: `VERIFY PASS (task N.N.N)`, plus the test count if it is
231
232
  extractable from the log tail at no extra cost.
@@ -234,10 +235,11 @@ red-phase, green-phase, session wrap-up — executes with output captured to a t
234
235
  - **Red-phase runs** (spec tests expected to fail) → surface only the failing spec-test
235
236
  names/count confirming the red state — never the full dump.
236
237
 
237
- The full log always remains on disk for the session. If the log location is unwritable, fall
238
- back to running verify plainly ONCE and note the fallback in the session summary. This rule is
239
- about CONTEXT, not rigor: the verify command itself, its scope, and pass/fail gating are
240
- unchanged — and the temp log is read-only evidence, never executed.
238
+ The full log remains on disk until the session wrap-up cleanup deletes it (see
239
+ `_shared/workspace-hygiene.md`); nothing in the transcript depends on it afterward. If the log
240
+ location is unwritable, fall back to running verify plainly ONCE and note the fallback in the
241
+ session summary. This rule is about CONTEXT, not rigor: the verify command itself, its scope, and
242
+ pass/fail gating are unchanged — and the temp log is read-only evidence, never executed.
241
243
 
242
244
  ### Zero-Ambiguity During Execution
243
245
 
@@ -403,6 +405,9 @@ otherwise still `[~]` — with the progress counter and Last Updated stamp curre
403
405
  3. Run the verify command (output captured per the Verify-output capture rule).
404
406
  4. Handle the commit per the active commit mode (see [commit-modes.md](commit-modes.md)).
405
407
  5. Report the session summary (must include `Execution Plan Updated: ✅`).
408
+ 6. **Cleanup:** delete every temporary artifact this session created — verify logs under
409
+ `$CODEOPS_TMPDIR`, scratch directories, temporary diffs — per
410
+ `_shared/workspace-hygiene.md`, and report `Cleanup: done` or name what was kept and why.
406
411
 
407
412
  ### Session Summary Template
408
413
 
@@ -14,13 +14,14 @@ A request to commit authorizes a local commit only. Push only when the user expl
14
14
  1. Resolve the repository root and inspect `git status --short`, staged/unstaged diffs, and recent commit style.
15
15
  2. If clean, report `nothing to commit` and stop.
16
16
  3. Inspect every untracked file. Stop and ask before staging likely secrets, credentials, build output, large binaries, or unrelated scratch files.
17
- 4. Resolve the authoritative verification command from `AGENTS.md`, CodeOps plan Verify lines, or project manifests. Run it with output captured to a temporary log. On failure, report the failure tail and do not stage or commit.
17
+ 4. Resolve the authoritative verification command from `AGENTS.md`, CodeOps plan Verify lines, or project manifests. Run it with output captured to a log under `$CODEOPS_TMPDIR` (fallback: the OS temp directory), never in the repository. On failure, report the failure tail and do not stage or commit.
18
18
  5. Stage deliberately by explicit paths or coherent groups. Avoid `git add .` when the working directory may be a monorepo subtree or unrelated changes exist.
19
19
  6. Review `git diff --cached --check`, the staged stat, and the staged diff. Ensure the commit contains one coherent purpose and preserves unrelated user changes.
20
- 7. Write a Conventional Commit message to a temporary file and commit with `git commit -F`. Never use an inline multiline message.
20
+ 7. Write a Conventional Commit message to a temporary file under `$CODEOPS_TMPDIR` (fallback: the OS temp directory) and commit with `git commit -F`. Never use an inline multiline message.
21
21
  8. If a commit hook modifies files, inspect and restage only relevant changes, then retry once. Never use `--no-verify` automatically.
22
22
  9. For push mode, fetch/rebase only when appropriate for the branch policy. Stop on conflicts; never resolve ambiguous conflicts automatically. Push normally, never with force.
23
23
  10. Report the resulting commit, verification, and push state.
24
+ 11. Delete the temporary verification log and commit-message file, then report `Cleanup: done` or name what was kept and why.
24
25
 
25
26
  ## Message shape
26
27
 
@@ -33,3 +34,11 @@ type(scope): imperative summary
33
34
  ```
34
35
 
35
36
  Use `feat`, `fix`, `refactor`, `test`, `docs`, or `chore` unless repository guidance defines another convention.
37
+
38
+ ---
39
+
40
+ > **Workspace hygiene (non-negotiable):** put every temporary artifact this run creates in
41
+ > `$CODEOPS_TMPDIR` (fallback: the OS temp directory), never in the repository, and delete them
42
+ > all before reporting completion. Never delete user files, versioned artifacts, worktrees, or
43
+ > another session's temporary files. Full rules:
44
+ > [_shared/workspace-hygiene.md](../../_shared/workspace-hygiene.md).
@@ -36,3 +36,11 @@ For each issue:
36
36
  5. Continue past nonexistent individual issues but record every outcome.
37
37
 
38
38
  Return a per-issue summary. Never create, edit, label, close, reopen, or comment unless the user's request explicitly authorizes that mutation.
39
+
40
+ ---
41
+
42
+ > **Workspace hygiene (non-negotiable):** put every temporary artifact this run creates in
43
+ > `$CODEOPS_TMPDIR` (fallback: the OS temp directory), never in the repository, and delete them
44
+ > all before reporting completion. Never delete user files, versioned artifacts, worktrees, or
45
+ > another session's temporary files. Full rules:
46
+ > [_shared/workspace-hygiene.md](../../_shared/workspace-hygiene.md).
@@ -340,3 +340,11 @@ grill-me → identify design tree → walk each branch → resolve decisions →
340
340
 
341
341
  **Output:** A shared understanding summary with all decisions, assumptions,
342
342
  constraints, and deferrals — ready to feed into any downstream skill.
343
+
344
+ ---
345
+
346
+ > **Workspace hygiene (non-negotiable):** put every temporary artifact this run creates in
347
+ > `$CODEOPS_TMPDIR` (fallback: the OS temp directory), never in the repository, and delete them
348
+ > all before reporting completion. Never delete user files, versioned artifacts, worktrees, or
349
+ > another session's temporary files. Full rules:
350
+ > [_shared/workspace-hygiene.md](../../_shared/workspace-hygiene.md).
@@ -282,3 +282,11 @@ See the **roadmap skill** for the full Roadmap Keeper protocol.
282
282
  - **upgrade-plan skill** — upgrades outdated plans; the gate applies to new decisions only.
283
283
  - **techdocs skill** — architecture docs read during Phase 1.2 and updated during execution.
284
284
  - For coding, testing, and git standards, follow **your project's coding standards (AGENTS.md)** and use **git-commit skill** / **git-commit skill in push mode** for commits.
285
+
286
+ ---
287
+
288
+ > **Workspace hygiene (non-negotiable):** put every temporary artifact this run creates in
289
+ > `$CODEOPS_TMPDIR` (fallback: the OS temp directory), never in the repository, and delete them
290
+ > all before reporting completion. Never delete user files, versioned artifacts, worktrees, or
291
+ > another session's temporary files. Full rules:
292
+ > [_shared/workspace-hygiene.md](../../_shared/workspace-hygiene.md).
@@ -268,3 +268,11 @@ comparable systems → key discovery focus is in **`discovery-phases.md`**.
268
268
  - the upgrade-plan skill — upgrading outdated requirements (upgrade_requirements)
269
269
  - the roadmap skill — sync each newly drafted RD to stage `RD Drafted`
270
270
  - Read the project's AGENTS.md (or detected project conventions) for project-specific constraints
271
+
272
+ ---
273
+
274
+ > **Workspace hygiene (non-negotiable):** put every temporary artifact this run creates in
275
+ > `$CODEOPS_TMPDIR` (fallback: the OS temp directory), never in the repository, and delete them
276
+ > all before reporting completion. Never delete user files, versioned artifacts, worktrees, or
277
+ > another session's temporary files. Full rules:
278
+ > [_shared/workspace-hygiene.md](../../_shared/workspace-hygiene.md).
@@ -32,3 +32,11 @@ Outcome evidence is opt-in, local, and content-free. Invocation counts are not q
32
32
  6. Present the smallest change likely to improve the measured outcome and define how to evaluate it.
33
33
 
34
34
  Never upload or quote project content from the outcome store.
35
+
36
+ ---
37
+
38
+ > **Workspace hygiene (non-negotiable):** put every temporary artifact this run creates in
39
+ > `$CODEOPS_TMPDIR` (fallback: the OS temp directory), never in the repository, and delete them
40
+ > all before reporting completion. Never delete user files, versioned artifacts, worktrees, or
41
+ > another session's temporary files. Full rules:
42
+ > [_shared/workspace-hygiene.md](../../_shared/workspace-hygiene.md).
@@ -308,3 +308,11 @@ checklist. Full safeguards in [report-format.md](report-format.md).
308
308
  **Standalone:** when used without a follow-up, finish the scan + resolution, present the final
309
309
  status, then ask the user what to do next (apply fixes, create a plan, start execution, or review
310
310
  specific findings).
311
+
312
+ ---
313
+
314
+ > **Workspace hygiene (non-negotiable):** put every temporary artifact this run creates in
315
+ > `$CODEOPS_TMPDIR` (fallback: the OS temp directory), never in the repository, and delete them
316
+ > all before reporting completion. Never delete user files, versioned artifacts, worktrees, or
317
+ > another session's temporary files. Full rules:
318
+ > [_shared/workspace-hygiene.md](../../_shared/workspace-hygiene.md).
@@ -216,3 +216,11 @@ mapping is in **`phases.md`**.
216
216
  - the make-requirements skill — consumes `09-reconstruction-brief.md` to produce formal RDs (downstream; this brief is its input)
217
217
  - the make-plan skill — turns RDs into implementation plans (rebuild pipeline)
218
218
  - your project's coding/testing standards (AGENTS.md) — code-quality and test patterns to reference while analyzing
219
+
220
+ ---
221
+
222
+ > **Workspace hygiene (non-negotiable):** put every temporary artifact this run creates in
223
+ > `$CODEOPS_TMPDIR` (fallback: the OS temp directory), never in the repository, and delete them
224
+ > all before reporting completion. Never delete user files, versioned artifacts, worktrees, or
225
+ > another session's temporary files. Full rules:
226
+ > [_shared/workspace-hygiene.md](../../_shared/workspace-hygiene.md).
@@ -379,3 +379,11 @@ only facts you can read — do not invent settings.
379
379
  - Related skills: requirements (`RD Drafted` hook), preflight (`RD/Plan Preflighted`
380
380
  hooks), make-plan (`Plan Created` hook + linking), exec-plan (`Executing` / `Done` /
381
381
  `Blocked` hooks).
382
+
383
+ ---
384
+
385
+ > **Workspace hygiene (non-negotiable):** put every temporary artifact this run creates in
386
+ > `$CODEOPS_TMPDIR` (fallback: the OS temp directory), never in the repository, and delete them
387
+ > all before reporting completion. Never delete user files, versioned artifacts, worktrees, or
388
+ > another session's temporary files. Full rules:
389
+ > [_shared/workspace-hygiene.md](../../_shared/workspace-hygiene.md).
@@ -92,3 +92,11 @@ on), present only **genuinely viable** options, second-guessed and grounded in w
92
92
  actually reported, and lead with a recommendation. The user decides; never apply a migration
93
93
  without an explicit confirmation (or `--yes`). For consequential choices, apply the
94
94
  recommendation-hardening protocol (`_shared/recommendation-hardening.md`).
95
+
96
+ ---
97
+
98
+ > **Workspace hygiene (non-negotiable):** put every temporary artifact this run creates in
99
+ > `$CODEOPS_TMPDIR` (fallback: the OS temp directory), never in the repository, and delete them
100
+ > all before reporting completion. Never delete user files, versioned artifacts, worktrees, or
101
+ > another session's temporary files. Full rules:
102
+ > [_shared/workspace-hygiene.md](../../_shared/workspace-hygiene.md).
@@ -90,7 +90,7 @@ Creation, after approval:
90
90
  2. Write `routing.roles.<role>` policy first when a model/effort/sandbox/reasoning override is needed: routing wins over the brief, and a policy written later makes the generated agent immediately stale.
91
91
  3. Generate the agent: `python3 "${CODEOPS_PLUGIN_ROOT}/scripts/install_agents.py" --project . --custom <role>`.
92
92
  4. Sync the index: `... --sync-agents-md`.
93
- 5. Verify last with `... --check`, then tell the user the agent is available from the next OpenCode session.
93
+ 5. Verify last with `... --check`, then tell the user the agent is available as soon as its generated file exists (discovery timing follows the running OpenCode build).
94
94
 
95
95
  Removal: confirm, run `--remove-custom <role> --yes` (it deletes the agent and brief and syncs the index), drop the routing entry, warn when an active plan references the role, and report that `exec-plan` will fall back to a dynamic packet.
96
96
 
@@ -114,3 +114,11 @@ python3 "${CODEOPS_PLUGIN_ROOT}/scripts/install_agents.py" --project . --check
114
114
  ```
115
115
 
116
116
  Report configured roles, model pins if any, read-only roles, fallbacks, and unresolved capability gaps.
117
+
118
+ ---
119
+
120
+ > **Workspace hygiene (non-negotiable):** put every temporary artifact this run creates in
121
+ > `$CODEOPS_TMPDIR` (fallback: the OS temp directory), never in the repository, and delete them
122
+ > all before reporting completion. Never delete user files, versioned artifacts, worktrees, or
123
+ > another session's temporary files. Full rules:
124
+ > [_shared/workspace-hygiene.md](../../_shared/workspace-hygiene.md).
@@ -197,3 +197,11 @@ auto-compacts context — no manual threshold handling is needed.)
197
197
  - [templates.md](templates.md) — all VitePress file templates (index, architecture/*, ADR log + ADR template, guides/*, reference/*). Read when writing any document in Phase 4.
198
198
  - [vitepress-setup.md](vitepress-setup.md) — Phase 3 install, `config.ts`, npm scripts, `.gitignore`, and sidebar auto-update. Read when scaffolding VitePress or adding pages.
199
199
  - [authoring-and-update.md](authoring-and-update.md) — Phase 5 authoring guidelines + Mermaid types, Phase 6 incremental/comprehensive update protocol with the Design Intent Preservation rule, and the review_techdocs health check. Read before authoring, before any auto-update, and for review_techdocs.
200
+
201
+ ---
202
+
203
+ > **Workspace hygiene (non-negotiable):** put every temporary artifact this run creates in
204
+ > `$CODEOPS_TMPDIR` (fallback: the OS temp directory), never in the repository, and delete them
205
+ > all before reporting completion. Never delete user files, versioned artifacts, worktrees, or
206
+ > another session's temporary files. Full rules:
207
+ > [_shared/workspace-hygiene.md](../../_shared/workspace-hygiene.md).
@@ -73,3 +73,11 @@ approved drift repair; and the Git diff contains only the approved migration.
73
73
 
74
74
  Report old formats, new schema, files changed, ambiguities resolved, RD-to-plan coverage, preserved
75
75
  progress, and residual risk. Do not auto-advance lifecycle stages.
76
+
77
+ ---
78
+
79
+ > **Workspace hygiene (non-negotiable):** put every temporary artifact this run creates in
80
+ > `$CODEOPS_TMPDIR` (fallback: the OS temp directory), never in the repository, and delete them
81
+ > all before reporting completion. Never delete user files, versioned artifacts, worktrees, or
82
+ > another session's temporary files. Full rules:
83
+ > [_shared/workspace-hygiene.md](../../_shared/workspace-hygiene.md).
@@ -50,6 +50,25 @@ These apply to all code I write unless this project's `AGENTS.md` overrides a sp
50
50
  - **Prevent injection:** parameterized queries (never string-concatenate SQL/NoSQL), escape output / use framework auto-escaping (XSS), never pass unsanitized input to shells/`eval` (command injection), canonicalize and reject `..`/absolute paths (path traversal), anti-CSRF tokens + `SameSite` cookies, rate-limit auth endpoints.
51
51
  - **Protect data:** TLS in transit; encrypt sensitive data at rest; hash passwords with `bcrypt`/`argon2`/`scrypt`; never hardcode secrets (use env vars / secret managers); never log secrets or PII; return minimal errors in production; restrictive CORS; request-size limits; audit dependencies; run containers as non-root from minimal images.
52
52
 
53
+ # Workspace hygiene (NON-NEGOTIABLE)
54
+
55
+ - **Own your temporary artifacts.** Verification logs, diffs, patch files, commit-message files,
56
+ scratch directories, fixture trees, and downloaded artifacts are borrowed space. Put them under
57
+ `$CODEOPS_TMPDIR` when the CodeOps plugin exports it (one directory per session); otherwise use
58
+ the OS temp directory. Never write temporary files into the repository.
59
+ - **Delete at completion.** Before reporting any task, phase, or session complete, delete every
60
+ temporary artifact the run created — including verification logs. If the user asked for an
61
+ artifact to be kept, name its exact path and keep that file only.
62
+ - **Never delete what you do not own.** User files, repository content, versioned artifacts,
63
+ `codeops/` planning artifacts, and git worktrees are durable. Never touch another session's
64
+ temporary files, and never follow a symlink out of the temp root.
65
+ - **No secrets in temp files.** Do not write secrets into a temporary file; if one already holds a
66
+ secret, delete it and say so without printing its contents.
67
+ - **Report it.** The final summary states `Cleanup: done`, or names what was kept and why, or
68
+ reports a failed deletion with its path and reason.
69
+ - The canonical protocol, including the plugin's automatic safety net, is
70
+ `_shared/workspace-hygiene.md`.
71
+
53
72
  # Testing standards
54
73
 
55
74
  - **Run the project's verify command (build + test) before completing any task or committing.** No code is "done" while any test fails.
@@ -42,6 +42,12 @@ Do not duplicate these standards in `~/.config/opencode/AGENTS.md` — the plugi
42
42
  artifacts get validation too — see the full standards' validation-command table.
43
43
 
44
44
  # Working style
45
+ - **Cleanup after yourself (NON-NEGOTIABLE).** Put every temporary artifact you create — logs,
46
+ diffs, patches, commit-message files, scratch directories — under `$CODEOPS_TMPDIR` when it is
47
+ set (otherwise the OS temp directory), never inside the repository, and delete them all before
48
+ reporting a task complete. Never delete user files, versioned artifacts, worktrees, or another
49
+ session's temporary files. If something must outlive the task, name it and say why. Full rules:
50
+ `_shared/workspace-hygiene.md`.
45
51
  - **Ask before assuming**; **verify previous work** before building on it.
46
52
  - **Do not overengineer:** use the simplest implementation that fully satisfies the authorized
47
53
  requirements and existing project conventions. Do not add abstractions, layers, dependencies,