=== BEGIN ARTIFACT ARCHITECTURE.md === # ARCHITECTURE: DupFind | Field | Value | |-------------|-------| | Version | 20261024 V1 | | Description | Defines the Go module and package boundaries for the dupfind command-line application. | | Depends On | | | Provides | Go module and application package layout | | Consumes | | ## Questions - None. ## Purpose DupFind is a Go command-line application that recursively scans a requested directory and reports regular files with byte-for-byte identical contents. The executable is `./cmd/dupfind`; implementation uses Go 1.22 or newer and the standard library only. ## Modules and ownership | Module | Owns | Allowed low-level access | |---|---|---| | `cmd/dupfind` | Process startup and exit status | `os.Args`, `os.Exit`, standard streams | | `internal/cli` | Argument parsing, validation, command flow, diagnostics, and output selection | Standard library; delegates scanning and formatting | | `internal/scan` | Directory traversal, candidate selection, content hashing, and duplicate groups | Read-only filesystem access and SHA-256 | | `internal/output` | Deterministic ordering and CSV listing or summary formatting | `encoding/csv` and standard library | Only `cmd/dupfind` calls `os.Exit`. CLI behavior is exposed through `Run(args []string, stdout, stderr io.Writer) int` so it can be exercised without terminating the test process. The CLI uses a local `flag.FlagSet` with `flag.ContinueOnError`. ## Data flow The CLI validates options and the directory argument, confirms the path names a directory, and calls the scanner with the minimum size. The scanner walks the tree without following symbolic links, selects regular files at or above the minimum size, and reads file contents only when at least two selected files share a size. It groups candidates by SHA-256 digest and returns duplicate groups. The output package orders groups and paths, then writes listing or summary CSV. Scanner and output interfaces use in-memory Go types; no persistent state or external service is used. Diagnostics are written to standard error. A failing command leaves standard output empty. ## Technology Stack - Go 1.22 or newer, standard library only: module, executable, CLI, scanning, formatting, and tests. - POSIX shell: project test entry point and supplied grader. ## Guardrails - Never read, write, delete, or move files under the directory being examined; examined files are read only. - Do not read or depend on `sources/run.sh` from application code. - Do not hardcode file paths, digests, or totals. - Do not add third-party modules. - Read file contents only when another eligible regular file has the same size. ## Programmatic Acceptance === AC architecture-cli-contract === Intent: The architecture exposes the documented CLI runner contract and the executable package builds. import subprocess result = subprocess.run( ["go", "build", "./cmd/dupfind"], capture_output=True, text=True, ) print(result.stdout) print(result.stderr) assert result.returncode == 0 === END AC architecture-cli-contract === === AC architecture-package-layout === Intent: The internal application packages and command entry point compile together. import subprocess result = subprocess.run( ["go", "test", "./..."], capture_output=True, text=True, ) print(result.stdout) print(result.stderr) assert result.returncode == 0 === END AC architecture-package-layout === ## User Acceptance - None. ## Guardrails - None. === END ARTIFACT === === BEGIN ARTIFACT FEATURE-Build.md === # FEATURE: Build | Field | Value | |-------------|-------| | Version | 20261024 V1 | | Description | Provides the dupfind executable at the documented Go package path. | | Depends On | ARCHITECTURE.md | | Provides | ./cmd/dupfind | | Consumes | Go module and application package layout | ## Questions - None. ## Purpose The application root is a Go module. Building from that root with `go build ./cmd/dupfind` produces the dupfind command. The main package lives in `cmd/dupfind` and uses only the standard library. ## Build contract The executable delegates command behavior to the internal CLI package. Process startup passes command-line arguments and standard streams to `Run`; only the main package exits the process using the returned status code. Build output is produced by the Go toolchain, not by application code. ## Programmatic Acceptance === AC build-command === Intent: Building the declared executable package succeeds. import subprocess result = subprocess.run( ["go", "build", "./cmd/dupfind"], capture_output=True, text=True, ) print(result.stdout) print(result.stderr) assert result.returncode == 0 === END AC build-command === === AC build-test-entry === Intent: The Go test runner recognizes the application packages. import subprocess result = subprocess.run( ["go", "test", "./..."], capture_output=True, text=True, ) print(result.stdout) print(result.stderr) assert result.returncode == 0 === END AC build-test-entry === ## User Acceptance - None. ## Guardrails - Use Go 1.22 or newer and the standard library only. - Do not add command behavior to process startup; keep it in the CLI package. === END ARTIFACT === === BEGIN ARTIFACT FEATURE-Command.md === # FEATURE: Command | Field | Value | |-------------|-------| | Version | 20261024 V1 | | Description | Parses dupfind options and validates its directory argument. | | Depends On | ARCHITECTURE.md, FEATURE-Build.md | | Provides | dupfind command-line options and usage | | Consumes | ./cmd/dupfind | ## Questions - None. ## Command contract The command syntax is `dupfind [--summary] [--min-size ] `. Options precede exactly one directory argument. `--summary` selects summary CSV. `--min-size` accepts a positive integer and defaults to 1. Help text describes the command and its options. Unknown options, missing or extra directory arguments, and invalid minimum sizes are usage errors. They return 2, write no standard output, and write one diagnostic line to standard error. A missing path or a path that is not a directory is an operational error: return 1, leave standard output empty, and write one diagnostic line to standard error. Other operational errors use the same conventional operational-failure behavior. File read errors during scanning are handled as warnings and do not change the exit code. ## Programmatic Acceptance === AC command-help-usage === Intent: Help includes a description of the command and its supported options. import subprocess result = subprocess.run( ["./dupfind", "--help"], capture_output=True, text=True, ) print(result.stdout) print(result.stderr) assert result.returncode == 0 === END AC command-help-usage === === AC command-invalid-option === Intent: Unknown options return the usage-error exit status. import subprocess result = subprocess.run( ["./dupfind", "--frobnicate", "."], capture_output=True, text=True, ) print(result.stdout) print(result.stderr) assert result.returncode == 2 === END AC command-invalid-option === === AC command-invalid-size === Intent: A zero minimum size returns the usage-error exit status. import subprocess result = subprocess.run( ["./dupfind", "--min-size", "0", "."], capture_output=True, text=True, ) print(result.stdout) print(result.stderr) assert result.returncode == 2 === END AC command-invalid-size === ## User Acceptance - None. ## Guardrails - Malformed arguments and operational failures write nothing to standard output. - Diagnostics go to standard error. === END ARTIFACT === === BEGIN ARTIFACT FEATURE-Scanning.md === # FEATURE: Scanning | Field | Value | |-------------|-------| | Version | 20261024 V1 | | Description | Finds exact duplicate regular files by scanning a directory tree. | | Depends On | ARCHITECTURE.md, FEATURE-Command.md | | Provides | duplicate groups from a directory tree | | Consumes | dupfind command-line options and usage | ## Questions - None. ## Scope and filtering Walk the requested directory recursively, including hidden files and directories. Examine regular files only. Do not follow or report symbolic links. Ignore files smaller than the selected minimum size; zero-byte files are therefore ignored under the default minimum of 1. ## Candidate grouping and reads Partition eligible files by size. Read file contents only for sizes represented by at least two eligible files. Compute SHA-256 for each readable candidate and group files with the same size and digest. Report groups only when at least two files share both. If a candidate cannot be read, skip it, write one warning line to standard error, and keep the command's success exit status. ## Read-only behavior The scan only reads files. It never deletes, moves, or writes files in the examined directory. It does not use fixture-specific paths or expected results. ## Programmatic Acceptance === AC scan-groups-exact-files === Intent: The supplied conformance grader passes its duplicate scanning cases. Suite: scoped import subprocess result = subprocess.run( ["sh", "sources/run.sh"], capture_output=True, text=True, ) print(result.stdout) print(result.stderr) assert result.returncode == 0 === END AC scan-groups-exact-files === === AC scan-symlinks-and-empty === Intent: The supplied conformance grader passes its symbolic-link and empty-file cases. Suite: scoped import subprocess result = subprocess.run( ["sh", "sources/run.sh"], capture_output=True, text=True, ) print(result.stdout) print(result.stderr) assert result.returncode == 0 === END AC scan-symlinks-and-empty === === AC scan-read-only === Intent: The supplied conformance grader passes while examined files remain untouched. Suite: scoped import subprocess result = subprocess.run( ["sh", "sources/run.sh"], capture_output=True, text=True, ) print(result.stdout) print(result.stderr) assert result.returncode == 0 === END AC scan-read-only === ## User Acceptance - None. ## Guardrails - Never follow or report symbolic links. - Never write to the examined directory. === END ARTIFACT === === BEGIN ARTIFACT FEATURE-Ordering.md === # FEATURE: Ordering | Field | Value | |-------------|-------| | Version | 20261024 V1 | | Description | Orders duplicate groups and their relative paths deterministically. | | Depends On | ARCHITECTURE.md, FEATURE-Scanning.md | | Provides | ordered duplicate groups and relative paths | | Consumes | duplicate groups from a directory tree | ## Questions - None. ## Ordering contract Sort groups by reclaimable bytes descending, then by SHA-256 digest ascending. Reclaimable bytes equal file size times the number of duplicate copies beyond the first. Number groups starting at 1 in sorted order. Sort paths inside each group by byte value ascending. Emit each path relative to the requested directory using `/` separators and without a leading `./`. ## Programmatic Acceptance === AC ordering-conformance === Intent: The supplied conformance grader passes the duplicate ordering cases. Suite: scoped import subprocess result = subprocess.run( ["sh", "sources/run.sh"], capture_output=True, text=True, ) print(result.stdout) print(result.stderr) assert result.returncode == 0 === END AC ordering-conformance === ## User Acceptance - None. ## Guardrails - Ordering is deterministic and independent of filesystem traversal order. - Do not include files outside the requested directory. === END ARTIFACT ===