Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!-- AUTO-GENERATED by agent-core sync. Do not edit directly. -->
# sync-docs

> Sync documentation with code changes. Find outdated refs, update CHANGELOG, flag stale examples.
Expand All @@ -24,7 +23,7 @@
5. **Always run git hooks** - Never bypass pre-commit or pre-push hooks.
6. **Use single dash for em-dashes** - In prose, use ` - ` (single dash with spaces), never ` -- `.
7. **Report script failures before manual fallback** - Never silently bypass broken tooling.
8. **Token efficiency** - Be concise. Save tokens over decorations.
8. **Token efficiency** - Save tokens over decorations.

## Model Selection

Expand Down
67 changes: 2 additions & 65 deletions lib/collectors/docs-patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ const { execFileSync } = require('child_process');
let repoMapModule = null;
let repoMapLoadError = null;

// Lazy-load binary module (only available when agent-core syncs it)
let binaryModule = null;
let binaryLoadError = null;

/**
* Get the repo-map module, loading it lazily
* @returns {{module: Object|null, error: string|null}}
Expand All @@ -46,27 +42,6 @@ function getRepoMapLoadError() {
return repoMapLoadError;
}

/**
* Get the binary module, loading it lazily
* @returns {Object|null}
*/
function getBinary() {
if (!binaryModule && !binaryLoadError) {
try {
const lib = require('../index');
if (lib.binary && typeof lib.binary.runAnalyzer === 'function') {
binaryModule = lib.binary;
} else {
binaryLoadError = 'binary module not available in @agentsys/lib';
}
} catch (err) {
binaryLoadError = err.message || 'Failed to load binary module';
binaryModule = null;
}
}
return binaryModule;
}

const DEFAULT_OPTIONS = {
cwd: process.cwd()
};
Expand Down Expand Up @@ -682,40 +657,6 @@ function checkChangelog(changedFiles, options = {}) {
};
}

/**
* Get doc-drift signals from agent-analyzer binary.
*
* Returns docs with low code coupling - files that rarely co-change with code
* and are likely drifting out of sync. Requires repo-intel map file to exist.
*
* @param {string} cwd - Working directory (repository root)
* @returns {Array|null} Array of drift entries or null if unavailable
*/
function getDocDriftSignals(cwd) {
const binary = getBinary();
if (!binary) return null;

// Resolve map file path: <stateDir>/repo-intel.json
const stateDir = ['.claude', '.opencode', '.codex']
.find(d => fs.existsSync(path.join(cwd, d))) || '.claude';
const mapFile = path.join(cwd, stateDir, 'repo-intel.json');

if (!fs.existsSync(mapFile)) return null;

try {
const output = binary.runAnalyzer([
'repo-intel', 'query', 'doc-drift',
'--top', '20',
'--map-file', mapFile,
cwd
]);
return JSON.parse(output);
} catch {
// Binary not available, query failed, or parse error - not critical
return null;
}
}

/**
* Collect all documentation-related data
* @param {Object} options - Collection options
Expand All @@ -742,11 +683,9 @@ function collect(options = {}) {
} : null
},
// New: undocumented exports detection (pass repoMapStatus to avoid redundant call)
undocumentedExports: repoMapStatus.available
undocumentedExports: repoMapStatus.available
? findUndocumentedExports(changedFiles, { ...opts, repoMapStatus })
: [],
// Doc-drift signals from agent-analyzer (optional, null if unavailable)
docDrift: getDocDriftSignals(opts.cwd)
: []
};
}

Expand All @@ -767,8 +706,6 @@ module.exports = {
findUndocumentedExports,
isInternalExport,
isEntryPoint,
// Doc-drift integration
getDocDriftSignals,
// Utilities
escapeRegex,
// Diagnostic
Expand Down
16 changes: 6 additions & 10 deletions lib/collectors/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Git History Collector
*
* Collects git history analysis data using the agent-analyzer binary.
* Runs a full git-map init and extracts key metrics for downstream consumers.
* Runs a full repo-intel init and extracts key metrics for downstream consumers.
*
* @module lib/collectors/git
*/
Expand All @@ -20,7 +20,7 @@ const DEFAULT_OPTIONS = {
/**
* Collect git history data for the given repository.
*
* Runs agent-analyzer git-map init to produce a full map, then extracts
* Runs agent-analyzer repo-intel init to produce a full map, then extracts
* key metrics (hotspots, bus factor, AI ratio, etc.) from the result.
*
* @param {Object} [options={}] - Collection options
Expand All @@ -44,7 +44,7 @@ function collectGitData(options = {}) {

let map;
try {
const json = binary.runAnalyzer(['git-map', 'init', cwd]);
const json = binary.runAnalyzer(['repo-intel', 'init', cwd]);
map = JSON.parse(json);
} catch (err) {
return {
Expand All @@ -57,7 +57,6 @@ function collectGitData(options = {}) {
const fileActivity = map.fileActivity || {};
const contributors = map.contributors || {};
const aiAttribution = map.aiAttribution || {};
const commitShape = map.commitShape || {};
const conventions = map.conventions || {};
const releases = map.releases || {};

Expand All @@ -66,6 +65,7 @@ function collectGitData(options = {}) {
.map(([path, activity]) => ({
path,
changes: activity.totalChanges || 0,
recentChanges: activity.recentChanges || 0,
authors: activity.authors ? Object.keys(activity.authors).length : 0,
lastChanged: activity.lastChanged || null
}))
Expand Down Expand Up @@ -114,25 +114,21 @@ function collectGitData(options = {}) {
attributed: aiAttribution.attributed || 0,
heuristic: aiAttribution.heuristic || 0,
none: aiAttribution.none || 0,
confidence: aiAttribution.confidence || 'low',
tools: aiAttribution.tools || {}
},
busFactor,
conventions: {
style: conventions.style || null,
prefixes: conventions.prefixes || {},
scopes: conventions.scopes || {}
usesScopes: conventions.usesScopes || false
},
releaseInfo: {
tagCount: releases.tags ? releases.tags.length : 0,
lastRelease: releases.tags && releases.tags.length > 0
? releases.tags[releases.tags.length - 1]
: null,
cadence: releases.cadence || null
},
commitShape: {
typicalSize: commitShape.typicalSize || null,
filesPerCommit: commitShape.filesPerCommit || null,
mergeCount: commitShape.mergeCount || 0
}
};
}
Expand Down
1 change: 0 additions & 1 deletion lib/collectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ module.exports = {
findUndocumentedExports: docsPatterns.findUndocumentedExports,
isInternalExport: docsPatterns.isInternalExport,
isEntryPoint: docsPatterns.isEntryPoint,
getDocDriftSignals: docsPatterns.getDocDriftSignals,

collectGitData: git.collectGitData,

Expand Down
Loading