Files
evig/scripts/hirn-ingest.ts
GandClaude Opus 5 a21d8906af chore: add a formatter, and close a CSS comment that was never closed (#419)
* chore: add a formatter, matching the style this repo already writes

singleQuote=true was chosen by counting this repo's own
imports, not by fleet decree. The fleet is genuinely split and the two repos
that already had a .prettierrc disagreed with each other, so there was no
standard to restore. Quote style does not cross repo boundaries; having a
gate does.

Markdown is ignored for now — prettier rewraps prose, which would bury the
real diff.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* style: format with prettier, and close a comment that was never closed

The formatter refused this repo outright, which turned out to be a real defect
rather than a tooling complaint. kivitendo-intake.css opens a header comment,
and line 17 contains an inner /* ⚠ PRÜFEN */ — CSS comments do not nest, so
that inner terminator CLOSES the header. Everything after it is parsed as CSS
until the stray */ on line 20. A browser mis-parses it the same way.

The file exists in two places (public/presentations/ and deliverables/), both
carrying the same defect; fixing one still failed the gate, which is how the
duplicate surfaced at all.

Mechanical otherwise. This SHA is listed in .git-blame-ignore-revs.

* chore: teach git blame to skip the reformat

* fix: undo a 3-way merge duplication in AdminSidebar.tsx

Merging main with -X theirs duplicated a 30-line block: main's currency-sweep
commit and this branch's prettier reformat both touched overlapping lines in
the single-destination-group render path, and the -X theirs strategy inserted
rather than replaced, leaving two near-identical copies and a dangling closing
brace — SyntaxError: ',' expected at line 298.

The branch has no legitimate change to this file's logic, only formatting, so
main's content is correct outright. Took it wholesale rather than hand-editing
the merge result.

* fix(lint): reattach 5 directives the reformat detached

Four eslint-disable-next-line sites for react-hooks/set-state-in-effect and one
@ts-expect-error, all the same defect: the directive sat above useEffect( (or
above a JSX element), while the statement that actually errors is 1-2 lines
further down inside the block. eslint/tsc report at the real statement; the
directive, still bound to its original line number, protects nothing there.

TimecardReviewDrawer.tsx (x2), DataEntryTabs.tsx, AppointmentBookingForm.tsx,
CreatePoolModal.tsx. Same root cause documented for hirnli, fleetcrown and
ivy-portal earlier today — a positional directive is a hidden dependency on
formatting, and this is the fourth distinct shape it's taken.

* fix(i18n): restore a same-line audit-exemption marker

Fifth shape of today's positional-directive defect, this time the repo's own
i18n-hardcoded-audit convention rather than eslint or tsc: a // i18n-ok comment
exempts a hardcoded string only when it trails the SAME line. prettier wrapped
this one if-statement's long condition onto its own line, leaving the marker
on the return statement below — the exact sibling one line down
('fortgeschrittene bis experten') stayed on one line because it was short
enough not to wrap, and it alone kept passing.

Restored the one-line form and added // prettier-ignore so a future reformat
cannot re-split it. Verified against the real audit script locally: 0 new
violations.

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-31 13:35:50 +00:00

152 lines
4.9 KiB
TypeScript

#!/usr/bin/env npx tsx
/**
* Hirn Document Ingestion CLI
*
* Usage:
* npx tsx scripts/hirn-ingest.ts [options]
*
* Options:
* --dir <path> Directory to ingest (default: ./docs)
* --file <path> Single file to ingest
* --extensions File extensions to include (default: .md,.mdx,.ts,.tsx,.js,.jsx,.py,.sql,.txt)
* --exclude Directories to exclude (default: node_modules,.git,dist,build,.next)
* --stats Show current ingestion stats
* --help Show this help message
*
* Examples:
* npx tsx scripts/hirn-ingest.ts --dir ./docs
* npx tsx scripts/hirn-ingest.ts --file ./README.md
* npx tsx scripts/hirn-ingest.ts --stats
*/
import * as path from 'path';
import * as fs from 'fs';
// Load environment variables from .env.local
const envPath = path.join(process.cwd(), '.env.local');
if (fs.existsSync(envPath)) {
const envContent = fs.readFileSync(envPath, 'utf-8');
for (const line of envContent.split('\n')) {
const trimmed = line.trim();
if (trimmed && !trimmed.startsWith('#')) {
const [key, ...valueParts] = trimmed.split('=');
if (key && valueParts.length > 0) {
process.env[key] = valueParts.join('=');
}
}
}
}
async function main() {
const args = process.argv.slice(2);
if (args.includes('--help') || args.includes('-h')) {
console.log(`
Hirn Document Ingestion CLI
Usage:
npx tsx scripts/hirn-ingest.ts [options]
Options:
--dir <path> Directory to ingest (default: ./docs)
--file <path> Single file to ingest
--extensions <ext> File extensions (comma-separated, default: .md,.mdx,.ts,.tsx)
--exclude <dirs> Directories to exclude (comma-separated)
--stats Show current ingestion stats
--help Show this help message
Examples:
npx tsx scripts/hirn-ingest.ts --dir ./docs
npx tsx scripts/hirn-ingest.ts --file ./README.md
npx tsx scripts/hirn-ingest.ts --dir ./src/lib --extensions .ts,.tsx
npx tsx scripts/hirn-ingest.ts --stats
`);
process.exit(0);
}
// Dynamic import to avoid loading modules before env is set
const { ingestFile, ingestDirectory, getIngestionStats } =
await import('../src/lib/hirn/ingestion');
// Show stats
if (args.includes('--stats')) {
console.log('Fetching ingestion stats...\n');
const stats = await getIngestionStats();
console.log('=== Hirn Ingestion Stats ===');
console.log(`Total Documents: ${stats.totalDocuments}`);
console.log(`Total Chunks: ${stats.totalChunks}`);
console.log(`Last Indexed: ${stats.lastIndexed ? stats.lastIndexed.toISOString() : 'Never'}`);
console.log('\nBy Type:');
Object.entries(stats.byType).forEach(([type, count]) => {
console.log(` ${type}: ${count}`);
});
process.exit(0);
}
// Parse options
const dirIndex = args.indexOf('--dir');
const fileIndex = args.indexOf('--file');
const extensionsIndex = args.indexOf('--extensions');
const excludeIndex = args.indexOf('--exclude');
const dir = dirIndex !== -1 ? args[dirIndex + 1] : null;
const file = fileIndex !== -1 ? args[fileIndex + 1] : null;
const extensions =
extensionsIndex !== -1
? args[extensionsIndex + 1].split(',')
: ['.md', '.mdx', '.ts', '.tsx', '.js', '.jsx', '.py', '.sql', '.txt'];
const exclude =
excludeIndex !== -1
? args[excludeIndex + 1].split(',')
: ['node_modules', '.git', 'dist', 'build', '.next', '__pycache__', '.cache'];
// Ingest single file
if (file) {
const filePath = path.resolve(process.cwd(), file);
console.log(`Ingesting file: ${filePath}`);
try {
const result = await ingestFile(filePath);
console.log(`\n✓ Document ID: ${result.documentId}`);
console.log(` Chunks created: ${result.chunksCreated}`);
console.log(` Updated: ${result.wasUpdated}`);
} catch (error) {
console.error(`\n✗ Error: ${error instanceof Error ? error.message : String(error)}`);
process.exit(1);
}
process.exit(0);
}
// Ingest directory
const targetDir = dir ? path.resolve(process.cwd(), dir) : path.join(process.cwd(), 'docs');
console.log(`Ingesting directory: ${targetDir}`);
console.log(`Extensions: ${extensions.join(', ')}`);
console.log(`Excluding: ${exclude.join(', ')}`);
console.log('');
try {
const result = await ingestDirectory(targetDir, {
extensions,
exclude,
recursive: true,
});
console.log('\n=== Ingestion Complete ===');
console.log(`Total files found: ${result.total}`);
console.log(`Ingested/Updated: ${result.ingested}`);
console.log(`Skipped (unchanged): ${result.skipped}`);
if (result.errors.length > 0) {
console.log(`\nErrors (${result.errors.length}):`);
result.errors.forEach((err) => console.log(` - ${err}`));
}
} catch (error) {
console.error(`\n✗ Error: ${error instanceof Error ? error.message : String(error)}`);
process.exit(1);
}
}
main().catch((error) => {
console.error('Fatal error:', error);
process.exit(1);
});