Migrate memory cloud to Appwrite-backed live service
This commit is contained in:
@@ -9,6 +9,8 @@ lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
package-server.json
|
||||
server/
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
|
||||
Generated
+816
-2
File diff suppressed because it is too large
Load Diff
+4
-1
@@ -7,9 +7,12 @@
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
"preview": "vite preview",
|
||||
"start": "node server.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"express": "^5.1.0",
|
||||
"react": "^19.2.4",
|
||||
"react-dom": "^19.2.4"
|
||||
},
|
||||
|
||||
@@ -0,0 +1,502 @@
|
||||
import express from 'express'
|
||||
import cors from 'cors'
|
||||
import fs from 'node:fs'
|
||||
import fsp from 'node:fs/promises'
|
||||
import path from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { execFile } from 'node:child_process'
|
||||
import { promisify } from 'node:util'
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
|
||||
const app = express()
|
||||
app.use(cors())
|
||||
app.use(express.json({ limit: '1mb' }))
|
||||
|
||||
const WORKSPACE_DIR = path.join(process.env.HOME || '', '.openclaw/workspace')
|
||||
const MEMORY_DIR = path.join(WORKSPACE_DIR, 'memory')
|
||||
const MAIN_MEMORY_FILE = path.join(WORKSPACE_DIR, 'MEMORY.md')
|
||||
const DIST_DIR = path.join(__dirname, 'dist')
|
||||
const DAILY_MEMORY_PATTERN = /^\d{4}-\d{2}-\d{2}\.md$/
|
||||
|
||||
const APPWRITE_ENDPOINT = process.env.APPWRITE_SELF_HOSTED_URL || process.env.APPWRITE_LOCAL_ENDPOINT
|
||||
const APPWRITE_PROJECT_ID = process.env.APPWRITE_SELF_HOSTED_PROJECT_ID || process.env.APPWRITE_LOCAL_PROJECT_ID
|
||||
const APPWRITE_KEY = process.env.APPWRITE_SELF_HOSTED_API_KEY || process.env.APPWRITE_LOCAL_API_KEY
|
||||
const APPWRITE_DATABASE_ID = process.env.APPWRITE_MEMORY_DATABASE_ID || 'freecastle'
|
||||
const APPWRITE_COLLECTION_ID = process.env.APPWRITE_MEMORY_COLLECTION_ID || 'memory_files'
|
||||
|
||||
const APPWRITE_ENV = {
|
||||
...process.env,
|
||||
APPWRITE_ENDPOINT,
|
||||
APPWRITE_PROJECT_ID,
|
||||
APPWRITE_KEY,
|
||||
}
|
||||
|
||||
if (!fs.existsSync(MEMORY_DIR)) {
|
||||
fs.mkdirSync(MEMORY_DIR, { recursive: true })
|
||||
}
|
||||
|
||||
function todayDateStamp() {
|
||||
return new Date().toISOString().split('T')[0]
|
||||
}
|
||||
|
||||
function currentTimeStamp() {
|
||||
return new Date().toTimeString().slice(0, 5)
|
||||
}
|
||||
|
||||
function isValidDailyMemoryFilename(filename) {
|
||||
return typeof filename === 'string' && DAILY_MEMORY_PATTERN.test(filename)
|
||||
}
|
||||
|
||||
function isValidMemoryFilename(filename) {
|
||||
return filename === 'MEMORY.md' || isValidDailyMemoryFilename(filename)
|
||||
}
|
||||
|
||||
function resolveDailyMemoryPath(filename) {
|
||||
if (!isValidDailyMemoryFilename(filename)) return null
|
||||
const resolvedPath = path.resolve(MEMORY_DIR, filename)
|
||||
const memoryDirPrefix = `${path.resolve(MEMORY_DIR)}${path.sep}`
|
||||
return resolvedPath.startsWith(memoryDirPrefix) ? resolvedPath : null
|
||||
}
|
||||
|
||||
function resolveMemoryPath(filename) {
|
||||
if (filename === 'MEMORY.md') return MAIN_MEMORY_FILE
|
||||
return resolveDailyMemoryPath(filename)
|
||||
}
|
||||
|
||||
function kindForFilename(filename) {
|
||||
return filename === 'MEMORY.md' ? 'main' : 'daily'
|
||||
}
|
||||
|
||||
function readUtf8File(filePath) {
|
||||
return fs.readFileSync(filePath, 'utf8')
|
||||
}
|
||||
|
||||
function wordCount(content) {
|
||||
return content.trim().split(/\s+/).filter(Boolean).length
|
||||
}
|
||||
|
||||
function getEntryCount(content) {
|
||||
if (!content) return 0
|
||||
return content.split('\n').filter((line) => line.trim().startsWith('- [')).length
|
||||
}
|
||||
|
||||
function formatDateLabel(filename) {
|
||||
const match = filename.match(/^(\d{4})-(\d{2})-(\d{2})\.md$/)
|
||||
if (!match) return filename
|
||||
const [, year, month, day] = match
|
||||
const date = new Date(`${year}-${month}-${day}T12:00:00`)
|
||||
return date.toLocaleDateString(undefined, {
|
||||
weekday: 'short',
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
})
|
||||
}
|
||||
|
||||
async function runAppwrite(args) {
|
||||
const { stdout } = await execFileAsync('appwrite', args, {
|
||||
env: APPWRITE_ENV,
|
||||
maxBuffer: 10 * 1024 * 1024,
|
||||
})
|
||||
return stdout?.trim() || ''
|
||||
}
|
||||
|
||||
async function runAppwriteJson(args) {
|
||||
const stdout = await runAppwrite([...args, '--json'])
|
||||
return stdout ? JSON.parse(stdout) : null
|
||||
}
|
||||
|
||||
async function getDocument(documentId) {
|
||||
try {
|
||||
return await runAppwriteJson([
|
||||
'databases', 'get-document',
|
||||
'--database-id', APPWRITE_DATABASE_ID,
|
||||
'--collection-id', APPWRITE_COLLECTION_ID,
|
||||
'--document-id', documentId,
|
||||
])
|
||||
} catch (error) {
|
||||
const stderr = `${error.stderr || ''}${error.stdout || ''}${error.message || ''}`
|
||||
if (/document_not_found|404|not found|could not be found/i.test(stderr)) return null
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async function listDocuments() {
|
||||
const result = await runAppwriteJson([
|
||||
'databases', 'list-documents',
|
||||
'--database-id', APPWRITE_DATABASE_ID,
|
||||
'--collection-id', APPWRITE_COLLECTION_ID,
|
||||
])
|
||||
return result?.documents || []
|
||||
}
|
||||
|
||||
async function upsertDocument(filename, content) {
|
||||
const data = JSON.stringify({
|
||||
filename,
|
||||
kind: kindForFilename(filename),
|
||||
content,
|
||||
})
|
||||
|
||||
const existing = await getDocument(filename)
|
||||
if (existing) {
|
||||
return runAppwriteJson([
|
||||
'databases', 'update-document',
|
||||
'--database-id', APPWRITE_DATABASE_ID,
|
||||
'--collection-id', APPWRITE_COLLECTION_ID,
|
||||
'--document-id', filename,
|
||||
'--data', data,
|
||||
])
|
||||
}
|
||||
|
||||
return runAppwriteJson([
|
||||
'databases', 'create-document',
|
||||
'--database-id', APPWRITE_DATABASE_ID,
|
||||
'--collection-id', APPWRITE_COLLECTION_ID,
|
||||
'--document-id', filename,
|
||||
'--data', data,
|
||||
])
|
||||
}
|
||||
|
||||
async function syncFileToAppwrite(filename) {
|
||||
const filePath = resolveMemoryPath(filename)
|
||||
if (!filePath || !fs.existsSync(filePath)) return null
|
||||
const content = await fsp.readFile(filePath, 'utf8')
|
||||
return upsertDocument(filename, content)
|
||||
}
|
||||
|
||||
async function syncWorkspaceToAppwrite() {
|
||||
const filenames = [
|
||||
'MEMORY.md',
|
||||
...fs.readdirSync(MEMORY_DIR).filter(isValidDailyMemoryFilename).sort(),
|
||||
]
|
||||
|
||||
for (const filename of filenames) {
|
||||
await syncFileToAppwrite(filename)
|
||||
}
|
||||
}
|
||||
|
||||
let syncPromise = syncWorkspaceToAppwrite().catch((error) => {
|
||||
console.error('Initial Appwrite sync failed:', error)
|
||||
})
|
||||
|
||||
async function ensureSync() {
|
||||
await syncPromise
|
||||
}
|
||||
|
||||
async function readMemoryDocument(filename) {
|
||||
const doc = await getDocument(filename)
|
||||
if (doc?.content != null) {
|
||||
return doc
|
||||
}
|
||||
|
||||
await syncFileToAppwrite(filename)
|
||||
return getDocument(filename)
|
||||
}
|
||||
|
||||
function buildFileMeta(doc) {
|
||||
const content = doc.content || ''
|
||||
const mtimeMs = doc.$updatedAt ? new Date(doc.$updatedAt).getTime() : Date.now()
|
||||
return {
|
||||
filename: doc.filename,
|
||||
mtimeMs,
|
||||
size: Buffer.byteLength(content, 'utf8'),
|
||||
wordCount: wordCount(content),
|
||||
entryCount: getEntryCount(content),
|
||||
dateLabel: formatDateLabel(doc.filename),
|
||||
}
|
||||
}
|
||||
|
||||
app.get('/api/health', async (req, res) => {
|
||||
try {
|
||||
await ensureSync()
|
||||
await runAppwrite(['databases', 'get-collection', '--database-id', APPWRITE_DATABASE_ID, '--collection-id', APPWRITE_COLLECTION_ID])
|
||||
res.json({
|
||||
ok: true,
|
||||
appwrite: true,
|
||||
memoryDir: fs.existsSync(MEMORY_DIR),
|
||||
mainMemory: fs.existsSync(MAIN_MEMORY_FILE),
|
||||
})
|
||||
} catch (error) {
|
||||
res.status(500).json({ ok: false, error: error.message })
|
||||
}
|
||||
})
|
||||
|
||||
app.get('/api/meta', async (req, res) => {
|
||||
try {
|
||||
await ensureSync()
|
||||
const docs = await listDocuments()
|
||||
const mainDoc = docs.find((doc) => doc.filename === 'MEMORY.md')
|
||||
const dailyDocs = docs
|
||||
.filter((doc) => isValidDailyMemoryFilename(doc.filename))
|
||||
.sort((a, b) => String(b.filename).localeCompare(String(a.filename)))
|
||||
|
||||
const mainMemory = mainDoc ? {
|
||||
exists: true,
|
||||
mtimeMs: new Date(mainDoc.$updatedAt).getTime(),
|
||||
size: Buffer.byteLength(mainDoc.content || '', 'utf8'),
|
||||
wordCount: wordCount(mainDoc.content || ''),
|
||||
entryCount: getEntryCount(mainDoc.content || ''),
|
||||
} : null
|
||||
|
||||
const dailyFiles = dailyDocs.map(buildFileMeta)
|
||||
const summary = dailyFiles.reduce((acc, file) => {
|
||||
acc.dailyFileCount += 1
|
||||
acc.totalDailyEntries += file.entryCount
|
||||
acc.totalDailyWords += file.wordCount
|
||||
return acc
|
||||
}, { dailyFileCount: 0, totalDailyEntries: 0, totalDailyWords: 0 })
|
||||
|
||||
res.json({ mainMemory, dailyFiles, summary })
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message })
|
||||
}
|
||||
})
|
||||
|
||||
app.get('/api/memories', async (req, res) => {
|
||||
try {
|
||||
await ensureSync()
|
||||
const docs = await listDocuments()
|
||||
const files = docs
|
||||
.map((doc) => doc.filename)
|
||||
.filter(isValidDailyMemoryFilename)
|
||||
.sort()
|
||||
.reverse()
|
||||
res.json(files)
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message })
|
||||
}
|
||||
})
|
||||
|
||||
app.get('/api/memories/:filename', async (req, res) => {
|
||||
try {
|
||||
const { filename } = req.params
|
||||
if (!isValidDailyMemoryFilename(filename)) {
|
||||
return res.status(400).json({ error: 'Invalid memory filename' })
|
||||
}
|
||||
await ensureSync()
|
||||
const doc = await readMemoryDocument(filename)
|
||||
if (!doc) return res.status(404).json({ error: 'File not found' })
|
||||
return res.json({ content: doc.content || '' })
|
||||
} catch (error) {
|
||||
return res.status(500).json({ error: error.message })
|
||||
}
|
||||
})
|
||||
|
||||
app.get('/api/main-memory', async (req, res) => {
|
||||
try {
|
||||
await ensureSync()
|
||||
const doc = await readMemoryDocument('MEMORY.md')
|
||||
if (!doc) return res.status(404).json({ error: 'MEMORY.md not found' })
|
||||
res.json({ content: doc.content || '' })
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message })
|
||||
}
|
||||
})
|
||||
|
||||
async function writeThrough(filename, content) {
|
||||
const filePath = resolveMemoryPath(filename)
|
||||
if (!filePath) throw new Error('Invalid memory filename')
|
||||
await fsp.writeFile(filePath, content, 'utf8')
|
||||
await upsertDocument(filename, content)
|
||||
}
|
||||
|
||||
app.put('/api/main-memory', async (req, res) => {
|
||||
try {
|
||||
const { content } = req.body
|
||||
if (typeof content !== 'string') {
|
||||
return res.status(400).json({ error: 'Content is required' })
|
||||
}
|
||||
await ensureSync()
|
||||
await writeThrough('MEMORY.md', content)
|
||||
res.json({ success: true })
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message })
|
||||
}
|
||||
})
|
||||
|
||||
app.put('/api/memories/:filename', async (req, res) => {
|
||||
try {
|
||||
const { filename } = req.params
|
||||
if (!isValidDailyMemoryFilename(filename)) {
|
||||
return res.status(400).json({ error: 'Invalid memory filename' })
|
||||
}
|
||||
const { content } = req.body
|
||||
if (typeof content !== 'string') {
|
||||
return res.status(400).json({ error: 'Content is required' })
|
||||
}
|
||||
await ensureSync()
|
||||
await writeThrough(filename, content)
|
||||
res.json({ success: true })
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message })
|
||||
}
|
||||
})
|
||||
|
||||
app.get('/api/search', async (req, res) => {
|
||||
const query = typeof req.query.q === 'string' ? req.query.q.trim().toLowerCase() : ''
|
||||
if (!query || query.length < 2) {
|
||||
return res.json({ query, results: [], total: 0 })
|
||||
}
|
||||
|
||||
try {
|
||||
await ensureSync()
|
||||
const docs = (await listDocuments())
|
||||
.filter((doc) => isValidDailyMemoryFilename(doc.filename))
|
||||
.sort((a, b) => String(b.filename).localeCompare(String(a.filename)))
|
||||
|
||||
const results = []
|
||||
for (const doc of docs) {
|
||||
const content = doc.content || ''
|
||||
const lower = content.toLowerCase()
|
||||
if (!lower.includes(query)) continue
|
||||
|
||||
const lines = content.split('\n')
|
||||
const matchingLines = lines
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line.toLowerCase().includes(query))
|
||||
.slice(0, 5)
|
||||
|
||||
const firstMatchIdx = lower.indexOf(query)
|
||||
const windowStart = Math.max(0, firstMatchIdx - 80)
|
||||
const windowEnd = Math.min(content.length, firstMatchIdx + 120)
|
||||
const snippet = content.slice(windowStart, windowEnd).replace(/\n/g, ' ')
|
||||
|
||||
results.push({
|
||||
filename: doc.filename,
|
||||
dateLabel: formatDateLabel(doc.filename),
|
||||
entryCount: getEntryCount(content),
|
||||
wordCount: wordCount(content),
|
||||
matchCount: (lower.match(new RegExp(query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g')) || []).length,
|
||||
snippet: `${windowStart > 0 ? '…' : ''}${snippet}${windowEnd < content.length ? '…' : ''}`,
|
||||
matchingLines,
|
||||
})
|
||||
}
|
||||
|
||||
results.sort((a, b) => b.matchCount - a.matchCount)
|
||||
res.json({ query, results, total: results.length })
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message })
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/api/log', async (req, res) => {
|
||||
const message = typeof req.body?.message === 'string' ? req.body.message.trim() : ''
|
||||
if (!message) {
|
||||
return res.status(400).json({ error: 'Message is required' })
|
||||
}
|
||||
|
||||
try {
|
||||
await ensureSync()
|
||||
const filename = `${todayDateStamp()}.md`
|
||||
const filePath = resolveDailyMemoryPath(filename)
|
||||
const existing = filePath && fs.existsSync(filePath) ? await fsp.readFile(filePath, 'utf8') : ''
|
||||
const prefix = existing && !existing.endsWith('\n') ? '\n' : ''
|
||||
const content = `${existing}${prefix}- [${currentTimeStamp()}] ${message}\n`
|
||||
await writeThrough(filename, content)
|
||||
res.json({ success: true, mode: 'appwrite' })
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message })
|
||||
}
|
||||
})
|
||||
|
||||
app.get('/api/review', async (req, res) => {
|
||||
try {
|
||||
const { stdout, stderr } = await execFileAsync('claw-mem', ['review'])
|
||||
const output = `${stdout || ''}${stderr || ''}`
|
||||
const REVIEW_PATTERN = /^ File: (.+\.md)$/gm
|
||||
const files = []
|
||||
let match
|
||||
while ((match = REVIEW_PATTERN.exec(output)) !== null) {
|
||||
const filename = path.basename(match[1].trim())
|
||||
if (isValidDailyMemoryFilename(filename)) {
|
||||
const doc = await readMemoryDocument(filename)
|
||||
if (doc) {
|
||||
files.push({
|
||||
filename,
|
||||
dateLabel: formatDateLabel(filename),
|
||||
wordCount: wordCount(doc.content || ''),
|
||||
entryCount: getEntryCount(doc.content || ''),
|
||||
content: doc.content || '',
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
res.json({
|
||||
files,
|
||||
hasCandidates: files.length > 0,
|
||||
instructions: files.length > 0
|
||||
? 'Read each file, distill key learnings into MEMORY.md, then prune.'
|
||||
: 'All memory files are recent. Check back in a few days.',
|
||||
})
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message })
|
||||
}
|
||||
})
|
||||
|
||||
app.get('/api/review-count', async (req, res) => {
|
||||
try {
|
||||
const { stdout, stderr } = await execFileAsync('claw-mem', ['review'])
|
||||
const output = `${stdout || ''}${stderr || ''}`
|
||||
const REVIEW_PATTERN = /^ File: (.+\.md)$/gm
|
||||
let count = 0
|
||||
let match
|
||||
while ((match = REVIEW_PATTERN.exec(output)) !== null) {
|
||||
const filename = path.basename(match[1].trim())
|
||||
if (isValidDailyMemoryFilename(filename)) count++
|
||||
}
|
||||
res.json({ count })
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message })
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/api/prune', async (req, res) => {
|
||||
try {
|
||||
const { stdout, stderr } = await execFileAsync('claw-mem', ['prune'])
|
||||
const output = `${stdout || ''}${stderr || ''}`
|
||||
const countMatch = output.match(/(\d+)\s+file/i) || output.match(/pruned\s+(\d+)/i)
|
||||
res.json({ success: true, prunedCount: countMatch ? Number.parseInt(countMatch[1], 10) : null, output })
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message || 'Prune failed', output: `${error.stdout || ''}${error.stderr || ''}` })
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/api/distill', async (req, res) => {
|
||||
const { note, sourceFilename } = req.body || {}
|
||||
if (typeof note !== 'string' || !note.trim()) {
|
||||
return res.status(400).json({ error: 'Distilled note is required' })
|
||||
}
|
||||
|
||||
try {
|
||||
await ensureSync()
|
||||
const mainDoc = await readMemoryDocument('MEMORY.md')
|
||||
if (!mainDoc) return res.status(404).json({ error: 'MEMORY.md not found' })
|
||||
|
||||
const existing = mainDoc.content || ''
|
||||
const dateStr = todayDateStamp()
|
||||
const sourceTag = sourceFilename ? ` (from ${sourceFilename})` : ''
|
||||
const distillEntry = `\n- **[${dateStr}]**${sourceTag} ${note.trim()}\n`
|
||||
await writeThrough('MEMORY.md', `${existing}${distillEntry}`)
|
||||
res.json({ success: true, appended: distillEntry.trim() })
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message })
|
||||
}
|
||||
})
|
||||
|
||||
app.use(express.static(DIST_DIR))
|
||||
app.get(/.*/, (req, res) => {
|
||||
res.sendFile(path.join(DIST_DIR, 'index.html'))
|
||||
})
|
||||
|
||||
const PORT = Number(process.env.PORT) || 3333
|
||||
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
app.listen(PORT, '0.0.0.0', () => {
|
||||
console.log(`Freeclaw Memory Cloud running on port ${PORT}`)
|
||||
})
|
||||
}
|
||||
|
||||
export { app, isValidDailyMemoryFilename, resolveDailyMemoryPath }
|
||||
+577
-69
@@ -1,96 +1,604 @@
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
background:
|
||||
radial-gradient(circle at top, rgba(112, 89, 255, 0.18), transparent 35%),
|
||||
linear-gradient(180deg, #071019 0%, #090d16 45%, #05070d 100%);
|
||||
color: #edf2ff;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
background: #0f0f14;
|
||||
color: #e0e0e8;
|
||||
min-height: 100vh;
|
||||
background: transparent;
|
||||
color: #edf2ff;
|
||||
}
|
||||
|
||||
button,
|
||||
input {
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
button {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
#root {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.app-shell {
|
||||
position: relative;
|
||||
min-height: 100vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.nebula {
|
||||
position: fixed;
|
||||
inset: auto;
|
||||
border-radius: 999px;
|
||||
filter: blur(80px);
|
||||
opacity: 0.5;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.nebula-a {
|
||||
top: -6rem;
|
||||
left: -3rem;
|
||||
width: 24rem;
|
||||
height: 24rem;
|
||||
background: rgba(78, 168, 255, 0.2);
|
||||
}
|
||||
|
||||
.nebula-b {
|
||||
right: -5rem;
|
||||
top: 10rem;
|
||||
width: 28rem;
|
||||
height: 28rem;
|
||||
background: rgba(172, 98, 255, 0.18);
|
||||
}
|
||||
|
||||
.app {
|
||||
max-width: 860px;
|
||||
position: relative;
|
||||
max-width: 1180px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem 1.5rem;
|
||||
padding: 2.5rem 1.25rem 4rem;
|
||||
}
|
||||
|
||||
.app-header { text-align: center; margin-bottom: 2rem; }
|
||||
.app-header h1 { font-size: 2rem; font-weight: 700; color: #fff; }
|
||||
.subtitle { color: #6b7280; font-size: 0.9rem; margin-top: 0.4rem; }
|
||||
|
||||
.summary-bar {
|
||||
.hero {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
justify-content: center;
|
||||
margin-bottom: 2rem;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
gap: 1.5rem;
|
||||
align-items: flex-end;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.eyebrow,
|
||||
.card-kicker,
|
||||
.results-header,
|
||||
.section-label,
|
||||
.viewer-kicker {
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.18em;
|
||||
font-size: 0.7rem;
|
||||
color: #8ca3c7;
|
||||
}
|
||||
|
||||
.hero h1 {
|
||||
font-size: clamp(2.2rem, 4vw, 4rem);
|
||||
line-height: 0.95;
|
||||
max-width: 10ch;
|
||||
margin-top: 0.45rem;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
max-width: 40rem;
|
||||
margin-top: 0.85rem;
|
||||
color: #aeb9d7;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.hero-actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.ghost-btn,
|
||||
.primary-btn,
|
||||
.back-btn,
|
||||
.file-card,
|
||||
.result-item {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.ghost-btn,
|
||||
.primary-btn,
|
||||
.back-btn {
|
||||
border-radius: 999px;
|
||||
padding: 0.8rem 1.1rem;
|
||||
transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
|
||||
}
|
||||
|
||||
.ghost-btn,
|
||||
.back-btn {
|
||||
background: rgba(15, 22, 37, 0.7);
|
||||
color: #edf2ff;
|
||||
border: 1px solid rgba(156, 179, 221, 0.2);
|
||||
box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
|
||||
}
|
||||
|
||||
.primary-btn {
|
||||
background: linear-gradient(135deg, #62b0ff, #8b6dff);
|
||||
color: #09101d;
|
||||
font-weight: 700;
|
||||
min-width: 7rem;
|
||||
}
|
||||
|
||||
.ghost-btn:hover,
|
||||
.primary-btn:hover,
|
||||
.back-btn:hover,
|
||||
.file-card:hover,
|
||||
.result-item:hover {
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.primary-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: default;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.slash-hint {
|
||||
color: #8ca3c7;
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
|
||||
kbd {
|
||||
background: rgba(255,255,255,0.08);
|
||||
border: 1px solid rgba(255,255,255,0.12);
|
||||
border-bottom-width: 2px;
|
||||
border-radius: 0.5rem;
|
||||
padding: 0.15rem 0.42rem;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.dashboard-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1.35fr 0.9fr 1fr;
|
||||
gap: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.feature-card,
|
||||
.composer-card,
|
||||
.file-card,
|
||||
.result-item,
|
||||
.memory-content,
|
||||
.viewer-header {
|
||||
background: rgba(12, 19, 33, 0.72);
|
||||
border: 1px solid rgba(146, 166, 206, 0.14);
|
||||
box-shadow:
|
||||
0 20px 40px rgba(0, 0, 0, 0.25),
|
||||
inset 0 1px 0 rgba(255,255,255,0.04);
|
||||
backdrop-filter: blur(18px);
|
||||
}
|
||||
|
||||
.feature-card,
|
||||
.composer-card {
|
||||
border-radius: 24px;
|
||||
padding: 1.2rem 1.25rem;
|
||||
}
|
||||
|
||||
.spark-text {
|
||||
margin-top: 0.85rem;
|
||||
font-size: 1.1rem;
|
||||
line-height: 1.6;
|
||||
color: #f3f6ff;
|
||||
}
|
||||
|
||||
.spark-source {
|
||||
margin-top: 0.75rem;
|
||||
color: #8ca3c7;
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
display: grid;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.mini-stat {
|
||||
color: #c9d6f0;
|
||||
font-size: 0.92rem;
|
||||
}
|
||||
|
||||
.mini-stat span {
|
||||
display: inline-block;
|
||||
min-width: 3.8rem;
|
||||
font-size: 1.35rem;
|
||||
font-weight: 800;
|
||||
color: #78c1ff;
|
||||
}
|
||||
|
||||
.recap-card {
|
||||
display: grid;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
|
||||
.recap-line {
|
||||
color: #d8e1f6;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.composer-card {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.composer-title {
|
||||
margin-top: 0.35rem;
|
||||
color: #d8e1f6;
|
||||
}
|
||||
|
||||
.composer-form {
|
||||
margin-top: 1rem;
|
||||
display: flex;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
|
||||
.search-section {
|
||||
position: relative;
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
.summary-stat {
|
||||
background: #1a1a24;
|
||||
border: 1px solid #2a2a3a;
|
||||
border-radius: 12px;
|
||||
padding: 0.75rem 1.25rem;
|
||||
text-align: center;
|
||||
min-width: 100px;
|
||||
}
|
||||
.stat-num { display: block; font-size: 1.5rem; font-weight: 700; color: #60a5fa; }
|
||||
.stat-label { display: block; font-size: 0.7rem; color: #6b7280; margin-top: 2px; text-transform: uppercase; letter-spacing: 0.05em; }
|
||||
|
||||
.search-section { position: relative; margin-bottom: 1.5rem; }
|
||||
.search-input {
|
||||
width: 100%;
|
||||
background: #1a1a24;
|
||||
border: 1px solid #2a2a3a;
|
||||
border-radius: 12px;
|
||||
padding: 0.75rem 1rem;
|
||||
color: #e0e0e8;
|
||||
font-size: 1rem;
|
||||
background: rgba(13, 20, 34, 0.78);
|
||||
border: 1px solid rgba(141, 164, 207, 0.18);
|
||||
border-radius: 18px;
|
||||
padding: 0.9rem 1rem;
|
||||
color: #edf2ff;
|
||||
outline: none;
|
||||
transition: border-color 0.2s;
|
||||
transition: border-color 0.15s ease, box-shadow 0.15s ease;
|
||||
}
|
||||
.search-input:focus { border-color: #60a5fa; }
|
||||
.search-input::placeholder { color: #4b5563; }
|
||||
.search-spinner { position: absolute; right: 1rem; top: 50%; transform: translateY(-50%); }
|
||||
|
||||
.section-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: #6b7280; margin-bottom: 0.75rem; }
|
||||
.search-input:focus {
|
||||
border-color: rgba(113, 190, 255, 0.9);
|
||||
box-shadow: 0 0 0 4px rgba(98, 176, 255, 0.12);
|
||||
}
|
||||
|
||||
.files-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.75rem; }
|
||||
.search-input::placeholder {
|
||||
color: #7282a4;
|
||||
}
|
||||
|
||||
.search-spinner {
|
||||
position: absolute;
|
||||
right: 1rem;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
.files-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
|
||||
gap: 0.9rem;
|
||||
}
|
||||
|
||||
.file-card {
|
||||
background: #1a1a24;
|
||||
border: 1px solid #2a2a3a;
|
||||
border-radius: 12px;
|
||||
text-align: left;
|
||||
border-radius: 20px;
|
||||
padding: 1rem;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.2s, transform 0.15s;
|
||||
border: 1px solid rgba(146, 166, 206, 0.14);
|
||||
transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
|
||||
}
|
||||
|
||||
.file-card.light:hover,
|
||||
.result-item:hover {
|
||||
border-color: rgba(116, 191, 255, 0.42);
|
||||
}
|
||||
|
||||
.file-card.active:hover {
|
||||
border-color: rgba(169, 132, 255, 0.52);
|
||||
}
|
||||
|
||||
.file-card.intense:hover {
|
||||
border-color: rgba(255, 122, 191, 0.52);
|
||||
}
|
||||
|
||||
.file-card-top {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.file-date {
|
||||
color: #7ec8ff;
|
||||
font-size: 0.82rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.file-label {
|
||||
margin-top: 0.2rem;
|
||||
color: #dbe5fb;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.file-orb {
|
||||
width: 0.9rem;
|
||||
height: 0.9rem;
|
||||
border-radius: 999px;
|
||||
background: radial-gradient(circle at 35% 35%, #fff, rgba(126,200,255,0.92) 30%, rgba(126,200,255,0.08) 70%);
|
||||
box-shadow: 0 0 20px rgba(126, 200, 255, 0.55);
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.file-card.active .file-orb {
|
||||
background: radial-gradient(circle at 35% 35%, #fff, rgba(172,128,255,0.92) 30%, rgba(172,128,255,0.08) 70%);
|
||||
box-shadow: 0 0 22px rgba(172, 128, 255, 0.48);
|
||||
}
|
||||
|
||||
.file-card.intense .file-orb {
|
||||
background: radial-gradient(circle at 35% 35%, #fff, rgba(255,124,190,0.92) 30%, rgba(255,124,190,0.08) 70%);
|
||||
box-shadow: 0 0 22px rgba(255, 124, 190, 0.48);
|
||||
}
|
||||
|
||||
.file-stats {
|
||||
display: flex;
|
||||
gap: 0.45rem;
|
||||
flex-wrap: wrap;
|
||||
margin-top: 0.75rem;
|
||||
color: #8ca3c7;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.entry-tag {
|
||||
border-radius: 999px;
|
||||
padding: 0.18rem 0.55rem;
|
||||
background: rgba(113, 190, 255, 0.12);
|
||||
color: #7ec8ff;
|
||||
}
|
||||
|
||||
.file-age {
|
||||
margin-top: 0.6rem;
|
||||
color: #7282a4;
|
||||
font-size: 0.76rem;
|
||||
}
|
||||
|
||||
.search-results {
|
||||
display: grid;
|
||||
gap: 0.65rem;
|
||||
}
|
||||
|
||||
.results-header,
|
||||
.section-label {
|
||||
margin-bottom: 0.65rem;
|
||||
}
|
||||
.file-card:hover { border-color: #60a5fa; transform: translateY(-2px); }
|
||||
.file-date { font-size: 0.8rem; color: #60a5fa; font-weight: 600; }
|
||||
.file-label { font-size: 0.85rem; color: #9ca3af; margin-top: 2px; }
|
||||
.file-stats { display: flex; gap: 0.5rem; margin-top: 0.5rem; font-size: 0.7rem; color: #6b7280; }
|
||||
.entry-tag { background: #1e3a5f; color: #60a5fa; border-radius: 4px; padding: 0 4px; }
|
||||
.file-age { font-size: 0.7rem; color: #4b5563; margin-top: 0.4rem; }
|
||||
|
||||
.search-results { margin-top: 1rem; }
|
||||
.results-header { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: #6b7280; margin-bottom: 0.75rem; }
|
||||
.result-item {
|
||||
background: #1a1a24;
|
||||
border: 1px solid #2a2a3a;
|
||||
border-radius: 10px;
|
||||
padding: 0.875rem 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.2s;
|
||||
text-align: left;
|
||||
border-radius: 18px;
|
||||
padding: 1rem 1.05rem;
|
||||
border: 1px solid rgba(146, 166, 206, 0.14);
|
||||
}
|
||||
.result-item:hover { border-color: #60a5fa; }
|
||||
.result-name { font-size: 0.85rem; font-weight: 600; color: #60a5fa; margin-bottom: 0.3rem; }
|
||||
.result-snippet { font-size: 0.8rem; color: #9ca3af; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
|
||||
.result-meta { font-size: 0.7rem; color: #4b5563; margin-top: 0.4rem; }
|
||||
|
||||
.viewer { max-width: 800px; margin: 0 auto; }
|
||||
.viewer-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; }
|
||||
.back-btn { background: #1a1a24; border: 1px solid #2a2a3a; color: #e0e0e8; border-radius: 8px; padding: 0.4rem 0.875rem; cursor: pointer; font-size: 0.85rem; }
|
||||
.back-btn:hover { border-color: #60a5fa; }
|
||||
.viewer-title { font-size: 0.85rem; color: #6b7280; }
|
||||
.loading { color: #6b7280; font-size: 0.9rem; text-align: center; padding: 2rem; }
|
||||
.memory-content { white-space: pre-wrap; font-size: 0.875rem; line-height: 1.7; color: #d1d5db; background: #1a1a24; border: 1px solid #2a2a3a; border-radius: 12px; padding: 1.5rem; }
|
||||
.no-results { text-align: center; color: #6b7280; padding: 2rem; }
|
||||
.result-name {
|
||||
color: #7ec8ff;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.result-snippet,
|
||||
.result-lines {
|
||||
margin-top: 0.45rem;
|
||||
color: #d6e0f6;
|
||||
line-height: 1.55;
|
||||
}
|
||||
|
||||
.result-lines {
|
||||
color: #97abd3;
|
||||
font-size: 0.88rem;
|
||||
}
|
||||
|
||||
.result-meta {
|
||||
margin-top: 0.55rem;
|
||||
color: #7282a4;
|
||||
font-size: 0.76rem;
|
||||
}
|
||||
|
||||
.viewer-shell {
|
||||
max-width: 1000px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem 1.25rem 3rem;
|
||||
}
|
||||
|
||||
.viewer-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
border-radius: 20px;
|
||||
padding: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.viewer-save {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.viewer-title {
|
||||
margin-top: 0.2rem;
|
||||
color: #edf2ff;
|
||||
font-size: 1.05rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.loading,
|
||||
.no-results {
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
color: #8ca3c7;
|
||||
}
|
||||
|
||||
.memory-content {
|
||||
white-space: pre-wrap;
|
||||
border-radius: 24px;
|
||||
padding: 1.35rem;
|
||||
line-height: 1.7;
|
||||
color: #ecf2ff;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.memory-editor {
|
||||
width: 100%;
|
||||
min-height: 70vh;
|
||||
resize: vertical;
|
||||
border-radius: 24px;
|
||||
padding: 1.35rem;
|
||||
line-height: 1.7;
|
||||
color: #ecf2ff;
|
||||
background: rgba(12, 19, 33, 0.72);
|
||||
border: 1px solid rgba(146, 166, 206, 0.14);
|
||||
box-shadow:
|
||||
0 20px 40px rgba(0, 0, 0, 0.25),
|
||||
inset 0 1px 0 rgba(255,255,255,0.04);
|
||||
backdrop-filter: blur(18px);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.memory-editor:focus {
|
||||
border-color: rgba(113, 190, 255, 0.9);
|
||||
box-shadow:
|
||||
0 20px 40px rgba(0, 0, 0, 0.25),
|
||||
inset 0 1px 0 rgba(255,255,255,0.04),
|
||||
0 0 0 4px rgba(98, 176, 255, 0.12);
|
||||
}
|
||||
|
||||
.skyline-card {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.skyline-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.skyline-title {
|
||||
margin-top: 0.35rem;
|
||||
color: #d8e1f6;
|
||||
}
|
||||
|
||||
.skyline-plot {
|
||||
position: relative;
|
||||
height: 170px;
|
||||
margin-top: 1.2rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.skyline-line {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 50%;
|
||||
border-top: 1px dashed rgba(140, 163, 199, 0.25);
|
||||
}
|
||||
|
||||
.star-node {
|
||||
position: absolute;
|
||||
transform: translate(-50%, -50%);
|
||||
border-radius: 999px;
|
||||
border: 1px solid rgba(255,255,255,0.18);
|
||||
background: radial-gradient(circle at 35% 35%, #ffffff, rgba(126,200,255,0.95) 35%, rgba(126,200,255,0.08) 75%);
|
||||
box-shadow: 0 0 18px rgba(126, 200, 255, 0.35);
|
||||
transition: transform 140ms ease, box-shadow 140ms ease;
|
||||
}
|
||||
|
||||
.star-node:hover {
|
||||
transform: translate(-50%, -50%) scale(1.08);
|
||||
box-shadow: 0 0 26px rgba(172, 128, 255, 0.48);
|
||||
}
|
||||
|
||||
.star-tooltip {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
bottom: calc(100% + 0.75rem);
|
||||
transform: translateX(-50%);
|
||||
white-space: nowrap;
|
||||
font-size: 0.72rem;
|
||||
color: #edf2ff;
|
||||
background: rgba(7, 12, 22, 0.88);
|
||||
border: 1px solid rgba(146, 166, 206, 0.18);
|
||||
border-radius: 999px;
|
||||
padding: 0.3rem 0.55rem;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.star-node:hover .star-tooltip {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.skyline-labels {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
|
||||
gap: 0.55rem;
|
||||
}
|
||||
|
||||
.skyline-label {
|
||||
text-align: left;
|
||||
background: rgba(255,255,255,0.03);
|
||||
border: 1px solid rgba(146, 166, 206, 0.12);
|
||||
color: #aeb9d7;
|
||||
border-radius: 14px;
|
||||
padding: 0.65rem 0.75rem;
|
||||
}
|
||||
|
||||
.skyline-label span,
|
||||
.skyline-label strong {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.skyline-label span {
|
||||
font-size: 0.76rem;
|
||||
}
|
||||
|
||||
.skyline-label strong {
|
||||
margin-top: 0.18rem;
|
||||
color: #edf2ff;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.dashboard-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.hero {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.hero-actions {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.composer-form {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.app,
|
||||
.viewer-shell {
|
||||
padding-inline: 1rem;
|
||||
}
|
||||
|
||||
.hero h1 {
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
.files-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
+315
-78
@@ -1,6 +1,7 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import './App.css'
|
||||
|
||||
const API = 'http://localhost:3333'
|
||||
const API = import.meta.env.VITE_API_BASE || ''
|
||||
|
||||
function formatDate(ts) {
|
||||
return new Date(ts).toLocaleDateString(undefined, { weekday: 'short', month: 'short', day: 'numeric' })
|
||||
@@ -17,143 +18,379 @@ function formatRelative(ts) {
|
||||
return `${d}d ago`
|
||||
}
|
||||
|
||||
function clipText(text, max = 180) {
|
||||
const clean = text.replace(/[#>*`_-]/g, ' ').replace(/\s+/g, ' ').trim()
|
||||
if (clean.length <= max) return clean
|
||||
return `${clean.slice(0, max).trim()}…`
|
||||
}
|
||||
|
||||
function pickSpark(content) {
|
||||
const lines = content
|
||||
.split('\n')
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line && !line.startsWith('#'))
|
||||
|
||||
const candidate = lines.find((line) => line.startsWith('- ')) || lines[0] || ''
|
||||
return clipText(candidate.replace(/^-\s*/, ''))
|
||||
}
|
||||
|
||||
function intensityClass(wordCount) {
|
||||
if (wordCount >= 1800) return 'intense'
|
||||
if (wordCount >= 900) return 'active'
|
||||
return 'light'
|
||||
}
|
||||
|
||||
function FileCard({ f, onClick }) {
|
||||
return (
|
||||
<div className="file-card" onClick={onClick}>
|
||||
<div className="file-date">{formatDate(f.mtimeMs)}</div>
|
||||
<div className="file-label">{f.dateLabel}</div>
|
||||
<button className={`file-card ${intensityClass(f.wordCount)}`} onClick={onClick}>
|
||||
<div className="file-card-top">
|
||||
<div>
|
||||
<div className="file-date">{formatDate(f.mtimeMs)}</div>
|
||||
<div className="file-label">{f.dateLabel}</div>
|
||||
</div>
|
||||
<div className="file-orb" aria-hidden="true" />
|
||||
</div>
|
||||
<div className="file-stats">
|
||||
<span>{f.wordCount.toLocaleString()} words</span>
|
||||
{f.entryCount > 0 && <span className="entry-tag">{f.entryCount} entries</span>}
|
||||
</div>
|
||||
<div className="file-age">{formatRelative(f.mtimeMs)}</div>
|
||||
</div>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
function MemoryViewer({ filename, onBack }) {
|
||||
function Viewer({ selected, onBack }) {
|
||||
const [content, setContent] = useState('')
|
||||
const [draft, setDraft] = useState('')
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [saveState, setSaveState] = useState('idle')
|
||||
const isMainMemory = selected.type === 'main'
|
||||
|
||||
useEffect(() => {
|
||||
fetch(`${API}/api/memories/${filename}`)
|
||||
.then(r => r.json())
|
||||
.then(d => { setContent(d.content); setLoading(false) })
|
||||
setLoading(true)
|
||||
setSaveState('idle')
|
||||
const url = isMainMemory
|
||||
? `${API}/api/main-memory`
|
||||
: `${API}/api/memories/${selected.filename}`
|
||||
|
||||
fetch(url)
|
||||
.then((r) => r.json())
|
||||
.then((d) => {
|
||||
const next = d.content || ''
|
||||
setContent(next)
|
||||
setDraft(next)
|
||||
setLoading(false)
|
||||
})
|
||||
.catch(() => setLoading(false))
|
||||
}, [filename])
|
||||
}, [selected, isMainMemory])
|
||||
|
||||
const save = async () => {
|
||||
if (!isMainMemory || draft === content) return
|
||||
setSaveState('saving')
|
||||
try {
|
||||
const r = await fetch(`${API}/api/main-memory`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ content: draft }),
|
||||
})
|
||||
if (!r.ok) throw new Error('save failed')
|
||||
setContent(draft)
|
||||
setSaveState('saved')
|
||||
setTimeout(() => setSaveState('idle'), 1800)
|
||||
} catch {
|
||||
setSaveState('error')
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="viewer">
|
||||
<div className="viewer-shell">
|
||||
<div className="viewer-header">
|
||||
<button className="back-btn" onClick={onBack}>← Back</button>
|
||||
<span className="viewer-title">{filename}</span>
|
||||
<div>
|
||||
<div className="viewer-kicker">{isMainMemory ? 'core memory editor' : 'memory viewer'}</div>
|
||||
<div className="viewer-title">{selected.title}</div>
|
||||
</div>
|
||||
{isMainMemory && !loading && (
|
||||
<button className="primary-btn viewer-save" onClick={save} disabled={saveState === 'saving' || draft === content}>
|
||||
{saveState === 'saving' ? 'Saving…' : saveState === 'saved' ? 'Saved ✓' : saveState === 'error' ? 'Retry save' : 'Save MEMORY.md'}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{loading ? <div className="loading">Loading...</div> : (
|
||||
{loading ? (
|
||||
<div className="loading">Loading memory fog…</div>
|
||||
) : isMainMemory ? (
|
||||
<textarea className="memory-editor" value={draft} onChange={(e) => setDraft(e.target.value)} spellCheck={false} />
|
||||
) : (
|
||||
<pre className="memory-content">{content}</pre>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function MemorySkyline({ files, onSelect }) {
|
||||
if (!files?.length) return null
|
||||
const recent = files.slice(0, 12).reverse()
|
||||
const maxWords = Math.max(...recent.map((f) => f.wordCount), 1)
|
||||
|
||||
return (
|
||||
<section className="feature-card skyline-card">
|
||||
<div className="skyline-header">
|
||||
<div>
|
||||
<div className="card-kicker">memory constellation</div>
|
||||
<div className="skyline-title">Twelve recent days, mapped by size and freshness.</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="skyline-plot" role="list" aria-label="Recent memory activity timeline">
|
||||
{recent.map((file, index) => {
|
||||
const y = 16 + ((maxWords - file.wordCount) / maxWords) * 120
|
||||
const size = 10 + (file.wordCount / maxWords) * 22
|
||||
return (
|
||||
<button
|
||||
key={file.filename}
|
||||
className="star-node"
|
||||
style={{ left: `${(index / Math.max(recent.length - 1, 1)) * 100}%`, top: `${y}px`, width: `${size}px`, height: `${size}px` }}
|
||||
onClick={() => onSelect(file)}
|
||||
title={`${file.dateLabel} · ${file.wordCount.toLocaleString()} words`}
|
||||
>
|
||||
<span className="star-tooltip">{file.dateLabel} · {file.wordCount.toLocaleString()} words</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
<div className="skyline-line" aria-hidden="true" />
|
||||
</div>
|
||||
<div className="skyline-labels">
|
||||
{recent.map((file) => (
|
||||
<button key={file.filename} className="skyline-label" onClick={() => onSelect(file)}>
|
||||
<span>{formatDate(file.mtimeMs)}</span>
|
||||
<strong>{file.wordCount.toLocaleString()}</strong>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const [meta, setMeta] = useState(null)
|
||||
const [selectedFile, setSelectedFile] = useState(null)
|
||||
const [selected, setSelected] = useState(null)
|
||||
const [query, setQuery] = useState('')
|
||||
const [searchResults, setSearchResults] = useState([])
|
||||
const [searching, setSearching] = useState(false)
|
||||
const [spark, setSpark] = useState('')
|
||||
const [sparkSource, setSparkSource] = useState('')
|
||||
const [reviewCount, setReviewCount] = useState(null)
|
||||
const [quickLog, setQuickLog] = useState('')
|
||||
const [logState, setLogState] = useState('idle')
|
||||
const searchRef = useRef(null)
|
||||
|
||||
useEffect(() => {
|
||||
fetch(`${API}/api/meta`).then(r => r.json()).then(setMeta)
|
||||
const onKey = (e) => {
|
||||
if (e.key === '/' && document.activeElement?.tagName !== 'INPUT' && document.activeElement?.tagName !== 'TEXTAREA') {
|
||||
e.preventDefault()
|
||||
searchRef.current?.focus()
|
||||
}
|
||||
}
|
||||
window.addEventListener('keydown', onKey)
|
||||
return () => window.removeEventListener('keydown', onKey)
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
fetch(`${API}/api/meta`).then((r) => r.json()).then(setMeta)
|
||||
fetch(`${API}/api/review-count`).then((r) => r.json()).then((d) => setReviewCount(d.count ?? 0)).catch(() => setReviewCount(null))
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (!meta?.dailyFiles?.length) return
|
||||
const latest = meta.dailyFiles[0]
|
||||
fetch(`${API}/api/memories/${latest.filename}`)
|
||||
.then((r) => r.json())
|
||||
.then((d) => {
|
||||
const text = pickSpark(d.content || '')
|
||||
setSpark(text || 'No spark yet — apparently the ravens are quiet.')
|
||||
setSparkSource(latest.dateLabel)
|
||||
})
|
||||
.catch(() => {
|
||||
setSpark('Could not pull a spark from the archive.')
|
||||
setSparkSource('')
|
||||
})
|
||||
}, [meta])
|
||||
|
||||
const search = async (q) => {
|
||||
if (!q.trim() || q.length < 2) { setSearchResults([]); return }
|
||||
if (!q.trim() || q.length < 2) {
|
||||
setSearchResults([])
|
||||
return
|
||||
}
|
||||
setSearching(true)
|
||||
try {
|
||||
const r = await fetch(`${API}/api/search?q=${encodeURIComponent(q)}`)
|
||||
const d = await r.json()
|
||||
setSearchResults(d.results || [])
|
||||
} catch { setSearchResults([]) }
|
||||
} catch {
|
||||
setSearchResults([])
|
||||
}
|
||||
setSearching(false)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const t = setTimeout(() => search(query), 300)
|
||||
const t = setTimeout(() => search(query), 250)
|
||||
return () => clearTimeout(t)
|
||||
}, [query])
|
||||
|
||||
if (selectedFile) {
|
||||
return <MemoryViewer filename={selectedFile} onBack={() => setSelectedFile(null)} />
|
||||
const heroStats = useMemo(() => {
|
||||
if (!meta?.dailyFiles?.length) return null
|
||||
const latest = meta.dailyFiles[0]
|
||||
const longest = [...meta.dailyFiles].sort((a, b) => b.wordCount - a.wordCount)[0]
|
||||
return { latest, longest }
|
||||
}, [meta])
|
||||
|
||||
const submitLog = async (e) => {
|
||||
e.preventDefault()
|
||||
const message = quickLog.trim()
|
||||
if (!message) return
|
||||
setLogState('saving')
|
||||
try {
|
||||
const r = await fetch(`${API}/api/log`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ message }),
|
||||
})
|
||||
if (!r.ok) throw new Error('save failed')
|
||||
setQuickLog('')
|
||||
setLogState('saved')
|
||||
const refreshed = await fetch(`${API}/api/meta`).then((res) => res.json())
|
||||
setMeta(refreshed)
|
||||
setTimeout(() => setLogState('idle'), 1600)
|
||||
} catch {
|
||||
setLogState('error')
|
||||
}
|
||||
}
|
||||
|
||||
if (selected) {
|
||||
return <Viewer selected={selected} onBack={() => setSelected(null)} />
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="app">
|
||||
<header className="app-header">
|
||||
<h1>🧠 Memory</h1>
|
||||
<p className="subtitle">OpenClaw workspace memory at a glance</p>
|
||||
</header>
|
||||
<div className="app-shell">
|
||||
<div className="nebula nebula-a" />
|
||||
<div className="nebula nebula-b" />
|
||||
<div className="app">
|
||||
<header className="hero">
|
||||
<div className="hero-copy">
|
||||
<div className="eyebrow">freeclaw memory cloud</div>
|
||||
<h1>Memory, but with a little mischief.</h1>
|
||||
<p className="subtitle">Browse the archive, search the ghosts, and toss fresh thoughts straight into today’s log.</p>
|
||||
</div>
|
||||
<div className="hero-actions">
|
||||
<button
|
||||
className="ghost-btn"
|
||||
onClick={() => setSelected({ type: 'main', title: 'MEMORY.md', filename: 'MEMORY.md' })}
|
||||
>
|
||||
Open core memory
|
||||
</button>
|
||||
<div className="slash-hint">Press <kbd>/</kbd> to search</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{meta && (
|
||||
<div className="summary-bar">
|
||||
<div className="summary-stat">
|
||||
<span className="stat-num">{meta.summary.dailyFileCount}</span>
|
||||
<span className="stat-label">daily files</span>
|
||||
</div>
|
||||
<div className="summary-stat">
|
||||
<span className="stat-num">{meta.summary.totalDailyWords.toLocaleString()}</span>
|
||||
<span className="stat-label">words logged</span>
|
||||
</div>
|
||||
<div className="summary-stat">
|
||||
<span className="stat-num">{meta.summary.totalDailyEntries}</span>
|
||||
<span className="stat-label">entries distilled</span>
|
||||
</div>
|
||||
{meta.mainMemory && (
|
||||
<div className="summary-stat">
|
||||
<span className="stat-num">{meta.mainMemory.entryCount}</span>
|
||||
<span className="stat-label">MEMORY.md entries</span>
|
||||
{meta && heroStats && (
|
||||
<section className="dashboard-grid">
|
||||
<div className="feature-card pulse-card">
|
||||
<div className="card-kicker">tonight’s spark</div>
|
||||
<div className="spark-text">“{spark || 'Loading something interesting…'}”</div>
|
||||
<div className="spark-source">{sparkSource || 'recent archive'}</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="search-section">
|
||||
<input
|
||||
className="search-input"
|
||||
type="text"
|
||||
placeholder="Search memory files..."
|
||||
value={query}
|
||||
onChange={e => setQuery(e.target.value)}
|
||||
<div className="feature-card stat-card">
|
||||
<div className="mini-stat"><span>{meta.summary.dailyFileCount}</span> daily files</div>
|
||||
<div className="mini-stat"><span>{meta.summary.totalDailyWords.toLocaleString()}</span> words logged</div>
|
||||
<div className="mini-stat"><span>{meta.mainMemory?.entryCount ?? 0}</span> core memories</div>
|
||||
<div className="mini-stat"><span>{reviewCount ?? '—'}</span> review candidates</div>
|
||||
</div>
|
||||
|
||||
<div className="feature-card recap-card">
|
||||
<div className="card-kicker">archive pulse</div>
|
||||
<div className="recap-line"><strong>Latest:</strong> {heroStats.latest.dateLabel} · {heroStats.latest.wordCount.toLocaleString()} words</div>
|
||||
<div className="recap-line"><strong>Biggest day:</strong> {heroStats.longest.dateLabel} · {heroStats.longest.wordCount.toLocaleString()} words</div>
|
||||
<div className="recap-line"><strong>Last touched:</strong> {formatRelative(heroStats.latest.mtimeMs)}</div>
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
|
||||
<MemorySkyline
|
||||
files={meta?.dailyFiles}
|
||||
onSelect={(file) => setSelected({ type: 'daily', filename: file.filename, title: file.dateLabel })}
|
||||
/>
|
||||
{searching && <span className="search-spinner">⏳</span>}
|
||||
</div>
|
||||
|
||||
{searchResults.length > 0 && (
|
||||
<div className="search-results">
|
||||
<div className="results-header">Search results ({searchResults.length})</div>
|
||||
{searchResults.map(r => (
|
||||
<div key={r.filename} className="result-item" onClick={() => setSelectedFile(r.filename)}>
|
||||
<div className="result-name">{r.dateLabel}</div>
|
||||
<div className="result-snippet">{r.snippet}</div>
|
||||
<div className="result-meta">{r.matchCount} matches · {r.wordCount} words</div>
|
||||
</div>
|
||||
))}
|
||||
<section className="composer-card">
|
||||
<div>
|
||||
<div className="card-kicker">quick log</div>
|
||||
<div className="composer-title">Throw a thought into today’s memory file</div>
|
||||
</div>
|
||||
<form className="composer-form" onSubmit={submitLog}>
|
||||
<input
|
||||
className="search-input composer-input"
|
||||
type="text"
|
||||
placeholder="Ship a note, clue, tiny victory, or suspiciously good idea…"
|
||||
value={quickLog}
|
||||
onChange={(e) => {
|
||||
setQuickLog(e.target.value)
|
||||
if (logState !== 'idle') setLogState('idle')
|
||||
}}
|
||||
/>
|
||||
<button className="primary-btn" type="submit" disabled={!quickLog.trim() || logState === 'saving'}>
|
||||
{logState === 'saving' ? 'Logging…' : logState === 'saved' ? 'Saved ✓' : logState === 'error' ? 'Retry' : 'Log it'}
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<div className="search-section">
|
||||
<input
|
||||
ref={searchRef}
|
||||
className="search-input"
|
||||
type="text"
|
||||
placeholder="Search memory files…"
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
/>
|
||||
{searching && <span className="search-spinner">⏳</span>}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{searchResults.length === 0 && !searching && query.length < 2 && meta && (
|
||||
<>
|
||||
<div className="section-label">Daily Memory Files</div>
|
||||
<div className="files-grid">
|
||||
{meta.dailyFiles.map(f => (
|
||||
<FileCard key={f.filename} f={f} onClick={() => setSelectedFile(f.filename)} />
|
||||
{searchResults.length > 0 && (
|
||||
<div className="search-results">
|
||||
<div className="results-header">Search results ({searchResults.length})</div>
|
||||
{searchResults.map((r) => (
|
||||
<button
|
||||
key={r.filename}
|
||||
className="result-item"
|
||||
onClick={() => setSelected({ type: 'daily', filename: r.filename, title: r.dateLabel })}
|
||||
>
|
||||
<div className="result-name">{r.dateLabel}</div>
|
||||
<div className="result-snippet">{r.snippet}</div>
|
||||
{r.matchingLines?.length > 0 && <div className="result-lines">{clipText(r.matchingLines[0], 120)}</div>}
|
||||
<div className="result-meta">{r.matchCount} matches · {r.wordCount} words</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
)}
|
||||
|
||||
{searchResults.length === 0 && !searching && query.length >= 2 && (
|
||||
<div className="no-results">No results for "{query}"</div>
|
||||
)}
|
||||
{searchResults.length === 0 && !searching && query.length < 2 && meta && (
|
||||
<>
|
||||
<div className="section-label">Daily Memory Files</div>
|
||||
<div className="files-grid">
|
||||
{meta.dailyFiles.map((f) => (
|
||||
<FileCard
|
||||
key={f.filename}
|
||||
f={f}
|
||||
onClick={() => setSelected({ type: 'daily', filename: f.filename, title: f.dateLabel })}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{searchResults.length === 0 && !searching && query.length >= 2 && (
|
||||
<div className="no-results">No ghosts answered for “{query}”.</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user