# Cross-table reference join plans `csv join preview` resolves explicitly declared external keys across selected CSV sources before import. Native item identities are generated by the pm SDK and saved in the review artifact. Core owns item identity, lifecycle, parent and `blocked_by` validation; provider adapters continue to own their remote keys. ```sh pm csv join preview joins.json --output reviewed.json --json pm csv join apply reviewed.json --json # Retrying the SAME reviewed artifact rechecks current target revisions. pm csv join apply reviewed.json ``` Example input (`joins.json`): ```json { "version": 1, "tables": [ { "name": "projects", "key": "key", "csv": "key,title\np1,Launch\n", "fields": {"title": "title"}, "references": [] }, { "name": "tasks", "key": "key", "csv": "key,title,project\nt1,Build,p1\n", "fields": {"title": "title"}, "references": [{"column": "project", "table": "projects", "kind": "parent"}] }, { "name": "checks", "key": "key", "csv": "key,title,task\nc1,Verify,t1\n", "fields": {"title": "title"}, "references": [{"column": "task", "table": "tasks", "kind": "blocked_by"}] } ] } ``` The SDK exports `previewJoins(pmRoot, input)` and `applyJoins(pmRoot, plan, {author})` from `pm-csv` (and the corresponding typed `JoinInput`, `JoinPlan`, `JoinReceipt`, `JoinIssue` declarations). Preview returns `{receipt, plan?}`. Only successful previews produce a plan. Preview never writes tracker state. CLI output uses the host's compact TOON or `--json` rendering; full source-bearing artifacts are saved only with `--output`, exclusively with private file permissions. Treat review artifacts as source data. Mapping names are exact SDK create-option names: `title`, `body`, `type`, `status`, `priority`, `tags`, `assignee`, `sprint`, `release`, `estimatedMinutes`, `acceptanceCriteria`, `closeReason`, `completedAt`. Every mapped header must exist. Other headers have no effect. `title` is required. The SDK performs native normalization; body whitespace is passed intact to it. Types and statuses must be configured native IDs; terminal status meaning comes from SDK registry roles and requires `closeReason`. Priority is an integer 0–4; estimates are finite 0–1,000,000,000 minutes. Lifecycle policy remains enforced by native SDK create. The version 1 boundary is strict: unknown properties, sparse arrays and wrong primitive types are rejected. Configured type/status membership and all input-keyed field/header/reference lookups use Map or own-property checks. Prototype names such as `constructor` and `__proto__` cannot impersonate configured types or fields; they remain valid literal external keys and mapped source headers. Limits: 16 tables, 16 reference declarations per table, 128 columns, 1,000 selected rows total, 8 MiB total UTF-8 CSV. Comma CSV accepts quoted cells, BOM, consistent LF or CRLF. Keys compare case-sensitively after trimming surrounding whitespace. Empty keys, duplicates (including unused ones), unresolved nonempty reference cells and cycles block the entire preview. An empty reference cell means no edge. Each declaration contains one key per cell; use multiple declared dependency columns for multiple edges. Coordinates are one-based logical CSV records and columns, with the header as record 1; embedded newlines do not add logical records. Dependency item leases remain fenced from the final dependency revision check through native child creation. Cleanup attempts every acquired dependency lease in reverse acquisition order, then reports the first release failure if any. A dependency edited before those leases are held refuses the child write; a competing native writer cannot enter during creation. The coordinator checks every target again at its `committing` transition, so a precommit conflict runs reverse compensation instead of committing a journal whose targets already fail validation. Compensation preserves foreign edits and retains tombstone history; a blocked cleanup remains explicit in the journal. Plans bind exact SHA-256 source-byte digests, tracker settings, generated native IDs and explicit `expected: "absent"` target revisions. Sources are captured inline, so apply never rereads external files. Any source or artifact edit invalidates the review. A new preview assigns new identities and represents a new import; use the original artifact for crash recovery; a compensated plan requires a fresh preview. This is a create-only import, with no keyed update, export or sync protocol. Existing CSV import/export, spreadsheet checkout and row-lineage workflows remain separate APIs. All saved IDs must be canonical under the reviewed tracker's SDK prefix, and uniqueness is checked after SDK identity normalization before any target lease, journal or item write. For example, `abcd` and `review-abcd` cannot name two rows when the prefix is `review`. Bare, case or whitespace aliases in saved artifacts return `csv_join_invalid`, even if the artifact was rehashed. Apply never rewrites reviewed IDs to repair an artifact; preview a fresh plan. Compilation and comparisons use one captured settings/schema view. Type and status defaults come from that view's native SDK registries and are passed explicitly to create. Live settings reads only revalidate the digest before and after each mutation batch inside the SDK transaction writer lease. Settings changes at any between-row boundary refuse with `csv_join_settings_changed`; they cannot produce a successful receipt with mixed defaults. Before cleanup, the attempt captures a separate current-policy snapshot and guards it throughout compensation. Another settings change or a peer revision can stop cleanup with an explicit reconciliation remedy. SDK transaction steps reuse their coordinator's lease, preserving its existing SIGKILL/retry lifetime. Standalone lineage and negotiated-table batches use the SDK settings/schema writer lease. These APIs retain their documented partial import semantics. Spreadsheet and legacy atomic operations use the same snapshot checks with their existing native compensation. Source arrays, saved artifacts, options and the tracker root are captured before the first asynchronous SDK read. Apply uses `commitWorkspaceTransaction` and native SDK create. Every retry reads current target documents and immutable history, including after a committed journal. An unchanged target must still have the exact owned create revision; later edits refuse replay. Foreign collisions are skipped with `foreign`, and all dependent targets with `dependency_skipped`, without changing those records. No separate checkpoint, outbox or custom lease files are introduced. Native SDK item locks and transaction writer locks own concurrency. As with existing CSV atomic import, host persistence fencing beyond item-lease expiry remains a host SDK requirement (tracked separately). The transaction key and recorded step domain cover the entire reviewed plan, including rows currently skipped as foreign. Peer-created items cannot produce a second transaction key on retry. Historical subset journals are identified by their plan-bound key and exact recorded steps; pending compensation takes priority over later receipts. Selection is revalidated inside SDK writer coordination before forward rows, including the SDK's monotonically increasing attempt generation. A compensation restart cannot be mistaken for the earlier applying snapshot. Recovery completes under the original journal, then refuses with `csv_join_reconcile` so the caller can preview fresh identities. It never reports owned live leftovers as unchanged while an older journal is compensating. Multiple historical forks require reconciliation; unrelated or malformed journal records are preserved and do not authorize ownership. Ordinary apply failures run reverse-order compensation through the SDK transaction coordinator. Unchanged creates from this transaction are removed, with native append-only delete events retained. The deterministic transaction ID uses `deriveMutationTransactionId` where available and binds reviewed source/settings, native target identities and expected absent revisions; existing journals keep their original keys across upgrades. Before removing anything, compensation runs native SDK delete policy/guard checks and revalidates ownership, complete history, scope and settings under the SDK item lease. The SDK derived-index lease covers removal and authoritative index refresh; the item lease releases last. Foreign records and peer edits are preserved. Policy refusal or a changed owned target requires explicit journal reconciliation rather than an unsafe cleanup. Invalid plans leave the entire tracker byte-identical, including history and journals. After a persisted row fails, compensation restores byte-identical live documents and preserves unrelated records; append-only native audit events and the recovery journal remain. It does not erase the audit trail to reproduce the entire pre-import directory byte for byte. An immutable tombstone is recorded before file removal, so interrupted cleanup can validate the surviving document against its prior SDK revision and finish removal without rewriting history. Recovery then refuses to resurrect the old plan's reserved native IDs: preview fresh identities after cleanup completes. A crash during forward apply can resume the original plan when all owned revisions are unchanged. This is compensating atomicity, rather than isolation from readers during an in-progress transaction. Receipts contain bounded counts and at most 20 coordinate-only issues; `issueCount` reports the complete total. `ok: false` means no reviewable plan or some targets skipped. Applied/unchanged/skipped partition the selected rows. Thrown `JoinRefusal` errors have exit status 2, `code`, `remedy` and host-native `nextSteps`: `csv_join_invalid`, `csv_join_io`, `csv_join_settings_changed`, `csv_join_target_changed`, `csv_join_apply_failed`, `csv_join_reconcile`. Correct the input or reconcile current SDK state as directed; retries never silently overwrite newer target revisions. ## Without git Preview, apply and replay work in plain initialized trackers without a Git executable. Git is not needed for these commands. ## Explicit scope and refusal boundaries All package mutation paths share `buildMutationIntent` in `mutation-intent.ts`. A create with no parent uses the SDK's `unset: ["parent"]` form; an empty CSV parent cell never means “inherit the current focus”. Absent create assignment, reviewer, sprint/release, goal/objective and blocker fields are also explicitly unset, and absent dependency/file/doc/test collections are explicitly cleared. The intent never reads session focus or the working directory. Native `none`/`null` clear aliases for every supported nullable scope scalar and linked collection are converted to explicit unsets too. Stored SDK patch/restore snapshots preserve their literal values and do not interpret them as command-input aliases. Legacy CSV imports use the same builder for standard, streaming, atomic and schema-negotiated imports. On keyed updates, absent columns and empty cells preserve current values and dependency edges. Nonempty supported cells set values; `none`/`null` explicitly clear supported nullable scope fields, and blocker cells add edges. Spreadsheet patches, compensation and marker cleanup preserve unselected native scope; raw patches/restores build their selected scope from the current document inside the SDK item lock. Native lifecycle policy still owns terminal transitions. Join replay compares current native scope to the reviewed source intent using SDK canonicalization. It refuses old owned records with an inherited parent, unreviewed scope or extra links, including when their unchanged history and a committed journal would otherwise look reusable. Lineage reports these old scope mismatches as identity conflicts; legacy atomic create receipts also refuse scope drift. Changing focus after preview is harmless for a correctly reviewed plan and never adds a parent. Both `previewJoins` and `applyJoins` expose only `JoinRefusal` on failure. Malformed quoting, ragged records and inconsistent line endings are wrapped from the table parser, retaining its `sourceCode`, actionable `remedy` and original `cause`. The CLI does the same for invalid UTF-8/JSON and file errors. Expected lower-level failures are not leaked as another API's refusal family. Joined preview, apply, replay and compensation activate the selected workspace's extensions. Native type registries supply installed types, folders and defaults; authoritative reads and scope normalization include registered extension fields, including under strict unknown-field policy. SDK field defaults remain intact. The existing CSV field vocabulary and history-based ownership rules still apply: an independent edit to any field refuses compensation rather than deleting the peer's item.