railyard/apps/ritgram/web/utils/aitmChangeStory.ts
caelum0x f80b04ae0f feat(ritgram): move GitGram app into railyard as Ritgram, next to Rithub
Moved later/gitgram-ai/gitgram/ to apps/ritgram/ (fresh history; full history stays in caelum0x/gitgram).
AITimeMachine stays separate in later/gitgram-ai per the Rithub master plan.
Logs, pid files and env files are ignored; GPL-3.0 mobile/proximity noted in THIRD_PARTY_NOTICES.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-13 04:18:46 +03:00

75 lines
2.1 KiB
TypeScript

export interface AitmChangeStory {
title?: string;
checkpointId: string;
fromCheckpointId?: string;
aitmProjectId?: string;
diffAdded: number;
diffRemoved: number;
diffModified: number;
changedFiles: string[];
}
const START = '[AITM_CHANGE_STORY]';
const END = '[/AITM_CHANGE_STORY]';
export function parseAitmChangeStoryBlock(content: string): { story: AitmChangeStory | null; cleanContent: string } {
if (!content || !content.includes(START) || !content.includes(END)) {
return { story: null, cleanContent: content || '' };
}
const startIdx = content.indexOf(START);
const endIdx = content.indexOf(END, startIdx);
if (startIdx < 0 || endIdx < 0) {
return { story: null, cleanContent: content };
}
const blockBody = content
.slice(startIdx + START.length, endIdx)
.split('\n')
.map((line) => line.trim())
.filter(Boolean);
const kv: Record<string, string> = {};
for (const line of blockBody) {
const eq = line.indexOf('=');
if (eq <= 0) continue;
const key = line.slice(0, eq).trim();
const value = line.slice(eq + 1).trim();
kv[key] = value;
}
if (!kv.checkpointId) {
return {
story: null,
cleanContent: (content.slice(0, startIdx) + content.slice(endIdx + END.length)).trim(),
};
}
let files: string[] = [];
if (kv.changedFiles) {
try {
const parsed = JSON.parse(kv.changedFiles);
if (Array.isArray(parsed)) {
files = parsed.map((f) => String(f)).filter(Boolean);
}
} catch {
files = kv.changedFiles.split(',').map((f) => f.trim()).filter(Boolean);
}
}
const story: AitmChangeStory = {
title: kv.title || undefined,
checkpointId: kv.checkpointId,
fromCheckpointId: kv.fromCheckpointId || undefined,
aitmProjectId: kv.aitmProjectId || undefined,
diffAdded: Number(kv.diffAdded || 0),
diffRemoved: Number(kv.diffRemoved || 0),
diffModified: Number(kv.diffModified || 0),
changedFiles: files,
};
const cleanContent = (content.slice(0, startIdx) + content.slice(endIdx + END.length)).trim();
return { story, cleanContent };
}