phase-7_alpha: legacy code cleanup

This commit is contained in:
Kazuma
2026-06-05 22:27:53 -04:00
committed by Kazuma
parent 5b32bd7a04
commit 7cb1b03fd5
13 changed files with 31 additions and 983 deletions
-85
View File
@@ -1,85 +0,0 @@
/**
* bin/finance.ts — Personal Finance CLI
*/
import 'dotenv/config';
import { existsSync, readFileSync } from 'fs';
import { SimpleFINClient, saveAccessUrlToEnv } from '../server/clients/SimpleFINClient';
import { FinanceReporter } from '../server/reporters/FinanceReporter';
import { PersonalFinanceAnalyzer } from '../server/services/PersonalFinanceAnalyzer';
import { PortfolioAdvisor } from '../server/services/PortfolioAdvisor';
import { ScreenerEngine } from '../server/services/ScreenerEngine';
import type { PortfolioHolding } from '../server/types';
const PORTFOLIO_PATH = './portfolio.json';
async function main(): Promise<void> {
if (!existsSync(PORTFOLIO_PATH))
throw new Error('portfolio.json not found — edit it with your holdings and re-run.');
const { holdings } = JSON.parse(readFileSync(PORTFOLIO_PATH, 'utf8')) as {
holdings: PortfolioHolding[];
};
const byType = holdings.reduce<Record<string, number>>((acc, h) => {
const t = h.type ?? 'stock';
acc[t] = (acc[t] ?? 0) + 1;
return acc;
}, {});
console.log(
`📋 Portfolio: ${holdings.length} positions — ${Object.entries(byType)
.map(([t, n]) => `${n} ${t}`)
.join(', ')}\n`,
);
// ── SimpleFIN accounts (optional)
let personalFinance = null;
if (process.env.SIMPLEFIN_ACCESS_URL || process.env.SIMPLEFIN_SETUP_TOKEN) {
try {
process.stdout.write('💰 Fetching SimpleFIN accounts...');
const client = new SimpleFINClient({ onAccessUrlClaimed: saveAccessUrlToEnv });
await client.init();
const { accounts } = await client.getAccounts();
personalFinance = new PersonalFinanceAnalyzer().analyze(accounts);
process.stdout.write(` ${accounts.length} accounts loaded\n`);
} catch (err) {
process.stdout.write(` skipped — ${(err as Error).message}\n`);
}
} else {
console.log(' Add SIMPLEFIN_SETUP_TOKEN to .env for account balances & spending data\n');
}
// ── Screen stocks & ETFs
const screenableTickers = holdings
.filter((h) => (h.type ?? 'stock') !== 'crypto')
.map((h) => h.ticker.toUpperCase());
let results = {
STOCK: [] as any[],
ETF: [] as any[],
BOND: [] as any[],
ERROR: [] as any[],
marketContext: {} as any,
};
if (screenableTickers.length > 0) {
process.stdout.write(`📊 Screening ${screenableTickers.length} stock/ETF positions...`);
results = (await new ScreenerEngine().screenTickers(screenableTickers)) as any;
process.stdout.write(' done\n');
}
process.stdout.write('💡 Generating portfolio advice...');
const advice = await new PortfolioAdvisor().advise(holdings, results);
process.stdout.write(' done\n');
const reportPath = new FinanceReporter().generate(
advice as any,
personalFinance,
results.marketContext,
);
console.log(`\n✅ Finance report: ${reportPath}\n`);
}
main().catch((err) => {
console.error('Failed:', (err as Error).message);
process.exit(1);
});
-84
View File
@@ -1,84 +0,0 @@
/**
* bin/screen.ts — Market Screener CLI
*
* Fetches today's catalyst tickers from Yahoo Finance news,
* screens them under both Market-Adjusted and Fundamental lenses,
* and saves a full HTML report.
*
* Usage:
* npm start → Yahoo news → catalyst tickers → screen
* npm start -- watch → default watchlist
* npm start -- AAPL MSFT VOO → specific tickers
*/
import 'dotenv/config';
import { CatalystAnalyst } from '../server/services/CatalystAnalyst';
import { ScreenerEngine } from '../server/services/ScreenerEngine';
import { HtmlReporter } from '../server/reporters/HtmlReporter';
const DEFAULT_WATCHLIST: string[] = [
'PLTR',
'AAPL',
'MSFT',
'TSLA',
'O',
'VOO',
'QQQ',
'BND',
'LQD',
'TLT',
'IEF',
'SHY',
'GOVT',
'AGG',
'MUB',
];
async function main(): Promise<void> {
const args = process.argv.slice(2);
let tickers: string[] = [];
if (args.length > 0 && args[0] !== 'watch') {
tickers = args.map((t) => t.toUpperCase());
console.log(`📋 Screening: ${tickers.join(', ')}\n`);
} else if (args[0] === 'watch') {
tickers = DEFAULT_WATCHLIST;
console.log(`📋 Screening default watchlist (${tickers.length} tickers)\n`);
} else {
try {
const { tickers: newsTickers, stories } = await new CatalystAnalyst().run();
if (newsTickers.length === 0) {
console.warn("⚠ No tickers in today's news — using default watchlist\n");
tickers = DEFAULT_WATCHLIST;
} else {
tickers = newsTickers;
console.log("\n📰 Stories driving today's screen:");
stories.slice(0, 5).forEach((s) => {
const tags = s.tickers.slice(0, 3).join(', ');
console.log(`${s.title}${tags ? ` [${tags}]` : ''}`);
});
console.log(`\n📋 Tickers: ${tickers.join(', ')}\n`);
}
} catch (err) {
console.warn(
`⚠ Catalyst analysis failed (${(err as Error).message}) — using default watchlist\n`,
);
tickers = DEFAULT_WATCHLIST;
}
}
try {
const { STOCK, ETF, BOND, ERROR, marketContext } =
await new ScreenerEngine().screenWithProgress(tickers);
const reportPath = new HtmlReporter().generate(
{ STOCK, ETF, BOND, ERROR } as any,
marketContext,
);
console.log(`\n✅ Done — report saved to: ${reportPath}\n`);
} catch (err) {
console.error('Screener failed:', (err as Error).message);
process.exit(1);
}
}
main().catch(console.error);