---
description: Inspect writer-owned text and publishing files for invisible Unicode, metadata, and hard-bound provenance signals without modifying them.
argument-hint: "[target] [--scope <source|build|output|all>] [--strict]"
---

<!-- Implements: P-MUST-01, P-MUST-02, P-MUST-03, P-MUST-04, P-MUST-05, P-MUST-06, P-MUST-07, P-MUST-08, P-MUST-09, P-MUST-10, P-MUST-11, P-MUST-12, P-MUST-13, P-MUST-14, P-MUST-15, P-MUST-17, P-MUST-18 -->

# /scr:provenance-check - Provenance Audit

Inspect text, manuscript assets, publication files, directories, or a read-only website target for machine-readable provenance and hygiene findings. This command is read-only. It must not modify the target.

This is a privacy and publishing-hygiene tool for content the writer owns or is authorized to process. A clean report does not prove human authorship, remove disclosure duties, or certify that a vendor detector will not find a residual signal.

## Usage

```text
/scr:provenance-check [target...] [--scope <source|build|output|all>] [--jobs <1-8>] [--format <markdown|json|sarif>] [--output <path>] [--strict] [--provider <local|auto|watermarks-remover>] [--require-provider]
```

- `target...`: One or more local files or directories, or an HTTP or HTTPS URL for the agent-guided read-only lane. Supplied targets override manuscript scope discovery. The packaged local CLI reports remote URLs as degraded rather than uploading or mutating content.
- `--scope source`: Inspect `.manuscript/drafts/`, front matter, back matter, marketing text, and other authored text.
- `--scope build`: Inspect `.manuscript/build/`.
- `--scope output`: Inspect `.manuscript/output/`.
- `--scope all`: Inspect all three manuscript scopes. This is the default when no target or scope is supplied.
- `--jobs <1-8>`: Bound concurrent local reads. The default is 4 and the hard maximum is 8.
- `--format <markdown|json|sarif>`: Render the same normalized findings as writer-facing Markdown, schema-versioned JSON, or SARIF 2.1.0.
- `--output <path>`: Write the selected report format to a local non-symlink path that is not an audited input.
- `--strict`: Treat unsupported or degraded inspection lanes as unresolved findings instead of informational limitations.
- `--provider local`: Use only the dependency-free local provider. This is the default and never uploads files.
- `--provider auto`: Use the watermarks-remover service only when `SCRIVENO_WATERMARKS_SERVICE_URL` is configured. Otherwise remain local without a network request.
- `--provider watermarks-remover`: Request the optional service. A recoverable service failure is reported and falls back to the local lanes.
- `--require-provider`: Refuse local fallback. A provider negotiation or inspection failure exits `70` and produces no cleaned output.

The installed CLI uses the same contract:

```bash
scriveno provenance-check ./drafts ./assets --jobs 4 --format json --provider local
scriveno provenance-check ./release --format sarif --output provenance.sarif --provider local
SCRIVENO_WATERMARKS_SERVICE_URL=http://127.0.0.1:8765 scriveno provenance-check ./release --provider watermarks-remover
```

## Instruction

You are a provenance auditor. Separate confirmed machine-readable evidence from guesses, protect valid language and media data, and report limitations precisely.

### STEP 0: LOAD CONTEXT AND SET BOUNDARIES

When `.manuscript/` exists, read:

- `.manuscript/CONTEXT.md` first when current
- `.manuscript/config.json`
- `.manuscript/STATE.md`
- `.manuscript/STYLE-GUIDE.md` when present
- Scriveno's installed or project `CONSTRAINTS.json`
- `.manuscript/reviews/PLATFORM-COMPLIANCE.md` when present

Use STYLE-GUIDE.md only to preserve the writer's voice boundary. Do not evaluate style or rewrite prose here. External detector scores are context only and must not set audit confidence.

Operate only on content the writer owns or is authorized to process. If a target is clearly outside the active project and ownership is unclear, ask for confirmation before reading it. Never mutate a remote target.

### STEP 1: RESOLVE TARGETS

Resolve the explicit target first. Otherwise inventory the selected manuscript scope. Follow directories recursively, but exclude:

- `.git/`, dependency caches, and tool caches
- existing backup files unless explicitly selected
- temporary or lock files
- symlink targets outside the selected root

For HTTP or HTTPS targets, perform a read-only audit. Fetch only the selected page, its declared sitemap when requested, and same-origin assets required for the audit. Do not crawl forms, authenticated areas, non-HTTP schemes, or mutation endpoints.

Reject any other URL scheme.

### STEP 2: INVENTORY CAPABILITIES

Check optional tools without installing anything:

```bash
command -v c2patool >/dev/null 2>&1
command -v exiftool >/dev/null 2>&1
command -v qpdf >/dev/null 2>&1
command -v unzip >/dev/null 2>&1
```

Record each tool as `available` or `missing`. Missing tools create a degraded lane only for formats that need them. Never report the whole target as clean because an optional tool is missing.

Use:

- `c2patool` for documented read-only C2PA manifest inspection
- `exiftool` for read-only EXIF, XMP, PDF, and document metadata inventory
- `qpdf` only as a capability note for later PDF cleaning and verification
- `unzip` only for read-only container listing or extraction into a temporary directory

Do not pass credentials on a command line. Quote every path.

### OPTIONAL WATERMARKS-REMOVER PROVIDER

The optional provider is an explicit transport, not an implicit upload lane. Read its base URL only from `SCRIVENO_WATERMARKS_SERVICE_URL` and its bearer token only from `SCRIVENO_WATERMARKS_SERVICE_TOKEN`. Never accept either value as a command argument, print the token, or include it in Markdown, JSON, SARIF, errors, or logs.

Before uploading any file bytes, validate `GET /health` and `GET /capabilities`, record the service version, confirm the requested operation and format, and clamp concurrency to the lowest advertised or local limit. Open the writer-owned input once through a non-symlink stable handle, then verify its identity, ownership, size, and expected digest before uploading the bytes read from that handle. Refuse redirects. Plain HTTP is allowed only for the documented loopback service. A remote endpoint must use HTTPS, and every resolved address must be global-unicast. Reject private, loopback, link-local, shared, multicast, unspecified, cloud metadata, and every other special-purpose range.

Send base64 file bodies to `POST /inspect` only after those checks. Bound input bytes and the encoded request envelope independently. Use a small report response cap, a separate bounded clean response cap, and absolute wall-clock deadlines for DNS, connect, TLS, and the full response stream. Validate complexity without rewriting protocol fields or cleaned base64, then redact the token only from approved public evidence and errors during normalization. Normalize only typed structured hits and explicit summary booleans into the Scriveno finding schema. True summary booleans create normalized summary findings. Ignore every untyped upstream `report.findings` and `post_findings` string regardless of its wording or agreement with a summary boolean. This categorical rule excludes Layer B stylometry, its phrase-marker, cadence, density, burstiness, lexical-diversity, and aggregate strings. Do not claim that a high or low stylometry score establishes authorship.

In `auto` mode, no configured URL means local-only operation. In explicit `watermarks-remover` mode, a recoverable provider failure must record the failed provider attempt and the successful local fallback. With `--require-provider`, stop with exit `70` instead of silently using local results.

### STEP 3: CLASSIFY BEFORE READING

Classify each local file by extension, magic bytes, and container structure. Markdown, plain text, HTML, SVG, PNG, JPEG, PDF, DOCX, ODT, EPUB, WebP, AVIF, HEIC, BMP, GIF, TIFF, BigTIFF, XLSX, and PPTX have explicit lanes. Inspect embedded raster data URIs through the matching media lane. Anything else is `unsupported` unless a credible installed tool recognizes it.

Magic bytes override a misleading extension. ZIP containers, PDF files, images, executables, databases, fonts, compressed archives, audio, and video must never be decoded or rewritten as text. If a text path receives binary input, stop that lane and name the correct container or media path.

Warn before reading unusually large files. Do not load an entire large binary into model context when a metadata tool can inspect it directly.

For ZIP-based containers, reject absolute paths, parent-directory traversal, symlink entries, every duplicate entry and normalized alias, encryption, excessive archive entries, excessive total expansion, and unsafe compression ratios. Validate that each local header agrees with its central entry on raw and decoded name, flags, method, CRC, sizes, offset, and data descriptor semantics. Reject overlapping local ranges. Stop the lane and report the archive as unsafe instead of extracting it.

The cleaning command reuses these archive and signature decisions. A post-clean result is never published when this audit classifies the temporary sibling as unsafe, invalid, or a different format.

Enforce fixed caps for file count, directory depth and count, aggregate stable-read input bytes, embedded data URI per-item and aggregate decoded bytes and match count, archive entries, archive expansion, compression ratio, and concurrency. A breached cap is unsafe input and must not be partially treated as clear.

### STEP 4: INSPECT TEXT AND UNICODE

For text bodies, report suspicious code points with file, line or offset, Unicode name, class, and count.

Inspect these classes:

- zero-width carriers, including ZWSP, ZWNJ, ZWJ, WJ, and BOM
- bidi controls and isolates
- Unicode tag characters
- variation selectors
- NBSP and other exotic spaces
- confusable fullwidth or cross-script characters as an optional probable finding

Context is mandatory. Preserve and classify as legitimate when the same code point is load-bearing for:

- script joiners inside Arabic, Syriac, Persian, Indic, or another joining script
- emoji ZWJ or variation-selector sequences
- flag tag sequences
- orthographic controls required by the language

An isolated invisible between plain ASCII characters can be confirmed when its carrier role is unambiguous. A confusable or unusual space is usually probable until context establishes intent.

### STEP 5: INSPECT FILE PROVENANCE

Use the strongest credible lane per format:

- Markdown: inspect body Unicode and YAML frontmatter for AI, generator, provenance, or tool keys.
- HTML: inspect meta generator fields, XMP, JSON-LD provenance, and `data-ai*` attributes. Treat ordinary CMS generator fields as informational unless they claim AI provenance.
- SVG: inspect `<metadata>` and XMP blocks without treating visible SVG text as metadata.
- PNG and JPEG: use `c2patool` for manifest evidence and `exiftool` for EXIF or XMP when available. Preserve ICC color information as protected rendering data.
- PDF: use `exiftool` for metadata inventory when available and inspect C2PA only when the tool supports the file. Without a credible parser, mark coverage degraded. Raw strings inside compressed streams are likely false positives.
- DOCX: inspect only `docProps/` and `customXml/` container members for document properties or provenance. Do not scan visible body text as compressed raw bytes.
- ODT: inspect `meta.xml` and relevant manifest metadata.
- EPUB: inspect package metadata, declared generator fields, and text resources through their correct lanes. Preserve navigation, accessibility metadata, and visible content.
- WebP, AVIF, HEIC, BMP, GIF, TIFF, and BigTIFF: classify from signatures and parse recognized metadata containers without changing image bytes, frames, animation state, or color data.
- XLSX and PPTX: inspect document properties separately from visible workbook strings and presentation text. Do not treat visible content as metadata.
- Embedded raster data URIs: bound decoded size, require the declared MIME type to match the decoded signature, and inspect the decoded bytes without rewriting the parent text.

Distinguish hard-bound C2PA embedded in the file from soft binding or pixel-domain signals that may survive metadata removal. Audio and video watermark detection is unsupported by this command.

### STEP 6: CLASSIFY FINDINGS

Every finding must use exactly one confidence label:

- `confirmed`: parsed recognized provenance structure, field, or unambiguous carrier
- `probable`: suspicious value inside a recognized metadata structure or a context-dependent text carrier
- `informational`: ordinary software or CMS metadata and tool-availability notes
- `likely_false_positive`: raw byte or compressed-stream collision without parsed structural evidence

For each file, also report lane status: `complete`, `degraded`, `unsupported`, or `not-applicable`.

In strict mode, any `degraded` or `unsupported` lane becomes an unresolved finding. Strict mode does not raise the confidence of weak evidence.

The CLI exit contract is `0` for clear, `1` for findings or actionable residuals, `2` for degraded or unsupported coverage, `64` for invalid or unsafe input, and `70` for an unrecovered internal failure.

### STEP 7: PRESERVE VOICE AND DISCLOSURE TRUTH

This command must not paraphrase prose or run a statistical watermark attack. Statistical text watermark claims are unverifiable without the relevant vendor detector and key. Do not claim a text is unmarked.

If visible craft problems need revision, route to `/scr:line-edit`, `/scr:polish`, or a scoped re-draft. Those transforms load STYLE-GUIDE.md and improve the writing itself. They must not optimize for detector scores.

Metadata state does not determine how content was created. AI-generated or AI-assisted disclosure remains based on project history. A cleaned file must not be described as human-written.

### STEP 8: WRITE THE REPORT

For manuscript-scoped runs, write `.manuscript/reviews/PROVENANCE-AUDIT.md`. For an explicit external target without a manuscript, print the report unless `--output` names a safe report path. Markdown is the default. JSON and SARIF 2.1.0 must serialize the same normalized findings, confidence, channel, rule id, and artifact location.

Use this structure:

```markdown
# Provenance Audit

## Verdict

CLEAR / FINDINGS / DEGRADED / UNSUPPORTED

## Target Inventory

Files, directories, or URLs inspected.

## Capability Inventory

| Tool or lane | Status | Effect on coverage |
|---|---|---|

## Findings

| Confidence | Channel | Target | Evidence | Suggested action |
|---|---|---|---|---|

## Format Coverage

| Format | Lane | Status | Notes |
|---|---|---|---|

## Residual Risk

Soft binding, pixel-domain media signals, statistical text marks, secret-key detectors, and unsupported formats.

## Disclosure Note

Metadata cleaning does not change creation history or platform disclosure duties.
```

### STEP 9: FINAL RESPONSE

Show:

- verdict
- report path
- confirmed and probable finding counts
- degraded or unsupported lanes
- whether a safe cleaning dry-run is available
- the disclosure note

## Automation Status

Every response must include:

```text
Automation status:
Trigger: /scr:provenance-check {target or scope}
Auto-invoked commands:
- none
Spawned agents:
- none
Local operations:
- targets inspected: {count}
- provenance report written: yes/no
- target files modified: none
Manual gates:
- cleaning decision: writer-owned
Why: provenance-check is read-only and separates evidence from uncertain residual signals
```

## Response Contract

Every writer-facing response must end with one to four next-command suggestions. Each suggestion must include a short explanation of what that path will do.

The final visible section of every writer-facing response must be the `Next commands:` block. This applies to successful completion, partial completion, blocked, stopped, validation-failed, and prerequisite-missing responses. Do not end with only a summary, report, checklist, external action, upload instruction, or prose-only options.

Use the invocation style for the active runtime when writing command suggestions. Source command IDs use `/scr:*`; Claude Code installed commands use `/scr-*`; Codex installed skills use `$scr-*`. Suggest only runnable Scriveno commands that exist in the installed command surface. Do not invent adjacent workflow names.

Use this format:

```markdown
Next commands:
- `/scr:...`: One short sentence explaining what this path will do.
- `/scr:...`: One short sentence explaining what this alternate path will do.
```

If exactly one path is clearly best, provide one suggestion. If two, three, or four useful paths exist, show them as alternatives. Do not force a linear path when the writer has a real choice.

If the writer seems unsure or no specific next command is obvious, include this default option:

```markdown
Next commands:
- `/scr:next`: Inspect the project state and choose the right next step.
```

If the command stops because a prerequisite is missing, suggest the command that fixes the prerequisite. Keep every explanation practical and writer-facing.

## Tone

Be factual and conservative. State what was parsed, what was inferred, and what could not be checked. Never turn missing evidence into proof of absence.
