@kaddo/cli 3.90.2 → 3.90.3

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/dist/core.js CHANGED
@@ -9398,6 +9398,7 @@ function buildRefinementHandoff(dir, workItemId) {
9398
9398
 
9399
9399
  // src/core/work-item-import.ts
9400
9400
  import crypto3 from "crypto";
9401
+ import fs4 from "fs";
9401
9402
  import matter8 from "gray-matter";
9402
9403
  var MAX_INPUT_BYTES = 102400;
9403
9404
  var LIFECYCLE_FIELDS = /* @__PURE__ */ new Set([
@@ -9546,6 +9547,12 @@ function findDuplicateByHash(dir, hash) {
9546
9547
  }
9547
9548
  return void 0;
9548
9549
  }
9550
+ function findExistingById(dir, id) {
9551
+ const items = discoverWorkItems(dir);
9552
+ const match = items.find((item) => (item.id || item.title) === id);
9553
+ if (!match) return void 0;
9554
+ return { workItemId: match.id || match.title, path: match.relPath, filePath: match.filePath };
9555
+ }
9549
9556
  function importWorkItem(dir, opts) {
9550
9557
  const content = opts.content;
9551
9558
  if (!content?.trim()) throw new ImportError("EMPTY_INPUT", "Import content is empty.");
@@ -9574,6 +9581,31 @@ function importWorkItem(dir, opts) {
9574
9581
  sourceHash,
9575
9582
  sourceFormat: parsed.format
9576
9583
  });
9584
+ const importedId = typeof parsed.candidateFields.id === "string" ? parsed.candidateFields.id.trim() : void 0;
9585
+ let replacedWorkItem;
9586
+ if (importedId && /^WI-\d+$/.test(importedId)) {
9587
+ const existing = findExistingById(dir, importedId);
9588
+ if (existing) {
9589
+ if (!opts.onConflict) {
9590
+ return {
9591
+ created: false,
9592
+ workItemId: existing.workItemId,
9593
+ path: existing.path,
9594
+ status: "draft",
9595
+ source: opts.source,
9596
+ sourceFormat: parsed.format,
9597
+ sourceHash,
9598
+ executed: false,
9599
+ conflict: { importedId, existingPath: existing.path },
9600
+ ...normalized.discardedFields.length > 0 ? { discardedFields: normalized.discardedFields } : {}
9601
+ };
9602
+ }
9603
+ if (opts.onConflict === "replace") {
9604
+ fs4.rmSync(existing.filePath, { force: true });
9605
+ replacedWorkItem = existing.workItemId;
9606
+ }
9607
+ }
9608
+ }
9577
9609
  const result = createWorkItem(dir, {
9578
9610
  intent: normalized.intent,
9579
9611
  type: normalized.type,
@@ -9595,7 +9627,8 @@ function importWorkItem(dir, opts) {
9595
9627
  sourceHash,
9596
9628
  executed: false,
9597
9629
  refinementHandoff,
9598
- ...normalized.discardedFields.length > 0 ? { discardedFields: normalized.discardedFields } : {}
9630
+ ...normalized.discardedFields.length > 0 ? { discardedFields: normalized.discardedFields } : {},
9631
+ ...replacedWorkItem ? { replacedWorkItem } : {}
9599
9632
  };
9600
9633
  }
9601
9634
  var ImportError = class extends Error {
@@ -11061,6 +11094,7 @@ export {
11061
11094
  enableIntegration,
11062
11095
  exists,
11063
11096
  findDuplicateByHash,
11097
+ findExistingById,
11064
11098
  findLinkedWorkItem,
11065
11099
  findSystemPaths,
11066
11100
  getAvailableIntegrationTypes,
package/dist/index.js CHANGED
@@ -20291,6 +20291,7 @@ async function runAdmin(opts = {}) {
20291
20291
 
20292
20292
  // src/core/work-item-import.ts
20293
20293
  import crypto3 from "crypto";
20294
+ import fs7 from "fs";
20294
20295
  import matter15 from "gray-matter";
20295
20296
 
20296
20297
  // src/core/work-items.ts
@@ -20988,6 +20989,12 @@ function findDuplicateByHash(dir, hash) {
20988
20989
  }
20989
20990
  return void 0;
20990
20991
  }
20992
+ function findExistingById(dir, id) {
20993
+ const items = discoverWorkItems(dir);
20994
+ const match = items.find((item) => (item.id || item.title) === id);
20995
+ if (!match) return void 0;
20996
+ return { workItemId: match.id || match.title, path: match.relPath, filePath: match.filePath };
20997
+ }
20991
20998
  function importWorkItem(dir, opts) {
20992
20999
  const content = opts.content;
20993
21000
  if (!content?.trim()) throw new ImportError("EMPTY_INPUT", "Import content is empty.");
@@ -21016,6 +21023,31 @@ function importWorkItem(dir, opts) {
21016
21023
  sourceHash,
21017
21024
  sourceFormat: parsed.format
21018
21025
  });
21026
+ const importedId = typeof parsed.candidateFields.id === "string" ? parsed.candidateFields.id.trim() : void 0;
21027
+ let replacedWorkItem;
21028
+ if (importedId && /^WI-\d+$/.test(importedId)) {
21029
+ const existing = findExistingById(dir, importedId);
21030
+ if (existing) {
21031
+ if (!opts.onConflict) {
21032
+ return {
21033
+ created: false,
21034
+ workItemId: existing.workItemId,
21035
+ path: existing.path,
21036
+ status: "draft",
21037
+ source: opts.source,
21038
+ sourceFormat: parsed.format,
21039
+ sourceHash,
21040
+ executed: false,
21041
+ conflict: { importedId, existingPath: existing.path },
21042
+ ...normalized.discardedFields.length > 0 ? { discardedFields: normalized.discardedFields } : {}
21043
+ };
21044
+ }
21045
+ if (opts.onConflict === "replace") {
21046
+ fs7.rmSync(existing.filePath, { force: true });
21047
+ replacedWorkItem = existing.workItemId;
21048
+ }
21049
+ }
21050
+ }
21019
21051
  const result = createWorkItem(dir, {
21020
21052
  intent: normalized.intent,
21021
21053
  type: normalized.type,
@@ -21037,7 +21069,8 @@ function importWorkItem(dir, opts) {
21037
21069
  sourceHash,
21038
21070
  executed: false,
21039
21071
  refinementHandoff,
21040
- ...normalized.discardedFields.length > 0 ? { discardedFields: normalized.discardedFields } : {}
21072
+ ...normalized.discardedFields.length > 0 ? { discardedFields: normalized.discardedFields } : {},
21073
+ ...replacedWorkItem ? { replacedWorkItem } : {}
21041
21074
  };
21042
21075
  }
21043
21076
  var ImportError = class extends Error {
@@ -21102,19 +21135,42 @@ async function runWorkItemImport(dir, fileOrText, opts) {
21102
21135
  process.exit(0);
21103
21136
  }
21104
21137
  }
21105
- const result = importWorkItem(dir, {
21138
+ let result = importWorkItem(dir, {
21106
21139
  content,
21107
21140
  source: "cli",
21108
21141
  type: opts.type,
21109
21142
  filePath: fileOrText
21110
21143
  });
21144
+ if (result.conflict) {
21145
+ const { importedId, existingPath } = result.conflict;
21146
+ log2.warn(`The imported content has id "${importedId}" which already exists at ${existingPath}.`);
21147
+ const resolution = await select2({
21148
+ message: `How should Kaddo handle this conflict?`,
21149
+ options: [
21150
+ { value: "new-id", label: "Assign a new consecutive ID", hint: "keeps the existing Work Item intact" },
21151
+ { value: "replace", label: `Delete ${importedId} and create the new one`, hint: "removes the existing file" }
21152
+ ]
21153
+ });
21154
+ result = importWorkItem(dir, {
21155
+ content,
21156
+ source: "cli",
21157
+ type: opts.type,
21158
+ filePath: fileOrText,
21159
+ onConflict: resolution
21160
+ });
21161
+ }
21111
21162
  if (!result.created) {
21112
- log2.warn(`Already imported as ${result.duplicateOf}.`);
21113
- outro2("No duplicate was created.");
21163
+ if (result.duplicateOf) {
21164
+ log2.warn(`Already imported as ${result.duplicateOf}.`);
21165
+ outro2("No duplicate was created.");
21166
+ }
21114
21167
  return;
21115
21168
  }
21116
21169
  log2.info(`Created ${result.workItemId} (Draft, needs refinement).`);
21117
21170
  log2.info(`Path: ${result.path}`);
21171
+ if (result.replacedWorkItem) {
21172
+ log2.warn(`Replaced existing Work Item ${result.replacedWorkItem}.`);
21173
+ }
21118
21174
  if (result.discardedFields?.length) {
21119
21175
  log2.warn(`Lifecycle fields discarded from import: ${result.discardedFields.join(", ")}`);
21120
21176
  log2.message("Kaddo always generates its own id and status \u2014 external values are ignored.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaddo/cli",
3
- "version": "3.90.2",
3
+ "version": "3.90.3",
4
4
  "description": "Knowledge Driven Development toolkit",
5
5
  "license": "MIT",
6
6
  "repository": {