authoring-cli 0.1.10 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authoring-cli",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "CLI for SNOMED CT authoring against authoring-services",
5
5
  "license": "Apache-2.0",
6
6
  "bin": {
@@ -43,6 +43,34 @@ committing to a sequence of edits. If nothing is selected and no flags are passe
43
43
  rather than guessing. `authoring-cli projects` and `authoring-cli tasks` list what's available to
44
44
  pick from; a session with no valid cookie needs `authoring-cli login [production|uat|dev]` first.
45
45
 
46
+ **A stale session can fail in a way that looks exactly like a server outage.** Symptoms: `get-concept`
47
+ (and everything else) suddenly returns `"Could not resolve branch path for <project>/<task>"` on a
48
+ branch that worked moments before, while `authoring-cli projects` and `authoring-cli tasks --project
49
+ <P> --summary` both come back empty (`"No projects available"` / `"No tasks in project <P>"`).
50
+ Retrying doesn't help — it isn't a transient blip, the session token expired mid-session. Fix:
51
+ `authoring-cli login uat` (or the relevant environment) reuses an already-signed-in Chrome session
52
+ with no browser popup if you're still logged in there. Confirm the branch/server is actually fine
53
+ with one plain `get-concept` call before concluding a real outage — the fix here takes seconds.
54
+
55
+ ## Concurrency: one mutating caller per task branch, at a time
56
+
57
+ Never run more than one mutating call against the same task branch concurrently, and never
58
+ delegate a batch of mutating calls to a subagent working the same branch alongside you. Even a
59
+ single sequential caller can trigger `branch locked, retrying` from the server's own internal
60
+ locking — true concurrent callers (parallel tool calls, an `xargs -P`-style fan-out, a subagent
61
+ mutating the same branch while you also are) compound this and have exhausted their retry budget
62
+ and failed outright with HTTP 400, silently leaving whatever they were doing half-finished despite
63
+ the command appearing to run to completion. This is a property of the branch lock, not of any one
64
+ command — confirmed for `set-definition-status` under `xargs -P 8`, but the same risk applies to
65
+ `create-concept`/`add-relationship`/`replace-fsn`/`add-description`/etc. equally. Reserve
66
+ parallelism for **read-only** calls (a `get-concept` sweep, independent `search-concepts` lookups)
67
+ — queue every mutating call against a given task branch sequentially, one at a time, whether
68
+ you're driving the sequence yourself or via a background loop. After any batch that hit retries or
69
+ ran under uncertain conditions, re-verify the whole target set with fresh `get-concept` calls
70
+ rather than trusting the batch run's exit status alone. See `references/batch-authoring.md`'s
71
+ "Driving a batch of mutating calls" for the fuller reasoning, including why a subagent's
72
+ self-reported summary isn't ground truth either.
73
+
46
74
  The `--project`/`--task` flags are shown on the examples below for explicitness. When a task is
47
75
  already selected via `select-task`, you can omit them everywhere.
48
76
 
@@ -175,6 +203,10 @@ you catch them during review or read the concept back afterward. Watch for these
175
203
  - **Missing or wrong semantic tag**: every FSN must end with a semantic tag; verify it matches the
176
204
  concept's actual domain. A body-structure concept should end with `(body structure)`, a finding
177
205
  with `(finding)`, etc.
206
+ - **A semantic tag on the PT or a synonym.** Only the FSN ever carries one. A PT/synonym built by
207
+ reusing the same tagged string passed to `--fsn` looks like `"Structure of X (body structure)"`
208
+ where it should just be `"Structure of X"` — check `get-concept --description-full`'s PT/synonym
209
+ terms whenever you passed the same source string to both `--fsn` and `--pt`.
178
210
 
179
211
  **Synonym specificity and meaning:**
180
212
  - **Inappropriate synonyms that shift the concept's meaning**: a synonym must name the same clinical
@@ -191,6 +223,15 @@ Run `review-concepts` before promoting a task to check these mistakes aren't hid
191
223
  pending changes — they save cleanly but are real content errors, not save-time constraint
192
224
  violations.
193
225
 
226
+ **`search-concepts` and `get-concept` put the FSN at different JSON paths — using the wrong one
227
+ silently reads as "no results," not an error.** `get-concept` nests it as `.fsn.term` (an object).
228
+ `search-concepts` returns it flat as `.items[].fsn` (a plain string). Applying `.fsn.term` to a
229
+ `search-concepts` result throws a jq parse error that's easy to let scroll past as "no match" —
230
+ this has produced strings of false negatives across a dozen-plus consecutive existence checks in
231
+ practice, nearly causing duplicate mints of concepts that already existed. Before trusting any
232
+ empty or erroring existence check built on `search-concepts` output, confirm the field path against
233
+ one real response rather than assuming the shape that works for `get-concept`.
234
+
194
235
  ## Ground truth vs. echoed validation results
195
236
 
196
237
  Every concept-mutating command (`create-concept`, `add-description`, `set-acceptability`, ...)
@@ -383,31 +424,31 @@ common case — are unaffected; plain `add-relationship` is fine and simpler the
383
424
  (`remove-relationship` is also callable as `delete-relationship` — same command, whichever verb
384
425
  you reach for first.)
385
426
 
386
- `update-axiom` and `remove-relationship` are gated at **different levels**, and that difference is
387
- the whole story for editing an axiom that's already been released:
427
+ Neither `update-axiom` nor `remove-relationship` gates on the axiom's own `effectiveTime` — both
428
+ edit a published axiom's row in place (same `axiomId`), matching the real Authoring Workbench, which
429
+ edits a released axiom's content directly rather than inactivating it and adding a replacement. The
430
+ difference between the two commands is what each is built to touch, not what publication state they
431
+ tolerate:
388
432
 
389
- - `update-axiom` checks the **axiom's own** `effectiveTime`. If the axiom has ever been versioned
390
- (`released: true` with a real `effectiveTime`, not just inherited from the concept), every call
391
- fails with HTTP 409 — it replaces `relationships` wholesale, so it refuses outright rather than
392
- risk silently changing a released axiom's meaning.
393
- - `remove-relationship` checks the **targeted relationship's own** `effectiveTime` only, never the
394
- axiom's. This mirrors the real Authoring Workbench: its "Remove Relationship" button re-saves the
395
- same axiom (same `axiomId`) with one relationship gone, regardless of whether that axiom has been
396
- released before — only the specific relationship being removed must itself never have been
397
- versioned.
433
+ - `remove-relationship` splices out exactly one relationship, addressed by `relationshipId` (or
434
+ array index) — the simplest tool when you know which single relationship has to go and want to
435
+ leave the rest of the axiom untouched.
436
+ - `update-axiom` replaces the whole `relationships` array at once — the tool for rebuilding several
437
+ relationships/groups together in one call (see the multi-group case above). The same applies to
438
+ `update-gci-axiom` on `gciAxioms`.
398
439
 
399
- So: **removing one relationship from a published axiom is `remove-relationship`, not
400
- `update-axiom`.** Get the target's `relationshipId` (or its array index within that axiom) from
401
- `get-concept --axioms`, then:
440
+ So for removing just one relationship, prefer `remove-relationship`. Get the target's
441
+ `relationshipId` (or its array index within that axiom) from `get-concept --axioms`, then:
402
442
 
403
443
  ```
404
444
  authoring-cli remove-relationship --id <SCTID> --axiom-id <axiomId> --relationship-id <relationshipId>
405
445
  ```
406
446
 
407
- If that specific relationship has its own `effectiveTime` set (it was independently versioned —
408
- uncommon, but possible for a relationship inside an otherwise-unversioned axiom edit history), the
409
- call 409s and there's no way to remove it via the CLI; that's expected residue, same as the fully-
410
- versioned-axiom case in "Redundant stated Is-a relationships" below.
447
+ `remove-relationship` still guards the **targeted relationship's own** `effectiveTime`: if that
448
+ specific relationship has its own `effectiveTime` set (independently versioned — uncommon, but
449
+ possible for a relationship inside an otherwise-unversioned axiom edit history), the call 409s and
450
+ there's no way to remove it via the CLI; that's expected residue, same as the fully-versioned-
451
+ relationship case in "Redundant stated Is-a relationships" below.
411
452
 
412
453
  ### Removing an entire role group
413
454
 
@@ -457,8 +498,8 @@ stated `Is a`) is excluded from matching unless you explicitly pass `--group-id
457
498
  pair that happens to match an ungrouped attribute could sweep up unrelated ungrouped relationships,
458
499
  including `Is a`, as collateral damage. And `remove-role-group` only targets `classAxioms`; a GCI
459
500
  role group still needs the `update-gci-axiom` workaround (rewrite the relationships list with that
460
- group's entries omitted), gated on the whole GCI axiom's own `effectiveTime` since there's no
461
- per-relationship GCI removal endpoint.
501
+ group's entries omitted) — with no axiom-level `effectiveTime` gate either, same in-place-edit
502
+ behavior as `update-axiom`, since there's no per-relationship GCI removal endpoint.
462
503
 
463
504
  Confirm with `authoring-cli validate-concept --id <SCTID>` afterward.
464
505
 
@@ -510,7 +551,16 @@ groups above. Retiring the axiom itself follows the same delete-vs-inactivate sp
510
551
  `delete-gci-axiom --id <SCTID> --axiom-id <axiomId>` 409s on a published one, `inactivate-gci-axiom
511
552
  --id <SCTID> --axiom-id <axiomId>` 409s on a never-versioned one. Unlike `inactivate-axiom`,
512
553
  `inactivate-gci-axiom` has no minimum-active-count guard — GCI axioms are optional, so a concept can
513
- be left with zero active ones.
554
+ be left with zero active ones (inactivating the sole GCI axiom, with nothing to replace it, is a
555
+ legitimate, allowed retirement).
556
+
557
+ **`add-gci-axiom` then `inactivate-gci-axiom` must never be used together to replace one GCI's
558
+ content**, same rule and same reason as class axioms below: `inactivate-gci-axiom` 409s if doing so
559
+ would leave only unpublished GCI axiom(s) active, naming `update-gci-axiom` as the in-place fix. Use
560
+ `update-gci-axiom` to rewrite a published GCI's content; reach for `add-gci-axiom` only when the
561
+ concept genuinely needs an independent, additional GCI axiom — unlike class axioms, a concept
562
+ carrying more than one GCI (or a GCI alongside its single class axiom) is normal, not an edge case,
563
+ so this carve-out is the common path for GCIs even though it's rare for class axioms.
514
564
 
515
565
  **Deciding *whether* and *how* to model with a GCI at all — for any concept type (disorder,
516
566
  procedure, observable, ...), not just this command's mechanics — is its own judgment call.** See
@@ -521,34 +571,60 @@ actually discriminate), how to shape the antecedent (genus + nexus + defining at
521
571
  role-group partition that silently changes an axiom's meaning if got wrong), and how to derive the
522
572
  axiom set from the terminology's own content rather than from theory alone.
523
573
 
524
- ### Replacing a published axiom
574
+ ### Editing a published axiom's content
525
575
 
526
- `update-axiom` and `delete-axiom` both refuse outright once an axiom's own `effectiveTime` is set —
527
- there is no in-place edit for a released axiom's content, by design (rewriting a versioned axiom's
528
- relationships, or removing it wholesale, risks silently changing what already shipped). "Replace"
529
- therefore means two separate calls, not one: add the new axiom, then retire the old one.
576
+ `update-axiom --id <SCTID> --axiom-id <axiomId> --relationships '[...]'` edits a class axiom's
577
+ content in place, published or not — it replaces `relationships` wholesale on the *same* `axiomId`
578
+ row and leaves it there; Snowstorm's own save clears that axiom's `effectiveTime` as part of
579
+ versioning the change. This matches the real Authoring Workbench exactly: editing a released axiom's
580
+ content there does not inactivate the old row and add a new one. `update-gci-axiom` behaves
581
+ identically for `gciAxioms`. Do **not** reach for "add a replacement axiom, then inactivate the old
582
+ one" for a content change — that produces two `OwlAxiom` rows on the concept (one inactive-but-
583
+ published, one newly active) where the real UI produces exactly one; that mismatch is real content
584
+ divergence, not cosmetic, and it's what `authoring-cli` used to do here before this was fixed.
530
585
 
531
586
  ```
532
- authoring-cli add-axiom --id <SCTID> --relationships \
587
+ authoring-cli update-axiom --id <SCTID> --axiom-id <axiomId> --relationships \
533
588
  '[{"active":true,"groupId":0,"type":{"conceptId":"116680003"},"target":{"conceptId":"..."}},
534
589
  {"active":true,"groupId":1,"type":{"conceptId":"363698007"},"target":{"conceptId":"..."}}]'
590
+ ```
535
591
 
536
- authoring-cli inactivate-axiom --id <SCTID> --axiom-id <oldAxiomId>
592
+ **`add-axiom` and `inactivate-axiom` must never be used together to replace one axiom's content —
593
+ the CLI itself refuses it.** Calling `add-axiom` with the intended new content, then
594
+ `inactivate-axiom` on the axiom that content replaces, is exactly the two-step "add a replacement,
595
+ then retire the original" anti-pattern the previous section warns about, and `inactivate-axiom` 409s
596
+ on the second call: *"would leave concept ... with only unpublished class axiom(s) active ... Use
597
+ update-axiom to edit ... in place instead."* There is no way around that refusal, and no reason to
598
+ want one — `update-axiom` does the same edit correctly, as one save, with no duplicate row. If you
599
+ find yourself reaching for `add-axiom` immediately before `inactivate-axiom` on the axiom whose
600
+ content you're changing, stop and use `update-axiom` instead.
601
+
602
+ Unlike GCI axioms (see above), a genuinely independent second class axiom is rare: most SNOMED CT
603
+ concepts carry exactly one, and `add-axiom` exists mainly for the unusual editorial case where a
604
+ concept truly needs an additional, independent class axiom alongside the first. That's the only
605
+ legitimate use of `add-axiom`/`inactivate-axiom` together — and even then, the axiom being added and
606
+ the axiom being retired (if any) must be unrelated, with any axiom that survives active alongside a
607
+ newly-added one already published from earlier work, not something created in the same session as
608
+ part of retiring another. If you're not deliberately in that unusual situation, seeing yourself reach
609
+ for `add-axiom` right before `inactivate-axiom` is a sign to stop and use `update-axiom` instead —
610
+ treat it as the exception, not a normal two-step edit.
611
+
612
+ ```
613
+ authoring-cli add-axiom --id <SCTID> --relationships \
614
+ '[{"active":true,"groupId":0,"type":{"conceptId":"116680003"},"target":{"conceptId":"..."}},
615
+ {"active":true,"groupId":1,"type":{"conceptId":"363698007"},"target":{"conceptId":"..."}}]'
537
616
  ```
538
617
 
539
- Like `add-gci-axiom`, `add-axiom` has **no publication gate** — it appends a brand-new axiom, so a
540
- released concept accepts it normally. `inactivate-axiom` requires the axiom being retired to
541
- already be published (`effectiveTime` set) — setting `active: false` on a released axiom's row is
542
- the normal RF2 retirement path; a never-versioned one has nothing to retire and should be
543
- `delete-axiom`d instead. It also enforces that **at least one class axiom stays active**, so run
544
- `add-axiom` first: the concept must never be left without a stated definition, even momentarily
545
- within the same task.
618
+ `add-axiom` has **no publication gate** — it appends a brand-new axiom, so a released concept
619
+ accepts it normally. `inactivate-axiom` requires the axiom being retired to already be published
620
+ (`effectiveTime` set) — setting `active: false` on a released axiom's row is the normal RF2
621
+ retirement path; a never-versioned one has nothing to retire and should be `delete-axiom`d instead.
622
+ It also enforces that **at least one class axiom stays active**.
546
623
 
547
- The new axiom's `definitionStatus` defaults to `PRIMITIVE` regardless of what the axiom being
548
- replaced was. If the axiom you're retiring was the concept's `FULLY_DEFINED` one and the new axiom
549
- should take over that role, follow up with `set-definition-status --status FULLY_DEFINED
550
- --axiom-index <N>` (index into `classAxioms` from a fresh `get-concept --axioms` — `add-axiom`'s own
551
- output reports the server-assigned `axiomId` for the one you just added).
624
+ The new axiom's `definitionStatus` defaults to `PRIMITIVE` regardless of any other axiom's. If it
625
+ should become the concept's `FULLY_DEFINED` axiom, follow up with `set-definition-status --status
626
+ FULLY_DEFINED --axiom-index <N>` (index into `classAxioms` from a fresh `get-concept --axioms` —
627
+ `add-axiom`'s own output reports the server-assigned `axiomId` for the one you just added).
552
628
 
553
629
  ### Collapsing an axiom to the standard authoring form
554
630
 
@@ -557,9 +633,9 @@ primitive parent(s) plus every currently-inferred attribute — the shape editor
557
633
  expects a primitive concept's stated definition to take, letting the classifier re-derive the more
558
634
  specific hierarchy instead of the axiom asserting it directly. It gets this shape from Snowstorm's
559
635
  own `GET .../authoring-form` (the same proximal-primitive-parent substitution the classifier itself
560
- uses), not a local reimplementation, then routes through exactly the mechanism above: `update-axiom`
561
- in place if the axiom has never been versioned, or `add-axiom` (carrying over the old axiom's
562
- `moduleId` and `definitionStatus`) followed by `inactivate-axiom` if it has.
636
+ uses), not a local reimplementation, then routes through `update-axiom` to rewrite the axiom in
637
+ place — published or not, same `axiomId` row, exactly like the mechanism described in "Editing a
638
+ published axiom's content" above.
563
639
 
564
640
  The one silent trap: **the target concept must already be classified**. `authoring-form` reads the
565
641
  concept's saved *inferred* relationships to do the substitution, not a live reasoner call — call it
@@ -568,9 +644,7 @@ it comes back with no parents and no attributes at all, which `transform-axiom`
568
644
  write as an axiom ("produced no relationships"). That error names the symptom, not the cause; if you
569
645
  see it, `classify --wait` the task first, then retry. If the axiom already matches authoring form,
570
646
  `transform-axiom` checks that before writing anything and reports `alreadyConformed: true` rather
571
- than reaching Snowstorm at all — the naive version of this reached `add-axiom` and let it 400 with
572
- "Active Concept should not have duplicate axioms" for a published axiom, which was a real but
573
- needless error to make the caller decode.
647
+ than reaching Snowstorm at all — avoiding a pointless rewrite-to-identical-content PUT.
574
648
 
575
649
  **`validate-concept`/`validate-review-concepts` deliberately don't run this check.** They're meant
576
650
  to be a quick, synchronous, single-concept (or per-concept-in-a-loop) check, and authoring-form
@@ -651,11 +725,10 @@ more specific one. Resolve it immediately rather than leaving it as residue:
651
725
  <id> --axiom-id <axiomId> --relationship-index <N>` removes just that one relationship
652
726
  cleanly, in one call, **regardless of whether the axiom itself has been released** — prefer
653
727
  this over rewriting the whole axiom.
654
- - Else (that specific relationship has itself been versioned) → try `update-axiom` if the *whole
655
- axiom* has never been versioned (rewrite the full list with the redundant parent dropped). If
656
- the axiom is genuinely versioned too, `update-axiom` 409s — fall back to "Replacing a published
657
- axiom" above: `add-axiom` with the full relationship list minus the redundant parent, then
658
- `inactivate-axiom` on the original. Don't leave both stated parents in place and file it as
728
+ - Else (that specific relationship has itself been versioned) → `update-axiom` with the full
729
+ relationship list minus the redundant parent, same `axiomId`, **regardless of whether the axiom
730
+ itself has been released** — it edits the row in place rather than refusing (see "Editing a
731
+ published axiom's content" above). Don't leave both stated parents in place and file it as
659
732
  expected residue — the warning is real and resolvable in one CLI session.
660
733
  3. Re-run `validate-concept --id <id>` to confirm the warning cleared.
661
734
 
@@ -691,9 +764,9 @@ axioms as authored — which is what catches a same-session edit (a new relation
691
764
  `Is a`) before classification has run, exactly the situation right after authoring. Neither view
692
765
  alone is a complete answer on a branch with pending, unclassified changes; the inferred view misses
693
766
  what you just stated, and the stated view misses anything the terminology already carries only
694
- through inference. `--limit`/`--offset` page through `referencesByType[].referencingConcepts` on a
695
- heavily-referenced concept — check `total` against what came back, the same caution as any other
696
- paginated search here.
767
+ through inference. Without `--limit`/`--offset`, the command itself pages through and returns every
768
+ referencing concept on a heavily-referenced concept — pass `--limit`/`--offset` only if you want to
769
+ page through `referencesByType[].referencingConcepts` yourself instead.
697
770
 
698
771
  ### 2. Deal with every reference before deleting anything
699
772
 
@@ -703,20 +776,17 @@ a reference you're looking straight at.
703
776
  - **Children must be re-parented, not orphaned.** Decide their new parent deliberately: usually the
704
777
  concept that supersedes the one being deleted, or failing that the deleted concept's own parent,
705
778
  so the child doesn't silently jump up the hierarchy. Retarget with `update-axiom`, rewriting the
706
- full relationship list with only that `Is a` target changed — or, if the child's axiom is itself
707
- versioned and `update-axiom` 409s, `add-axiom` with the corrected list followed by
708
- `inactivate-axiom` on the original (see "Replacing a published axiom" above). Dropping the `Is a`
709
- outright is only right when the child has other parents that already place it correctly — check,
710
- don't assume.
779
+ full relationship list with only that `Is a` target changed — it edits the axiom in place, same
780
+ `axiomId`, regardless of whether it's published (see "Editing a published axiom's content" above).
781
+ Dropping the `Is a` outright is only right when the child has other parents that already place it
782
+ correctly — check, don't assume.
711
783
  - **Attribute references** get retargeted the same way, onto whichever concept now carries the
712
784
  meaning.
713
785
  - **A retrofitted `Is a` added to an existing published concept** (the common case when the
714
786
  now-unwanted concept was minted as a new parent for existing content) is removed, not retargeted:
715
- `remove-relationship --id <existingId> --axiom-id <axiomId> --relationship-index <N>`. Its axiom
716
- will usually be `released: true` while the retrofit relationship inside it is not, and
717
- `remove-relationship` gates on the relationship's own `effectiveTime` — this is exactly the case
718
- where `update-axiom` fails with 409 and `remove-relationship` succeeds. See "Removing a
719
- relationship — including from a published axiom" above.
787
+ `remove-relationship --id <existingId> --axiom-id <axiomId> --relationship-index <N>` — simpler
788
+ than `update-axiom` here since it only needs the one relationship's id/index, not the whole
789
+ relationship list rebuilt. See "Removing a relationship — including from a published axiom" above.
720
790
  - **A referrer that is itself being deleted** needs nothing — just delete it first.
721
791
 
722
792
  ### 3. Delete in dependency order
@@ -828,16 +898,29 @@ The same choice exists for a single class axiom too: `delete-axiom --id <SCTID>
828
898
  a never-versioned one — same guard pairing as concept/description. There's no indicator or
829
899
  association target at the axiom level; both commands instead also guard the concept's minimum: it
830
900
  must keep at least one class axiom (`delete-axiom` counts all of them) and, separately, at least
831
- one *active* one (`inactivate-axiom` counts only active ones). See "Replacing a published axiom"
832
- above for the add-axiom-then-inactivate-axiom sequence this feeds into when the goal is swapping an
833
- axiom's content rather than just retiring it.
901
+ one *active* one (`inactivate-axiom` counts only active ones). Unlike the concept/description case,
902
+ this pairing is for retiring an axiom outright (a concept that genuinely no longer needs one of its
903
+ several axioms) — swapping one axiom's *content* for another is `update-axiom` in place, see
904
+ "Editing a published axiom's content" above, not add-then-inactivate.
905
+
906
+ `inactivate-axiom`/`inactivate-gci-axiom` also refuse when every *other* active axiom of the same
907
+ type is itself unpublished: that combination — retiring one axiom while only a brand-new,
908
+ never-versioned one remains active — has no legitimate reading other than "I just added a
909
+ replacement, now let me retire the original", and the error names `update-axiom`/`update-gci-axiom`
910
+ as the in-place fix instead. A concept with a genuinely independent second axiom has both already
911
+ published from earlier work, so this never blocks a real multi-axiom retirement.
834
912
 
835
913
  ## Generating a concept structurally parallel to an existing one
836
914
 
837
915
  A common authoring task, especially at scale: mint a new concept whose defining axiom is identical
838
916
  to an existing source concept's except for one substituted attribute value — a different
839
917
  anatomical site, laterality, substance, or similar. (For a worked example of this pattern applied
840
- across a large source list, see `references/batch-authoring.md`.)
918
+ across a large source list, see `references/batch-authoring.md`.) When the substituted value is
919
+ itself a body-structure anatomy concept, see `references/anatomy-authoring.md` for the
920
+ SNOMED CT-wide patterns this kind of work runs into: the `Structure of X`/`Entire X` pairing
921
+ convention, the laterality exception to it (and the `FULLY_DEFINED` shape a laterality-only axiom
922
+ needs), and the decomposition procedure for finding a concept's other generalization axes beyond
923
+ whichever one prompted the substitution.
841
924
 
842
925
  1. Fetch the source's **real** defining axiom via `get-concept --axioms` — not a rendering or a note from an
843
926
  earlier session; it may have changed. Identify exactly which relationship(s) carry the attribute
@@ -0,0 +1,131 @@
1
+ # Body-structure anatomy authoring patterns
2
+
3
+ General SNOMED CT body-structure modeling rules that recur across any anatomy content authoring project.
4
+
5
+ ## The `Structure of X` / `Entire X` pair
6
+
7
+ SNOMED CT routinely models a body-structure site as **two** concepts:
8
+
9
+ - `Structure of X (body structure)` — the general/partial-structure concept, used as the value of
10
+ a `Finding site`/`Procedure site` attribute elsewhere.
11
+ - `Entire X (body structure)` — Is-a `Structure of X` — representing the site as a whole
12
+ organ/part rather than "some of it".
13
+
14
+ This is not an occasional pattern; it recurs throughout SNOMED CT's body-structure hierarchy. The
15
+ naming isn't always a clean textual pair either — e.g. `Finger joint structure` pairs with
16
+ `Entire joint of finger`, not a mechanical word-order swap — so confirm a candidate pair via the
17
+ real stated parent (`get-concept`'s `classAxioms[].relationships`), never guess from FSN text
18
+ alone.
19
+
20
+ **Whenever you generalize, retarget, or otherwise touch one half of a pair, check the other
21
+ half.** Leaving one half unhandled produces an under-parented `Entire X` concept that falls back
22
+ to a generic ancestor instead of the specific `Structure of X` it should actually be a subtype of,
23
+ and silently strands the pair-mate's own work item even though it was directly relevant to work
24
+ already done. This check runs in **both directions** and needs both:
25
+ - From a `Structure of X` concept, an `Entire X` pair-mate (if one exists) is a **descendant** —
26
+ invisible to an ordinary ancestor/parent walk. Hypothesize the child's FSN and confirm via
27
+ `get-concept` that it actually states the `Structure of X` concept as a parent before treating
28
+ it as a real pair-mate.
29
+ - From an `Entire X` concept, its `Structure of X` pair-mate is among its own **stated parents** —
30
+ already visible from a `get-concept` on it, but `Entire X` concepts can carry 2-4 parents, so
31
+ check every one, not just the first plausible match.
32
+
33
+ **An `Entire X` concept's own parent should be another `Entire X` concept, not a `Structure of X`
34
+ concept, once you're one level up the hierarchy.** Getting this backwards silently produces
35
+ classifier-flagged equivalent concepts, with no save-time validation warning at all — confirmed
36
+ real case: an `Entire X` concept was stated Is-a a `Structure of X` concept (plus a qualifying
37
+ attribute) when it should have been Is-a the broader, already-existing `Entire X` ancestor plus
38
+ the same attribute. The only symptom is `classify`/`review-concepts` reporting
39
+ `equivalentConceptsFound: true` — the CLI has no command listing which concepts are actually
40
+ flagged as equivalent (only the Authoring Workbench UI shows the pair), so whenever that flag
41
+ appears, check every `Entire X` concept touched this session for a stated parent that isn't
42
+ itself `Entire X`-named before searching further; that's the pattern to check first.
43
+
44
+ ## Laterality is an exception to the pairing pattern, not a variant of it
45
+
46
+ **A laterality-specific `Structure of X` never gets its own laterality-specific `Entire X`.**
47
+ `Structure of X of left hand` / `Structure of X of right hand` does not pair with a minted
48
+ `Entire X of left hand` / `Entire X of right hand` — there is exactly one `Entire X`,
49
+ laterality-neutral, the same way there is exactly one `Structure of X`. Laterality is expressed
50
+ as a `Laterality` attribute value applied to the generic pair, not by duplicating the
51
+ whole-structure concept once per side. Skip the pairing check above entirely whenever the source
52
+ concept being processed is itself laterality-qualified (FSN mentions "of left/right X", or it
53
+ carries a stated `Laterality` relationship) — running the pair-mate search anyway either finds
54
+ nothing (correct, but for the wrong apparent reason) or, worse, surfaces the real generic-level
55
+ `Entire X` and risks it being wrongly treated as a duplicate-candidate for renaming.
56
+
57
+ **A laterality-only axiom is a `FULLY_DEFINED` shape, and `create-concept` will not set that for
58
+ you.** If a concept's stated axiom is exactly one Is-a (to a generic parent) plus one `Laterality`
59
+ relationship and nothing else, that combination is definitionally sufficient — SNOMED CT already
60
+ treats it as such. Confirmed against native, decades-old content: `85151006 |Structure of left
61
+ hand|` is `FULLY_DEFINED` off a stated axiom of Is-a `40983000 |Hand structure|` (itself
62
+ `PRIMITIVE`) + `Laterality` = `Left` — the *parent's* own primitiveness is irrelevant; what
63
+ matters is that Laterality is the *sole* distinguishing attribute added. `create-concept` has no
64
+ `--definition-status` flag at all — every newly minted concept starts `PRIMITIVE` regardless of
65
+ its axiom's actual shape, and nothing downstream flags a laterality-specific concept left that way
66
+ as wrong (it doesn't trip any Snowstorm convention check). If the axiom carries *any* other
67
+ relationship beyond the one Is-a and the one Laterality (an extra site, a morphology, a second
68
+ parent from the decomposition check below, etc.), do **not** set `FULLY_DEFINED` — verify the
69
+ exact shape with `get-concept --axioms` every time, then `set-definition-status --id <id> --status
70
+ FULLY_DEFINED`, and re-`get-concept` to confirm it actually changed. When fixing this across a
71
+ batch of concepts, see `SKILL.md`'s "Concurrency: one mutating caller per task branch, at a time"
72
+ — queue the calls sequentially rather than in parallel, and re-verify the whole target set
73
+ afterward with fresh `get-concept` calls rather than trusting the batch run's exit status.
74
+
75
+ ## Additional parents via decomposition — don't assume one axis is universal
76
+
77
+ A body-structure FSN is usually a composite of several semantic entities: a part/region word, a
78
+ tissue- or bone-class word, a containing structure, sometimes an articular/functional
79
+ relationship. Each entity is its own potential generalization axis, and each can have a real,
80
+ already-existing SNOMED CT concept that a concept being generalized or newly minted should also be
81
+ Is-a — beyond whatever single axis it was originally derived from.
82
+
83
+ **Evidence for any given axis has to come from the source's own real relationship history (active
84
+ *and* inactive) or from a genuine relationship between concepts already in the same batch — never
85
+ from analogy to a sibling that happened to have the axis.** A real, confirmed mistake: a
86
+ tissue-type parent (e.g. "soft tissue") was applied uniformly across several concept families in
87
+ one batch because it was correct for two of them — but wrong for others in the same batch that
88
+ had no such relationship at any point in their history (a vein family, correctly classified under
89
+ the vascular hierarchy instead) or that reached the same target only *transitively*, through a
90
+ real chain among the batch's own source concepts, making a direct link redundant on top of being
91
+ the wrong axis to reach for.
92
+
93
+ **Procedure:**
94
+ 1. Decompose the concept's FSN into its semantic entities (part/region, tissue/bone-class,
95
+ containing structure, any articular/functional relationship implied).
96
+ 2. For each entity, hypothesize a more generic categorization concept at the same specificity
97
+ level and `search-concepts` for it.
98
+ 3. For each hit, `get-concept` it and confirm it's a genuine categorization — read its own
99
+ FSN/definition, don't just accept a plausible-sounding name.
100
+ 4. Check whether two of the *current batch's own* source concepts are related to each other at a
101
+ more generic level — if so, mirror that relationship at the level you're working at too; this
102
+ is easy to miss because each source is naturally processed as an independent candidate.
103
+ 5. Add each confirmed axis as its own stated Is-a. Absence of evidence for an axis is a judgment
104
+ call, not an automatic skip or an automatic apply — don't force a categorization without a
105
+ real, confirmable target, and don't assume an axis is universal just because it applied to a
106
+ sibling in the same batch.
107
+ 6. After adding any second (or third+) parent, `classify --wait` and confirm
108
+ `equivalentConceptsFound: false` before treating the axiom as final — two parents in an
109
+ unexpected ancestor/descendant relationship, or that make two sibling concepts equivalent,
110
+ would surface here.
111
+
112
+ This decomposition check applies retroactively too, not just to concepts being minted right now —
113
+ a concept minted before this check was part of your process can just as easily be missing a real
114
+ axis that was sitting on its own source's `get-concept` output the whole time. Treat every batch
115
+ of related concepts as needing this audit, not as a one-time sweep.
116
+
117
+ ## A retrofitted relationship and a renamed/updated description are independent checklist items
118
+
119
+ When generalizing a specific concept into a broader one, the stated Is-a retrofit (the specific
120
+ concept pointing at the new broader one) and any accompanying description change (an FSN
121
+ disambiguation, a new synonym) are two **separately skippable** steps — never treat one as proof
122
+ the other happened. This risk is highest when the retrofit relationship already existed natively
123
+ in the terminology, sometimes for years, before your project touched the concept: it's easy to
124
+ reason "the relationship is already there, so this concept's work is done" and skip the
125
+ description change entirely, even though that change has nothing to do with whether the
126
+ relationship needed adding.
127
+
128
+ On a tracker or project resumed from a prior session, run a live check of the actual current
129
+ description text — not a cached/frozen value from when a tracker row was seeded — for every
130
+ concept marked complete, at least once, rather than assuming an earlier pass gave every one the
131
+ full treatment.
@@ -112,6 +112,45 @@ Either way, such a script should only ever *find candidates*, never decide fitne
112
112
  its own — keep the compound-word/idiom/cardinality judgment calls (see `SKILL.md`) as an explicit
113
113
  manual step after the script (or this flag) narrows the field.
114
114
 
115
+ ## Driving a batch of mutating calls
116
+
117
+ Queue mutating calls sequentially against one task branch; never run them in parallel, and never
118
+ delegate the batch itself to a subagent — see `SKILL.md`'s "Concurrency: one mutating caller per
119
+ task branch, at a time" for why this holds regardless of which command you're batching. The rest
120
+ of this section is the concrete driving mechanics for a large multi-session batch specifically.
121
+
122
+ - **Never run mutating calls in parallel against the same task branch.** Even a single sequential
123
+ caller can surface "branch locked, retrying" from the server's own internal locking — true
124
+ concurrent callers (multiple background loops, or an `xargs -P`-style fan-out) compound this and
125
+ have produced real, silent data loss (a call that appears to succeed but didn't land). Reserve
126
+ parallelism for **read-only** calls (a `get-concept` audit sweep) — never for
127
+ `create-concept`/`add-relationship`/`replace-fsn`/`add-description`/etc.
128
+ - **A real shell array, not an unquoted loop variable.** In zsh, `for id in $VAR; do ... done` does
129
+ **not** word-split an unquoted space-separated variable the way bash does — the loop silently
130
+ runs once with the whole string as one bogus "ID," which looks like a hang (the CLI chokes on
131
+ garbage input) rather than an obvious error. Use a real array (`IDS=(...)` / `"${IDS[@]}"`), which
132
+ is safe and is exactly the right pattern for a backgrounded batch — don't avoid arrays on the
133
+ mistaken belief that all shell-loop batch driving is equally risky; the specific risk is the
134
+ unquoted-variable word-splitting bug and true parallel execution, not arrays or backgrounding
135
+ themselves.
136
+ - **Never delegate the batch itself to a subagent.** A subagent's self-reported summary is not
137
+ ground truth — subagents have been observed to report a relationship added when none existed on
138
+ either concept, and to report an "exact match" for an ID that doesn't correspond to anything
139
+ relevant. Whoever runs the batch should drive it directly and re-verify every created/modified ID
140
+ (and every claimed pre-existing match) against live `get-concept`/`search-concepts` output before
141
+ recording it in the tracker — never trust a delegate's summary as the record of what happened.
142
+ - **Never reimplement the touched-concept list with a hand-tracked file.**
143
+ `authoring-cli get-concepts-for-review` already returns every concept with pending stated changes
144
+ on the task, flags entries created-then-deleted on the same branch (`"deleted": true` — filter
145
+ these out before validating or reporting), and needs no bookkeeping of your own. Call it fresh
146
+ whenever you need the list — for a structural self-check, a validation pass, or close-out — rather
147
+ than trusting a list assembled earlier in the session; a hand-rolled tracking mechanism drifts the
148
+ moment something gets deleted, retried, or added out of band.
149
+ - Don't let one script's early exit (`set -e` plus a transient network blip) silently truncate a
150
+ batch — check the actual per-concept completion count against the expected total before trusting a
151
+ "completed" exit status, and build retry logic for known-transient errors (socket disconnects,
152
+ "branch locked") rather than letting the whole run die on the first one.
153
+
115
154
  ## Closing out a session
116
155
 
117
156
  Report, and record in the tracker: how many created, how many skipped and why (grouped by