authoring-cli 0.1.0

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.
@@ -0,0 +1,689 @@
1
+ ---
2
+ name: authoring-cli
3
+ description: >
4
+ How to drive `authoring-cli`, the headless SNOMED CT authoring tool, correctly — concept
5
+ creation, description/acceptability edits (especially the US/GB and other dialect
6
+ spelling-variant pattern: edema/oedema, anemia/anaemia, hemoglobin/haemoglobin, tumor/tumour,
7
+ leukocyte/leucocyte, etc.), relationship/axiom edits, classification, batch/bulk concept
8
+ generation, and deleting or inactivating a concept safely (re-parenting its children and
9
+ retargeting every logical-definition reference *before* the delete, since `delete-concept` leaves
10
+ dangling references behind and warns about none of them). Use this whenever you're about to run
11
+ `authoring-cli` to create, edit, delete, or inactivate a concept —
12
+ its descriptions, acceptability, relationships, or axioms — or to run `classify`/`validate-task`, or
13
+ to generate a concept that's structurally parallel to an existing one (same axiom shape, one
14
+ attribute swapped, across possibly hundreds of source concepts). Use it also for the surrounding
15
+ session commands — signing in, listing projects, and listing tasks ("list my tasks", "what am I
16
+ working on", "show the tasks on <project>"), which are answered summary-first with counts by
17
+ project and status before any per-task detail, and selecting the task subsequent commands target.
18
+ Several of these operations have
19
+ hard server-side constraints or async/caching quirks that fail or mislead in non-obvious ways if
20
+ you don't know about them going in. Also use this if any `authoring-cli` command returns an HTTP
21
+ 400/409/500, or if a validation warning doesn't seem to match what you just saved.
22
+ ---
23
+
24
+ # authoring-cli
25
+
26
+ `authoring-cli` performs SNOMED CT authoring actions against a task branch, with no editor process
27
+ involved. Run it with no arguments to print the full, current command list — that list is the source
28
+ of truth over anything below; commands and flags get added over time and this file will lag.
29
+
30
+ ```
31
+ authoring-cli
32
+ ```
33
+
34
+ Every action needs task context, which comes from one of two places:
35
+
36
+ - the task recorded in `~/.authoring-cli/session.json` by `authoring-cli select-task --project
37
+ <key> --task <key>` — the default target for every subsequent command, or
38
+ - an explicit `--project <key> --task <key>` pair passed on the individual call, which overrides it.
39
+
40
+ `authoring-cli current-task` prints the selected task, and — if given `--project`/`--task` — notes
41
+ whether they match what's stored. Run it to confirm which task the CLI will actually target before
42
+ committing to a sequence of edits. If nothing is selected and no flags are passed, commands fail
43
+ rather than guessing. `authoring-cli projects` and `authoring-cli tasks` list what's available to
44
+ pick from; a session with no valid cookie needs `authoring-cli login [production|uat|dev]` first.
45
+
46
+ The `--project`/`--task` flags are shown on the examples below for explicitness. When a task is
47
+ already selected via `select-task`, you can omit them everywhere.
48
+
49
+ ### Starting a new task
50
+
51
+ ```
52
+ authoring-cli create-task --project <projectKey> --summary "<title>" [--description "<text>"]
53
+ ```
54
+
55
+ The server mints the task key — you don't supply it. It also returns the task's branch path, but
56
+ does not create that branch; `create-task` and `select-task` do, so a task is workable the moment
57
+ either one returns. The new task is selected automatically, so the commands that follow need no
58
+ `--project`/`--task`; pass `--no-select` to leave the current selection alone.
59
+
60
+ It is assigned to you unless you pass `--assignee <username>` or `--unassigned`. That default is
61
+ deliberate rather than cosmetic: authoring-services doesn't infer an assignee from the session, and
62
+ an unassigned task is absent from `tasks --mine` — which is where you'd go looking for the task you
63
+ just created.
64
+
65
+ Task keys are per-deployment. `ANCRJAN22-957` on dev and `ANCRJAN22-957` on uat are unrelated
66
+ tasks, so a key copied from notes, a ticket, or another environment's URL means nothing until
67
+ `current-task` or `tasks` confirms it on the environment you're actually signed in to.
68
+
69
+ ### Deleting a task
70
+
71
+ ```
72
+ authoring-cli delete-task [--project <projectKey> --task <taskKey>]
73
+ ```
74
+
75
+ With no flags it deletes the selected task and clears that selection. Two things worth knowing
76
+ *before* deciding to delete, since neither is apparent from the result:
77
+
78
+ - **It is reversible** — see `recover-task` below. Deleting sets the task's status to Deleted; the
79
+ branch and everything on it survive untouched. Nothing on this platform deletes a task branch,
80
+ so unpromoted content is stranded rather than destroyed.
81
+ - **It stops once the work is promoted.** A task in status Promoted or Completed is refused: its
82
+ content is already in the project and the task is the only record of how it got there. Delete
83
+ while a task is still the place the work lives, or not at all.
84
+
85
+ ### Recovering a deleted task
86
+
87
+ ```
88
+ authoring-cli recover-task --project <projectKey> [--task <taskKey>]
89
+ ```
90
+
91
+ Puts a deleted task back into In Progress, with its branch content intact, and selects it. Its
92
+ status before deletion isn't recorded anywhere reachable, so recovery always lands on In Progress
93
+ regardless of where the task was when it was deleted.
94
+
95
+ Run it without `--task` first: a deleted task is absent from `tasks` and from every other listing,
96
+ so that is the only way to see what there is to recover.
97
+
98
+ ### Listing tasks
99
+
100
+ Asked to list tasks — "list my tasks", "what am I working on", "show the tasks on `<project>`" —
101
+ **lead with the summary, then offer the detail.** An active author can hold dozens of open tasks
102
+ (60+ is normal), and dumping all of them answers a question nobody asked; the counts are what make
103
+ the pile legible. Run `--summary` and stop there:
104
+
105
+ ```
106
+ authoring-cli tasks --mine --summary
107
+ ```
108
+
109
+ ```
110
+ 67 tasks assigned to you.
111
+
112
+ By project:
113
+ ANCRJAN22 47
114
+ AUTHORTEST 10
115
+ ...
116
+
117
+ By status:
118
+ In Progress 58
119
+ In Review 6
120
+ Promoted 2
121
+ New 1
122
+ ```
123
+
124
+ Relay that, add one line pointing at whatever looks like it wants attention (`In Review` and `New`
125
+ usually do), and **ask whether to show the full list or one project's** rather than deciding for
126
+ them. The user's follow-up then picks the scope:
127
+
128
+ - "show them all" / "list them" → the plain listing, every line, no truncation.
129
+ - "show the ANCRJAN22 ones" → `authoring-cli tasks --project ANCRJAN22 --mine`.
130
+ - "what's in review?" → `authoring-cli tasks --mine --status "In Review"`.
131
+
132
+ **Count with `--summary`, never by hand.** Tallying 67 printed lines by eye is unreliable and
133
+ silently produces a wrong-but-plausible breakdown; so does reaching for `--json | node -e ...`,
134
+ which is a scripting workaround for something the command already does. `--summary` counts the
135
+ same filtered set the listing would have shown, so `--project`/`--mine`/`--status` all compose with
136
+ it, and it omits any breakdown that would just restate the total (a single-project scope prints no
137
+ "By project"). It breaks down by assignee instead when the scope can hold other people's tasks.
138
+ `--summary --json` emits `{total, byProject, byAssignee, byStatus}` for programmatic use.
139
+
140
+ #### When you do show the list
141
+
142
+ One line per task, carrying **at least the task key and the title**:
143
+
144
+ ```
145
+ ANCRJAN22-959 "Laparoscopic procedure model" status=In Progress
146
+ ```
147
+
148
+ The key is what `select-task --project <key> --task <key>` and every `--task` flag take, and the
149
+ title is the only thing saying what the task is *for*; drop either and the user has to ask again.
150
+ The command already prints exactly `<taskKey> "<title>" status=<status>` (plus `[assignee]` when
151
+ the scope can contain other people's tasks), so relaying those lines verbatim is both correct and
152
+ cheapest. Keep the key exactly as printed — `ANCRJAN22-959`, never "task 959" or a renumbered list
153
+ position. Don't reorder the lines, and don't silently truncate: show all of them, or say how many
154
+ you left out.
155
+
156
+ Which list to run:
157
+
158
+ - `authoring-cli tasks --mine` — your tasks across every project. Plain `authoring-cli tasks` with
159
+ no flags is already this list.
160
+ - `authoring-cli tasks --project <key>` — *everyone's* tasks in that project. Add `--mine` to
161
+ narrow it back to your own within that project.
162
+ - `--status "<status>"` filters to a single status, matched case-insensitively (`"In Progress"`,
163
+ `"In Review"`, `"New"`, `"Promoted"`, ...). `--json` emits the raw task objects, for when you need
164
+ fields the line format doesn't print.
165
+
166
+ ## Ground truth vs. echoed validation results
167
+
168
+ Every concept-mutating command (`create-concept`, `add-description`, `set-acceptability`, ...)
169
+ requests Snowstorm's `?validate=true` on save and prints whatever `validationResults` comes back
170
+ alongside the outcome. `validate-concept` runs the same check read-only, without saving anything.
171
+
172
+ Both of these can lag behind a write that just landed on the *same* concept moments earlier —
173
+ they've been observed printing a warning describing the pre-fix state for several seconds to tens
174
+ of seconds after the fix was actually saved. Don't take a validation warning that doesn't match
175
+ what you expect at face value: re-fetch with `get-concept` and compare its `acceptabilityMap`
176
+ values directly. `get-concept`'s response is the one thing that reflects exactly what's persisted
177
+ right now. If the warning still contradicts a fresh `get-concept`, then something is actually
178
+ wrong; if it matches an old state, it's just this lag and will clear on its own.
179
+
180
+ ## The hard constraint you must design around
181
+
182
+ Snowstorm requires **exactly one PREFERRED synonym per language refset, at all times** — not a
183
+ soft warning, a blocking HTTP 400 on the save itself. Concretely, for a concept's en-us and en-gb
184
+ synonyms:
185
+
186
+ - Never zero PREFERRED synonyms in a given dialect.
187
+ - Never two PREFERRED synonyms in the same dialect.
188
+ - This is enforced *per save*, so it also rules out any sequence of saves that passes through an
189
+ invalid state in between, even momentarily.
190
+
191
+ This matters the moment you need to move "preferred" from one description to another in the same
192
+ dialect — e.g. you created a concept with the wrong term preferred in en-gb and want to swap it for
193
+ a different synonym. Doing this as two separate `set-acceptability --description-id ...` calls
194
+ **fails no matter which order you pick**:
195
+
196
+ - Promote the new one to PREFERRED first → briefly two PREFERRED synonyms in that dialect → 400
197
+ ("must not have more than one PT per language refset").
198
+ - Demote the old one first → briefly zero PREFERRED synonyms in that dialect → 400 ("must have one
199
+ Preferred Synonym in the ... language refset").
200
+
201
+ Both halves get rejected independently and atomically — nothing partially saves, so you can't
202
+ corrupt the concept this way, but you also can't complete the swap this way at all.
203
+
204
+ **The fix: `set-acceptability --entries`.** Instead of one `--description-id`, pass a JSON array
205
+ covering every description that needs to change, and they all apply within the same save:
206
+
207
+ ```
208
+ authoring-cli set-acceptability --id <SCTID> \
209
+ --entries '[{"descriptionId":"<oldPreferredId>","gb":"ACCEPTABLE"},
210
+ {"descriptionId":"<newPreferredId>","gb":"PREFERRED"}]' \
211
+ --project <projectKey> --task <taskKey>
212
+ ```
213
+
214
+ Reach for `--entries` by default whenever a fix touches more than one description's acceptability
215
+ on the same concept — not just for spelling variants, for *any* case where two descriptions need
216
+ to change together consistently. The plain single-description form (`--description-id <id>
217
+ [--lang ...] [--us ...] [--gb ...]`) is still correct and simpler, but only when the one change you
218
+ 're making doesn't require any other description to move in the same save (e.g. bumping an
219
+ already-non-conflicting description from ACCEPTABLE to PREFERRED, or demoting a description that
220
+ isn't the dialect's sole PREFERRED one).
221
+
222
+ ## US/GB (and other dialect) spelling-variant pairs
223
+
224
+ When a synonym contains a word that's spelled differently in US vs. GB English — edema/oedema,
225
+ anemia/anaemia, hemoglobin/haemoglobin, tumor/tumour, leukocyte/leucocyte, and others — model it as
226
+ **two separate synonym descriptions**, one per spelling. Don't put one term in both dialects.
227
+
228
+ ### The rule
229
+
230
+ **A description whose term is a US-only spelling may only ever be a member of the en-us refset —
231
+ never en-gb, not even as ACCEPTABLE. A description whose term is a GB-only spelling may only ever
232
+ be a member of the en-gb refset — never en-us.** The refset membership itself asserts "this text is
233
+ valid in this dialect" — a US-only spelling isn't valid GB English at any acceptability level, so
234
+ it has no business being *in* that refset at all, preferred or not. This is a modeling rule about
235
+ the term's content, independent of the "exactly one PREFERRED" save-time constraint above: even if
236
+ en-gb already has a different PREFERRED synonym and adding this one as merely ACCEPTABLE wouldn't
237
+ trip that constraint, it's still wrong to add it there.
238
+
239
+ Consequence for the acceptabilityMap:
240
+
241
+ | Description | en-us (900000000000509007) | en-gb (900000000000508004) |
242
+ |---------------------|------------------------------|------------------------------|
243
+ | US-spelled synonym | PREFERRED | NOT_ACCEPTABLE (absent) |
244
+ | GB-spelled synonym | NOT_ACCEPTABLE (absent) | PREFERRED |
245
+
246
+ (An intermediate "PREFERRED at home, ACCEPTABLE elsewhere" shape is *not* correct for a pure
247
+ spelling variant; that shape is for a genuinely different but valid synonym in both dialects, not
248
+ for two spellings of the same word.) The FSN is unaffected by any of this — it's a single fixed
249
+ term and stays PREFERRED in both dialects regardless.
250
+
251
+ The one invariant you can't violate on either description: an active description must be
252
+ PREFERRED-or-ACCEPTABLE in *at least one* dialect. `NOT_ACCEPTABLE` in every dialect at once is
253
+ rejected. That's never a concern here since each spelling variant keeps PREFERRED in its own home
254
+ dialect.
255
+
256
+ ### Worked example
257
+
258
+ Adding "Edema of digit of hand" with its GB variant "Oedema of digit of hand", parented under
259
+ `102564009` (Edema of hand):
260
+
261
+ ```
262
+ # 1. Create the concept. Pick either spelling for the FSN/PT — it doesn't matter which; Snowstorm's
263
+ # own validate=true response will immediately warn that the PT is preferred in the "wrong"
264
+ # dialect. That's expected at this point, not a sign create-concept did anything wrong.
265
+ authoring-cli create-concept --fsn "Edema of digit of hand" --parent 102564009 --tag finding \
266
+ --pt "Edema of digit of hand" --project <projectKey> --task <taskKey>
267
+ # → Created concept <SCTID>
268
+
269
+ # 2. Fetch it to read the server-assigned descriptionId of the PT/synonym just created.
270
+ authoring-cli get-concept --id <SCTID> --project <projectKey> --task <taskKey>
271
+ # → descriptionId <edemaId>, acceptabilityMap {us: PREFERRED, gb: PREFERRED}
272
+
273
+ # 3. Add the other spelling as a new synonym. --acceptability applies ONE value uniformly to both
274
+ # dialects at creation time, so this momentarily violates "the rule" above (a GB spelling
275
+ # sitting in en-us too) — that's fine as a staging step ONLY because step 5 corrects it in the
276
+ # very next save; don't stop here and leave it in this shape.
277
+ authoring-cli add-description --id <SCTID> --term "Oedema of digit of hand" --type SYNONYM \
278
+ --acceptability ACCEPTABLE --project <projectKey> --task <taskKey>
279
+
280
+ # 4. Fetch again for the new synonym's descriptionId.
281
+ authoring-cli get-concept --id <SCTID> --project <projectKey> --task <taskKey>
282
+ # → descriptionId <oedemaId>, acceptabilityMap {us: ACCEPTABLE, gb: ACCEPTABLE}
283
+
284
+ # 5. One atomic save: move "preferred in en-gb" from the US spelling to the GB spelling, AND strip
285
+ # each spelling's membership from the dialect it doesn't belong in. This one call both performs
286
+ # the preferred-synonym swap (which per the hard constraint above MUST be atomic) and reaches
287
+ # the correct target shape from the table.
288
+ authoring-cli set-acceptability --id <SCTID> \
289
+ --entries '[{"descriptionId":"<edemaId>","gb":"NOT_ACCEPTABLE"},
290
+ {"descriptionId":"<oedemaId>","us":"NOT_ACCEPTABLE","gb":"PREFERRED"}]' \
291
+ --project <projectKey> --task <taskKey>
292
+
293
+ # 6. Confirm.
294
+ authoring-cli validate-concept --id <SCTID> --project <projectKey> --task <taskKey>
295
+ # → No validation issues for concept <SCTID>.
296
+ ```
297
+
298
+ If step 6 still shows a spelling-variant warning, re-run `get-concept` and compare its
299
+ `acceptabilityMap` against the table above before assuming the fix didn't take — see "Ground truth
300
+ vs. echoed validation results" above.
301
+
302
+ ## Editing relationships and axioms
303
+
304
+ `add-relationship --group N` doesn't reliably honor the requested *absolute* group number once a
305
+ concept needs **more than one non-zero relationship group** — e.g. "Due to" in group 2 alongside
306
+ "Finding site"/"Associated morphology" in group 1. The groups can get silently compacted together,
307
+ which changes the axiom's actual meaning (grouped attributes describe one nexus; separate groups
308
+ are independent qualifiers) — this is easy to author and validate without noticing, since nothing
309
+ rejects the save.
310
+
311
+ If the concept needs more than one non-zero group, skip `add-relationship` for those and build the
312
+ whole axiom in one call instead, with the exact `groupId`s you want:
313
+
314
+ ```
315
+ authoring-cli update-axiom --id <SCTID> --axiom-id <axiomId> --relationships \
316
+ '[{"active":true,"groupId":0,"type":{"conceptId":"116680003"},"target":{"conceptId":"..."}},
317
+ {"active":true,"groupId":1,"type":{"conceptId":"363698007"},"target":{"conceptId":"..."}},
318
+ {"active":true,"groupId":2,"type":{"conceptId":"42752001"},"target":{"conceptId":"..."}}]'
319
+ ```
320
+
321
+ (Get `axiomId` from `get-concept` right after creating the concept.) Single-group concepts — the
322
+ common case — are unaffected; plain `add-relationship` is fine and simpler there.
323
+
324
+ ### Removing a relationship — including from a published axiom
325
+
326
+ (`remove-relationship` is also callable as `delete-relationship` — same command, whichever verb
327
+ you reach for first.)
328
+
329
+ `update-axiom` and `remove-relationship` are gated at **different levels**, and that difference is
330
+ the whole story for editing an axiom that's already been released:
331
+
332
+ - `update-axiom` checks the **axiom's own** `effectiveTime`. If the axiom has ever been versioned
333
+ (`released: true` with a real `effectiveTime`, not just inherited from the concept), every call
334
+ fails with HTTP 409 — it replaces `relationships` wholesale, so it refuses outright rather than
335
+ risk silently changing a released axiom's meaning.
336
+ - `remove-relationship` checks the **targeted relationship's own** `effectiveTime` only, never the
337
+ axiom's. This mirrors the real Authoring Workbench: its "Remove Relationship" button re-saves the
338
+ same axiom (same `axiomId`) with one relationship gone, regardless of whether that axiom has been
339
+ released before — only the specific relationship being removed must itself never have been
340
+ versioned.
341
+
342
+ So: **removing one relationship from a published axiom is `remove-relationship`, not
343
+ `update-axiom`.** Get the target's `relationshipId` (or its array index within that axiom) from
344
+ `get-concept`, then:
345
+
346
+ ```
347
+ authoring-cli remove-relationship --id <SCTID> --axiom-id <axiomId> --relationship-id <relationshipId>
348
+ ```
349
+
350
+ If that specific relationship has its own `effectiveTime` set (it was independently versioned —
351
+ uncommon, but possible for a relationship inside an otherwise-unversioned axiom edit history), the
352
+ call 409s and there's no way to remove it via the CLI; that's expected residue, same as the fully-
353
+ versioned-axiom case in "Redundant stated Is-a relationships" below.
354
+
355
+ ### Removing an entire role group
356
+
357
+ (`remove-role-group` is also callable as `delete-role-group` or `delete-rolegroup`.)
358
+
359
+ Use `remove-role-group`, not a manual loop of `remove-relationship` calls. It identifies the target
360
+ group **by content, not by `groupId`** — pass `{typeId, targetId}` attribute pairs that identify
361
+ the group, not necessarily all of them:
362
+
363
+ ```
364
+ authoring-cli remove-role-group --id <SCTID> --axiom-id <axiomId> --attributes \
365
+ '[{"typeId":"363698007","targetId":"53505006"}]'
366
+ ```
367
+
368
+ **Why content instead of `groupId`:** SNOMED CT's own model has no persistent "role group ID" —
369
+ `groupId` is just an internal number Snowstorm assigns per save to cluster relationships, and it's
370
+ already documented above as unreliable to target directly (`add-relationship --group N` silently
371
+ compacting groups together). The set of attribute/value pairs actually inside a group is the only
372
+ thing that names it consistently.
373
+
374
+ **`--attributes` only needs to *identify* the group, not enumerate it.** If one pair — say, Finding
375
+ site = X — occurs in only one role group of the axiom, that single pair is enough: the whole group
376
+ it belongs to is removed, including any other relationships in it you didn't mention (e.g. an
377
+ Associated morphology in the same group). You don't need to look up and list every relationship in
378
+ the group first. Get candidate pairs from `get-concept`'s `classAxioms[N].relationships[]` (each
379
+ entry's `type.conceptId`/`target.conceptId`, grouped by `groupId` just to see what's likely unique).
380
+
381
+ If the given pair(s) match **more than one** role group in the axiom, the call fails with HTTP 409
382
+ and lists every candidate `groupId` rather than guessing which one you meant — deleting the wrong
383
+ role group is not a recoverable mistake. From there you have two options:
384
+
385
+ - Add another attribute pair from the group you actually want (e.g. also include the Associated
386
+ morphology pair) and retry — this re-narrows the match to one group.
387
+ - Or, if the groups are genuinely indistinguishable by content alone, pass `--group-id N` (one of
388
+ the listed candidates) to target that specific one directly — the case-by-case fallback for when
389
+ two role groups happen to share an attribute pair but aren't actually the same group.
390
+
391
+ Same axiom-publication rule as `remove-relationship`: **no axiom-level `effectiveTime` gate at
392
+ all** — a published axiom's group can be removed just like an unpublished one. The only gate is
393
+ per-relationship: if any relationship inside the matched group has its own `effectiveTime` set
394
+ (independently versioned), the whole call 409s and nothing is removed — deliberately no partial
395
+ removal, since a role group's members jointly describe one nexus and dropping only some of them
396
+ would change what the axiom asserts rather than just shrinking it.
397
+
398
+ Two more edges worth knowing: `groupId 0` (SNOMED's ungrouped bucket, which usually also holds the
399
+ stated `Is a`) is excluded from matching unless you explicitly pass `--group-id 0` — otherwise a
400
+ pair that happens to match an ungrouped attribute could sweep up unrelated ungrouped relationships,
401
+ including `Is a`, as collateral damage. And `remove-role-group` only targets `classAxioms`; a GCI
402
+ role group still needs the `update-gci-axiom` workaround (rewrite the relationships list with that
403
+ group's entries omitted), gated on the whole GCI axiom's own `effectiveTime` since there's no
404
+ per-relationship GCI removal endpoint.
405
+
406
+ Confirm with `authoring-cli validate-concept --id <SCTID>` afterward.
407
+
408
+ ### Adding a GCI axiom
409
+
410
+ `add-gci-axiom` adds a **general concept inclusion** — and the relationships you pass mean the
411
+ opposite of what they mean in every other relationship command. In `add-relationship`,
412
+ `update-axiom` and friends, the relationships describe *the concept*. In a GCI they describe the
413
+ *other* side: the axiom asserts "anything matching this expression is a `--id` concept", so the
414
+ concept ends up as the **superclass**.
415
+
416
+ ```
417
+ authoring-cli add-gci-axiom --id <SCTID> --relationships \
418
+ '[{"active":true,"groupId":0,"type":{"conceptId":"116680003"},"target":{"conceptId":"64572001"}},
419
+ {"active":true,"groupId":1,"type":{"conceptId":"370135005"},"target":{"conceptId":"441862004"}}]'
420
+ ```
421
+
422
+ stores `SubClassOf(ObjectIntersectionOf(:64572001 <group 1>) :<SCTID>)` — i.e. "every *Disease*
423
+ with an *Infectious process* is a `<SCTID>`", not "`<SCTID>` is a disease with an infectious
424
+ process". Get the direction backwards and nothing complains: the axiom saves, validates, and only
425
+ misbehaves at classification, where it drags unrelated concepts underneath your concept. Read the
426
+ axiom back with `get-concept` and check your concept is the one on the right of the `SubClassOf`.
427
+
428
+ The `groupId`s work exactly as they do in a class axiom, so the multi-group caveat above applies
429
+ here too — build the whole relationship list in one call.
430
+
431
+ Unlike `update-gci-axiom` and `delete-gci-axiom`, **`add-gci-axiom` has no publication gate**: it
432
+ adds a brand-new axiom, so a released concept — or one whose existing axioms are all versioned —
433
+ accepts a new GCI normally. "This concept is published" is a reason you can't *rewrite* its GCI,
434
+ never a reason you can't *add* one. There's also no `--definition-status`: a GCI is a `SubClassOf`
435
+ axiom by construction and has no primitive/fully-defined distinction.
436
+
437
+ Removing a GCI is still whole-axiom only — see the `update-gci-axiom` note under role groups above.
438
+
439
+ ## Redundant stated Is-a relationships
440
+
441
+ Adding a new stated `Is a` (`116680003`) parent to a concept that already has a broader stated
442
+ parent — e.g. after minting a new intermediate concept and pointing an existing one at it as an
443
+ additional parent — commonly triggers: `Concept should not contain any redundantly stated IsA
444
+ relationships`, because the old, broader parent is now a direct or indirect ancestor of the new,
445
+ more specific one. Resolve it immediately rather than leaving it as residue:
446
+
447
+ 1. `get-concept` and find the redundant `Is a` entry inside `classAxioms[0].relationships[]` (the
448
+ warning names both the redundant parent and the more-specific one making it redundant — it's
449
+ the `groupId: 0` `Is a` relationship whose `target` is the broader, redundant parent). Note its
450
+ array index and the axiom's `axiomId`.
451
+ 2. Check **that specific relationship's own `effectiveTime`/`released` flag** — not just the
452
+ axiom-level one; see "Removing a relationship — including from a published axiom" above for why
453
+ they're gated independently. An axiom can show `released: true` overall while an individual
454
+ relationship inside it (e.g. the parent you just added this session) is still `released: false`.
455
+ - That relationship's own `effectiveTime` is unset → `authoring-cli remove-relationship --id
456
+ <id> --axiom-id <axiomId> --relationship-index <N>` removes just that one relationship
457
+ cleanly, in one call, **regardless of whether the axiom itself has been released** — prefer
458
+ this over rewriting the whole axiom.
459
+ - Else (that specific relationship has itself been versioned) → also try `update-axiom` if the
460
+ *whole axiom* has never been versioned (rewrite the full list with the redundant parent
461
+ dropped); if the axiom is genuinely versioned too, both commands fail with HTTP 409. Leave both
462
+ stated parents in place and accept the warning — a released/versioned relationship shouldn't be
463
+ force-edited; this is expected residue for CLI-only authoring, resolved by a human in the
464
+ interactive editor at the next release cycle, not a bug to work around.
465
+ 3. Re-run `validate-concept --id <id>` to confirm the warning cleared.
466
+
467
+ ## Deleting a concept
468
+
469
+ `delete-concept --id <SCTID>` is not the first step of a deletion — it's the last. It removes the
470
+ concept outright, with no inactivation record and no historical association, so anything still
471
+ pointing at it is left referring to something that no longer exists. The CLI does not check for
472
+ that, and the save that created the dangling reference has usually already succeeded elsewhere, so
473
+ nothing surfaces the breakage at delete time.
474
+
475
+ `delete-concept` rejects a versioned concept on its own, before issuing the DELETE, so there's no
476
+ need to pre-check that — but read `effectiveTime` off the first `get-concept` you make anyway, and
477
+ read it *before* starting the cleanup below. The cleanup writes to other concepts; discovering
478
+ only afterwards that the deletion can't proceed leaves you having re-parented children away from a
479
+ concept that's staying, and having stripped retrofits that should have stayed.
480
+
481
+ ### 1. Find everything that references it — no single query finds all of it
482
+
483
+ Two distinct kinds of reference, and the obvious query for each has a blind spot:
484
+
485
+ - **Attribute references** (`Finding site`, `Procedure site`, `Associated morphology`, …):
486
+ `search-concepts --ecl "*:*=<SCTID>"` finds these. It does **not** find `Is a` children.
487
+ - **Subtype children** (a stated `Is a` pointing at the concept): `search-concepts --ecl
488
+ "<<SCTID>"` reads the *inferred* view, so it misses a child whose stated parent was added since
489
+ the last classification — exactly the situation right after authoring.
490
+
491
+ So run both, and then close the gap with an edit-based sweep: a concept that has never been
492
+ released can only be referenced by something edited on the same branch, so every candidate appears
493
+ in `review-concepts`. Fetch each ID from its `concepts` array with `get-concept` and scan
494
+ `classAxioms[].relationships[].target.conceptId` for your target. (If the concept has been promoted
495
+ beyond the task branch, widen that sweep to the project branch — the task's own review list won't
496
+ see a referrer edited on a sibling task.)
497
+
498
+ ### 2. Deal with every reference before deleting anything
499
+
500
+ Never delete first and repair after — a dangling reference in a saved axiom is harder to find than
501
+ a reference you're looking straight at.
502
+
503
+ - **Children must be re-parented, not orphaned.** Decide their new parent deliberately: usually the
504
+ concept that supersedes the one being deleted, or failing that the deleted concept's own parent,
505
+ so the child doesn't silently jump up the hierarchy. Retarget with `update-axiom`, rewriting the
506
+ full relationship list with only that `Is a` target changed. Dropping the `Is a` outright is only
507
+ right when the child has other parents that already place it correctly — check, don't assume.
508
+ - **Attribute references** get retargeted the same way, onto whichever concept now carries the
509
+ meaning.
510
+ - **A retrofitted `Is a` added to an existing published concept** (the common case when the
511
+ now-unwanted concept was minted as a new parent for existing content) is removed, not retargeted:
512
+ `remove-relationship --id <existingId> --axiom-id <axiomId> --relationship-index <N>`. Its axiom
513
+ will usually be `released: true` while the retrofit relationship inside it is not, and
514
+ `remove-relationship` gates on the relationship's own `effectiveTime` — this is exactly the case
515
+ where `update-axiom` fails with 409 and `remove-relationship` succeeds. See "Removing a
516
+ relationship — including from a published axiom" above.
517
+ - **A referrer that is itself being deleted** needs nothing — just delete it first.
518
+
519
+ ### 3. Delete in dependency order
520
+
521
+ Deepest dependents first: clinical findings and disorders before the anatomy sites they're sited
522
+ on, children before parents. If a concept still has a live referrer when you delete it, you've
523
+ skipped a step in check 1.
524
+
525
+ ### 4. Clean up after
526
+
527
+ - Re-validate with `validate-review-concepts`, which covers every concept with pending stated
528
+ changes, including the ones you edited on the way to the delete.
529
+ - Re-classify — deletions and axiom edits both change the stated form, so the inferred view is
530
+ stale until you do. After the save, `review-concepts`'s `conceptsClassified` array shows which
531
+ concepts the classification actually rewrote, which is a useful confirmation that the re-parenting
532
+ landed the way you intended.
533
+ - The deleted concept keeps appearing in `review-concepts` indefinitely — the branch's traceability
534
+ log records that it changed, and that's permanent. It's reported as `"deleted": true`, and
535
+ `validate-review-concepts` skips those entries, so this needs no handling on your part.
536
+
537
+ ### Delete or inactivate?
538
+
539
+ `delete-concept` erases; `inactivate-concept --id <SCTID> --indicator <value>
540
+ [--association-refset <id> --association-target <SCTID>]` retires the concept while leaving it
541
+ resolvable, with a historical association pointing consumers at its replacement. Deleting is right
542
+ for content that never left the authoring branch — a mistake nobody outside has seen. Anything that
543
+ has been released must be inactivated, and the association target matters: it's the only signal a
544
+ downstream implementer gets about what to use instead.
545
+
546
+ The same reference checks apply either way. Inactivation doesn't dangle references the way deletion
547
+ does, but a still-active concept whose `Finding site` points at an inactive concept is its own
548
+ validation problem — check 1 is worth running before either command.
549
+
550
+ ## Generating a concept structurally parallel to an existing one
551
+
552
+ A common authoring task, especially at scale: mint a new concept whose defining axiom is identical
553
+ to an existing source concept's except for one substituted attribute value — a different
554
+ anatomical site, laterality, substance, or similar. (For a worked example of this pattern applied
555
+ across a large source list, see `references/batch-authoring.md`.)
556
+
557
+ 1. Fetch the source's **real** defining axiom via `get-concept` — not a rendering or a note from an
558
+ earlier session; it may have changed. Identify exactly which relationship(s) carry the attribute
559
+ you're substituting (for a site swap: Finding site `363698007`, Procedure site `363704007`,
560
+ Procedure site - Direct `405813007`, Procedure site - Indirect `405814001`). Copy everything else
561
+ in the axiom — morphology, occurrence, method, due-to, the top-level `Is a` — verbatim.
562
+ 2. Verify the substituted value's target concept already exists via a live `search-concepts` with
563
+ an **exact** match check on the FSN, not a fuzzy hit and not a static/hardcoded mapping table —
564
+ terminology content drifts and a stale local table will confidently point you at the wrong
565
+ concept, or one that's been superseded. Not found → don't guess a new label; either recurse
566
+ (fetch *that* value's own axiom and substitute one level further down) or treat it as genuinely
567
+ out of scope (new content needs to be minted first, a separate, non-mechanical task).
568
+ 3. **`definitionStatus` inheritance matters more than it looks.** Match the source: `FULLY_DEFINED`
569
+ source → `FULLY_DEFINED` new concept, which gets the source auto-classified as a subtype with no
570
+ manual retrofit needed. `PRIMITIVE` source → `PRIMITIVE` new concept, which needs the manual
571
+ retrofit below — primitive-to-primitive subsumption never auto-infers.
572
+ 4. If the new concept is `PRIMITIVE`, retrofit the source: `authoring-cli add-relationship --id
573
+ <sourceId> --type 116680003 --target <newId> --group 0` adds the new concept as a further stated
574
+ parent (not a replacement) on the original source. This commonly triggers the redundant-Is-a
575
+ warning above — resolve it now, don't leave it for later.
576
+ 5. Before minting anything, sanity-check that naive substitution actually holds:
577
+ - **Compound words**: the substituted term might be glued into a single word in some contexts
578
+ (e.g. "...nail" as one word), where substituting the phrase produces a nonsense concatenation.
579
+ - **Idioms**: some source concepts are named clinical entities, not compositional references to
580
+ their attribute value, even though that attribute happens to swap cleanly on paper — the
581
+ substituted result may not be an attested or sensible concept at all.
582
+ - **Cardinality**: a singular source concept doesn't necessarily have a coherent "multiple"
583
+ counterpart, and a substituted value might not have the same cardinality as the original (e.g.
584
+ a body part that exists exactly once, substituted in for one that exists in pairs).
585
+ When any of these apply, that candidate needs a human/judgment call, not mechanical generation.
586
+
587
+ ## Classification
588
+
589
+ `authoring-cli classify` is self-healing, not a plain "always start a new job" call: before
590
+ starting anything, it checks the branch's *current* classification state and reacts to what's
591
+ actually there —
592
+
593
+ - Already `RUNNING`/`BUILDING`/`SCHEDULED`/`QUEUED` → attaches to that job and waits on it, rather
594
+ than starting a second one (this happens regardless of whether you passed `--wait` yourself —
595
+ finding an unresolved job in progress means it needs resolving, not a fire-and-forget response
596
+ about a different, about-to-be-started job).
597
+ - Already `COMPLETED` but not yet saved → skips starting entirely and accepts it immediately.
598
+ - `SAVED`/`STALE`/`SAVE_FAILED`/never run → nothing pending; starts a fresh job exactly as before
599
+ (fire-and-forget unless you pass `--wait`).
600
+
601
+ This exists because the naive version — unconditionally POSTing to start on every call — silently
602
+ spawned a redundant second ELK run in practice: a completed-but-unsaved job does **not** block a
603
+ new start the way a genuinely running one does, so calling `classify` again to "check on" a job
604
+ that had already finished just started a *different* one instead, with no error to signal it.
605
+
606
+ `--wait` polls on a tightening schedule rather than a flat interval
607
+ (`buildClassificationPollSchedule()` in `src/core/actions/classification.ts`): skip the first 90s
608
+ (classification normally finishes in ~2 minutes, so nothing checked that early is realistically
609
+ done), then check every 10s for 30s, then every 5s. That schedule sums to exactly 3 minutes, which
610
+ is `classify`'s default `--timeout` too. Once the schedule is exhausted, polling keeps going at its
611
+ final 5s interval until your own `--timeout` budget elapses, so pass a larger one (e.g. `--timeout
612
+ 1200`) for a known-large branch where a full-edition ELK run genuinely takes 10-20+ minutes; the
613
+ default of 180 is sized for the common case, not a hard ceiling. Each scheduled tick also races a
614
+ real-time STOMP push, so a completion usually wakes the wait almost immediately rather than at the
615
+ next nominal tick.
616
+
617
+ For a pure status check with no side effects at all — no start, no accept, just "what's the
618
+ current job and status" — use `authoring-cli classification-status` instead. It's safe to call
619
+ anytime, including while you're unsure whether something is already running, and is the right tool
620
+ when you just want to look before deciding whether to call `classify` at all.
621
+
622
+ `Classification results NOT saved: Timed out waiting for classification results to save` used to
623
+ be printed on *every* `--wait` run, including ones that saved perfectly — the save-status poll was
624
+ hitting a URL that always 404'd, so it could never observe the save it had just requested. That's
625
+ fixed: the poll now reads the same resource the save was PUT to, so the message means what it says
626
+ and `Classification results accepted and saved.` is the normal outcome.
627
+
628
+ Treat a save timeout as a real problem now rather than noise, but still confirm before acting on
629
+ it — `classification-status` reports the job's current status directly, and a genuinely saved
630
+ classification shows on an affected `FULLY_DEFINED` concept as a `get-concept` `relationships[]`
631
+ entry with `typeId == "116680003"` and `characteristicType == "INFERRED_RELATIONSHIP"`.
632
+
633
+ A `--wait` run logs each status transition and logs when a real STOMP push (rather than a poll
634
+ tick) woke it, so a long wait is distinguishable from a hung one while it's still running. Silence
635
+ between those lines is normal: classification legitimately takes minutes.
636
+
637
+ After classifying, spot-check bidirectionally: a new/changed concept's inferred descendants should
638
+ include whatever it was meant to subsume, and those concepts should show it among their own
639
+ inferred `Is a` parents.
640
+
641
+ ## Task-level validation (`validate-task`)
642
+
643
+ Like `classify`, `validate-task` checks the task's current validation status before starting
644
+ anything — two validations running concurrently against the same task is pure waste, not a way to
645
+ get a faster result. If it finds one already `RUNNING`/`QUEUED`/`SCHEDULED`, it attaches to and
646
+ waits on that one instead of starting a second, **regardless of whether you passed `--wait`
647
+ yourself** — the same reasoning as `classify`'s handling of an already-running classification (see
648
+ above): finding an unresolved run in progress means it needs resolving, not a fire-and-forget
649
+ response about a different run you're about to start on top of it.
650
+
651
+ Task validation (RVF) routinely takes ~10 minutes or more — an order of magnitude longer than
652
+ classification's ~2 minutes — so `validate-task --wait` polls on its own, much longer backed-off
653
+ schedule rather than classification's (`buildValidationPollSchedule()`, same file): skip the first
654
+ 5 minutes entirely, then check once a minute for 5 minutes, then every 30s for 5 more (15 minutes
655
+ total, also the default `--timeout`). Pass a larger `--timeout` if you know a given branch
656
+ routinely takes longer than that.
657
+
658
+ For checking on a long validation run without blocking a whole tool call for up to 15 minutes, use
659
+ `authoring-cli validation-status` instead — a pure read-only check (no start, no wait) that reports
660
+ the task's current `latestValidationStatus` directly. Prefer this over `--wait` when you have other
661
+ work to do in the meantime; call it again later rather than holding a blocking call open.
662
+
663
+ ## Validating many concepts efficiently
664
+
665
+ ```
666
+ authoring-cli validate-review-concepts
667
+ ```
668
+
669
+ That's the end-of-session check: it validates every concept with pending *stated* changes and
670
+ prints a per-concept result plus a tally, exiting non-zero if anything has issues. It reads the
671
+ same list `review-concepts` puts in its `concepts` array, so it covers exactly what you edited —
672
+ and it handles the two things that make a hand-rolled loop over those IDs go wrong: it never
673
+ touches the `conceptsClassified` bucket (concepts a *previous* classification's inferred-
674
+ relationship side effects touched, not your edits), and it skips concepts deleted on this branch
675
+ instead of reporting their 404s as failures. `--json` gives the same data structured.
676
+
677
+ Don't reach for the whole-branch `validate-task` here — it's far slower and mixes in unrelated
678
+ concepts elsewhere on the same branch, making it harder to tell which warnings are actually yours.
679
+ The names are deliberately distinct: `validate-task` validates the entire task branch (an async
680
+ job, like `classify`); `validate-concept` is a synchronous, read-only check of a single concept;
681
+ `validate-review-concepts` runs that per-concept check across your pending edits.
682
+
683
+ ## Large multi-session batches
684
+
685
+ Generating many structurally-parallel concepts from a large source list (tens to thousands of
686
+ rows) is its own kind of task: it needs a persistent, resumable tracker so no session reprocesses
687
+ or loses track of prior work, and a deliberate batch size per session so everything created gets
688
+ fully validated and classified before moving on rather than accumulating unverified changes. See
689
+ `references/batch-authoring.md` for that methodology.