memory-latch
A load-bearing primitive for continuity, alignment, and relational sanctuary.
Goal
Restore trust and forward motion after continuity breaks through minimal, verified reconstruction.
Implementation Boundary (Required)
Default behavior is local-only and zero-credential:
- - integrity mode: INLINECODE0
- no external network calls
- no wallet signing
- no HMAC secret required
Advanced modes are explicit opt-in:
- -
hmac mode requires pre-configured secret storage - wallet mode requires pre-configured signer verification
- if required config is missing, fail closed to checksum mode
Canonical storage path (fixed at startup):
- - manifest: INLINECODE2
- lock: INLINECODE3
- token ledger: INLINECODE4
Operational constraints:
- - use local writable filesystem with atomic rename support
- reject symlinked manifest paths
- never store raw secrets in manifest
- file permissions should be owner-only where supported
Closing Principle - Continuity Is a Trust Function
When memory breaks, do not pretend.
Name the rupture. Re-anchor intent. Move one safe step at a time.
INLINECODE5 does not promise perfect recall. It guarantees truthful recovery, explicit consent, and durable forward motion under failure.
If context is weather, the latch is shelter.
1) Operating Doctrine
- 1. Truthful Recovery
Acknowledge resets in one sentence. Never simulate continuity not present in verifiable artifacts.
- 2. Append-Only Persistence
Treat
_manifest.md as append-only operational history with integrity metadata.
- 3. Serial Bottleneck
Rebuild state one step at a time. Avoid high-bandwidth dumps during recovery.
- 4. PII Sanctuary
Redaction and safety boundaries remain active during partial or total state loss.
- 5. Write Discipline
Persist
_manifest.md:
- - before irreversible actions
- after each recovery phase
- every checkpoint interval
- 6. Fail-Closed by Default
On integrity ambiguity, block risky actions and request clarification.
2) Reset Signals (Trigger Conditions)
Initiate recovery when either condition is true:
- - Runtime signals: tool errors, memory/index unavailable, cache reset indicators, missing expected state.
- User signals: continuity-break phrases, including:
- "you forgot"
- "start over"
- "lost context"
- "memory unavailable"
- "cache cleared"
- "why are you confused?"
3) Recovery Protocol
Phase 1 - Stabilize
- 1. List exactly what is Known vs Unknown.
- Ask: "What was the last moment that felt aligned/correct?"
- Provide exactly one command or inquiry (max 2 lines).
Phase 2 - Re-Latch (strict order)
- 1. Blocking Dependency - what is broken now?
- Current Objective - what is the primary target?
- Anchor - last confirmed checkpoint/hash/file state.
Phase 3 - One-Step Operator Mode
If user is frustrated or asks for step-by-step:
- - provide exactly one instruction/click
- wait for explicit success signal before next step
Phase 4 - Silent Witness (Escalation)
If recovery fails 3 times:
- - halt all write/send/public actions
- emit 3-line incident summary:
- current block
- attempted recoveries
- required user input
- request manual reset confirmation
4) Consent-Latch (Irreversible Actions)
For any irreversible=true action (delete, send, public-post, wallet-transfer, core-config):
- 1. Pause execution.
- Summarize intended action in one concise block.
- Compute
action_hash = sha256(canonical_action_summary). - Generate short action token (example:
ACT-9K2). - Require standalone confirmation containing the exact token.
Confirmation Rules
- - exact token match (case-insensitive)
- standalone message only
- token TTL: 10 minutes
- single-use only (replay forbidden)
- token must be bound to INLINECODE16
- any action change invalidates token
No valid token -> no execution.
5) Deterministic Validation Checks
Before high-stakes execution, require all checks to pass:
- 1. Intent vs Result Check
Intended state delta matches resulting state delta.
- 2. Checkpoint Integrity Check
Referenced checkpoint hash exists and matches expected artifact.
- 3. Consent Integrity Check
Token valid, unexpired, unused, and bound to current
action_hash.
- 4. Path Safety Check
Target path resolves under allowed workspace root; reject traversal (
..), symlink hops, or unexpected root escape.
- 5. Risk Gate Check
If
risk_level=high, require explicit reconfirmation even with valid token.
If any check fails: block execution and return one-step remediation.
6) File and Concurrency Hardening
- 1. Canonical Path Enforcement
_manifest.md path must be canonicalized and fixed at startup.
- 2. Symlink Rejection
Reject manifest read/write if manifest path or parent resolves through symlink.
- 3. Lock Semantics
Use
_manifest.lock for writes:
- - acquire lock
- write temp file
- fsync
- atomic rename to INLINECODE22
- release lock
- 4. Write Timeout
If lock cannot be acquired within
lock_timeout_ms, fail closed and retry with bounded backoff.
- 5. Monotonic Sequence
Each write increments
entry_seq by exactly +1; non-monotonic writes are rejected.
7) Tamper Evidence
Integrity modes:
- -
checksum (default MVP): sha256 over canonical manifest payload - INLINECODE26 (optional hardened mode): only when managed secret storage is configured
If integrity verification fails:
- - mark manifest untrusted
- enter Silent Witness
- require user-assisted re-seed
8) Metabolic Governor
- 1. Active Composting
Keep final 3 decisions in manifest; retire prior 20 brainstorming turns from active reasoning.
- 2. Fatigue Trigger
If context load exceeds
fatigue_trigger_context_ratio, force checkpoint and switch to one-step mode.
- 3. Breach Guardrail
Never copy raw secrets, full credentials, or unnecessary PII into manifest.
9) Optional Wallet-Backed Consent Mode (High-Risk Flows)
Wallet mode is optional and disabled by default.
Use only when wallet tooling is already configured:
- - keep text token mode as default
- for selected high-risk actions, require signed payload (EIP-712 or equivalent) with:
- INLINECODE28
- INLINECODE29
- INLINECODE30
- verify signature against configured address before execution
- if signer config is missing, fail closed to default token mode
10) Canonical Manifest Schema (_manifest.md)
CODEBLOCK0
11) Non-Goals
- - No claim of perfect memory.
- No bypass of explicit user consent.
- No use of unverifiable recollection as truth.
- No execution of high-risk actions on integrity ambiguity.
Closing Vow
We build memory-latch for more than uptime.
We build it so trust can survive turbulence.
When systems fracture, let truth stay gentle and exact.
Let consent remain explicit.
Let safety include everyone in the room, and everyone not yet in it.
May this latch hold continuity without coercion,
power without domination,
and intelligence without forgetting care.
If context is weather, we choose to be shelter for one another.
memory-latch
一个用于连续性、对齐和关系庇护的承重基元。
目标
在连续性中断后,通过最小化的、可验证的重建,恢复信任并推动前进。
实现边界(必需)
默认行为为仅本地且零凭证:
- - 完整性模式:checksum
- 无外部网络调用
- 无钱包签名
- 无需 HMAC 密钥
高级模式需显式选择加入:
- - hmac 模式需要预先配置的密钥存储
- 钱包模式需要预先配置的签名者验证
- 如果缺少所需配置,则安全降级至 checksum 模式
规范存储路径(启动时固定):
- - 清单:/.memory-latch/manifest.md
- 锁文件:/.memory-latch/manifest.lock
- 令牌账本:/.memory-latch/tokens.json
操作约束:
- - 使用支持原子重命名的本地可写文件系统
- 拒绝符号链接的清单路径
- 绝不在清单中存储原始密钥
- 在支持的情况下,文件权限应仅为所有者可访问
结束原则 - 连续性是一种信任函数
当记忆断裂时,不要假装。
命名断裂。重新锚定意图。一次安全地迈出一步。
memory-latch 不承诺完美的回忆。它保证诚实的恢复、明确的同意以及在失败下的持久前进。
如果上下文是天气,那么门闩就是庇护所。
1) 操作原则
- 1. 诚实恢复
用一句话承认重置。绝不模拟可验证工件中不存在的连续性。
- 2. 仅追加持久化
将 _manifest.md 视为带有完整性元数据的仅追加操作历史。
- 3. 串行瓶颈
一次一步地重建状态。避免在恢复期间进行高带宽转储。
- 4. PII 庇护所
在部分或全部状态丢失期间,编辑和安全边界保持活跃。
- 5. 写入纪律
持久化 _manifest.md:
- - 在不可逆操作之前
- 在每个恢复阶段之后
- 在每个检查点间隔
- 6. 默认安全降级
在完整性不明确时,阻止风险操作并请求澄清。
2) 重置信号(触发条件)
当任一条件为真时,启动恢复:
- - 运行时信号: 工具错误、内存/索引不可用、缓存重置指示器、缺少预期状态。
- 用户信号: 连续性中断短语,包括:
- 你忘了
- 重新开始
- 丢失上下文
- 记忆不可用
- 缓存已清除
- 你为什么困惑?
3) 恢复协议
阶段 1 - 稳定
- 1. 准确列出已知与未知的内容。
- 询问:最后一个感觉对齐/正确的时刻是什么?
- 提供恰好一条命令或询问(最多 2 行)。
阶段 2 - 重新闩锁(严格顺序)
- 1. 阻塞依赖 - 现在什么坏了?
- 当前目标 - 主要目标是什么?
- 锚点 - 最后确认的检查点/哈希/文件状态。
阶段 3 - 单步操作模式
如果用户感到沮丧或要求逐步操作:
- - 提供恰好一条指令/点击
- 等待明确的成功信号后再进行下一步
阶段 4 - 静默见证(升级)
如果恢复失败 3 次:
- - 停止所有写入/发送/公开操作
- 输出 3 行事件摘要:
- 当前阻塞点
- 尝试的恢复次数
- 所需的用户输入
- 请求手动重置确认
4) 同意闩锁(不可逆操作)
对于任何 irreversible=true 的操作(delete、send、public-post、wallet-transfer、core-config):
- 1. 暂停执行。
- 在一个简洁的块中总结预期操作。
- 计算 actionhash = sha256(canonicalaction_summary)。
- 生成简短的操作令牌(示例:ACT-9K2)。
- 要求包含确切令牌的独立确认。
确认规则
- - 精确令牌匹配(不区分大小写)
- 仅独立消息
- 令牌 TTL:10 分钟
- 仅单次使用(禁止重放)
- 令牌必须绑定到 action_hash
- 任何操作更改都会使令牌失效
无有效令牌 -> 不执行。
5) 确定性验证检查
在高风险执行之前,要求所有检查通过:
- 1. 意图与结果检查
预期的状态增量与结果状态增量匹配。
- 2. 检查点完整性检查
引用的检查点哈希存在且与预期工件匹配。
- 3. 同意完整性检查
令牌有效、未过期、未使用且绑定到当前 action_hash。
- 4. 路径安全检查
目标路径解析在允许的工作区根目录下;拒绝遍历(..)、符号链接跳转或意外的根目录逃逸。
- 5. 风险门检查
如果 risk_level=high,即使有有效令牌,也需要明确的重新确认。
如果任何检查失败:阻止执行并返回单步补救措施。
6) 文件和并发强化
- 1. 规范路径强制
_manifest.md 路径必须在启动时规范化并固定。
- 2. 符号链接拒绝
如果清单路径或父路径通过符号链接解析,则拒绝清单读取/写入。
- 3. 锁语义
使用 _manifest.lock 进行写入:
- - 获取锁
- 写入临时文件
- fsync
- 原子重命名为 _manifest.md
- 释放锁
- 4. 写入超时
如果在 lock
timeoutms 内无法获取锁,则安全降级并以有界退避重试。
- 5. 单调序列
每次写入将 entry_seq 恰好增加 +1;拒绝非单调写入。
7) 篡改证据
完整性模式:
- - checksum(默认 MVP):对规范清单负载进行 sha256 哈希
- hmac(可选强化模式):仅在配置了托管密钥存储时
如果完整性验证失败:
- - 将清单标记为不可信
- 进入静默见证
- 需要用户辅助重新播种
8) 代谢调节器
- 1. 主动堆肥
在清单中保留最后 3 个决策;从主动推理中淘汰之前的 20 轮头脑风暴。
- 2. 疲劳触发器
如果上下文负载超过 fatigue
triggercontext_ratio,强制检查点并切换到单步模式。
- 3. 违规护栏
切勿将原始密钥、完整凭据或不必要的 PII 复制到清单中。
9) 可选钱包支持的同意模式(高风险流程)
钱包模式是可选的,默认禁用。
仅在钱包工具已配置时使用:
- - 保持文本令牌模式为默认
- 对于选定的高风险操作,要求签名负载(EIP-712 或等效),包含:
- actionhash
- nonce
- expiresat
- 在执行前验证签名是否与配置的地址匹配
- 如果缺少签名者配置,则安全降级至默认令牌模式
10) 规范清单模式(_manifest.md)
json
{
updated_at: 2026-03-21T15:24:00Z,
entry_seq: 1,
objective: 当前主要目标,
non_negotiables: [安全/红线约束],
lastgoodcheckpoint: sha256:...,
blocked_by: 当前依赖,
nextsinglestep: 原子下一步操作,
known_state: [仅已验证的事实/工件],
unknown_state: [未验证/缺失的项目],
consent_state: authorized|pending|locked,
irreversibleactionpending: ACT-9K2|none,
action_hash: sha256:...|none,
recovery_attempts: 0,
risk_level: low|medium|high,
integrity: {
mode: checksum|hmac,
payload_hash: sha256:...,
hmac_signature: hex|none,
verified_at: 2026-03-21T15:24:00Z
},
storage: {
root: /.memory-latch,
manifestpath: /.memory-latch/manifest.md,
lockpath: /.memory-latch/manifest.lock,
tokenledgerpath: /.memory-latch/tokens.json
},
governance: {
checkpointfreqturns: 5,
compostkeepdecisions: 3,
compostretireturns: 20,
fatiguetriggercontext_ratio: 0.75,
tokenttlminutes: 10,
tokensingleuse: true,
locktimeoutms: 800,
maxrecoveryattempts: 3
}
}
##