@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
@@ -1,5 +1,5 @@
1
1
  import '../chunk-ZKLT27T4.mjs';
2
- export { CIO_CODE_RE, CONCEPT_CODE_RE, LEARNER_CLAUSE, SIO_CODE_RE, ULO_CODE_RE, assignConceptCodes, auditDepthLayers, auditPhasePlan, auditSyllabusCoverage, breakPrerequisiteCycles, cioActionSlug, cioCode, conceptCodeFromName, detectPrerequisiteCycles, escalateAndMapConcepts, extractFeatureSteps, extractFeatureStepsBatched, extractProjectOverview, extractScaffold, generateHybridGraph, generateKnowledgeGraph, sioCode, standardStatement, techTagFor, uloCode, verifyKnowledgeGraph, verifyProjectGraph } from '../chunk-HILSUZOF.mjs';
2
+ export { CIO_CODE_RE, CONCEPT_CODE_RE, LEARNER_CLAUSE, SIO_CODE_RE, ULO_CODE_RE, assignConceptCodes, auditDepthLayers, auditPhasePlan, auditSyllabusCoverage, breakPrerequisiteCycles, cioActionSlug, cioCode, conceptCodeFromName, detectPrerequisiteCycles, escalateAndMapConcepts, extractFeatureSteps, extractFeatureStepsBatched, extractProjectOverview, extractScaffold, generateHybridGraph, generateKnowledgeGraph, sioCode, standardStatement, techTagFor, uloCode, verifyKnowledgeGraph, verifyProjectGraph } from '../chunk-TYXSJUQU.mjs';
3
3
  import '../chunk-T4Y2DE2W.mjs';
4
4
  //# sourceMappingURL=index.mjs.map
5
5
  //# sourceMappingURL=index.mjs.map
package/dist/index.cjs CHANGED
@@ -109,6 +109,15 @@ var init_curriculumFeedSchema = __esm({
109
109
  reason: zod.z.string().default("")
110
110
  })).optional(),
111
111
  is_core: zod.z.boolean().default(false),
112
+ // Depth layer text (optional, additive — old feeds validate unchanged).
113
+ // Carries the ULO/CIO/SIO authored text from the KnowledgeGraph concept
114
+ // so downstream consumers (KX generator) can inject depth-appropriate
115
+ // material into their prompts without a second LLM call.
116
+ depth_context: zod.z.object({
117
+ ulo: zod.z.string().default(""),
118
+ cio: zod.z.string().default(""),
119
+ sio: zod.z.array(zod.z.string()).default([])
120
+ }).optional(),
112
121
  // Progressive-completion bookkeeping (feed v2, additive):
113
122
  // phase_id = development phase that introduces/uses this node;
114
123
  // introduce_aspect = how the phase teaches a concept node (first intro, advanced
@@ -262,6 +271,11 @@ function feedNodeFromConcept(concept) {
262
271
  // concepts are taught, not shipped — checkpoints live on product steps
263
272
  ...deriveDepthInputs(Math.max(0, Math.round(num(concept.estimated_minutes, 15))), deriveConceptDepthHint(concept)),
264
273
  is_core: false,
274
+ depth_context: {
275
+ ulo: str(concept.ulo),
276
+ cio: str(concept.cio),
277
+ sio: strs(concept.sio)
278
+ },
265
279
  phase_id: "",
266
280
  introduce_aspect: null
267
281
  };
@@ -4716,7 +4730,42 @@ async function generateKnowledgeGraph(options) {
4716
4730
  const structuredTopicsGuide = parsedSyllabus && parsedSyllabus.allTopics.length > 0 ? `
4717
4731
  STRUCTURED SYLLABUS TOPICS (Every topic MUST map to at least one concept to ensure 100% syllabus coverage):
4718
4732
  ` + parsedSyllabus.allTopics.map((t) => `- [${t.unitTitle}] ${t.id}: ${t.title} (Keywords: ${t.keywords.join(", ")})`).join("\n") + "\n" : "";
4719
- 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";
4733
+ const systemPrompt = `You are an expert curriculum designer. Decompose the given subject into a structured knowledge graph with concepts, prerequisites, and problem types.
4734
+
4735
+ CRITICAL RULES:
4736
+ 1. Each concept MUST have the three depth layers, authored against this CONTRACT:
4737
+ - ulo (WHAT + WHY): bound to the CONCEPT's intrinsic NATURE. It explains what the
4738
+ concept is and why it exists \u2014 the problem it solves in principle. It must be
4739
+ TECHNOLOGY-AGNOSTIC: never name a concrete library, API, function, file format,
4740
+ tool or language feature. Typical assessment level: Remember / Understand.
4741
+ - cio (HOW): the MECHANISM \u2014 how the concept works and solves that problem, step
4742
+ by step. Still bound to the concept's nature: more concrete than the ULO, but
4743
+ NOT tied to one specific technology (no concrete API names). CIO capability is
4744
+ assessed INDIRECTLY, through completing contextual work, not in isolation.
4745
+ - sio (IMPLEMENTATION): an array of 2-4 items. EVERY item MUST reference concrete
4746
+ KEYWORDS/technologies (a real API, function, module, file, or named pattern) and
4747
+ describe a completable, context-specific implementation task. Application,
4748
+ Analysis and Creation skills are assessed INDIRECTLY through completing these
4749
+ items. There is NO fixed Bloom ceiling for a layer \u2014 but concreteness MUST
4750
+ strictly increase: SIO more technology-bound than CIO, CIO more concrete than ULO.
4751
+ - prerequisites: concept IDs that must be learned first (MUST NOT create cycles)
4752
+ - problem_types: 2-4 problem types with bloom_level and difficulty. Remember and
4753
+ Understand problem types test the ULO/CIO directly; Apply-and-above types are
4754
+ proxies for SIO completion in context.
4755
+ - techniques: methods, formulas, tools
4756
+ 2. Prerequisite chains MUST be acyclic (no concept can depend on itself or create a loop)
4757
+ 3. Concepts should be ordered by prerequisite dependency (topological sort)
4758
+ 4. Problem types should range from Remember to Apply (not all at same level)
4759
+ 5. Group concepts into categories (chapters/sections)
4760
+ 6. ALL text in ENGLISH (even if input is Vietnamese)
4761
+ 7. NEVER invent concepts not present in the syllabus
4762
+ 8. KEYWORDS: Each concept MUST include 5-10 domain-specific keywords that:
4763
+ - Are concrete terms a student encounters when studying THIS concept
4764
+ - Include at least 2 technology-specific terms (APIs, functions, types, tools)
4765
+ - Are DISTINCT from keywords of other concepts (minimal overlap)
4766
+ - NEVER generic English words (e.g. "view", "data", "code" are TOO generic)
4767
+ - Example for "SwiftUI Layout": ["VStack", "HStack", "ZStack", ".padding()", ".frame()", "alignment", "Spacer", "LazyVGrid"]
4768
+ 9. Return JSON matching the KnowledgeGraphSchema`;
4720
4769
  const userPrompt = `Subject: ${subject}
4721
4770
  ${description ? `Description: ${description}` : ""}
4722
4771
  ${structuredTopicsGuide}${truncatedSyllabus ? `Syllabus:
@@ -4737,8 +4786,9 @@ Return JSON:
4737
4786
  {
4738
4787
  "id": "C1",
4739
4788
  "name": "Concept name",
4740
- "description": "Brief description",
4789
+ "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.",
4741
4790
  "category": "category_id",
4791
+ "keywords": ["specific_term_1", "concrete_api_2", "method_call_3", "tool_or_type_4", "syntax_keyword_5", "concept_term_6"],
4742
4792
  "ulo": "WHAT + WHY in technology-agnostic language: what the concept is and the problem it exists to solve. No library/API/tool names.",
4743
4793
  "cio": "HOW the mechanism works, still technology-agnostic but more concrete than the ULO.",
4744
4794
  "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"],
@@ -4779,18 +4829,23 @@ Return JSON:
4779
4829
  log("STEP_2", "Validating and cleaning knowledge graph...");
4780
4830
  const concepts = result.concepts || [];
4781
4831
  const categories = result.categories || [];
4832
+ for (const c of concepts) {
4833
+ if ((c.description || "").length < 50) {
4834
+ warnings.push("Concept " + c.id + ": description too short (" + (c.description || "").length + " chars) \u2014 may produce shallow KX narratives");
4835
+ }
4836
+ }
4782
4837
  {
4783
4838
  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"]);
4784
4839
  const tokensFrom = (text) => text.toLowerCase().replace(/[^a-z0-9\s-]/g, " ").split(/\s+/).filter((w) => w.length >= 4 && !STOP.has(w));
4785
4840
  for (const c of concepts) {
4786
4841
  const existing = (c.keywords || []).map((k) => String(k).trim()).filter(Boolean);
4787
4842
  if (existing.length === 0) {
4788
- const derived = [.../* @__PURE__ */ new Set([...tokensFrom(c.name), ...tokensFrom(c.description || "")])].slice(0, 5);
4843
+ const derived = [.../* @__PURE__ */ new Set([...tokensFrom(c.name), ...tokensFrom(c.description || "")])].slice(0, 8);
4789
4844
  if (derived.length === 0) {
4790
4845
  throw new Error("Concept " + c.id + " (" + c.name + ") has no keywords and none could be derived from name/description \u2014 fail-closed");
4791
4846
  }
4792
4847
  c.keywords = derived;
4793
- warnings.push("Concept " + c.id + ": empty keyword set - derived " + derived.join(", ") + " from name/description");
4848
+ warnings.push("Concept " + c.id + ": empty keyword set - derived " + derived.join(", ") + " from name/description (WARNING: LLM returned no keywords)");
4794
4849
  } else {
4795
4850
  c.keywords = existing;
4796
4851
  }
@@ -4915,6 +4970,52 @@ Return JSON:
4915
4970
  }
4916
4971
  log("STEP_5", "Depth layers authored: " + concepts.length + " concepts, audit " + lo.audits.filter((a) => a.passed).length + "/" + concepts.length + " passed");
4917
4972
  }
4973
+ {
4974
+ for (const concept of concepts) {
4975
+ const sioText = (concept.sio || []).join(" ");
4976
+ const techTokens = [];
4977
+ let m;
4978
+ const techTokenRe = /`([^`]+)`/g;
4979
+ while ((m = techTokenRe.exec(sioText)) !== null) {
4980
+ if (m[1].length >= 3 && m[1].length <= 40) techTokens.push(m[1]);
4981
+ }
4982
+ const annotationRe = /(?:^|[\s(])(@[A-Za-z]\w*)/g;
4983
+ while ((m = annotationRe.exec(sioText)) !== null) techTokens.push(m[1]);
4984
+ const dotRe = /\b\w+\.\w+\(/g;
4985
+ while ((m = dotRe.exec(sioText)) !== null) techTokens.push(m[0].replace("(", ""));
4986
+ const modifierRe = /(?:^|[\s(])(\.[a-z]\w*)\b/g;
4987
+ while ((m = modifierRe.exec(sioText)) !== null) techTokens.push(m[1]);
4988
+ const camelRe = /\b[a-z]+[A-Z][A-Za-z]+\b/g;
4989
+ while ((m = camelRe.exec(sioText)) !== null) techTokens.push(m[0]);
4990
+ const existing = new Set((concept.keywords || []).map((k) => k.toLowerCase()));
4991
+ const newTokens = [...new Set(techTokens)].filter((t) => !existing.has(t.toLowerCase())).slice(0, 8);
4992
+ if (newTokens.length > 0) {
4993
+ concept.keywords = [...concept.keywords || [], ...newTokens];
4994
+ warnings.push("Concept " + concept.id + ": enriched keywords with " + newTokens.length + " SIO-derived tokens");
4995
+ }
4996
+ }
4997
+ log("STEP_5b", "SIO-keyword enrichment complete");
4998
+ }
4999
+ {
5000
+ for (const concept of concepts) {
5001
+ const sioCount = (concept.sio || []).length;
5002
+ const ptCount = (concept.problem_types || []).length;
5003
+ const prereqCount = (concept.prerequisites || []).length;
5004
+ const hasHighBloom = (concept.problem_types || []).some(
5005
+ (pt) => ["Analyze", "Evaluate", "Create"].includes(pt.bloom_level || "")
5006
+ );
5007
+ const score = Math.min(1, sioCount * 0.2 + ptCount * 0.15 + prereqCount * 0.15 + (hasHighBloom ? 0.2 : 0));
5008
+ const calibrated = Math.round(15 + score * 45);
5009
+ const llmEstimate = concept.estimated_minutes || 30;
5010
+ if (llmEstimate === 30 || Math.abs(calibrated - llmEstimate) / llmEstimate > 0.5) {
5011
+ concept.estimated_minutes = calibrated;
5012
+ if (llmEstimate !== calibrated) {
5013
+ warnings.push("Concept " + concept.id + ": minutes calibrated " + llmEstimate + "m \u2192 " + calibrated + "m (score=" + score.toFixed(2) + ")");
5014
+ }
5015
+ }
5016
+ }
5017
+ log("STEP_5c", "Minute calibration complete");
5018
+ }
4918
5019
  for (const step of learningPath) {
4919
5020
  if (!conceptIds.has(step.concept_id)) {
4920
5021
  warnings.push(`Learning path references non-existent concept ${step.concept_id}`);
@@ -5180,8 +5281,12 @@ async function decomposePhases(args) {
5180
5281
  const linkList = links.map(
5181
5282
  (l) => "- " + l.feature_id + " -> " + l.concept_id + " (" + l.depth + ")"
5182
5283
  ).join("\n") || "(none)";
5183
- 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.';
5184
- 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";
5284
+ 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.';
5285
+ const totalFeatureMinutes = features.reduce((s, f) => s + (f.steps || []).reduce((ss, st) => ss + (st.effort?.estimated_minutes || 15), 0), 0);
5286
+ const totalConceptMinutes = concepts.reduce((s, c) => s + (c.estimated_minutes || 30), 0);
5287
+ const totalMinutes = totalFeatureMinutes + totalConceptMinutes;
5288
+ const targetPhaseCount = Math.max(3, Math.round(totalMinutes / 180));
5289
+ 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";
5185
5290
  const MAX_DECOMPOSE_ATTEMPTS = 3;
5186
5291
  let auditErrors = [];
5187
5292
  let phases = [];