(sessionId, info = {})
| 405 | // NOT read-modify-write to dedupe here — that would race across concurrent |
| 406 | // sessions; append-only is safe and the file is bounded by session count. |
| 407 | function recordMarkedSession(sessionId, info = {}) { |
| 408 | const sid = String(sessionId || '').trim(); |
| 409 | if (!sid) return false; |
| 410 | const file = getMarkedSessionsPath(); |
| 411 | try { |
| 412 | fs.mkdirSync(path.dirname(file), { recursive: true }); |
| 413 | const record = { |
| 414 | session_id: sid, |
| 415 | ...(info.cwd ? { cwd: String(info.cwd) } : {}), |
| 416 | ...(info.source ? { source: String(info.source) } : {}), |
| 417 | marked_at: new Date().toISOString(), |
| 418 | }; |
| 419 | fs.appendFileSync(file, JSON.stringify(record) + '\n', { encoding: 'utf8', mode: 0o600 }); |
| 420 | return true; |
| 421 | } catch (_) { |
| 422 | // Never let a registry write failure break session-start: the context |
| 423 | // injection (stdout JSON) must always be emitted. |
| 424 | return false; |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | // TTL throttle keyed by an arbitrary string. Returns true if `key` fired within |
| 429 | // the last `ttlMs` (caller should suppress); otherwise records "now" for `key` |
no test coverage detected