@thanh01.pmt/domain-kit 0.4.0 → 0.5.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.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/dist/{chunk-PKUEOSZ3.mjs → chunk-E4GCCWJO.mjs} +11 -2
  3. package/dist/chunk-E4GCCWJO.mjs.map +1 -0
  4. package/dist/{chunk-LZQLLAYP.mjs → chunk-G7HLFMD2.mjs} +5 -5
  5. package/dist/{chunk-LZQLLAYP.mjs.map → chunk-G7HLFMD2.mjs.map} +1 -1
  6. package/dist/{chunk-QJF4QCBJ.mjs → chunk-TWKIVUTQ.mjs} +8 -3
  7. package/dist/chunk-TWKIVUTQ.mjs.map +1 -0
  8. package/dist/{chunk-HILSUZOF.mjs → chunk-TYXSJUQU.mjs} +99 -8
  9. package/dist/chunk-TYXSJUQU.mjs.map +1 -0
  10. package/dist/curriculumFeedEmitter-T7NUBLAM.mjs +4 -0
  11. package/dist/{curriculumFeedEmitter-6IK6PFDH.mjs.map → curriculumFeedEmitter-T7NUBLAM.mjs.map} +1 -1
  12. package/dist/{curriculumFeedSchema-B66H3gEV.d.ts → curriculumFeedSchema-DUFwFyr2.d.cts} +56 -0
  13. package/dist/{curriculumFeedSchema-B66H3gEV.d.cts → curriculumFeedSchema-DUFwFyr2.d.ts} +56 -0
  14. package/dist/feed/index.cjs +14 -0
  15. package/dist/feed/index.cjs.map +1 -1
  16. package/dist/feed/index.d.cts +1 -1
  17. package/dist/feed/index.d.ts +1 -1
  18. package/dist/feed/index.mjs +2 -2
  19. package/dist/graph/index.cjs +97 -6
  20. package/dist/graph/index.cjs.map +1 -1
  21. package/dist/graph/index.mjs +1 -1
  22. package/dist/index.cjs +111 -6
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +1 -1
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.mjs +4 -4
  27. package/dist/pipeline/index.cjs +111 -6
  28. package/dist/pipeline/index.cjs.map +1 -1
  29. package/dist/pipeline/index.d.cts +1 -1
  30. package/dist/pipeline/index.d.ts +1 -1
  31. package/dist/pipeline/index.mjs +4 -4
  32. package/dist/schemas/index.cjs +9 -0
  33. package/dist/schemas/index.cjs.map +1 -1
  34. package/dist/schemas/index.d.cts +1 -1
  35. package/dist/schemas/index.d.ts +1 -1
  36. package/dist/schemas/index.mjs +1 -1
  37. package/package.json +9 -10
  38. package/dist/chunk-HILSUZOF.mjs.map +0 -1
  39. package/dist/chunk-PKUEOSZ3.mjs.map +0 -1
  40. package/dist/chunk-QJF4QCBJ.mjs.map +0 -1
  41. package/dist/curriculumFeedEmitter-6IK6PFDH.mjs +0 -4
@@ -1778,7 +1778,42 @@ async function generateKnowledgeGraph(options) {
1778
1778
  const structuredTopicsGuide = parsedSyllabus && parsedSyllabus.allTopics.length > 0 ? `
1779
1779
  STRUCTURED SYLLABUS TOPICS (Every topic MUST map to at least one concept to ensure 100% syllabus coverage):
1780
1780
  ` + parsedSyllabus.allTopics.map((t) => `- [${t.unitTitle}] ${t.id}: ${t.title} (Keywords: ${t.keywords.join(", ")})`).join("\n") + "\n" : "";
1781
- const systemPrompt = "You are an expert curriculum designer. Decompose the given subject into a structured knowledge graph with concepts, prerequisites, and problem types.\n\nCRITICAL RULES:\n1. Each concept MUST have the three depth layers, authored against this CONTRACT:\n - ulo (WHAT + WHY): bound to the CONCEPT's intrinsic NATURE. It explains what the\n concept is and why it exists \u2014 the problem it solves in principle. It must be\n TECHNOLOGY-AGNOSTIC: never name a concrete library, API, function, file format,\n tool or language feature. Typical assessment level: Remember / Understand.\n - cio (HOW): the MECHANISM \u2014 how the concept works and solves that problem, step\n by step. Still bound to the concept's nature: more concrete than the ULO, but\n NOT tied to one specific technology (no concrete API names). CIO capability is\n assessed INDIRECTLY, through completing contextual work, not in isolation.\n - sio (IMPLEMENTATION): an array of 2-4 items. EVERY item MUST reference concrete\n KEYWORDS/technologies (a real API, function, module, file, or named pattern) and\n describe a completable, context-specific implementation task. Application,\n Analysis and Creation skills are assessed INDIRECTLY through completing these\n items. There is NO fixed Bloom ceiling for a layer \u2014 but concreteness MUST\n strictly increase: SIO more technology-bound than CIO, CIO more concrete than ULO.\n - prerequisites: concept IDs that must be learned first (MUST NOT create cycles)\n - problem_types: 2-4 problem types with bloom_level and difficulty. Remember and\n Understand problem types test the ULO/CIO directly; Apply-and-above types are\n proxies for SIO completion in context.\n - techniques: methods, formulas, tools\n2. Prerequisite chains MUST be acyclic (no concept can depend on itself or create a loop)\n3. Concepts should be ordered by prerequisite dependency (topological sort)\n4. Problem types should range from Remember to Apply (not all at same level)\n5. Group concepts into categories (chapters/sections)\n6. ALL text in ENGLISH (even if input is Vietnamese)\n7. NEVER invent concepts not present in the syllabus\n8. Return JSON matching the KnowledgeGraphSchema";
1781
+ const systemPrompt = `You are an expert curriculum designer. Decompose the given subject into a structured knowledge graph with concepts, prerequisites, and problem types.
1782
+
1783
+ CRITICAL RULES:
1784
+ 1. Each concept MUST have the three depth layers, authored against this CONTRACT:
1785
+ - ulo (WHAT + WHY): bound to the CONCEPT's intrinsic NATURE. It explains what the
1786
+ concept is and why it exists \u2014 the problem it solves in principle. It must be
1787
+ TECHNOLOGY-AGNOSTIC: never name a concrete library, API, function, file format,
1788
+ tool or language feature. Typical assessment level: Remember / Understand.
1789
+ - cio (HOW): the MECHANISM \u2014 how the concept works and solves that problem, step
1790
+ by step. Still bound to the concept's nature: more concrete than the ULO, but
1791
+ NOT tied to one specific technology (no concrete API names). CIO capability is
1792
+ assessed INDIRECTLY, through completing contextual work, not in isolation.
1793
+ - sio (IMPLEMENTATION): an array of 2-4 items. EVERY item MUST reference concrete
1794
+ KEYWORDS/technologies (a real API, function, module, file, or named pattern) and
1795
+ describe a completable, context-specific implementation task. Application,
1796
+ Analysis and Creation skills are assessed INDIRECTLY through completing these
1797
+ items. There is NO fixed Bloom ceiling for a layer \u2014 but concreteness MUST
1798
+ strictly increase: SIO more technology-bound than CIO, CIO more concrete than ULO.
1799
+ - prerequisites: concept IDs that must be learned first (MUST NOT create cycles)
1800
+ - problem_types: 2-4 problem types with bloom_level and difficulty. Remember and
1801
+ Understand problem types test the ULO/CIO directly; Apply-and-above types are
1802
+ proxies for SIO completion in context.
1803
+ - techniques: methods, formulas, tools
1804
+ 2. Prerequisite chains MUST be acyclic (no concept can depend on itself or create a loop)
1805
+ 3. Concepts should be ordered by prerequisite dependency (topological sort)
1806
+ 4. Problem types should range from Remember to Apply (not all at same level)
1807
+ 5. Group concepts into categories (chapters/sections)
1808
+ 6. ALL text in ENGLISH (even if input is Vietnamese)
1809
+ 7. NEVER invent concepts not present in the syllabus
1810
+ 8. KEYWORDS: Each concept MUST include 5-10 domain-specific keywords that:
1811
+ - Are concrete terms a student encounters when studying THIS concept
1812
+ - Include at least 2 technology-specific terms (APIs, functions, types, tools)
1813
+ - Are DISTINCT from keywords of other concepts (minimal overlap)
1814
+ - NEVER generic English words (e.g. "view", "data", "code" are TOO generic)
1815
+ - Example for "SwiftUI Layout": ["VStack", "HStack", "ZStack", ".padding()", ".frame()", "alignment", "Spacer", "LazyVGrid"]
1816
+ 9. Return JSON matching the KnowledgeGraphSchema`;
1782
1817
  const userPrompt = `Subject: ${subject}
1783
1818
  ${description ? `Description: ${description}` : ""}
1784
1819
  ${structuredTopicsGuide}${truncatedSyllabus ? `Syllabus:
@@ -1799,8 +1834,9 @@ Return JSON:
1799
1834
  {
1800
1835
  "id": "C1",
1801
1836
  "name": "Concept name",
1802
- "description": "Brief description",
1837
+ "description": "2-3 sentence description: what this concept covers, why a learner encounters it, and what mastering it enables. Must be specific enough that a student reading only this description understands the concept's scope.",
1803
1838
  "category": "category_id",
1839
+ "keywords": ["specific_term_1", "concrete_api_2", "method_call_3", "tool_or_type_4", "syntax_keyword_5", "concept_term_6"],
1804
1840
  "ulo": "WHAT + WHY in technology-agnostic language: what the concept is and the problem it exists to solve. No library/API/tool names.",
1805
1841
  "cio": "HOW the mechanism works, still technology-agnostic but more concrete than the ULO.",
1806
1842
  "sio": ["Concrete task naming a REAL API/function/module/file from the target technology, completable end to end", "Another technology-bound task using a different concrete keyword"],
@@ -1841,18 +1877,23 @@ Return JSON:
1841
1877
  log("STEP_2", "Validating and cleaning knowledge graph...");
1842
1878
  const concepts = result.concepts || [];
1843
1879
  const categories = result.categories || [];
1880
+ for (const c of concepts) {
1881
+ if ((c.description || "").length < 50) {
1882
+ warnings.push("Concept " + c.id + ": description too short (" + (c.description || "").length + " chars) \u2014 may produce shallow KX narratives");
1883
+ }
1884
+ }
1844
1885
  {
1845
1886
  const STOP = /* @__PURE__ */ new Set(["and", "the", "for", "with", "from", "that", "this", "into", "when", "while", "using", "their", "your", "each", "how", "why", "what", "between", "through", "about"]);
1846
1887
  const tokensFrom = (text) => text.toLowerCase().replace(/[^a-z0-9\s-]/g, " ").split(/\s+/).filter((w) => w.length >= 4 && !STOP.has(w));
1847
1888
  for (const c of concepts) {
1848
1889
  const existing = (c.keywords || []).map((k) => String(k).trim()).filter(Boolean);
1849
1890
  if (existing.length === 0) {
1850
- const derived = [.../* @__PURE__ */ new Set([...tokensFrom(c.name), ...tokensFrom(c.description || "")])].slice(0, 5);
1891
+ const derived = [.../* @__PURE__ */ new Set([...tokensFrom(c.name), ...tokensFrom(c.description || "")])].slice(0, 8);
1851
1892
  if (derived.length === 0) {
1852
1893
  throw new Error("Concept " + c.id + " (" + c.name + ") has no keywords and none could be derived from name/description \u2014 fail-closed");
1853
1894
  }
1854
1895
  c.keywords = derived;
1855
- warnings.push("Concept " + c.id + ": empty keyword set - derived " + derived.join(", ") + " from name/description");
1896
+ warnings.push("Concept " + c.id + ": empty keyword set - derived " + derived.join(", ") + " from name/description (WARNING: LLM returned no keywords)");
1856
1897
  } else {
1857
1898
  c.keywords = existing;
1858
1899
  }
@@ -1977,6 +2018,52 @@ Return JSON:
1977
2018
  }
1978
2019
  log("STEP_5", "Depth layers authored: " + concepts.length + " concepts, audit " + lo.audits.filter((a) => a.passed).length + "/" + concepts.length + " passed");
1979
2020
  }
2021
+ {
2022
+ for (const concept of concepts) {
2023
+ const sioText = (concept.sio || []).join(" ");
2024
+ const techTokens = [];
2025
+ let m;
2026
+ const techTokenRe = /`([^`]+)`/g;
2027
+ while ((m = techTokenRe.exec(sioText)) !== null) {
2028
+ if (m[1].length >= 3 && m[1].length <= 40) techTokens.push(m[1]);
2029
+ }
2030
+ const annotationRe = /(?:^|[\s(])(@[A-Za-z]\w*)/g;
2031
+ while ((m = annotationRe.exec(sioText)) !== null) techTokens.push(m[1]);
2032
+ const dotRe = /\b\w+\.\w+\(/g;
2033
+ while ((m = dotRe.exec(sioText)) !== null) techTokens.push(m[0].replace("(", ""));
2034
+ const modifierRe = /(?:^|[\s(])(\.[a-z]\w*)\b/g;
2035
+ while ((m = modifierRe.exec(sioText)) !== null) techTokens.push(m[1]);
2036
+ const camelRe = /\b[a-z]+[A-Z][A-Za-z]+\b/g;
2037
+ while ((m = camelRe.exec(sioText)) !== null) techTokens.push(m[0]);
2038
+ const existing = new Set((concept.keywords || []).map((k) => k.toLowerCase()));
2039
+ const newTokens = [...new Set(techTokens)].filter((t) => !existing.has(t.toLowerCase())).slice(0, 8);
2040
+ if (newTokens.length > 0) {
2041
+ concept.keywords = [...concept.keywords || [], ...newTokens];
2042
+ warnings.push("Concept " + concept.id + ": enriched keywords with " + newTokens.length + " SIO-derived tokens");
2043
+ }
2044
+ }
2045
+ log("STEP_5b", "SIO-keyword enrichment complete");
2046
+ }
2047
+ {
2048
+ for (const concept of concepts) {
2049
+ const sioCount = (concept.sio || []).length;
2050
+ const ptCount = (concept.problem_types || []).length;
2051
+ const prereqCount = (concept.prerequisites || []).length;
2052
+ const hasHighBloom = (concept.problem_types || []).some(
2053
+ (pt) => ["Analyze", "Evaluate", "Create"].includes(pt.bloom_level || "")
2054
+ );
2055
+ const score = Math.min(1, sioCount * 0.2 + ptCount * 0.15 + prereqCount * 0.15 + (hasHighBloom ? 0.2 : 0));
2056
+ const calibrated = Math.round(15 + score * 45);
2057
+ const llmEstimate = concept.estimated_minutes || 30;
2058
+ if (llmEstimate === 30 || Math.abs(calibrated - llmEstimate) / llmEstimate > 0.5) {
2059
+ concept.estimated_minutes = calibrated;
2060
+ if (llmEstimate !== calibrated) {
2061
+ warnings.push("Concept " + concept.id + ": minutes calibrated " + llmEstimate + "m \u2192 " + calibrated + "m (score=" + score.toFixed(2) + ")");
2062
+ }
2063
+ }
2064
+ }
2065
+ log("STEP_5c", "Minute calibration complete");
2066
+ }
1980
2067
  for (const step of learningPath) {
1981
2068
  if (!conceptIds.has(step.concept_id)) {
1982
2069
  warnings.push(`Learning path references non-existent concept ${step.concept_id}`);
@@ -2242,8 +2329,12 @@ async function decomposePhases(args) {
2242
2329
  const linkList = links.map(
2243
2330
  (l) => "- " + l.feature_id + " -> " + l.concept_id + " (" + l.depth + ")"
2244
2331
  ).join("\n") || "(none)";
2245
- const systemPrompt = 'You decompose a software project build into PROGRESSIVE COMPLETION PHASES for learning purposes.\n\nA phase is NOT a feature and NOT a milestone list: it is a cross-feature slice of the\nproduct whose completion yields a DEMONSTRABLY more complete product. Build up gradually:\nthe product grows feature by feature across phases, and each phase adds its features to\nwhat previous phases already built.\n\nRULES:\n1. Every feature must be assigned to EXACTLY ONE phase (no feature reused, none skipped).\n2. Phases are ordered; later phases depend on earlier ones and yield a more complete product.\n3. product_completion describes concretely what the product can DO once the phase is done.\n4. introduces lists which concepts the phase must teach BEFORE its feature work starts:\n - aspect new: first time the concept appears in the course\n - aspect advanced: a concept introduced in an EARLIER phase, revisited here at a\n higher depth (an advanced aspect of the same concept, e.g. validation rules on top\n of basic data modeling). Use the note field to say which aspect.\n - aspect preview: a light awareness pass ("know it exists", ULO depth only, ~5 min)\n placed in an EARLIER phase when its feature work needs the vocabulary before the\n full teach. The anchor phase still owns the full new introduction.\n5. A concept MUST be introduced (new) no later than the first phase that consumes it.\n6. A concept must not be introduced before its own prerequisites are introduced.\n7. Typically 3-6 phases for a small project; keep phases balanced.\n8. Phase 1 usually covers project setup/foundation features plus the first minimal slice.\n9. Return JSON only.';
2246
- const baseUserPrompt = "FEATURES:\n" + featureList + "\n\nCONCEPTS:\n" + conceptList + "\n\nFEATURE-CONCEPT LINKS:\n" + linkList + "\n\nReturn JSON with a phases array. Each phase: { id: PH1, name, product_completion, feature_ids: [F0, F1], introduces: [{ concept_id: C1, aspect: new or advanced, note }] }.\n";
2332
+ const systemPrompt = 'You decompose a software project build into PROGRESSIVE COMPLETION PHASES for learning purposes.\n\nA phase is NOT a feature and NOT a milestone list: it is a cross-feature slice of the\nproduct whose completion yields a DEMONSTRABLY more complete product. Build up gradually:\nthe product grows feature by feature across phases, and each phase adds its features to\nwhat previous phases already built.\n\nRULES:\n1. Every feature must be assigned to EXACTLY ONE phase (no feature reused, none skipped).\n2. Phases are ordered; later phases depend on earlier ones and yield a more complete product.\n3. product_completion describes concretely what the product can DO once the phase is done.\n4. introduces lists which concepts the phase must teach BEFORE its feature work starts:\n - aspect new: first time the concept appears in the course\n - aspect advanced: a concept introduced in an EARLIER phase, revisited here at a\n higher depth (an advanced aspect of the same concept, e.g. validation rules on top\n of basic data modeling). Use the note field to say which aspect.\n - aspect preview: a light awareness pass ("know it exists", ULO depth only, ~5 min)\n placed in an EARLIER phase when its feature work needs the vocabulary before the\n full teach. The anchor phase still owns the full new introduction.\n5. A concept MUST be introduced (new) no later than the first phase that consumes it.\n6. A concept must not be introduced before its own prerequisites are introduced.\n7. Typically 3-6 phases for a small project; keep phases balanced.\n8. MINUTE BALANCE: Each phase should contain approximately 120-240 total minutes of\n concept + feature work (about 3-5 sessions of 90 minutes each). If a phase\n would contain < 60 minutes (too thin) or > 400 minutes (too heavy), rebalance.\n9. Phase 1 usually covers project setup/foundation features plus the first minimal slice.\n10. Return JSON only.';
2333
+ const totalFeatureMinutes = features.reduce((s, f) => s + (f.steps || []).reduce((ss, st) => ss + (st.effort?.estimated_minutes || 15), 0), 0);
2334
+ const totalConceptMinutes = concepts.reduce((s, c) => s + (c.estimated_minutes || 30), 0);
2335
+ const totalMinutes = totalFeatureMinutes + totalConceptMinutes;
2336
+ const targetPhaseCount = Math.max(3, Math.round(totalMinutes / 180));
2337
+ const baseUserPrompt = "FEATURES:\n" + featureList + "\n\nCONCEPTS:\n" + conceptList + "\n\nFEATURE-CONCEPT LINKS:\n" + linkList + "\n\nTOTAL MINUTES: ~" + totalMinutes + "m (" + totalFeatureMinutes + "m features + " + totalConceptMinutes + "m concepts)\nTARGET: ~" + targetPhaseCount + " phases of ~180m each\n\nReturn JSON with a phases array. Each phase: { id: PH1, name, product_completion, feature_ids: [F0, F1], introduces: [{ concept_id: C1, aspect: new or advanced, note }] }.\n";
2247
2338
  const MAX_DECOMPOSE_ATTEMPTS = 3;
2248
2339
  let auditErrors = [];
2249
2340
  let phases = [];
@@ -2281,5 +2372,5 @@ async function decomposePhases(args) {
2281
2372
  }
2282
2373
 
2283
2374
  export { CIO_CODE_RE, CONCEPT_CODE_RE, LEARNER_CLAUSE, SIO_CODE_RE, ULO_CODE_RE, assignConceptCodes, auditDepthLayers, auditPhasePlan, auditSyllabusCoverage, breakPrerequisiteCycles, cioActionSlug, cioCode, conceptCodeFromName, createLlmClient, detectPrerequisiteCycles, escalateAndMapConcepts, extractFeatureSteps, extractFeatureStepsBatched, extractProjectOverview, extractScaffold, generateHybridGraph, generateKnowledgeGraph, llmChatJson, sioCode, standardStatement, techTagFor, uloCode, verifyKnowledgeGraph, verifyProjectGraph };
2284
- //# sourceMappingURL=chunk-HILSUZOF.mjs.map
2285
- //# sourceMappingURL=chunk-HILSUZOF.mjs.map
2375
+ //# sourceMappingURL=chunk-TYXSJUQU.mjs.map
2376
+ //# sourceMappingURL=chunk-TYXSJUQU.mjs.map