⛰️ LifeOS — The AI-powered Life Operating System that helps you hill climb to wherever you're going.
fix: Add timezone validation to installer (#302)
IJASolutions4d1bd88758cf
diff --git a/Bundles/Kai/install.ts b/Bundles/Kai/install.tsold mode 100644new mode 100755index 35b4fa91..9ba521ff--- a/Bundles/Kai/install.ts+++ b/Bundles/Kai/install.ts@@ -60,6 +60,15 @@ async function askWithDefault(question: string, defaultValue: string): Promise<sreturn answer || defaultValue;}+function isValidTimezone(tz: string): boolean {+ try {+ Intl.DateTimeFormat(undefined, { timeZone: tz });+ return true;+ } catch {+ return false;+ }+}+async function askYesNo(question: string, defaultYes = true): Promise<boolean> {const defaultStr = defaultYes ? "Y/n" : "y/N";const answer = await ask(`${question} [${defaultStr}]: `);@@ -327,10 +336,16 @@ async function gatherConfig(): Promise<WizardConfig> {existing.daName || "Kai");- const timeZone = await askWithDefault(- "What's your timezone?",- existing.timeZone || Intl.DateTimeFormat().resolvedOptions().timeZone- );+ // Get timezone with validation+ const defaultTz = Intl.DateTimeFormat().resolvedOptions().timeZone;+ const existingTz = existing.timeZone && isValidTimezone(existing.timeZone) ? existing.timeZone : defaultTz;+ let timeZone = await askWithDefault("What's your timezone?", existingTz);++ while (!isValidTimezone(timeZone)) {+ console.log(` ⚠️ "${timeZone}" is not a valid IANA timezone.`);+ console.log(` Examples: America/New_York, Europe/London, Asia/Tokyo`);+ timeZone = await askWithDefault("What's your timezone?", defaultTz);+ }// Voice - in update mode, default to yes if already configuredconst defaultWantsVoice = !!existing.elevenLabsApiKey;diff --git a/Packs/kai-history-system/src/stop-hook.ts b/Packs/kai-history-system/src/stop-hook.tsindex 677c5082..6da3cf29 100644--- a/Packs/kai-history-system/src/stop-hook.ts+++ b/Packs/kai-history-system/src/stop-hook.ts@@ -68,6 +68,33 @@ function generateFilename(type: string, description: string): string {return `${timestamp}_${type}_${kebab}.md`;}+function extractLastResponse(transcriptPath: string): string | null {+ try {+ if (!existsSync(transcriptPath)) return null;++ const content = require('fs').readFileSync(transcriptPath, 'utf-8');+ const lines = content.split('\n').filter((l: string) => l.trim());++ // Find last assistant message+ for (let i = lines.length - 1; i >= 0; i--) {+ try {+ const entry = JSON.parse(lines[i]);+ if (entry.type === 'assistant' && entry.message?.content) {+ // Extract text from content array+ const textParts = entry.message.content+ .filter((c: any) => c.type === 'text')+ .map((c: any) => c.text)+ .join('\n');+ if (textParts.length > 50) return textParts;+ }+ } catch {}+ }+ return null;+ } catch {+ return null;+ }+}+async function main() {try {const stdinData = await Bun.stdin.text();@@ -76,14 +103,21 @@ async function main() {}const payload: StopPayload = JSON.parse(stdinData);- if (!payload.response) {++ // Get response from payload or extract from transcript+ let response = payload.response;+ if (!response && payload.transcript_path) {+ response = extractLastResponse(payload.transcript_path) || undefined;+ }++ if (!response) {process.exit(0);}const paiDir = process.env.PAI_DIR || join(homedir(), '.config', 'pai');const historyDir = join(paiDir, 'history');- const isLearning = hasLearningIndicators(payload.response);+ const isLearning = hasLearningIndicators(response);const type = isLearning ? 'LEARNING' : 'SESSION';const subdir = isLearning ? 'learnings' : 'sessions';@@ -95,7 +129,7 @@ async function main() {mkdirSync(outputDir, { recursive: true });}- const summary = extractSummary(payload.response);+ const summary = extractSummary(response);const filename = generateFilename(type, summary);const filepath = join(outputDir, filename);@@ -108,7 +142,7 @@ executor: main# ${type}: ${summary}-${payload.response}+${response.slice(0, 5000)}---