@kaddo/cli 3.107.0 → 3.108.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.
- package/dist/core.js +329 -267
- package/dist/index.js +286 -257
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -1635,6 +1635,215 @@ function loadExternalCapsules(dir) {
|
|
|
1635
1635
|
return out;
|
|
1636
1636
|
}
|
|
1637
1637
|
|
|
1638
|
+
// src/core/initiative.ts
|
|
1639
|
+
import matter3 from "gray-matter";
|
|
1640
|
+
var INITIATIVES_DIR = "knowledge/delivery/initiatives";
|
|
1641
|
+
var INITIATIVE_STATES = [
|
|
1642
|
+
"candidate",
|
|
1643
|
+
"planned",
|
|
1644
|
+
"in-progress",
|
|
1645
|
+
"completed",
|
|
1646
|
+
"deferred",
|
|
1647
|
+
"cancelled"
|
|
1648
|
+
];
|
|
1649
|
+
var INITIATIVE_TRANSITIONS = {
|
|
1650
|
+
candidate: ["planned", "cancelled"],
|
|
1651
|
+
planned: ["in-progress", "deferred", "cancelled"],
|
|
1652
|
+
"in-progress": ["completed", "deferred", "cancelled"],
|
|
1653
|
+
deferred: ["planned", "cancelled"],
|
|
1654
|
+
completed: [],
|
|
1655
|
+
cancelled: []
|
|
1656
|
+
};
|
|
1657
|
+
var STATUS_SET = new Set(INITIATIVE_STATES);
|
|
1658
|
+
function isValidInitiativeStatus(s) {
|
|
1659
|
+
return STATUS_SET.has(s);
|
|
1660
|
+
}
|
|
1661
|
+
function isValidInitiativeTransition(from, to) {
|
|
1662
|
+
return INITIATIVE_TRANSITIONS[from].includes(to);
|
|
1663
|
+
}
|
|
1664
|
+
function toPosix2(p) {
|
|
1665
|
+
return p.replace(/\\/g, "/");
|
|
1666
|
+
}
|
|
1667
|
+
function optStr(v) {
|
|
1668
|
+
if (typeof v === "string" && v.trim()) return v.trim();
|
|
1669
|
+
if (typeof v === "number") return String(v);
|
|
1670
|
+
return void 0;
|
|
1671
|
+
}
|
|
1672
|
+
function strList(v) {
|
|
1673
|
+
if (!Array.isArray(v)) return [];
|
|
1674
|
+
return v.map((x) => typeof x === "string" ? x.trim() : String(x)).filter(Boolean);
|
|
1675
|
+
}
|
|
1676
|
+
function parseCandidates(data) {
|
|
1677
|
+
const raw = data.candidates;
|
|
1678
|
+
if (!Array.isArray(raw)) return [];
|
|
1679
|
+
const out = [];
|
|
1680
|
+
for (const entry of raw) {
|
|
1681
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
1682
|
+
const o = entry;
|
|
1683
|
+
const id = optStr(o.id);
|
|
1684
|
+
const title = optStr(o.title);
|
|
1685
|
+
if (!id || !title) continue;
|
|
1686
|
+
out.push({
|
|
1687
|
+
id,
|
|
1688
|
+
title,
|
|
1689
|
+
type: optStr(o.type),
|
|
1690
|
+
suggestedKnowledgeLevel: optStr(o.suggested_knowledge_level ?? o.knowledge_level),
|
|
1691
|
+
expectedValue: optStr(o.expected_value),
|
|
1692
|
+
notes: optStr(o.notes),
|
|
1693
|
+
sourceSignals: strList(o.source_signals),
|
|
1694
|
+
dependencies: strList(o.dependencies),
|
|
1695
|
+
materializedAs: optStr(o.materialized_as) ?? null
|
|
1696
|
+
});
|
|
1697
|
+
}
|
|
1698
|
+
return out;
|
|
1699
|
+
}
|
|
1700
|
+
function parseExternalLinks(data) {
|
|
1701
|
+
const raw = data.external_links;
|
|
1702
|
+
if (!Array.isArray(raw)) return [];
|
|
1703
|
+
const out = [];
|
|
1704
|
+
for (const entry of raw) {
|
|
1705
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
1706
|
+
const o = entry;
|
|
1707
|
+
const integration = optStr(o.integration);
|
|
1708
|
+
const externalId = optStr(o.external_id);
|
|
1709
|
+
if (!integration || !externalId) continue;
|
|
1710
|
+
out.push({
|
|
1711
|
+
integration,
|
|
1712
|
+
externalId,
|
|
1713
|
+
externalType: optStr(o.external_type),
|
|
1714
|
+
url: optStr(o.url),
|
|
1715
|
+
externalStatus: optStr(o.external_status)
|
|
1716
|
+
});
|
|
1717
|
+
}
|
|
1718
|
+
return out;
|
|
1719
|
+
}
|
|
1720
|
+
function parseInitiative(dir, filePath, raw) {
|
|
1721
|
+
let parsed;
|
|
1722
|
+
try {
|
|
1723
|
+
parsed = matter3(raw, {});
|
|
1724
|
+
} catch {
|
|
1725
|
+
return null;
|
|
1726
|
+
}
|
|
1727
|
+
const data = parsed.data;
|
|
1728
|
+
if (optStr(data.type) !== "initiative") return null;
|
|
1729
|
+
const id = optStr(data.id);
|
|
1730
|
+
if (!id) return null;
|
|
1731
|
+
const statusRaw = optStr(data.status) ?? "planned";
|
|
1732
|
+
const status = isValidInitiativeStatus(statusRaw) ? statusRaw : "planned";
|
|
1733
|
+
return {
|
|
1734
|
+
id,
|
|
1735
|
+
title: optStr(data.title) ?? id,
|
|
1736
|
+
status,
|
|
1737
|
+
horizon: optStr(data.horizon) ?? null,
|
|
1738
|
+
priority: optStr(data.priority) ?? null,
|
|
1739
|
+
knowledgeLevel: optStr(data.knowledge_level) ?? null,
|
|
1740
|
+
domains: strList(data.domains),
|
|
1741
|
+
relatedCapabilities: strList(data.related_capabilities),
|
|
1742
|
+
source: optStr(data.source) ?? null,
|
|
1743
|
+
sourceId: optStr(data.source_id) ?? null,
|
|
1744
|
+
createdAt: optStr(data.created_at) ?? null,
|
|
1745
|
+
externalLinks: parseExternalLinks(data),
|
|
1746
|
+
candidates: parseCandidates(data),
|
|
1747
|
+
filePath,
|
|
1748
|
+
relPath: toPosix2(filePath).startsWith(toPosix2(dir) + "/") ? toPosix2(filePath).slice(toPosix2(dir).length + 1) : toPosix2(filePath),
|
|
1749
|
+
body: parsed.content.trim(),
|
|
1750
|
+
rawFrontmatter: data
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
function discoverInitiatives(dir) {
|
|
1754
|
+
const iniDir = join(dir, INITIATIVES_DIR);
|
|
1755
|
+
if (!exists(iniDir)) return [];
|
|
1756
|
+
const out = [];
|
|
1757
|
+
for (const entry of readDir(iniDir)) {
|
|
1758
|
+
if (!entry.endsWith(".md")) continue;
|
|
1759
|
+
const full = join(iniDir, entry);
|
|
1760
|
+
if (!isFile(full)) continue;
|
|
1761
|
+
const ini = parseInitiative(dir, full, readFile(full));
|
|
1762
|
+
if (ini) out.push(ini);
|
|
1763
|
+
}
|
|
1764
|
+
return out.sort((a, b) => a.id.localeCompare(b.id));
|
|
1765
|
+
}
|
|
1766
|
+
function getInitiative(dir, id) {
|
|
1767
|
+
const want = id.trim().toLowerCase();
|
|
1768
|
+
return discoverInitiatives(dir).find((i) => i.id.toLowerCase() === want) ?? null;
|
|
1769
|
+
}
|
|
1770
|
+
function nextInitiativeId(dir) {
|
|
1771
|
+
const iniDir = join(dir, INITIATIVES_DIR);
|
|
1772
|
+
let max = 0;
|
|
1773
|
+
if (exists(iniDir)) {
|
|
1774
|
+
for (const entry of readDir(iniDir)) {
|
|
1775
|
+
const m = entry.match(/INI-(\d+)/);
|
|
1776
|
+
if (m) max = Math.max(max, parseInt(m[1], 10));
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
return `INI-${String(max + 1).padStart(3, "0")}`;
|
|
1780
|
+
}
|
|
1781
|
+
function workItemBelongsToInitiative(workItemInitiative, iniId) {
|
|
1782
|
+
const v = (workItemInitiative ?? "").trim().toLowerCase();
|
|
1783
|
+
return v !== "" && v === iniId.trim().toLowerCase();
|
|
1784
|
+
}
|
|
1785
|
+
function associatedWorkItems(dir, iniId) {
|
|
1786
|
+
return discoverWorkItems(dir).filter((wi) => workItemBelongsToInitiative(wi.initiative, iniId)).map((wi) => ({
|
|
1787
|
+
id: wi.id,
|
|
1788
|
+
title: wi.title,
|
|
1789
|
+
status: wi.lifecycle ?? "ready"
|
|
1790
|
+
})).sort((a, b) => a.id.localeCompare(b.id));
|
|
1791
|
+
}
|
|
1792
|
+
function computeInitiativeProgress(dir, ini) {
|
|
1793
|
+
const totalCandidates = ini.candidates.length;
|
|
1794
|
+
const materialized = ini.candidates.filter((c) => c.materializedAs).length;
|
|
1795
|
+
const byState = emptyLifecycleCounts();
|
|
1796
|
+
const associated = associatedWorkItems(dir, ini.id);
|
|
1797
|
+
for (const wi of associated) byState[wi.status]++;
|
|
1798
|
+
return {
|
|
1799
|
+
initiative: ini.id,
|
|
1800
|
+
status: ini.status,
|
|
1801
|
+
planning: {
|
|
1802
|
+
totalCandidates,
|
|
1803
|
+
materialized,
|
|
1804
|
+
remaining: Math.max(0, totalCandidates - materialized)
|
|
1805
|
+
},
|
|
1806
|
+
delivery: {
|
|
1807
|
+
total: associated.length,
|
|
1808
|
+
byState
|
|
1809
|
+
}
|
|
1810
|
+
};
|
|
1811
|
+
}
|
|
1812
|
+
function getInitiativeContext(dir, ini) {
|
|
1813
|
+
return {
|
|
1814
|
+
initiative: {
|
|
1815
|
+
id: ini.id,
|
|
1816
|
+
title: ini.title,
|
|
1817
|
+
status: ini.status,
|
|
1818
|
+
horizon: ini.horizon,
|
|
1819
|
+
priority: ini.priority,
|
|
1820
|
+
knowledgeLevel: ini.knowledgeLevel,
|
|
1821
|
+
domains: ini.domains,
|
|
1822
|
+
relatedCapabilities: ini.relatedCapabilities,
|
|
1823
|
+
source: ini.source,
|
|
1824
|
+
sourceId: ini.sourceId
|
|
1825
|
+
},
|
|
1826
|
+
progress: computeInitiativeProgress(dir, ini),
|
|
1827
|
+
candidates: {
|
|
1828
|
+
total: ini.candidates.length,
|
|
1829
|
+
materialized: ini.candidates.filter((c) => c.materializedAs),
|
|
1830
|
+
pending: ini.candidates.filter((c) => !c.materializedAs)
|
|
1831
|
+
},
|
|
1832
|
+
workItems: associatedWorkItems(dir, ini.id),
|
|
1833
|
+
externalLinks: ini.externalLinks
|
|
1834
|
+
};
|
|
1835
|
+
}
|
|
1836
|
+
function suggestInitiativesForExternalItem(dir, integration, externalId) {
|
|
1837
|
+
const wantIntegration = integration.trim().toLowerCase();
|
|
1838
|
+
const wantId = externalId.trim().toLowerCase();
|
|
1839
|
+
if (!wantIntegration || !wantId) return [];
|
|
1840
|
+
return discoverInitiatives(dir).filter(
|
|
1841
|
+
(ini) => ini.externalLinks.some(
|
|
1842
|
+
(l) => l.integration.trim().toLowerCase() === wantIntegration && l.externalId.trim().toLowerCase() === wantId
|
|
1843
|
+
)
|
|
1844
|
+
);
|
|
1845
|
+
}
|
|
1846
|
+
|
|
1638
1847
|
// src/core/graph.ts
|
|
1639
1848
|
var KNOWLEDGE2 = "knowledge";
|
|
1640
1849
|
var ACTIVE_STATUSES = ["draft", "ready", "in-progress", "blocked"];
|
|
@@ -1642,14 +1851,14 @@ var ALL_STATUSES = ["draft", "ready", "in-progress", "blocked", "completed"];
|
|
|
1642
1851
|
function scopeStatuses(scope) {
|
|
1643
1852
|
return scope === "all" ? { included: ALL_STATUSES, excluded: ["archived"] } : { included: ACTIVE_STATUSES, excluded: ["completed", "archived"] };
|
|
1644
1853
|
}
|
|
1645
|
-
function
|
|
1854
|
+
function toPosix3(p) {
|
|
1646
1855
|
return p.replace(/\\/g, "/");
|
|
1647
1856
|
}
|
|
1648
1857
|
function slug(s) {
|
|
1649
1858
|
return s.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
1650
1859
|
}
|
|
1651
1860
|
function isAdr(a) {
|
|
1652
|
-
return
|
|
1861
|
+
return toPosix3(a.filePath).includes("/tech/decisions/") && Boolean(a.type);
|
|
1653
1862
|
}
|
|
1654
1863
|
function buildGraph(dir, config, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
1655
1864
|
const scope = opts.scope ?? "active";
|
|
@@ -1688,6 +1897,33 @@ function buildGraph(dir, config, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
|
1688
1897
|
const includedSet = new Set(included);
|
|
1689
1898
|
const activeWICount = workItems.filter((a) => a.lifecycle && isActiveState(a.lifecycle)).length;
|
|
1690
1899
|
const selectedWIs = workItems.filter((a) => a.lifecycle && includedSet.has(a.lifecycle));
|
|
1900
|
+
for (const ini of discoverInitiatives(dir)) {
|
|
1901
|
+
const iniNodeId = `initiative:${slug(ini.id) || ini.id}`;
|
|
1902
|
+
addNode({
|
|
1903
|
+
id: iniNodeId,
|
|
1904
|
+
type: "initiative",
|
|
1905
|
+
label: `${ini.id} ${ini.title}`.trim(),
|
|
1906
|
+
path: ini.relPath,
|
|
1907
|
+
status: ini.status
|
|
1908
|
+
});
|
|
1909
|
+
for (const cap of ini.relatedCapabilities) {
|
|
1910
|
+
if (!cap.trim()) continue;
|
|
1911
|
+
const capId = `capability:${slug(cap) || cap}`;
|
|
1912
|
+
addNode({ id: capId, type: "capability", label: cap });
|
|
1913
|
+
addEdge(iniNodeId, capId, "targets");
|
|
1914
|
+
}
|
|
1915
|
+
for (const link of ini.externalLinks) {
|
|
1916
|
+
const extId = `external-item:${slug(link.integration) || link.integration}:${slug(link.externalId) || link.externalId}`;
|
|
1917
|
+
addNode({ id: extId, type: "external-item", label: `${link.integration}:${link.externalId}`, path: link.url });
|
|
1918
|
+
addEdge(iniNodeId, extId, "references_external");
|
|
1919
|
+
}
|
|
1920
|
+
for (const cand of ini.candidates) {
|
|
1921
|
+
const candId = `candidate:${cand.id}`;
|
|
1922
|
+
addNode({ id: candId, type: "roadmap-candidate", label: cand.id });
|
|
1923
|
+
addEdge(candId, iniNodeId, "belongs_to");
|
|
1924
|
+
if (cand.materializedAs) addEdge(candId, `wi:${cand.materializedAs}`, "materialized_as");
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1691
1927
|
for (const wi of selectedWIs) {
|
|
1692
1928
|
const id = wi.id || wi.title;
|
|
1693
1929
|
if (!id || !id.trim()) continue;
|
|
@@ -1812,14 +2048,14 @@ function loadGraphSummary(dir) {
|
|
|
1812
2048
|
|
|
1813
2049
|
// src/core/graph-hints.ts
|
|
1814
2050
|
var KNOWLEDGE3 = "knowledge";
|
|
1815
|
-
function
|
|
2051
|
+
function toPosix4(p) {
|
|
1816
2052
|
return p.replace(/\\/g, "/");
|
|
1817
2053
|
}
|
|
1818
2054
|
function slug2(s) {
|
|
1819
2055
|
return s.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
1820
2056
|
}
|
|
1821
2057
|
function isAdr2(a) {
|
|
1822
|
-
return
|
|
2058
|
+
return toPosix4(a.filePath).includes("/tech/decisions/") && Boolean(a.type);
|
|
1823
2059
|
}
|
|
1824
2060
|
function capabilityHeadings(dir) {
|
|
1825
2061
|
const p = join(dir, KNOWLEDGE3, "product", "capabilities.md");
|
|
@@ -1986,7 +2222,7 @@ function loadGraphHints(dir) {
|
|
|
1986
2222
|
}
|
|
1987
2223
|
|
|
1988
2224
|
// src/services/installed-skills.ts
|
|
1989
|
-
import
|
|
2225
|
+
import matter4 from "gray-matter";
|
|
1990
2226
|
var SKILLS_DIR = join("knowledge", "skills");
|
|
1991
2227
|
function discoverInstalledSkills(dir) {
|
|
1992
2228
|
const base = join(dir, SKILLS_DIR);
|
|
@@ -1996,7 +2232,7 @@ function discoverInstalledSkills(dir) {
|
|
|
1996
2232
|
const skillFile = join(base, entry, "skill.md");
|
|
1997
2233
|
if (!isFile(skillFile)) continue;
|
|
1998
2234
|
try {
|
|
1999
|
-
const { data } =
|
|
2235
|
+
const { data } = matter4(readFile(skillFile));
|
|
2000
2236
|
if (data.type && String(data.type) !== "skill") continue;
|
|
2001
2237
|
const id = String(data.id ?? entry);
|
|
2002
2238
|
out.push({
|
|
@@ -3507,7 +3743,7 @@ function deriveDeliveryCompletedStatus(dir) {
|
|
|
3507
3743
|
}
|
|
3508
3744
|
|
|
3509
3745
|
// src/core/assets.ts
|
|
3510
|
-
import
|
|
3746
|
+
import matter5 from "gray-matter";
|
|
3511
3747
|
|
|
3512
3748
|
// src/core/version.ts
|
|
3513
3749
|
import { fileURLToPath } from "url";
|
|
@@ -6713,7 +6949,7 @@ function canonicalSkills() {
|
|
|
6713
6949
|
}
|
|
6714
6950
|
function versionOf(content) {
|
|
6715
6951
|
try {
|
|
6716
|
-
const v =
|
|
6952
|
+
const v = matter5(content).data.version;
|
|
6717
6953
|
return v === void 0 || v === null ? null : String(v);
|
|
6718
6954
|
} catch {
|
|
6719
6955
|
return null;
|
|
@@ -6873,19 +7109,19 @@ function parseWorkItemSource(frontmatter) {
|
|
|
6873
7109
|
const rawSource = frontmatter.source;
|
|
6874
7110
|
if (rawSource != null && typeof rawSource === "object" && !Array.isArray(rawSource)) {
|
|
6875
7111
|
const obj = rawSource;
|
|
6876
|
-
const t =
|
|
7112
|
+
const t = optStr2(obj.type);
|
|
6877
7113
|
const type = t && isValidSource(t) ? t : "unknown";
|
|
6878
7114
|
return {
|
|
6879
7115
|
type,
|
|
6880
|
-
id:
|
|
6881
|
-
title:
|
|
6882
|
-
context:
|
|
6883
|
-
provider:
|
|
6884
|
-
integration:
|
|
6885
|
-
url:
|
|
6886
|
-
imported_at:
|
|
6887
|
-
external_updated_at:
|
|
6888
|
-
synced_at:
|
|
7116
|
+
id: optStr2(obj.id) ?? optStr2(frontmatter.source_id),
|
|
7117
|
+
title: optStr2(obj.title) ?? optStr2(frontmatter.source_title),
|
|
7118
|
+
context: optStr2(obj.context) ?? optStr2(frontmatter.source_context),
|
|
7119
|
+
provider: optStr2(obj.provider) ?? optStr2(frontmatter.source_provider),
|
|
7120
|
+
integration: optStr2(obj.integration) ?? optStr2(frontmatter.source_integration),
|
|
7121
|
+
url: optStr2(obj.url) ?? optStr2(frontmatter.source_url),
|
|
7122
|
+
imported_at: optStr2(obj.imported_at) ?? optStr2(frontmatter.source_imported_at),
|
|
7123
|
+
external_updated_at: optStr2(obj.external_updated_at) ?? optStr2(frontmatter.source_external_updated_at),
|
|
7124
|
+
synced_at: optStr2(obj.synced_at) ?? optStr2(frontmatter.source_synced_at),
|
|
6889
7125
|
inferred: obj.inferred === true || obj.inferred === "true",
|
|
6890
7126
|
reason: t && !isValidSource(t) ? `Invalid source type in object: "${t}".` : void 0
|
|
6891
7127
|
};
|
|
@@ -6894,28 +7130,28 @@ function parseWorkItemSource(frontmatter) {
|
|
|
6894
7130
|
if (raw && isValidSource(raw)) {
|
|
6895
7131
|
return {
|
|
6896
7132
|
type: raw,
|
|
6897
|
-
id:
|
|
6898
|
-
title:
|
|
6899
|
-
context:
|
|
6900
|
-
provider:
|
|
6901
|
-
url:
|
|
6902
|
-
imported_at:
|
|
6903
|
-
external_updated_at:
|
|
6904
|
-
synced_at:
|
|
7133
|
+
id: optStr2(frontmatter.source_id),
|
|
7134
|
+
title: optStr2(frontmatter.source_title),
|
|
7135
|
+
context: optStr2(frontmatter.source_context),
|
|
7136
|
+
provider: optStr2(frontmatter.source_provider),
|
|
7137
|
+
url: optStr2(frontmatter.source_url),
|
|
7138
|
+
imported_at: optStr2(frontmatter.source_imported_at),
|
|
7139
|
+
external_updated_at: optStr2(frontmatter.source_external_updated_at),
|
|
7140
|
+
synced_at: optStr2(frontmatter.source_synced_at),
|
|
6905
7141
|
inferred: false
|
|
6906
7142
|
};
|
|
6907
7143
|
}
|
|
6908
7144
|
if (raw && !isValidSource(raw)) {
|
|
6909
7145
|
return {
|
|
6910
7146
|
type: "unknown",
|
|
6911
|
-
id:
|
|
6912
|
-
title:
|
|
6913
|
-
context:
|
|
6914
|
-
provider:
|
|
6915
|
-
url:
|
|
6916
|
-
imported_at:
|
|
6917
|
-
external_updated_at:
|
|
6918
|
-
synced_at:
|
|
7147
|
+
id: optStr2(frontmatter.source_id),
|
|
7148
|
+
title: optStr2(frontmatter.source_title),
|
|
7149
|
+
context: optStr2(frontmatter.source_context),
|
|
7150
|
+
provider: optStr2(frontmatter.source_provider),
|
|
7151
|
+
url: optStr2(frontmatter.source_url),
|
|
7152
|
+
imported_at: optStr2(frontmatter.source_imported_at),
|
|
7153
|
+
external_updated_at: optStr2(frontmatter.source_external_updated_at),
|
|
7154
|
+
synced_at: optStr2(frontmatter.source_synced_at),
|
|
6919
7155
|
inferred: true,
|
|
6920
7156
|
reason: `Invalid source value: "${raw}".`
|
|
6921
7157
|
};
|
|
@@ -6923,8 +7159,8 @@ function parseWorkItemSource(frontmatter) {
|
|
|
6923
7159
|
if (frontmatter.source_work_item_candidate || frontmatter.source_roadmap_initiative) {
|
|
6924
7160
|
return {
|
|
6925
7161
|
type: "roadmap",
|
|
6926
|
-
id:
|
|
6927
|
-
title:
|
|
7162
|
+
id: optStr2(frontmatter.source_id) ?? optStr2(frontmatter.source_work_item_candidate),
|
|
7163
|
+
title: optStr2(frontmatter.source_initiative_title),
|
|
6928
7164
|
inferred: true,
|
|
6929
7165
|
reason: "Inferred from legacy roadmap fields."
|
|
6930
7166
|
};
|
|
@@ -6932,7 +7168,7 @@ function parseWorkItemSource(frontmatter) {
|
|
|
6932
7168
|
if (frontmatter.source_id) {
|
|
6933
7169
|
return {
|
|
6934
7170
|
type: "unknown",
|
|
6935
|
-
id:
|
|
7171
|
+
id: optStr2(frontmatter.source_id),
|
|
6936
7172
|
inferred: true,
|
|
6937
7173
|
reason: "Has source_id but no source type."
|
|
6938
7174
|
};
|
|
@@ -6943,7 +7179,7 @@ function parseWorkItemSource(frontmatter) {
|
|
|
6943
7179
|
reason: "No source metadata found."
|
|
6944
7180
|
};
|
|
6945
7181
|
}
|
|
6946
|
-
function
|
|
7182
|
+
function optStr2(v) {
|
|
6947
7183
|
if (typeof v === "string" && v.trim()) return v.trim();
|
|
6948
7184
|
return void 0;
|
|
6949
7185
|
}
|
|
@@ -7404,7 +7640,7 @@ function buildProjectRoute(dir) {
|
|
|
7404
7640
|
}
|
|
7405
7641
|
|
|
7406
7642
|
// src/core/metadata-health.ts
|
|
7407
|
-
import
|
|
7643
|
+
import matter6 from "gray-matter";
|
|
7408
7644
|
var KNOWLEDGE_FILES2 = [
|
|
7409
7645
|
"knowledge/business/business.md",
|
|
7410
7646
|
"knowledge/product/product.md",
|
|
@@ -7424,7 +7660,7 @@ function analyzeMetadataHealth(dir) {
|
|
|
7424
7660
|
let data;
|
|
7425
7661
|
try {
|
|
7426
7662
|
const raw = readFile(p);
|
|
7427
|
-
data =
|
|
7663
|
+
data = matter6(raw).data;
|
|
7428
7664
|
} catch {
|
|
7429
7665
|
continue;
|
|
7430
7666
|
}
|
|
@@ -7456,7 +7692,7 @@ function analyzeMetadataHealth(dir) {
|
|
|
7456
7692
|
if (isFile(p) && entry.endsWith(".md")) {
|
|
7457
7693
|
try {
|
|
7458
7694
|
const raw = readFile(p);
|
|
7459
|
-
const fm =
|
|
7695
|
+
const fm = matter6(raw).data;
|
|
7460
7696
|
if (fm.status === "done") {
|
|
7461
7697
|
const rel = p.replace(dir + "/", "").replace(dir + "\\", "").replace(/\\/g, "/");
|
|
7462
7698
|
findings.push({
|
|
@@ -8053,7 +8289,7 @@ function analyzeCrossRepoEvidence(input) {
|
|
|
8053
8289
|
}
|
|
8054
8290
|
|
|
8055
8291
|
// src/core/work-items.ts
|
|
8056
|
-
import
|
|
8292
|
+
import matter7 from "gray-matter";
|
|
8057
8293
|
|
|
8058
8294
|
// src/core/system-topology.ts
|
|
8059
8295
|
import { parse as parseYaml8, stringify as stringifyYaml4 } from "yaml";
|
|
@@ -8091,7 +8327,7 @@ var PROVENANCE = /* @__PURE__ */ new Set(["declared", "derived", "agent-reviewed
|
|
|
8091
8327
|
function isRelative(p) {
|
|
8092
8328
|
return typeof p === "string" && p.trim() !== "" && !/^([a-zA-Z]:[\\/]|\/)/.test(p) && !p.includes("..");
|
|
8093
8329
|
}
|
|
8094
|
-
function
|
|
8330
|
+
function strList2(v) {
|
|
8095
8331
|
return Array.isArray(v) ? v.map((x) => typeof x === "string" ? x.trim() : "").filter(Boolean) : [];
|
|
8096
8332
|
}
|
|
8097
8333
|
function loadSystemTopology(dir) {
|
|
@@ -8132,7 +8368,7 @@ function parseTopologyContent(raw, dir) {
|
|
|
8132
8368
|
const moduleRaw = typeof e.module === "string" ? e.module.trim() : void 0;
|
|
8133
8369
|
if (moduleRaw && !validModules.has(moduleRaw)) findings.push({ level: "warning", message: `Entity "${id}" references unregistered module "${moduleRaw}".` });
|
|
8134
8370
|
const rawImpl = e.implementation ?? e.implementation_refs;
|
|
8135
|
-
const implementation =
|
|
8371
|
+
const implementation = strList2(rawImpl).filter((p) => {
|
|
8136
8372
|
if (isRelative(p)) return true;
|
|
8137
8373
|
findings.push({ level: "warning", message: `Entity "${id}" implementation ref "${p}" is not a safe relative path and was dropped.` });
|
|
8138
8374
|
return false;
|
|
@@ -8140,7 +8376,7 @@ function parseTopologyContent(raw, dir) {
|
|
|
8140
8376
|
const prov = e.provenance;
|
|
8141
8377
|
const provOrigin = typeof prov === "string" ? prov : prov && typeof prov === "object" && typeof prov.origin === "string" ? String(prov.origin) : void 0;
|
|
8142
8378
|
const provenance = provOrigin && PROVENANCE.has(provOrigin) ? provOrigin : void 0;
|
|
8143
|
-
const evidence =
|
|
8379
|
+
const evidence = strList2(e.evidence ?? (prov && typeof prov === "object" ? prov.evidence_refs : void 0)).filter(isRelative);
|
|
8144
8380
|
seenIds.add(id);
|
|
8145
8381
|
entities.push({
|
|
8146
8382
|
id,
|
|
@@ -8149,7 +8385,7 @@ function parseTopologyContent(raw, dir) {
|
|
|
8149
8385
|
...typeof e.purpose === "string" && e.purpose.trim() ? { purpose: e.purpose.trim() } : {},
|
|
8150
8386
|
...moduleRaw && validModules.has(moduleRaw) ? { moduleId: moduleRaw } : {},
|
|
8151
8387
|
implementationRefs: implementation,
|
|
8152
|
-
knowledgeRefs:
|
|
8388
|
+
knowledgeRefs: strList2(e.knowledge ?? e.knowledge_refs),
|
|
8153
8389
|
...provenance ? { provenance } : {},
|
|
8154
8390
|
evidence
|
|
8155
8391
|
});
|
|
@@ -8183,7 +8419,7 @@ function parseTopologyContent(raw, dir) {
|
|
|
8183
8419
|
}
|
|
8184
8420
|
seenRels.add(key);
|
|
8185
8421
|
const prov = r.provenance;
|
|
8186
|
-
relationships.push({ from, to, type, evidence:
|
|
8422
|
+
relationships.push({ from, to, type, evidence: strList2(r.evidence ?? prov?.evidence_refs).filter(isRelative) });
|
|
8187
8423
|
}
|
|
8188
8424
|
return { entities, relationships, findings, ...sourceRevision ? { sourceRevision } : {} };
|
|
8189
8425
|
}
|
|
@@ -8485,7 +8721,7 @@ function parseOriginalSnapshot(fm) {
|
|
|
8485
8721
|
function readBody(filePath) {
|
|
8486
8722
|
try {
|
|
8487
8723
|
const raw = readFile(filePath);
|
|
8488
|
-
return
|
|
8724
|
+
return matter7(raw).content;
|
|
8489
8725
|
} catch {
|
|
8490
8726
|
return "";
|
|
8491
8727
|
}
|
|
@@ -8569,7 +8805,7 @@ function normalizeImpact(ia) {
|
|
|
8569
8805
|
...v.question ? { question: v.question } : {}
|
|
8570
8806
|
}));
|
|
8571
8807
|
}
|
|
8572
|
-
function
|
|
8808
|
+
function optStr3(v) {
|
|
8573
8809
|
if (typeof v === "string" && v.trim()) return v.trim();
|
|
8574
8810
|
return void 0;
|
|
8575
8811
|
}
|
|
@@ -8584,13 +8820,13 @@ function parseEvidence(fm) {
|
|
|
8584
8820
|
const validations = Array.isArray(d.validations) ? d.validations.map((v) => ({
|
|
8585
8821
|
command: String(v.command ?? ""),
|
|
8586
8822
|
status: String(v.status ?? "unknown"),
|
|
8587
|
-
...
|
|
8823
|
+
...optStr3(v.reason) ? { reason: optStr3(v.reason) } : {}
|
|
8588
8824
|
})) : [];
|
|
8589
8825
|
const migrations = Array.isArray(d.migrations) ? d.migrations.map((m) => ({
|
|
8590
8826
|
id: String(m.id ?? ""),
|
|
8591
8827
|
environment: String(m.environment ?? ""),
|
|
8592
8828
|
status: String(m.status ?? "unknown"),
|
|
8593
|
-
...
|
|
8829
|
+
...optStr3(m.reason) ? { reason: optStr3(m.reason) } : {}
|
|
8594
8830
|
})) : [];
|
|
8595
8831
|
out.push({
|
|
8596
8832
|
module,
|
|
@@ -8608,8 +8844,8 @@ function parseReleaseGates(fm) {
|
|
|
8608
8844
|
return fm.release_gates.filter((g) => g && typeof g === "object").map((g) => ({
|
|
8609
8845
|
id: String(g.id ?? ""),
|
|
8610
8846
|
status: String(g.status ?? "pending"),
|
|
8611
|
-
...
|
|
8612
|
-
...
|
|
8847
|
+
...optStr3(g.reason) ? { reason: optStr3(g.reason) } : {},
|
|
8848
|
+
...optStr3(g.required_for) ? { requiredFor: optStr3(g.required_for) } : {}
|
|
8613
8849
|
}));
|
|
8614
8850
|
}
|
|
8615
8851
|
function parseExceptions(fm) {
|
|
@@ -8617,9 +8853,9 @@ function parseExceptions(fm) {
|
|
|
8617
8853
|
return fm.completion_exceptions.filter((e) => e && typeof e === "object").map((e) => ({
|
|
8618
8854
|
id: String(e.id ?? ""),
|
|
8619
8855
|
status: String(e.status ?? "proposed"),
|
|
8620
|
-
...
|
|
8621
|
-
...
|
|
8622
|
-
...
|
|
8856
|
+
...optStr3(e.reason) ? { reason: optStr3(e.reason) } : {},
|
|
8857
|
+
...optStr3(e.category) ? { category: optStr3(e.category) } : {},
|
|
8858
|
+
...optStr3(e.impact) ? { impact: optStr3(e.impact) } : {}
|
|
8623
8859
|
}));
|
|
8624
8860
|
}
|
|
8625
8861
|
function parseDecisions(decisions, knowledgeById) {
|
|
@@ -8652,7 +8888,7 @@ function parseRelatedKnowledge(fm, knowledgeById) {
|
|
|
8652
8888
|
import fs3 from "fs";
|
|
8653
8889
|
import path3 from "path";
|
|
8654
8890
|
import crypto2 from "crypto";
|
|
8655
|
-
import
|
|
8891
|
+
import matter8 from "gray-matter";
|
|
8656
8892
|
|
|
8657
8893
|
// src/core/knowledge-levels.ts
|
|
8658
8894
|
var WORK_ITEM_TYPES2 = ["feature", "bugfix", "hotfix", "spike", "chore"];
|
|
@@ -9051,7 +9287,7 @@ function applyFrontmatter(data, input) {
|
|
|
9051
9287
|
return next;
|
|
9052
9288
|
}
|
|
9053
9289
|
function serialize(data, body) {
|
|
9054
|
-
return
|
|
9290
|
+
return matter8.stringify(`
|
|
9055
9291
|
${body.trim()}
|
|
9056
9292
|
`, data);
|
|
9057
9293
|
}
|
|
@@ -9110,7 +9346,7 @@ function toInput(data, content) {
|
|
|
9110
9346
|
function getWorkItemForEdit(dir, id) {
|
|
9111
9347
|
const { filePath, relPath } = findArtifact(dir, id);
|
|
9112
9348
|
const raw = readFile(filePath);
|
|
9113
|
-
const { data, content } =
|
|
9349
|
+
const { data, content } = matter8(raw);
|
|
9114
9350
|
const status = lifecycleStateOf({ status: String(data.status ?? ""), filePath });
|
|
9115
9351
|
const input = toInput(data, content);
|
|
9116
9352
|
const editable = EDITABLE_STATES.includes(status);
|
|
@@ -9201,7 +9437,7 @@ function updateWorkItem(dir, id, input, expectedRevision) {
|
|
|
9201
9437
|
if (revisionOf(raw) !== expectedRevision) {
|
|
9202
9438
|
throw new WorkItemWriteError("WORK_ITEM_CONFLICT", "This Work Item changed outside Kaddo Admin. Reload the latest version before saving.");
|
|
9203
9439
|
}
|
|
9204
|
-
const { data, content } =
|
|
9440
|
+
const { data, content } = matter8(raw);
|
|
9205
9441
|
const status = lifecycleStateOf({ status: String(data.status ?? ""), filePath });
|
|
9206
9442
|
if (!EDITABLE_STATES.includes(status)) {
|
|
9207
9443
|
throw new WorkItemWriteError("WORK_ITEM_NOT_EDITABLE", `A ${status} Work Item cannot be edited. Reopen it as Draft first.`);
|
|
@@ -9215,7 +9451,7 @@ function updateWorkItem(dir, id, input, expectedRevision) {
|
|
|
9215
9451
|
function validateWorkItem(dir, id) {
|
|
9216
9452
|
const { filePath } = findArtifact(dir, id);
|
|
9217
9453
|
const raw = readFile(filePath);
|
|
9218
|
-
const { data, content } =
|
|
9454
|
+
const { data, content } = matter8(raw);
|
|
9219
9455
|
const input = toInput(data, content);
|
|
9220
9456
|
const findings = [];
|
|
9221
9457
|
const modules = validModuleIds(dir);
|
|
@@ -9268,7 +9504,7 @@ function transitionWorkItem(dir, id, to, expectedRevision) {
|
|
|
9268
9504
|
if (revisionOf(raw) !== expectedRevision) {
|
|
9269
9505
|
throw new WorkItemWriteError("WORK_ITEM_CONFLICT", "This Work Item changed outside Kaddo Admin. Reload the latest version before continuing.");
|
|
9270
9506
|
}
|
|
9271
|
-
const { data, content } =
|
|
9507
|
+
const { data, content } = matter8(raw);
|
|
9272
9508
|
const from = lifecycleStateOf({ status: String(data.status ?? ""), filePath });
|
|
9273
9509
|
if (!(ALLOWED[from] ?? []).includes(to)) {
|
|
9274
9510
|
throw new WorkItemWriteError("INVALID_TRANSITION", `Cannot transition a ${from} Work Item to ${to}.`);
|
|
@@ -10110,7 +10346,7 @@ function deriveImplementationStatus(repos) {
|
|
|
10110
10346
|
// src/core/work-item-import.ts
|
|
10111
10347
|
import crypto3 from "crypto";
|
|
10112
10348
|
import fs4 from "fs";
|
|
10113
|
-
import
|
|
10349
|
+
import matter9 from "gray-matter";
|
|
10114
10350
|
var MAX_INPUT_BYTES = 102400;
|
|
10115
10351
|
var LIFECYCLE_FIELDS = /* @__PURE__ */ new Set([
|
|
10116
10352
|
"id",
|
|
@@ -10132,7 +10368,7 @@ function detectFormat(raw) {
|
|
|
10132
10368
|
if (!trimmed) throw new ImportError("EMPTY_INPUT", "Import content is empty.");
|
|
10133
10369
|
if (trimmed.startsWith("---")) {
|
|
10134
10370
|
try {
|
|
10135
|
-
const { data } =
|
|
10371
|
+
const { data } = matter9(trimmed);
|
|
10136
10372
|
if (data && typeof data === "object" && Object.keys(data).length > 0) {
|
|
10137
10373
|
const d = data;
|
|
10138
10374
|
if (d.type === "work-item" || d.id && typeof d.id === "string" && /^WI-\d+/.test(d.id)) {
|
|
@@ -10154,7 +10390,7 @@ function parseContent(raw) {
|
|
|
10154
10390
|
let bodyText = trimmed;
|
|
10155
10391
|
if (format === "kaddo-frontmatter" || format === "markdown-frontmatter") {
|
|
10156
10392
|
try {
|
|
10157
|
-
const parsed =
|
|
10393
|
+
const parsed = matter9(trimmed);
|
|
10158
10394
|
frontmatterFields = parsed.data ?? {};
|
|
10159
10395
|
bodyText = parsed.content.trim();
|
|
10160
10396
|
} catch {
|
|
@@ -10245,7 +10481,7 @@ function findDuplicateByHash(dir, hash) {
|
|
|
10245
10481
|
const raw = readFile(item.filePath);
|
|
10246
10482
|
if (!raw) continue;
|
|
10247
10483
|
try {
|
|
10248
|
-
const { data } =
|
|
10484
|
+
const { data } = matter9(raw);
|
|
10249
10485
|
const source = data?.source;
|
|
10250
10486
|
if (source && typeof source === "object" && !Array.isArray(source)) {
|
|
10251
10487
|
const s = source;
|
|
@@ -10352,7 +10588,7 @@ var ImportError = class extends Error {
|
|
|
10352
10588
|
};
|
|
10353
10589
|
|
|
10354
10590
|
// src/services/integrations.ts
|
|
10355
|
-
import
|
|
10591
|
+
import matter10 from "gray-matter";
|
|
10356
10592
|
import { parse as parseYaml9, stringify as stringifyYaml5 } from "yaml";
|
|
10357
10593
|
|
|
10358
10594
|
// ../integrations/src/errors.ts
|
|
@@ -11694,7 +11930,7 @@ function findLinkedWorkItem(dir, integrationId, externalId) {
|
|
|
11694
11930
|
for (const art of discoverWorkItems(dir)) {
|
|
11695
11931
|
let data;
|
|
11696
11932
|
try {
|
|
11697
|
-
data =
|
|
11933
|
+
data = matter10(readFile(art.filePath)).data;
|
|
11698
11934
|
} catch {
|
|
11699
11935
|
continue;
|
|
11700
11936
|
}
|
|
@@ -11710,7 +11946,7 @@ function buildImportIndex(dir) {
|
|
|
11710
11946
|
for (const art of discoverWorkItems(dir)) {
|
|
11711
11947
|
let data;
|
|
11712
11948
|
try {
|
|
11713
|
-
data =
|
|
11949
|
+
data = matter10(readFile(art.filePath)).data;
|
|
11714
11950
|
} catch {
|
|
11715
11951
|
continue;
|
|
11716
11952
|
}
|
|
@@ -11885,204 +12121,6 @@ function getStatus(dir) {
|
|
|
11885
12121
|
};
|
|
11886
12122
|
}
|
|
11887
12123
|
|
|
11888
|
-
// src/core/initiative.ts
|
|
11889
|
-
import matter10 from "gray-matter";
|
|
11890
|
-
var INITIATIVES_DIR = "knowledge/delivery/initiatives";
|
|
11891
|
-
var INITIATIVE_STATES = [
|
|
11892
|
-
"candidate",
|
|
11893
|
-
"planned",
|
|
11894
|
-
"in-progress",
|
|
11895
|
-
"completed",
|
|
11896
|
-
"deferred",
|
|
11897
|
-
"cancelled"
|
|
11898
|
-
];
|
|
11899
|
-
var INITIATIVE_TRANSITIONS = {
|
|
11900
|
-
candidate: ["planned", "cancelled"],
|
|
11901
|
-
planned: ["in-progress", "deferred", "cancelled"],
|
|
11902
|
-
"in-progress": ["completed", "deferred", "cancelled"],
|
|
11903
|
-
deferred: ["planned", "cancelled"],
|
|
11904
|
-
completed: [],
|
|
11905
|
-
cancelled: []
|
|
11906
|
-
};
|
|
11907
|
-
var STATUS_SET = new Set(INITIATIVE_STATES);
|
|
11908
|
-
function isValidInitiativeStatus(s) {
|
|
11909
|
-
return STATUS_SET.has(s);
|
|
11910
|
-
}
|
|
11911
|
-
function isValidInitiativeTransition(from, to) {
|
|
11912
|
-
return INITIATIVE_TRANSITIONS[from].includes(to);
|
|
11913
|
-
}
|
|
11914
|
-
function toPosix4(p) {
|
|
11915
|
-
return p.replace(/\\/g, "/");
|
|
11916
|
-
}
|
|
11917
|
-
function optStr3(v) {
|
|
11918
|
-
if (typeof v === "string" && v.trim()) return v.trim();
|
|
11919
|
-
if (typeof v === "number") return String(v);
|
|
11920
|
-
return void 0;
|
|
11921
|
-
}
|
|
11922
|
-
function strList2(v) {
|
|
11923
|
-
if (!Array.isArray(v)) return [];
|
|
11924
|
-
return v.map((x) => typeof x === "string" ? x.trim() : String(x)).filter(Boolean);
|
|
11925
|
-
}
|
|
11926
|
-
function parseCandidates(data) {
|
|
11927
|
-
const raw = data.candidates;
|
|
11928
|
-
if (!Array.isArray(raw)) return [];
|
|
11929
|
-
const out = [];
|
|
11930
|
-
for (const entry of raw) {
|
|
11931
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
11932
|
-
const o = entry;
|
|
11933
|
-
const id = optStr3(o.id);
|
|
11934
|
-
const title = optStr3(o.title);
|
|
11935
|
-
if (!id || !title) continue;
|
|
11936
|
-
out.push({
|
|
11937
|
-
id,
|
|
11938
|
-
title,
|
|
11939
|
-
type: optStr3(o.type),
|
|
11940
|
-
suggestedKnowledgeLevel: optStr3(o.suggested_knowledge_level ?? o.knowledge_level),
|
|
11941
|
-
expectedValue: optStr3(o.expected_value),
|
|
11942
|
-
notes: optStr3(o.notes),
|
|
11943
|
-
sourceSignals: strList2(o.source_signals),
|
|
11944
|
-
dependencies: strList2(o.dependencies),
|
|
11945
|
-
materializedAs: optStr3(o.materialized_as) ?? null
|
|
11946
|
-
});
|
|
11947
|
-
}
|
|
11948
|
-
return out;
|
|
11949
|
-
}
|
|
11950
|
-
function parseExternalLinks(data) {
|
|
11951
|
-
const raw = data.external_links;
|
|
11952
|
-
if (!Array.isArray(raw)) return [];
|
|
11953
|
-
const out = [];
|
|
11954
|
-
for (const entry of raw) {
|
|
11955
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
11956
|
-
const o = entry;
|
|
11957
|
-
const integration = optStr3(o.integration);
|
|
11958
|
-
const externalId = optStr3(o.external_id);
|
|
11959
|
-
if (!integration || !externalId) continue;
|
|
11960
|
-
out.push({
|
|
11961
|
-
integration,
|
|
11962
|
-
externalId,
|
|
11963
|
-
externalType: optStr3(o.external_type),
|
|
11964
|
-
url: optStr3(o.url)
|
|
11965
|
-
});
|
|
11966
|
-
}
|
|
11967
|
-
return out;
|
|
11968
|
-
}
|
|
11969
|
-
function parseInitiative(dir, filePath, raw) {
|
|
11970
|
-
let parsed;
|
|
11971
|
-
try {
|
|
11972
|
-
parsed = matter10(raw, {});
|
|
11973
|
-
} catch {
|
|
11974
|
-
return null;
|
|
11975
|
-
}
|
|
11976
|
-
const data = parsed.data;
|
|
11977
|
-
if (optStr3(data.type) !== "initiative") return null;
|
|
11978
|
-
const id = optStr3(data.id);
|
|
11979
|
-
if (!id) return null;
|
|
11980
|
-
const statusRaw = optStr3(data.status) ?? "planned";
|
|
11981
|
-
const status = isValidInitiativeStatus(statusRaw) ? statusRaw : "planned";
|
|
11982
|
-
return {
|
|
11983
|
-
id,
|
|
11984
|
-
title: optStr3(data.title) ?? id,
|
|
11985
|
-
status,
|
|
11986
|
-
horizon: optStr3(data.horizon) ?? null,
|
|
11987
|
-
priority: optStr3(data.priority) ?? null,
|
|
11988
|
-
knowledgeLevel: optStr3(data.knowledge_level) ?? null,
|
|
11989
|
-
domains: strList2(data.domains),
|
|
11990
|
-
relatedCapabilities: strList2(data.related_capabilities),
|
|
11991
|
-
source: optStr3(data.source) ?? null,
|
|
11992
|
-
sourceId: optStr3(data.source_id) ?? null,
|
|
11993
|
-
createdAt: optStr3(data.created_at) ?? null,
|
|
11994
|
-
externalLinks: parseExternalLinks(data),
|
|
11995
|
-
candidates: parseCandidates(data),
|
|
11996
|
-
filePath,
|
|
11997
|
-
relPath: toPosix4(filePath).startsWith(toPosix4(dir) + "/") ? toPosix4(filePath).slice(toPosix4(dir).length + 1) : toPosix4(filePath),
|
|
11998
|
-
body: parsed.content.trim(),
|
|
11999
|
-
rawFrontmatter: data
|
|
12000
|
-
};
|
|
12001
|
-
}
|
|
12002
|
-
function discoverInitiatives(dir) {
|
|
12003
|
-
const iniDir = join(dir, INITIATIVES_DIR);
|
|
12004
|
-
if (!exists(iniDir)) return [];
|
|
12005
|
-
const out = [];
|
|
12006
|
-
for (const entry of readDir(iniDir)) {
|
|
12007
|
-
if (!entry.endsWith(".md")) continue;
|
|
12008
|
-
const full = join(iniDir, entry);
|
|
12009
|
-
if (!isFile(full)) continue;
|
|
12010
|
-
const ini = parseInitiative(dir, full, readFile(full));
|
|
12011
|
-
if (ini) out.push(ini);
|
|
12012
|
-
}
|
|
12013
|
-
return out.sort((a, b) => a.id.localeCompare(b.id));
|
|
12014
|
-
}
|
|
12015
|
-
function getInitiative(dir, id) {
|
|
12016
|
-
const want = id.trim().toLowerCase();
|
|
12017
|
-
return discoverInitiatives(dir).find((i) => i.id.toLowerCase() === want) ?? null;
|
|
12018
|
-
}
|
|
12019
|
-
function nextInitiativeId(dir) {
|
|
12020
|
-
const iniDir = join(dir, INITIATIVES_DIR);
|
|
12021
|
-
let max = 0;
|
|
12022
|
-
if (exists(iniDir)) {
|
|
12023
|
-
for (const entry of readDir(iniDir)) {
|
|
12024
|
-
const m = entry.match(/INI-(\d+)/);
|
|
12025
|
-
if (m) max = Math.max(max, parseInt(m[1], 10));
|
|
12026
|
-
}
|
|
12027
|
-
}
|
|
12028
|
-
return `INI-${String(max + 1).padStart(3, "0")}`;
|
|
12029
|
-
}
|
|
12030
|
-
function workItemBelongsToInitiative(workItemInitiative, iniId) {
|
|
12031
|
-
const v = (workItemInitiative ?? "").trim().toLowerCase();
|
|
12032
|
-
return v !== "" && v === iniId.trim().toLowerCase();
|
|
12033
|
-
}
|
|
12034
|
-
function associatedWorkItems(dir, iniId) {
|
|
12035
|
-
return discoverWorkItems(dir).filter((wi) => workItemBelongsToInitiative(wi.initiative, iniId)).map((wi) => ({
|
|
12036
|
-
id: wi.id,
|
|
12037
|
-
title: wi.title,
|
|
12038
|
-
status: wi.lifecycle ?? "ready"
|
|
12039
|
-
})).sort((a, b) => a.id.localeCompare(b.id));
|
|
12040
|
-
}
|
|
12041
|
-
function computeInitiativeProgress(dir, ini) {
|
|
12042
|
-
const totalCandidates = ini.candidates.length;
|
|
12043
|
-
const materialized = ini.candidates.filter((c) => c.materializedAs).length;
|
|
12044
|
-
const byState = emptyLifecycleCounts();
|
|
12045
|
-
const associated = associatedWorkItems(dir, ini.id);
|
|
12046
|
-
for (const wi of associated) byState[wi.status]++;
|
|
12047
|
-
return {
|
|
12048
|
-
initiative: ini.id,
|
|
12049
|
-
status: ini.status,
|
|
12050
|
-
planning: {
|
|
12051
|
-
totalCandidates,
|
|
12052
|
-
materialized,
|
|
12053
|
-
remaining: Math.max(0, totalCandidates - materialized)
|
|
12054
|
-
},
|
|
12055
|
-
delivery: {
|
|
12056
|
-
total: associated.length,
|
|
12057
|
-
byState
|
|
12058
|
-
}
|
|
12059
|
-
};
|
|
12060
|
-
}
|
|
12061
|
-
function getInitiativeContext(dir, ini) {
|
|
12062
|
-
return {
|
|
12063
|
-
initiative: {
|
|
12064
|
-
id: ini.id,
|
|
12065
|
-
title: ini.title,
|
|
12066
|
-
status: ini.status,
|
|
12067
|
-
horizon: ini.horizon,
|
|
12068
|
-
priority: ini.priority,
|
|
12069
|
-
knowledgeLevel: ini.knowledgeLevel,
|
|
12070
|
-
domains: ini.domains,
|
|
12071
|
-
relatedCapabilities: ini.relatedCapabilities,
|
|
12072
|
-
source: ini.source,
|
|
12073
|
-
sourceId: ini.sourceId
|
|
12074
|
-
},
|
|
12075
|
-
progress: computeInitiativeProgress(dir, ini),
|
|
12076
|
-
candidates: {
|
|
12077
|
-
total: ini.candidates.length,
|
|
12078
|
-
materialized: ini.candidates.filter((c) => c.materializedAs),
|
|
12079
|
-
pending: ini.candidates.filter((c) => !c.materializedAs)
|
|
12080
|
-
},
|
|
12081
|
-
workItems: associatedWorkItems(dir, ini.id),
|
|
12082
|
-
externalLinks: ini.externalLinks
|
|
12083
|
-
};
|
|
12084
|
-
}
|
|
12085
|
-
|
|
12086
12124
|
// src/core/initiative-write.ts
|
|
12087
12125
|
import matter11 from "gray-matter";
|
|
12088
12126
|
var WORK_ITEMS_DIR2 = "knowledge/delivery/work-items";
|
|
@@ -12115,6 +12153,7 @@ function externalLinkToData(l) {
|
|
|
12115
12153
|
const out = { integration: l.integration, external_id: l.externalId };
|
|
12116
12154
|
if (l.externalType) out.external_type = l.externalType;
|
|
12117
12155
|
if (l.url) out.url = l.url;
|
|
12156
|
+
if (l.externalStatus) out.external_status = l.externalStatus;
|
|
12118
12157
|
return out;
|
|
12119
12158
|
}
|
|
12120
12159
|
function normalizeCandidate(input, fallbackId) {
|
|
@@ -12267,6 +12306,27 @@ function updateInitiative(dir, id, patch) {
|
|
|
12267
12306
|
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after update.");
|
|
12268
12307
|
return updated;
|
|
12269
12308
|
}
|
|
12309
|
+
function addExternalLink(dir, id, link) {
|
|
12310
|
+
const ini = getInitiative(dir, id);
|
|
12311
|
+
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
12312
|
+
if (!link.integration?.trim() || !link.externalId?.trim()) {
|
|
12313
|
+
throw new InitiativeWriteError("External link requires integration and externalId.");
|
|
12314
|
+
}
|
|
12315
|
+
if (ini.externalLinks.some(
|
|
12316
|
+
(l) => l.integration.trim().toLowerCase() === link.integration.trim().toLowerCase() && l.externalId.trim().toLowerCase() === link.externalId.trim().toLowerCase()
|
|
12317
|
+
)) {
|
|
12318
|
+
throw new InitiativeWriteError(`External link ${link.integration}:${link.externalId} already exists on ${id}.`);
|
|
12319
|
+
}
|
|
12320
|
+
const raw = readFile(ini.filePath);
|
|
12321
|
+
const { data, content } = matter11(raw, {});
|
|
12322
|
+
const existing = Array.isArray(data.external_links) ? data.external_links : [];
|
|
12323
|
+
data.external_links = [...existing, externalLinkToData(link)];
|
|
12324
|
+
const newContent = matter11.stringify(content, data);
|
|
12325
|
+
writeFile(ini.filePath, newContent);
|
|
12326
|
+
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
12327
|
+
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after adding an external link.");
|
|
12328
|
+
return updated;
|
|
12329
|
+
}
|
|
12270
12330
|
function nextWorkItemId2(dir) {
|
|
12271
12331
|
const wiDir = join(dir, WORK_ITEMS_DIR2);
|
|
12272
12332
|
let max = 0;
|
|
@@ -12517,6 +12577,7 @@ export {
|
|
|
12517
12577
|
WorkItemNotReadyError,
|
|
12518
12578
|
WorkItemWriteError,
|
|
12519
12579
|
addCandidate,
|
|
12580
|
+
addExternalLink,
|
|
12520
12581
|
analyzeCrossRepoEvidence,
|
|
12521
12582
|
analyzeInitiative,
|
|
12522
12583
|
analyzeScopeCoverage,
|
|
@@ -12604,6 +12665,7 @@ export {
|
|
|
12604
12665
|
removeIntegrationSecret,
|
|
12605
12666
|
searchSystemNodes,
|
|
12606
12667
|
setIntegrationSecret,
|
|
12668
|
+
suggestInitiativesForExternalItem,
|
|
12607
12669
|
topologyRevision,
|
|
12608
12670
|
transitionInitiative,
|
|
12609
12671
|
transitionWorkItem,
|