(server)
| 576 | return { |
| 577 | name: 'plannotator-dev-mock-api', |
| 578 | configureServer(server) { |
| 579 | server.middlewares.use(async (req, res, next) => { |
| 580 | if (req.url === '/api/hooks/status') { |
| 581 | res.setHeader('Content-Type', 'application/json'); |
| 582 | try { |
| 583 | const { readImprovementHook, getImprovementHookExpectedPath } = await import('@plannotator/shared/improvement-hooks'); |
| 584 | const { loadConfig } = await import('@plannotator/shared/config'); |
| 585 | const { composeImproveContext } = await import('@plannotator/shared/pfm-reminder'); |
| 586 | const config = loadConfig(); |
| 587 | const hook = readImprovementHook('enterplanmode-improve'); |
| 588 | const pfmEnabled = config.pfmReminder === true; |
| 589 | const composed = composeImproveContext({ pfmEnabled, improvementHookContent: hook?.content ?? null }); |
| 590 | res.end(JSON.stringify({ |
| 591 | pfmReminder: { enabled: pfmEnabled }, |
| 592 | improvementHook: { |
| 593 | present: !!hook, |
| 594 | filePath: hook?.filePath ?? getImprovementHookExpectedPath('enterplanmode-improve'), |
| 595 | fileSize: hook?.content?.length ?? null, |
| 596 | content: hook?.content ?? null, |
| 597 | }, |
| 598 | composedLength: composed?.length ?? null, |
| 599 | })); |
| 600 | } catch { |
| 601 | res.end(JSON.stringify({ |
| 602 | pfmReminder: { enabled: false }, |
| 603 | improvementHook: { present: false, filePath: '~/.plannotator/hooks/compound/enterplanmode-improve-hook.txt', fileSize: null, content: null }, |
| 604 | composedLength: null, |
| 605 | })); |
| 606 | } |
| 607 | return; |
| 608 | } |
| 609 | |
| 610 | if (req.url === '/api/config' && req.method === 'POST') { |
| 611 | let body = ''; |
| 612 | req.on('data', (chunk: Buffer) => { body += chunk.toString(); }); |
| 613 | req.on('end', async () => { |
| 614 | try { |
| 615 | const { saveConfig } = await import('@plannotator/shared/config'); |
| 616 | const parsed = JSON.parse(body); |
| 617 | const toSave: Record<string, unknown> = {}; |
| 618 | if (parsed.pfmReminder !== undefined) toSave.pfmReminder = parsed.pfmReminder; |
| 619 | if (Object.keys(toSave).length > 0) saveConfig(toSave as any); |
| 620 | res.setHeader('Content-Type', 'application/json'); |
| 621 | res.end(JSON.stringify({ ok: true })); |
| 622 | } catch { |
| 623 | res.statusCode = 400; |
| 624 | res.end(JSON.stringify({ error: 'Invalid request' })); |
| 625 | } |
| 626 | }); |
| 627 | return; |
| 628 | } |
| 629 | |
| 630 | if (req.url === '/api/plan') { |
| 631 | res.setHeader('Content-Type', 'application/json'); |
| 632 | if (USE_GOAL_SETUP_DEMO) { |
| 633 | res.end(JSON.stringify({ |
| 634 | plan: '', |
| 635 | origin: 'claude-code', |
nothing calls this directly
no test coverage detected