@a-company/paradigm 3.23.3 → 3.24.1

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 (33) hide show
  1. package/dist/{accept-orchestration-ORQRKKGR.js → accept-orchestration-AAYFKS74.js} +5 -5
  2. package/dist/chunk-4UC6AQOC.js +631 -0
  3. package/dist/{chunk-YOFP72IB.js → chunk-6EQRU7WC.js} +4 -4
  4. package/dist/{chunk-Z42FOOVT.js → chunk-GC6X3YM7.js} +6 -6
  5. package/dist/{chunk-C3BK3E23.js → chunk-OXG5GVDJ.js} +1 -1
  6. package/dist/{chunk-XKAFTZOZ.js → chunk-VHSTF72C.js} +1 -1
  7. package/dist/{chunk-UI3XXVJ6.js → chunk-W4VFKZVF.js} +58 -1
  8. package/dist/{chunk-K34C7NAN.js → chunk-XKI55IFI.js} +2 -2
  9. package/dist/{graph-5VSRBRKZ.js → chunk-Z7W7HNRG.js} +2 -1
  10. package/dist/context-audit-RI4R2WRH.js +549 -0
  11. package/dist/{diff-4XJZN4OB.js → diff-QC7PWIPF.js} +5 -5
  12. package/dist/{doctor-FINKMI66.js → doctor-RVODPMHJ.js} +1 -1
  13. package/dist/graph-ERNQQQ7C.js +12 -0
  14. package/dist/index.js +64 -30
  15. package/dist/mcp.js +841 -17
  16. package/dist/{orchestrate-6XGEA655.js → orchestrate-NNNWNELP.js} +8 -8
  17. package/dist/pipeline-3G2FRAKM.js +263 -0
  18. package/dist/{probe-T77FFIAG.js → probe-SN4BNXOC.js} +2 -1
  19. package/dist/{providers-VIBWDN5D.js → providers-NKGY36QF.js} +1 -1
  20. package/dist/{shift-SW3GSODO.js → shift-R6TQ6MBP.js} +15 -14
  21. package/dist/{spawn-JSV2HST3.js → spawn-52PASJJL.js} +3 -3
  22. package/dist/sweep-5POCF2E4.js +934 -0
  23. package/dist/{team-YIYA4ZLX.js → team-JZHIH7H5.js} +6 -6
  24. package/dist/university-content/courses/.purpose +307 -0
  25. package/dist/university-content/plsat/.purpose +131 -0
  26. package/dist/university-ui/assets/{index-BV7lKIqO.js → index-BPzqnvrg.js} +2 -2
  27. package/dist/university-ui/assets/{index-BV7lKIqO.js.map → index-BPzqnvrg.js.map} +1 -1
  28. package/dist/university-ui/index.html +1 -1
  29. package/dist/{workspace-S5Q5LVA6.js → workspace-L27RR5MF.js} +3 -2
  30. package/package.json +1 -1
  31. package/dist/chunk-ZMN3RAIT.js +0 -564
  32. package/dist/{chunk-XNUWLW73.js → chunk-7WTOOH23.js} +0 -0
  33. package/dist/{flow-UFMPVOEM.js → flow-KZKMMXJC.js} +1 -1
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  indexCommand
4
- } from "./chunk-UI3XXVJ6.js";
4
+ } from "./chunk-W4VFKZVF.js";
5
5
  import {
6
6
  log
7
7
  } from "./chunk-4NCFWYGG.js";
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  BackgroundOrchestrator
4
- } from "./chunk-Z42FOOVT.js";
4
+ } from "./chunk-GC6X3YM7.js";
5
5
  import {
6
6
  AGENT_MODEL_RECOMMENDATIONS,
7
7
  addActivity,
@@ -6,6 +6,9 @@ import {
6
6
  import {
7
7
  aggregateFromDirectory
8
8
  } from "./chunk-6P4IFIK2.js";
9
+ import {
10
+ cliBuildGraphState
11
+ } from "./chunk-Z7W7HNRG.js";
9
12
 
10
13
  // src/commands/scan/navigator.ts
11
14
  import * as fs from "fs";
@@ -264,6 +267,8 @@ async function indexCommand(targetPath, options) {
264
267
  console.log(chalk2.blue("\n\u{1F52D} Generating Paradigm Scan Index\n"));
265
268
  }
266
269
  let scanConfig;
270
+ let graphConfig;
271
+ let tierConfig;
267
272
  const configPaths = [
268
273
  path2.join(rootDir, ".paradigm"),
269
274
  path2.join(rootDir, ".paradigm", "config.yaml")
@@ -273,7 +278,11 @@ async function indexCommand(targetPath, options) {
273
278
  try {
274
279
  const content = fs2.readFileSync(configPath, "utf8");
275
280
  const config = parseHorizonConfig(content);
276
- scanConfig = config.scan;
281
+ const typedConfig = config;
282
+ scanConfig = typedConfig.scan;
283
+ graphConfig = typedConfig.graph;
284
+ const contextConfig = typedConfig.context;
285
+ tierConfig = contextConfig?.tiers;
277
286
  break;
278
287
  } catch {
279
288
  }
@@ -318,6 +327,7 @@ async function indexCommand(targetPath, options) {
318
327
  screenDefinitions: scanConfig?.screens
319
328
  }
320
329
  );
330
+ classifyTiers(index, { hot: tierConfig?.["hot-threshold"], warm: tierConfig?.["warm-threshold"] });
321
331
  try {
322
332
  fs2.writeFileSync(outputPath, serializeScanIndex(index), "utf8");
323
333
  spinner.succeed(chalk2.green("Scan index generated"));
@@ -335,6 +345,23 @@ async function indexCommand(targetPath, options) {
335
345
  spinner.succeed(chalk2.green(`Flow index generated (${Object.keys(flowIndex.flows).length} flows)`));
336
346
  }
337
347
  }
348
+ const autoGenerate = graphConfig?.["auto-generate"] !== false;
349
+ if (autoGenerate) {
350
+ try {
351
+ const graphState = cliBuildGraphState(rootDir);
352
+ const graphsDir = path2.join(rootDir, ".paradigm", "graphs");
353
+ if (!fs2.existsSync(graphsDir)) fs2.mkdirSync(graphsDir, { recursive: true });
354
+ const graphPath = path2.join(graphsDir, "auto.graph.json");
355
+ fs2.writeFileSync(graphPath, JSON.stringify(graphState, null, 2), "utf8");
356
+ if (!options.quiet) {
357
+ spinner.succeed(chalk2.green(`Symbol graph updated (${graphState.nodes.length} nodes)`));
358
+ }
359
+ } catch {
360
+ if (!options.quiet) {
361
+ spinner.warn(chalk2.yellow("Could not auto-generate symbol graph"));
362
+ }
363
+ }
364
+ }
338
365
  if (!options.quiet) {
339
366
  console.log(chalk2.gray(`
340
367
  Output: ${outputPath}`));
@@ -350,6 +377,36 @@ async function indexCommand(targetPath, options) {
350
377
  }
351
378
  return index;
352
379
  }
380
+ function classifyTiers(index, config) {
381
+ const hotThreshold = config?.hot ?? 15;
382
+ const warmThreshold = config?.warm ?? 5;
383
+ const refCounts = /* @__PURE__ */ new Map();
384
+ const allSections = ["components", "flows", "gates", "signals", "aspects", "features", "state"];
385
+ for (const section of allSections) {
386
+ const entries = index[section];
387
+ if (!entries) continue;
388
+ for (const [, entry] of Object.entries(entries)) {
389
+ const refs = entry.related;
390
+ if (refs) {
391
+ for (const ref of refs) {
392
+ const stripped = ref.replace(/^[#$^!~]/, "");
393
+ refCounts.set(stripped, (refCounts.get(stripped) || 0) + 1);
394
+ }
395
+ }
396
+ }
397
+ }
398
+ for (const section of allSections) {
399
+ const entries = index[section];
400
+ if (!entries) continue;
401
+ for (const [id, entry] of Object.entries(entries)) {
402
+ const refs = refCounts.get(id) || 0;
403
+ const visualTags = entry.visualTags || [];
404
+ const centrality = visualTags.length;
405
+ const score = refs * 3 + centrality;
406
+ entry.tier = score > hotThreshold ? "hot" : score > warmThreshold ? "warm" : "cold";
407
+ }
408
+ }
409
+ }
353
410
  async function generateFlowIndex(rootDir, purposeFiles, options) {
354
411
  const flows = {};
355
412
  const symbolToFlows = {};
@@ -5,7 +5,7 @@ import {
5
5
  } from "./chunk-CHSHON3O.js";
6
6
  import {
7
7
  indexCommand
8
- } from "./chunk-UI3XXVJ6.js";
8
+ } from "./chunk-W4VFKZVF.js";
9
9
  import {
10
10
  getDefaultPremiseContent
11
11
  } from "./chunk-6P4IFIK2.js";
@@ -530,7 +530,7 @@ function applyDisciplineToConfig(paradigmDir, rootDir) {
530
530
  const config = getDisciplineConfig(discipline);
531
531
  const mappingLines = Object.entries(config.symbolMapping).map(([pattern, symbol]) => ` "${pattern}": "${symbol}"`).join("\n");
532
532
  content = content.replace(
533
- / symbol-mapping:\n(?: .*\n)*/,
533
+ / symbol-mapping:\n(?:(?: .*| *)\n)*/,
534
534
  ` symbol-mapping:
535
535
  ${mappingLines}
536
536
  `
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import "./chunk-ZXMDA7VB.js";
3
2
 
4
3
  // src/commands/graph.ts
5
4
  import chalk from "chalk";
@@ -157,7 +156,9 @@ View: paradigm graph`));
157
156
  process.exit(1);
158
157
  }
159
158
  }
159
+
160
160
  export {
161
161
  graphCommand,
162
+ cliBuildGraphState,
162
163
  graphGenerateCommand
163
164
  };
@@ -0,0 +1,549 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ log
4
+ } from "./chunk-4NCFWYGG.js";
5
+ import "./chunk-ZXMDA7VB.js";
6
+
7
+ // src/commands/doctor/context-audit.ts
8
+ import * as fs from "fs";
9
+ import * as path from "path";
10
+ var INSTRUCTION_FILES = ["CLAUDE.md", ".cursorrules", "AGENTS.md"];
11
+ function loadInstructionFiles(rootDir) {
12
+ const results = [];
13
+ for (const name of INSTRUCTION_FILES) {
14
+ const filePath = path.join(rootDir, name);
15
+ if (fs.existsSync(filePath)) {
16
+ const content = fs.readFileSync(filePath, "utf8");
17
+ results.push({ name, content, lines: content.split("\n") });
18
+ }
19
+ }
20
+ return results;
21
+ }
22
+ function findSourceDirs(dir, extensions) {
23
+ const dirs = /* @__PURE__ */ new Set();
24
+ const skipDirs = /* @__PURE__ */ new Set(["node_modules", "dist", ".git", ".paradigm", "coverage", "build", "__pycache__", "target", ".next", ".nuxt"]);
25
+ function walk(current) {
26
+ let entries;
27
+ try {
28
+ entries = fs.readdirSync(current, { withFileTypes: true });
29
+ } catch {
30
+ return;
31
+ }
32
+ let hasSource = false;
33
+ for (const entry of entries) {
34
+ if (skipDirs.has(entry.name)) continue;
35
+ const full = path.join(current, entry.name);
36
+ if (entry.isDirectory()) {
37
+ walk(full);
38
+ } else if (entry.isFile()) {
39
+ const ext = path.extname(entry.name);
40
+ if (extensions.includes(ext)) {
41
+ hasSource = true;
42
+ }
43
+ }
44
+ }
45
+ if (hasSource) {
46
+ dirs.add(current);
47
+ }
48
+ }
49
+ walk(dir);
50
+ return dirs;
51
+ }
52
+ function hasPurposeCoverage(dir, rootDir) {
53
+ let current = dir;
54
+ while (true) {
55
+ if (fs.existsSync(path.join(current, ".purpose"))) return true;
56
+ if (current === rootDir) break;
57
+ const parent = path.dirname(current);
58
+ if (parent === current) break;
59
+ current = parent;
60
+ }
61
+ return false;
62
+ }
63
+ async function checkStaleReferences(rootDir) {
64
+ const results = [];
65
+ const files = loadInstructionFiles(rootDir);
66
+ if (files.length === 0) {
67
+ results.push({
68
+ check: "stale-references",
69
+ status: "advisory",
70
+ message: "No instruction files found (CLAUDE.md, .cursorrules, AGENTS.md)"
71
+ });
72
+ return results;
73
+ }
74
+ const pathPattern = /(?:^|\s|`|"|')([.a-zA-Z0-9_-]+(?:\/[.a-zA-Z0-9_*{}-]+)+\/?)/gm;
75
+ const extPattern = /(?:^|\s|`|"|')([a-zA-Z0-9_-]+\.(?:ts|js|py|rs|go|yaml|yml|json|md|toml))\b/gm;
76
+ const stale = [];
77
+ const checked = /* @__PURE__ */ new Set();
78
+ for (const file of files) {
79
+ const allMatches = [];
80
+ let match;
81
+ pathPattern.lastIndex = 0;
82
+ while ((match = pathPattern.exec(file.content)) !== null) {
83
+ allMatches.push(match[1]);
84
+ }
85
+ extPattern.lastIndex = 0;
86
+ while ((match = extPattern.exec(file.content)) !== null) {
87
+ allMatches.push(match[1]);
88
+ }
89
+ for (const ref of allMatches) {
90
+ const cleaned = ref.replace(/\/+$/, "").replace(/`/g, "");
91
+ if (cleaned.startsWith("http") || cleaned.startsWith("//")) continue;
92
+ if (cleaned.includes("*") || cleaned.includes("{")) continue;
93
+ if (cleaned.startsWith("paradigm://")) continue;
94
+ if (cleaned.startsWith("node_modules/")) continue;
95
+ if (checked.has(cleaned)) continue;
96
+ checked.add(cleaned);
97
+ const fullPath = path.join(rootDir, cleaned);
98
+ if (!fs.existsSync(fullPath)) {
99
+ stale.push(`${file.name}: ${cleaned}`);
100
+ }
101
+ }
102
+ }
103
+ if (stale.length > 0) {
104
+ results.push({
105
+ check: "stale-references",
106
+ status: "error",
107
+ message: `${stale.length} dead path reference${stale.length > 1 ? "s" : ""} in instruction files`,
108
+ details: stale,
109
+ fix: "Update or remove dead paths from instruction files"
110
+ });
111
+ } else {
112
+ results.push({
113
+ check: "stale-references",
114
+ status: "ok",
115
+ message: "All referenced paths exist"
116
+ });
117
+ }
118
+ return results;
119
+ }
120
+ async function checkConventionContradictions(rootDir) {
121
+ const results = [];
122
+ const files = loadInstructionFiles(rootDir);
123
+ const configPath = path.join(rootDir, ".paradigm", "config.yaml");
124
+ if (fs.existsSync(configPath)) {
125
+ const content = fs.readFileSync(configPath, "utf8");
126
+ files.push({ name: "config.yaml", content, lines: content.split("\n") });
127
+ }
128
+ if (files.length === 0) {
129
+ results.push({
130
+ check: "convention-contradictions",
131
+ status: "ok",
132
+ message: "No instruction files to check"
133
+ });
134
+ return results;
135
+ }
136
+ const conventions = [];
137
+ const contradictions = [];
138
+ const namingPatterns = [
139
+ [/\bcamelCase\b/i, "camelCase"],
140
+ [/\bkebab[- ]?case\b/i, "kebab-case"],
141
+ [/\bsnake[_ ]?case\b/i, "snake_case"],
142
+ [/\bPascalCase\b/i, "PascalCase"]
143
+ ];
144
+ for (const file of files) {
145
+ for (let i = 0; i < file.lines.length; i++) {
146
+ const line = file.lines[i];
147
+ for (const [pattern, name] of namingPatterns) {
148
+ if (pattern.test(line)) {
149
+ const scopeMatch = line.match(/\b(file|variable|function|class|component|symbol|directory|folder|module|import)\s*nam/i);
150
+ const scope = scopeMatch ? scopeMatch[1].toLowerCase() : "general";
151
+ conventions.push({ scope, directive: name, source: file.name, line: i + 1 });
152
+ }
153
+ }
154
+ }
155
+ }
156
+ const byScope = /* @__PURE__ */ new Map();
157
+ for (const conv of conventions) {
158
+ const existing = byScope.get(conv.scope) || [];
159
+ existing.push(conv);
160
+ byScope.set(conv.scope, existing);
161
+ }
162
+ for (const [scope, rules] of byScope) {
163
+ const directives = new Set(rules.map((r) => r.directive));
164
+ const conflictPairs = [
165
+ ["camelCase", "kebab-case"],
166
+ ["camelCase", "snake_case"],
167
+ ["kebab-case", "snake_case"]
168
+ ];
169
+ for (const [a, b] of conflictPairs) {
170
+ if (directives.has(a) && directives.has(b)) {
171
+ const ruleA = rules.find((r) => r.directive === a);
172
+ const ruleB = rules.find((r) => r.directive === b);
173
+ contradictions.push(
174
+ `${scope} naming: ${a} (${ruleA.source}:${ruleA.line}) vs ${b} (${ruleB.source}:${ruleB.line})`
175
+ );
176
+ }
177
+ }
178
+ }
179
+ if (contradictions.length > 0) {
180
+ results.push({
181
+ check: "convention-contradictions",
182
+ status: "warn",
183
+ message: `${contradictions.length} potential convention contradiction${contradictions.length > 1 ? "s" : ""}`,
184
+ details: contradictions,
185
+ fix: "Reconcile conflicting naming/style conventions in instruction files"
186
+ });
187
+ } else {
188
+ results.push({
189
+ check: "convention-contradictions",
190
+ status: "ok",
191
+ message: "No contradictions detected"
192
+ });
193
+ }
194
+ return results;
195
+ }
196
+ var SKIP_DEPS = /* @__PURE__ */ new Set([
197
+ "typescript",
198
+ "tsup",
199
+ "vitest",
200
+ "eslint",
201
+ "prettier",
202
+ "rimraf",
203
+ "tsx",
204
+ "ts-node",
205
+ "nodemon",
206
+ "concurrently",
207
+ "husky",
208
+ "lint-staged",
209
+ "unbuild",
210
+ "turbo",
211
+ "lerna",
212
+ "changesets"
213
+ ]);
214
+ var SKIP_PREFIXES = ["@types/", "@typescript-eslint/", "@eslint/"];
215
+ async function checkUndocumentedStack(rootDir) {
216
+ const results = [];
217
+ const pkgPath = path.join(rootDir, "package.json");
218
+ if (!fs.existsSync(pkgPath)) {
219
+ results.push({
220
+ check: "undocumented-stack",
221
+ status: "ok",
222
+ message: "No package.json found (not a JS/TS project or monorepo root)"
223
+ });
224
+ return results;
225
+ }
226
+ let pkg;
227
+ try {
228
+ pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
229
+ } catch {
230
+ results.push({
231
+ check: "undocumented-stack",
232
+ status: "advisory",
233
+ message: "Could not parse package.json"
234
+ });
235
+ return results;
236
+ }
237
+ const allDeps = /* @__PURE__ */ new Set([
238
+ ...Object.keys(pkg.dependencies || {}),
239
+ ...Object.keys(pkg.devDependencies || {})
240
+ ]);
241
+ const majorDeps = [];
242
+ for (const dep of allDeps) {
243
+ if (SKIP_DEPS.has(dep)) continue;
244
+ if (SKIP_PREFIXES.some((p) => dep.startsWith(p))) continue;
245
+ majorDeps.push(dep);
246
+ }
247
+ if (majorDeps.length === 0) {
248
+ results.push({
249
+ check: "undocumented-stack",
250
+ status: "ok",
251
+ message: "No major dependencies to document"
252
+ });
253
+ return results;
254
+ }
255
+ const files = loadInstructionFiles(rootDir);
256
+ const allContent = files.map((f) => f.content).join("\n").toLowerCase();
257
+ const undocumented = [];
258
+ for (const dep of majorDeps) {
259
+ const depLower = dep.toLowerCase();
260
+ const shortName = dep.includes("/") ? dep.split("/").pop() : dep;
261
+ if (!allContent.includes(depLower) && !allContent.includes(shortName.toLowerCase())) {
262
+ undocumented.push(dep);
263
+ }
264
+ }
265
+ if (undocumented.length > 0) {
266
+ results.push({
267
+ check: "undocumented-stack",
268
+ status: "advisory",
269
+ message: `${undocumented.length} dependenc${undocumented.length > 1 ? "ies" : "y"} not mentioned in instruction files`,
270
+ details: undocumented.slice(0, 20),
271
+ // Cap at 20 to avoid noise
272
+ fix: "Consider documenting major dependencies in CLAUDE.md for AI context"
273
+ });
274
+ } else {
275
+ results.push({
276
+ check: "undocumented-stack",
277
+ status: "ok",
278
+ message: "All major dependencies are documented"
279
+ });
280
+ }
281
+ return results;
282
+ }
283
+ async function checkPurposeCoverage(rootDir) {
284
+ const results = [];
285
+ const sourceExtensions = [".ts", ".js", ".py", ".rs", ".go", ".tsx", ".jsx"];
286
+ const sourceDirs = findSourceDirs(rootDir, sourceExtensions);
287
+ if (sourceDirs.size === 0) {
288
+ results.push({
289
+ check: "purpose-coverage",
290
+ status: "ok",
291
+ message: "No source directories found"
292
+ });
293
+ return results;
294
+ }
295
+ let covered = 0;
296
+ const uncovered = [];
297
+ for (const dir of sourceDirs) {
298
+ if (hasPurposeCoverage(dir, rootDir)) {
299
+ covered++;
300
+ } else {
301
+ const rel = path.relative(rootDir, dir);
302
+ uncovered.push(rel);
303
+ }
304
+ }
305
+ const total = sourceDirs.size;
306
+ const pct = Math.round(covered / total * 100);
307
+ if (pct < 80) {
308
+ results.push({
309
+ check: "purpose-coverage",
310
+ status: "warn",
311
+ message: `${pct}% purpose coverage (${covered}/${total} source directories) \u2014 below 80% threshold`,
312
+ details: uncovered.slice(0, 15),
313
+ fix: "Create .purpose files in uncovered source directories"
314
+ });
315
+ } else {
316
+ results.push({
317
+ check: "purpose-coverage",
318
+ status: "ok",
319
+ message: `${pct}% purpose coverage (${covered}/${total} source directories)`
320
+ });
321
+ }
322
+ return results;
323
+ }
324
+ async function checkOrphanedSymbols(rootDir) {
325
+ const results = [];
326
+ const indexPath = path.join(rootDir, ".paradigm", "scan-index.json");
327
+ if (!fs.existsSync(indexPath)) {
328
+ results.push({
329
+ check: "orphaned-symbols",
330
+ status: "advisory",
331
+ message: "No scan-index.json found \u2014 run paradigm scan first"
332
+ });
333
+ return results;
334
+ }
335
+ let index;
336
+ try {
337
+ index = JSON.parse(fs.readFileSync(indexPath, "utf8"));
338
+ } catch {
339
+ results.push({
340
+ check: "orphaned-symbols",
341
+ status: "advisory",
342
+ message: "Could not parse scan-index.json"
343
+ });
344
+ return results;
345
+ }
346
+ const categories = ["components", "gates", "signals", "flows", "aspects"];
347
+ const allSymbols = /* @__PURE__ */ new Map();
348
+ const referencedSymbols = /* @__PURE__ */ new Set();
349
+ for (const cat of categories) {
350
+ const entries = index[cat];
351
+ if (!entries || typeof entries !== "object") continue;
352
+ for (const [id, entry] of Object.entries(entries)) {
353
+ if (entry.symbol) {
354
+ allSymbols.set(entry.symbol, id);
355
+ }
356
+ if (entry.related && Array.isArray(entry.related)) {
357
+ for (const ref of entry.related) {
358
+ referencedSymbols.add(ref);
359
+ }
360
+ }
361
+ }
362
+ }
363
+ const orphaned = [];
364
+ for (const [symbol] of allSymbols) {
365
+ if (!referencedSymbols.has(symbol)) {
366
+ orphaned.push(symbol);
367
+ }
368
+ }
369
+ if (orphaned.length > 0) {
370
+ results.push({
371
+ check: "orphaned-symbols",
372
+ status: "advisory",
373
+ message: `${orphaned.length} symbol${orphaned.length > 1 ? "s" : ""} with zero cross-references`,
374
+ details: orphaned.slice(0, 20),
375
+ fix: "Add cross-references in .purpose files to connect orphaned symbols"
376
+ });
377
+ } else {
378
+ results.push({
379
+ check: "orphaned-symbols",
380
+ status: "ok",
381
+ message: "All symbols have cross-references"
382
+ });
383
+ }
384
+ return results;
385
+ }
386
+ async function checkStalePortal(rootDir) {
387
+ const results = [];
388
+ const portalPath = path.join(rootDir, "portal.yaml");
389
+ if (!fs.existsSync(portalPath)) {
390
+ results.push({
391
+ check: "stale-portal",
392
+ status: "ok",
393
+ message: "No portal.yaml found (no routes to check)"
394
+ });
395
+ return results;
396
+ }
397
+ let portal;
398
+ try {
399
+ const { parse } = await import("./dist-PSF5CP4I.js");
400
+ portal = parse(fs.readFileSync(portalPath, "utf8"));
401
+ } catch {
402
+ results.push({
403
+ check: "stale-portal",
404
+ status: "error",
405
+ message: "Could not parse portal.yaml"
406
+ });
407
+ return results;
408
+ }
409
+ if (!portal?.routes || typeof portal.routes !== "object") {
410
+ results.push({
411
+ check: "stale-portal",
412
+ status: "ok",
413
+ message: "No routes defined in portal.yaml"
414
+ });
415
+ return results;
416
+ }
417
+ const routePatterns = Object.keys(portal.routes);
418
+ const staleRoutes = [];
419
+ const sourceExtensions = [".ts", ".js", ".py", ".rs", ".go"];
420
+ const allSourceFiles = [];
421
+ function collectSourceFiles(dir) {
422
+ const skipDirs = /* @__PURE__ */ new Set(["node_modules", "dist", ".git", ".paradigm", "coverage", "build", "target"]);
423
+ try {
424
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
425
+ for (const entry of entries) {
426
+ if (skipDirs.has(entry.name)) continue;
427
+ const full = path.join(dir, entry.name);
428
+ if (entry.isDirectory()) {
429
+ collectSourceFiles(full);
430
+ } else if (entry.isFile()) {
431
+ const ext = path.extname(entry.name);
432
+ if (sourceExtensions.includes(ext)) {
433
+ allSourceFiles.push(full);
434
+ }
435
+ }
436
+ }
437
+ } catch {
438
+ }
439
+ }
440
+ collectSourceFiles(rootDir);
441
+ const filenameLower = allSourceFiles.map((f) => ({
442
+ full: f,
443
+ name: path.basename(f, path.extname(f)).toLowerCase(),
444
+ relPath: path.relative(rootDir, f).toLowerCase()
445
+ }));
446
+ for (const route of routePatterns) {
447
+ const pathPart = route.replace(/^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\s+/i, "");
448
+ const segments = pathPart.split("/").filter((s) => s && !s.startsWith(":") && s !== "api");
449
+ if (segments.length === 0) continue;
450
+ const resource = segments[0].toLowerCase();
451
+ const hasMatch = filenameLower.some(
452
+ (f) => f.name.includes(resource) || f.relPath.includes(resource)
453
+ );
454
+ if (!hasMatch) {
455
+ staleRoutes.push(route);
456
+ }
457
+ }
458
+ if (staleRoutes.length > 0) {
459
+ results.push({
460
+ check: "stale-portal",
461
+ status: "error",
462
+ message: `${staleRoutes.length} portal route${staleRoutes.length > 1 ? "s" : ""} with no matching implementation file`,
463
+ details: staleRoutes,
464
+ fix: "Implement missing route handlers or remove stale routes from portal.yaml"
465
+ });
466
+ } else {
467
+ results.push({
468
+ check: "stale-portal",
469
+ status: "ok",
470
+ message: `All ${routePatterns.length} portal routes have matching implementation files`
471
+ });
472
+ }
473
+ return results;
474
+ }
475
+ var VAGUE_PATTERNS = [
476
+ { pattern: /\btry to\b/i, label: "try to" },
477
+ { pattern: /\bmaybe\b/i, label: "maybe" },
478
+ { pattern: /\bif possible\b/i, label: "if possible" },
479
+ { pattern: /\bconsider\b/i, label: "consider" },
480
+ { pattern: /\bmight want to\b/i, label: "might want to" },
481
+ { pattern: /\byou could\b/i, label: "you could" },
482
+ { pattern: /\boptionally\b/i, label: "optionally" }
483
+ ];
484
+ async function checkInstructionVagueness(rootDir) {
485
+ const results = [];
486
+ const files = loadInstructionFiles(rootDir);
487
+ if (files.length === 0) {
488
+ results.push({
489
+ check: "instruction-vagueness",
490
+ status: "ok",
491
+ message: "No instruction files to check"
492
+ });
493
+ return results;
494
+ }
495
+ const instances = [];
496
+ for (const file of files) {
497
+ for (let i = 0; i < file.lines.length; i++) {
498
+ const line = file.lines[i];
499
+ if (line.trimStart().startsWith("```")) continue;
500
+ if (line.trim().startsWith("|---")) continue;
501
+ for (const { pattern, label } of VAGUE_PATTERNS) {
502
+ if (pattern.test(line)) {
503
+ const trimmed = line.trim();
504
+ const preview = trimmed.length > 80 ? trimmed.slice(0, 77) + "..." : trimmed;
505
+ instances.push(`${file.name}:${i + 1} \u2014 "${label}" \u2014 ${preview}`);
506
+ }
507
+ }
508
+ }
509
+ }
510
+ if (instances.length > 0) {
511
+ results.push({
512
+ check: "instruction-vagueness",
513
+ status: "advisory",
514
+ message: `${instances.length} vague phrase${instances.length > 1 ? "s" : ""} in instruction files`,
515
+ details: instances.slice(0, 20),
516
+ fix: "Replace vague language with clear, actionable directives"
517
+ });
518
+ } else {
519
+ results.push({
520
+ check: "instruction-vagueness",
521
+ status: "ok",
522
+ message: "No vague language detected"
523
+ });
524
+ }
525
+ return results;
526
+ }
527
+ async function runContextAudit(rootDir, _options) {
528
+ const tracker = log.command("doctor:context-audit").start("Running context audit checks");
529
+ const results = [];
530
+ results.push(...await checkStaleReferences(rootDir));
531
+ results.push(...await checkConventionContradictions(rootDir));
532
+ results.push(...await checkUndocumentedStack(rootDir));
533
+ results.push(...await checkPurposeCoverage(rootDir));
534
+ results.push(...await checkOrphanedSymbols(rootDir));
535
+ results.push(...await checkStalePortal(rootDir));
536
+ results.push(...await checkInstructionVagueness(rootDir));
537
+ const errorCount = results.filter((r) => r.status === "error").length;
538
+ const warnCount = results.filter((r) => r.status === "warn").length;
539
+ const advisoryCount = results.filter((r) => r.status === "advisory").length;
540
+ if (errorCount > 0) {
541
+ tracker.error("Context audit found issues", { errors: errorCount, warnings: warnCount, advisories: advisoryCount });
542
+ } else {
543
+ tracker.success("Context audit complete", { warnings: warnCount, advisories: advisoryCount });
544
+ }
545
+ return results;
546
+ }
547
+ export {
548
+ runContextAudit
549
+ };