sdtk-wiki-kit 0.1.3 → 0.2.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.
@@ -7,6 +7,7 @@ const {
7
7
  assertWikiWorkspaceWritePath,
8
8
  getWikiGraphPath,
9
9
  getWikiPagesPath,
10
+ getPreferredWikiContentPath,
10
11
  getWikiProvenanceSourcesPath,
11
12
  getWikiRawSourcesPath,
12
13
  getWikiReportsPath,
@@ -55,7 +56,7 @@ const CATEGORY_DEFS = [
55
56
  ["markers", "TODO/Open Questions/Gaps"],
56
57
  ["contradictions", "Candidate contradictions"],
57
58
  ["sourceQuality", "Source quality"],
58
- ["personalBrainQuality", "Personal-brain quality gate"],
59
+ ["personalBrainQuality", "Local wiki quality gate"],
59
60
  ];
60
61
 
61
62
  const REQUIRED_PERSONAL_BRAIN_SECTIONS = {
@@ -69,6 +70,8 @@ const REQUIRED_PERSONAL_BRAIN_SECTIONS = {
69
70
 
70
71
  const PERSONAL_BRAIN_STUB_CHAR_LIMIT = 600;
71
72
  const PERSONAL_BRAIN_GIANT_PAGE_BYTES = 50000;
73
+ const LINT_CONTEXT_CHAR_LIMIT = 96;
74
+ const STRICT_SEMANTIC_PERSONAL_BRAIN_TYPES = new Set(["tool_entity", "concept", "comparison", "synthesis"]);
72
75
 
73
76
  function toPosix(value) {
74
77
  return String(value || "").replace(/\\/g, "/");
@@ -158,24 +161,54 @@ function listMarkdownPages(rootPath) {
158
161
  return files;
159
162
  }
160
163
 
164
+ function truncateForReport(value, limit = LINT_CONTEXT_CHAR_LIMIT) {
165
+ const text = String(value || "").replace(/\s+/g, " ").trim();
166
+ if (text.length <= limit) return text;
167
+ return `${text.slice(0, Math.max(0, limit - 3)).trim()}...`;
168
+ }
169
+
170
+ function isExternalMarkdownTarget(rawTarget) {
171
+ const target = String(rawTarget || "").trim();
172
+ return (
173
+ target.startsWith("#") ||
174
+ /^(?:https?:|mailto:|tel:)/i.test(target) ||
175
+ /^(?:h|ht|htt|http|https)\.{3,}(?:\s|$)/i.test(target)
176
+ );
177
+ }
178
+
161
179
  function extractMarkdownLinks(body) {
162
180
  const links = [];
163
- const matcher = /\[[^\]]+\]\(([^)]+)\)/g;
181
+ const matcher = /\[([^\]]+)\]\(([^)]+)\)/g;
164
182
  let match;
165
183
  while ((match = matcher.exec(body || "")) !== null) {
166
- const rawTarget = String(match[1] || "").trim();
184
+ const rawLabel = String(match[1] || "").trim();
185
+ const rawTarget = String(match[2] || "").trim();
167
186
  if (!rawTarget) continue;
168
- if (
169
- rawTarget.startsWith("#") ||
170
- /^(?:https?:|mailto:|tel:)/i.test(rawTarget)
171
- ) {
187
+ if (isExternalMarkdownTarget(rawTarget)) {
172
188
  continue;
173
189
  }
174
- links.push(rawTarget);
190
+ links.push({
191
+ target: rawTarget,
192
+ label: rawLabel,
193
+ context: truncateForReport(rawLabel || rawTarget),
194
+ });
175
195
  }
176
196
  return links;
177
197
  }
178
198
 
199
+ function formatBrokenLinkFinding(pageRelPath, link) {
200
+ const target = typeof link === "string" ? link : link.target;
201
+ const context = typeof link === "string" ? "" : link.context;
202
+ const parts = [
203
+ `page: \`${pageRelPath}\``,
204
+ `missing target: \`${truncateForReport(target)}\``,
205
+ ];
206
+ if (context) {
207
+ parts.push(`context: \`${context}\``);
208
+ }
209
+ return parts.join("; ") + ".";
210
+ }
211
+
179
212
  function hasHeading(body, heading) {
180
213
  const escaped = String(heading).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
181
214
  return new RegExp(`^##\\s+${escaped}\\s*$`, "im").test(String(body || ""));
@@ -468,11 +501,12 @@ function analyzePages(projectPath) {
468
501
  const pagesByRelPath = new Map(pages.map((page) => [toPosix(path.normalize(page.relPath)), page]));
469
502
  for (const page of pages) {
470
503
  for (const link of page.links) {
471
- const rawPath = link.split("#")[0].trim();
504
+ const target = typeof link === "string" ? link : link.target;
505
+ const rawPath = target.split("#")[0].trim();
472
506
  if (!rawPath) continue;
473
507
  const resolved = path.resolve(path.dirname(page.filePath), rawPath);
474
508
  if (!isPathInsideOrEqual(resolved, inputs.pagesRoot) || !fs.existsSync(resolved)) {
475
- appendFinding(findings, "brokenLinks", `\`${page.relPath}\` links to missing \`${link}\`.`);
509
+ appendFinding(findings, "brokenLinks", formatBrokenLinkFinding(page.relPath, link));
476
510
  continue;
477
511
  }
478
512
  const targetRel = toPosix(path.relative(inputs.pagesRoot, resolved));
@@ -602,16 +636,27 @@ function analyzePages(projectPath) {
602
636
  }
603
637
 
604
638
  function analyzePersonalBrainPages(projectPath, findings) {
605
- const personalBrainRoot = path.join(getWikiWorkspacePath(projectPath), "personal-brain");
639
+ const contentRoot = getPreferredWikiContentPath(projectPath);
640
+ const personalBrainRoot = contentRoot.path;
641
+ const contentRelative = toPosix(contentRoot.relative);
606
642
  const pageFiles = listMarkdownPages(personalBrainRoot);
607
643
  const pages = [];
608
644
  const metrics = {
609
645
  pageCount: pageFiles.length,
646
+ contentRoot: personalBrainRoot,
647
+ contentMode: contentRoot.mode,
648
+ contentRelative,
610
649
  byType: {},
611
650
  frontmatterCoverage: 0,
612
651
  requiredSectionCoverage: 0,
613
652
  sourceRefsCoverage: 0,
614
653
  stubRatio: 0,
654
+ sourcePageCount: 0,
655
+ sourceThinAnchorCount: 0,
656
+ sourceThinAnchorRatio: 0,
657
+ semanticPageCount: 0,
658
+ semanticStubCount: 0,
659
+ semanticStubRatio: 0,
615
660
  giantPageCount: 0,
616
661
  brokenInternalLinks: 0,
617
662
  conceptCount: 0,
@@ -636,13 +681,15 @@ function analyzePersonalBrainPages(projectPath, findings) {
636
681
  const type = String(fields.type || "unknown");
637
682
  pages.push({ filePath, relPath, fields, body: parsed.body, hasFrontmatter: parsed.hasFrontmatter, type });
638
683
  metrics.byType[type] = (metrics.byType[type] || 0) + 1;
684
+ if (type === "source") metrics.sourcePageCount += 1;
685
+ if (STRICT_SEMANTIC_PERSONAL_BRAIN_TYPES.has(type)) metrics.semanticPageCount += 1;
639
686
  if (type === "concept") metrics.conceptCount += 1;
640
687
  if (type === "tool_entity") metrics.entityCount += 1;
641
688
  if (type === "comparison") metrics.comparisonCount += 1;
642
689
  if (type === "synthesis") metrics.synthesisCount += 1;
643
690
 
644
691
  if (!parsed.hasFrontmatter) {
645
- appendFinding(findings, "schema", `personal-brain/${relPath} is missing parseable frontmatter.`);
692
+ appendFinding(findings, "schema", `${contentRelative}/${relPath} is missing parseable frontmatter.`);
646
693
  continue;
647
694
  }
648
695
  frontmatterCount += 1;
@@ -652,7 +699,7 @@ function analyzePersonalBrainPages(projectPath, findings) {
652
699
  appendFinding(
653
700
  findings,
654
701
  "schema",
655
- `personal-brain/${relPath} is missing required personal-brain fields: ${missingFields.join(", ")}.`
702
+ `${contentRelative}/${relPath} is missing required local wiki fields: ${missingFields.join(", ")}.`
656
703
  );
657
704
  }
658
705
 
@@ -664,14 +711,14 @@ function analyzePersonalBrainPages(projectPath, findings) {
664
711
  appendFinding(
665
712
  findings,
666
713
  "personalBrainQuality",
667
- `personal-brain/${relPath} is missing required sections for ${type}: ${missingSections.join(", ")}.`
714
+ `${contentRelative}/${relPath} is missing required sections for ${type}: ${missingSections.join(", ")}.`
668
715
  );
669
716
  }
670
717
 
671
718
  if (!["root"].includes(type)) {
672
719
  sourceRefsEligible += 1;
673
720
  if (hasSourceRefs(fields)) sourceRefsPresent += 1;
674
- else appendFinding(findings, "personalBrainQuality", `personal-brain/${relPath} has no source_refs coverage.`);
721
+ else appendFinding(findings, "personalBrainQuality", `${contentRelative}/${relPath} has no source_refs coverage.`);
675
722
  }
676
723
 
677
724
  if (["tool_entity", "concept", "comparison", "synthesis"].includes(type)) {
@@ -679,30 +726,34 @@ function analyzePersonalBrainPages(projectPath, findings) {
679
726
  if (hasSourceRefs(fields) && /(?:source|provenance|evidence)/i.test(parsed.body)) {
680
727
  sourceEvidencePresent += 1;
681
728
  } else {
682
- appendFinding(findings, "personalBrainQuality", `personal-brain/${relPath} lacks source evidence coverage in body/frontmatter.`);
729
+ appendFinding(findings, "personalBrainQuality", `${contentRelative}/${relPath} lacks source evidence coverage in body/frontmatter.`);
683
730
  }
684
731
  }
685
732
 
686
733
  const compactBody = parsed.body.replace(/\s+/g, " ").trim();
687
- if (compactBody.length < PERSONAL_BRAIN_STUB_CHAR_LIMIT && !["root"].includes(type)) {
734
+ if (type === "source") {
735
+ metrics.sourceThinAnchorCount += 1;
736
+ } else if (compactBody.length < PERSONAL_BRAIN_STUB_CHAR_LIMIT && STRICT_SEMANTIC_PERSONAL_BRAIN_TYPES.has(type)) {
688
737
  stubCount += 1;
689
- appendFinding(findings, "personalBrainQuality", `personal-brain/${relPath} appears stub-like (${compactBody.length} normalized characters).`);
738
+ metrics.semanticStubCount += 1;
739
+ appendFinding(findings, "personalBrainQuality", `${contentRelative}/${relPath} appears stub-like (${compactBody.length} normalized characters).`);
690
740
  }
691
741
 
692
742
  const byteSize = fs.statSync(filePath).size;
693
743
  if (byteSize > PERSONAL_BRAIN_GIANT_PAGE_BYTES) {
694
744
  metrics.giantPageCount += 1;
695
- appendFinding(findings, "personalBrainQuality", `personal-brain/${relPath} is very large (${byteSize} bytes) and may need splitting.`);
745
+ appendFinding(findings, "personalBrainQuality", `${contentRelative}/${relPath} is very large (${byteSize} bytes) and may need splitting.`);
696
746
  }
697
747
  }
698
748
 
699
749
  for (const page of pages) {
700
750
  for (const link of extractMarkdownLinks(page.body)) {
701
- const rawPath = link.split("#")[0].trim();
751
+ const target = typeof link === "string" ? link : link.target;
752
+ const rawPath = target.split("#")[0].trim();
702
753
  if (!rawPath) continue;
703
754
  const resolved = path.resolve(path.dirname(page.filePath), rawPath);
704
755
  if (!isPathInsideOrEqual(resolved, personalBrainRoot) || !fs.existsSync(resolved)) {
705
- appendFinding(findings, "brokenLinks", `personal-brain/${page.relPath} links to missing ${link}.`);
756
+ appendFinding(findings, "brokenLinks", formatBrokenLinkFinding(`${contentRelative}/${page.relPath}`, link));
706
757
  metrics.brokenInternalLinks += 1;
707
758
  }
708
759
  }
@@ -712,10 +763,12 @@ function analyzePersonalBrainPages(projectPath, findings) {
712
763
  metrics.requiredSectionCoverage = sectionRequiredTotal > 0 ? sectionPresentTotal / sectionRequiredTotal : 1;
713
764
  metrics.sourceRefsCoverage = sourceRefsEligible > 0 ? sourceRefsPresent / sourceRefsEligible : 1;
714
765
  metrics.stubRatio = pageFiles.length > 0 ? stubCount / pageFiles.length : 0;
766
+ metrics.sourceThinAnchorRatio = metrics.sourcePageCount > 0 ? metrics.sourceThinAnchorCount / metrics.sourcePageCount : 0;
767
+ metrics.semanticStubRatio = metrics.semanticPageCount > 0 ? metrics.semanticStubCount / metrics.semanticPageCount : 0;
715
768
  metrics.sourceEvidenceCoverage = sourceEvidenceEligible > 0 ? sourceEvidencePresent / sourceEvidenceEligible : 1;
716
769
 
717
770
  if (pageFiles.length === 0) {
718
- appendFinding(findings, "personalBrainQuality", "No personal-brain pages were found under .sdtk/wiki/personal-brain.");
771
+ appendFinding(findings, "personalBrainQuality", "No local wiki pages were found under wiki/ or legacy .sdtk/wiki/personal-brain.");
719
772
  }
720
773
  if (metrics.frontmatterCoverage < 1) {
721
774
  appendFinding(findings, "personalBrainQuality", `Frontmatter coverage is ${formatPercent(metrics.frontmatterCoverage)}; expected 100%.`);
@@ -726,8 +779,8 @@ function analyzePersonalBrainPages(projectPath, findings) {
726
779
  if (metrics.sourceRefsCoverage < 0.9) {
727
780
  appendFinding(findings, "personalBrainQuality", `Source refs coverage is ${formatPercent(metrics.sourceRefsCoverage)}; expected at least 90%.`);
728
781
  }
729
- if (metrics.stubRatio > 0.1) {
730
- appendFinding(findings, "personalBrainQuality", `Stub ratio is ${formatPercent(metrics.stubRatio)}; expected at most 10%.`);
782
+ if (metrics.semanticStubRatio > 0.1) {
783
+ appendFinding(findings, "personalBrainQuality", `Semantic stub ratio is ${formatPercent(metrics.semanticStubRatio)}; expected at most 10% for tool/concept/comparison/synthesis pages.`);
731
784
  }
732
785
  if (metrics.entityCount > 0 && metrics.conceptCount === 0) {
733
786
  appendFinding(findings, "personalBrainQuality", "Tool/entity pages exist but no concept pages were generated.");
@@ -751,21 +804,29 @@ function totalFindings(findings) {
751
804
  }
752
805
 
753
806
  function renderPersonalBrainMetrics(metrics) {
754
- if (!metrics) return ["## Personal-Brain Quality Metrics", "", "- No personal-brain metrics available.", ""];
807
+ if (!metrics) return ["## Local Wiki Quality Metrics", "", "- No local wiki metrics available.", ""];
755
808
  const typeRows = Object.entries(metrics.byType || {})
756
809
  .sort(([a], [b]) => a.localeCompare(b))
757
810
  .map(([type, count]) => `| ${type} | ${count} |`);
758
811
  return [
759
- "## Personal-Brain Quality Metrics",
812
+ "## Local Wiki Quality Metrics",
760
813
  "",
761
- `- personal-brain pages: ${metrics.pageCount}`,
814
+ `- wiki content root: ${metrics.contentRoot}`,
815
+ `- wiki content mode: ${metrics.contentMode}`,
816
+ `- local wiki pages: ${metrics.pageCount}`,
762
817
  `- frontmatter coverage: ${formatPercent(metrics.frontmatterCoverage)}`,
763
818
  `- required section coverage: ${formatPercent(metrics.requiredSectionCoverage)}`,
764
819
  `- source refs coverage: ${formatPercent(metrics.sourceRefsCoverage)}`,
765
820
  `- source evidence coverage: ${formatPercent(metrics.sourceEvidenceCoverage)}`,
766
- `- stub ratio: ${formatPercent(metrics.stubRatio)}`,
821
+ `- source pages: ${metrics.sourcePageCount}`,
822
+ `- source pages accepted as provenance anchors: ${metrics.sourceThinAnchorCount}`,
823
+ `- source-page thin-anchor ratio: ${formatPercent(metrics.sourceThinAnchorRatio)}`,
824
+ `- strict semantic pages: ${metrics.semanticPageCount}`,
825
+ `- strict semantic stub pages: ${metrics.semanticStubCount}`,
826
+ `- semantic stub ratio: ${formatPercent(metrics.semanticStubRatio)}`,
827
+ `- stub ratio policy: source pages are measured separately; strict stub findings apply to tool_entity, concept, comparison, and synthesis pages.`,
767
828
  `- giant page warnings: ${metrics.giantPageCount}`,
768
- `- broken personal-brain internal links: ${metrics.brokenInternalLinks}`,
829
+ `- broken local wiki internal links: ${metrics.brokenInternalLinks}`,
769
830
  `- entity pages: ${metrics.entityCount}`,
770
831
  `- concept pages: ${metrics.conceptCount}`,
771
832
  `- comparison pages: ${metrics.comparisonCount}`,
@@ -15,6 +15,8 @@ const WIKI_PROVENANCE_SOURCES_RELATIVE = path.join(".sdtk", "wiki", "provenance"
15
15
  const WIKI_QUERIES_RELATIVE = path.join(".sdtk", "wiki", "queries");
16
16
  const WIKI_REPORTS_RELATIVE = path.join(".sdtk", "wiki", "reports");
17
17
  const WIKI_LOGS_RELATIVE = path.join(".sdtk", "wiki", "logs");
18
+ const CANONICAL_WIKI_RELATIVE = "wiki";
19
+ const LEGACY_PERSONAL_BRAIN_RELATIVE = path.join(".sdtk", "wiki", "personal-brain");
18
20
  const LEGACY_ATLAS_RELATIVE = path.join(".sdtk", "atlas");
19
21
 
20
22
  function resolveProjectPath(projectPath) {
@@ -51,6 +53,43 @@ function getWikiWorkspacePath(projectPath) {
51
53
  return path.join(resolveProjectPath(projectPath), WIKI_WORKSPACE_RELATIVE);
52
54
  }
53
55
 
56
+ function getCanonicalWikiPath(projectPath) {
57
+ return path.join(resolveProjectPath(projectPath), CANONICAL_WIKI_RELATIVE);
58
+ }
59
+
60
+ function getLegacyPersonalBrainPath(projectPath) {
61
+ return path.join(resolveProjectPath(projectPath), LEGACY_PERSONAL_BRAIN_RELATIVE);
62
+ }
63
+
64
+ function getPreferredWikiContentPath(projectPath) {
65
+ const canonical = getCanonicalWikiPath(projectPath);
66
+ const legacy = getLegacyPersonalBrainPath(projectPath);
67
+ try {
68
+ const fs = require("fs");
69
+ if (fs.existsSync(canonical) && fs.statSync(canonical).isDirectory()) {
70
+ return {
71
+ path: canonical,
72
+ mode: "canonical_project_wiki",
73
+ relative: CANONICAL_WIKI_RELATIVE,
74
+ };
75
+ }
76
+ if (fs.existsSync(legacy) && fs.statSync(legacy).isDirectory()) {
77
+ return {
78
+ path: legacy,
79
+ mode: "legacy_personal_brain_fallback",
80
+ relative: LEGACY_PERSONAL_BRAIN_RELATIVE,
81
+ };
82
+ }
83
+ } catch (_) {
84
+ // Callers perform their own existence validation and error reporting.
85
+ }
86
+ return {
87
+ path: canonical,
88
+ mode: "canonical_project_wiki",
89
+ relative: CANONICAL_WIKI_RELATIVE,
90
+ };
91
+ }
92
+
54
93
  function getWikiGraphPath(projectPath) {
55
94
  return path.join(resolveProjectPath(projectPath), WIKI_GRAPH_RELATIVE);
56
95
  }
@@ -111,9 +150,19 @@ function assertWikiWorkspaceWritePath(targetPath, projectPath) {
111
150
  );
112
151
  }
113
152
 
153
+ function assertCanonicalWikiWritePath(targetPath, projectPath) {
154
+ return assertPathInsideOrEqual(
155
+ targetPath,
156
+ getCanonicalWikiPath(projectPath),
157
+ "Refusing to write outside project-local wiki output"
158
+ );
159
+ }
160
+
114
161
  function describeWikiPaths(projectPath) {
115
162
  return {
116
163
  projectPath: resolveProjectPath(projectPath),
164
+ canonicalWikiPath: getCanonicalWikiPath(projectPath),
165
+ legacyPersonalBrainPath: getLegacyPersonalBrainPath(projectPath),
117
166
  wikiWorkspacePath: getWikiWorkspacePath(projectPath),
118
167
  wikiGraphPath: getWikiGraphPath(projectPath),
119
168
  wikiManifestPath: getWikiManifestPath(projectPath),
@@ -132,7 +181,9 @@ function describeWikiPaths(projectPath) {
132
181
  }
133
182
 
134
183
  module.exports = {
184
+ CANONICAL_WIKI_RELATIVE,
135
185
  LEGACY_ATLAS_RELATIVE,
186
+ LEGACY_PERSONAL_BRAIN_RELATIVE,
136
187
  WIKI_GRAPH_RELATIVE,
137
188
  WIKI_LOGS_RELATIVE,
138
189
  WIKI_MANIFEST_RELATIVE,
@@ -147,9 +198,13 @@ module.exports = {
147
198
  WIKI_REPORTS_RELATIVE,
148
199
  WIKI_WORKSPACE_RELATIVE,
149
200
  assertPathInsideOrEqual,
201
+ assertCanonicalWikiWritePath,
150
202
  assertWikiWorkspaceWritePath,
151
203
  describeWikiPaths,
204
+ getCanonicalWikiPath,
205
+ getLegacyPersonalBrainPath,
152
206
  getLegacyAtlasPath,
207
+ getPreferredWikiContentPath,
153
208
  getWikiGraphPath,
154
209
  getWikiLogsPath,
155
210
  getWikiManifestPath,
@@ -4,13 +4,14 @@ const fs = require("fs");
4
4
  const path = require("path");
5
5
  const { ValidationError } = require("./errors");
6
6
  const {
7
- getWikiWorkspacePath,
7
+ getPreferredWikiContentPath,
8
8
  isPathInsideOrEqual,
9
9
  resolveProjectPath,
10
10
  } = require("./wiki-paths");
11
11
 
12
12
  const DEFAULT_LIMIT = 10;
13
- const PERSONAL_BRAIN_RELATIVE = path.join(".sdtk", "wiki", "personal-brain");
13
+ const CANONICAL_WIKI_RELATIVE = "wiki";
14
+ const LEGACY_PERSONAL_BRAIN_RELATIVE = path.join(".sdtk", "wiki", "personal-brain");
14
15
 
15
16
  function toPosix(value) {
16
17
  return String(value || "").replace(/\\/g, "/");
@@ -120,18 +121,19 @@ function runWikiSearch({ projectPath, query, limit = DEFAULT_LIMIT }) {
120
121
 
121
122
  const parsedLimit = Number.parseInt(limit, 10);
122
123
  const safeLimit = Number.isFinite(parsedLimit) && parsedLimit > 0 ? Math.min(parsedLimit, 50) : DEFAULT_LIMIT;
123
- const personalBrainPath = path.join(getWikiWorkspacePath(resolvedProjectPath), "personal-brain");
124
- if (!isPathInsideOrEqual(personalBrainPath, resolvedProjectPath)) {
124
+ const contentRoot = getPreferredWikiContentPath(resolvedProjectPath);
125
+ const wikiContentPath = contentRoot.path;
126
+ if (!isPathInsideOrEqual(wikiContentPath, resolvedProjectPath)) {
125
127
  throw new ValidationError("Refusing to search outside the project root.");
126
128
  }
127
- if (!fs.existsSync(personalBrainPath) || !fs.statSync(personalBrainPath).isDirectory()) {
129
+ if (!fs.existsSync(wikiContentPath) || !fs.statSync(wikiContentPath).isDirectory()) {
128
130
  throw new ValidationError(
129
- `No SDTK-WIKI personal brain found at ${personalBrainPath}. Run "sdtk-wiki ingest <source-root>" and "sdtk-wiki compile --mode safe --apply" first. Advanced users can still use wiki extract/compile sidecar commands.`
131
+ `No SDTK-WIKI local wiki found at ${wikiContentPath}. Run "sdtk-wiki ingest <source-root>" and "sdtk-wiki compile --mode safe --apply" first. Legacy .sdtk/wiki/personal-brain workspaces are still readable when present.`
130
132
  );
131
133
  }
132
134
 
133
135
  const tokens = tokenize(normalizedQuery);
134
- const files = collectMarkdownFiles(personalBrainPath);
136
+ const files = collectMarkdownFiles(wikiContentPath);
135
137
  const matches = [];
136
138
 
137
139
  for (const filePath of files) {
@@ -157,19 +159,24 @@ function runWikiSearch({ projectPath, query, limit = DEFAULT_LIMIT }) {
157
159
  return {
158
160
  query: normalizedQuery,
159
161
  projectPath: resolvedProjectPath,
160
- personalBrainPath,
162
+ wikiContentPath,
163
+ wikiContentMode: contentRoot.mode,
164
+ personalBrainPath: wikiContentPath,
161
165
  scannedFiles: files.length,
162
166
  matches: matches.slice(0, safeLimit),
163
167
  totalMatches: matches.length,
164
168
  limit: safeLimit,
165
- searchMode: "local_deterministic_personal_brain_markdown",
169
+ searchMode: contentRoot.mode === "canonical_project_wiki"
170
+ ? "local_deterministic_project_wiki_markdown"
171
+ : "local_deterministic_legacy_personal_brain_markdown",
166
172
  premiumRequired: false,
167
173
  mutated: false,
168
174
  };
169
175
  }
170
176
 
171
177
  module.exports = {
172
- PERSONAL_BRAIN_RELATIVE,
178
+ CANONICAL_WIKI_RELATIVE,
179
+ LEGACY_PERSONAL_BRAIN_RELATIVE,
173
180
  runWikiSearch,
174
181
  tokenize,
175
182
  };