* Facts to inject for a session in `cwd`: this project's facts PLUS all global * user facts. User facts come first so personal preferences lead. Deduped.
(cwd: string, limit = 50)
| 313 | * facts are stored with a '*' sentinel cwd so they never collide with a real path. |
| 314 | */ |
| 315 | addFact(sessionId: string, cwd: string, fact: string, scope: 'project' | 'user' = 'project'): void { |
| 316 | this.db.prepare(`INSERT INTO session_facts (session_id, cwd, fact, scope) VALUES (?, ?, ?, ?)`).run( |
| 317 | sessionId, |
| 318 | scope === 'user' ? '*' : cwd, |
| 319 | fact, |
| 320 | scope, |
| 321 | ); |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Facts to inject for a session in `cwd`: this project's facts PLUS all global |
| 326 | * user facts. User facts come first so personal preferences lead. Deduped. |
| 327 | */ |
| 328 | getFactsForCwd(cwd: string, limit = 50): string[] { |
| 329 | const userRows = this.db.prepare( |
| 330 | `SELECT DISTINCT fact FROM session_facts WHERE scope = 'user' ORDER BY id DESC LIMIT ?`, |
| 331 | ).all(limit) as { fact: string }[]; |
| 332 | const projectRows = this.db.prepare( |
| 333 | `SELECT DISTINCT fact FROM session_facts WHERE cwd = ? AND scope = 'project' ORDER BY id DESC LIMIT ?`, |
| 334 | ).all(cwd, limit) as { fact: string }[]; |
no test coverage detected