| #!/usr/bin/env node |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| const path = require('path'); |
| const fs = require('fs'); |
| const { |
| getSessionsDir, |
| getLearnedSkillsDir, |
| findFiles, |
| ensureDir, |
| readFile, |
| log, |
| output |
| } = require('../lib/utils'); |
| const { getPackageManager, getSelectionPrompt } = require('../lib/package-manager'); |
| const { listAliases } = require('../lib/session-aliases'); |
|
|
| async function main() { |
| const sessionsDir = getSessionsDir(); |
| const learnedDir = getLearnedSkillsDir(); |
|
|
| |
| ensureDir(sessionsDir); |
| ensureDir(learnedDir); |
|
|
| |
| const recentSessions = findFiles(sessionsDir, '*-session.tmp', { maxAge: 7 }); |
|
|
| if (recentSessions.length > 0) { |
| const latest = recentSessions[0]; |
| log(`[SessionStart] Found ${recentSessions.length} recent session(s)`); |
| log(`[SessionStart] Latest: ${latest.path}`); |
|
|
| |
| const content = readFile(latest.path); |
| if (content && !content.includes('[Session context goes here]')) { |
| |
| output(`Previous session summary:\n${content}`); |
| } |
| } |
|
|
| |
| const learnedSkills = findFiles(learnedDir, '*.md'); |
|
|
| if (learnedSkills.length > 0) { |
| log(`[SessionStart] ${learnedSkills.length} learned skill(s) available in ${learnedDir}`); |
| } |
|
|
| |
| const aliases = listAliases({ limit: 5 }); |
|
|
| if (aliases.length > 0) { |
| const aliasNames = aliases.map(a => a.name).join(', '); |
| log(`[SessionStart] ${aliases.length} session alias(es) available: ${aliasNames}`); |
| log(`[SessionStart] Use /sessions load <alias> to continue a previous session`); |
| } |
|
|
| |
| const activeTicketFile = path.join(process.cwd(), '.ai', 'tickets', 'active.md'); |
| if (fs.existsSync(activeTicketFile)) { |
| const activeContent = readFile(activeTicketFile); |
| const ticketIdMatch = activeContent && activeContent.match(/^(GH-\d+|\d+)$/m); |
| if (ticketIdMatch) { |
| const rawId = ticketIdMatch[1]; |
| const ticketId = rawId.startsWith('GH-') ? rawId : `GH-${rawId}`; |
| const contextFile = path.join(process.cwd(), '.ai', 'tickets', ticketId, 'context.md'); |
| if (fs.existsSync(contextFile)) { |
| const contextContent = readFile(contextFile); |
| if (contextContent) { |
| output(`Active ticket context (${ticketId}):\n${contextContent}`); |
| log(`[SessionStart] Loaded ticket context: ${ticketId}`); |
| } |
| } |
| } |
| } |
|
|
| |
| const buildingSetupPath = path.join(process.cwd(), 'BUILDING-SETUP.md'); |
| const buildingMdPath = path.join(process.cwd(), 'BUILDING.md'); |
| if (fs.existsSync(buildingSetupPath) && !fs.existsSync(buildingMdPath)) { |
| log('[SessionStart] BUILDING-SETUP.md found — build journal not yet initialized'); |
| output(`IMPORTANT: This project has BUILDING-SETUP.md but no BUILDING.md yet. |
| The build journal has not been set up. Before starting any work, tell the user: |
| "I noticed BUILDING-SETUP.md is present but BUILDING.md hasn't been created yet. Would you like to set up your build journal now? Just say the word and I'll run through the setup — it takes 2-3 minutes and will self-update as you build." |
| Do not start any implementation work until you've offered this.`); |
| } |
|
|
| |
| const pm = getPackageManager(); |
| log(`[SessionStart] Package manager: ${pm.name} (${pm.source})`); |
|
|
| |
| if (pm.source === 'default') { |
| log('[SessionStart] No package manager preference found.'); |
| log(getSelectionPrompt()); |
| } |
|
|
| process.exit(0); |
| } |
|
|
| main().catch(err => { |
| console.error('[SessionStart] Error:', err.message); |
| process.exit(0); |
| }); |
|
|