authoring-cli 0.1.2 → 0.1.4

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.2",
3
+ "version": "0.1.4",
4
4
  "description": "CLI for SNOMED CT authoring against authoring-services",
5
5
  "license": "Apache-2.0",
6
6
  "bin": {
@@ -8,6 +8,7 @@
8
8
  },
9
9
  "files": [
10
10
  "dist/index.js",
11
+ "HELP.md",
11
12
  "skills/"
12
13
  ],
13
14
  "engines": {
@@ -163,6 +163,34 @@ Which list to run:
163
163
  `"In Review"`, `"New"`, `"Promoted"`, ...). `--json` emits the raw task objects, for when you need
164
164
  fields the line format doesn't print.
165
165
 
166
+ ## Common authoring mistakes to avoid
167
+
168
+ Some mistakes are easy to make and don't trigger validation errors, so they slip through unless
169
+ you catch them during review or read the concept back afterward. Watch for these:
170
+
171
+ **FSN semantic tag errors:**
172
+ - **Duplicate semantic tags**: `Structure of deep flexor tendon within digit of hand (body
173
+ structure) (body structure)` is malformed. The FSN ends with exactly one semantic tag in
174
+ parentheses, not multiple identical ones. If you see duplicates, it's a copy-paste error.
175
+ - **Missing or wrong semantic tag**: every FSN must end with a semantic tag; verify it matches the
176
+ concept's actual domain. A body-structure concept should end with `(body structure)`, a finding
177
+ with `(finding)`, etc.
178
+
179
+ **Synonym specificity and meaning:**
180
+ - **Inappropriate synonyms that shift the concept's meaning**: a synonym must name the same clinical
181
+ entity — just a different way of saying it. Don't add a synonym that is too generic or names a
182
+ larger/different structure. For example, "finger and/or thumb" is inappropriate for "Structure of
183
+ deep flexor tendon within digit of hand (body structure)" because it names a broader anatomical
184
+ region, not the tendon structure itself. If the synonym would be true of multiple unrelated
185
+ concepts or a broader concept, it's the wrong synonym for this one.
186
+ - **Synonym conflation**: don't mix two genuinely different clinical ideas in different synonyms on
187
+ the same concept, expecting them to be clarified by acceptability or acceptability flags. The
188
+ Preferred Term and acceptable synonyms should all refer to the same clinical entity.
189
+
190
+ Run `review-concepts` before promoting a task to check these mistakes aren't hiding in your
191
+ pending changes — they save cleanly but are real content errors, not save-time constraint
192
+ violations.
193
+
166
194
  ## Ground truth vs. echoed validation results
167
195
 
168
196
  Every concept-mutating command (`create-concept`, `add-description`, `set-acceptability`, ...)
@@ -425,6 +453,18 @@ process". Get the direction backwards and nothing complains: the axiom saves, va
425
453
  misbehaves at classification, where it drags unrelated concepts underneath your concept. Read the
426
454
  axiom back with `get-concept` and check your concept is the one on the right of the `SubClassOf`.
427
455
 
456
+ **Checking whether a concept already has GCI axioms, before adding another:** a plain `get-concept
457
+ --id <SCTID>` already answers this — a non-zero `gciAxioms.length` on that response means the
458
+ concept has at least one, no filter needed. To check whether a *specific* attribute type is already
459
+ asserted inside an existing GCI — e.g. before adding a GCI whose antecedent would duplicate one
460
+ already there — add `--gci` to `get-concept`'s `--attribute-type` filter (see the substitution
461
+ pattern below for the flag's base behavior): `get-concept --id <SCTID> --attribute-type <typeId>
462
+ --gci` returns just that GCI's matching relationships instead of the whole concept. Without `--gci`,
463
+ `--attribute-type` scans `classAxioms` only — the two are never scanned together, since a class
464
+ axiom's relationships and a GCI's mean opposite things (see above). See
465
+ `references/gci-modeling.md`'s "Confirming the concept's current state" for the fuller pre-flight
466
+ check this feeds into.
467
+
428
468
  The `groupId`s work exactly as they do in a class axiom, so the multi-group caveat above applies
429
469
  here too — build the whole relationship list in one call.
430
470
 
@@ -574,22 +614,27 @@ read it *before* starting the cleanup below. The cleanup writes to other concept
574
614
  only afterwards that the deletion can't proceed leaves you having re-parented children away from a
575
615
  concept that's staying, and having stripped retrofits that should have stayed.
576
616
 
577
- ### 1. Find everything that references it — no single query finds all of it
617
+ ### 1. Find everything that references it — one query, run twice
578
618
 
579
- Two distinct kinds of reference, and the obvious query for each has a blind spot:
619
+ `find-references --id <SCTID>` wraps Snowstorm's own concept-references lookup, and covers both
620
+ kinds of reference in one call — attribute values (`Finding site`, `Procedure site`, `Associated
621
+ morphology`, …) *and* stated `Is a` children — grouped by reference type, instead of needing a
622
+ separate ECL query per kind:
580
623
 
581
- - **Attribute references** (`Finding site`, `Procedure site`, `Associated morphology`, …):
582
- `search-concepts --ecl "*:*=<SCTID>"` finds these. It does **not** find `Is a` children.
583
- - **Subtype children** (a stated `Is a` pointing at the concept): `search-concepts --ecl
584
- "<<SCTID>"` reads the *inferred* view, so it misses a child whose stated parent was added since
585
- the last classification — exactly the situation right after authoring.
624
+ ```
625
+ authoring-cli find-references --id <SCTID> # inferred/realized view
626
+ authoring-cli find-references --id <SCTID> --stated # literal stated axioms
627
+ ```
586
628
 
587
- So run both, and then close the gap with an edit-based sweep: a concept that has never been
588
- released can only be referenced by something edited on the same branch, so every candidate appears
589
- in `get-concepts-for-review`. Fetch each ID from its `concepts` array with `get-concept` and scan
590
- `classAxioms[].relationships[].target.conceptId` for your target. (If the concept has been promoted
591
- beyond the task branch, widen that sweep to the project branch — the task's own review list won't
592
- see a referrer edited on a sibling task.)
629
+ Run **both**. Without `--stated` it reads the *inferred* view — the realized, already-classified
630
+ state, which is what already-released content shows up under. With `--stated` it reads the literal
631
+ axioms as authored — which is what catches a same-session edit (a new relationship, a new stated
632
+ `Is a`) before classification has run, exactly the situation right after authoring. Neither view
633
+ alone is a complete answer on a branch with pending, unclassified changes; the inferred view misses
634
+ what you just stated, and the stated view misses anything the terminology already carries only
635
+ through inference. `--limit`/`--offset` page through `referencesByType[].referencingConcepts` on a
636
+ heavily-referenced concept — check `total` against what came back, the same caution as any other
637
+ paginated search here.
593
638
 
594
639
  ### 2. Deal with every reference before deleting anything
595
640
 
@@ -646,6 +691,30 @@ The same reference checks apply either way. Inactivation doesn't dangle referenc
646
691
  does, but a still-active concept whose `Finding site` points at an inactive concept is its own
647
692
  validation problem — check 1 is worth running before either command.
648
693
 
694
+ The same choice exists one level down, for a single description: `delete-description` splices a
695
+ never-versioned FSN/PT/synonym out entirely, while `inactivate-description --id <SCTID>
696
+ --description-id <descriptionId> --indicator <value> [--association-refset <id>
697
+ --association-target <SCTID>]` retires a *released* one in place, matching real RF2 data — an
698
+ already-inactive description always has an empty `acceptabilityMap`, so `inactivate-description`
699
+ clears it for you rather than leaving a stale PREFERRED/ACCEPTABLE entry behind. Each command
700
+ guards the case the other one is for: `delete-description` 409s on a versioned description,
701
+ `inactivate-description` 409s on one that was never versioned. Note this can still trip the "exactly one PREFERRED synonym per language refset" constraint above:
702
+ inactivating a dialect's sole PT clears its only PREFERRED entry in that refset, so
703
+ `inactivate-description` itself gets the 400 if you do it first. Same fix as replacing a published
704
+ axiom — promote the replacement synonym to PREFERRED with `set-acceptability`/`--entries` *before*
705
+ inactivating the old PT, not after, so the dialect never has zero PREFERREDs at any save boundary.
706
+
707
+ The same choice exists for a single class axiom too, with one asymmetry from the concept/description
708
+ pair above: `delete-axiom --id <SCTID> --axiom-id <axiomId>` refuses outright once that axiom's own
709
+ `effectiveTime` is set, but `inactivate-axiom --id <SCTID> --axiom-id <axiomId>` has no such gate —
710
+ setting `active: false` on an axiom's row is the normal RF2 retirement path regardless of whether it
711
+ was ever versioned, so it accepts both a released and a never-versioned axiom. There's no indicator
712
+ or association target at the axiom level; both commands instead guard the concept's minimum: it must
713
+ keep at least one class axiom (`delete-axiom` counts all of them) and, separately, at least one
714
+ *active* one (`inactivate-axiom` counts only active ones). See "Replacing a published axiom" above
715
+ for the add-axiom-then-inactivate-axiom sequence this feeds into when the goal is swapping an
716
+ axiom's content rather than just retiring it.
717
+
649
718
  ## Generating a concept structurally parallel to an existing one
650
719
 
651
720
  A common authoring task, especially at scale: mint a new concept whose defining axiom is identical
@@ -656,8 +725,11 @@ across a large source list, see `references/batch-authoring.md`.)
656
725
  1. Fetch the source's **real** defining axiom via `get-concept` — not a rendering or a note from an
657
726
  earlier session; it may have changed. Identify exactly which relationship(s) carry the attribute
658
727
  you're substituting (for a site swap: Finding site `363698007`, Procedure site `363704007`,
659
- Procedure site - Direct `405813007`, Procedure site - Indirect `405814001`). Copy everything else
660
- in the axiom — morphology, occurrence, method, due-to, the top-level `Is a` — verbatim.
728
+ Procedure site - Direct `405813007`, Procedure site - Indirect `405814001`) — `get-concept --id
729
+ <sourceId> --attribute-type <typeId>` returns just those matches (target concept, `groupId`,
730
+ `relationshipId`) instead of making you pick them out of the full axiom dump by hand. Copy
731
+ everything else in the axiom — morphology, occurrence, method, due-to, the top-level `Is a` —
732
+ verbatim.
661
733
  2. Verify the substituted value's target concept already exists via a live `search-concepts` with
662
734
  an **exact** match check on the FSN, not a fuzzy hit and not a static/hardcoded mapping table —
663
735
  terminology content drifts and a stale local table will confidently point you at the wrong
@@ -779,6 +851,13 @@ The names are deliberately distinct: `validate-task` validates the entire task b
779
851
  job, like `classify`); `validate-concept` is a synchronous, read-only check of a single concept;
780
852
  `validate-review-concepts` runs that per-concept check across your pending edits.
781
853
 
854
+ **Important:** `validate-review-concepts` catches Snowstorm-enforced issues (MRCM violations,
855
+ description constraints, etc.), but it does *not* catch content errors that save cleanly — duplicate
856
+ semantic tags in FSNs, inappropriate synonyms, synonym conflation, or other modeling mistakes. Those
857
+ require editorial review. Always follow `validate-review-concepts` with `review-concepts` to check
858
+ for these issues before promoting a task. See "Common authoring mistakes to avoid" above and the
859
+ full `references/review-concepts.md` checklist for what to watch for.
860
+
782
861
  ## Reviewing concepts against SNOMED CT terminology standards
783
862
 
784
863
  ```
@@ -76,24 +76,41 @@ value. If repeated re-lookups genuinely become a bottleneck at scale, that's a r
76
76
  introduce a cache — but validate the cache against live search periodically rather than treating it
77
77
  as permanently authoritative.
78
78
 
79
- ## Scripting against authoring-cli's JSON output
80
-
81
- Shell scripts that automate scope-filtering or candidate discovery should parse `authoring-cli`'s
82
- JSON output with `jq`, not a general-purpose scripting language — it keeps the script a single
83
- dependency-free file and makes the intent legible at a glance:
84
-
85
- ```bash
86
- json=$(authoring-cli get-concept --id "$id" --project "$PROJ" --task "$TASK" 2>/dev/null)
87
- defstatus=$(echo "$json" | jq -r '.definitionStatus')
88
- sites=$(echo "$json" | jq -r '
89
- [.classAxioms[]?.relationships[]? | select(.typeId=="363698007")]
90
- | .[] | [.target.fsn.term, .destinationId, .groupId] | @tsv
91
- ')
79
+ ## Getting the source's attribute value without hand-parsing the axiom
80
+
81
+ The substitution pattern needs, for each source concept, the current target of whatever attribute
82
+ is being substituted (Finding site, Procedure site, ...). Use `get-concept --attribute-type
83
+ <typeId>` for this rather than pulling the full concept and picking the relationship out of
84
+ `classAxioms[].relationships[]` yourself — it returns just the matches, across every active class
85
+ axiom, with the fields the substitution step needs already extracted:
86
+
87
+ ```
88
+ authoring-cli get-concept --id <sourceId> --attribute-type 363698007
89
+ ```
90
+
91
+ ```json
92
+ {
93
+ "conceptId": "<sourceId>",
94
+ "attributeType": "363698007",
95
+ "matches": [
96
+ { "axiomId": "...", "relationshipId": "...", "relationshipIndex": 1, "groupId": 1,
97
+ "targetId": "53505006", "targetFsn": "Structure of nail unit of great toe",
98
+ "active": true, "effectiveTime": null, "released": false }
99
+ ]
100
+ }
92
101
  ```
93
102
 
94
- Such a script should only ever *find candidates* — it shouldn't decide fitness for creation on its
95
- own. Keep the compound-word/idiom/cardinality judgment calls (see `SKILL.md`) as an explicit manual
96
- step after the script narrows the field, not folded into the script's filtering logic.
103
+ `matches` is `[]`, not an error, when the concept has none of that attribute — a real result worth
104
+ routing to `SKIPPED_TRIAGE`, not a failure to retry. `definitionStatus` (needed for step 3 of the
105
+ substitution pattern) is a single top-level field on the plain `get-concept` response — read it
106
+ directly from that JSON, no extraction needed.
107
+
108
+ If a scope-filtering or candidate-discovery script needs data this flag doesn't cover, that's a
109
+ capability gap in the CLI, not something to close with a `jq`/`node -e` script against raw
110
+ `get-concept` output — see `CLAUDE.md`'s guidance on when a missing capability is a feature request.
111
+ Either way, such a script should only ever *find candidates*, never decide fitness for creation on
112
+ its own — keep the compound-word/idiom/cardinality judgment calls (see `SKILL.md`) as an explicit
113
+ manual step after the script (or this flag) narrows the field.
97
114
 
98
115
  ## Closing out a session
99
116
 
@@ -160,17 +160,30 @@ information yet."
160
160
  Read the live axioms before assuming anything about what's already there — a candidate can already
161
161
  be modelled and simply not annotated as such in whatever list surfaced it:
162
162
 
163
- ```bash
164
- authoring-cli get-concept --id <SCTID> | sed -n '/^{/,$p' | jq -r '
165
- "\(.fsn.term) [\(.definitionStatus)] gci=\(.gciAxioms|length)",
166
- (.classAxioms[] | "CLASS " + ([.relationships[]|select(.active)|"g\(.groupId):\(.type.pt.term)=\(.target.conceptId)|\(.target.fsn.term)"]|join(" | "))),
167
- (.gciAxioms[] | "GCI " + ([.relationships[]|select(.active)|"g\(.groupId):\(.type.pt.term)=\(.target.conceptId)|\(.target.fsn.term)"]|join(" | ")))'
163
+ ```
164
+ authoring-cli get-concept --id <SCTID>
168
165
  ```
169
166
 
170
- `gci=0` means there's no existing GCI on this concept — but check the checklist above before
171
- concluding one is *needed*; the common outcome across any grouper-style hierarchy is that most
172
- candidates correctly get none. Anything else means you're reviewing existing axioms, which is a
173
- different job from authoring new ones — say so rather than adding duplicates on top.
167
+ Read `definitionStatus` and `gciAxioms.length` straight off that JSON — no extraction step needed
168
+ for a single concept; a non-zero `gciAxioms.length` is enough to answer "does this concept have a
169
+ GCI" without any filter. For each active relationship inside `classAxioms[].relationships[]` and
170
+ `gciAxioms[].relationships[]`, the fields that matter are `groupId`, `type.pt.term` (or
171
+ `type.conceptId`), and `target.fsn.term` (or `target.conceptId`); read `classAxioms` for the
172
+ target's own definition and `gciAxioms` for what it already asserts as sufficient conditions on
173
+ others. If you only need one attribute type's relationships rather than the whole axiom — e.g.
174
+ checking a specific candidate attribute in isolation — `get-concept --id <SCTID> --attribute-type
175
+ <typeId>` returns just those matches (target, `groupId`, `relationshipId`) instead, scanning
176
+ `classAxioms` by default. Add `--gci` to scan `gciAxioms` instead when the question is specifically
177
+ "does an *existing GCI* already assert this attribute" — e.g. confirming the tautology check
178
+ earlier in this file, or checking whether a candidate antecedent's defining attribute is already
179
+ covered by a GCI the target carries. The two scans are never combined in one call, since a class
180
+ axiom's relationships and a GCI's mean opposite things (see "What a GCI is" above) and conflating
181
+ their matches would misreport which side of the concept's definition the attribute lives on.
182
+
183
+ An empty `gciAxioms` array means there's no existing GCI on this concept — but check the checklist
184
+ above before concluding one is *needed*; the common outcome across any grouper-style hierarchy is
185
+ that most candidates correctly get none. Anything else means you're reviewing existing axioms,
186
+ which is a different job from authoring new ones — say so rather than adding duplicates on top.
174
187
 
175
188
  ## The antecedent: genus, nexus, defining attribute
176
189
 
@@ -85,7 +85,11 @@ Read the axiom from `get-concept`, not a cached summary, and check:
85
85
  each other. A concept where everything landed in one group, or where a self-grouped attribute got
86
86
  swept into a clinical-finding group, has had its actual meaning changed even though it validates —
87
87
  this is the judgment layer behind the `add-relationship --group N` compaction hazard documented in
88
- `SKILL.md`.
88
+ `SKILL.md`. To confirm which `groupId` two attribute types actually landed in without picking
89
+ through the full axiom by hand, run `get-concept --id <id> --attribute-type <typeId>` once per
90
+ type (e.g. Finding site `363698007`, Associated morphology `116676008`) and compare the returned
91
+ `groupId` values directly — same `groupId` means Snowstorm grouped them together, different
92
+ `groupId`s means it didn't.
89
93
  - **Primitive vs. sufficiently-defined status is appropriate, not just consistent with the source
90
94
  concept.** A concept should be sufficiently defined when its stated relationships are "adequate to
91
95
  define it relative to its immediate supertypes" — i.e. another concept with the same parent and
@@ -121,16 +125,30 @@ Read the axiom from `get-concept`, not a cached summary, and check:
121
125
  actually name two different clinical ideas, not two names for the same one.
122
126
  `set-acceptability`/`add-description` will happily save either shape; only reading the terms
123
127
  side by side catches the conflation.
128
+ - **Inappropriate synonyms that lose specificity** — a synonym that is too generic, vague, or
129
+ semantically shifts the concept's meaning. For example, "finger and/or thumb" is inappropriate as
130
+ a synonym for "Structure of deep flexor tendon within digit of hand (body structure)" because it
131
+ names a larger anatomical region, not the same structure — the synonym must name the same clinical
132
+ entity, just a different way of saying it. If the synonym would be true of a broader or differently
133
+ defined concept, it's the wrong synonym for this one.
124
134
  - **No relationships beyond `Is a`** — likely under-modelled for a concept whose hierarchy position
125
135
  implies it should carry at least one defining attribute (e.g. a disorder with no `Finding site`
126
136
  or `Associated morphology` at all, when siblings all have one).
127
137
  - **A parenthetical qualifier inside the FSN body, distinct from the semantic tag** — sometimes a
128
138
  legitimate disambiguator, but can also signal that the concept should have been split, or that the
129
139
  qualifying detail belongs in the definition/attributes instead of the name.
140
+ - **Duplicate semantic tags in the FSN** — the FSN must end with exactly one semantic tag in
141
+ parentheses, not multiple identical ones (e.g. "Structure of deep flexor tendon within digit of
142
+ hand (body structure)" is correct; "Structure of deep flexor tendon within digit of hand (body
143
+ structure) (body structure)" is wrong). If you see duplicate tags, it's a copy-paste or formatting
144
+ error that needs correction.
130
145
  - **Value-set-style checks**: if the review surfaces a group of concepts meant to function as a set
131
146
  (a batch you just authored, or an existing reference set), confirm every member is active — an
132
147
  inactive code hiding inside an otherwise-active set is easy to miss one at a time and obvious once
133
- counted.
148
+ counted. For a batch you just authored, `review-concepts`'s own output already has each member's
149
+ active status, no extra step needed. For an existing reference set, don't fetch every member with
150
+ `get-concept` to check by hand — `search-concepts --ecl "^ <refsetId>" --active false` asks
151
+ Snowstorm directly for just the inactive members of that refset in one call.
134
152
 
135
153
  ## Historical associations for inactive concepts encountered during review
136
154