Skip to content
Merged
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
35 changes: 24 additions & 11 deletions commands/sync-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,40 @@ const scope = scopeArg ? scopeArg.split('=')[1] : 'recent';
const pathArg = args.find(a => !a.startsWith('--') && a !== 'report' && a !== 'apply');
```

### Step 2: Pre-fetch repo-intel doc-drift data
### Step 2: Pre-fetch repo-intel doc analysis data

```javascript
let repoIntelContext = '';
try {
const { binary } = require('@agentsys/lib');
const { getStateDirPath } = require('@agentsys/lib/platform/state-dir');
const fs = require('fs');
const path = require('path');
const cwd = process.cwd();
const stateDir = ['.claude', '.opencode', '.codex'].find(d => fs.existsSync(path.join(cwd, d))) || '.claude';
const mapFile = path.join(cwd, stateDir, 'repo-intel.json');
const mapFile = require('path').join(getStateDirPath(cwd), 'repo-intel.json');
const q = (args) => { try { return JSON.parse(binary.runAnalyzer(args)); } catch { return null; } };

if (fs.existsSync(mapFile)) {
const docDrift = JSON.parse(binary.runAnalyzer(['repo-intel', 'query', 'doc-drift', '--top', '20', '--map-file', mapFile, cwd]));
if (docDrift.length > 0) {
const stale = docDrift.filter(d => d.codeCoupling === 0).map(d => d.path);
repoIntelContext = '\n\nRepo-intel doc-drift data (use this, do not re-scan):';
if (stale.length > 0) {
repoIntelContext += '\nDocs with ZERO code coupling (likely stale, check these first): ' + stale.join(', ');
// Symbol-level stale doc references (Phase 4 - most precise)
const staleDocs = q(['repo-intel', 'query', 'stale-docs', '--top', '30', '--map-file', mapFile, cwd]);
// Heuristic doc-drift (Phase 1 - coupling-based)
const docDrift = q(['repo-intel', 'query', 'doc-drift', '--top', '20', '--map-file', mapFile, cwd]);

if ((staleDocs && staleDocs.length > 0) || (docDrift && docDrift.length > 0)) {
repoIntelContext = '\n\nRepo-intel doc analysis (use this data, do NOT re-scan):';

if (staleDocs && staleDocs.length > 0) {
repoIntelContext += '\n\nStale doc references (symbol-level - highest priority):';
staleDocs.forEach(s => {
repoIntelContext += `\n ${s.doc}:${s.line} "${s.reference}" [${s.issue}] ${s.suggestion}`;
});
}
Comment on lines +78 to +83
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While the current implementation is correct, using map and join is a more idiomatic and performant way to build strings from an array in JavaScript compared to using forEach with repeated string concatenation. This change would also make the code slightly more concise.

Suggested change
if (staleDocs && staleDocs.length > 0) {
repoIntelContext += '\n\nStale doc references (symbol-level - highest priority):';
staleDocs.forEach(s => {
repoIntelContext += `\n ${s.doc}:${s.line} "${s.reference}" [${s.issue}] ${s.suggestion}`;
});
}
if (staleDocs && staleDocs.length > 0) {
const staleDocItems = staleDocs.map(s => `\n ${s.doc}:${s.line} \"${s.reference}\" [${s.issue}] ${s.suggestion}`);
repoIntelContext += '\n\nStale doc references (symbol-level - highest priority):' + staleDocItems.join('');
}


if (docDrift && docDrift.length > 0) {
const severelyStale = docDrift.filter(d => d.codeCoupling === 0).map(d => d.path);
if (severelyStale.length > 0) {
repoIntelContext += '\n\nDocs with ZERO code coupling (likely entirely stale): ' + severelyStale.join(', ');
}
}
repoIntelContext += '\nFull doc-drift data: ' + JSON.stringify(docDrift);
}
}
} catch (e) { /* unavailable */ }
Expand Down
Loading