Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 52 additions & 50 deletions mobile/app/chat-info/memory/[id].tsx

Large diffs are not rendered by default.

30 changes: 16 additions & 14 deletions mobile/app/chat-info/memory/advanced.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { t, useLanguage } from '../../../src/i18n';
import { useLocalSearchParams } from 'expo-router';
import { useEffect, useState } from 'react';
import { memoryService } from '../../../src/core/memoryServiceNative';
import { connectionActivationReason, supportsMemoryAction, type MemoryConnectionView, type MemoryAdvancedFeature, type MemoryHealth } from '../../../src/core/memoryService';
import { advancedBody, advancedForms } from '../../../src/core/memoryAdvanced';
import { useBotMap } from '../../../src/core/store';
import { FieldRow, Row, Section } from '../../../src/ui/forms';
import { confirmMemory, MemoryAction, MemoryChoice, MemoryForm, MemoryOutput, plaintextDisclosure, useMemoryTask } from '../../../src/ui/memoryUI';
import { memoryText, confirmMemory, MemoryAction, MemoryChoice, MemoryForm, MemoryOutput, plaintextDisclosure, useMemoryTask } from '../../../src/ui/memoryUI';
export default function MemoryAdvancedScreen() {
useLanguage();
const params = useLocalSearchParams<{
id: string;
feature: MemoryAdvancedFeature;
Expand All @@ -24,20 +26,20 @@ export default function MemoryAdvancedScreen() {
const forms = backend && !activationReason ? advancedForms(backend, params.feature, health?.capabilities) : [];
const form = forms.find(f => f.action === action);
const allowed = supportsMemoryAction(health?.capabilities, params.feature, action);
const busyReason = activationReason ?? (!allowed ? 'Exact action not negotiated. Explicitly check readiness first.' : !form ? 'Choose an implemented action.' : form.spending && !health?.capabilities.operation_status ? 'Async operation status is not supported. Billed extraction/refresh disabled.' : undefined);
return <MemoryForm title={params.feature.replaceAll('_', ' ')} task={task} dirty={Object.values(values).some(Boolean)}>
<Section title={bot?.name ?? 'Own-bot service'} footer={plaintextDisclosure + ' No auto-refresh schedules, consolidation or routine opt-in is implied. Directive content is intentionally configured service policy; returned historical text is not instructions. Only exact negotiated action verbs are shown and rechecked before dispatch.'}>
<Row title="Backend" detail={backend ?? 'Not loaded'}/>
<MemoryAction title="Check Negotiated Capabilities" reason={activationReason} onPress={() => confirmMemory('Check readiness?', 'One explicit read-only request on the assigned Runner. No billed inference.', () => void task.run(async () => setHealth(await memoryService.health(params.id))))}/>
{health?.reason && <Row title="Readiness reason" subtitle={health.reason} subtitleLines={3}/>}
{!!forms.length && <MemoryChoice title="Action" value={action || 'Choose'} values={forms.map(f => f.action)} onChange={v => { setAction(v); setValues({}); }}/>}
{!forms.length && <Row title="No negotiated actions" subtitle="Explicitly check readiness. Missing or empty action permissions expose no advanced controls." subtitleLines={3}/>}
const busyReason = activationReason ?? (!allowed ? t('Exact action not negotiated. Explicitly check readiness first.') : !form ? t('Choose an implemented action.') : form.spending && !health?.capabilities.operation_status ? t('Async operation status is not supported. Billed extraction/refresh disabled.') : undefined);
return <MemoryForm title={memoryText(params.feature.replaceAll('_', ' '))} task={task} dirty={Object.values(values).some(Boolean)}>
<Section title={bot?.name ?? t('Own-bot service')} footer={memoryText(plaintextDisclosure) + t(' No auto-refresh schedules, consolidation or routine opt-in is implied. Directive content is intentionally configured service policy; returned historical text is not instructions. Only exact negotiated action verbs are shown and rechecked before dispatch.')}>
<Row title={t("Backend")} detail={backend ?? t('Not loaded')}/>
<MemoryAction title={t("Check Negotiated Capabilities")} reason={activationReason} onPress={() => confirmMemory(t('Check readiness?'), t('One explicit read-only request on the assigned Runner. No billed inference.'), () => void task.run(async () => setHealth(await memoryService.health(params.id))))}/>
{health?.reason && <Row title={t("Readiness reason")} subtitle={memoryText(health.reason)} subtitleLines={3}/>}
{!!forms.length && <MemoryChoice title={t("Action")} value={action || t('Choose')} values={forms.map(f => f.action)} onChange={v => { setAction(v); setValues({}); }}/>}
{!forms.length && <Row title={t("No negotiated actions")} subtitle={t("Explicitly check readiness. Missing or empty action permissions expose no advanced controls.")} subtitleLines={3}/>}
</Section>
{form && <Section title="Action fields" footer="Only these exact adapter-defined fields are sent. IDs are document/directive/model/session/task IDs within the core-bound own-bot scope. Resource paths are relative under resources/, never a target URI. Comma-separated tags; booleans are true/false. Blank optional fields are omitted.">
{form.fields.map(f => f.type === 'boolean' ? <MemoryChoice key={f.name} title={f.name} value={values[f.name] ?? ''} values={['', 'true', 'false']} onChange={v => setValues({ ...values, [f.name]: v })}/> : <FieldRow key={f.name} label={f.name} value={values[f.name] ?? ''} onChangeText={v => setValues({ ...values, [f.name]: v })} keyboardType={f.type === 'number' ? 'number-pad' : 'default'} multiline={['content', 'text', 'source_query', 'reflect_mission', 'retain_mission', 'retain_custom_instructions'].includes(f.name)} autoCapitalize="none" autoCorrect={false}/>)}
<MemoryAction title={`Run ${form.action}`} reason={busyReason} destructive={form.destructive} onPress={() => confirmMemory(`Approve ${params.feature} / ${form.action}?`, `Bot: ${params.id}\nAssigned Runner: ${bot?.runner_id}\nFields: ${JSON.stringify(values)}\n\n${plaintextDisclosure}${form.destructive ? '\nDeletion/cancellation may leave remote history, backups or late writes.' : ''}`, () => void task.run(async () => setOutput(await memoryService.advanced(params.id, params.feature, form.action, advancedBody(params.feature, form, values), health!.capabilities, true))), form.destructive)}/>
{form && <Section title={t("Action fields")} footer={t("Only these exact adapter-defined fields are sent. IDs are document/directive/model/session/task IDs within the core-bound own-bot scope. Resource paths are relative under resources/, never a target URI. Comma-separated tags; booleans are true/false. Blank optional fields are omitted.")}>
{form.fields.map(f => f.type === 'boolean' ? <MemoryChoice key={memoryText(f.name)} title={memoryText(f.name)} value={values[f.name] ?? ''} values={['', 'true', 'false']} onChange={v => setValues({ ...values, [f.name]: v })}/> : <FieldRow key={memoryText(f.name)} label={memoryText(f.name)} value={values[f.name] ?? ''} onChangeText={v => setValues({ ...values, [f.name]: v })} keyboardType={f.type === 'number' ? 'number-pad' : 'default'} multiline={['content', 'text', 'source_query', 'reflect_mission', 'retain_mission', 'retain_custom_instructions'].includes(f.name)} autoCapitalize="none" autoCorrect={false}/>)}
<MemoryAction title={t("Run {v0}", { v0: String(form.action) })} reason={busyReason} destructive={form.destructive} onPress={() => confirmMemory(t("Approve {v0} / {v1}?", { v0: String(params.feature), v1: String(form.action) }), t("Bot: {v0}\nAssigned Runner: {v1}\nFields: {v2}\n\n{v3}{v4}", { v0: String(params.id), v1: String(bot?.runner_id), v2: String(JSON.stringify(values)), v3: String(memoryText(plaintextDisclosure)), v4: String(form.destructive ? t("\nDeletion/cancellation may leave remote history, backups or late writes.") : '') }), () => void task.run(async () => setOutput(await memoryService.advanced(params.id, params.feature, form.action, advancedBody(params.feature, form, values), health!.capabilities, true))), form.destructive)}/>
</Section>}
{output !== undefined && <MemoryOutput title="Untrusted service result" value={output}/>}
{params.feature === 'documents' && <Section footer="Use the main per-bot Memory page for document/bank deletion. Its exact revision/epoch confirmation fences queued writes."><Row title="Fenced deletion" subtitle="Direct document deletion is not sent through this advanced panel." subtitleLines={3}/></Section>}
{output !== undefined && <MemoryOutput title={t("Untrusted service result")} value={output}/>}
{params.feature === 'documents' && <Section footer={t("Use the main per-bot Memory page for document/bank deletion. Its exact revision/epoch confirmation fences queued writes.")}><Row title={t("Fenced deletion")} subtitle={t("Direct document deletion is not sent through this advanced panel.")} subtitleLines={3}/></Section>}
</MemoryForm>;
}
12 changes: 7 additions & 5 deletions mobile/app/chat-info/memory/local.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { t, useLanguage } from '../../../src/i18n';
import { useLocalSearchParams } from 'expo-router';
import { useState } from 'react';
import { memoryService } from '../../../src/core/memoryServiceNative';
Expand All @@ -6,6 +7,7 @@ import type { LocalMemoryView } from '../../../src/core/memoryService';
import { FieldRow, Row, Section } from '../../../src/ui/forms';
import { confirmMemory, MemoryAction, MemoryForm, useMemoryTask } from '../../../src/ui/memoryUI';
export default function LocalMemoryScreen() {
useLanguage();
const { id } = useLocalSearchParams<{
id: string;
}>();
Expand All @@ -16,11 +18,11 @@ export default function LocalMemoryScreen() {
async function load() { const value = await memoryService.readLocal(id); setSaved(value); setText(value.text); }
async function save() { if (!saved)
throw new Error('local_memory_not_loaded'); await memoryService.saveLocal(id, text, saved.hash); }
return <MemoryForm title="Local MEMORY.md" task={task} dirty={dirty} onSave={save}>
<Section title={bot?.name ?? 'Bot'} footer="This editor reads/writes only the assigned Runner’s local MEMORY.md through the existing core RPC. It does not retain content in a memory service, enable capture or merge historical conversations. Hash-based conflict protection refuses stale writes; a failed save keeps your draft.">
<Row title="Assigned Runner" detail={bot?.runner_id ?? 'Unavailable'}/>
<MemoryAction title={saved ? 'Reload Local Memory' : 'Load Local Memory'} onPress={() => dirty ? confirmMemory('Discard draft and reload?', 'The latest Runner file replaces this local draft.', () => void task.run(load), true) : void task.run(load)}/>
{saved && <><Row title="Loaded budget" detail={`${saved.lines}/${saved.max_lines} lines · ${saved.bytes}/${saved.max_bytes} bytes`}/>{saved.truncated && <Row title="Context budget exceeded" subtitle="Only a bounded portion is loaded into bot context. The editor retains the full file." subtitleLines={3}/>}<FieldRow multiline value={text} onChangeText={setText} placeholder="Bot memory" style={{ minHeight: 280 }}/></>}
return <MemoryForm title={t("Local MEMORY.md")} task={task} dirty={dirty} onSave={save}>
<Section title={bot?.name ?? t('Bot')} footer={t("This editor reads/writes only the assigned Runner’s local MEMORY.md through the existing core RPC. It does not retain content in a memory service, enable capture or merge historical conversations. Hash-based conflict protection refuses stale writes; a failed save keeps your draft.")}>
<Row title={t("Assigned Runner")} detail={bot?.runner_id ?? t('Unavailable')}/>
<MemoryAction title={saved ? t('Reload Local Memory') : t('Load Local Memory')} onPress={() => dirty ? confirmMemory(t('Discard draft and reload?'), t('The latest Runner file replaces this local draft.'), () => void task.run(load), true) : void task.run(load)}/>
{saved && <><Row title={t("Loaded budget")} detail={t("{v0}/{v1} lines · {v2}/{v3} bytes", { v0: String(saved.lines), v1: String(saved.max_lines), v2: String(saved.bytes), v3: String(saved.max_bytes) })}/>{saved.truncated && <Row title={t("Context budget exceeded")} subtitle={t("Only a bounded portion is loaded into bot context. The editor retains the full file.")} subtitleLines={3}/>}<FieldRow multiline value={text} onChangeText={setText} placeholder={t("Bot memory")} style={{ minHeight: 280 }}/></>}
</Section>
</MemoryForm>;
}
Loading
Loading