@handsupmin/gc-tree 0.8.1 → 0.8.3

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,9 +1,59 @@
1
- import { mkdir, readFile, writeFile } from 'node:fs/promises';
1
+ import { access, mkdir, readFile, writeFile } from 'node:fs/promises';
2
+ import { constants } from 'node:fs';
3
+ import { resolve } from 'node:path';
4
+ import { tmpdir } from 'node:os';
2
5
  import { settingsPath } from './paths.js';
6
+ async function pathExists(target) {
7
+ try {
8
+ await access(target, constants.F_OK);
9
+ return true;
10
+ }
11
+ catch {
12
+ return false;
13
+ }
14
+ }
15
+ function isTemporaryScaffoldTarget(targetDir) {
16
+ if (!targetDir)
17
+ return false;
18
+ const normalized = resolve(targetDir);
19
+ const tempRoot = resolve(tmpdir());
20
+ return normalized.startsWith(tempRoot) || normalized.includes('/gctree-');
21
+ }
22
+ async function sanitizeScaffoldedHosts(records) {
23
+ const input = records || [];
24
+ const next = [];
25
+ for (const record of input) {
26
+ if (record.scope === 'local') {
27
+ if (!record.target_dir)
28
+ continue;
29
+ if (isTemporaryScaffoldTarget(record.target_dir))
30
+ continue;
31
+ if (!(await pathExists(record.target_dir)))
32
+ continue;
33
+ }
34
+ if (next.some((entry) => entry.host === record.host &&
35
+ entry.scope === record.scope &&
36
+ entry.target_dir === record.target_dir)) {
37
+ continue;
38
+ }
39
+ next.push(record);
40
+ }
41
+ return next;
42
+ }
3
43
  export async function readSettings(home) {
4
44
  try {
5
45
  const raw = await readFile(settingsPath(home), 'utf8');
6
- return JSON.parse(raw);
46
+ const parsed = JSON.parse(raw);
47
+ const sanitizedHosts = await sanitizeScaffoldedHosts(parsed.scaffolded_hosts);
48
+ const hostsChanged = JSON.stringify(sanitizedHosts) !== JSON.stringify(parsed.scaffolded_hosts || []);
49
+ const next = hostsChanged
50
+ ? { ...parsed, scaffolded_hosts: sanitizedHosts, updated_at: new Date().toISOString() }
51
+ : { ...parsed, scaffolded_hosts: sanitizedHosts };
52
+ if (hostsChanged) {
53
+ await mkdir(home, { recursive: true });
54
+ await writeFile(settingsPath(home), `${JSON.stringify(next, null, 2)}\n`, 'utf8');
55
+ }
56
+ return next;
7
57
  }
8
58
  catch {
9
59
  return null;
@@ -22,10 +72,12 @@ export async function writeSettings({ home, providerMode, preferredProvider, pre
22
72
  return settings;
23
73
  }
24
74
  export async function appendScaffoldedHost(home, record) {
75
+ if (record.scope === 'local' && isTemporaryScaffoldTarget(record.target_dir))
76
+ return;
25
77
  const settings = await readSettings(home);
26
78
  if (!settings)
27
79
  return;
28
- const existing = settings.scaffolded_hosts || [];
80
+ const existing = await sanitizeScaffoldedHosts(settings.scaffolded_hosts);
29
81
  const filtered = existing.filter((h) => !(h.host === record.host && h.scope === record.scope && h.target_dir === record.target_dir));
30
82
  filtered.push({ ...record, scaffolded_at: new Date().toISOString() });
31
83
  const updated = { ...settings, scaffolded_hosts: filtered, updated_at: new Date().toISOString() };
@@ -1,6 +1,9 @@
1
- import { readFile } from 'node:fs/promises';
1
+ import { existsSync } from 'node:fs';
2
+ import { readFile, readdir } from 'node:fs/promises';
3
+ import { join } from 'node:path';
2
4
  import { parseIndexEntries } from './markdown.js';
3
- import { branchIndexPath, DEFAULT_BRANCH } from './paths.js';
5
+ import { resolveContext } from './resolve.js';
6
+ import { branchDocsDir, branchIndexPath, DEFAULT_BRANCH } from './paths.js';
4
7
  import { ensureBranchExists, statusForBranch } from './store.js';
5
8
  const VALID_CATEGORIES = new Set(['role', 'repos', 'domain', 'workflows', 'conventions', 'infra', 'verification']);
6
9
  export async function verifyOnboarding({ home, branch, }) {
@@ -12,6 +15,42 @@ export async function verifyOnboarding({ home, branch, }) {
12
15
  const indexedDocCount = docs.length;
13
16
  const hasDocs = status.doc_count > 0 && indexedDocCount > 0;
14
17
  const qualityIssues = [];
18
+ const docsDir = branchDocsDir(home, gcBranch);
19
+ const sourceDocs = await listSourceDocPaths(docsDir);
20
+ const nonIndexSourceDocs = sourceDocs.filter((path) => !/(^|\/)index\.md$/i.test(path));
21
+ if (sourceDocs.some((path) => /(^|\/)index\.md$/i.test(path))) {
22
+ qualityIssues.push('Source docs must not include docs/index.md. The branch-level index.md is the only dictionary.');
23
+ }
24
+ const indexedPaths = new Set(docs.map((doc) => doc.path));
25
+ for (const path of indexedPaths) {
26
+ if (!existsSync(join(branchDirForDoc(home, gcBranch), path))) {
27
+ qualityIssues.push(`Index points to a missing source doc: ${path}.`);
28
+ }
29
+ }
30
+ for (const path of nonIndexSourceDocs) {
31
+ const indexPath = `docs/${path}`;
32
+ if (!indexedPaths.has(indexPath)) {
33
+ qualityIssues.push(`Source doc is not reachable from index.md: ${indexPath}.`);
34
+ }
35
+ }
36
+ const pathLikeLabels = docs
37
+ .filter((doc) => /^\.?docs\//i.test(doc.label) || /\.md$/i.test(doc.label))
38
+ .map((doc) => doc.label);
39
+ if (pathLikeLabels.length > 0) {
40
+ qualityIssues.push(`Index labels must be search terms, not paths: ${dedupe(pathLikeLabels).join(', ')}.`);
41
+ }
42
+ const prefixedLabels = docs
43
+ .filter((doc) => /^(repo|repository|domain|workflow|convention|role|infra|verification)\s*:/i.test(doc.label))
44
+ .map((doc) => doc.label);
45
+ if (prefixedLabels.length > 0) {
46
+ qualityIssues.push(`Index labels must not keep category prefixes: ${dedupe(prefixedLabels).join(', ')}.`);
47
+ }
48
+ const invalidCategories = docs
49
+ .filter((doc) => doc.category !== 'general' && !VALID_CATEGORIES.has(doc.category))
50
+ .map((doc) => `${doc.label} (${doc.category})`);
51
+ if (invalidCategories.length > 0) {
52
+ qualityIssues.push(`Index contains invalid categories: ${dedupe(invalidCategories).join(', ')}.`);
53
+ }
15
54
  if (hasDocs && indexedDocCount >= 3) {
16
55
  const categoryCounts = new Map();
17
56
  for (const doc of docs) {
@@ -25,6 +64,25 @@ export async function verifyOnboarding({ home, branch, }) {
25
64
  const generalDocLabels = docs.filter((d) => d.category === 'general').map((d) => d.label);
26
65
  qualityIssues.push(`${generalCount} doc(s) still have category "general": ${generalDocLabels.join(', ')}. Move them to one of: ${[...VALID_CATEGORIES].join(', ')}.`);
27
66
  }
67
+ if (indexedDocCount >= 5) {
68
+ const presentCategories = new Set(docs.map((doc) => doc.category));
69
+ const missingCore = ['role', 'repos', 'domain', 'workflows'].filter((category) => !presentCategories.has(category));
70
+ if (missingCore.length > 0) {
71
+ qualityIssues.push(`Onboarding is missing core dictionary categories: ${missingCore.join(', ')}. Capture them or explicitly add small docs for unavailable categories.`);
72
+ }
73
+ }
74
+ }
75
+ if (status.warnings.length > 0) {
76
+ qualityIssues.push(...status.warnings);
77
+ }
78
+ const searchQuality = [];
79
+ for (const doc of docs.slice(0, 12)) {
80
+ const resolved = await resolveContext({ home, branch: gcBranch, query: doc.label });
81
+ const matched = resolved.matches.some((match) => match.path === doc.path);
82
+ searchQuality.push({ query: doc.label, expected_path: doc.path, matched });
83
+ if (!matched) {
84
+ qualityIssues.push(`Resolve smoke test failed: query "${doc.label}" did not return ${doc.path}.`);
85
+ }
28
86
  }
29
87
  const complete = hasDocs && qualityIssues.length === 0;
30
88
  return {
@@ -35,6 +93,7 @@ export async function verifyOnboarding({ home, branch, }) {
35
93
  docs,
36
94
  warnings: status.warnings,
37
95
  quality_issues: qualityIssues,
96
+ search_quality: searchQuality,
38
97
  message: complete
39
98
  ? `Onboarding is complete for gc-branch "${gcBranch}".`
40
99
  : hasDocs
@@ -42,3 +101,23 @@ export async function verifyOnboarding({ home, branch, }) {
42
101
  : `Onboarding is incomplete for gc-branch "${gcBranch}". Docs or index entries are missing.`,
43
102
  };
44
103
  }
104
+ async function listSourceDocPaths(dir, prefix = '') {
105
+ const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
106
+ const files = [];
107
+ for (const entry of entries) {
108
+ const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
109
+ if (entry.isDirectory()) {
110
+ files.push(...(await listSourceDocPaths(join(dir, entry.name), relative)));
111
+ }
112
+ else if (entry.isFile() && entry.name.endsWith('.md')) {
113
+ files.push(relative);
114
+ }
115
+ }
116
+ return files.sort();
117
+ }
118
+ function branchDirForDoc(home, branch) {
119
+ return join(home, 'branches', branch);
120
+ }
121
+ function dedupe(values) {
122
+ return [...new Set(values)];
123
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@handsupmin/gc-tree",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "description": "Global Context Tree, a lightweight branch-aware global context orchestrator for AI coding tools",
5
5
  "type": "module",
6
6
  "private": false,