# Duplicate-Code Enforcement

Open Orchestra uses `jscpd` to make the existing DRY and
`collection-standards` rules enforceable in CI.

## Command

```bash
npm run duplicates
```

The command writes machine-readable reports under
`.agent-workflow/reports/jscpd/` and prints a console summary.

## Scope

The detector scans source, scripts, web clients, extension code, rules, skills,
and selected docs. It excludes generated output, package locks, workflow runtime
state, diagrams, historical reports, and large backlog documents that are not
maintained as product code.

The initial threshold is intentionally conservative:

- `threshold`: 5%
- `minLines`: 10
- `minTokens`: 80

This keeps the gate focused on meaningful copy-paste while avoiding noisy
failures from small examples or test setup.

## Relationship To Collection Standards

`jscpd` detects textual duplication. It does not replace semantic review.

When the duplicate block is a repeated list, map, command matrix, provider list,
role/status list, selector set, fixture set, or validator set, remediation must
load `collection-standards` and move the values into a typed source of truth.

Examples:

- command lists should derive from the command manifest or a command catalog;
- workflow phases should derive from the workflow phase registry;
- task statuses should derive from task status helpers;
- UI dropdown options should derive from shared metadata or API contracts;
- test fixtures should use builders/factories when reused across files.

## CI Behavior

The CI quality job runs `npm run duplicates` after the normal precommit gate.
This keeps duplicate detection visible in pull requests and release evidence.

If a finding is intentional, prefer one of these responses:

1. Extract a shared source of truth.
2. Narrow the scanned scope if the file is generated or historical.
3. Add a documented exclusion only when duplication is unavoidable.
4. Create a follow-up issue when the remediation is larger than the current
   story.

Do not suppress findings silently.
