@kaddo/cli 3.90.2 → 3.91.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.
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>admin</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-CJ_ZkVBF.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/assets/index-DNkI-1xG.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
|
@@ -366,10 +366,21 @@ function assertExternalId(externalId) {
|
|
|
366
366
|
throw new CoreError("INVALID_EXTERNAL_ID", "Invalid external work item identifier.");
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
|
+
function assertIntegrationId(id) {
|
|
370
|
+
if (!id || id.includes("..") || id.includes("/") || id.includes("\\") || id.startsWith(".") || !/^[a-z0-9][a-z0-9._-]*$/i.test(id)) {
|
|
371
|
+
throw new CoreError("INVALID_INTEGRATION_ID", "Invalid integration identifier.");
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
function assertSecretName(name) {
|
|
375
|
+
if (!name || name.includes("..") || name.includes("/") || name.includes("\\") || !/^[a-zA-Z0-9_-]+$/.test(name)) {
|
|
376
|
+
throw new CoreError("INVALID_SECRET_NAME", "Invalid secret name.");
|
|
377
|
+
}
|
|
378
|
+
}
|
|
369
379
|
function getIntegrations(dir) {
|
|
370
380
|
return coreListIntegrations(dir);
|
|
371
381
|
}
|
|
372
382
|
async function getIntegrationStatus(dir, id) {
|
|
383
|
+
assertIntegrationId(id);
|
|
373
384
|
try {
|
|
374
385
|
return await coreVerifyIntegration(dir, id);
|
|
375
386
|
} catch (err) {
|
|
@@ -377,6 +388,7 @@ async function getIntegrationStatus(dir, id) {
|
|
|
377
388
|
}
|
|
378
389
|
}
|
|
379
390
|
async function getExternalWorkItems(dir, id, opts) {
|
|
391
|
+
assertIntegrationId(id);
|
|
380
392
|
try {
|
|
381
393
|
return await coreListExternalWorkItems(dir, id, { cursor: opts.cursor, pageSize: opts.pageSize, filters: opts.filters });
|
|
382
394
|
} catch (err) {
|
|
@@ -384,6 +396,7 @@ async function getExternalWorkItems(dir, id, opts) {
|
|
|
384
396
|
}
|
|
385
397
|
}
|
|
386
398
|
async function getExternalWorkItemDetail(dir, id, externalId) {
|
|
399
|
+
assertIntegrationId(id);
|
|
387
400
|
assertExternalId(externalId);
|
|
388
401
|
try {
|
|
389
402
|
return await coreGetExternalWorkItem(dir, id, externalId);
|
|
@@ -392,6 +405,7 @@ async function getExternalWorkItemDetail(dir, id, externalId) {
|
|
|
392
405
|
}
|
|
393
406
|
}
|
|
394
407
|
async function previewIntegrationImport(dir, id, externalId, opts) {
|
|
408
|
+
assertIntegrationId(id);
|
|
395
409
|
assertExternalId(externalId);
|
|
396
410
|
try {
|
|
397
411
|
return await corePreviewImport(dir, id, externalId, { type: opts.type });
|
|
@@ -400,6 +414,7 @@ async function previewIntegrationImport(dir, id, externalId, opts) {
|
|
|
400
414
|
}
|
|
401
415
|
}
|
|
402
416
|
async function importIntegrationWorkItem(dir, id, externalId, opts) {
|
|
417
|
+
assertIntegrationId(id);
|
|
403
418
|
assertExternalId(externalId);
|
|
404
419
|
try {
|
|
405
420
|
return await coreImportExternalWorkItem(dir, id, externalId, { type: opts.type });
|
|
@@ -409,6 +424,7 @@ async function importIntegrationWorkItem(dir, id, externalId, opts) {
|
|
|
409
424
|
}
|
|
410
425
|
}
|
|
411
426
|
function getIntegrationDetail(dir, id) {
|
|
427
|
+
assertIntegrationId(id);
|
|
412
428
|
try {
|
|
413
429
|
return coreGetIntegration(dir, id);
|
|
414
430
|
} catch (err) {
|
|
@@ -416,6 +432,7 @@ function getIntegrationDetail(dir, id) {
|
|
|
416
432
|
}
|
|
417
433
|
}
|
|
418
434
|
async function getIntegrationSecretStatusAdmin(dir, id) {
|
|
435
|
+
assertIntegrationId(id);
|
|
419
436
|
try {
|
|
420
437
|
return await coreGetIntegrationSecretStatus(dir, id);
|
|
421
438
|
} catch (err) {
|
|
@@ -433,6 +450,7 @@ function createIntegrationAdmin(dir, body) {
|
|
|
433
450
|
}
|
|
434
451
|
}
|
|
435
452
|
function updateIntegrationAdmin(dir, id, body) {
|
|
453
|
+
assertIntegrationId(id);
|
|
436
454
|
try {
|
|
437
455
|
return coreUpdateIntegration(dir, id, body);
|
|
438
456
|
} catch (err) {
|
|
@@ -440,6 +458,7 @@ function updateIntegrationAdmin(dir, id, body) {
|
|
|
440
458
|
}
|
|
441
459
|
}
|
|
442
460
|
function deleteIntegrationAdmin(dir, id) {
|
|
461
|
+
assertIntegrationId(id);
|
|
443
462
|
try {
|
|
444
463
|
coreDeleteIntegration(dir, id);
|
|
445
464
|
} catch (err) {
|
|
@@ -447,6 +466,7 @@ function deleteIntegrationAdmin(dir, id) {
|
|
|
447
466
|
}
|
|
448
467
|
}
|
|
449
468
|
function enableIntegrationAdmin(dir, id) {
|
|
469
|
+
assertIntegrationId(id);
|
|
450
470
|
try {
|
|
451
471
|
return coreEnableIntegration(dir, id);
|
|
452
472
|
} catch (err) {
|
|
@@ -454,6 +474,7 @@ function enableIntegrationAdmin(dir, id) {
|
|
|
454
474
|
}
|
|
455
475
|
}
|
|
456
476
|
function disableIntegrationAdmin(dir, id) {
|
|
477
|
+
assertIntegrationId(id);
|
|
457
478
|
try {
|
|
458
479
|
return coreDisableIntegration(dir, id);
|
|
459
480
|
} catch (err) {
|
|
@@ -461,6 +482,8 @@ function disableIntegrationAdmin(dir, id) {
|
|
|
461
482
|
}
|
|
462
483
|
}
|
|
463
484
|
async function setIntegrationSecretAdmin(dir, id, secretName, value) {
|
|
485
|
+
assertIntegrationId(id);
|
|
486
|
+
assertSecretName(secretName);
|
|
464
487
|
try {
|
|
465
488
|
await coreSetIntegrationSecret(dir, id, secretName, value);
|
|
466
489
|
} catch (err) {
|
|
@@ -468,6 +491,8 @@ async function setIntegrationSecretAdmin(dir, id, secretName, value) {
|
|
|
468
491
|
}
|
|
469
492
|
}
|
|
470
493
|
async function removeIntegrationSecretAdmin(dir, id, secretName) {
|
|
494
|
+
assertIntegrationId(id);
|
|
495
|
+
assertSecretName(secretName);
|
|
471
496
|
try {
|
|
472
497
|
await coreRemoveIntegrationSecret(dir, id, secretName);
|
|
473
498
|
} catch (err) {
|
|
@@ -482,6 +507,7 @@ async function discoverExternalWorkItemsAdmin(dir, opts) {
|
|
|
482
507
|
}
|
|
483
508
|
}
|
|
484
509
|
function getIntegrationFiltersAdmin(dir, id) {
|
|
510
|
+
assertIntegrationId(id);
|
|
485
511
|
try {
|
|
486
512
|
return coreGetIntegrationFilters(dir, id);
|
|
487
513
|
} catch (err) {
|
|
@@ -489,6 +515,7 @@ function getIntegrationFiltersAdmin(dir, id) {
|
|
|
489
515
|
}
|
|
490
516
|
}
|
|
491
517
|
function updateIntegrationFiltersAdmin(dir, id, filters) {
|
|
518
|
+
assertIntegrationId(id);
|
|
492
519
|
try {
|
|
493
520
|
return coreUpdateIntegrationFilters(dir, id, filters);
|
|
494
521
|
} catch (err) {
|
|
@@ -853,6 +880,9 @@ function statusForCode(code) {
|
|
|
853
880
|
return 409;
|
|
854
881
|
case "INVALID_INPUT":
|
|
855
882
|
case "INVALID_WORK_ITEM_ID":
|
|
883
|
+
case "INVALID_INTEGRATION_ID":
|
|
884
|
+
case "INVALID_SECRET_NAME":
|
|
885
|
+
case "INVALID_EXTERNAL_ID":
|
|
856
886
|
case "INVALID_TRANSITION":
|
|
857
887
|
return 400;
|
|
858
888
|
default:
|
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
|
-
|
|
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
|
-
|
|
21113
|
-
|
|
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.");
|