facult 1.0.3 → 1.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.
@@ -1,7 +1,7 @@
1
1
  import { homedir } from "node:os";
2
- import { join } from "node:path";
2
+ import { ensureAiIndexPath } from "../ai-state";
3
3
  import type { FacultIndex } from "../index-builder";
4
- import { facultRootDir } from "../paths";
4
+ import { facultAiIndexPath, facultRootDir } from "../paths";
5
5
  import type { AuditItemResult, Severity } from "./types";
6
6
  import { SEVERITY_ORDER } from "./types";
7
7
 
@@ -17,6 +17,7 @@ function ensureIndexStructure(index: FacultIndex): FacultIndex {
17
17
  mcp: index.mcp ?? { servers: {} },
18
18
  agents: index.agents ?? {},
19
19
  snippets: index.snippets ?? {},
20
+ instructions: index.instructions ?? {},
20
21
  };
21
22
  }
22
23
 
@@ -33,8 +34,12 @@ function computeAuditStatus(
33
34
  return worst >= SEVERITY_ORDER.high ? "flagged" : "passed";
34
35
  }
35
36
 
36
- async function loadIndex(rootDir: string): Promise<FacultIndex | null> {
37
- const indexPath = join(rootDir, "index.json");
37
+ async function loadIndex(homeDir: string): Promise<FacultIndex | null> {
38
+ const { path: indexPath } = await ensureAiIndexPath({
39
+ homeDir,
40
+ rootDir: facultRootDir(homeDir),
41
+ repair: true,
42
+ });
38
43
  const file = Bun.file(indexPath);
39
44
  if (!(await file.exists())) {
40
45
  return null;
@@ -46,8 +51,8 @@ async function loadIndex(rootDir: string): Promise<FacultIndex | null> {
46
51
  }
47
52
  }
48
53
 
49
- async function writeIndex(rootDir: string, index: FacultIndex) {
50
- const indexPath = join(rootDir, "index.json");
54
+ async function writeIndex(homeDir: string, index: FacultIndex) {
55
+ const indexPath = facultAiIndexPath(homeDir);
51
56
  await Bun.write(indexPath, `${JSON.stringify(index, null, 2)}\n`);
52
57
  }
53
58
 
@@ -57,9 +62,7 @@ export async function updateIndexFromAuditReport(opts: {
57
62
  results: AuditItemResult[];
58
63
  }): Promise<{ updated: boolean; reason?: string }> {
59
64
  const home = opts.homeDir ?? homedir();
60
- const rootDir = facultRootDir(home);
61
-
62
- const loaded = await loadIndex(rootDir);
65
+ const loaded = await loadIndex(home);
63
66
  if (!loaded) {
64
67
  return { updated: false, reason: "index-missing" };
65
68
  }
@@ -110,6 +113,6 @@ export async function updateIndexFromAuditReport(opts: {
110
113
  }
111
114
 
112
115
  index.updatedAt = new Date().toISOString();
113
- await writeIndex(rootDir, index);
116
+ await writeIndex(home, index);
114
117
  return { updated: true };
115
118
  }