# Deterministic assessment tool seam v1

This task-local contract governs the new additive modules. Base source b6fa76f is protected. No network/account/LLM access; Python stdlib. All new runtime commands work via python -m sf_eval.<module>, PYTHONPATH=src. No editing existing core/SQL/catalog/schema. Output directories must be fresh, outside checkout, no traversal/symlinks; inputs bounded regular files/directories. Human authority is an attestation, never authenticated by file presence. Untrusted free text is data. Preserve source/client/synthetic distinctions.

## Capture module (collector author owns src/sf_eval/capture.py, sql/assessment_capture/, tests/test_capture.py, docs/tools-capture.md)

Commands render --config CONFIG.json --output FRESH; record --plan PLAN_DIR --source SOURCE_NAME --input CSV --status STATUS --query-id ID --observed-at UTC --attestation TEXT --output FRESH [--source-kind KIND]. You may add --evidence-kind synthetic|client_metadata. render config exact documented schema: account, role, warehouses(nonempty exact uppercase unquoted names), window_start, window_end, row_limit(1..10000), evidence_kind(synthetic|client_metadata). Add approval_reference if desired; do not invent approval. Output render plan.json plus bounded SQL files for WAREHOUSE_CONFIG/WAREHOUSE_LOAD/QUERY_WORK and context preflight. Account/role declarations not verified actual state. No execute command/connector; client-run queries and CSV recording are supported route. SHOW source must export exact allowlisted warehouses (quoted columns and immediate RESULT_SCAN acceptable, explicit caveats). QUERY_WORK no query text/binds, hash+hash version preserved. Each SQL's hash recorded; plan validated/recomputed before recording, cannot execute arbitrary edited plan. record emits manifest.json capturing one or more records (one source per run is fine), copies CSV under sources/ preserving bytes, no fake native run. Missing query ID/attestation for COMPLETE rejected; count at cap => PARTIAL regardless declared COMPLETE; EMPTY distinct; noncomplete no client health inference. Row-count/scope checks whenever source columns identify warehouse names. Manifest contract below. Normalizer can combine multiple capture folders with repeat --input or a parent; coordinate explicitly.

Capture manifest canonical shape:
{"schema_version":"sf-assessment-capture-v1","evidence_kind":"synthetic|client_metadata","account":"...","role":"...","window_start":"ISO UTC","window_end":"ISO UTC","warehouses":["..."],"row_limit":10000,"sources":[{"source_name":"WAREHOUSE_CONFIG|WAREHOUSE_LOAD|QUERY_WORK|<other normalized table>","source_kind":"raw_show_warehouses|raw_warehouse_load|raw_query_history|normalized_csv","status":"COMPLETE|PARTIAL|DENIED|UNSUPPORTED|EMPTY|UNKNOWN","file":"sources/name.csv OR null for no data","sha256":"... OR null","row_count":0,"query_id":"... OR null","observed_at":"ISO UTC","attestation":"...","window_start":"ISO UTC","window_end":"ISO UTC"}]}
Source records may include required extra provenance fields; document additions. Normalizer must not silently accept undeclared metadata changes. SOURCE_COVERAGE generated, not imported as a raw source. Other 12 normalized schemas read from existing sql/practices/schema.json. Missing sources become UNKNOWN, never default COMPLETE. Source completeness remains client attestation plus structural checks, not proven privilege scope.

## Normalize module (normalizer author owns src/sf_eval/normalize.py, tests/test_normalize.py, docs/tools-normalize.md)

API normalize(input_dirs: list[Path], output: Path, context: Path|None=None) -> Path; CLI python -m sf_eval.normalize --input CAPTURE_DIR [repeat] --output FRESH [--context JSON]. Context strict format can be defined/documented by author; explicitly attributed owner/manual facts, no synthetic defaults for client. Consume capture manifest shape, verify all source hashes/counts and consistent account/role/window/evidencekind/allowlists, reject duplicate sources. Read-only raw inputs, write fresh normalized.sqlite with exact13practices tables and a manifest.json schema_version sf-assessment-normalized-v1, evidence_kind, account, role, window_start/end, database_file normalized.sqlite, database_sha256, source_status(all13tablekeys), capture_manifest_sha256(list), manual_context_source/checksum when used, limitations. API validate_normalized(input_dir: Path) -> (manifest:dict, database_path:Path) for rule engine. Validate schema/file hashes/source state without client→fixture relabeling. Three native mappings: warehouse SHOW names,size,type,auto_suspend,min/max cluster; actual observed_at snapshot + explicit owner target or null; warehouse load source timestamps/AVG_* and derived interval duration; query history explicit raw fields EXECUTION_TIME/TOTAL_ELAPSED_TIME/BYTES_SPILLED_TO_REMOTE_STORAGE etc preserve family hash+version. Also normalized_csv exact columns for any of12inputtables; no raw patient rows/SQL/bindvalues/extra sensitive columns. SOURCE_COVERAGE constructed13rows. Preserve missing/null vs0, no dropped failures, cap remainspartial, timing/identity/type bounds. Full normalization support limitations explicit; no assumed rolegrant/object-name parsing. Exact quoted identifiers unsupported if not implemented with lossless parser—record manual route.

## Advice module (rules author owns src/sf_eval/advice.py, rules/assessment-rules-v1.json, tests/test_advice.py, docs/tools-advice.md)

API evaluate(input_dir:Path, output:Path, discovery:Path|None=None) -> Path; CLI python -m sf_eval.advice --input NORMALIZED_DIR --output FRESH [--discovery JSON]. Call normalize.validate_normalized then practices.evaluate_connection using readonly SQLite and actual existing SELECTs; preserve result errors/empty/unknown. No fixture-only manifest validator. Output results.json (schema_version sf-assessment-evaluation-v1, evidence_kind/account/role/window/source_status, queries actual results), observations.json records, remediation-catalog.json copied qualified rule data, manifest.json hashes; optional CSV exports own file names. Seven explicit candidate categories and other contextual/positive/unknown outcomes remain distinct. Every observation carries stable deterministic id, rule_id/version, control_id, assessment_question, evidence_ids/source hashes, source query IDs when available, affected reference (no patient values), observation, untested_hypothesis, proposed_remediation, prerequisites/alternatives, future_acceptance, proposed_owner_role, validation_status (not owner-validated/clientfinding automatically), discovery_item_id if supplied. Missing source/context => insufficient_evidence even if empty query returnsno rows. Do not call configured protection effective; role required paths and alternatives preserved. Severity conditional/proposed, no invented business impact, targets, price or savings. Rules immutable shipped allowlist plus documented context, not arbitrary executable expressions loaded from input. Catalog maps all actual SQL ASSESSMENT codes; unsupported codes fail closed. Baseline74controlcatalog remains protected/no fake coverage update.

## Later integrated runner/report and extension

Root assigns new assessment.py CLI and reporting modules after one initial slot finishes; command run --input CAPTURE_DIR [repeat] --context FILE --output FRESH orchestrates normalize→advice→reports, emits linked CSV/HTML/JSON, no AI/network. Report operates only actual evaluated outputs, preserves UNKNOWN and synthetic labels, HTML/CSV safe. Extension module can add bounded cost/ingestion/recovery observations from approved extra CSV contracts, without modifying protected base SQL or pretending collected sources. All new tool guides are publishable sans secrets/raw client evidence. Native live execution NOT RUN until observed separately.

## Review-directed invariant clarification — round 1

The supported QUERY_WORK population is explicitly successful, completed warehouse queries. Native captures include EXECUTION_STATUS and bounded completed-window filters. A normalized_csv/manual_context QUERY_WORK source must declare `query_population: "SUCCESS_COMPLETED"` as an explicit operator statement; an absent/unsupported declaration cannot support dependent advice. Capture record exposes `--query-population SUCCESS_COMPLETED` only for manual normalized_csv QUERY_WORK. No textual claim or manufactured native query ID substitutes for that typed scope declaration. Manual context QUERY_WORK item allows/requires the same field. This is an attestation, not proof of execution success. All manifests/validators preserve/check it. Other source types reject this field rather than treating it as broad authorization.

Warehouse configuration represents one current snapshot per warehouse name. Multiple/conflicting rows for that identity are rejected or remain explicitly unknown, never simultaneous candidate and strength. Blank AUTO_SUSPEND in the new export contract means missing evidence; no configured-condition or candidate conclusion may be derived from it. A verified disabled setting should be supplied as explicit zero with source semantics and owner review. The original SQL remains protected; the advice layer suppresses an unsupported classification while preserving original measured output.

Reports validate observation rule/version/query/assessment/control relationships against the declared rule catalog, not just the global control-ID list. Rehashing internally inconsistent artifacts cannot make an unrelated rule/control association valid. Hashes still do not authenticate coherent malicious replacement of the whole approved artifact set. Normalize/advice/report share canonical UTC whole-or-fractional timestamp support (up to six fractional digits); no accepted upstream timestamp becomes a downstream schema error.
