authoring-cli 0.1.11 → 0.1.13

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/HELP.md CHANGED
@@ -193,6 +193,7 @@ authoring-cli validate-review-concepts
193
193
 
194
194
  ### Session Management
195
195
  - Your session is stored in `~/.authoring-cli/session.json`
196
+ - Set `AUTHORING_CLI_HOME` to store the session under a different directory instead (e.g. a workspace-local path when `~` isn't accessible to the caller, such as a sandboxed agent) — the session file is then `$AUTHORING_CLI_HOME/session.json`
196
197
  - If you have multiple Chrome profiles, specify which one: `authoring-cli login --chrome-profile "Work Profile"`
197
198
  - If your session expires during use, you'll get a `401 Unauthorized` error — run `authoring-cli login` again
198
199
 
package/README.md CHANGED
@@ -79,6 +79,8 @@ Signed in as Jane Doe. (reused an existing Chrome session — no browser opened.
79
79
 
80
80
  `logout` deletes the locally stored session (`~/.authoring-cli/session.json`). It does not sign you out of IMS in Chrome, so a subsequent `login` will reuse that browser session.
81
81
 
82
+ By default the session lives under the real home directory (`os.homedir()`), which a sandboxed caller — an AI agent whose filesystem access is scoped to a workspace, for example — may not be able to read or write. Set `AUTHORING_CLI_HOME` to a workspace-local directory to store `session.json` there instead; every command reads/writes the session through the same path, so setting the variable once (e.g. exported alongside the agent's launch environment) covers `login`, `select-task`, and everything else with no per-command flag.
83
+
82
84
  Optional flags, for a deployment the named environments don't cover: `--ims-endpoint`, `--terminology-server-endpoint`, `--authoring-services-endpoint` (each overrides just that one value of the selected environment), `--cookie-name <name>` (override the IMS session cookie name), `--chrome-profile <name>` (target a specific Chrome profile by its display name or directory name if you have more than one).
83
85
 
84
86
  ## Pick a project and task
package/dist/index.js CHANGED
@@ -81,7 +81,7 @@ var http = __toESM(require("http"));
81
81
  var https = __toESM(require("https"));
82
82
  function requestJson(url, opts = {}) {
83
83
  const { method = "GET", cookie, body, headers = {}, timeoutMs = 15e3 } = opts;
84
- return new Promise((resolve2, reject) => {
84
+ return new Promise((resolve3, reject) => {
85
85
  let urlObj;
86
86
  try {
87
87
  urlObj = new URL(url);
@@ -137,7 +137,7 @@ function requestJson(url, opts = {}) {
137
137
  sessionExpired = !looksJson;
138
138
  }
139
139
  }
140
- resolve2({ statusCode, body: parsed, rawBody: data, sessionExpired });
140
+ resolve3({ statusCode, body: parsed, rawBody: data, sessionExpired });
141
141
  });
142
142
  }
143
143
  );
@@ -919,7 +919,7 @@ function cleanConceptForUpdate(concept) {
919
919
  return cleaned;
920
920
  }
921
921
  function sleep(ms) {
922
- return new Promise((resolve2) => setTimeout(resolve2, ms));
922
+ return new Promise((resolve3) => setTimeout(resolve3, ms));
923
923
  }
924
924
  function isBranchLockConflict(result) {
925
925
  if (result.statusCode !== 400) {
@@ -1542,13 +1542,10 @@ async function updateAxiom(cfg, input, currentTask) {
1542
1542
  if (!axiom) {
1543
1543
  return { statusCode: 404, body: { error: `Concept ${input.conceptId} has no class axiom ${input.axiomId}.` } };
1544
1544
  }
1545
- if (axiom.effectiveTime != null) {
1546
- return {
1547
- statusCode: 409,
1548
- body: { error: `Axiom ${input.axiomId} has effectiveTime ${String(axiom.effectiveTime)} set (already versioned) \u2014 cannot update.` }
1549
- };
1550
- }
1551
1545
  axiom.relationships = input.relationships;
1546
+ if (input.active != null) {
1547
+ axiom.active = input.active;
1548
+ }
1552
1549
  return null;
1553
1550
  });
1554
1551
  }
@@ -1566,13 +1563,10 @@ async function updateGciAxiom(cfg, input, currentTask) {
1566
1563
  if (!axiom) {
1567
1564
  return { statusCode: 404, body: { error: `Concept ${input.conceptId} has no GCI axiom ${input.axiomId}.` } };
1568
1565
  }
1569
- if (axiom.effectiveTime != null) {
1570
- return {
1571
- statusCode: 409,
1572
- body: { error: `GCI axiom ${input.axiomId} has effectiveTime ${String(axiom.effectiveTime)} set (already versioned) \u2014 cannot update.` }
1573
- };
1574
- }
1575
1566
  axiom.relationships = input.relationships;
1567
+ if (input.active != null) {
1568
+ axiom.active = input.active;
1569
+ }
1576
1570
  return null;
1577
1571
  });
1578
1572
  }
@@ -1684,13 +1678,21 @@ async function inactivateAxiom(cfg, input, currentTask) {
1684
1678
  body: { error: `Unpublished axiom ${input.axiomId} cannot be inactivated \u2014 it should be deleted instead (use delete-axiom).` }
1685
1679
  };
1686
1680
  }
1687
- const otherActiveCount = axioms.filter((a) => a !== axiom && a.active !== false).length;
1688
- if (otherActiveCount === 0) {
1681
+ const otherActiveAxioms = axioms.filter((a) => a !== axiom && a.active !== false);
1682
+ if (otherActiveAxioms.length === 0) {
1689
1683
  return {
1690
1684
  statusCode: 409,
1691
1685
  body: { error: `Concept ${input.conceptId} has only one active class axiom \u2014 a concept must retain at least one.` }
1692
1686
  };
1693
1687
  }
1688
+ if (otherActiveAxioms.every((a) => a.effectiveTime == null)) {
1689
+ return {
1690
+ statusCode: 409,
1691
+ body: {
1692
+ error: `Inactivating axiom ${input.axiomId} would leave concept ${input.conceptId} with only unpublished class axiom(s) active \u2014 this is the add-a-replacement-then-inactivate-the-original pattern, which produces two OwlAxiom rows where the real Authoring Workbench produces one. Use update-axiom to edit ${input.axiomId}'s content in place instead.`
1693
+ }
1694
+ };
1695
+ }
1694
1696
  axiom.active = false;
1695
1697
  return null;
1696
1698
  });
@@ -1869,7 +1871,7 @@ function relationshipsMatchAuthoringForm(current, target) {
1869
1871
  const groupsB = b.groups.map((g) => g.join("|")).sort();
1870
1872
  return groupsA.join("||") === groupsB.join("||");
1871
1873
  }
1872
- async function transformAxiom(cfg, input, currentTask, metadataCache = /* @__PURE__ */ new Map()) {
1874
+ async function transformAxiom(cfg, input, currentTask) {
1873
1875
  if (!input.conceptId) {
1874
1876
  return { statusCode: 400, body: { error: "conceptId is required." } };
1875
1877
  }
@@ -1889,48 +1891,11 @@ async function transformAxiom(cfg, input, currentTask, metadataCache = /* @__PUR
1889
1891
  );
1890
1892
  return { statusCode: 200, body: { conceptId: input.conceptId, axiomId, alreadyConformed: true } };
1891
1893
  }
1892
- const published = axiom.effectiveTime != null;
1893
- if (!published) {
1894
- return updateAxiom(
1895
- cfg,
1896
- { conceptId: input.conceptId, axiomId, relationships: targetRelationships, projectKey: taskContext.projectKey, taskKey: taskContext.taskKey },
1897
- currentTask
1898
- );
1899
- }
1900
- const addResult = await addAxiom(
1894
+ return updateAxiom(
1901
1895
  cfg,
1902
- {
1903
- conceptId: input.conceptId,
1904
- relationships: targetRelationships,
1905
- moduleId: typeof axiom.moduleId === "string" ? axiom.moduleId : void 0,
1906
- definitionStatus: axiom.definitionStatus,
1907
- projectKey: taskContext.projectKey,
1908
- taskKey: taskContext.taskKey
1909
- },
1910
- currentTask,
1911
- metadataCache
1912
- );
1913
- if (addResult.statusCode < 200 || addResult.statusCode >= 300) {
1914
- return addResult;
1915
- }
1916
- const inactivateResult = await inactivateAxiom(
1917
- cfg,
1918
- { conceptId: input.conceptId, axiomId, projectKey: taskContext.projectKey, taskKey: taskContext.taskKey },
1896
+ { conceptId: input.conceptId, axiomId, relationships: targetRelationships, projectKey: taskContext.projectKey, taskKey: taskContext.taskKey },
1919
1897
  currentTask
1920
1898
  );
1921
- if (inactivateResult.statusCode < 200 || inactivateResult.statusCode >= 300) {
1922
- return {
1923
- statusCode: inactivateResult.statusCode,
1924
- body: {
1925
- error: `Added the transformed axiom but failed to inactivate published axiom ${axiomId}: ${JSON.stringify(inactivateResult.body)}`,
1926
- addResult: addResult.body
1927
- }
1928
- };
1929
- }
1930
- return {
1931
- statusCode: inactivateResult.statusCode,
1932
- body: { replacedAxiomId: axiomId, addResult: addResult.body, inactivateResult: inactivateResult.body }
1933
- };
1934
1899
  }
1935
1900
  async function checkStatedParentsDefinitionStatus(cfg, input, currentTask) {
1936
1901
  if (!input.conceptId) {
@@ -2089,6 +2054,15 @@ async function inactivateGciAxiom(cfg, input, currentTask) {
2089
2054
  if (axiom.active === false) {
2090
2055
  return { statusCode: 409, body: { error: `GCI axiom ${input.axiomId} is already inactive.` } };
2091
2056
  }
2057
+ const otherActiveAxioms = axioms.filter((a) => a !== axiom && a.active !== false);
2058
+ if (otherActiveAxioms.length > 0 && otherActiveAxioms.every((a) => a.effectiveTime == null)) {
2059
+ return {
2060
+ statusCode: 409,
2061
+ body: {
2062
+ error: `Inactivating GCI axiom ${input.axiomId} would leave concept ${input.conceptId} with only unpublished GCI axiom(s) active \u2014 this is the add-a-replacement-then-inactivate-the-original pattern, which produces two OwlAxiom rows where the real Authoring Workbench produces one. Use update-gci-axiom to edit ${input.axiomId}'s content in place instead.`
2063
+ }
2064
+ };
2065
+ }
2092
2066
  axiom.active = false;
2093
2067
  return null;
2094
2068
  });
@@ -2499,11 +2473,11 @@ function matchesNotification(payload, match) {
2499
2473
  function waitForNotification(match) {
2500
2474
  let unsubscribe = () => {
2501
2475
  };
2502
- const promise = new Promise((resolve2) => {
2476
+ const promise = new Promise((resolve3) => {
2503
2477
  unsubscribe = onNotification((payload) => {
2504
2478
  if (matchesNotification(payload, match)) {
2505
2479
  unsubscribe();
2506
- resolve2(payload);
2480
+ resolve3(payload);
2507
2481
  }
2508
2482
  });
2509
2483
  });
@@ -2516,7 +2490,7 @@ var VALIDATION_RUNNING_STATUSES = ["QUEUED", "SCHEDULED", "RUNNING"];
2516
2490
  var BLOCKED_TASK_STATUSES = ["Promoted", "Completed"];
2517
2491
  var POLL_INTERVAL_MS = 5e3;
2518
2492
  function sleep2(ms) {
2519
- return new Promise((resolve2) => setTimeout(resolve2, ms));
2493
+ return new Promise((resolve3) => setTimeout(resolve3, ms));
2520
2494
  }
2521
2495
  async function pollUntil(check, intervalMs, maxAttempts) {
2522
2496
  let attempt = 0;
@@ -3271,8 +3245,8 @@ async function watchNotification(cfg, input, currentTask) {
3271
3245
  const timeoutSeconds = input.timeoutSeconds ?? DEFAULT_TIMEOUT_SECONDS;
3272
3246
  const wake = waitForNotification({ entityType: input.entityType, projectKey, taskKey, branchPath });
3273
3247
  let timer;
3274
- const timeout = new Promise((resolve2) => {
3275
- timer = setTimeout(() => resolve2({ kind: "timeout" }), timeoutSeconds * 1e3);
3248
+ const timeout = new Promise((resolve3) => {
3249
+ timer = setTimeout(() => resolve3({ kind: "timeout" }), timeoutSeconds * 1e3);
3276
3250
  });
3277
3251
  const notified = wake.promise.then((payload) => ({ kind: "notification", payload }));
3278
3252
  const result = await Promise.race([notified, timeout]);
@@ -3474,7 +3448,7 @@ async function readCookieValue(profileDirectory, host, cookieName) {
3474
3448
  }
3475
3449
  }
3476
3450
  function defaultSleep(ms) {
3477
- return new Promise((resolve2) => setTimeout(resolve2, ms));
3451
+ return new Promise((resolve3) => setTimeout(resolve3, ms));
3478
3452
  }
3479
3453
  async function captureFreshCookie(opts, deps = {}) {
3480
3454
  const platform = deps.platform ?? process.platform;
@@ -3537,7 +3511,7 @@ function waitForBrowserLogin(opts, deps = {}) {
3537
3511
  const captureCookie = deps.captureCookie ?? captureFreshCookie;
3538
3512
  const timeoutMs = opts.callbackTimeoutMs ?? 12e4;
3539
3513
  const profile = resolveProfile(opts.chromeProfile);
3540
- return new Promise((resolve2, reject) => {
3514
+ return new Promise((resolve3, reject) => {
3541
3515
  let settled = false;
3542
3516
  const finish = (fn) => {
3543
3517
  if (!settled) {
@@ -3554,7 +3528,7 @@ function waitForBrowserLogin(opts, deps = {}) {
3554
3528
  void (async () => {
3555
3529
  try {
3556
3530
  const value = await captureCookie({ profileDirectory: profile.directoryName, host: opts.host, cookieName });
3557
- finish(() => resolve2({ cookie: `${cookieName}=${value}` }));
3531
+ finish(() => resolve3({ cookie: `${cookieName}=${value}` }));
3558
3532
  } catch (err) {
3559
3533
  finish(() => reject(err));
3560
3534
  }
@@ -3571,7 +3545,7 @@ function waitForBrowserLogin(opts, deps = {}) {
3571
3545
  openChrome(loginUrl, profile.directoryName);
3572
3546
  });
3573
3547
  server.on("error", (err) => finish(() => reject(err)));
3574
- setTimeout(() => finish(() => resolve2(null)), timeoutMs);
3548
+ setTimeout(() => finish(() => resolve3(null)), timeoutMs);
3575
3549
  });
3576
3550
  }
3577
3551
 
@@ -3579,7 +3553,12 @@ function waitForBrowserLogin(opts, deps = {}) {
3579
3553
  var fs4 = __toESM(require("fs"));
3580
3554
  var os3 = __toESM(require("os"));
3581
3555
  var path3 = __toESM(require("path"));
3556
+ var HOME_OVERRIDE_ENV_VAR = "AUTHORING_CLI_HOME";
3582
3557
  function sessionDir() {
3558
+ const override = process.env[HOME_OVERRIDE_ENV_VAR];
3559
+ if (override && override.trim() !== "") {
3560
+ return path3.resolve(override);
3561
+ }
3583
3562
  return path3.join(os3.homedir(), ".authoring-cli");
3584
3563
  }
3585
3564
  function sessionPath() {
@@ -4560,7 +4539,14 @@ async function runUpdateAxiom(args) {
4560
4539
  const cfg = toBackendConfig(session);
4561
4540
  const result = await updateAxiom(
4562
4541
  cfg,
4563
- { conceptId: args.id, axiomId: args.axiomId, relationships, projectKey: args.project, taskKey: args.task },
4542
+ {
4543
+ conceptId: args.id,
4544
+ axiomId: args.axiomId,
4545
+ relationships,
4546
+ active: args.reactivate ? true : void 0,
4547
+ projectKey: args.project,
4548
+ taskKey: args.task
4549
+ },
4564
4550
  session.currentTask
4565
4551
  );
4566
4552
  const body = result.body;
@@ -4588,7 +4574,14 @@ async function runUpdateGciAxiom(args) {
4588
4574
  const cfg = toBackendConfig(session);
4589
4575
  const result = await updateGciAxiom(
4590
4576
  cfg,
4591
- { conceptId: args.id, axiomId: args.axiomId, relationships, projectKey: args.project, taskKey: args.task },
4577
+ {
4578
+ conceptId: args.id,
4579
+ axiomId: args.axiomId,
4580
+ relationships,
4581
+ active: args.reactivate ? true : void 0,
4582
+ projectKey: args.project,
4583
+ taskKey: args.task
4584
+ },
4592
4585
  session.currentTask
4593
4586
  );
4594
4587
  const body = result.body;
@@ -5779,19 +5772,20 @@ var COMMANDS = [
5779
5772
  },
5780
5773
  {
5781
5774
  name: "update-axiom",
5782
- usage: `update-axiom --id <SCTID> --axiom-id <axiomId> --relationships '[{"active":true,"groupId":0,"type":{"conceptId":"..."},"target":{"conceptId":"..."}}]' [--project <projectKey> --task <taskKey>] (only if never versioned; replaces the axiom's relationships wholesale)`,
5775
+ usage: `update-axiom --id <SCTID> --axiom-id <axiomId> --relationships '[{"active":true,"groupId":0,"type":{"conceptId":"..."},"target":{"conceptId":"..."}}]' [--reactivate] [--project <projectKey> --task <taskKey>] (replaces the axiom's relationships wholesale in place, same axiomId, published or not \u2014 Snowstorm clears the axiom's effectiveTime on save if it was versioned; --reactivate also sets the axiom active, for repairing one previously retired via inactivate-axiom)`,
5783
5776
  required: ["id", "axiom-id", "relationships"],
5784
5777
  run: (flags) => runUpdateAxiom({
5785
5778
  id: flags.id,
5786
5779
  axiomId: flags["axiom-id"],
5787
5780
  relationships: flags.relationships,
5781
+ reactivate: "reactivate" in flags,
5788
5782
  project: flags.project,
5789
5783
  task: flags.task
5790
5784
  })
5791
5785
  },
5792
5786
  {
5793
5787
  name: "add-axiom",
5794
- usage: `add-axiom --id <SCTID> --relationships '[{"active":true,"groupId":0,"type":{"conceptId":"116680003"},"target":{"conceptId":"..."}}]' [--definition-status PRIMITIVE|FULLY_DEFINED] [--module-id <moduleId>] [--project <projectKey> --task <taskKey>] (adds a new class axiom; use to replace a published axiom \u2014 add the replacement here, then inactivate-axiom the old one)`,
5788
+ usage: `add-axiom --id <SCTID> --relationships '[{"active":true,"groupId":0,"type":{"conceptId":"116680003"},"target":{"conceptId":"..."}}]' [--definition-status PRIMITIVE|FULLY_DEFINED] [--module-id <moduleId>] [--project <projectKey> --task <taskKey>] (appends a genuinely additional class axiom alongside the concept's existing one(s) \u2014 to change an existing axiom's content instead, use update-axiom in place, published or not)`,
5795
5789
  required: ["id", "relationships"],
5796
5790
  run: (flags) => runAddAxiom({
5797
5791
  id: flags.id,
@@ -5816,12 +5810,13 @@ var COMMANDS = [
5816
5810
  },
5817
5811
  {
5818
5812
  name: "update-gci-axiom",
5819
- usage: `update-gci-axiom --id <SCTID> --axiom-id <axiomId> --relationships '[{"active":true,"groupId":0,"type":{"conceptId":"..."},"target":{"conceptId":"..."}}]' [--project <projectKey> --task <taskKey>] (only if never versioned; replaces the axiom's relationships wholesale)`,
5813
+ usage: `update-gci-axiom --id <SCTID> --axiom-id <axiomId> --relationships '[{"active":true,"groupId":0,"type":{"conceptId":"..."},"target":{"conceptId":"..."}}]' [--reactivate] [--project <projectKey> --task <taskKey>] (replaces the axiom's relationships wholesale in place, same axiomId, published or not \u2014 Snowstorm clears the axiom's effectiveTime on save if it was versioned; --reactivate also sets the axiom active, for repairing one previously retired via inactivate-gci-axiom)`,
5820
5814
  required: ["id", "axiom-id", "relationships"],
5821
5815
  run: (flags) => runUpdateGciAxiom({
5822
5816
  id: flags.id,
5823
5817
  axiomId: flags["axiom-id"],
5824
5818
  relationships: flags.relationships,
5819
+ reactivate: "reactivate" in flags,
5825
5820
  project: flags.project,
5826
5821
  task: flags.task
5827
5822
  })
@@ -5914,7 +5909,7 @@ var COMMANDS = [
5914
5909
  },
5915
5910
  {
5916
5911
  name: "inactivate-axiom",
5917
- usage: "inactivate-axiom --id <SCTID> --axiom-id <axiomId> [--project <projectKey> --task <taskKey>] (only if published; for an unpublished axiom use delete-axiom instead; a concept must retain at least one active class axiom)",
5912
+ usage: "inactivate-axiom --id <SCTID> --axiom-id <axiomId> [--project <projectKey> --task <taskKey>] (only if published; for an unpublished axiom use delete-axiom instead; a concept must retain at least one active class axiom; 409s if every other active class axiom is itself unpublished \u2014 that combination is the add-a-replacement-then-inactivate anti-pattern, not a legitimate retirement; use update-axiom to edit this axiom in place instead)",
5918
5913
  required: ["id", "axiom-id"],
5919
5914
  run: (flags) => runInactivateAxiom({
5920
5915
  id: flags.id,
@@ -5925,7 +5920,7 @@ var COMMANDS = [
5925
5920
  },
5926
5921
  {
5927
5922
  name: "transform-axiom",
5928
- usage: "transform-axiom --id <SCTID> [--axiom-id <axiomId>] [--project <projectKey> --task <taskKey>] (rewrites a class axiom into the standard authoring form \u2014 Is-a to the proximal primitive parent(s) plus every currently-inferred attribute, per Snowstorm's own authoring-form computation; a never-versioned axiom is updated in place, a published one is replaced by adding the transformed axiom and inactivating the original \u2014 omit --axiom-id to target the concept's sole active class axiom)",
5923
+ usage: "transform-axiom --id <SCTID> [--axiom-id <axiomId>] [--project <projectKey> --task <taskKey>] (rewrites a class axiom into the standard authoring form \u2014 Is-a to the proximal primitive parent(s) plus every currently-inferred attribute, per Snowstorm's own authoring-form computation; updates the axiom in place, published or not \u2014 omit --axiom-id to target the concept's sole active class axiom)",
5929
5924
  required: ["id"],
5930
5925
  run: (flags) => runTransformAxiom({
5931
5926
  id: flags.id,
@@ -5958,7 +5953,7 @@ var COMMANDS = [
5958
5953
  },
5959
5954
  {
5960
5955
  name: "inactivate-gci-axiom",
5961
- usage: "inactivate-gci-axiom --id <SCTID> --axiom-id <axiomId> [--project <projectKey> --task <taskKey>] (only if published; for an unpublished GCI axiom use delete-gci-axiom instead; unlike inactivate-axiom there is no minimum-active-count guard, since GCI axioms are optional)",
5956
+ usage: "inactivate-gci-axiom --id <SCTID> --axiom-id <axiomId> [--project <projectKey> --task <taskKey>] (only if published; for an unpublished GCI axiom use delete-gci-axiom instead; unlike inactivate-axiom there is no minimum-active-count guard, since GCI axioms are optional; 409s if every other active GCI axiom is itself unpublished \u2014 use update-gci-axiom to edit this axiom in place instead)",
5962
5957
  required: ["id", "axiom-id"],
5963
5958
  run: (flags) => runInactivateGciAxiom({
5964
5959
  id: flags.id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authoring-cli",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "CLI for SNOMED CT authoring against authoring-services",
5
5
  "license": "Apache-2.0",
6
6
  "bin": {
@@ -424,31 +424,31 @@ common case — are unaffected; plain `add-relationship` is fine and simpler the
424
424
  (`remove-relationship` is also callable as `delete-relationship` — same command, whichever verb
425
425
  you reach for first.)
426
426
 
427
- `update-axiom` and `remove-relationship` are gated at **different levels**, and that difference is
428
- the whole story for editing an axiom that's already been released:
429
-
430
- - `update-axiom` checks the **axiom's own** `effectiveTime`. If the axiom has ever been versioned
431
- (`released: true` with a real `effectiveTime`, not just inherited from the concept), every call
432
- fails with HTTP 409 — it replaces `relationships` wholesale, so it refuses outright rather than
433
- risk silently changing a released axiom's meaning.
434
- - `remove-relationship` checks the **targeted relationship's own** `effectiveTime` only, never the
435
- axiom's. This mirrors the real Authoring Workbench: its "Remove Relationship" button re-saves the
436
- same axiom (same `axiomId`) with one relationship gone, regardless of whether that axiom has been
437
- released before — only the specific relationship being removed must itself never have been
438
- versioned.
439
-
440
- So: **removing one relationship from a published axiom is `remove-relationship`, not
441
- `update-axiom`.** Get the target's `relationshipId` (or its array index within that axiom) from
442
- `get-concept --axioms`, then:
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:
432
+
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`.
439
+
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:
443
442
 
444
443
  ```
445
444
  authoring-cli remove-relationship --id <SCTID> --axiom-id <axiomId> --relationship-id <relationshipId>
446
445
  ```
447
446
 
448
- If that specific relationship has its own `effectiveTime` set (it was independently versioned —
449
- uncommon, but possible for a relationship inside an otherwise-unversioned axiom edit history), the
450
- call 409s and there's no way to remove it via the CLI; that's expected residue, same as the fully-
451
- 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.
452
452
 
453
453
  ### Removing an entire role group
454
454
 
@@ -498,8 +498,8 @@ stated `Is a`) is excluded from matching unless you explicitly pass `--group-id
498
498
  pair that happens to match an ungrouped attribute could sweep up unrelated ungrouped relationships,
499
499
  including `Is a`, as collateral damage. And `remove-role-group` only targets `classAxioms`; a GCI
500
500
  role group still needs the `update-gci-axiom` workaround (rewrite the relationships list with that
501
- group's entries omitted), gated on the whole GCI axiom's own `effectiveTime` since there's no
502
- 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.
503
503
 
504
504
  Confirm with `authoring-cli validate-concept --id <SCTID>` afterward.
505
505
 
@@ -551,7 +551,16 @@ groups above. Retiring the axiom itself follows the same delete-vs-inactivate sp
551
551
  `delete-gci-axiom --id <SCTID> --axiom-id <axiomId>` 409s on a published one, `inactivate-gci-axiom
552
552
  --id <SCTID> --axiom-id <axiomId>` 409s on a never-versioned one. Unlike `inactivate-axiom`,
553
553
  `inactivate-gci-axiom` has no minimum-active-count guard — GCI axioms are optional, so a concept can
554
- 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.
555
564
 
556
565
  **Deciding *whether* and *how* to model with a GCI at all — for any concept type (disorder,
557
566
  procedure, observable, ...), not just this command's mechanics — is its own judgment call.** See
@@ -562,34 +571,60 @@ actually discriminate), how to shape the antecedent (genus + nexus + defining at
562
571
  role-group partition that silently changes an axiom's meaning if got wrong), and how to derive the
563
572
  axiom set from the terminology's own content rather than from theory alone.
564
573
 
565
- ### Replacing a published axiom
574
+ ### Editing a published axiom's content
566
575
 
567
- `update-axiom` and `delete-axiom` both refuse outright once an axiom's own `effectiveTime` is set —
568
- there is no in-place edit for a released axiom's content, by design (rewriting a versioned axiom's
569
- relationships, or removing it wholesale, risks silently changing what already shipped). "Replace"
570
- 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.
571
585
 
572
586
  ```
573
- authoring-cli add-axiom --id <SCTID> --relationships \
587
+ authoring-cli update-axiom --id <SCTID> --axiom-id <axiomId> --relationships \
574
588
  '[{"active":true,"groupId":0,"type":{"conceptId":"116680003"},"target":{"conceptId":"..."}},
575
589
  {"active":true,"groupId":1,"type":{"conceptId":"363698007"},"target":{"conceptId":"..."}}]'
590
+ ```
591
+
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.
576
611
 
577
- authoring-cli inactivate-axiom --id <SCTID> --axiom-id <oldAxiomId>
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":"..."}}]'
578
616
  ```
579
617
 
580
- Like `add-gci-axiom`, `add-axiom` has **no publication gate** — it appends a brand-new axiom, so a
581
- released concept accepts it normally. `inactivate-axiom` requires the axiom being retired to
582
- already be published (`effectiveTime` set) — setting `active: false` on a released axiom's row is
583
- the normal RF2 retirement path; a never-versioned one has nothing to retire and should be
584
- `delete-axiom`d instead. It also enforces that **at least one class axiom stays active**, so run
585
- `add-axiom` first: the concept must never be left without a stated definition, even momentarily
586
- 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**.
587
623
 
588
- The new axiom's `definitionStatus` defaults to `PRIMITIVE` regardless of what the axiom being
589
- replaced was. If the axiom you're retiring was the concept's `FULLY_DEFINED` one and the new axiom
590
- should take over that role, follow up with `set-definition-status --status FULLY_DEFINED
591
- --axiom-index <N>` (index into `classAxioms` from a fresh `get-concept --axioms` — `add-axiom`'s own
592
- 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).
593
628
 
594
629
  ### Collapsing an axiom to the standard authoring form
595
630
 
@@ -598,9 +633,9 @@ primitive parent(s) plus every currently-inferred attribute — the shape editor
598
633
  expects a primitive concept's stated definition to take, letting the classifier re-derive the more
599
634
  specific hierarchy instead of the axiom asserting it directly. It gets this shape from Snowstorm's
600
635
  own `GET .../authoring-form` (the same proximal-primitive-parent substitution the classifier itself
601
- uses), not a local reimplementation, then routes through exactly the mechanism above: `update-axiom`
602
- in place if the axiom has never been versioned, or `add-axiom` (carrying over the old axiom's
603
- `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.
604
639
 
605
640
  The one silent trap: **the target concept must already be classified**. `authoring-form` reads the
606
641
  concept's saved *inferred* relationships to do the substitution, not a live reasoner call — call it
@@ -609,9 +644,7 @@ it comes back with no parents and no attributes at all, which `transform-axiom`
609
644
  write as an axiom ("produced no relationships"). That error names the symptom, not the cause; if you
610
645
  see it, `classify --wait` the task first, then retry. If the axiom already matches authoring form,
611
646
  `transform-axiom` checks that before writing anything and reports `alreadyConformed: true` rather
612
- than reaching Snowstorm at all — the naive version of this reached `add-axiom` and let it 400 with
613
- "Active Concept should not have duplicate axioms" for a published axiom, which was a real but
614
- needless error to make the caller decode.
647
+ than reaching Snowstorm at all — avoiding a pointless rewrite-to-identical-content PUT.
615
648
 
616
649
  **`validate-concept`/`validate-review-concepts` deliberately don't run this check.** They're meant
617
650
  to be a quick, synchronous, single-concept (or per-concept-in-a-loop) check, and authoring-form
@@ -692,11 +725,10 @@ more specific one. Resolve it immediately rather than leaving it as residue:
692
725
  <id> --axiom-id <axiomId> --relationship-index <N>` removes just that one relationship
693
726
  cleanly, in one call, **regardless of whether the axiom itself has been released** — prefer
694
727
  this over rewriting the whole axiom.
695
- - Else (that specific relationship has itself been versioned) → try `update-axiom` if the *whole
696
- axiom* has never been versioned (rewrite the full list with the redundant parent dropped). If
697
- the axiom is genuinely versioned too, `update-axiom` 409s — fall back to "Replacing a published
698
- axiom" above: `add-axiom` with the full relationship list minus the redundant parent, then
699
- `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
700
732
  expected residue — the warning is real and resolvable in one CLI session.
701
733
  3. Re-run `validate-concept --id <id>` to confirm the warning cleared.
702
734
 
@@ -744,20 +776,17 @@ a reference you're looking straight at.
744
776
  - **Children must be re-parented, not orphaned.** Decide their new parent deliberately: usually the
745
777
  concept that supersedes the one being deleted, or failing that the deleted concept's own parent,
746
778
  so the child doesn't silently jump up the hierarchy. Retarget with `update-axiom`, rewriting the
747
- full relationship list with only that `Is a` target changed — or, if the child's axiom is itself
748
- versioned and `update-axiom` 409s, `add-axiom` with the corrected list followed by
749
- `inactivate-axiom` on the original (see "Replacing a published axiom" above). Dropping the `Is a`
750
- outright is only right when the child has other parents that already place it correctly — check,
751
- 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.
752
783
  - **Attribute references** get retargeted the same way, onto whichever concept now carries the
753
784
  meaning.
754
785
  - **A retrofitted `Is a` added to an existing published concept** (the common case when the
755
786
  now-unwanted concept was minted as a new parent for existing content) is removed, not retargeted:
756
- `remove-relationship --id <existingId> --axiom-id <axiomId> --relationship-index <N>`. Its axiom
757
- will usually be `released: true` while the retrofit relationship inside it is not, and
758
- `remove-relationship` gates on the relationship's own `effectiveTime` — this is exactly the case
759
- where `update-axiom` fails with 409 and `remove-relationship` succeeds. See "Removing a
760
- 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.
761
790
  - **A referrer that is itself being deleted** needs nothing — just delete it first.
762
791
 
763
792
  ### 3. Delete in dependency order
@@ -869,9 +898,17 @@ The same choice exists for a single class axiom too: `delete-axiom --id <SCTID>
869
898
  a never-versioned one — same guard pairing as concept/description. There's no indicator or
870
899
  association target at the axiom level; both commands instead also guard the concept's minimum: it
871
900
  must keep at least one class axiom (`delete-axiom` counts all of them) and, separately, at least
872
- one *active* one (`inactivate-axiom` counts only active ones). See "Replacing a published axiom"
873
- above for the add-axiom-then-inactivate-axiom sequence this feeds into when the goal is swapping an
874
- 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.
875
912
 
876
913
  ## Generating a concept structurally parallel to an existing one
877
914