# SKILL — lfcs-job-scaffold

## Purpose

Create a new LFCS job folder per the canonical 11-section structure (`lfcs-standards/folder-spec.md`) and seed it with a populated `00-brief.md` + `README.md`. First step of every new bid or awarded job.

## Trigger

User says any of:
- "New bid for [job number] [client] [site]"
- "Working on a new bid — [details]"
- "Scaffold a job folder for [details]"
- "Awarded — set up the project folder"

Or invoked programmatically by `lfcs-tender-correspondence` (v2) when a tender pack arrives.

## Inputs

Required:
- `job_no` — 4-digit, year-prefixed (e.g. `2602` = 2nd job of 2026)
- `client` — head contractor name (e.g. "Dec Projects")
- `site` — short site/project name (e.g. "Munmorah Bridge")
- `bid_due` (if upcoming bid) OR `start_date` (if awarded) — ISO date

Optional:
- `end_client`, `designer`, `client_signatory_*`, `type` (price / dayworks / etc.), `qs_call`

## Behaviour

1. **Validate `job_no`** — must be 4 digits, year-prefixed, sequential. Read `Jobs/Upcoming/`, `Jobs/Ongoing Jobs/`, `Jobs/Completed Jobs/` to check no collision. If collision, abort + ask user.
2. **Determine destination:**
   - If bid (`bid_due` set, `start_date` empty): `Jobs/Upcoming/{job_no} - {client} - {site}/`
   - If awarded (`start_date` set): `Jobs/Ongoing Jobs/{job_no} - {client} - {site}/`
3. **Create the 11-section folder tree** per `lfcs-standards/folder-spec.md`. All sub-folders get a `.gitkeep` placeholder so empty sections sync cleanly.
4. **Write `00-brief.md`** with frontmatter populated from inputs. Use the 2602 Munmorah `00-brief.md` as the template — preserve every frontmatter field, default unknowns to `TBC` (never invent).
5. **Write `README.md`** — folder map mirroring `folder-spec.md` per-job structure block, status line ("Status: bid in prep — bid due {date}"), and pointers to `00-brief.md` + `00-Bid-Prep.md` (if exists).
5b. **Write per-job `CLAUDE.md`** (added v3 — cowork-lfcs Phase 6, transcript-gap fix; v4 Phase 7 adds Patterns section; **v5 Phase 8 — adds orientation layer adopted from Friend-Vault-Audit-2026-05-06**). Per-job AI context inheriting from `_System/CLAUDE.md` + `11_OpsMan_LFCS/_Brain/CLAUDE.md`. Two-layer structure:

   **Top layer — orientation (NEW v5 — surfaces job state in 5 seconds):**
   - **Quick Links table** — one wikilink per per-job artefact (00-brief, 00-Bid-Prep, _REGISTER files, key drawings, latest pricing-grill, Pre-Call-Questions). Pattern adopted from Hasibul Khan's `03 - Claude Memory/Jobs/[job].md`.
   - **Status one-liner** — Stage (Bid / Upcoming / Ongoing / Completed / DLP) + key date (bid due, site start, PC date)
   - **What I Know** — terse bullets: subcontract / contract value, programme, payment basis + claim cadence, critical scope conventions (FRP-install-only, props excluded, etc.), site supervisor / signatory
   - **Documents Completed** — checkbox list of done items
   - **What's Pending** — checkbox list of in-flight items, ⚠ flag for time-critical
   - **Site Team** — wikilinks to `40_People/{Name}.md` for each LFCS supervisor / lead on this job

   **Bottom layer — reference (existing v3-v4 sections):**
   - Job snapshot (Job Number / Client / Site / Status / Bid Due / Active Bid Airtable record id / Job Airtable record id / Vault path)
   - Scope (1-line)
   - Where things live (folder map table)
   - Live registers ALWAYS-go-to-source rule
   - Airtable pointers (per-table query hints with this Job's record id)
   - Skill routing table for this job
   - Patterns section (wikilinks to applicable cross-cutting concept notes from `Operations/lfcs-standards/concepts/`; lookup via `job_type` input — see lookup table below)
   - Job-specific notes / risks / open items
   - Common Rocky-queries quick handlers
   - Source files in vault

   Use the 2602 Munmorah CLAUDE.md or 2626 Mack Civil CLAUDE.md as the regression template (both updated to v5 structure 2026-05-06). Generated for new jobs; updated on material change. **Append-only on Documents Completed (mark items done, never unmark) and on What's Pending (move items to Documents Completed when done, never delete).**

**Patterns lookup table (v4):**
| `job_type` input | Wikilink in Patterns section |
|---|---|
| `stormwater-pit`, `drainage-pit`, `kerb-inlet-pit` | `[[lfcs-standards/concepts/TfNSW-R0220-pit-pattern]]` + `[[lfcs-standards/concepts/Defensible-for-variations-posture]]` |
| `bridge`, `bridge-substructure`, `bridge-superstructure`, `bridge-FRP-package` | `[[lfcs-standards/concepts/TfNSW-bridge-FRP-subcontract-pattern]]` + `[[lfcs-standards/concepts/Defensible-for-variations-posture]]` |
| `footing`, `slab`, `wall`, `field-of-play` (private commercial) | `[[lfcs-standards/concepts/Defensible-for-variations-posture]]` (decision tree only — no specific TfNSW concept) |
| `unknown` or unset | No Patterns section; flag for Rocky to add manually OR re-run scaffold with explicit job_type |

Always also link `[[lfcs-standards/pricing-checklist]]` (cross-cutting, applies to all jobs).
6. **Append project log:** one-liner to `11_OpsMan_LFCS/_Brain/_Log.md` per AI Team Protocol write protocol.
7. **Append daily note:** session entry to `01_Daily/{today}.md` per protocol.
8. **Output to user:** absolute path of new folder, list of next-step skills to run (`lfcs-drawing-extract-text` once drawings dropped, `lfcs-boq-parse` once BOQ dropped).
9. **After vault writes commit, invoke `lfcs-airtable-sync`** with `vault_path={job_folder}/00-brief.md` and `target_table=Jobs`. Per the Airtable behaviour section above, failure is non-blocking — log to `_System/Conflicts.md` and continue.

## Files to read (in order)

```
HQ-Vault/_System/CLAUDE.md                                       ← AI Team Protocol
HQ-Vault/11_OpsMan_LFCS/_Brain/CLAUDE.md                         ← LFCS-specific extensions
HQ-Vault/11_OpsMan_LFCS/Operations/lfcs-standards/folder-spec.md ← canonical structure
HQ-Vault/11_OpsMan_LFCS/Operations/Jobs/Upcoming/2602 - Dec Projects - Munmorah Bridge/00-brief.md  ← regression fixture template
HQ-Vault/11_OpsMan_LFCS/Operations/Jobs/Upcoming/2602 - Dec Projects - Munmorah Bridge/README.md   ← README template
HQ-Vault/11_OpsMan_LFCS/Operations/Jobs/Upcoming/2602 - Dec Projects - Munmorah Bridge/CLAUDE.md   ← per-job CLAUDE.md template (v3, cowork-lfcs Phase 6)
```

## Airtable behaviour

- **Reads:** `Jobs` (search by Job Number to detect collision before scaffold).
- **Writes:** `Jobs` (upsert one row — Job Number / Name / Client / Status / Bid Due / Vault Path / Drive Folder URL when known). Calls `lfcs-airtable-sync` as final step with the new `00-brief.md` as input + `target_table=Jobs`.
- **Idempotency:** searches `Jobs` by Job Number primary field; updates existing row, does not create duplicate. Re-running on same `job_no` = no-op for Airtable (matches vault scaffold abort-on-existing rule).

## Output format

Plain text to user:

```
✓ Scaffolded {job_no} - {client} - {site}
  Path: HQ-Vault/11_OpsMan_LFCS/Operations/Jobs/{Upcoming|Ongoing Jobs}/{folder}/

Created:
  - 00-brief.md (frontmatter populated, {n} TBC fields)
  - README.md (folder map)
  - 11-section folder tree (with .gitkeep placeholders)

Next steps:
  1. Drop drawings into 03/03a — Issued for Construction/
  2. Drop BOQ xlsx into 02/02b — BOQ and Rate Schedules/
  3. Run lfcs-drawing-extract-text + lfcs-boq-parse
  4. Run lfcs-bid-prep-doc + lfcs-precall-questions + lfcs-incl-excl-draft

TBC fields in 00-brief.md (fill from QS call or tender pack):
  - {list each TBC field}
```

## Hard rules

- **Never overwrite an existing job folder.** If the destination exists, abort + tell user.
- **Never invent metadata.** Unknown fields default to `TBC` literal string, never plausible-sounding fiction.
- **Naming:** hyphens between words, no underscores or spaces in filenames per folder-spec.md.
- **Append-only on `_Log.md` + daily note** per AI Team Protocol.
- **Read-before-edit:** even template files — re-read 2602 `00-brief.md` each invocation in case template has evolved.
- **Regression fixture:** if running on 2602 inputs, output must equal what's already in `Jobs/Upcoming/2602 - Dec Projects - Munmorah Bridge/00-brief.md` modulo frontmatter dates. Any drift = blocking issue.
- **Vault markdown is source of truth.** If `lfcs-airtable-sync` write fails, this scaffold is still considered successful — log the Airtable failure to `_System/Conflicts.md` and continue. Never block on Airtable.

## Dependencies

- `lfcs-standards/folder-spec.md` (canonical structure)
- 2602 Munmorah Bridge folder (regression fixture)

## Failure modes

| Failure | Detection | Recovery |
|---|---|---|
| job_no collision | Pre-check Jobs/* folders | Abort, ask user for new number |
| Required input missing | Validate before scaffold | Ask user for missing field, do not proceed |
| Filesystem write error | Catch on directory create | Abort, surface error, no partial scaffold |
| Template drift (2602 frontmatter changed) | Re-read template each invocation | Use current template; flag in output if structure changed |
