# Phase 3 — Write Resource Records & Update Index

INPUT: the manifest from Phase 1 plus transcripts/text from Phase 2. OUTPUT: one resource `.md` per new ready resource and an updated `docs/inputs/<project-slug>/index.json`.

Run the following:

```
1. Resolve project paths:
   - Records directory: `docs/inputs/<project-slug>/transcriptions/`
   - Index path: `docs/inputs/<project-slug>/index.json`

2. For each manifest item in order:
   - If decision is `reuse`, do not rewrite its existing `.md` and do not change the existing index entry.
   - If audio transcription failed, create or update the index entry with `status: failed`, `md: null`, and the current `src`. Do not write a resource `.md`.
   - If item is ready (new/retry/reprocess AUDIO with transcript, TEXT with content, or INLINE text), write a resource `.md`.

3. Resource slug rules:
   - For file inputs, start from the source filename without extension, kebab-cased.
   - For inline inputs, use `nota-inline-<N>`.
   - If `docs/inputs/<project-slug>/transcriptions/<resource-slug>.md` already exists for another source, append `-2`, `-3`, etc. until the path is free.
   - If the path exists for the same source, treat it as reuse and do not overwrite unless Phase 1 marked it `reprocess` because the prior path was missing/unreadable.

4. Copy `templates/input-record.md.tmpl` for each ready resource and fill:
   - `DATE`: today, ISO YYYY-MM-DD.
   - `PROJECT_SLUG`: the project slug.
   - `RESOURCE_SLUG`: the resource slug.
   - `RESOURCE_TYPE`: `audio`, `text`, or `inline`.
   - `STATUS`: `ready`.
   - `SOURCE_PATHS`: JSON-style array of source paths, or `[]` for inline.
   - `INDEX_PATH`: `docs/inputs/<project-slug>/index.json`.
   - `TITLE`: current interaction-language title for the resource record.
   - `SOURCE_RECORD_NOTE`: current interaction-language note that this record is faithful source material.
   - `NO_INTERPRETATION_NOTE`: current interaction-language note that no summary or interpretation was added.
   - `BODY_LABEL`: current interaction-language label for transcript, text, or inline note.
   - `BODY`: verbatim transcript/text/inline content.

5. Update `index.inputs`:
   - Locate an existing entry by matching `src`.
   - If none exists, append a new entry in encounter order.
   - Ready entry shape:
     `{ "src": "<project-relative source>", "md": "transcriptions/<resource-slug>.md", "status": "ready" }`
   - Failed entry shape:
     `{ "src": "<project-relative source>", "md": null, "status": "failed" }`
   - Ignored entries, if present, MUST be preserved unchanged.

6. Write `index.json` with stable pretty JSON indentation. Do not include full transcript text in the JSON.

RULES:
- Generated headings, notes, and final reports use the current user interaction language. Verbatim source content remains exactly as provided.
- Do not write a consolidated batch Markdown file.
- Do not overwrite an existing ready resource record for another source.
- Do not start any downstream skill (`business-proposal`, `render-docx`, ...). Stop after writing records and index.
```

FINAL REPORT:

- Show the project slug.
- Show counts: reused, new ready resources, failed resources, ignored resources.
- Show each written resource path.
- Show the updated index path.
- Score against `references/checklist.md`. Pass criterion: 9/9. If any item fails, fix it and re-score.
- Stop here. In the user-facing next-step suggestion, print exactly `/machine-business:business-proposal <project-slug>`. Do NOT run it.
