strukto-ai--mirage
bcbd1bdb22
Integ / changes (push) Has been skipped
Pre-commit / pre-commit (push) Failing after 1s
CLI exit codes / changes (push) Has been skipped
Test (Install) / changes (push) Has been skipped
Test (Python) / changes (push) Has been skipped
Test (TypeScript) / changes (push) Has been skipped
CLI exit codes / cli-gate (push) Has been cancelled
Test (Install) / test-install-gate (push) Has been cancelled
Integ / integ-gate (push) Has been cancelled
Test (Python) / test-python-gate (push) Has been cancelled
Test (TypeScript) / test-typescript-gate (push) Has been cancelled
Test (Install) / python-minimal (3.12) (push) Has been cancelled
Test (Install) / python-minimal (3.11) (push) Has been cancelled
Test (Install) / python-extra (agno, mirage.agents.agno) (push) Has been cancelled
Test (Install) / python-extra (chroma, mirage.resource.chroma) (push) Has been cancelled
Test (Install) / python-extra (pdf, mirage.core.filetype.pdf) (push) Has been cancelled
Integ / integ (push) Has been cancelled
Integ / integ-database (push) Has been cancelled
Integ / integ-database-ts (push) Has been cancelled
Integ / integ-data (push) Has been cancelled
Integ / integ-ssh (push) Has been cancelled
Integ / integ-ssh-ts (push) Has been cancelled
Test (Python) / audit (push) Has been cancelled
Test (TypeScript) / test (push) Has been cancelled
Test (TypeScript) / python-fs-shim (push) Has been cancelled
CLI exit codes / Python CLI (push) Has been cancelled
CLI exit codes / TypeScript CLI (push) Has been cancelled
CLI exit codes / Cross-language snapshot interop (push) Has been cancelled
Test (Python) / test (push) Has been cancelled
Test (Python) / import-isolation (deepagents, openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Python) / import-isolation (deepagents, pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Integ / integ-ts (push) Has been cancelled
Integ / integ-fuse (push) Has been cancelled
Test (Install) / python-extra (databricks, mirage.resource.databricks_volume) (push) Has been cancelled
Test (Install) / python-extra (deepagents, mirage.agents.langchain) (push) Has been cancelled
Test (Install) / python-extra (email, mirage.resource.email) (push) Has been cancelled
Test (Install) / python-extra (fuse, mirage.fuse.mount) (push) Has been cancelled
Test (Install) / python-extra (hdf5, mirage.core.filetype.hdf5) (push) Has been cancelled
Test (Install) / python-extra (hf, mirage.resource.hf_buckets) (push) Has been cancelled
Test (Install) / python-extra (lancedb, mirage.resource.lancedb) (push) Has been cancelled
Test (Install) / python-extra (langfuse, mirage.resource.langfuse) (push) Has been cancelled
Test (Install) / python-extra (mongodb, mirage.resource.mongodb) (push) Has been cancelled
Test (Install) / python-extra (nextcloud, mirage.resource.nextcloud) (push) Has been cancelled
Test (Install) / python-extra (openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Install) / python-extra (openhands, mirage.agents.openhands, 3.12) (push) Has been cancelled
Test (Install) / python-extra (parquet, mirage.core.filetype.parquet) (push) Has been cancelled
Test (Install) / python-extra (postgres, mirage.resource.postgres) (push) Has been cancelled
Test (Install) / python-extra (pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Test (Install) / python-extra (qdrant, mirage.resource.qdrant) (push) Has been cancelled
Test (Install) / python-extra (redis, mirage.resource.redis) (push) Has been cancelled
Test (Install) / python-extra (s3, mirage.resource.s3) (push) Has been cancelled
Test (Install) / python-extra (ssh, mirage.resource.ssh) (push) Has been cancelled
Test (Install) / ts-minimal (push) Has been cancelled
98 行
3.1 KiB
Plaintext
98 行
3.1 KiB
Plaintext
---
|
|
title: Observer
|
|
description: A hidden recorder that captures every command and file op as timestamped events, backed by a pluggable store. Powers command history.
|
|
icon: eye
|
|
---
|
|
|
|
## What It Does
|
|
|
|
Every workspace has one **Observer**: a hidden recorder that logs each top-level
|
|
command and its file ops as timestamp-ordered events. It owns no mount and has no
|
|
endpoint of its own, features like command history are just *views* over its
|
|
events. Nested evals (`$(...)`, `eval`, `source`, `xargs`) run without recording,
|
|
so only real top-level commands land.
|
|
|
|
```mermaid
|
|
flowchart TD
|
|
Exec["ws.execute(cmd)"] --> Obs[Observer]
|
|
Obs --> Store[("ObserverStore<br/>RAM · Disk · Redis")]
|
|
Store --> Hist["history builtin<br/>(calling session)"]
|
|
Store --> File["/.bash_history<br/>(all sessions)"]
|
|
```
|
|
|
|
## Storage backends
|
|
|
|
The Observer holds a storage-agnostic `ObserverStore`. RAM is the default; swap it
|
|
to persist events across daemon restarts. The store is chosen at construction; there
|
|
is no runtime API to change it.
|
|
|
|
<CodeGroup>
|
|
|
|
```python Python
|
|
from mirage import Workspace, MountMode
|
|
from mirage.resource.ram import RAMResource
|
|
from mirage.observe.disk_store import DiskObserverStore
|
|
from mirage.observe.redis_store import RedisObserverStore
|
|
|
|
# RAM (default), nothing to configure
|
|
ws = Workspace({"/data": RAMResource()}, mode=MountMode.WRITE)
|
|
|
|
# Persist to disk
|
|
ws = Workspace({"/data": RAMResource()}, mode=MountMode.WRITE,
|
|
observe=DiskObserverStore("/var/mirage/history"))
|
|
|
|
# Persist to Redis
|
|
ws = Workspace({"/data": RAMResource()}, mode=MountMode.WRITE,
|
|
observe=RedisObserverStore("redis://localhost:6379/0"))
|
|
```
|
|
|
|
```typescript TypeScript
|
|
import { Workspace, RAMResource } from '@struktoai/mirage-core'
|
|
import { DiskObserverStore, RedisObserverStore } from '@struktoai/mirage-node'
|
|
|
|
// RAM (default), nothing to configure
|
|
const ws = new Workspace({ '/data': new RAMResource() })
|
|
|
|
// Persist to disk
|
|
const wsDisk = new Workspace(
|
|
{ '/data': new RAMResource() },
|
|
{ observe: new DiskObserverStore('/var/mirage/history') },
|
|
)
|
|
|
|
// Persist to Redis
|
|
const wsRedis = new Workspace(
|
|
{ '/data': new RAMResource() },
|
|
{ observe: new RedisObserverStore({ url: 'redis://localhost:6379/0' }) },
|
|
)
|
|
```
|
|
|
|
</CodeGroup>
|
|
|
|
## Supported: command history
|
|
|
|
The Observer powers a GNU-bash-compatible history, exposed two ways over the same
|
|
events:
|
|
|
|
| Surface | Scope | Notes |
|
|
| --- | --- | --- |
|
|
| `history` builtin | calling session | GNU flags `-c -d -a -n -r -w -s -p` and a count arg |
|
|
| `/.bash_history` mount | all sessions | read-only, GNU histfile format (`#<epoch>` then the command) |
|
|
|
|
Because `/.bash_history` is a real read-only mount, the ordinary file commands work
|
|
on it directly:
|
|
|
|
```bash
|
|
history 5
|
|
tail -n 6 /.bash_history
|
|
grep cat /.bash_history
|
|
```
|
|
|
|
The format is GNU bash (`#<epoch>`), not zsh (`: <ts>:<dur>;<cmd>`).
|
|
|
|
## Snapshots
|
|
|
|
History is part of the workspace state: the Observer's command, clear, and delete
|
|
events are captured into a [snapshot](/home/snapshot) and restored on load, so a
|
|
restored workspace replays with the same history. The `/.bash_history` view mount
|
|
itself is not stored, it is a live projection rebuilt from the events.
|