feat(tools): add global learnings store with CRUD library and CLI support (#1831)

* feat(tools): add global learnings store with CRUD library and CLI support

* fix(tools): address review feedback for global learnings store

- Validate learning IDs against path traversal in learningsRead, learningsDelete, and cmdLearningsDelete
- Fix total invariant in learningsCopyFromProject (total = created + skipped)
- Wrap cmdLearningsPrune in try/catch to handle invalid duration format
- Rename raw -> content in readLearningFile to avoid variable shadowing
- Add CLI integration tests for list, query, prune error, and unknown subcommand
This commit is contained in:
Rezolv
2026-04-05 19:09:14 -04:00
committed by GitHub
parent 790cbbd0d6
commit f25ae33dff
3 changed files with 940 additions and 0 deletions

View File

@@ -147,6 +147,13 @@
*
* Documentation:
* docs-init Project context for docs-update workflow
*
* Learnings:
* learnings list List all global learnings (JSON)
* learnings query --tag <tag> Query learnings by tag
* learnings copy Copy from current project's LEARNINGS.md
* learnings prune --older-than <dur> Remove entries older than duration (e.g. 90d)
* learnings delete <id> Delete a learning by ID
*/
const fs = require('fs');
@@ -167,6 +174,7 @@ const profilePipeline = require('./lib/profile-pipeline.cjs');
const profileOutput = require('./lib/profile-output.cjs');
const workstream = require('./lib/workstream.cjs');
const docs = require('./lib/docs.cjs');
const learnings = require('./lib/learnings.cjs');
// ─── Arg parsing helpers ──────────────────────────────────────────────────────
@@ -1003,6 +1011,34 @@ async function runCommand(command, args, cwd, raw) {
break;
}
// ─── Learnings ─────────────────────────────────────────────────────────
case 'learnings': {
const subcommand = args[1];
if (subcommand === 'list') {
learnings.cmdLearningsList(raw);
} else if (subcommand === 'query') {
const tagIdx = args.indexOf('--tag');
const tag = tagIdx !== -1 ? args[tagIdx + 1] : null;
if (!tag) error('Usage: gsd-tools learnings query --tag <tag>');
learnings.cmdLearningsQuery(tag, raw);
} else if (subcommand === 'copy') {
learnings.cmdLearningsCopy(cwd, raw);
} else if (subcommand === 'prune') {
const olderIdx = args.indexOf('--older-than');
const olderThan = olderIdx !== -1 ? args[olderIdx + 1] : null;
if (!olderThan) error('Usage: gsd-tools learnings prune --older-than <duration>');
learnings.cmdLearningsPrune(olderThan, raw);
} else if (subcommand === 'delete') {
const id = args[2];
if (!id) error('Usage: gsd-tools learnings delete <id>');
learnings.cmdLearningsDelete(id, raw);
} else {
error('Unknown learnings subcommand. Available: list, query, copy, prune, delete');
}
break;
}
default:
error(`Unknown command: ${command}`);
}