musubix2 0.5.9 → 0.5.10

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.
@@ -1 +1 @@
1
- {"generator":"musubix2","version":"0.5.9","timestamp":"2026-07-09T10:34:18.313Z"}
1
+ {"generator":"musubix2","version":"0.5.10","timestamp":"2026-07-09T10:42:36.515Z"}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": "1.0",
3
- "generatedAt": "2026-07-09T10:34:18.341Z",
3
+ "generatedAt": "2026-07-09T10:42:36.544Z",
4
4
  "entries": [
5
5
  {
6
6
  "platform": "copilot",
package/dist/cli.js CHANGED
@@ -14431,93 +14431,129 @@ function researchTools() {
14431
14431
  param("depth", "string", "Research depth: shallow | medium | deep", false, "medium")
14432
14432
  ], async (params) => {
14433
14433
  try {
14434
- const research = await Promise.resolve().then(() => (init_dist10(), dist_exports10));
14435
- const result = research.query?.(params["topic"], params["depth"] ?? "medium");
14436
- return ok(result ?? { findings: [], topic: params["topic"] });
14434
+ const { createResearchEngine: createResearchEngine2 } = await Promise.resolve().then(() => (init_dist10(), dist_exports10));
14435
+ const sources = normalizeSources(params["sources"]);
14436
+ const result = createResearchEngine2().research({ topic: params["topic"] ?? "", depth: params["depth"] ?? "medium" }, sources);
14437
+ return ok(result);
14437
14438
  } catch {
14438
- return ok({ findings: [], topic: params["topic"] });
14439
+ return fail("Deep-research package not available");
14439
14440
  }
14440
14441
  }),
14441
- tool("research.iterative", "Perform iterative deep research with progressive refinement", "research", [
14442
+ tool("research.iterative", "Perform iterative research with progressive refinement over provided sources", "research", [
14442
14443
  param("topic", "string", "Research topic"),
14443
- param("iterations", "number", "Number of refinement iterations", false, 3)
14444
+ param("depth", "string", "Depth: shallow | medium | deep", false, "medium"),
14445
+ param("sources", "array", "Sources as {title,type,relevance,content} objects")
14444
14446
  ], async (params) => {
14445
14447
  try {
14446
- const research = await Promise.resolve().then(() => (init_dist10(), dist_exports10));
14447
- const result = research.iterativeResearch?.(params["topic"], params["iterations"] ?? 3);
14448
- return ok(result ?? { findings: [], iterations: 0, topic: params["topic"] });
14448
+ const { createResearchEngine: createResearchEngine2 } = await Promise.resolve().then(() => (init_dist10(), dist_exports10));
14449
+ const sources = normalizeSources(params["sources"]);
14450
+ const result = createResearchEngine2().researchIterative({ topic: params["topic"] ?? "", depth: params["depth"] ?? "medium" }, () => sources);
14451
+ return ok(result);
14449
14452
  } catch {
14450
- return ok({ findings: [], iterations: 0, topic: params["topic"] });
14453
+ return fail("Deep-research package not available");
14451
14454
  }
14452
14455
  }),
14453
- tool("research.evidence", "Generate evidence chain for a claim or hypothesis", "research", [
14454
- param("claim", "string", "Claim or hypothesis to evaluate"),
14455
- param("sources", "array", "Evidence sources to consider", false)
14456
+ tool("research.evidence", "Accumulate research results and retrieve evidence for a topic", "research", [
14457
+ param("topic", "string", "Topic to gather evidence for"),
14458
+ param("sources", "array", "Sources as {title,type,relevance,content} objects")
14456
14459
  ], async (params) => {
14457
14460
  try {
14458
- const research = await Promise.resolve().then(() => (init_dist10(), dist_exports10));
14459
- const result = research.generateEvidence?.(params["claim"], params["sources"]);
14460
- return ok(result ?? { evidence: [], confidence: 0 });
14461
+ const { createResearchEngine: createResearchEngine2, createKnowledgeAccumulator: createKnowledgeAccumulator2 } = await Promise.resolve().then(() => (init_dist10(), dist_exports10));
14462
+ const sources = normalizeSources(params["sources"]);
14463
+ const topic = params["topic"] ?? "";
14464
+ const result = createResearchEngine2().research({ topic, depth: "medium" }, sources);
14465
+ const acc = createKnowledgeAccumulator2();
14466
+ acc.accumulate(result);
14467
+ return ok({ evidence: acc.query(topic), summary: result.summary, confidence: result.confidence });
14461
14468
  } catch {
14462
- return ok({ evidence: [], confidence: 0 });
14469
+ return fail("Deep-research package not available");
14463
14470
  }
14464
14471
  })
14465
14472
  ];
14466
14473
  }
14474
+ function normalizeSources(raw) {
14475
+ const valid = /* @__PURE__ */ new Set(["code", "documentation", "article", "api-reference"]);
14476
+ const arr = Array.isArray(raw) ? raw : [];
14477
+ return arr.map((s, i) => {
14478
+ const o = s ?? {};
14479
+ const t = String(o["type"] ?? "documentation");
14480
+ return {
14481
+ title: String(o["title"] ?? `source-${i + 1}`),
14482
+ type: valid.has(t) ? t : "documentation",
14483
+ relevance: typeof o["relevance"] === "number" ? o["relevance"] : 0.5,
14484
+ content: String(o["content"] ?? (typeof s === "string" ? s : ""))
14485
+ };
14486
+ });
14487
+ }
14467
14488
  function neuralTools() {
14468
14489
  return [
14469
- tool("neural.search", "Neural similarity search across embeddings", "neural", [
14490
+ tool("neural.search", "Neural (TF-IDF) similarity search over provided documents", "neural", [
14470
14491
  param("query", "string", "Search query"),
14492
+ param("documents", "array", "Documents to index: strings or {id,text} objects"),
14471
14493
  param("topK", "number", "Number of results", false, 10)
14472
14494
  ], async (params) => {
14473
14495
  try {
14474
- const ns = await Promise.resolve().then(() => (init_dist14(), dist_exports14));
14475
- const results = ns.search?.(params["query"], params["topK"] ?? 10);
14476
- return ok(results ?? []);
14496
+ const { createNeuralSearchEngine: createNeuralSearchEngine2, createTfIdfEmbeddingModel: createTfIdfEmbeddingModel2 } = await Promise.resolve().then(() => (init_dist14(), dist_exports14));
14497
+ const model = createTfIdfEmbeddingModel2();
14498
+ const engine = createNeuralSearchEngine2();
14499
+ const docs = params["documents"] ?? [];
14500
+ const texts = docs.map((d) => typeof d === "string" ? d : d.text ?? "");
14501
+ const model2 = createTfIdfEmbeddingModel2();
14502
+ if (typeof model2.fit === "function") {
14503
+ model2.fit(texts);
14504
+ }
14505
+ const embedder = typeof model2.fit === "function" ? model2 : model;
14506
+ for (let i = 0; i < docs.length; i++) {
14507
+ const d = docs[i];
14508
+ const id = typeof d === "string" ? `doc-${i}` : d.id ?? `doc-${i}`;
14509
+ engine.addDocument(id, await embedder.embed(texts[i]), { text: texts[i] });
14510
+ }
14511
+ const hits = engine.search(await embedder.embed(params["query"] ?? ""), params["topK"] ?? 10);
14512
+ return ok({ query: params["query"], hits });
14477
14513
  } catch {
14478
- return ok([]);
14514
+ return fail("Neural-search package not available");
14479
14515
  }
14480
14516
  }),
14481
- tool("neural.embed", "Generate embeddings for text", "neural", [param("text", "string", "Text to embed")], async (params) => {
14517
+ tool("neural.embed", "Generate a TF-IDF embedding vector for text", "neural", [param("text", "string", "Text to embed")], async (params) => {
14482
14518
  try {
14483
- const ns = await Promise.resolve().then(() => (init_dist14(), dist_exports14));
14484
- const embedding = ns.embed?.(params["text"]);
14485
- return ok(embedding ?? { vector: [], dimensions: 0 });
14519
+ const { createTfIdfEmbeddingModel: createTfIdfEmbeddingModel2 } = await Promise.resolve().then(() => (init_dist14(), dist_exports14));
14520
+ const model = createTfIdfEmbeddingModel2();
14521
+ const text = params["text"] ?? "";
14522
+ if (typeof model.fit === "function") {
14523
+ model.fit([text]);
14524
+ }
14525
+ const vector = await model.embed(text);
14526
+ return ok({ vector, dimensions: Array.isArray(vector) ? vector.length : vector.values?.length ?? 0 });
14486
14527
  } catch {
14487
- return ok({ vector: [], dimensions: 0 });
14528
+ return fail("Neural-search package not available");
14488
14529
  }
14489
14530
  }),
14490
- tool("neural.patterns.extract", "Wake phase: extract patterns from code or data", "neural", [
14491
- param("source", "string", "Source code or data to extract patterns from"),
14492
- param("type", "string", "Pattern type: structural | behavioral | api", false, "structural")
14493
- ], async (params) => {
14531
+ tool("neural.patterns.extract", "Wake phase: extract patterns from a list of items", "neural", [param("items", "array", "Items (strings) to process for pattern extraction")], async (params) => {
14494
14532
  try {
14495
- const ws = await Promise.resolve().then(() => (init_dist15(), dist_exports15));
14496
- const patterns = ws.extractPatterns?.(params["source"], params["type"] ?? "structural");
14497
- return ok(patterns ?? { patterns: [], type: params["type"] ?? "structural" });
14533
+ const { createWakePhase: createWakePhase2 } = await Promise.resolve().then(() => (init_dist15(), dist_exports15));
14534
+ const items = (params["items"] ?? []).map(String);
14535
+ return ok(createWakePhase2().process(items));
14498
14536
  } catch {
14499
- return ok({ patterns: [], type: params["type"] ?? "structural" });
14537
+ return fail("Wake-sleep package not available");
14500
14538
  }
14501
14539
  }),
14502
- tool("neural.patterns.consolidate", "Sleep phase: consolidate and compress learned patterns", "neural", [param("patterns", "array", "Patterns to consolidate", false)], async (params) => {
14540
+ tool("neural.patterns.consolidate", "Sleep phase: consolidate and compress learned patterns", "neural", [param("patterns", "array", "Pattern strings to consolidate")], async (params) => {
14503
14541
  try {
14504
- const ws = await Promise.resolve().then(() => (init_dist15(), dist_exports15));
14505
- const result = ws.consolidatePatterns?.(params["patterns"]);
14506
- return ok(result ?? { consolidated: [], count: 0 });
14542
+ const { createSleepPhase: createSleepPhase2 } = await Promise.resolve().then(() => (init_dist15(), dist_exports15));
14543
+ const patterns = (params["patterns"] ?? []).map(String);
14544
+ return ok(createSleepPhase2().consolidate(patterns));
14507
14545
  } catch {
14508
- return ok({ consolidated: [], count: 0 });
14546
+ return fail("Wake-sleep package not available");
14509
14547
  }
14510
14548
  }),
14511
- tool("neural.library.learn", "Learn patterns from a library or framework", "neural", [
14512
- param("library", "string", "Library name or path"),
14513
- param("depth", "string", "Analysis depth: api | usage | deep", false, "api")
14514
- ], async (params) => {
14549
+ tool("neural.library.learn", "Learn reusable patterns from code snippets (E-graph library learning)", "neural", [param("snippets", "array", "Array of code snippet strings to learn from")], async (params) => {
14515
14550
  try {
14516
- const ll = await Promise.resolve().then(() => (init_dist11(), dist_exports11));
14517
- const result = ll.learnLibrary?.(params["library"], params["depth"] ?? "api");
14518
- return ok(result ?? { patterns: [], library: params["library"] });
14551
+ const { createLibraryLearner: createLibraryLearner2 } = await Promise.resolve().then(() => (init_dist11(), dist_exports11));
14552
+ const snippets = (params["snippets"] ?? []).map(String);
14553
+ const patterns = createLibraryLearner2().learn(snippets);
14554
+ return ok({ patterns, count: patterns.length });
14519
14555
  } catch {
14520
- return ok({ patterns: [], library: params["library"] });
14556
+ return fail("Library-learner package not available");
14521
14557
  }
14522
14558
  })
14523
14559
  ];
@@ -14671,52 +14707,81 @@ function formalVerifyTools() {
14671
14707
  })
14672
14708
  ];
14673
14709
  }
14710
+ async function loadTracker(basePath) {
14711
+ const { createStateTracker: createStateTracker2 } = await Promise.resolve().then(() => (init_dist6(), dist_exports6));
14712
+ const { existsSync: existsSync12, readFileSync: readFileSync7 } = await import("node:fs");
14713
+ const { join: join8 } = await import("node:path");
14714
+ const tracker = createStateTracker2();
14715
+ const file = join8(basePath, ".musubix", "workflow-state.json");
14716
+ try {
14717
+ if (existsSync12(file))
14718
+ tracker.restore(JSON.parse(readFileSync7(file, "utf-8")));
14719
+ } catch {
14720
+ }
14721
+ return { tracker, file };
14722
+ }
14723
+ async function saveTracker(tracker, file) {
14724
+ const { writeFileSync: writeFileSync4, mkdirSync: mkdirSync4 } = await import("node:fs");
14725
+ const { dirname: dirname4 } = await import("node:path");
14726
+ mkdirSync4(dirname4(file), { recursive: true });
14727
+ writeFileSync4(file, JSON.stringify(tracker.toJSON(), null, 2), "utf-8");
14728
+ }
14674
14729
  function workflowTools() {
14675
14730
  return [
14676
- tool("workflow.phase.current", "Get the current SDD workflow phase", "workflow", [param("basePath", "string", "Project base path", false, ".")], async (params) => {
14731
+ tool("workflow.phase.current", "Get the current SDD workflow phase and approvals", "workflow", [param("basePath", "string", "Project base path", false, ".")], async (params) => {
14677
14732
  try {
14678
- const wf = await Promise.resolve().then(() => (init_dist6(), dist_exports6));
14679
- const engine = wf.createWorkflowEngine?.(params["basePath"] ?? ".");
14680
- const phase = engine?.getCurrentPhase();
14681
- return ok(phase ?? { phase: "requirements", index: 0 });
14733
+ const { PHASE_ORDER: PHASE_ORDER2 } = await Promise.resolve().then(() => (init_dist6(), dist_exports6));
14734
+ const { tracker } = await loadTracker(params["basePath"] ?? ".");
14735
+ const state = tracker.getState();
14736
+ return ok({
14737
+ currentPhase: state.currentPhase,
14738
+ approvals: PHASE_ORDER2.map((p) => ({ phase: p, approved: tracker.isApproved(p) }))
14739
+ });
14682
14740
  } catch {
14683
- return ok({ phase: "requirements", index: 0 });
14741
+ return fail("Workflow-engine package not available");
14684
14742
  }
14685
14743
  }),
14686
- tool("workflow.phase.transition", "Transition to the next SDD workflow phase", "workflow", [
14744
+ tool("workflow.phase.transition", "Transition to a target SDD workflow phase (persisted)", "workflow", [
14687
14745
  param("targetPhase", "string", "Target phase to transition to"),
14688
14746
  param("basePath", "string", "Project base path", false, ".")
14689
14747
  ], async (params) => {
14690
14748
  try {
14691
- const wf = await Promise.resolve().then(() => (init_dist6(), dist_exports6));
14692
- const engine = wf.createWorkflowEngine?.(params["basePath"] ?? ".");
14693
- const result = engine?.transition(params["targetPhase"]);
14694
- return ok(result ?? { success: false, phase: params["targetPhase"] });
14749
+ const { createPhaseController: createPhaseController2 } = await Promise.resolve().then(() => (init_dist6(), dist_exports6));
14750
+ const { tracker, file } = await loadTracker(params["basePath"] ?? ".");
14751
+ const result = await createPhaseController2(tracker).transitionTo(params["targetPhase"]);
14752
+ if (result.success)
14753
+ await saveTracker(tracker, file);
14754
+ return ok(result);
14695
14755
  } catch {
14696
- return ok({ success: false, phase: params["targetPhase"] });
14756
+ return fail("Workflow-engine package not available");
14697
14757
  }
14698
14758
  }),
14699
- tool("workflow.gate.check", "Check if a quality gate can be passed", "workflow", [
14700
- param("gate", "string", "Gate name"),
14759
+ tool("workflow.gate.check", "Check whether the workflow can transition to a target phase (quality gates)", "workflow", [
14760
+ param("targetPhase", "string", "Target phase to check"),
14701
14761
  param("basePath", "string", "Project base path", false, ".")
14702
14762
  ], async (params) => {
14703
14763
  try {
14704
- const wf = await Promise.resolve().then(() => (init_dist6(), dist_exports6));
14705
- const engine = wf.createWorkflowEngine?.(params["basePath"] ?? ".");
14706
- const result = engine?.checkGate(params["gate"]);
14707
- return ok(result ?? { passed: false, gate: params["gate"] });
14764
+ const { createPhaseController: createPhaseController2 } = await Promise.resolve().then(() => (init_dist6(), dist_exports6));
14765
+ const { tracker } = await loadTracker(params["basePath"] ?? ".");
14766
+ const target = params["targetPhase"] ?? params["gate"];
14767
+ const canTransition = await createPhaseController2(tracker).canTransition(target);
14768
+ return ok({ targetPhase: target, canTransition });
14708
14769
  } catch {
14709
- return ok({ passed: false, gate: params["gate"] });
14770
+ return fail("Workflow-engine package not available");
14710
14771
  }
14711
14772
  }),
14712
- tool("workflow.tasks.list", "List tasks for the current workflow phase", "workflow", [param("basePath", "string", "Project base path", false, ".")], async (params) => {
14773
+ tool("workflow.approve", "Approve the current (or a named) SDD phase (persisted)", "workflow", [
14774
+ param("phase", "string", "Phase to approve"),
14775
+ param("basePath", "string", "Project base path", false, ".")
14776
+ ], async (params) => {
14713
14777
  try {
14714
- const wf = await Promise.resolve().then(() => (init_dist6(), dist_exports6));
14715
- const engine = wf.createWorkflowEngine?.(params["basePath"] ?? ".");
14716
- const tasks = engine?.listTasks();
14717
- return ok(tasks ?? []);
14778
+ const { tracker, file } = await loadTracker(params["basePath"] ?? ".");
14779
+ const phase = params["phase"] ?? tracker.getState().currentPhase;
14780
+ tracker.approve(phase);
14781
+ await saveTracker(tracker, file);
14782
+ return ok({ phase, approved: true });
14718
14783
  } catch {
14719
- return ok([]);
14784
+ return fail("Workflow-engine package not available");
14720
14785
  }
14721
14786
  })
14722
14787
  ];
package/dist/index.js CHANGED
@@ -14431,93 +14431,129 @@ function researchTools() {
14431
14431
  param("depth", "string", "Research depth: shallow | medium | deep", false, "medium")
14432
14432
  ], async (params) => {
14433
14433
  try {
14434
- const research = await Promise.resolve().then(() => (init_dist10(), dist_exports10));
14435
- const result = research.query?.(params["topic"], params["depth"] ?? "medium");
14436
- return ok(result ?? { findings: [], topic: params["topic"] });
14434
+ const { createResearchEngine: createResearchEngine2 } = await Promise.resolve().then(() => (init_dist10(), dist_exports10));
14435
+ const sources = normalizeSources(params["sources"]);
14436
+ const result = createResearchEngine2().research({ topic: params["topic"] ?? "", depth: params["depth"] ?? "medium" }, sources);
14437
+ return ok(result);
14437
14438
  } catch {
14438
- return ok({ findings: [], topic: params["topic"] });
14439
+ return fail("Deep-research package not available");
14439
14440
  }
14440
14441
  }),
14441
- tool("research.iterative", "Perform iterative deep research with progressive refinement", "research", [
14442
+ tool("research.iterative", "Perform iterative research with progressive refinement over provided sources", "research", [
14442
14443
  param("topic", "string", "Research topic"),
14443
- param("iterations", "number", "Number of refinement iterations", false, 3)
14444
+ param("depth", "string", "Depth: shallow | medium | deep", false, "medium"),
14445
+ param("sources", "array", "Sources as {title,type,relevance,content} objects")
14444
14446
  ], async (params) => {
14445
14447
  try {
14446
- const research = await Promise.resolve().then(() => (init_dist10(), dist_exports10));
14447
- const result = research.iterativeResearch?.(params["topic"], params["iterations"] ?? 3);
14448
- return ok(result ?? { findings: [], iterations: 0, topic: params["topic"] });
14448
+ const { createResearchEngine: createResearchEngine2 } = await Promise.resolve().then(() => (init_dist10(), dist_exports10));
14449
+ const sources = normalizeSources(params["sources"]);
14450
+ const result = createResearchEngine2().researchIterative({ topic: params["topic"] ?? "", depth: params["depth"] ?? "medium" }, () => sources);
14451
+ return ok(result);
14449
14452
  } catch {
14450
- return ok({ findings: [], iterations: 0, topic: params["topic"] });
14453
+ return fail("Deep-research package not available");
14451
14454
  }
14452
14455
  }),
14453
- tool("research.evidence", "Generate evidence chain for a claim or hypothesis", "research", [
14454
- param("claim", "string", "Claim or hypothesis to evaluate"),
14455
- param("sources", "array", "Evidence sources to consider", false)
14456
+ tool("research.evidence", "Accumulate research results and retrieve evidence for a topic", "research", [
14457
+ param("topic", "string", "Topic to gather evidence for"),
14458
+ param("sources", "array", "Sources as {title,type,relevance,content} objects")
14456
14459
  ], async (params) => {
14457
14460
  try {
14458
- const research = await Promise.resolve().then(() => (init_dist10(), dist_exports10));
14459
- const result = research.generateEvidence?.(params["claim"], params["sources"]);
14460
- return ok(result ?? { evidence: [], confidence: 0 });
14461
+ const { createResearchEngine: createResearchEngine2, createKnowledgeAccumulator: createKnowledgeAccumulator2 } = await Promise.resolve().then(() => (init_dist10(), dist_exports10));
14462
+ const sources = normalizeSources(params["sources"]);
14463
+ const topic = params["topic"] ?? "";
14464
+ const result = createResearchEngine2().research({ topic, depth: "medium" }, sources);
14465
+ const acc = createKnowledgeAccumulator2();
14466
+ acc.accumulate(result);
14467
+ return ok({ evidence: acc.query(topic), summary: result.summary, confidence: result.confidence });
14461
14468
  } catch {
14462
- return ok({ evidence: [], confidence: 0 });
14469
+ return fail("Deep-research package not available");
14463
14470
  }
14464
14471
  })
14465
14472
  ];
14466
14473
  }
14474
+ function normalizeSources(raw) {
14475
+ const valid = /* @__PURE__ */ new Set(["code", "documentation", "article", "api-reference"]);
14476
+ const arr = Array.isArray(raw) ? raw : [];
14477
+ return arr.map((s, i) => {
14478
+ const o = s ?? {};
14479
+ const t = String(o["type"] ?? "documentation");
14480
+ return {
14481
+ title: String(o["title"] ?? `source-${i + 1}`),
14482
+ type: valid.has(t) ? t : "documentation",
14483
+ relevance: typeof o["relevance"] === "number" ? o["relevance"] : 0.5,
14484
+ content: String(o["content"] ?? (typeof s === "string" ? s : ""))
14485
+ };
14486
+ });
14487
+ }
14467
14488
  function neuralTools() {
14468
14489
  return [
14469
- tool("neural.search", "Neural similarity search across embeddings", "neural", [
14490
+ tool("neural.search", "Neural (TF-IDF) similarity search over provided documents", "neural", [
14470
14491
  param("query", "string", "Search query"),
14492
+ param("documents", "array", "Documents to index: strings or {id,text} objects"),
14471
14493
  param("topK", "number", "Number of results", false, 10)
14472
14494
  ], async (params) => {
14473
14495
  try {
14474
- const ns = await Promise.resolve().then(() => (init_dist14(), dist_exports14));
14475
- const results = ns.search?.(params["query"], params["topK"] ?? 10);
14476
- return ok(results ?? []);
14496
+ const { createNeuralSearchEngine: createNeuralSearchEngine2, createTfIdfEmbeddingModel: createTfIdfEmbeddingModel2 } = await Promise.resolve().then(() => (init_dist14(), dist_exports14));
14497
+ const model = createTfIdfEmbeddingModel2();
14498
+ const engine = createNeuralSearchEngine2();
14499
+ const docs = params["documents"] ?? [];
14500
+ const texts = docs.map((d) => typeof d === "string" ? d : d.text ?? "");
14501
+ const model2 = createTfIdfEmbeddingModel2();
14502
+ if (typeof model2.fit === "function") {
14503
+ model2.fit(texts);
14504
+ }
14505
+ const embedder = typeof model2.fit === "function" ? model2 : model;
14506
+ for (let i = 0; i < docs.length; i++) {
14507
+ const d = docs[i];
14508
+ const id = typeof d === "string" ? `doc-${i}` : d.id ?? `doc-${i}`;
14509
+ engine.addDocument(id, await embedder.embed(texts[i]), { text: texts[i] });
14510
+ }
14511
+ const hits = engine.search(await embedder.embed(params["query"] ?? ""), params["topK"] ?? 10);
14512
+ return ok({ query: params["query"], hits });
14477
14513
  } catch {
14478
- return ok([]);
14514
+ return fail("Neural-search package not available");
14479
14515
  }
14480
14516
  }),
14481
- tool("neural.embed", "Generate embeddings for text", "neural", [param("text", "string", "Text to embed")], async (params) => {
14517
+ tool("neural.embed", "Generate a TF-IDF embedding vector for text", "neural", [param("text", "string", "Text to embed")], async (params) => {
14482
14518
  try {
14483
- const ns = await Promise.resolve().then(() => (init_dist14(), dist_exports14));
14484
- const embedding = ns.embed?.(params["text"]);
14485
- return ok(embedding ?? { vector: [], dimensions: 0 });
14519
+ const { createTfIdfEmbeddingModel: createTfIdfEmbeddingModel2 } = await Promise.resolve().then(() => (init_dist14(), dist_exports14));
14520
+ const model = createTfIdfEmbeddingModel2();
14521
+ const text = params["text"] ?? "";
14522
+ if (typeof model.fit === "function") {
14523
+ model.fit([text]);
14524
+ }
14525
+ const vector = await model.embed(text);
14526
+ return ok({ vector, dimensions: Array.isArray(vector) ? vector.length : vector.values?.length ?? 0 });
14486
14527
  } catch {
14487
- return ok({ vector: [], dimensions: 0 });
14528
+ return fail("Neural-search package not available");
14488
14529
  }
14489
14530
  }),
14490
- tool("neural.patterns.extract", "Wake phase: extract patterns from code or data", "neural", [
14491
- param("source", "string", "Source code or data to extract patterns from"),
14492
- param("type", "string", "Pattern type: structural | behavioral | api", false, "structural")
14493
- ], async (params) => {
14531
+ tool("neural.patterns.extract", "Wake phase: extract patterns from a list of items", "neural", [param("items", "array", "Items (strings) to process for pattern extraction")], async (params) => {
14494
14532
  try {
14495
- const ws = await Promise.resolve().then(() => (init_dist15(), dist_exports15));
14496
- const patterns = ws.extractPatterns?.(params["source"], params["type"] ?? "structural");
14497
- return ok(patterns ?? { patterns: [], type: params["type"] ?? "structural" });
14533
+ const { createWakePhase: createWakePhase2 } = await Promise.resolve().then(() => (init_dist15(), dist_exports15));
14534
+ const items = (params["items"] ?? []).map(String);
14535
+ return ok(createWakePhase2().process(items));
14498
14536
  } catch {
14499
- return ok({ patterns: [], type: params["type"] ?? "structural" });
14537
+ return fail("Wake-sleep package not available");
14500
14538
  }
14501
14539
  }),
14502
- tool("neural.patterns.consolidate", "Sleep phase: consolidate and compress learned patterns", "neural", [param("patterns", "array", "Patterns to consolidate", false)], async (params) => {
14540
+ tool("neural.patterns.consolidate", "Sleep phase: consolidate and compress learned patterns", "neural", [param("patterns", "array", "Pattern strings to consolidate")], async (params) => {
14503
14541
  try {
14504
- const ws = await Promise.resolve().then(() => (init_dist15(), dist_exports15));
14505
- const result = ws.consolidatePatterns?.(params["patterns"]);
14506
- return ok(result ?? { consolidated: [], count: 0 });
14542
+ const { createSleepPhase: createSleepPhase2 } = await Promise.resolve().then(() => (init_dist15(), dist_exports15));
14543
+ const patterns = (params["patterns"] ?? []).map(String);
14544
+ return ok(createSleepPhase2().consolidate(patterns));
14507
14545
  } catch {
14508
- return ok({ consolidated: [], count: 0 });
14546
+ return fail("Wake-sleep package not available");
14509
14547
  }
14510
14548
  }),
14511
- tool("neural.library.learn", "Learn patterns from a library or framework", "neural", [
14512
- param("library", "string", "Library name or path"),
14513
- param("depth", "string", "Analysis depth: api | usage | deep", false, "api")
14514
- ], async (params) => {
14549
+ tool("neural.library.learn", "Learn reusable patterns from code snippets (E-graph library learning)", "neural", [param("snippets", "array", "Array of code snippet strings to learn from")], async (params) => {
14515
14550
  try {
14516
- const ll = await Promise.resolve().then(() => (init_dist11(), dist_exports11));
14517
- const result = ll.learnLibrary?.(params["library"], params["depth"] ?? "api");
14518
- return ok(result ?? { patterns: [], library: params["library"] });
14551
+ const { createLibraryLearner: createLibraryLearner2 } = await Promise.resolve().then(() => (init_dist11(), dist_exports11));
14552
+ const snippets = (params["snippets"] ?? []).map(String);
14553
+ const patterns = createLibraryLearner2().learn(snippets);
14554
+ return ok({ patterns, count: patterns.length });
14519
14555
  } catch {
14520
- return ok({ patterns: [], library: params["library"] });
14556
+ return fail("Library-learner package not available");
14521
14557
  }
14522
14558
  })
14523
14559
  ];
@@ -14671,52 +14707,81 @@ function formalVerifyTools() {
14671
14707
  })
14672
14708
  ];
14673
14709
  }
14710
+ async function loadTracker(basePath) {
14711
+ const { createStateTracker: createStateTracker2 } = await Promise.resolve().then(() => (init_dist6(), dist_exports6));
14712
+ const { existsSync: existsSync12, readFileSync: readFileSync7 } = await import("node:fs");
14713
+ const { join: join8 } = await import("node:path");
14714
+ const tracker = createStateTracker2();
14715
+ const file = join8(basePath, ".musubix", "workflow-state.json");
14716
+ try {
14717
+ if (existsSync12(file))
14718
+ tracker.restore(JSON.parse(readFileSync7(file, "utf-8")));
14719
+ } catch {
14720
+ }
14721
+ return { tracker, file };
14722
+ }
14723
+ async function saveTracker(tracker, file) {
14724
+ const { writeFileSync: writeFileSync4, mkdirSync: mkdirSync4 } = await import("node:fs");
14725
+ const { dirname: dirname4 } = await import("node:path");
14726
+ mkdirSync4(dirname4(file), { recursive: true });
14727
+ writeFileSync4(file, JSON.stringify(tracker.toJSON(), null, 2), "utf-8");
14728
+ }
14674
14729
  function workflowTools() {
14675
14730
  return [
14676
- tool("workflow.phase.current", "Get the current SDD workflow phase", "workflow", [param("basePath", "string", "Project base path", false, ".")], async (params) => {
14731
+ tool("workflow.phase.current", "Get the current SDD workflow phase and approvals", "workflow", [param("basePath", "string", "Project base path", false, ".")], async (params) => {
14677
14732
  try {
14678
- const wf = await Promise.resolve().then(() => (init_dist6(), dist_exports6));
14679
- const engine = wf.createWorkflowEngine?.(params["basePath"] ?? ".");
14680
- const phase = engine?.getCurrentPhase();
14681
- return ok(phase ?? { phase: "requirements", index: 0 });
14733
+ const { PHASE_ORDER: PHASE_ORDER2 } = await Promise.resolve().then(() => (init_dist6(), dist_exports6));
14734
+ const { tracker } = await loadTracker(params["basePath"] ?? ".");
14735
+ const state = tracker.getState();
14736
+ return ok({
14737
+ currentPhase: state.currentPhase,
14738
+ approvals: PHASE_ORDER2.map((p) => ({ phase: p, approved: tracker.isApproved(p) }))
14739
+ });
14682
14740
  } catch {
14683
- return ok({ phase: "requirements", index: 0 });
14741
+ return fail("Workflow-engine package not available");
14684
14742
  }
14685
14743
  }),
14686
- tool("workflow.phase.transition", "Transition to the next SDD workflow phase", "workflow", [
14744
+ tool("workflow.phase.transition", "Transition to a target SDD workflow phase (persisted)", "workflow", [
14687
14745
  param("targetPhase", "string", "Target phase to transition to"),
14688
14746
  param("basePath", "string", "Project base path", false, ".")
14689
14747
  ], async (params) => {
14690
14748
  try {
14691
- const wf = await Promise.resolve().then(() => (init_dist6(), dist_exports6));
14692
- const engine = wf.createWorkflowEngine?.(params["basePath"] ?? ".");
14693
- const result = engine?.transition(params["targetPhase"]);
14694
- return ok(result ?? { success: false, phase: params["targetPhase"] });
14749
+ const { createPhaseController: createPhaseController2 } = await Promise.resolve().then(() => (init_dist6(), dist_exports6));
14750
+ const { tracker, file } = await loadTracker(params["basePath"] ?? ".");
14751
+ const result = await createPhaseController2(tracker).transitionTo(params["targetPhase"]);
14752
+ if (result.success)
14753
+ await saveTracker(tracker, file);
14754
+ return ok(result);
14695
14755
  } catch {
14696
- return ok({ success: false, phase: params["targetPhase"] });
14756
+ return fail("Workflow-engine package not available");
14697
14757
  }
14698
14758
  }),
14699
- tool("workflow.gate.check", "Check if a quality gate can be passed", "workflow", [
14700
- param("gate", "string", "Gate name"),
14759
+ tool("workflow.gate.check", "Check whether the workflow can transition to a target phase (quality gates)", "workflow", [
14760
+ param("targetPhase", "string", "Target phase to check"),
14701
14761
  param("basePath", "string", "Project base path", false, ".")
14702
14762
  ], async (params) => {
14703
14763
  try {
14704
- const wf = await Promise.resolve().then(() => (init_dist6(), dist_exports6));
14705
- const engine = wf.createWorkflowEngine?.(params["basePath"] ?? ".");
14706
- const result = engine?.checkGate(params["gate"]);
14707
- return ok(result ?? { passed: false, gate: params["gate"] });
14764
+ const { createPhaseController: createPhaseController2 } = await Promise.resolve().then(() => (init_dist6(), dist_exports6));
14765
+ const { tracker } = await loadTracker(params["basePath"] ?? ".");
14766
+ const target = params["targetPhase"] ?? params["gate"];
14767
+ const canTransition = await createPhaseController2(tracker).canTransition(target);
14768
+ return ok({ targetPhase: target, canTransition });
14708
14769
  } catch {
14709
- return ok({ passed: false, gate: params["gate"] });
14770
+ return fail("Workflow-engine package not available");
14710
14771
  }
14711
14772
  }),
14712
- tool("workflow.tasks.list", "List tasks for the current workflow phase", "workflow", [param("basePath", "string", "Project base path", false, ".")], async (params) => {
14773
+ tool("workflow.approve", "Approve the current (or a named) SDD phase (persisted)", "workflow", [
14774
+ param("phase", "string", "Phase to approve"),
14775
+ param("basePath", "string", "Project base path", false, ".")
14776
+ ], async (params) => {
14713
14777
  try {
14714
- const wf = await Promise.resolve().then(() => (init_dist6(), dist_exports6));
14715
- const engine = wf.createWorkflowEngine?.(params["basePath"] ?? ".");
14716
- const tasks = engine?.listTasks();
14717
- return ok(tasks ?? []);
14778
+ const { tracker, file } = await loadTracker(params["basePath"] ?? ".");
14779
+ const phase = params["phase"] ?? tracker.getState().currentPhase;
14780
+ tracker.approve(phase);
14781
+ await saveTracker(tracker, file);
14782
+ return ok({ phase, approved: true });
14718
14783
  } catch {
14719
- return ok([]);
14784
+ return fail("Workflow-engine package not available");
14720
14785
  }
14721
14786
  })
14722
14787
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musubix2",
3
- "version": "0.5.9",
3
+ "version": "0.5.10",
4
4
  "description": "MUSUBIX2 — Specification Driven Development System",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",