Files
fidelity-ai-workspace/.opencode/plugins/fidelity-compaction.js

73 lines
2.3 KiB
JavaScript

import { readdir, readFile } from "node:fs/promises"
import path from "node:path"
async function safeRead(filePath) {
try {
return await readFile(filePath, "utf8")
} catch {
return null
}
}
export const FidelityCompaction = async ({ directory }) => {
return {
"experimental.session.compacting": async (_input, output) => {
const baseFiles = [
"profiles/fidelity/profile.md",
"agent-memory/behavior/agent-behavior.md",
"agent-memory/behavior/learning-sessions.md",
"agent-memory/memory/promotion-rules.md",
"agent-memory/integrations/technical-verification.md",
"agent-memory/workflows/ai-to-ai-prompting.md",
"project-knowledge/00-start/start-here.md",
"project-knowledge/01-current/current-work.md",
"project-knowledge/01-current/work-items.md",
"project-knowledge/03-context/project.md",
"project-knowledge/03-context/process/communication.md",
"project-knowledge/03-context/ios/index.md",
"project-knowledge/03-context/ios/project-swift-guidance.md",
"project-knowledge/04-people/manager.md",
"project-knowledge/04-people/index.md",
]
const sections = []
for (const relPath of baseFiles) {
const content = await safeRead(path.join(directory, relPath))
if (content) {
sections.push(`### ${relPath}\n${content.trim()}`)
}
}
try {
const logsDir = path.join(directory, "project-knowledge/06-daily")
const logs = (await readdir(logsDir))
.filter((name) => name.endsWith(".md"))
.sort()
.slice(-1)
for (const logName of logs) {
const content = await safeRead(path.join(logsDir, logName))
if (content) {
sections.push(`### project-knowledge/06-daily/${logName}\n${content.trim()}`)
}
}
} catch {
// No logs available yet.
}
if (sections.length > 0) {
output.context.push(
[
"## AI Workspace Persistent Context",
"Preserve this operational memory across compaction.",
"If later messages introduced corrections or durable facts, prefer the corrected view over stale summaries.",
"",
sections.join("\n\n"),
].join("\n"),
)
}
},
}
}