sdtk-wiki-kit 0.1.3 → 0.1.4

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.
@@ -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
  };