# Composition Plan AI Authoring Guide

Start with [START-HERE](START-HERE.md). This guide explains how to use a live
manifest; it is not a replacement for the complete JSON Reference.

## Reading the manifest

| Member | Use |
| --- | --- |
| `schema`, `version` | Identify the manifest format; version 1 alone is not a list of installed capabilities. |
| `units`, `jsonPropertyNaming` | Geometry is in points and JSON keys use lowerCamelCase. |
| `userScriptsPanelFolder` | Local path to the current user's InDesign Scripts Panel folder for installing a generated script. Included when InDesign supplies the path. |
| `sectionTypes` | Available section families, properties and per-type restrictions. Shared property listings do not make every property meaningful on every type. |
| `threadProperties` | Direction, spacing and thread-level controls. |
| `compositionPlanJSON` | Root members, selectors, grouping, expressions, layout and validation contracts. |
| `compositionPlanJSON.layoutPatternContract` | Fixed counts versus responsive fixed-width columns, units and limits. |
| `data.description` | Selection description/snapshot; do not assume a bounded sample contains all records. |
| `data.groupHierarchy` | Existing grouping levels, used to preserve group scope. |
| `data.fields` | Exact names and definitions, including comparison/formatting and tabular status. |
| `document.available` | Whether live document resources were available at export. |
| `document.formattingRules`, `ruleSets`, `parents`, `pages` | Available named assets, their settings and target geometry. |
| `authoring` | Embedded output, binding, checking and offline guidance; additive metadata, not a plan-root member. |
| `authoring.documentationRoot` | Root URL of the published composition-plan documentation. Use its JSON Reference for detailed constraints. |

Export a new manifest after changing the selection, assets or document. The
manifest describes availability; it does not prove every asset fits the target.
The documentation URL is a reference for authoring, not a source of installed
capabilities or document-specific resource names.
The strings showing `{...}` shapes are explanatory notation, not literal JSON
or complete JSON Schema documents.

## Choose data scope before layout

`selectionRoot` denotes the selected hierarchy. A group wrapper is not one
record and `result: "self"` does not iterate its descendants. Use `forEach` with
`shape: {"scope":"records"}` when a card should appear once per record. Bind its
template to the loop's `itemName` through `source: "variable"`.

For named groups, use the named-group collector described by the manifest;
bind descendants to their enclosing group variable instead of selecting the
whole root again. Inspect `data.groupHierarchy` before choosing group levels.
Do not wrap an authored table or native template container in a record loop
merely to make it populate: those sections can already own population of a
complete source wrapper. Consult their data-cardinality contracts.

## Choose the section and layout

| Intent | Starting point |
| --- | --- |
| One reusable design per record | `forEach` and `formattingRule`; a wrapping body for cards. |
| Flowing text | `textFrame` or `textFlow`, with the documented asset/story requirements. |
| Record table | `table`; choose generated versus `structure: "authored"` explicitly. |
| Live design on a master page | `masterPage` with the exact master name and one-based page index; exactly one top-level source item. |
| Native authored container | `templateContainer` referencing a container formatting rule. |
| Group header, continuing content and footer | `flow` with header/body/footer regions. |
| Explicit transaction across sibling sections | Named `constraintGroups` with contiguous sibling membership. |
| Multiple independently populated lanes | Named threads and the documented coordination policy. |

For plans that use master-page artwork, retain the `masterPage`
references rather than replacing them with saved-rule asset names. Their
placement flows below preceding output and preserves authored outsets.
Set `insideMargins` for each section: `true` uses margin-relative
positions; `false` uses source page-relative positions, including the source
margin offsets, for a full-page target or a container with that intended area.
Omitting it preserves the older inside-margins behavior.
Set `spaceAfter` in points to add trailing space. A master reference reads
live artwork on each compilation and can be used in a plan container as well
as document pagination. See [Master-page sections](Composition%20Plan%20JSON%20Reference.md#master-page-sections)
for the placement formula and example.

Keep the distinction between `layoutPattern.columns` (equal divisions of the
available width) and `layoutPattern.columnWidth` (preserve a width in points and
fit as many full columns as possible). Use exactly one geometry mode:
`columnWidth`, `columns`, `rows`, or `areas`. `columnGutter` is in points. Explicit
area bounds are fractions; ordinary physical bounds and insets use points.
For fixed-width columns, unused width remains unused; a narrower target gets
one area at its available width and still must satisfy section fit rules.
Fixed-width patterns currently use compact sequential placement, not balancing.

Putting columns inside a flow body keeps its outer header above the column
region. Putting the whole group flow inside columns lets the header participate
in each column's continuation. These are different structures.

## Product data sheets from master pages

Use the [Data Sheet Pagination Guide](Data%20Sheet%20Pagination%20Guide.md)
when a product's overview, specifications, variants and drawings should flow
as one sheet. It covers preparing one top-level item per source master,
inherited fitting/keeps, margin-relative placement and container population.
Start with the generated plan and exact source master references. Establish
which record or product group defines one execution before adding selectors
or loops. Ask for the intended sheet-start policy: one execution per group
does not automatically mean a new physical page per group.

## Headers, spacing and fit

Flow-header `repeat` choices include `first area`, `every area`, `every page` and
`every spread`. Page/spread policies are per flow occurrence, not global to the
document. A first-area header and continuation variant share boundary tracking.
A new group can therefore have its own header on an already used page. Unknown
physical page/spread identity falls back to per-area repetition. Do not use an
`areaIndex` modulo expression as a substitute for physical-page repetition when
column counts can change.

Use `spaceBefore`/`spaceAfter` for section boundaries and region gutters for
spacing between siblings. `spaceBeforeAtAreaStart` defaults to `retain`; choose
`suppress` to remove it at an area start. `trimTrailingSpace` is flow-only and
removes inherited final-child spacing before the flow's own `spaceAfter`.
Auto-fit dimensions and limits are distinct from continuation permission.
`threadable: false` requires complete text to fit; disabling it is not a way to
silently truncate text. Keep constraints must survive physical trial layout.

## Authored table overrides

`table.columns.byIndex` addresses physical prototype columns. With
`structure: "authored"`, use `table.cellAttributes.byIndex` entries containing
zero-based `row` and `column` anchor coordinates plus settings. Coordinates refer
to the original table including header/footer rows, before population expands
it. Do not target covered positions inside merged cells. Asset-dependent bounds
and anchor validity require physical validation. Use the JSON Reference for
allowed merge values and override precedence; do not invent `"non"` for `"none"`.

## Validation and repair

`session.ecCheckCompositionPlanJSON(json, options)` supports `contract`,
`resolve` and `layout`. Resolve/layout require the intended target and selection;
layout is bounded and rolled back. See the API Reference for exact options.
To check a plan in InDesign, select its container and choose **Composition Plan (Beta) →
Check Composition Plan...** from the Containers panel menu. Use the diagnostics
in the report when revising the plan.

Diagnostics use JSON Pointer paths: `/threads/0/content/1` selects the second
content item of the first thread. Within a member name, `~1` means `/` and `~0`
means `~`. Use the returned message and expected value; not every execution
failure is a portable grammar error.

| Diagnostic situation | Correction |
| --- | --- |
| Missing property, invalid type/value, out-of-range | Repair the exact pointed-to member using the installed contract. |
| Unknown member or unsupported feature | Remove or replace it only after checking the intended behavior; do not invent aliases. |
| Ambiguous layout | Select one layout geometry mode. |
| Missing field, asset or parent | Match the live manifest exactly, including Unicode; refresh stale exports. |
| Asset-contract failure | Inspect the actual rule's roots/story/table/container structure; changing its name cannot repair its shape. |
| No fit or no progress | Inspect actual versus available bounds, size limits, keeps and continuation capacity. Do not suppress the failure by omitting required data. |
| Successful trial with remaining content | Increase the diagnostic area budget or inspect continuation; do not call the catalogue complete. |

Keep authoring provenance and repair notes outside the strict plan JSON. A
native preview on representative initial/continuation pages remains necessary.

## Minimal record-loop example

This is an authoring example. Replace `Record Card` with a compatible formatting
rule from the live manifest before checking it. No claim of live validation is
made for this placeholder asset.

```json
{
  "schema": "easycatalog-composition-plan/1",
  "threads": [{
    "name": "records",
    "direction": "top to bottom",
    "content": [{
      "type": "forEach",
      "itemName": "record",
      "data": {"source": "selectionRoot", "result": "children", "shape": {"scope": "records"}},
      "template": {
        "type": "formattingRule",
        "name": "record-{index1}",
        "asset": "Record Card",
        "data": {"source": "variable", "variable": "record", "result": "self"},
        "overflow": "continue"
      }
    }]
  }]
}
```
