fix(intel): make PostToolUse hook opt-in only
Hook now checks if .planning/intel/ exists before indexing. This prevents polluting non-GSD projects with intel files. Directory is created by: - /gsd:new-project (during setup) - /gsd:analyze-codebase (explicit user action) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -381,9 +381,19 @@ function generateSummary(index, conventions) {
|
|||||||
/**
|
/**
|
||||||
* Update the index.json file with new file entry
|
* Update the index.json file with new file entry
|
||||||
* Uses read-modify-write pattern with synchronous operations
|
* Uses read-modify-write pattern with synchronous operations
|
||||||
|
*
|
||||||
|
* IMPORTANT: Only runs if .planning/intel/ already exists (opt-in behavior).
|
||||||
|
* Directory is created by /gsd:new-project or /gsd:analyze-codebase.
|
||||||
*/
|
*/
|
||||||
function updateIndex(filePath, exports, imports) {
|
function updateIndex(filePath, exports, imports) {
|
||||||
const indexPath = path.join(process.cwd(), '.planning', 'intel', 'index.json');
|
const intelDir = path.join(process.cwd(), '.planning', 'intel');
|
||||||
|
const indexPath = path.join(intelDir, 'index.json');
|
||||||
|
|
||||||
|
// Opt-in check: only index if intel directory already exists
|
||||||
|
// This prevents polluting non-GSD projects
|
||||||
|
if (!fs.existsSync(intelDir)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Read existing index or create new
|
// Read existing index or create new
|
||||||
let index = { version: 1, updated: null, files: {} };
|
let index = { version: 1, updated: null, files: {} };
|
||||||
@@ -405,10 +415,7 @@ function updateIndex(filePath, exports, imports) {
|
|||||||
};
|
};
|
||||||
index.updated = Date.now();
|
index.updated = Date.now();
|
||||||
|
|
||||||
// Ensure directory exists
|
// Write atomically (directory already exists per opt-in check above)
|
||||||
fs.mkdirSync(path.dirname(indexPath), { recursive: true });
|
|
||||||
|
|
||||||
// Write atomically
|
|
||||||
fs.writeFileSync(indexPath, JSON.stringify(index, null, 2));
|
fs.writeFileSync(indexPath, JSON.stringify(index, null, 2));
|
||||||
|
|
||||||
// Detect and save conventions (regenerated on every index update)
|
// Detect and save conventions (regenerated on every index update)
|
||||||
|
|||||||
Reference in New Issue
Block a user