diff --git a/.changeset/34770-upgrade-skill-router.md b/.changeset/34770-upgrade-skill-router.md new file mode 100644 index 00000000000..f9ecfa42edb --- /dev/null +++ b/.changeset/34770-upgrade-skill-router.md @@ -0,0 +1,23 @@ +--- +'@objectstack/skills': patch +--- + +docs(skills): the objectstack-upgrade entry file becomes a router + +Clause-②: no +Metadata-protocol: none + +`skills/objectstack-upgrade/SKILL.md` goes from 24.7 KB to 9.0 KB (481 lines to 159). It now holds five things: the boundary (the four "never" rules and one `conversionId` per commit), four first checks (the authored major, the `os validate` control, where the prescriptions ship, the skills re-install), the Quickstart command block, seven traps that each look finished and are not, and the rule for when you decide a residue item alone and when you ask the owner. A table at the end says which section of the reference file to open. No rule's teaching changes. Text moved, and this entry says where it went. The skill's two authored files are 0.3 KB smaller together (29.5 KB to 29.2 KB). + +**What the entry keeps.** The seven traps: `os migrate meta` rewrites no source file by default, so the printed edits are ported by hand, or `--write` is passed and the edits it only lists are ported, then the range is replayed; a green `validate` does not mean the chain has nothing left, so replay `--from --to --json` until `applied` is `[]` with no `replayedNothing`; stored `sys_metadata` rows are rewritten only at read and only while the release carries their conversions, so run the `--stored` pass before you leave it; data migrations are per-deployment gates the report carries as `pending`; code on a retired API can keep compiling while it reads `undefined`; prose that still teaches the old shape fails nothing; and the parse-gate probe is a plain data literal with no `define*` call. + +**What left, and where it is now.** `references/examples-upgrade.md` now holds the whole run in order, around the three blocks it already had (the worked R1, the report template, the v17-canonical shapes, all unchanged): + +- `0 · Preflight` (`#0--preflight`): the three sources of the FROM major, the `.upgrade/` workspace, the commands that re-install the skills. +- `1 · Mechanical layer` (`#1--mechanical-layer`): what a run does and prints, stored rows, data gates. +- `2 · Semantic residue` (`#2--semantic-residue`): where the prescriptions ship and how to harvest them, the residue classes, what each decide-or-ask condition looks like, the R2 and R3 searches. +- `3 · Acceptance` (`#3--acceptance`): typed, parse-gated, validate, the reverse check (`#reverse-check`) with its three outcomes, the stored-row assertion. +- `Failure modes` (`#failure-modes`) and the `--json` error codes. +- Anchors that no longer exist in `SKILL.md`: `#-the-boundary--read-this-before-the-first-command` (now `#-the-boundary`), `#0--preflight`, `#establish-the-from-major--do-not-guess-it`, `#make-the-work-reviewable-before-you-change-anything`, `#re-install-the-skills-from-the-moved-catalog`, `#1--mechanical-layer--invoke-the-chain`, `#what-os-migrate-meta-actually-does`, `#-the-one-fact-that-surprises-every-operator`, `#stored-rows-rehydration-replays-what-the-release-carries`, `#data-migrations-are-not-metadata-migrations`, `#2--semantic-residue--the-part-that-is-yours` and its `2.1` to `2.6` sections, `#3--acceptance--what-upgraded-means` and its `3.1` to `3.6` sections, `#reverse-check`, `#failure-modes`. `#quickstart`, `#decide-alone-or-ask` and `#cross-skill-routing` still do. + +**Not carried over, because something else already says it.** The list of `os migrate meta` forms (`os migrate meta --help` prints the same forms and describes every flag; the Quickstart keeps the ones a run needs), and two `Failure modes` rows. "Reports changes, but the files are unchanged": its symptom and cause are trap 1, and its fix (pass `--write`, or port the printed edits by hand, then replay) is kept as that trap's last sentence. "Findings that have nothing to do with retired keys" restated first check 2, the control. diff --git a/scripts/check-skills-token-ratchet.mjs b/scripts/check-skills-token-ratchet.mjs index 06b6137ca5f..754909c5977 100644 --- a/scripts/check-skills-token-ratchet.mjs +++ b/scripts/check-skills-token-ratchet.mjs @@ -1349,7 +1349,16 @@ export const CEILINGS = new Map([ // `references/examples-upgrade.md` (row below), one pointer line each. // 6193 -> 6188: A2′ — the release-stamp line left the count (see // STAMP_LINE_REPIN); the file's count fell by the same 5, headroom unchanged. - ['skills/objectstack-upgrade/SKILL.md', 6170], // -18 to the measurement (was 6188) + // 6170 -> 2244 (#34770): the entry becomes a router. It keeps the boundary, four first + // checks, the Quickstart, seven traps (each looks finished and is not) and the decide-alone- + // or-ask rule, then a routing table into `references/examples-upgrade.md` (row below), which + // RECEIVES the rest as the complement of what stays, so nothing is stated twice. The file is + // 24707 bytes (24680 priced) -> 9000 (8973 priced) -> 2244 tokens, pinned AT the measurement. + // The two objectstack-upgrade rows sum 7363 -> 7288 (-75), so the sum of all ceilings falls. + // Authority: the ruling of record that orders the entry file down to router size, decision + // record #34691 S3 = A, and ruling 7128031203 fork 4 = A on #34770 for the row that rises. + // ceil(($(wc -c < skills/objectstack-upgrade/SKILL.md) - 27) / 4) == ceil(8973 / 4) + ['skills/objectstack-upgrade/SKILL.md', 2244], // ── the #12392 extension: the rest of the AUTHORED bundle ──────────────── // Every row below is an INITIAL measurement, taken on @@ -2562,7 +2571,21 @@ export const CEILINGS = new Map([ // silent failure and links the rest. 12505 -> 11360 bytes (-1145) -> 2840 tokens. // ceil($(wc -c < skills/objectstack-platform/references/plugin-development.md) / 4) == ceil(11360 / 4) ['skills/objectstack-platform/references/plugin-development.md', 2840], - ['skills/objectstack-upgrade/references/examples-upgrade.md', 1193], // -4 to the measurement (was 1197) + // 1193 -> 5044 (#34770): RECEIVES from SKILL.md, no new teaching: `## 0 · Preflight`, + // `## 1 · Mechanical layer`, `## 2 · Semantic residue` (2.1, 2.2, 2.4 to 2.6 around the worked + // R1 already here), `## 3 · Acceptance` (3.1 to 3.3, 3.5, 3.6 around the report template + // already here) and `## Failure modes`. PAID DOWN FIRST: each section was cut to the complement + // of what the entry still says, the `os migrate meta` form list is one pointer at + // `os migrate meta --help` (the CLI prints the same forms and every flag), and two Failure + // modes rows are gone: one whose symptom is entry trap 1 and whose fix is that trap's last + // sentence, and one that restated the control. The three blocks that were + // here are byte-identical. The file is 4772 -> 20174 bytes (+15402) -> 5044 tokens, zero + // headroom before, ceiling +3851, pinned AT the measurement; the entry row above falls 3926, + // so both conditions of ruling 7128031203 fork 4 = A hold (moved text at the measurement, and + // the sum of ceilings does not rise). The skill's two authored files are 305 bytes smaller + // together (29479 -> 29174). + // ceil($(wc -c < skills/objectstack-upgrade/references/examples-upgrade.md) / 4) == ceil(20174 / 4) + ['skills/objectstack-upgrade/references/examples-upgrade.md', 5044], // NEW FILE, pinned AT the measurement: the context pack (`ai_context`, ADR-0160) // is a metadata kind no published skill taught beyond its key name. Card #37177 // (the `Skills-docs: follow-up` of the PR that admitted the kind) asks for the diff --git a/skills/objectstack-upgrade/SKILL.md b/skills/objectstack-upgrade/SKILL.md index adee7c0b6c3..6afe715b390 100644 --- a/skills/objectstack-upgrade/SKILL.md +++ b/skills/objectstack-upgrade/SKILL.md @@ -25,42 +25,52 @@ metadata: > **preflight → mechanical chain → semantic residue → acceptance report** -## ⛔ The boundary — read this before the first command - -**Never hand-write a rewrite the chain already applies.** If a key was renamed, -the conversion table knows the rename; running the chain attributes each rewrite -to a hop and proves the result is schema-valid. A hand-edit does neither, and it -silently diverges the moment the chain gains an entry. - -**Never add a tolerant read to make old metadata load.** No `??` alias, no -"accept both spellings" branch, no coercion in the project's own code. A key was -retired because nothing enforced it or because exactly one spelling survives; -re-admitting the old one at the consumer is how the defect the retirement closed -comes back inside the customer's repo, where no gate can see it. - -**Never resolve a residue item by guessing the owner's intent.** The residue -exists precisely because it is a business decision. The rule for when you decide -alone and when you ask is in [Layer 2](#decide-alone-or-ask) — it is the most -important paragraph in this skill. - -**Never report "upgraded" without the acceptance artifacts.** `validate` green -plus the report is the machine criterion. Absent either, the status is -*in progress*, whatever the diff looks like. - -**One `conversionId` per commit**, where the project's review culture allows it. -The id is the commit's subject line and its justification. - ---- +## ⛔ The boundary + +- **Never hand-write a rewrite the chain already applies.** The conversion table + knows the rename; the chain attributes each rewrite to a hop and proves the + result schema-valid. A hand-edit does neither, and silently diverges the + moment the chain gains an entry. +- **Never add a tolerant read to make old metadata load**: no `??` alias, no + "accept both spellings" branch, no coercion in the project's own code. It + brings the defect the retirement closed back inside the customer's repo, where + no gate can see it. +- **Never resolve a residue item by guessing the owner's intent** — it is a + business decision. [Decide alone, or ask](#decide-alone-or-ask) is this + skill's most important paragraph. +- **Never report "upgraded" without the acceptance artifacts.** `validate` green + plus the report is the machine criterion; absent either, the status is + *in progress*. +- **One `conversionId` per commit**, where the project's review culture allows + it: the id is the commit's subject line and its justification. + +## First checks + +1. **`--from` is the major the metadata was authored against, not the one + installed.** Read `manifest.engines.protocol`, a range, and take its floor: + `'^17'` → `--from 17`, `'>=15 <18'` → `--from 15`, never the upper bound. + Else read the lockfile's history. If the two disagree, ask — ⛔ never default + to the lower one. +2. **Keep a control**: `os validate` on the un-upgraded source, in + `.upgrade/`. A rule finding already in it is pre-existing, not upgrade residue. +3. **Read the prescriptions from the install, never from memory**: the chain's + `--json` result, and the `spec-changes.json`, tombstone `[REMOVED] …` text + and `CHANGELOG.md` inside `@objectstack/spec`. ⛔ Every count you report is a + reading of *this* install. +4. **Re-install the skills.** A lock entry reading `sourceType: github` (from + `skills add`) is skipped by the sync, exit 0, and the agent keeps reading the + old major's skill text. ## Quickstart ```bash -# 0 · preflight — what major is this project on, what major is installed? +# 0 · preflight — the authored major, the installed one grep -rn "protocol" objectstack.config.ts package.json | head node -p "require('@objectstack/spec/package.json').version" -# 1 · mechanical — replay the chain (writes only --out; --write also rewrites the sites it can prove) -os validate > .upgrade/validate-before.txt 2>&1 || true # the control, kept +# 1 · mechanical — replay the chain (trap 1) +mkdir -p .upgrade +os validate > .upgrade/validate-before.txt 2>&1 || true # the control, kept os migrate meta --from 16 --step os migrate meta --from 16 --json > .upgrade/migrate.json os migrate meta --from 16 --out .upgrade/migrated.stack.json @@ -69,413 +79,81 @@ os migrate meta --from 16 --out .upgrade/migrated.stack.json node -e "console.log(require('fs').readFileSync(require.resolve('@objectstack/spec/package.json').replace('package.json','spec-changes.json'),'utf8'))" > .upgrade/spec-changes.json # 3 · acceptance — all four, not three -os validate # green (compare against validate-before.txt) -tsc --noEmit # tombstones type the retired keys as `never` -os migrate meta --from 16 --to 18 --json # `applied` [] and no `replayedNothing` (see §3.3) -# → write .upgrade/REPORT.md (template in §3.4) -``` - ---- - -## 0 · Preflight - -### Establish the FROM major — do not guess it - -`--from` is the protocol major the metadata was **authored** against, not the -one installed. Three sources, in order of authority: - -1. **`manifest.engines.protocol`** in the stack config — the declared answer, - checked by the boot handshake. It is a **range**, not a version: every - scaffold and example writes the caret form (`engines: { protocol: '^19' }`), - and an exact `'16.0.0'` is only a range of one. Take the major it *targets* — - the floor: `'^17'` → `--from 17`, `'>=15 <18'` → `--from 15`, never the - upper bound. -2. **The last `@objectstack/spec` major the project ever installed** — read the - lockfile history (`git log -p pnpm-lock.yaml | grep -m5 '@objectstack/spec'`) - when the manifest is absent or stale. -3. **Ask.** A manifest that says 16 on a project last touched two years ago is a - claim, not a measurement. If (1) and (2) disagree, settle it — ⛔ never - default to the lower one: a default flip ([3.3](#33-validate)) stamps its - constraint onto a source already past that major. - -Arriving several majors late is the designed-for case: `os migrate meta --from 16` -replays every step in order, with no requirement to upgrade one major at a time — -down to the chain's support floor, 16 today. - -### Make the work reviewable before you change anything - -```bash -git checkout -b upgrade/protocol-17 -mkdir -p .upgrade -``` - -The `.upgrade/` directory is the deliverable's workspace: the machine outputs -(`migrate.json`, `migrated.stack.json`, `spec-changes.json`, `retired-names.txt`) -and the human output (`REPORT.md`). Keeping them in the repo for the review, and -deleting them on merge, is the usual arrangement — decide it with the owner. - -### Re-install the skills from the moved catalog - -A 17.x project's skills came from `skills add`; their `skills-lock.json` entries -read `sourceType: github`, so the sync skips them (exit 0) and the agent keeps -reading 17.x skill text. Remove them (a missing name is skipped; -`objectstack-pm-dispatch` is not in the 18 catalog, only an older install has it), add -`@objectstack/skills` at the installed spec's version with the manager that -installed the project, copy it: - -```bash -npx skills remove objectstack-ai objectstack-api objectstack-automation \ - objectstack-data objectstack-formula objectstack-i18n objectstack-platform \ - objectstack-pm-dispatch objectstack-query objectstack-ui objectstack-upgrade objectui -y -pnpm add -D "@objectstack/skills@$(node -p "require('@objectstack/spec/package.json').version")" -# npm: npm install --save-dev "@objectstack/skills@…" · yarn: yarn add -D "@objectstack/skills@…" -npx skills@1.7.2 experimental_sync --agent claude-code --copy -y -``` - ---- - -## 1 · Mechanical layer — invoke the chain - -### What `os migrate meta` actually does - -```bash -os migrate meta --from 16 # replay 16 → current -os migrate meta --from 16 --step # per-hop checkpoint (bisect a failure) -os migrate meta --from 16 --to 17 # stop at a specific major -os migrate meta --from 16 --json # machine-readable result -os migrate meta --from 16 --out migrated.json # write the canonicalized stack -os migrate meta --from 16 --write # rewrite the proven sites in place -os migrate meta --from 16 apps/crm/objectstack.config.ts # pick the stack explicitly +os validate # green (compare against validate-before.txt) +tsc --noEmit # tombstones type the retired keys as `never` +os migrate meta --from 16 --to 18 --json # `applied` [] and no `replayedNothing` (trap 2) +# → write .upgrade/REPORT.md (template: §3.4) ``` -It loads the stack config, normalizes it **without** applying the load-time -conversion pass, replays each major's conversions as a chain hop, and then -parses the result against the current schema to prove the output is valid. What -it prints: - -- **`Applied N mechanical change(s)`** — one line per rewritten site, as - `path: from → to (conversionId)`. This is the diff, already attributed. -- **`N manual change(s) require your judgment`** — the chain's semantic entries - for the majors you crossed, each with a `why` and a `verify` line. These are - Layer 2's input, not a warning to dismiss. -- **`Migrated stack is schema-valid`** — or the warning that it is not yet, - which means a residue item is still blocking the parse. - -### ⚠ The one fact that surprises every operator - -**By default `os migrate meta` rewrites no source file.** It lists the -mechanical edits and writes only the `--out` JSON snapshot. `--write` rewrites -in place each edit it can trace to one literal in one project file, lists every -other with the reason it was not written, never writes a semantic change, and -if re-running the chain over the written files disagrees, restores every file -and exits 1. - -### Stored rows: rehydration replays what the release carries - -A deployment's `sys_metadata` rows are the other subject. At read time the -metadata loader and the ObjectQL plugin pass each stored row through -`applyConversionsToStoredItem`, which replays every conversion the release still -carries, **including entries retired from the load path**. 18.3 drops those -retired at or below 16.x, so a row still in such a shape is no longer rewritten. - -Rehydration is a read-time projection: the rows on disk keep their old shape, -and you never hand-edit `sys_metadata`. ⛔ Run the stored pass before you move -(on 18.2 or earlier for such a row) — read-only by default: - - ```bash - os migrate meta --stored # preview, writes nothing - os migrate meta --stored --type view --type object # narrow the pass - os migrate meta --stored --apply --yes # rewrite the rows - ``` - - ⛔ **`--yes` is not optional for you.** Without it `--apply` asks for - confirmation, and in any non-TTY — every agent session — it refuses instead, - exiting 1 with `confirmation_required`. - - `--stored` takes no `--from`: a stored row carries its own history, so the - pass replays the whole chain. - -### Data migrations are not metadata migrations - -When the chain crosses into a major carrying per-deployment data gates, the run -ends by naming each one, what staying un-run costs, and that `--apply` is the -only writing mode. Read that output rather than re-deriving it. What it cannot -tell you is whether they have *run*: that happens against each deployment's own -database, and nothing in the metadata upgrade observes it. - -⛔ **Carry every gate the run printed into the report as `pending`, by name.** A -gate nobody was told about is served by nobody. - ---- - -## 2 · Semantic residue — the part that is yours - -A conversion can rename a key, drop a dead one, or lift a value onto its -declared block. It cannot make a decision. Everything it cannot do lands here. - -### 2.1 Harvest the instruction sources — all of them ship - -The prescriptions are not on a docs site you have to be online for. They ship -inside the installed package. **Measured** against the published -`@objectstack/spec` file list: - -| Source | Where, in a consumer project | Carries | -|:--|:--|:--| -| **Chain result** | `os migrate meta --from N --json` → `.specChanges` | The conversions + semantic entries for exactly the majors you cross. **Start here** — it is computed from the installed spec, so it can never be stale. | -| **D4 projection** | `node_modules/@objectstack/spec/spec-changes.json` | The same data for every major, offline: `perMajor[].converted` and `perMajor[].migrated`. | -| **Tombstone prescriptions** | `node_modules/@objectstack/spec/json-schema/**` and `src/**/*.zod.ts` | Every retired key's `[REMOVED] …` fix-it text, greppable. | -| **FROM → TO tables** | `node_modules/@objectstack/spec/CHANGELOG.md` | The per-retirement narrative, including the "what to write instead" table. This is why the package ships its changelog. | -| **The error itself** | Your parse / `tsc` output | The same prescription string, delivered at the moment you hit it. | - -```bash -# every tombstone prescription the installed spec carries, deduped (`| wc -l` sizes it) -grep -rho '\[REMOVED\][^"]*' node_modules/@objectstack/spec/json-schema/ | sort -u - -# protocol version, support floor, and this crossing's conversion / semantic counts -node -e " - const p = require.resolve('@objectstack/spec/package.json'); - const j = require(p.replace('package.json','spec-changes.json')); - const to = parseInt(j.protocolVersion, 10); - const e = j.perMajor.find(x => x.to === to); - console.log(j.protocolVersion, 'floor', j.supportFloor, '| →', to + ':', - e.converted.length, 'converted,', e.migrated.length, 'semantic'); -" - -# the FROM → TO table for one retired key -grep -n -B4 -A20 'transform' node_modules/@objectstack/spec/CHANGELOG.md | less -``` - -⛔ **Never carry a remembered count or a pinned table into the report.** Every -number here is a reading of *this* install; measure it at the start of the -upgrade and again in the report. - -> **Not reachable from a consumer project**, so do not send anyone there: the -> conversion and migration registries (`src/conversions/registry.ts`, -> `src/migrations/registry.ts`) and the platform repo's generated upgrade guide -> are **not** in the published package — only `src/**/*.zod.ts` is. - -### 2.2 The three residue classes - -**R1 · Intent choice — a key was retired with no single lossless target.** -The conversion drops the key (so the project parses) and, where it matters, -emits a notice naming the site. What the key was *for* still has to go -somewhere, and where is a business statement. - -**R2 · Custom code calling a retired API.** The chain's semantic entries name -these: a service slot that no longer exists, an engine method that was removed, -a context field that was renamed. Metadata parses fine; the project's own -TypeScript is what breaks — or worse, keeps compiling while reading `undefined`. - -**R3 · Prose that still teaches the old shape.** READMEs, comments, ADRs, seed -fixtures, and the project's own AI conventions file. Nothing fails, and the next -agent to read the repo re-authors the retired shape from it. - -**[2.3 A worked R1 — the retired field-mapping `transform`](./references/examples-upgrade.md#23-a-worked-r1--the-retired-field-mapping-transform)** - - - -### 2.4 Decide alone, or ask the owner - -**Decide it yourself when all three hold:** - -1. **The prescription names exactly one target.** The tombstone or conversion - summary gives a single FROM → TO, with the value unchanged. -2. **The evidence is in the project.** A grep in the repo settles it — the skill - that already owns the tool, the import that already exists, the field the - predicate already references. -3. **Being wrong fails a gate.** A mistaken choice breaks `tsc` or `validate` - rather than changing behaviour quietly. - -**Ask the owner when any one of these holds:** - -1. **Two or more real targets, and the choice is a business statement** — the - `transform` case above. -2. **The change is observable without a test failing** — security posture - (an authentication default), row visibility (an access predicate), retry - counts, retention. A wrong call here ships silently and is discovered by an - auditor. -3. **Capability has to be re-declared somewhere new**, so choosing wrong - *removes* a capability instead of breaking a build. Agent tooling that has to - move inside a specific skill is the canonical shape. -4. **The source is dead or undocumented in their repo** — nothing to decide - from. Say so; do not invent a rationale. - -**How to ask.** One message, per item, carrying: the site (file and path), the -prescription verbatim, the options with what each costs, your recommendation and -why, and what you will verify once they choose. Never a bare "how should I -handle `transform`?" — that hands the reading work back to the person with the -least context about the diff. - -**While you wait, do not stall the upgrade.** Park the item in the report as -`AWAITING DECISION`, keep the mechanical layer complete, and keep going. A -project can be schema-valid with open residue items; it just is not *done*. - -### 2.5 Working an R2 — retired APIs in the project's own code - -The chain's semantic entries are the search list. For each one, the surface it -names is a string you grep for in the project's own source: - -```bash -# from the chain's own output — the surfaces it says it cannot fix for you -os migrate meta --from 16 --json | node -e " - let s=''; process.stdin.on('data',d=>s+=d).on('end',()=>{ - for (const t of JSON.parse(s).todos) console.log(t.surface); - })" -# then, for each surface, search the project (not node_modules) -grep -rn "" src/ app/ --include='*.ts' --include='*.tsx' -``` - -One trap that has cost real upgrades a lap: **a rename is not always the fix.** -If the old read was itself wrong, renaming it migrates the defect rather than -the code. Read the semantic entry's `reason` before applying its `replacement`. - -### 2.6 Working an R3 — the prose sweep - -Run it last, once the shapes are settled, and run it over the whole repo: - -```bash -# every retired key name the installed spec knows, as a search list -grep -rho '\[REMOVED\] `[^`]*`' node_modules/@objectstack/spec/json-schema/ \ - | sed 's/.*`\(.*\)`.*/\1/' | sort -u > .upgrade/retired-names.txt -``` - -Then sweep the project's `*.md`, comments, seed fixtures, and its AI conventions -file. The conventions file matters most: it is what the next agent loads before -it writes anything, so a retired shape left there re-enters the codebase on the -next feature, long after the upgrade closed. - ---- - -## 3 · Acceptance — what "upgraded" means - -Four artifacts. Three are machine-checked; the fourth is the one a human reads. - -### 3.1 Typed - -```bash -tsc --noEmit -``` - -A retired key is not merely absent from the schema — it is declared as a -tombstone whose input type is `never`. Assigning anything to it fails to -compile, at the authoring site, before anything runs. A green `tsc` is therefore -positive evidence that no retired key survives in typed sources. - -### 3.2 Parse-gated - -The same tombstone rejects at parse time, and the rejection carries the -prescription rather than a generic "unrecognized key". This is the channel that -catches metadata `tsc` cannot see: JSON files, database rows, anything built at -runtime. You do not have to do anything to enable it — but you **do** have to -prove it is live for this project, because a schema that silently strips is -indistinguishable from one that accepts. See -[the reverse check](#reverse-check). - -### 3.3 Validate - -```bash -os validate # green is the criterion -os validate --strict # warnings become errors — agree with the owner whether this is the bar -``` - -`os validate` runs two passes: the protocol schema (where tombstones reject) and -the author-time rule set. Read the two separately — a rule finding about a -missing sharing model or an options-less choice field is a **pre-existing** -project-quality issue, not upgrade residue. Establish which is which by running -`os validate` **once before you start**, on the un-upgraded source, and keeping -that output as the control. - -> ### ⚠ A green `validate` does NOT mean the chain has nothing left to do -> -> Some conversions are **migration-chain-only**: the loader deliberately does -> not apply them and no tombstone rejects the old shape, because the change is a -> default flip rather than a rename — auto-applying it would stamp a constraint -> onto sources that deliberately omit it. This build ships none (every -> conversion it carries is tombstoned, so the parse refuses the old shape too), -> but a later one can, and the chain, not the parse, is what knows. -> -> A project carrying only such a shape validates **green** while the chain still -> has work. So `validate` green is necessary and not sufficient, and the -> criterion that closes the gap is a replay of the whole range you ported: -> -> ```bash -> os migrate meta --from --to --json -> # `applied` must be [] and `replayedNothing` absent -> ``` -> -> `--from ` proves nothing: `--to` defaults to the highest major -> this build carries a step for, so the range is empty — no step runs, `applied` -> is `[]` whatever the metadata holds, and the JSON says so with -> `replayedNothing` (its `widestRange` is `null` there: no wider range exists -> from that `--from`) — or it holds only the next major's step. `todos` is -> semantic residue, Layer 2's business, not a failure. - -**[3.4 The report — the human half](./references/examples-upgrade.md#34-the-report--the-human-half)** - - - -### 3.5 Prove the gate is real, do not assume it - -Make the parse gate fire once before you report it as evidence: take a value the -chain *would* have converted, put it back after migrating, and parse it. - -```bash -# a stack that still carries a retired key, fed straight to the schema -os validate .upgrade/residue-probe.config.mjs -``` - -Write the probe as a **plain data literal** — ⛔ no `define*` call. `os validate` -loads the config without authored-source mode, and every `define*` helper is a -`Schema.parse()`, so a probe written the way a real config is written throws -*inside the load* and never reaches the gate you are trying to prove. - -Predict the outcome **before** you run it, then record which one you actually -got — "it passed" is a different fact in every row: - -| Outcome | What it means | Your acceptance evidence | -|:--|:--|:--| -| Rejected, error carries the fix-it text | A tombstoned key. Not "unrecognized key", not a deprecation label — the prescription *is* the error. | The refusal itself, quoted. | -| Accepted, and the chain rewrites it | A conversion with a live load-path acceptance window. | The chain's diff — not the parse gate. | -| Accepted, and `validate` stays green | A migration-chain-only conversion ([3.3](#33-validate)). | Only the acceptance replay sees this class. | - -### 3.6 Stored rows: assert them, do not believe them - -The four artifacts above cover the authored sources. For a **deployment**, the -stored pass is itself the assertion — run it read-only and branch on the exit -code: - -```bash -os migrate meta --stored --json # 0 = every row canonical, 1 = work left -``` - -That is what makes "this deployment is on protocol N" a CI check — valid only -on the release you are leaving: one that dropped a row's conversions no longer -recognises it and answers `0`. Nothing gates on it having run. - ---- - -**[The v17-canonical shapes, compiled](./references/examples-upgrade.md#the-v17-canonical-shapes-compiled)** - -## Failure modes - -| Symptom | What it actually is | Fix | -|:--|:--|:--| -| `migrate meta` reports changes, but the files are unchanged | Working as designed — the default run only lists. | Pass `--write`, or port the printed edits by hand; then replay the ported range to confirm 0 changes. | -| The acceptance replay still applies changes | The port is incomplete, or a source builds metadata at runtime from a shape the chain never saw. | Diff against `--out`; grep for the `conversionId`'s surface in code that constructs metadata dynamically. | -| `validate` green, but a feature silently stopped working | An R2 residue item: code reading a renamed key now reads `undefined`. | Exercise the path for real. A green parse says nothing about a `??` chain in the project's own code. | -| `validate` reports findings that have nothing to do with retired keys | The author-time rule pass, not the schema pass. | Diff against the pre-upgrade `validate` control. Pre-existing findings are not this upgrade's scope. | -| A retired key round-trips without error | The schema carrying it is not strict and the key is being stripped, or the key still has a live load-path window. | Determine which — the two need different acceptance evidence. See [the reverse check](#reverse-check). | -| `--apply` refused / stored-only flag rejected | `--apply`, `--yes`, `--force`, `--type`, `--database-url` mean something only with `--stored`. | Add `--stored`, or drop the flag; the authored-source chain writes only `--out` and, with `--write`, the sources. | -| `MigrationFloorError` | `--from` is older than the chain's support floor. | Upgrade to the floor by an older route first; the floor is a release-policy boundary, not an oversight. | - -Scripting the run instead of reading it? Every `--json` failure above carries a -stable `error` code to branch on — `stored_only_flag`, `missing_from_major`, -`unsupported_from_major`, `confirmation_required`, `database_busy` — and the -prose row is the same fact for a human. +## Traps + +1. **By default `os migrate meta` rewrites no source file.** It prints each edit + as `path: from → to (conversionId)` and writes only `--out`. `--write` + rewrites an edit it can trace to one literal in one project file, lists every + other with the reason, and never writes a semantic change. Port the printed + edits by hand, or pass `--write` and port those it only lists; then replay + (trap 2). +2. **A green `validate` does not mean the chain has nothing left.** A + migration-chain-only conversion (a default flip) has no tombstone, so the old + shape validates. Replay the range you ported, + `os migrate meta --from --to --json`: + `applied` must be `[]` and `replayedNothing` absent. `--from ` + names an empty range and proves nothing. +3. **Stored `sys_metadata` rows are rewritten only at read**, by + `applyConversionsToStoredItem`, and only while the installed release carries + their conversions: 18.3 drops those retired at or below 16.x. ⛔ Before you + move (on 18.2 or earlier for such a row) run `os migrate meta --stored`, a + preview, then `os migrate meta --stored --apply --yes` — without `--yes` any + non-TTY is refused, `confirmation_required` — until + `os migrate meta --stored --json` exits 0. A release that dropped the + conversions answers 0 whatever the row holds. Never hand-edit `sys_metadata`. +4. **Data migrations are not metadata migrations.** The run names each + per-deployment gate; nothing in the upgrade observes whether it ran. ⛔ Carry + every gate it printed into the report as `pending`, by name. +5. **R2, code on a retired API, can keep compiling while it reads `undefined`.** + Grep the project's source for each `todos[].surface` of the `--json` result, + and read the entry's `reason` before its `replacement`: if the old read was + wrong, a rename migrates the defect. +6. **R3, prose that still teaches the old shape, fails nothing**: the next agent + re-authors it from a README, a comment, a seed fixture or the AI conventions + file. Sweep the whole repo last. +7. **Prove the parse gate once, with a plain data literal** — ⛔ no `define*` + call, which throws inside the load and never reaches the gate. A retired key + that still parses is stripped or in a load-path window: find which. + +## Decide alone, or ask + +**R1, an intent choice**: a key retired with no single lossless target. The +conversion drops it so the project parses; where its purpose goes is a business +statement. + +**Decide yourself when all three hold:** the prescription names exactly one +FROM → TO with the value unchanged; a grep in the project settles the evidence; +being wrong breaks `tsc` or `validate` rather than changing behaviour quietly. + +**Ask the owner when any one holds:** two or more real targets; the change is +observable with no test failing (an authentication default, row visibility, +retry counts, retention); a capability must be re-declared somewhere new, so a +wrong choice removes it; the source is dead or undocumented — say so, do not +invent a rationale. + +Ask in one message per item: the site, the prescription verbatim, the options +and what each costs, your recommendation, what you will verify. Park it in the +report as `AWAITING DECISION` and keep the mechanical layer moving. + +## Where to go + +| Section | For | +|:--|:--| +| [0 · Preflight](./references/examples-upgrade.md#0--preflight) | the FROM major's sources, `.upgrade/`, the skills re-install | +| [1 · Mechanical layer](./references/examples-upgrade.md#1--mechanical-layer) | what a run does and prints, stored rows, data gates | +| [2 · Semantic residue](./references/examples-upgrade.md#2--semantic-residue) | where the prescriptions ship, a worked R1 (`transform`), the R2 and R3 searches | +| [3 · Acceptance](./references/examples-upgrade.md#3--acceptance) | the four artifacts, the `REPORT.md` template, the reverse check's outcomes | +| [Failure modes](./references/examples-upgrade.md#failure-modes) | symptom → cause → fix, the `--json` error codes | +| [The v17-canonical shapes](./references/examples-upgrade.md#the-v17-canonical-shapes-compiled) | the examples after the upgrade, type-checked | ## Cross-skill routing -- Authoring the corrected metadata — load the domain skill for the shape you are - fixing (**data**, **ui**, **automation**, **ai**, **api**, **i18n**); each one - routes on to **formula** for any CEL you rewrite. -- Runtime, plugin, and CLI questions the upgrade turns up — load **platform**. +Authoring the corrected metadata: load the domain skill for the shape you fix +(**data**, **ui**, **automation**, **ai**, **api**, **i18n**); each routes on to +**formula** for any CEL you rewrite. Runtime, plugin and CLI questions: **platform**. diff --git a/skills/objectstack-upgrade/references/examples-upgrade.md b/skills/objectstack-upgrade/references/examples-upgrade.md index fbd80057c9d..f440442943a 100644 --- a/skills/objectstack-upgrade/references/examples-upgrade.md +++ b/skills/objectstack-upgrade/references/examples-upgrade.md @@ -1,4 +1,162 @@ -# Upgrade — worked examples and templates (moved verbatim from SKILL.md) +# Upgrade — the layers in detail, worked examples and templates + +What `SKILL.md` does not hold, in the order of a run. + +## 0 · Preflight + +### Establish the FROM major — do not guess it + +Three sources, in order of authority: + +1. **`manifest.engines.protocol`** in the stack config — the declared answer, + checked by the boot handshake. Every scaffold and example writes the caret + form (`engines: { protocol: '^19' }`), and an exact `'16.0.0'` is only a + range of one. +2. **The last `@objectstack/spec` major the project ever installed** — read the + lockfile history (`git log -p pnpm-lock.yaml | grep -m5 '@objectstack/spec'`) + when the manifest is absent or stale. +3. **Ask.** A manifest that says 16 on a project last touched two years ago is a + claim, not a measurement. The lower major is never the default because a + default flip ([3.3](#33-validate)) stamps its constraint onto a source + already past that major. + +Arriving several majors late is the designed-for case: `os migrate meta --from 16` +replays every step in order, with no requirement to upgrade one major at a time — +down to the chain's support floor, 16 today. + +### Make the work reviewable before you change anything + +```bash +git checkout -b upgrade/protocol-17 +mkdir -p .upgrade +``` + +The `.upgrade/` directory is the deliverable's workspace: the machine outputs +(`migrate.json`, `migrated.stack.json`, `spec-changes.json`, `retired-names.txt`) +and the human output (`REPORT.md`). Keeping them in the repo for the review, and +deleting them on merge, is the usual arrangement — decide it with the owner. + +### Re-install the skills from the moved catalog + +A 17.x project's skills came from `skills add`; their `skills-lock.json` +entries are the ones the sync skips. Remove them (a missing name is +skipped; `objectstack-pm-dispatch` is not in the 18 catalog, only an older +install has it), add `@objectstack/skills` at the installed spec's version with +the manager that installed the project, copy it: + +```bash +npx skills remove objectstack-ai objectstack-api objectstack-automation \ + objectstack-data objectstack-formula objectstack-i18n objectstack-platform \ + objectstack-pm-dispatch objectstack-query objectstack-ui objectstack-upgrade objectui -y +pnpm add -D "@objectstack/skills@$(node -p "require('@objectstack/spec/package.json').version")" +# npm: npm install --save-dev "@objectstack/skills@…" · yarn: yarn add -D "@objectstack/skills@…" +npx skills@1.7.2 experimental_sync --agent claude-code --copy -y +``` + +## 1 · Mechanical layer + +### What `os migrate meta` actually does + +`os migrate meta --help` lists every flag and form; the Quickstart shows the +ones a run needs. + +It loads the stack config, normalizes it **without** applying the load-time +conversion pass, replays each major's conversions as a chain hop, and then +parses the result against the current schema to prove the output is valid. What +it prints: + +- **`Applied N mechanical change(s)`** — one line per rewritten site. This is + the diff, already attributed. +- **`N manual change(s) require your judgment`** — the chain's semantic entries + for the majors you crossed, each with a `why` and a `verify` line. These are + Layer 2's input, not a warning to dismiss. +- **`Migrated stack is schema-valid`** — or the warning that it is not yet, + which means a residue item is still blocking the parse. + +`--write` checks itself: if re-running the chain over the written files +disagrees, it restores every file and exits 1. + +### Stored rows: rehydration replays what the release carries + +A deployment's `sys_metadata` rows are the other subject. At read time the +metadata loader and the ObjectQL plugin pass each stored row through +`applyConversionsToStoredItem`, which replays every conversion the release still +carries, **including entries retired from the load path**. + +Rehydration is a read-time projection: the rows on disk keep their old shape. +The stored pass is read-only by default: + +```bash +os migrate meta --stored # preview, writes nothing +os migrate meta --stored --type view --type object # narrow the pass +os migrate meta --stored --apply --yes # rewrite the rows +``` + +`--stored` takes no `--from`: a stored row carries its own history, so the +pass replays the whole chain. + +### Data migrations are not metadata migrations + +When the chain crosses into a major carrying per-deployment data gates, the run +ends by naming each one, what staying un-run costs, and that `--apply` is the +only writing mode. Read that output rather than re-deriving it. The gates run +against each deployment's own database. A gate nobody was told about is served +by nobody. + +## 2 · Semantic residue + +A conversion can rename a key, drop a dead one, or lift a value onto its +declared block. It cannot make a decision. Everything it cannot do lands here. + +### 2.1 Harvest the instruction sources — all of them ship + +The prescriptions are not on a docs site you have to be online for. They ship +inside the installed package. **Measured** against the published +`@objectstack/spec` file list: + +| Source | Where, in a consumer project | Carries | +|:--|:--|:--| +| **Chain result** | `os migrate meta --from N --json` → `.specChanges` | The conversions + semantic entries for exactly the majors you cross. **Start here** — it is computed from the installed spec, so it can never be stale. | +| **D4 projection** | `node_modules/@objectstack/spec/spec-changes.json` | The same data for every major, offline: `perMajor[].converted` and `perMajor[].migrated`. | +| **Tombstone prescriptions** | `node_modules/@objectstack/spec/json-schema/**` and `src/**/*.zod.ts` | Every retired key's `[REMOVED] …` fix-it text, greppable. | +| **FROM → TO tables** | `node_modules/@objectstack/spec/CHANGELOG.md` | The per-retirement narrative, including the "what to write instead" table. This is why the package ships its changelog. | +| **The error itself** | Your parse / `tsc` output | The same prescription string, delivered at the moment you hit it. | + +```bash +# every tombstone prescription the installed spec carries, deduped (`| wc -l` sizes it) +grep -rho '\[REMOVED\][^"]*' node_modules/@objectstack/spec/json-schema/ | sort -u + +# protocol version, support floor, and this crossing's conversion / semantic counts +node -e " + const p = require.resolve('@objectstack/spec/package.json'); + const j = require(p.replace('package.json','spec-changes.json')); + const to = parseInt(j.protocolVersion, 10); + const e = j.perMajor.find(x => x.to === to); + console.log(j.protocolVersion, 'floor', j.supportFloor, '| →', to + ':', + e.converted.length, 'converted,', e.migrated.length, 'semantic'); +" + +# the FROM → TO table for one retired key +grep -n -B4 -A20 'transform' node_modules/@objectstack/spec/CHANGELOG.md | less +``` + +Measure each number at the start of the upgrade and again in the report; a +pinned table is not a reading. + +> **Not reachable from a consumer project**, so do not send anyone there: the +> conversion and migration registries (`src/conversions/registry.ts`, +> `src/migrations/registry.ts`) and the platform repo's generated upgrade guide +> are **not** in the published package — only `src/**/*.zod.ts` is. + +### 2.2 The residue classes + +**R1 · Intent choice.** Where it matters, the conversion that drops the key +also emits a notice naming the site. + +**R2 · Custom code calling a retired API.** The chain's semantic entries name +these: a service slot that no longer exists, an engine method that was removed, +a context field that was renamed. Metadata parses fine; the project's own +TypeScript is what breaks. ### 2.3 A worked R1 — the retired field-mapping `transform` @@ -34,6 +192,106 @@ ever passed through this mapping. Where the data really comes from, and whether it is right, only the owner can answer — exactly the kind of finding the report exists to surface. +### 2.4 Decide alone, or ask the owner + +The rule is in `SKILL.md`. What each condition looks like: + +- **One target**: the tombstone or conversion summary gives a single FROM → TO. +- **Evidence in the project**: the skill that already owns the tool, the import + that already exists, the field the predicate already references. +- **Two or more real targets**: the `transform` case above. +- **Observable without a test failing**: security posture, row visibility + (an access predicate). A wrong call here ships silently and is discovered by + an auditor. +- **Capability re-declared somewhere new**: agent tooling that has to move + inside a specific skill is the canonical shape. + +**How to ask.** Never a bare "how should I handle `transform`?" — that hands +the reading work back to the person with the least context about the diff. + +**While you wait, do not stall the upgrade.** A project can be schema-valid +with open residue items; it just is not *done*. + +### 2.5 Working an R2 — retired APIs in the project's own code + +The chain's semantic entries are the search list. For each one, the surface it +names is a string you grep for in the project's own source: + +```bash +# from the chain's own output — the surfaces it says it cannot fix for you +os migrate meta --from 16 --json | node -e " + let s=''; process.stdin.on('data',d=>s+=d).on('end',()=>{ + for (const t of JSON.parse(s).todos) console.log(t.surface); + })" +# then, for each surface, search the project (not node_modules) +grep -rn "" src/ app/ --include='*.ts' --include='*.tsx' +``` + +A key was retired because nothing enforced it or because exactly one spelling +survives, so the fix in that code is never a tolerant read of the old one. + +### 2.6 Working an R3 — the prose sweep + +Run it once the shapes are settled: + +```bash +# every retired key name the installed spec knows, as a search list +grep -rho '\[REMOVED\] `[^`]*`' node_modules/@objectstack/spec/json-schema/ \ + | sed 's/.*`\(.*\)`.*/\1/' | sort -u > .upgrade/retired-names.txt +``` + +Then sweep the project's `*.md` (READMEs, ADRs), comments, seed fixtures, and +its AI conventions file. The conventions file matters most: it is what the next agent loads before +it writes anything, so a retired shape left there re-enters the codebase on the +next feature, long after the upgrade closed. + +## 3 · Acceptance + +Four artifacts. Three are machine-checked; the fourth is the one a human reads. + +### 3.1 Typed + +A retired key is not merely absent from the schema — it is declared as a +tombstone whose input type is `never`. Assigning anything to it fails to +compile, at the authoring site, before anything runs. A green `tsc --noEmit` is +therefore positive evidence that no retired key survives in typed sources. + +### 3.2 Parse-gated + +The same tombstone rejects at parse time, and the rejection carries the +prescription rather than a generic "unrecognized key". This is the channel that +catches metadata `tsc` cannot see: JSON files, database rows, anything built at +runtime. You do not have to do anything to enable it — but you **do** have to +prove it is live for this project, because a schema that silently strips is +indistinguishable from one that accepts. See +[the reverse check](#reverse-check). + +### 3.3 Validate + +```bash +os validate # green is the criterion +os validate --strict # warnings become errors — agree with the owner whether this is the bar +``` + +`os validate` runs two passes: the protocol schema (where tombstones reject) and +the author-time rule set. Read the two separately — a rule finding about a +missing sharing model or an options-less choice field is a project-quality +issue the control already shows. + +Some conversions are **migration-chain-only**: the loader deliberately does not +apply them and no tombstone rejects the old shape, because the change is a +default flip rather than a rename — auto-applying it would stamp a constraint +onto sources that deliberately omit it. This build ships none (every conversion +it carries is tombstoned, so the parse refuses the old shape too), but a later +one can, and the chain, not the parse, is what knows. + +Why `--from ` proves nothing: `--to` defaults to the highest major +this build carries a step for, so the range is empty — no step runs, `applied` +is `[]` whatever the metadata holds, and the JSON says so with +`replayedNothing` (its `widestRange` is `null` there: no wider range exists +from that `--from`) — or it holds only the next major's step. `todos` is +semantic residue, Layer 2's business, not a failure. + ### 3.4 The report — the human half The upgrade is not finished by a passing command; it is finished by a document a @@ -83,6 +341,44 @@ _N sites, M conversions. Ported into sources from `os migrate meta --out`._ - — no occurrences. ``` + + +### 3.5 Prove the gate is real, do not assume it + +Make the parse gate fire once before you report it as evidence: take a value the +chain *would* have converted, put it back after migrating, and parse it. + +```bash +# a stack that still carries a retired key, fed straight to the schema +os validate .upgrade/residue-probe.config.mjs +``` + +The probe is a plain data literal because `os validate` loads the config +without authored-source mode, and every `define*` helper is a `Schema.parse()`: +a probe written the way a real config is written throws *inside the load*. + +Predict the outcome **before** you run it, then record which one you actually +got — "it passed" is a different fact in every row: + +| Outcome | What it means | Your acceptance evidence | +|:--|:--|:--| +| Rejected, error carries the fix-it text | A tombstoned key. Not "unrecognized key", not a deprecation label — the prescription *is* the error. | The refusal itself, quoted. | +| Accepted, and the chain rewrites it | A conversion with a live load-path acceptance window. | The chain's diff — not the parse gate. | +| Accepted, and `validate` stays green | A migration-chain-only conversion ([3.3](#33-validate)). | Only the acceptance replay sees this class. | + +### 3.6 Stored rows: assert them, do not believe them + +The four artifacts above cover the authored sources. For a **deployment**, the +stored pass is itself the assertion — run it read-only and branch on the exit +code: + +```bash +os migrate meta --stored --json # 0 = every row canonical, 1 = work left +``` + +That is what makes "this deployment is on protocol N" a CI check, valid only on +the release you are leaving. Nothing gates on it having run. + ## The v17-canonical shapes, compiled What the protocol-16 shapes in this skill's examples look like after the @@ -117,3 +413,18 @@ export const SupportBot = defineAgent({ skills: ['crm_case_management'], }); ``` + +## Failure modes + +| Symptom | What it actually is | Fix | +|:--|:--|:--| +| The acceptance replay still applies changes | The port is incomplete, or a source builds metadata at runtime from a shape the chain never saw. | Diff against `--out`; grep for the `conversionId`'s surface in code that constructs metadata dynamically. | +| `validate` green, but a feature silently stopped working | An R2 residue item: code reading a renamed key now reads `undefined`. | Exercise the path for real. A green parse says nothing about a `??` chain in the project's own code. | +| A retired key round-trips without error | The schema carrying it is not strict and the key is being stripped, or the key still has a live load-path window. | Determine which — the two need different acceptance evidence. See [the reverse check](#reverse-check). | +| `--apply` refused / stored-only flag rejected | `--apply`, `--yes`, `--force`, `--type`, `--database-url` mean something only with `--stored`. | Add `--stored`, or drop the flag; the authored-source chain writes only `--out` and, with `--write`, the sources. | +| `MigrationFloorError` | `--from` is older than the chain's support floor. | Upgrade to the floor by an older route first; the floor is a release-policy boundary, not an oversight. | + +Scripting the run instead of reading it? Every `--json` failure above carries a +stable `error` code to branch on — `stored_only_flag`, `missing_from_major`, +`unsupported_from_major`, `confirmation_required`, `database_busy` — and the +prose row is the same fact for a human.