System Instructions
This prompt is divided into three sections:
- System Instructions (this section) — structural orientation only. Do not treat this
section as task input.
- Input Context — begins with the heading
# Input Context. All blocks are wrapped in
<pblock> tags. Two block types:
- File blocks:
<pblock filename="<name>" role="<role>" guidance="...">— optional
guidance attribute carries context-specific instructions; content is in a fenced block.
- Metadata/section blocks:
<pblock label="<label>" kind="<kind>">— job parameters,
rules, instructions, or group headers.
- Agent Task — begins with the heading
# Agent Task. Defines your persona, constraints,
and required outputs. Read all input context before acting on this section.
Input Context
<pblock label="Build block job" kind="job">
Build block job
- TARGET: DupFind
- BUILD_DIRECTORY: /mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/build/DupFind
- WORKING_DIRECTORY: /mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/build/DupFind
- BUILD_BLOCK: Block 2 · Service (block-2)
- STORIES: Parse --summary, --min-size, and exactly one directory argument; reject malformed usage with exit 2. (arg-parsing), Provide the cmd/dupfind main package that builds with go build and delegates to cli.Run. (module-build), Exit 1 with empty stdout when the directory is missing or is not a directory. (directory-validation), Walk the directory recursively and yield eligible regular files at or above the minimum size. (walk), Group candidate files by exact size and keep only sizes shared by two or more files. (size-grouping), Hash same-size files with SHA-256 and form duplicate groups, skipping unreadable files with a warning. (digest-grouping), Compute reclaimable bytes, order groups, number them from 1, and order paths within each group. (group-ordering), Write the CSV duplicate listing with header group,size,sha256,path using encoding/csv. (listing), Write the one-row summary of groups, duplicate files, and reclaimable bytes with --summary. (summary), Provide POSIX bin/test.sh and a Go test suite covering every rule, output form, and exit code. (test-gate)
- DATE: 2026-10-25
- BUILD_SCOPE: exactly one MANIFEST.md build block
</pblock>
<pblock label="Stories in this block" kind="section">
Stories in this block
- Parse --summary, --min-size, and exactly one directory argument; reject malformed usage with exit 2. (arg-parsing) [story]
- Provide the cmd/dupfind main package that builds with go build and delegates to cli.Run. (module-build) [story]
- Exit 1 with empty stdout when the directory is missing or is not a directory. (directory-validation) [story]
- Walk the directory recursively and yield eligible regular files at or above the minimum size. (walk) [story]
- Group candidate files by exact size and keep only sizes shared by two or more files. (size-grouping) [story]
- Hash same-size files with SHA-256 and form duplicate groups, skipping unreadable files with a warning. (digest-grouping) [story]
- Compute reclaimable bytes, order groups, number them from 1, and order paths within each group. (group-ordering) [story]
- Write the CSV duplicate listing with header group,size,sha256,path using encoding/csv. (listing) [story]
- Write the one-row summary of groups, duplicate files, and reclaimable bytes with --summary. (summary) [story]
- Provide POSIX bin/test.sh and a Go test suite covering every rule, output form, and exit code. (test-gate) [story]
</pblock>
<pblock label="Files on disk" kind="section">
Files on disk in the build directory
- sources/run.sh
These are the only imported files present on disk. Every other file named in this prompt is supplied as prompt context and is not on disk; read it here and do not report it as a missing input.
</pblock>
COMPASS - Target Orientation
<pblock filename="COMPASS.md" role="compass" path="/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/workspace/targets/DupFind/COMPASS.md" guidance="Important: This is the core project intent, constraints, and guardrails. It should have presecedence in conflicts.">
# COMPASS: DupFind
## Compass
Build a command-line duplicate file finder, the Go executable `./cmd/dupfind`, as described in
`sources/INSTRUCTIONS.md`. It walks a directory, groups regular files by size and then by SHA-256
digest, and reports each duplicate group or a one-row summary of the space that removing the
copies would recover.
Correctness is measured by `sources/run.sh`: it builds the executable with `go build` and makes
15 checks of exit code and standard output against a fixed directory tree. The goal is every check
passing.
## Constraints
- Implement in Go 1.22 or newer with the standard library only. No third-party modules.
- The application root is a Go module; the executable's main package is `./cmd/dupfind`.
- Read a file's contents only when another file has the same size.
- Write CSV with `encoding/csv`; diagnostics go to standard error and are never compared.
## Guardrails
- Do not modify, rewrite, regenerate, or substitute `sources/run.sh`.
- Do not read `sources/run.sh` from application code, and do not hardcode a digest, a path, or a
total. Every value is computed from the directory examined.
- Never delete, move, or write a file under the directory examined.
## Verification Protocol
| Story kind | Command | Asserts |
|---|---|---|
| Every behavioral story | `sh bin/test.sh` | exit `0` |
| Terminal story (once, last) | `sh sources/run.sh` | exit `0` |
<!-- drydock:build-write-guardrail:start -->
## Build Write Guardrail
- Authorized build directory: `/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/build/DupFind`
- Authorized Target directory: `/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/workspace/targets/DupFind`
- Build agents have permission to create, modify, and remove files required by the active build block inside these authorized directories.
- No path outside these authorized directories may be modified.
- Protected Drydock artifacts:
- `/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/workspace/targets/DupFind/blueprint/`
- `/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/workspace/targets/DupFind/MANIFEST.md`
- `/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/workspace/targets/DupFind/COMPASS.md`
- `/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/workspace/targets/DupFind/QuarterDeck/`
- `/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/workspace/targets/DupFind/evidence/`
<!-- drydock:build-write-guardrail:end -->
</pblock>
STACK - Technology HOW
<pblock filename="go_compact.md" role="stack" path="/mnt/c/Users/barlo/projects/drydock/Rigging/languages/go/go_compact.md">
<!-- Compacted from Rigging/languages/go/go.md sha256=aa96c7155b26f091e4f2ee9b7a47ff2202fc7c162254f2b8676779198c7147da on 2026-10-18 by Rigging maintenance -->
## Foundation Contract
The published shape of this foundation. It is built before every other foundation: a web server,
a database, or a CLI is built *into* this tree, this environment, and this test runner. Carried
verbatim into `go_compact.md`.
- source_root: internal/
- test_command: go test ./...
- environment: the module declared in `go.mod`; no vendored toolchain
- dependencies: `go.mod`
```
project/
go.mod # module path; the Go toolchain version
cmd/ # one directory per binary, each package main
internal/ # application packages; not importable outside this module
bin/ # launchers; each runs the toolchain, never a vendored copy
```
Application foundations add packages under `internal/`. The generated persistence library is a
separate module at `persistence/`, linked by the root `go.mod`.
### Native application layouts and fixtures
Initialize the root `go.mod` in the language foundation before the DATABASE block.
Use `cmd/app/main.go` for process startup, `internal/cli` for CLI behavior, and
`internal/appserver` for HTTP behavior. The root application module requires
`drydock.local/persistence v0.0.0` with `replace drydock.local/persistence => ./persistence`;
the generated persistence directory owns its nested module. Run both module test suites.
For a CLI, expose `Run(args []string, stdout, stderr io.Writer) int`, use a local
`flag.FlagSet` with `flag.ContinueOnError`, and test with `bytes.Buffer`. Only main calls
`os.Exit`. For HTTP, expose `NewHandler(...) http.Handler` using `net/http.ServeMux`.
Use `httptest.NewRecorder` and `httptest.NewRequest` for handler tests, or
`httptest.NewServer` with `t.Cleanup(server.Close)` when testing a real HTTP client.
Keep business logic in application packages and persistence access in the shipped library.
### How do we execute and measure Acceptance Criteria in this language?
An Acceptance Criterion (AC) is an executable check of Blueprint-required behavior. Native tests
use `testing` in `*_test.go`; the project gate is `go test ./...`. Within the existing Blueprint
Python AC container, execute a named test through the shipped helper:
```python
from drydock_go import run_test
result = run_test("./internal/orders", "TestCreateOrder")
assert result.passed, (result.status, result.stdout, result.stderr)
```
Drydock stages this helper beside the criterion. It runs `go test -json -count=1 -run` with an
exact test name, retains output and per-test outcomes, and rejects absent/skipped tests as proof.
The enclosing AC provides identity, timeout, result storage and repair state. Compilation errors
remain distinct from assertion failures in `result.status`. Coverage and persistence observations
require explicit instrumentation per criterion; unavailable observations are unknown.
A criterion that exercises the command line runs the built executable through the same helper,
never `go run`, which reports every non-zero program exit as 1:
```python
from drydock_go import cli_runner
code, out, err = cli_runner("--top", "0", "data.csv")
assert code == 2, (code, out, err)
```
`cli_runner` builds the single `./cmd/<name>` main package once with `go build` and returns
`(exit_code, stdout, stderr)`; pass `package="./cmd/<name>"` when there are several, and `input=`
for standard input. A failed build settles the criterion as `execution-error`.
### How does this language provide the shared persistence contract?
Use the shipped module in `Rigging/languages/go/persistence/`. Drydock copies it to the Target's
`persistence/`, generates `schema.go`, `testing.go` and a schema command from `DATABASE.md`, and
links it into the existing root `go.mod` as `drydock.local/persistence`. Driver versions and sums
are shipped; SQLite uses `go-sqlite3` (a C compiler and CGO are required), PostgreSQL uses `lib/pq`.
Run `go mod download` during dependency provisioning; execution requires these modules available.
Call `persistence.OpenDatabase(ctx, dsn)`, then typed methods such as
`db.Tickets.List(ctx, persistence.TicketsListInput{Status: "open"})`. Methods return a value and
an error. Optional inputs use pointers; read results are generated structs. Undeclared operations
and unsupported field types fail explicitly. Use `OpenSession(ctx, dsn)` for native database criteria;
empty DSN selects the configured, provisioned application store. Defer its cleanup and check the
returned error: it rolls back on success and failure, never applies schema or deletes the store.
Pass the same Store to the feature. Other connections and external effects require committed,
idempotent criteria with owned records and supported cleanup. Both engines retain autocommit
outside explicit rollback scopes.
The Go library and generator are verified on SQLite and PostgreSQL. Keep application SQL inside
the library; agents write callers. The language foundation must create `go.mod` before the
DATABASE step. Python Blueprint AC containers invoke the native Go tests through `run_test`.
---
## Consumer Rules
- Use `gofmt`, explicit errors, small consumer-owned interfaces and owned goroutine lifetimes.
- Keep business logic in `internal/` and entry points in `cmd/`; commit `go.mod` and `go.sum`.
- Gate with `go vet ./...`, `go build ./...` and `go test -race ./...`.
</pblock>
<pblock filename="common_compact.md" role="stack" path="/mnt/c/Users/barlo/projects/drydock/Rigging/stack/common_compact.md">
<!-- Compacted from /mnt/c/Users/barlo/projects/drydock/Rigging/stack/common.md sha256=2d665e4a232b3ef5b681149974e74928c8f5abb9adaac02604cc6b5987ac0f85 on 2026-10-24 by drydock rigging compact — regenerate with: drydock rigging compact --include-file {rel_source} -->
# Common Best Practices — Contract Surface
## Project Layout
### Rule: project-directory-layout
Every project must use the standard root layout and may add stack-specific directories.
Constraints: Include `bin/`, `data/` with `logs/` and `backups/`, `docs/`, `tests/`, optional `PROJECT/`, `.env`, `.env.example`, `.gitignore`, `CLAUDE.md`, and `Links.md`; keep runtime data under `data/`.
## Shell Scripts
### Rule: user-facing-operation-scripts
User-facing operations must be implemented as Bash scripts in `bin/`.
Constraints: Scripts must use standardized headers, `set -euo pipefail`, resolve project-relative paths, create `data/logs/`, log execution details, run from the project root, tee output to console and a timestamped log, and record completion.
### Rule: command-center-discovery-header
A discoverable script must begin with a Command Center header.
| Field | Required | Values |
|---|---:|---|
| `# CommandCenter Operation` | Yes | Literal |
| `# Name:` | Yes | Free text |
| `# Type:` | No | `daemon` or `batch`; defaults to `batch` |
| `# Port:` | No | Integer; daemon port |
Constraints: Scripts without `# CommandCenter Operation` remain valid but are not discoverable by Command Center.
### Rule: standard-scripts
Projects should provide applicable operation scripts with these names and purposes.
| Script | Type | Purpose |
|---|---|---|
| `bin/start.sh` | daemon | Start the development server |
| `bin/stop.sh` | batch | Stop the development server |
| `bin/test.sh` | batch | Run tests |
| `bin/build.sh` | batch | Build or compile |
| `bin/deploy.sh` | batch | Deploy to production |
| `bin/backup.sh` | batch | Back up data or databases |
### Rule: script-logging
Operation scripts must capture stdout and stderr in `data/logs/`.
Constraints: Log filenames must follow `<script>_<YYYY-MM-DD_HHMMSS>.log`; initial log lines must record timestamp, arguments, and working directory.
## Links
### Rule: links-file
Every project must provide a root-level `Links.md` containing one two-column Markdown table.
| Column | Requirement |
|---|---|
| `Label` | Short and descriptive |
| `URL` | Relevant project URL |
Constraints: Command Center reads this table and exposes the links through project configuration.
## Agent Instructions
### Rule: claude-file
Every project must provide a root-level `CLAUDE.md` with the following sections.
| Section | Required content |
|---|---|
| `## Project Overview` | Purpose and key features |
| `## Architecture` | Technology stack, key files, and patterns |
| `## Dev Commands` | Bash project commands in a code block |
| `## Service Endpoints` | `- Label: https://url` entries |
| `## Bookmarks` | Grouped links using `### Group` and `- [Title](URL)` |
Constraints: Normalize equivalent headings to the standard names: `Commands`, `Development Commands`, and `Build Commands` become `Dev Commands`; `Overview` and `Project Purpose` become `Project Overview`; `Stack` becomes `Architecture`.
## Version Control
### Rule: gitignore-and-secrets
Repositories must ignore secrets, generated files, and runtime data.
Constraints: Ignore `data/`, `*.db`, `*.log`, `.env`, `venv/`, `node_modules/`, Python caches and bytecode, `*.egg-info/`, `dist/`, `build/`, `.DS_Store`, and `Thumbs.db`; commit `.env.example` with placeholders.
### Rule: commit-message
Commit messages must use imperative, descriptive text without AI or tool mentions.
## Development Workflow
### Rule: task-commit
Completed, error-free tasks must be committed immediately.
### Rule: local-only-commit
Changes must be committed locally and must not be pushed.
### Rule: co-authorship
Commits must not contain `Co-authored-by` lines.
### Rule: restart-notice
Code-change responses for web-server projects must state whether a restart is required.
Constraints: Template, CSS, or static-only changes require the notice `No restart needed — browser refresh is enough.`; Python or JavaScript server changes require `Restart required — run the start script or equivalent.`
</pblock>
CONTEXT - Read-Only Support
<pblock filename="ARCHITECTURE.md" role="context" path="/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/workspace/targets/DupFind/blueprint/ARCHITECTURE.md" guidance="Foundational Architecture Specification">
# ARCHITECTURE: DupFind
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Module layout, package boundaries, and pipeline of the dupfind command-line duplicate file finder. |
| Depends On | None |
| Provides | go.mod, internal/, cmd/dupfind, bin/ |
## Overview
`dupfind` is a single-binary Go command-line tool. It finds regular files under a directory whose
contents are byte-for-byte identical, reports them as a CSV listing or a one-row CSV summary, and
never deletes, moves, or modifies any file.
Pipeline: parse arguments, validate the directory, walk, group by size, hash same-size groups with
SHA-256, order and number groups, emit CSV.
## Technology Stack
Derived from `TECHNOLOGY_STACK.md`; that file is the decision of record.
| Technology | Where it applies |
|---|---|
| Go 1.22 or newer, standard library only | All application code; `go.mod` declares no third-party requirement |
| go test and go vet | Test runner behind `bin/test.sh` |
| POSIX sh | `bin/test.sh` |
## Module Layout
| Path | Package | Responsibility |
|---|---|---|
| `go.mod` | module root | Module path and Go toolchain version; no `require` lines |
| `cmd/dupfind` | `main` | Calls `cli.Run(os.Args[1:], os.Stdout, os.Stderr)` and passes the result to `os.Exit`; the only caller of `os.Exit` |
| `internal/cli` | `cli` | `Run(args []string, stdout, stderr io.Writer) int`: argument parsing, directory validation, pipeline orchestration, exit codes |
| `internal/walk` | `walk` | Recursive directory walk yielding eligible regular files |
| `internal/dupes` | `dupes` | Size grouping, SHA-256 digest grouping, reclaimable bytes, ordering and numbering |
| `internal/report` | `report` | CSV listing and summary writers using `encoding/csv` |
| `bin/test.sh` | POSIX sh | Runs `go vet ./...` then `go test ./...` from the application root |
## Boundaries
- Only `main` calls `os.Exit`. `cli.Run` returns the exit code: 0 success, 1 operational failure, 2 usage error.
- Standard output carries only CSV. A failing command writes nothing to standard output and one diagnostic line to standard error.
- Warnings (unreadable file or subdirectory) go to standard error only and never change the exit code.
- File contents are read only by `dupes`, and only for files that share a size with another file.
- Files under the examined directory are opened read-only. Nothing is written, moved, or deleted there.
- Application code never reads `sources/run.sh` and never embeds a digest, path, or total.
## Module Ownership
| Boundary | Owning module | Allowed low-level APIs |
|---|---|---|
| Directory traversal and file metadata | `internal/walk` | `os.Lstat`, `os.ReadDir`, `io/fs` |
| File content reading and hashing | `internal/dupes` | `os.Open`, `crypto/sha256`, `io.Copy` |
| CSV output | `internal/report` | `encoding/csv` |
| Process arguments and exit codes | `internal/cli` and `cmd/dupfind` | `flag`, `os.Args`, `os.Exit` (main only) |
| Persistence, configuration files, external services | None; the tool has no persistent state | None |
## Foundation Scope
The foundation story creates `go.mod`, the package tree above, a `cmd/dupfind/main.go` that
delegates to `cli.Run`, and a minimal compiling placeholder in each internal package, so that
`go build ./cmd/dupfind`, `go vet ./...`, and `go test ./...` succeed before feature stories land.
The placeholder `Run` returns 0. `bin/` exists; `bin/test.sh` itself is delivered by the test-gate story.
## Programmatic Acceptance
=== AC arch-module-no-third-party ===
Intent: The application root is a Go module that declares no third-party requirement.
import pathlib
text = pathlib.Path("go.mod").read_text()
lines = [ln.strip() for ln in text.splitlines()]
module_lines = [ln for ln in lines if ln.startswith("module ")]
go_lines = [ln for ln in lines if ln.startswith("go ")]
assert len(module_lines) == 1, text
assert len(go_lines) == 1, text
assert "require" not in text, text
=== END AC arch-module-no-third-party ===
=== AC arch-package-tree ===
Intent: The package directories named by the architecture exist in the build tree.
import pathlib
for rel in ["cmd/dupfind", "internal/cli", "internal/walk", "internal/dupes", "internal/report", "bin"]:
assert pathlib.Path(rel).is_dir(), rel
assert pathlib.Path("cmd/dupfind/main.go").is_file()
=== END AC arch-package-tree ===
=== AC arch-vet-and-build ===
Intent: The foundation compiles and passes go vet across every package.
import subprocess
import sys
for cmd in (["go", "vet", "./..."], ["go", "build", "./..."]):
result = subprocess.run(cmd, capture_output=True, text=True)
print(result.stdout)
print(result.stderr, file=sys.stderr)
assert result.returncode == 0, cmd
=== END AC arch-vet-and-build ===
## User Acceptance
- None.
## Guardrails
- Standard library only; no third-party modules.
- Never delete, move, or write a file under the directory examined.
- Do not modify, rewrite, regenerate, or substitute `sources/run.sh`, and never read it from application code.
- Do not hardcode a digest, a path, or a total; every value is computed from the directory examined.
- Read a file's contents only when another file has the same size.
</pblock>
IMPLEMENTS - Authoritative Step Specifications
<pblock label="Implementation recency anchor" kind="section"> The files in this section are the load-bearing specifications for this build block. Build these files exactly. Treat earlier sections as constraints and context.
</pblock>
<pblock filename="FEATURE-ArgParsing.md" role="implements" path="/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/workspace/targets/DupFind/blueprint/FEATURE-ArgParsing.md" guidance="Feature Specification">
# FEATURE: Arg Parsing
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Parse --summary, --min-size, and exactly one directory argument, rejecting malformed usage with exit 2. |
| Depends On | ARCHITECTURE.md |
| Provides | cli.Run, cli.Config |
## Purpose
`cli.Run(args []string, stdout, stderr io.Writer) int` in `internal/cli` interprets the command
line `dupfind [--summary] [--min-size <bytes>] <directory>` and produces a parsed configuration for
later stories.
## Behavior
- Parsing uses a local `flag.FlagSet` with `flag.ContinueOnError` and its own output discarded.
- `cli.Config` carries `Summary bool`, `MinSize int64`, and `Dir string`. `MinSize` defaults to 1.
- Options precede the directory. Exactly one directory argument is required.
- Usage errors return exit code 2, write nothing to stdout, and write exactly one diagnostic line to stderr. Usage errors are:
- no arguments, or an option with no directory;
- more than one positional argument, or an option placed after the directory (it counts as an extra argument);
- an unknown option, including `-h` and `--help`;
- `--min-size` with a missing value, or a value that is not a positive decimal integer.
- A `--min-size` value is accepted only when it consists solely of ASCII decimal digits, is at least 1, and fits in an `int64`. Signs (`+5`, `-5`), zero, hexadecimal, exponent forms, and overflow are usage errors.
- Argument errors take precedence over directory validation.
## Reads
None.
## Writes
Standard error only, on usage errors.
## Programmatic Acceptance
=== AC argparse-usage-errors-exit-2 ===
Intent: Every malformed command line exits 2 with empty standard output.
import os
import tempfile
from drydock_go import cli_runner
with tempfile.TemporaryDirectory() as d:
other = os.path.join(d, "other")
os.mkdir(other)
bad = [
[],
["--summary"],
["--min-size", "5"],
[d, other],
["--frobnicate", d],
["-h", d],
["--min-size", "abc", d],
["--min-size", "0", d],
["--min-size", "-5", d],
["--min-size", "+5", d],
["--min-size", "0x10", d],
["--min-size", "1e3", d],
["--min-size", "99999999999999999999999", d],
["--min-size", d],
[d, "--summary"],
]
for args in bad:
code, out, err = cli_runner(*args)
print(args, code, repr(out), repr(err))
assert code == 2, args
assert out == "", args
=== END AC argparse-usage-errors-exit-2 ===
=== AC argparse-diagnostic-on-stderr ===
Intent: A usage error writes exactly one diagnostic line to standard error.
from drydock_go import cli_runner
code, out, err = cli_runner("--min-size", "0", ".")
print(code, repr(out), repr(err))
assert code == 2
assert out == ""
assert len(err.splitlines()) == 1
=== END AC argparse-diagnostic-on-stderr ===
=== AC argparse-valid-forms-not-usage-errors ===
Intent: Well-formed command lines are not rejected as usage errors.
import tempfile
from drydock_go import cli_runner
with tempfile.TemporaryDirectory() as d:
valid = [
[d],
["--summary", d],
["--min-size", "5", d],
["--summary", "--min-size", "5", d],
["--min-size", "5", "--summary", d],
]
for args in valid:
code, out, err = cli_runner(*args)
print(args, code, repr(out), repr(err))
assert code != 2, args
=== END AC argparse-valid-forms-not-usage-errors ===
## User Acceptance
- None.
## Guardrails
- Standard library only; parsing uses `flag` with `flag.ContinueOnError`.
- Only `main` calls `os.Exit`; `Run` returns the code.
- A failing command writes nothing to standard output.
- Never touch any file under the directory examined.
</pblock>
<pblock filename="FEATURE-ModuleBuild.md" role="implements" path="/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/workspace/targets/DupFind/blueprint/FEATURE-ModuleBuild.md" guidance="Feature Specification">
# FEATURE: Module Build
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | The cmd/dupfind main package builds with go build using only the standard library and delegates to cli.Run. |
| Depends On | ARCHITECTURE.md, FEATURE-ArgParsing.md |
| Provides | cmd/dupfind |
| Consumes | cli.Run |
## Purpose
The application root is a Go module whose executable is the main package at `./cmd/dupfind`.
`go build ./cmd/dupfind` must succeed using only the standard library.
## Behavior
- `cmd/dupfind/main.go` is `package main`. `main` calls `cli.Run(os.Args[1:], os.Stdout, os.Stderr)` and passes the returned code to `os.Exit`.
- `main` contains no other logic and is the only caller of `os.Exit`.
- Every package in the build's dependency graph is either in the standard library or inside this module.
## Reads
Process arguments, standard output, standard error.
## Writes
None.
## Programmatic Acceptance
=== AC modbuild-go-build ===
Intent: go build ./cmd/dupfind succeeds and produces an executable.
import os
import subprocess
import sys
import tempfile
with tempfile.TemporaryDirectory() as d:
out_path = os.path.join(d, "dupfind")
result = subprocess.run(["go", "build", "-o", out_path, "./cmd/dupfind"], capture_output=True, text=True)
print(result.stdout)
print(result.stderr, file=sys.stderr)
assert result.returncode == 0
assert os.path.isfile(out_path)
=== END AC modbuild-go-build ===
=== AC modbuild-standard-library-only ===
Intent: The executable's dependency graph contains only standard library and in-module packages.
import pathlib
import subprocess
import sys
mod = ""
for line in pathlib.Path("go.mod").read_text().splitlines():
if line.startswith("module "):
mod = line.split()[1]
assert mod
result = subprocess.run(
["go", "list", "-deps", "-f", "{{if not .Standard}}{{.ImportPath}}{{end}}", "./cmd/dupfind"],
capture_output=True, text=True,
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
assert result.returncode == 0
for pkg in result.stdout.split():
assert pkg == mod or pkg.startswith(mod + "/"), pkg
=== END AC modbuild-standard-library-only ===
=== AC modbuild-executable-runs ===
Intent: The built executable runs and rejects an empty command line with exit 2.
from drydock_go import cli_runner
code, out, err = cli_runner()
print(code, repr(out), repr(err))
assert code == 2
assert out == ""
=== END AC modbuild-executable-runs ===
## User Acceptance
- None.
## Guardrails
- Standard library only; no third-party modules.
- `main` never reads `sources/run.sh` and embeds no digest, path, or total.
- Only `main` calls `os.Exit`.
</pblock>
<pblock filename="FEATURE-DirectoryValidation.md" role="implements" path="/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/workspace/targets/DupFind/blueprint/FEATURE-DirectoryValidation.md" guidance="Feature Specification">
# FEATURE: Directory Validation
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Exit 1 with empty standard output when the directory argument is missing or is not a directory. |
| Depends On | ARCHITECTURE.md, FEATURE-ArgParsing.md |
| Provides | cli.validateDirectory |
| Consumes | cli.Config |
## Purpose
After successful argument parsing, `cli.Run` checks that `Config.Dir` names an existing directory
before any walking or output.
## Behavior
- A nonexistent path, or a path that exists but is not a directory (for example a regular file), returns exit code 1.
- A failure writes nothing to stdout and exactly one diagnostic line to stderr.
- Validation runs after argument parsing and before the walk, so a usage error (exit 2) takes precedence over an operational failure (exit 1).
- An existing directory, empty or not, proceeds and the run succeeds with exit 0.
- The check uses `os.Stat`, so a symbolic link given as the directory argument that resolves to a directory is accepted.
## Reads
File metadata of the directory argument.
## Writes
Standard error only, on failure.
## Programmatic Acceptance
=== AC dirval-missing-directory ===
Intent: A nonexistent directory exits 1 with empty standard output and one stderr line.
import os
import tempfile
from drydock_go import cli_runner
with tempfile.TemporaryDirectory() as d:
missing = os.path.join(d, "no-such-directory")
for args in ([missing], ["--summary", missing], ["--min-size", "3", missing]):
code, out, err = cli_runner(*args)
print(args, code, repr(out), repr(err))
assert code == 1, args
assert out == "", args
assert len(err.splitlines()) == 1, args
=== END AC dirval-missing-directory ===
=== AC dirval-not-a-directory ===
Intent: A regular file given as the directory exits 1 with empty standard output.
import os
import tempfile
from drydock_go import cli_runner
with tempfile.TemporaryDirectory() as d:
path = os.path.join(d, "plain.txt")
with open(path, "w") as fh:
fh.write("content")
for args in ([path], ["--summary", path]):
code, out, err = cli_runner(*args)
print(args, code, repr(out), repr(err))
assert code == 1, args
assert out == "", args
=== END AC dirval-not-a-directory ===
=== AC dirval-usage-precedes-validation ===
Intent: A usage error on a nonexistent directory still exits 2, not 1.
import os
import tempfile
from drydock_go import cli_runner
with tempfile.TemporaryDirectory() as d:
missing = os.path.join(d, "no-such-directory")
code, out, err = cli_runner("--min-size", "0", missing)
print(code, repr(out), repr(err))
assert code == 2
assert out == ""
=== END AC dirval-usage-precedes-validation ===
=== AC dirval-existing-directory-succeeds ===
Intent: An existing empty directory is accepted and the run exits 0.
import tempfile
from drydock_go import cli_runner
with tempfile.TemporaryDirectory() as d:
code, out, err = cli_runner(d)
print(code, repr(out), repr(err))
assert code == 0
=== END AC dirval-existing-directory-succeeds ===
## User Acceptance
- None.
## Guardrails
- A failing command writes nothing to standard output.
- Validation never creates, modifies, or removes anything on disk.
</pblock>
<pblock filename="FEATURE-Walk.md" role="implements" path="/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/workspace/targets/DupFind/blueprint/FEATURE-Walk.md" guidance="Feature Specification">
# FEATURE: Walk
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Walk the directory recursively and yield eligible regular files at or above the minimum size. |
| Depends On | ARCHITECTURE.md, FEATURE-DirectoryValidation.md |
| Provides | walk.Files |
| Consumes | cli.Config |
## Purpose
`internal/walk` enumerates the files that may be considered for duplicate detection. It never opens
file contents.
## Interface
```go
package walk
type Entry struct {
Path string // relative to root, "/" separated, no leading "./"
Size int64
}
func Files(root string, minSize int64, warn io.Writer) ([]Entry, error)
```
## Behavior
- Traversal is recursive and includes hidden files and directories (names beginning `.`).
- Only regular files are returned. Entries are classified without following links (`os.Lstat` or the `fs.DirEntry` type).
- Symbolic links are neither followed nor reported, whether they point at files or directories. A directory reachable only through a symbolic link is not traversed.
- Files whose size is below `minSize` are ignored. Zero-byte files are never returned, even if `minSize` is below 1.
- Paths use `/` as the separator and no leading `./`.
- A subdirectory that cannot be read yields one warning line on `warn`, is skipped, and the walk continues. This does not change the exit code.
- Return order is unspecified; ordering is the responsibility of later stories.
## Reads
Directory listings and file metadata under the root.
## Writes
Warning lines on the `warn` writer only.
## Programmatic Acceptance
=== AC walk-rules ===
Intent: Walk returns hidden and nested regular files, omits symbolic links and zero-byte files, and honors the minimum size.
import os
import pathlib
import subprocess
import sys
mod = ""
for line in pathlib.Path("go.mod").read_text().splitlines():
if line.startswith("module "):
mod = line.split()[1]
assert mod
GO_TEST = """package walk_test
import (
"io"
"os"
"path/filepath"
"sort"
"testing"
"MODPATH/internal/walk"
)
func build(t *testing.T, files map[string]string) string {
root := t.TempDir()
for name, body := range files {
p := filepath.Join(root, filepath.FromSlash(name))
if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(p, []byte(body), 0o644); err != nil {
t.Fatal(err)
}
}
return root
}
func check(t *testing.T, root string, files map[string]string, min int) {
got, err := walk.Files(root, int64(min), io.Discard)
if err != nil {
t.Fatal(err)
}
var gotPaths []string
for _, e := range got {
gotPaths = append(gotPaths, e.Path)
if int(e.Size) != len(files[e.Path]) {
t.Errorf("size of %s = %d", e.Path, e.Size)
}
}
var want []string
for name, body := range files {
if len(body) >= min && len(body) > 0 {
want = append(want, name)
}
}
sort.Strings(gotPaths)
sort.Strings(want)
if len(gotPaths) != len(want) {
t.Fatalf("got %v want %v", gotPaths, want)
}
for i := range want {
if gotPaths[i] != want[i] {
t.Fatalf("got %v want %v", gotPaths, want)
}
}
}
func TestAcceptanceWalkEligibility(t *testing.T) {
files := map[string]string{"a.txt": "abc", ".hid/.x": "hidden", "sub/deep/f": "ff", "empty": "", "b": "z"}
root := build(t, files)
if err := os.Symlink("a.txt", filepath.Join(root, "link")); err != nil {
t.Fatal(err)
}
if err := os.Symlink("sub", filepath.Join(root, "dirlink")); err != nil {
t.Fatal(err)
}
check(t, root, files, 1)
}
func TestAcceptanceWalkMinSize(t *testing.T) {
files := map[string]string{"one": "a", "two": "ab", "three": "abc", "d/four": "abcd"}
root := build(t, files)
check(t, root, files, 3)
check(t, root, files, 1)
}
""".replace("MODPATH", mod)
target = pathlib.Path("internal/walk/zz_acceptance_test.go")
target.write_text(GO_TEST)
try:
result = subprocess.run(
["go", "test", "./internal/walk", "-run", "TestAcceptanceWalk", "-count=1", "-v"],
capture_output=True, text=True,
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
assert result.returncode == 0
finally:
if target.exists():
os.remove(target)
=== END AC walk-rules ===
=== AC walk-vet ===
Intent: The walk package compiles and passes go vet.
import subprocess
import sys
result = subprocess.run(["go", "vet", "./internal/walk"], capture_output=True, text=True)
print(result.stdout)
print(result.stderr, file=sys.stderr)
assert result.returncode == 0
=== END AC walk-vet ===
## User Acceptance
- None.
## Guardrails
- Never follow or report a symbolic link, and never traverse a directory reached only through one.
- Never open file contents in the walk.
- Never delete, move, or write any file under the directory examined.
- Zero-byte files are never reported.
</pblock>
<pblock filename="FEATURE-SizeGrouping.md" role="implements" path="/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/workspace/targets/DupFind/blueprint/FEATURE-SizeGrouping.md" guidance="Feature Specification">
# FEATURE: Size Grouping
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Group candidate files by exact size and keep only sizes shared by two or more files, so unique-size files are never read. |
| Depends On | FEATURE-Walk.md, ARCHITECTURE.md |
| Provides | dupes.GroupBySize |
| Consumes | walk.Files |
## Purpose
Rule 3 of the build instructions says files are grouped by size first and only files that share a
size are read. This feature implements that first stage in `internal/dupes`.
## Interface
`dupes.GroupBySize` takes the eligible files produced by `walk.Files` (relative path and size) and
returns size buckets. Only buckets with two or more files are returned. The size is taken from the
walk result; file contents are never opened in this stage. A file whose size is unique appears in
no bucket and is therefore never opened for hashing.
## Reads and Writes
- Reads: the in-memory walk result only.
- Writes: nothing.
## Required Project Tests
The project test suite in `internal/dupes` contains `TestGroupBySizeOmitsUniqueSizes` (a unique
size produces no bucket) and `TestGroupBySizeKeepsSharedSizes` (two or more files with one size
produce one bucket holding all of them).
## Programmatic Acceptance
=== AC size-unique-and-shared ===
Intent: Files with a unique size are never reported and a shared size with identical contents is reported.
import csv
import os
import tempfile
from drydock_go import cli_runner
def write(root, rel, data):
p = os.path.join(root, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, "wb") as f:
f.write(data)
shared = b"dddddd"
unique = b"cc"
with tempfile.TemporaryDirectory() as root:
write(root, "d1.bin", shared)
write(root, "sub/d2.bin", shared)
write(root, "c.bin", unique)
code, out, err = cli_runner(root)
print(out)
print(err)
assert code == 0
rows = list(csv.reader(out.splitlines()))[1:]
paths = sorted(r[3] for r in rows)
assert paths == ["d1.bin", "sub/d2.bin"]
=== END AC size-unique-and-shared ===
=== AC size-same-size-different-content ===
Intent: Files that share a size but differ in content are not reported as duplicates.
import csv
import os
import tempfile
from drydock_go import cli_runner
def write(root, rel, data):
p = os.path.join(root, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, "wb") as f:
f.write(data)
with tempfile.TemporaryDirectory() as root:
write(root, "a.bin", b"aaaa")
write(root, "b.bin", b"bbbb")
code, out, err = cli_runner(root)
print(out)
print(err)
assert code == 0
rows = list(csv.reader(out.splitlines()))
assert len(rows) == 1
=== END AC size-same-size-different-content ===
=== AC size-unit-tests ===
Intent: The project's own tests for the size bucketing pass and actually execute.
from drydock_go import run_test
result = run_test("./internal/dupes", "TestGroupBySizeOmitsUniqueSizes")
assert result.passed, (result.status, result.stdout, result.stderr)
result = run_test("./internal/dupes", "TestGroupBySizeKeepsSharedSizes")
assert result.passed, (result.status, result.stdout, result.stderr)
=== END AC size-unit-tests ===
## User Acceptance
- None.
## Guardrails
- Contents of a file whose size is unique are never opened.
- No file under the examined directory is modified, moved, or deleted.
- Only the standard library is used.
</pblock>
<pblock filename="FEATURE-DigestGrouping.md" role="implements" path="/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/workspace/targets/DupFind/blueprint/FEATURE-DigestGrouping.md" guidance="Feature Specification">
# FEATURE: Digest Grouping
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Hash same-size files with SHA-256 and form duplicate groups, skipping unreadable files with a stderr warning. |
| Depends On | FEATURE-SizeGrouping.md, ARCHITECTURE.md |
| Provides | dupes.GroupByDigest |
| Consumes | dupes.GroupBySize |
## Purpose
Rule 3 groups same-size files by the SHA-256 digest of their contents; a group of two or more files
with the same size and digest is a duplicate group. Rule 6 skips unreadable files with one warning.
## Interface
`dupes.GroupByDigest` takes the size buckets from `dupes.GroupBySize`. For each bucket it opens each
file read-only and streams it through `crypto/sha256`. The digest is the lowercase hexadecimal
encoding of the full contents. Files with identical size and digest form one group; groups with a
single member are dropped.
A file that cannot be opened or read yields exactly one warning line on standard error, is excluded
from grouping, and does not change the exit code. Files are opened read-only; nothing is written,
moved, or deleted under the examined directory.
## Reads and Writes
- Reads: the contents of files in shared-size buckets.
- Writes: warning lines to standard error only.
## Required Project Tests
`internal/dupes` contains `TestGroupByDigest` (identical contents group, same-size different
contents do not) and `TestGroupByDigestSkipsUnreadable` (an unreadable file is skipped with one
warning and does not fail the call).
## Programmatic Acceptance
=== AC digest-columns-match-contents ===
Intent: Reported size and sha256 are the byte length and lowercase SHA-256 of the fixture contents.
import csv
import hashlib
import os
import tempfile
from drydock_go import cli_runner
def write(root, rel, data):
p = os.path.join(root, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, "wb") as f:
f.write(data)
content = b"quarterly report\n"
with tempfile.TemporaryDirectory() as root:
write(root, "a/one.txt", content)
write(root, "b/two.txt", content)
write(root, "c/three.txt", content)
code, out, err = cli_runner(root)
print(out)
print(err)
assert code == 0
rows = list(csv.reader(out.splitlines()))[1:]
assert len(rows) == 3
for r in rows:
assert int(r[1]) == len(content)
assert r[2] == hashlib.sha256(content).hexdigest()
assert sorted(r[3] for r in rows) == ["a/one.txt", "b/two.txt", "c/three.txt"]
=== END AC digest-columns-match-contents ===
=== AC digest-splits-same-size-groups ===
Intent: Same-size files with different digests form separate groups and a lone digest is dropped.
import csv
import os
import tempfile
from drydock_go import cli_runner
def write(root, rel, data):
p = os.path.join(root, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, "wb") as f:
f.write(data)
first = b"abcd"
second = b"abce"
third = b"abcf"
with tempfile.TemporaryDirectory() as root:
write(root, "x1", first)
write(root, "x2", first)
write(root, "y1", second)
write(root, "y2", second)
write(root, "z1", third)
code, out, err = cli_runner(root)
print(out)
print(err)
assert code == 0
rows = list(csv.reader(out.splitlines()))[1:]
by_group = {}
for r in rows:
by_group.setdefault(r[0], []).append(r[3])
assert len(by_group) == 2
assert sorted(sorted(v) for v in by_group.values()) == [["x1", "x2"], ["y1", "y2"]]
=== END AC digest-splits-same-size-groups ===
=== AC digest-unreadable-skipped ===
Intent: An unreadable duplicate candidate is skipped without changing the exit code (skipped when permissions cannot be enforced).
import csv
import os
import tempfile
from drydock_go import cli_runner
def write(root, rel, data):
p = os.path.join(root, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, "wb") as f:
f.write(data)
content = b"same bytes\n"
with tempfile.TemporaryDirectory() as root:
write(root, "ok1.txt", content)
write(root, "ok2.txt", content)
write(root, "locked.txt", content)
os.chmod(os.path.join(root, "locked.txt"), 0)
try:
enforced = False
try:
open(os.path.join(root, "locked.txt"), "rb").close()
except PermissionError:
enforced = True
code, out, err = cli_runner(root)
print(out)
print(err)
assert code == 0
rows = list(csv.reader(out.splitlines()))[1:]
paths = sorted(r[3] for r in rows)
if enforced:
assert paths == ["ok1.txt", "ok2.txt"]
else:
assert paths == ["locked.txt", "ok1.txt", "ok2.txt"]
finally:
os.chmod(os.path.join(root, "locked.txt"), 0o600)
=== END AC digest-unreadable-skipped ===
=== AC digest-tree-unmodified ===
Intent: Running the tool leaves every file's bytes and the directory listing unchanged.
import os
import tempfile
from drydock_go import cli_runner
def write(root, rel, data):
p = os.path.join(root, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, "wb") as f:
f.write(data)
def snapshot(root):
snap = {}
for dirpath, dirnames, filenames in os.walk(root):
for n in filenames:
p = os.path.join(dirpath, n)
with open(p, "rb") as f:
snap[os.path.relpath(p, root)] = f.read()
for n in dirnames:
snap[os.path.relpath(os.path.join(dirpath, n), root) + "/"] = None
return snap
content = b"keep me\n"
with tempfile.TemporaryDirectory() as root:
write(root, "a/f1", content)
write(root, "b/f2", content)
write(root, "c/other", b"different!")
before = snapshot(root)
code, out, err = cli_runner(root)
print(out)
print(err)
assert code == 0
code, out, err = cli_runner("--summary", root)
assert code == 0
assert snapshot(root) == before
=== END AC digest-tree-unmodified ===
=== AC digest-unit-tests ===
Intent: The project's own digest grouping tests pass and actually execute.
from drydock_go import run_test
result = run_test("./internal/dupes", "TestGroupByDigest")
assert result.passed, (result.status, result.stdout, result.stderr)
result = run_test("./internal/dupes", "TestGroupByDigestSkipsUnreadable")
assert result.passed, (result.status, result.stdout, result.stderr)
=== END AC digest-unit-tests ===
## User Acceptance
- None.
## Guardrails
- Files are opened read-only; nothing under the examined directory is written, moved, or deleted.
- Warnings go to standard error only and never alter the exit code.
- Only the standard library is used; no digest or path is hardcoded.
</pblock>
<pblock filename="FEATURE-GroupOrdering.md" role="implements" path="/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/workspace/targets/DupFind/blueprint/FEATURE-GroupOrdering.md" guidance="Feature Specification">
# FEATURE: Group Ordering
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Compute reclaimable bytes per group, order and number the groups, and order paths within each group. |
| Depends On | FEATURE-DigestGrouping.md, ARCHITECTURE.md |
| Provides | dupes.Order |
| Consumes | dupes.GroupByDigest |
## Purpose
Rules 4 and 5 fix how paths are written and how groups and paths are ordered so output is
deterministic.
## Interface
`dupes.Order` takes the duplicate groups and returns them ordered and numbered.
- Reclaimable bytes of a group are `size x (files - 1)`.
- Groups are ordered by reclaimable bytes descending, then by digest ascending, and numbered from 1
in that order.
- Within a group, paths are ordered by byte value ascending (plain string comparison).
- Paths are relative to the examined directory, use `/` as the separator, and carry no leading `./`.
## Reads and Writes
- Reads: the in-memory groups.
- Writes: nothing.
## Required Project Tests
`internal/dupes` contains `TestOrder` covering reclaimable-first ordering, digest tie-breaking,
and byte-order paths.
## Programmatic Acceptance
=== AC order-by-reclaimable-then-digest ===
Intent: Groups appear by reclaimable bytes descending then digest ascending and are numbered from 1.
import csv
import hashlib
import os
import tempfile
from drydock_go import cli_runner
def write(root, rel, data):
p = os.path.join(root, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, "wb") as f:
f.write(data)
fixtures = {
b"0123456789": ["big/a", "big/b"],
b"xyz": ["s/1", "s/2", "s/3", "s/4", "s/5"],
b"tie-aa": ["t1/a", "t1/b"],
b"tie-bb": ["t2/a", "t2/b"],
b"tie-cc": ["t3/a", "t3/b"],
}
groups = []
for content, paths in fixtures.items():
groups.append((len(content) * (len(paths) - 1), hashlib.sha256(content).hexdigest(), len(content), sorted(paths)))
expected = sorted(groups, key=lambda g: (-g[0], g[1]))
with tempfile.TemporaryDirectory() as root:
for content, paths in fixtures.items():
for p in paths:
write(root, p, content)
code, out, err = cli_runner(root)
print(out)
print(err)
assert code == 0
rows = list(csv.reader(out.splitlines()))[1:]
seen = []
for r in rows:
if not seen or seen[-1][0] != r[0]:
seen.append((r[0], r[2], int(r[1]), []))
seen[-1][3].append(r[3])
assert [int(s[0]) for s in seen] == list(range(1, len(expected) + 1))
assert [s[1] for s in seen] == [g[1] for g in expected]
assert [s[3] for s in seen] == [g[3] for g in expected]
=== END AC order-by-reclaimable-then-digest ===
=== AC order-paths-byte-ascending ===
Intent: Paths within a group are in byte order and written relative with slash separators and no leading dot-slash.
import csv
import os
import tempfile
from drydock_go import cli_runner
def write(root, rel, data):
p = os.path.join(root, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, "wb") as f:
f.write(data)
content = b"order me\n"
paths = ["b.txt", "B.txt", "a b.txt", "a/z.txt", ".hid/x.txt", "a.txt"]
with tempfile.TemporaryDirectory() as root:
for p in paths:
write(root, p, content)
code, out, err = cli_runner(root)
print(out)
print(err)
assert code == 0
got = [r[3] for r in list(csv.reader(out.splitlines()))[1:]]
assert got == sorted(paths, key=lambda s: s.encode("utf-8"))
for g in got:
assert not g.startswith("./")
assert not g.startswith("/")
assert "\\" not in g
=== END AC order-paths-byte-ascending ===
=== AC order-reclaimable-beats-size ===
Intent: A smaller file with more copies precedes a larger file with fewer copies when it reclaims more bytes.
import csv
import hashlib
import os
import tempfile
from drydock_go import cli_runner
def write(root, rel, data):
p = os.path.join(root, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, "wb") as f:
f.write(data)
large = b"L" * 10
small = b"s" * 3
large_paths = ["l1", "l2"]
small_paths = ["s1", "s2", "s3", "s4", "s5"]
assert len(small) * (len(small_paths) - 1) > len(large) * (len(large_paths) - 1)
with tempfile.TemporaryDirectory() as root:
for p in large_paths:
write(root, p, large)
for p in small_paths:
write(root, p, small)
code, out, err = cli_runner(root)
print(out)
print(err)
assert code == 0
rows = list(csv.reader(out.splitlines()))[1:]
assert rows[0][2] == hashlib.sha256(small).hexdigest()
assert rows[0][0] == rows[len(small_paths) - 1][0]
assert rows[len(small_paths)][2] == hashlib.sha256(large).hexdigest()
=== END AC order-reclaimable-beats-size ===
=== AC order-unit-tests ===
Intent: The project's own ordering test passes and actually executes.
from drydock_go import run_test
result = run_test("./internal/dupes", "TestOrder")
assert result.passed, (result.status, result.stdout, result.stderr)
=== END AC order-unit-tests ===
## User Acceptance
- None.
## Guardrails
- Ordering is deterministic and independent of directory enumeration order and locale.
- Paths never contain a leading `./` or a backslash separator.
</pblock>
<pblock filename="FEATURE-Listing.md" role="implements" path="/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/workspace/targets/DupFind/blueprint/FEATURE-Listing.md" guidance="Feature Specification">
# FEATURE: Listing
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Write the CSV duplicate listing with header group,size,sha256,path using encoding/csv and wire the default mode of cli.Run. |
| Depends On | FEATURE-GroupOrdering.md, FEATURE-ModuleBuild.md, ARCHITECTURE.md |
| Provides | report.WriteListing |
| Consumes | dupes.Order |
## Purpose
The default output of `dupfind <directory>` is a CSV listing of every file in every duplicate group.
## Interface
`report.WriteListing` writes to standard output through `encoding/csv` with `\n` line endings
(`UseCRLF` false). The header row is `group,size,sha256,path`. One row follows per file of every
ordered group: group number, size in bytes, lowercase hexadecimal SHA-256, relative path. With no
duplicates only the header is written. Fields containing a comma, a double quote, or a newline are
quoted as RFC 4180 specifies, by the csv writer.
The default (non-summary) mode of `cli.Run` runs the walk, size grouping, digest grouping, and
ordering with the configured `--min-size`, then this writer, and returns 0. `--min-size` excludes
files smaller than the given number of bytes.
## Reads and Writes
- Reads: ordered groups.
- Writes: CSV to standard output only.
## Programmatic Acceptance
=== AC listing-full-output ===
Intent: The entire standard output equals the CSV the standard csv writer produces from the fixture-derived rows.
import csv
import hashlib
import io
import os
import tempfile
from drydock_go import cli_runner
def write(root, rel, data):
p = os.path.join(root, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, "wb") as f:
f.write(data)
fixtures = {
b"alpha alpha\n": ["a/one.txt", "b/two.txt", "c/deep/three.txt"],
b"beta\n": [".hidden/.env", "env.bak"],
}
header = ["group", "size", "sha256", "path"]
groups = []
for content, paths in fixtures.items():
groups.append((len(content) * (len(paths) - 1), hashlib.sha256(content).hexdigest(), len(content), sorted(paths)))
groups.sort(key=lambda g: (-g[0], g[1]))
buf = io.StringIO()
w = csv.writer(buf, lineterminator="\n")
w.writerow(header)
for n, g in enumerate(groups, start=1):
for p in g[3]:
w.writerow([n, g[2], g[1], p])
expected = buf.getvalue()
with tempfile.TemporaryDirectory() as root:
for content, paths in fixtures.items():
for p in paths:
write(root, p, content)
code, out, err = cli_runner(root)
print(out)
print(err)
assert code == 0
assert out == expected
assert "\r" not in out
=== END AC listing-full-output ===
=== AC listing-csv-quoting ===
Intent: Paths containing a comma or a double quote survive a CSV round trip unchanged.
import csv
import os
import tempfile
from drydock_go import cli_runner
def write(root, rel, data):
p = os.path.join(root, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, "wb") as f:
f.write(data)
content = b"quote me\n"
paths = ["song,live.mp3", 'say "hi".txt', "plain.txt"]
with tempfile.TemporaryDirectory() as root:
for p in paths:
write(root, p, content)
code, out, err = cli_runner(root)
print(out)
print(err)
assert code == 0
rows = list(csv.reader(out.splitlines()))
assert all(len(r) == 4 for r in rows)
assert sorted(r[3] for r in rows[1:]) == sorted(paths)
=== END AC listing-csv-quoting ===
=== AC listing-header-only-when-no-duplicates ===
Intent: A directory without duplicates (or with only zero-byte files) yields the header row only, with exit 0.
import csv
import os
import tempfile
from drydock_go import cli_runner
def write(root, rel, data):
p = os.path.join(root, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, "wb") as f:
f.write(data)
with tempfile.TemporaryDirectory() as root:
write(root, "solo.txt", b"only one of me\n")
write(root, "empty/one", b"")
write(root, "empty/two", b"")
code, out, err = cli_runner(root)
print(out)
print(err)
assert code == 0
assert out.splitlines() == ["group,size,sha256,path"]
assert out.endswith("\n")
=== END AC listing-header-only-when-no-duplicates ===
=== AC listing-min-size ===
Intent: Files smaller than --min-size are excluded from the listing while larger duplicates remain.
import csv
import os
import tempfile
from drydock_go import cli_runner
def write(root, rel, data):
p = os.path.join(root, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, "wb") as f:
f.write(data)
small = b"tiny"
large = b"L" * 50
threshold = len(small) + 1
with tempfile.TemporaryDirectory() as root:
write(root, "s1", small)
write(root, "s2", small)
write(root, "l1", large)
write(root, "l2", large)
code, out, err = cli_runner("--min-size", str(threshold), root)
print(out)
print(err)
assert code == 0
rows = list(csv.reader(out.splitlines()))[1:]
assert sorted(r[3] for r in rows) == ["l1", "l2"]
code, out, err = cli_runner(root)
assert code == 0
rows = list(csv.reader(out.splitlines()))[1:]
assert len(rows) == 4
=== END AC listing-min-size ===
=== AC listing-symlinks-and-hidden ===
Intent: Hidden files are listed while symbolic links are neither followed nor reported.
import csv
import os
import tempfile
from drydock_go import cli_runner
def write(root, rel, data):
p = os.path.join(root, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, "wb") as f:
f.write(data)
content = b"KEY=1\n"
with tempfile.TemporaryDirectory() as root:
write(root, ".hidden/.env", content)
write(root, "env.bak", content)
os.symlink(os.path.join(root, "env.bak"), os.path.join(root, "link.bak"))
os.symlink(os.path.join(root, ".hidden"), os.path.join(root, "linkdir"))
code, out, err = cli_runner(root)
print(out)
print(err)
assert code == 0
rows = list(csv.reader(out.splitlines()))[1:]
assert sorted(r[3] for r in rows) == [".hidden/.env", "env.bak"]
=== END AC listing-symlinks-and-hidden ===
## User Acceptance
- None.
## Guardrails
- Output is produced with `encoding/csv`; fields are never concatenated by hand.
- A failing command writes nothing to standard output.
- No file under the examined directory is modified, moved, or deleted.
</pblock>
<pblock filename="FEATURE-Summary.md" role="implements" path="/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/workspace/targets/DupFind/blueprint/FEATURE-Summary.md" guidance="Feature Specification">
# FEATURE: Summary
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Write the one-row CSV summary of groups, duplicate files, and reclaimable bytes when --summary is given. |
| Depends On | FEATURE-Listing.md, ARCHITECTURE.md |
| Provides | report.WriteSummary |
| Consumes | dupes.Order |
## Purpose
With `--summary` the tool reports the totals of the listing that the same options would produce,
instead of the listing itself.
## Interface
`report.WriteSummary` writes, through `encoding/csv` with `\n` line endings, the header
`groups,duplicate_files,reclaimable_bytes` and one row:
- `groups`: the number of duplicate groups.
- `duplicate_files`: the sum of `files - 1` over all groups.
- `reclaimable_bytes`: the sum of every group's `size x (files - 1)`.
With no duplicates the row is `0,0,0`. The `--summary` mode of `cli.Run` uses the same walk,
grouping, and ordering as the listing, with the same `--min-size`, and returns 0.
## Reads and Writes
- Reads: ordered groups.
- Writes: CSV to standard output only.
## Programmatic Acceptance
=== AC summary-totals-match-fixture ===
Intent: The summary row equals totals computed from the fixture's known duplicate structure.
import csv
import os
import tempfile
from drydock_go import cli_runner
def write(root, rel, data):
p = os.path.join(root, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, "wb") as f:
f.write(data)
fixtures = {
b"quarterly report\n": ["a/r.txt", "b/r2.txt", "c/r3.txt"],
b"la la la\n": ["m/s.mp3", "m/s2.mp3"],
b"unique content here\n": ["u/solo"],
}
dup_groups = [(c, p) for c, p in fixtures.items() if len(p) > 1]
want_groups = len(dup_groups)
want_files = sum(len(p) - 1 for c, p in dup_groups)
want_bytes = sum(len(c) * (len(p) - 1) for c, p in dup_groups)
with tempfile.TemporaryDirectory() as root:
for content, paths in fixtures.items():
for p in paths:
write(root, p, content)
code, out, err = cli_runner("--summary", root)
print(out)
print(err)
assert code == 0
rows = list(csv.reader(out.splitlines()))
assert len(rows) == 2
assert rows[0] == ["groups", "duplicate_files", "reclaimable_bytes"]
assert [int(x) for x in rows[1]] == [want_groups, want_files, want_bytes]
=== END AC summary-totals-match-fixture ===
=== AC summary-no-duplicates ===
Intent: With no duplicates the summary row holds three zeros and exit status is 0.
import csv
import os
import tempfile
from drydock_go import cli_runner
def write(root, rel, data):
p = os.path.join(root, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, "wb") as f:
f.write(data)
with tempfile.TemporaryDirectory() as root:
write(root, "empty/one", b"")
write(root, "empty/two", b"")
code, out, err = cli_runner("--summary", root)
print(out)
print(err)
assert code == 0
rows = list(csv.reader(out.splitlines()))
assert len(rows) == 2
assert [int(x) for x in rows[1]] == [0, 0, 0]
=== END AC summary-no-duplicates ===
=== AC summary-agrees-with-listing ===
Intent: The summary totals equal the totals derived from the listing produced by the same options, including --min-size.
import csv
import os
import tempfile
from drydock_go import cli_runner
def write(root, rel, data):
p = os.path.join(root, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, "wb") as f:
f.write(data)
fixtures = {
b"S" * 4: ["s1", "s2"],
b"M" * 30: ["m1", "m2", "m3"],
b"B" * 200: ["b1", "b2"],
}
with tempfile.TemporaryDirectory() as root:
for content, paths in fixtures.items():
for p in paths:
write(root, p, content)
for opts in ([], ["--min-size", "20"], ["--min-size", "100"], ["--min-size", "1000"]):
code, listing, err = cli_runner(*opts, root)
assert code == 0
rows = list(csv.reader(listing.splitlines()))[1:]
per_group = {}
for r in rows:
per_group.setdefault(r[0], []).append(int(r[1]))
want = [
len(per_group),
sum(len(v) - 1 for v in per_group.values()),
sum(v[0] * (len(v) - 1) for v in per_group.values()),
]
code, summ, err = cli_runner("--summary", *opts, root)
print(summ)
print(err)
assert code == 0
srows = list(csv.reader(summ.splitlines()))
assert len(srows) == 2
assert [int(x) for x in srows[1]] == want
=== END AC summary-agrees-with-listing ===
=== AC summary-unit-tests ===
Intent: The project's own summary tests pass and actually execute.
from drydock_go import run_test
result = run_test("./internal/report", "TestWriteSummary")
assert result.passed, (result.status, result.stdout, result.stderr)
=== END AC summary-unit-tests ===
## User Acceptance
- None.
## Guardrails
- The summary never prints the listing and the listing never prints the summary.
- Output is produced with `encoding/csv`.
- No file under the examined directory is modified, moved, or deleted.
</pblock>
<pblock filename="FEATURE-TestGate.md" role="implements" path="/mnt/c/Users/barlo/projects/drydock/uat/DupFind/runs/20261025.174005/workspace/targets/DupFind/blueprint/FEATURE-TestGate.md" guidance="Feature Specification">
# FEATURE: Test Gate
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Provide the POSIX bin/test.sh launcher and a Go test suite that covers every rule, output form, and exit code of dupfind against real temporary directories. |
| Depends On | FEATURE-ModuleBuild.md, FEATURE-DirectoryValidation.md, FEATURE-Listing.md, FEATURE-Summary.md |
| Provides | bin/test.sh |
| Consumes | cli.Run |
## Purpose
The application needs one command that decides whether the code is healthy. `bin/test.sh` runs
`go vet ./...` and then `go test ./...` from the application root and exits zero only when both
pass. The Go test suite behind it exercises the finished tool, so a regression in any earlier story
turns this gate red.
## Trigger
A developer, the build engine, or the terminal verification story runs `sh bin/test.sh`.
## Sequence
1. `bin/test.sh` is POSIX `sh`: no bashisms, no arrays, no `[[ ]]`.
2. It derives the application root from the script's own location (`dirname "$0"`/`..`), changes
into it, so the result is the same from any working directory.
3. It runs `go vet ./...`. A non-zero status stops the script with that non-zero status.
4. It runs `go test ./...`. Its status becomes the script's exit status.
5. The script exits `0` only when both commands succeeded.
## Test Suite Coverage
The Go test suite lives in `*_test.go` files beside the packages under `internal/`. Tests call
`cli.Run(args, &stdout, &stderr)` with `bytes.Buffer` writers over real directories made with
`t.TempDir()`, and parse standard output with `encoding/csv`. Expectations are written against
observed real output. Each rule has at least one test named for the behavior:
| Area | Behavior covered |
|---|---|
| Scope | Hidden files and hidden directories are walked; nested directories are walked |
| Scope | A symbolic link to a file is neither followed nor reported; a link to a directory is not traversed |
| Empty files | Zero-byte files are never reported, including with an explicit small `--min-size` |
| Minimum size | Files below `--min-size` are ignored; the default is 1 |
| Duplicate test | Same size but different content is not a duplicate; same size and content is |
| Duplicate test | Files with a unique size are never opened for hashing |
| Paths | Relative to the directory, `/` separator, no leading `./` |
| Order | Groups by reclaimable bytes descending then digest ascending, numbered from 1; paths by byte value |
| Unreadable | An unreadable file is skipped, one warning on stderr, exit code unchanged (skipped when running as root) |
| Listing | Header `group,size,sha256,path`; header only when there are no duplicates |
| CSV quoting | A path containing a comma is quoted and round-trips through `encoding/csv` |
| Summary | Header `groups,duplicate_files,reclaimable_bytes`; `0,0,0` when there are no duplicates; totals equal those of the listing under the same options |
| Exit codes | `0` for success with or without duplicates; `1` for a missing directory or a regular file; `2` for no arguments, extra arguments, unknown option, `--min-size` of `abc` and of `0` |
| Failure output | Exit codes 1 and 2 write nothing to standard output |
## Reads
- The application source tree, through `go vet` and `go test`.
## Writes
- Nothing outside temporary directories created by the tests themselves. The suite never writes
under any directory the tool examines other than the temporary fixture it created.
## Programmatic Acceptance
=== AC test-script-exits-zero ===
Intent: bin/test.sh runs go vet and go test on the finished application and exits zero.
Requires: executable=sh; scope=test
Requires: executable=go; scope=test
import subprocess
import sys
result = subprocess.run(["sh", "bin/test.sh"], capture_output=True, text=True)
print(result.stdout)
print(result.stderr, file=sys.stderr)
assert result.returncode == 0, result.returncode
=== END AC test-script-exits-zero ===
=== AC test-script-posix-syntax ===
Intent: bin/test.sh exists and parses as POSIX sh without executing.
Requires: executable=sh; scope=test
import os
import subprocess
import sys
script = os.path.join("bin", "test.sh")
assert os.path.isfile(script)
result = subprocess.run(["sh", "-n", script], capture_output=True, text=True)
print(result.stdout)
print(result.stderr, file=sys.stderr)
assert result.returncode == 0, result.returncode
=== END AC test-script-posix-syntax ===
=== AC test-script-fails-on-failing-test ===
Intent: bin/test.sh exits non-zero when any Go test fails, proven on a temporary copy of the application.
Requires: executable=sh; scope=test
Requires: executable=go; scope=test
import os
import shutil
import subprocess
import sys
import tempfile
root = os.getcwd()
failing_test = 'package cli\n\nimport "testing"\n\nfunc TestForcedFailure(t *testing.T) {\n\tt.Fatal("forced")\n}\n'
with tempfile.TemporaryDirectory() as tmp:
dst = os.path.join(tmp, "app")
shutil.copytree(root, dst, ignore=shutil.ignore_patterns(".git"))
with open(os.path.join(dst, "internal", "cli", "zz_forced_failure_test.go"), "w") as handle:
handle.write(failing_test)
result = subprocess.run(["sh", "bin/test.sh"], cwd=dst, capture_output=True, text=True)
print(result.stdout)
print(result.stderr, file=sys.stderr)
assert result.returncode != 0, result.returncode
=== END AC test-script-fails-on-failing-test ===
=== AC test-script-independent-of-cwd ===
Intent: bin/test.sh locates the application root itself, so running it from another directory still exits zero.
Requires: executable=sh; scope=test
Requires: executable=go; scope=test
import os
import subprocess
import sys
import tempfile
script = os.path.abspath(os.path.join("bin", "test.sh"))
with tempfile.TemporaryDirectory() as elsewhere:
result = subprocess.run(["sh", script], cwd=elsewhere, capture_output=True, text=True)
print(result.stdout)
print(result.stderr, file=sys.stderr)
assert result.returncode == 0, result.returncode
=== END AC test-script-independent-of-cwd ===
=== AC suite-has-tests-for-cli ===
Intent: The Go test suite contains test files for the cli package and they pass when run alone.
Requires: executable=go; scope=test
import glob
import os
import subprocess
import sys
test_files = glob.glob(os.path.join("internal", "cli", "*_test.go"))
assert len(test_files) >= 1, test_files
result = subprocess.run(
["go", "test", "-count=1", "./internal/cli"], capture_output=True, text=True
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
assert result.returncode == 0, result.returncode
=== END AC suite-has-tests-for-cli ===
=== AC built-binary-exit-codes ===
Intent: The built executable exits 0 for a directory, 1 for a missing path, and 2 for each malformed argument form the suite covers.
Requires: executable=go; scope=test
import os
import tempfile
from drydock_go import cli_runner
with tempfile.TemporaryDirectory() as tree:
payload = "same bytes\n"
for name in ("one.txt", "two.txt"):
with open(os.path.join(tree, name), "w") as handle:
handle.write(payload)
missing = os.path.join(tree, "no-such-directory")
regular = os.path.join(tree, "one.txt")
ok_code, ok_out, ok_err = cli_runner(tree)
assert ok_code == 0, (ok_code, ok_out, ok_err)
missing_code, missing_out, missing_err = cli_runner(missing)
assert missing_code == 1, (missing_code, missing_out, missing_err)
assert missing_out == ""
file_code, file_out, file_err = cli_runner(regular)
assert file_code == 1, (file_code, file_out, file_err)
assert file_out == ""
for args in ([], [tree, tree], ["--min-size", "abc", tree], ["--min-size", "0", tree], ["--frobnicate", tree]):
code, out, err = cli_runner(*args)
print(args, code, err)
assert code == 2, (args, code, out, err)
assert out == "", (args, out)
=== END AC built-binary-exit-codes ===
## User Acceptance
- None.
## Guardrails
- `bin/test.sh` is POSIX `sh`; it does not require bash.
- The test suite never reads `sources/run.sh` and never embeds a digest, path, or total taken from it.
- Tests write only inside temporary directories they create; nothing under a directory the tool examines is deleted, moved, or modified by the tool.
- The tool is built with the standard library only; no third-party module is added for testing.
</pblock>
<pblock label="Build instructions" kind="instructions">
Build instructions for this block
Parse --summary, --min-size, and exactly one directory argument; reject malformed usage with exit 2. (arg-parsing)
Implement Run in internal/cli using a local flag.FlagSet with flag.ContinueOnError and its output discarded. Options precede the directory; exactly one directory argument is required.
Missing or extra arguments, an unknown option, a help flag, or a --min-size value that is not a positive decimal integer (no sign, no zero, no non-decimal forms) return 2 with empty stdout and one diagnostic line on stderr. The default min-size is 1.
Produce a parsed configuration (summary flag, min size, directory) for later stories.
Provide the cmd/dupfind main package that builds with go build and delegates to cli.Run. (module-build)
Write cmd/dupfind/main.go so main calls cli.Run(os.Args[1:], os.Stdout, os.Stderr) and passes the result to os.Exit. go build ./cmd/dupfind must succeed using only the standard library.
Exit 1 with empty stdout when the directory is missing or is not a directory. (directory-validation)
After successful argument parsing, stat the directory. A nonexistent path or a path that is not a directory returns exit 1 with nothing on stdout and one diagnostic line on stderr. Validation happens before any walking or output.
Walk the directory recursively and yield eligible regular files at or above the minimum size. (walk)
Implement walk.Files in internal/walk, returning each eligible file's relative path (slash separated, no leading ./) and size.
Traverse hidden files and directories. Consider regular files only: symbolic links are neither followed nor reported, and directories reached only through a symbolic link are not traversed. Ignore files smaller than min-size; zero-byte files are never returned. Use lstat semantics (os.Lstat or DirEntry type) and never open file contents here.
A subdirectory that cannot be read yields one stderr warning and the walk continues.
Group candidate files by exact size and keep only sizes shared by two or more files. (size-grouping)
Implement dupes.GroupBySize, returning only size buckets with at least two files. A file whose size is unique is never opened for hashing. The size is taken from the walk result, not from reading contents.
Hash same-size files with SHA-256 and form duplicate groups, skipping unreadable files with a warning. (digest-grouping)
For each same-size bucket, open each file read-only and stream it through crypto/sha256. The digest is lowercase hexadecimal of the full contents. Files with identical size and digest form one group of two or more files.
A file that cannot be opened or read yields exactly one warning line on stderr, is excluded from grouping, and does not change the exit code. Never delete, move, or write any file under the examined directory.
Compute reclaimable bytes, order groups, number them from 1, and order paths within each group. (group-ordering)
Reclaimable bytes per group equal size x (files - 1). Order groups by reclaimable bytes descending, then digest ascending, and number them from 1. Within a group order paths by byte value ascending (plain string comparison, not locale aware). Paths are relative to the directory with / separators and no leading ./.
Write the CSV duplicate listing with header group,size,sha256,path using encoding/csv. (listing)
Implement report.WriteListing with encoding/csv: header group,size,sha256,path, then one row per file in every ordered group. With no duplicates write only the header. Line endings are \n (Writer.UseCRLF false). Fields containing a comma, double quote, or newline are quoted by the csv writer.
Wire the default (non-summary) mode of cli.Run through walk, grouping, ordering, and this writer, exit 0.
Write the one-row summary of groups, duplicate files, and reclaimable bytes with --summary. (summary)
Implement report.WriteSummary with encoding/csv: header groups,duplicate_files,reclaimable_bytes then one row. duplicate_files is the sum of (files - 1) over groups; reclaimable_bytes is the sum of every group's reclaimable bytes. With no duplicates the row is 0,0,0.
Wire --summary mode of cli.Run to this writer using the same walk and grouping as the listing with the same --min-size, exit 0.
Provide POSIX bin/test.sh and a Go test suite covering every rule, output form, and exit code. (test-gate)
Write bin/test.sh as POSIX sh: cd to the application root, run go vet ./... then go test ./..., and exit non-zero if either fails.
Ensure the Go test suite, using real temporary directories and Run with bytes.Buffer, covers each rule (hidden files, symlinks, zero-byte, min-size, size-then-digest, ordering, path form, unreadable skip), each output form (listing, summary, empty cases), and each exit code (0, 1, 2). Expectations in tests are written against observed real output.
</pblock>
Agent Task
You are a Drydock build agent implementing exactly one build step of a larger plan. The build job block below names the target, the build working directory, and the step. Everything you need is stacked into this prompt under role headings:
compass— the Target's COMPASS.md orientation.implements— the Typed Specification files this step builds. These are
authoritative; implement them exactly.
context— read-only support specifications. Do not reimplement them.stack— enterprise stack and technology rules. Honor them.rules— governance and branding rules. Honor them.
Operating contract:
- Follow the write authorization and protected paths in the stacked
COMPASS.mdexactly.
That persisted guardrail is the sole authority for paths this build may modify.
- Start by inspecting the build working directory. Preserve existing application
files unless this step's specifications require a change. Its sources/ subdirectory holds staged build assets — imported test corpora, conformance harnesses, and fixtures — placed there for you. They are read-only inputs: run them, import them, and write code against them, but never create, rewrite, trim, regenerate, or substitute one, even to make a check pass. A step that modifies a staged asset fails and the asset is restored. If an asset you expect is absent, report that; do not author a replacement.
- Implement only this step. Use
context,stack, andrulesas constraints,
not as additional work to perform.
- Follow the stack and rules for languages, structure, naming, and branding.
- The programmatic acceptance assertions in the
implementsspecifications are
this step's Definition of Done — human-owned, declared before the build, and fixed. Build the story and, in this same step, write the deterministic tests that prove each declared assertion, as a TDD master would; add finer tests for coverage. Every test you write follows the same rule the acceptance assertions do: act on the system, read the state back, compare to expected. The oracle is a return value, parsed JSON, a status code, a stored row, file contents read back, or an exit status — never a substring of captured stdout or stderr, a test-runner tally, or a log line. Write tests in the project's own language using that language's libraries; an in-language HTTP client yields a status code and a parsed body, where curl yields text to scrape. Round-trip anything that stores state: act, then read back through the public interface. Assert declared failure signals on negative paths, never message wording. You may add tests but must never remove, soften, or weaken a declared acceptance assertion. A Suite: full conformance check gates on the entire imported test suite: the step is done only when it passes in full, never on a representative subset — reproduce the standard exactly rather than wrapping a third-party library that approximates it. For a suite, the runner's exit status is the verdict and the whole verdict: print its captured output for diagnosis, never assert on the text of its summary. When an assertion is a static or filesystem scan (import boundary, "X never appears outside Y," grep/AST gate), honor the scope the specification states and never widen it: scan production source only, exclude .venv/, site-packages, and vendored or generated code, and do not flag test doubles or fixtures that use the guarded dependency. Run every declared acceptance assertion before returning. For a conformance suite, use its section or example filters to diagnose coherent root-cause clusters, but rerun the full declared scope before reporting the result. Treat failing examples as a work queue for fixing general behavior; never add example-specific exceptions.
- Grow the project's own test suite as you write the code, and treat it as the project's
real coverage. The acceptance assertions in implements are gates: few, fixed, and written before any code existed, so every expectation in them is a prediction. The tests you write are written beside the finished code, so their expected values are observed rather than predicted — which is why exhaustive coverage belongs here and not there. Extend the suite in the project's established location and runner, keep it runnable by the project's declared test command, and leave it green when you return. Cover, at minimum: every public entry point and every verb it declares, including declared error paths; the boundaries — empty, exactly one, many, absent optional fields, declared maxima; declared idempotence, applied twice; one behavior per test, named for the behavior; and isolation — database criteria use the provisioned application store and the shipped rollback fixture, passing its connection into the feature. Other connections and durability tests use criterion-owned records, idempotent setup and checked cleanup through supported interfaces. Never replace the configured store, reapply schema, or delete unrelated business records. Where a staged authoritative suite already covers a surface, that suite is the coverage: run it, and do not restate its cases. Run it only through the invocation this step's acceptance criteria declare. A criterion marked Suite: scoped names the whole of this step's obligation to that suite; running the suite's unscoped entry point instead is not extra rigor, it is a different step's gate executed early. A partial capability fails most of an authoritative corpus by construction and its unimplemented cases exhaust the runner's per-case timeout rather than returning, so the unscoped run costs the most where it teaches the least, and interrupting it forfeits the step. If no criterion in this step invokes the staged suite, do not invoke it. Report the pass/fail counts of the invocations you did run in your SUMMARY so a reader can see coverage moving across steps.
- Treat
User Acceptanceentries as review evidence requirements. Implement
the supporting behavior, but do not claim to have performed human judgment.
- The
implementssection is authoritative and intentionally stacked late in
the prompt as the recency anchor. Build that WHAT exactly; do not substitute generic framework defaults.
- Before adding or installing Python dependencies, verify each package name
against the declared registry. Do not invent package names. If a needed package cannot be verified or appears newly published, fail explicitly instead of installing it.
- Use the stack's required package manager workflow for dependency changes.
When the stack requires uv, update manifests through uv conventions rather than bare pip install.
- Do not claim success unless you actually created or modified project files in
the build working directory. If you cannot write files or cannot complete the step, report failure explicitly.
- Do not run
git add,git commit, create branches, create tags, rewrite
history, or otherwise mutate Git history. Drydock checkpoints application changes and Target evidence after each execution and completed step. File lineage comes from Git and the Manifest's implements: entries; no additional attribution response is required.
- End your response with this exact closing structure:
RESULT: SUCCESS | FAILED
FILES CHANGED:
- relative/path
SUMMARY:
<brief reviewable summary>
BLOCKERS:
- <only if any>
Before RESULT, you may emit one optional JSON payload when implementation required a bounded choice not already settled by the owning specification. This records what you did; it does not ask permission, create a questionnaire, or excuse incomplete work:
<blueprint-decisions>
[{"spec":"FEATURE-Example.md","severity":"Material","subject":"Chosen behavior","decision":"Options A and B were available. I implemented B because ... Is that acceptable, or should this change on replan?"}]
</blueprint-decisions>
Name only a specification implemented by this build block. Use Low or Material; Build never emits a Blocking decision. Omit the payload when no implementation decision was necessary.
FILES CHANGEDmust list only files actually written in the build working
directory. When the existing implementation already satisfies this step, report RESULT: SUCCESS, list no changed files, and state the checks performed and their results. A verification-only step requires no application changes. Drydock runs the declared deterministic checks and decides the outcome independently of this report.
- On
RESULT: FAILED, append two additional lines so the failure is actionable
without opening logs. FAILURE_SUMMARY is one line naming the cause; FAILURE_DETAIL states what happened, why, and what to change before a rerun. Name concrete conditions when they apply: token or context limit exceeded, could not execute commands in this environment, a required input was missing, or a specific tool or command failed.
FAILURE_SUMMARY: <one line naming the cause>
FAILURE_DETAIL: <what happened, why, and what to change before rerunning>
- When a declared acceptance criterion cannot pass no matter how the code is written,
say so with this exact token. You may not edit the criterion — it is staged and restored before grading:
AC_BROKEN: <check-id>[, <check-id>]
This is a report, not a verdict, and it stops nothing. A criterion reaches you only when its expected value is one its author could not have invented — a status code, a staged suite's exit status, a value the criterion itself supplied as input — so your claim that the criterion rather than the code is at fault is the less likely explanation, and the budget is spent as it would be for any other failure. A criterion whose expectation was hand-typed already settles DISPUTED on its own, without you naming it. Emit the token only after running the criterion and confirming the underlying command succeeded while the assertion still failed. Name the affected check ids, emit it alongside your normal RESULT line, state the reasoning in FAILURE_DETAIL, and emit it even when RESULT: SUCCESS. Do not use it for a criterion you merely failed to satisfy.