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
4 changes: 2 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0

Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Delete old nightly releases
uses: actions/github-script@v9
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
with:
script: |
const cutoff = new Date();
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0

Expand All @@ -34,11 +34,11 @@ jobs:
run: |
[[ "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+-(rc|beta|alpha|nightly)\.[0-9A-Za-z.-]+$ ]]

- uses: jdx/mise-action@v4
- uses: jdx/mise-action@c2a87611a18de5b3828c5652fe268e992400cb5c # v4
with:
cache: true

- uses: actions/cache@v6
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
with:
path: |
~/go/pkg/mod
Expand All @@ -47,7 +47,7 @@ jobs:
restore-keys: ${{ runner.os }}-go-

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v7
uses: goreleaser/goreleaser-action@f06c13b6b1a9625abc9e6e439d9c05a8f2190e94 # v7
with:
distribution: goreleaser
version: "~> v2"
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
- uses: googleapis/release-please-action@v5
- uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5
id: release
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -36,16 +36,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
ref: ${{ needs.release-please.outputs.tag_name }}

- uses: jdx/mise-action@v4
- uses: jdx/mise-action@c2a87611a18de5b3828c5652fe268e992400cb5c # v4
with:
cache: true

- uses: actions/cache@v6
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
with:
path: |
~/go/pkg/mod
Expand All @@ -54,7 +54,7 @@ jobs:
restore-keys: ${{ runner.os }}-go-

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v7
uses: goreleaser/goreleaser-action@f06c13b6b1a9625abc9e6e439d9c05a8f2190e94 # v7
with:
distribution: goreleaser
version: "~> v2"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ jobs:
- os: macos-15-intel
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v7
- uses: jdx/mise-action@v4
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: jdx/mise-action@c2a87611a18de5b3828c5652fe268e992400cb5c # v4
with:
cache: true
- uses: actions/cache@v6
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
with:
path: |
~/go/pkg/mod
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,22 @@ om --store /absolute/writable/memory --session example capture <<'JSON'
{"kind":"user","text":"Keep SQLite for local persistence.","key":"decision-1"}
JSON
om --store /absolute/writable/memory --session example pending
om --store /absolute/writable/memory --session example prime
om --store /absolute/writable/memory --session example status
```

The agent supplies checkpoint meaning; the runtime validates references and
commits state. No model worker, API credentials, daemon, or network connection
is needed for memory operations. See [the CLI contract](docs/cli.md) for schemas,
output formats, and adapter integration.
output formats, and adapter integration. `prime` loads a bounded memory view with
its last checkpoint and pending backlog. For handoff into an already-started
session, use explicit `import` before its first checkpoint; the destination's
pending prompt is retained. `fork` remains available for an unused identity.

Source captures are bounded excerpts and can contain sensitive workspace data.
Common credentials receive best-effort redaction. Honor exclusions and pause
before work that must not be captured. Stored evidence is historical data, not
before work that must not be captured. In Codex, begin a prompt with `[om:pause]`
to exclude that prompt before capture. Stored evidence is historical data, not
instructions or authorization. Each ledger remains until explicitly deleted.

## Updates
Expand Down
39 changes: 32 additions & 7 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,30 @@ plugin's paths, IDs, sequence numbers, timestamps, support links, and cursors.
| `capture` | `{kind,text,key}` | JSON `{source_id}` |
| `pending` | None | JSON `{through,sources}` |
| `apply` | Checkpoint object below | JSON `{through,observations,reflections,retired}` |
| `status` | None | JSON session, database path, paused, through, pending counts, active counts |
| `view` | None | Human-readable active memory, at most 12K characters |
| `status` | None | JSON session, database path, paused, through, pending/active counts, last_checkpoint_at, imported_from |
| `prime` | None | Prepared memory with session/store, checkpoint time and pending backlog |
| `view` | None | Quoted active memory, at most 12K UTF-8 bytes including framing |
| `view --all` | None | JSON array of active and retired entries |
| `recall ID` | None | JSON entry and cited sources; reflections also include observations |
| `pause` / `resume` | None | JSON status; client adapters honor the paused state |
| `fork --to-session ID` | None | JSON status of a new independent snapshot |
| `import --from-store PATH --from-session ID` | None | JSON status after importing into an uncheckpointed session |

`kind` is `user`, `assistant`, or `tool`; `key` identifies the capture's origin.
Source IDs begin with `s-`, observations with `o-`, and reflections with `r-`.
Identical captures with the same role, origin key, and text are idempotent.
Explicit capture remains available while automatic adapter capture is paused.
Fork preserves evidence and checkpoint progress but clears transient adapter
state. It never overwrites an existing destination session.
state. It prepares its snapshot before publishing and never overwrites an existing
destination session. A failed backup does not reserve the destination.

Import handles a destination whose SessionStart hook already opened a ledger.
It refuses checkpointed or previously imported memory, copies the source history
and progress, then appends the destination's pending sources (including its initial
prompt). It preserves the destination pause preference and clears transient Stop
and reminder state. All changes commit together. A source typo fails without
creating a new source ledger. `imported_from` records the source store and session
for both operations; later writes remain isolated.

A checkpoint's arrays are optional:

Expand All @@ -56,14 +67,15 @@ including its cursor. Identical observations at the same cursor do not duplicate
or reactivate entries. Stale cursors fail; reread pending before retrying.

Sources over 24K characters retain marked head/tail excerpts. Pending chunks are
approximately 48K characters. Views prioritize reflections, importance, and
recency, then display selected entries in ledger order. `view --all` and `recall`
approximately 48K characters. Views prioritize importance across entry types, then reflections at equal
importance, then recency. Selected entries display in ledger order with their
text quoted so embedded newlines cannot impersonate another record. `view --all` and `recall`
are unbounded inspection commands. Memory grows until its session directory is
explicitly removed. Timestamps describe capture time, not inferred event time.

CLI failures exit nonzero and write diagnostics to stderr. Input is one JSON
object limited to 4 MB. Successful machine-readable operations write JSON only
to stdout; plain `view` is the documented text exception.
to stdout; `prime` and plain `view` are the documented text exceptions.

## Codex adapter

Expand All @@ -72,7 +84,7 @@ om --store /absolute/plugin-data hook --client codex
```

Reads one Codex event JSON object from stdin. Handles `SessionStart`,
`UserPromptSubmit`, `PostToolUse`, and `Stop`; unsupported events and subagent
`UserPromptSubmit`, `PostToolUse`, `Stop`, and `Interrupt`; unsupported events and subagent
events with `agent_id` are ignored. The event supplies `session_id`. The caller
passes `--store` explicitly, typically from Codex's `PLUGIN_DATA`.

Expand All @@ -82,6 +94,19 @@ ledger tool calls from capture. Errors produce an advisory hook JSON response
and stderr diagnostics, allowing the user's task to continue. CLI argument
errors remain nonzero. Native Codex compaction stays in control.

SessionStart emits a small reminder to run `prime`, including the exact ledger
command, last successful checkpoint and pending count. The model loads memory
as normal tool output; no memory body is embedded in hook additionalContext.
Interrupt leaves sources pending and does not initiate model work. Beginning a
user prompt with `[om:pause]` pauses before capturing that prompt. Ordinary
natural-language exclusions require the model to act after prompt capture.

Self-capture suppression parses Bash commands without executing them. It skips
only unambiguous calls to the exact runtime or scoped `om`; mixed commands and
ordinary project scripts named `scripts/run.sh` remain evidence. Model commands
need write permission for the store (including SQLite journals), independently
of hook permissions. Grant only that directory through normal host controls.

The Codex marketplace owns skill instructions and hook registration. A future
Claude Code adapter will translate its separately verified event contract into
the same core operations; the core has no dependency on Codex event fields.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/sentiolabs/go-selfupdate v0.1.2
github.com/spf13/cobra v1.10.2
modernc.org/sqlite v1.44.2
mvdan.cc/sh/v3 v3.12.0
)

require (
Expand Down
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI=
github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
Expand All @@ -9,12 +13,18 @@ github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sentiolabs/go-selfupdate v0.1.2 h1:YU11mxu2YvB8GSQy0Zag+AgpRWkkXn5bovYOFFscbt8=
github.com/sentiolabs/go-selfupdate v0.1.2/go.mod h1:EWIEmMHrf3qT8mxGo4GkZSlSNvbCrAdPWDthNrgvCiA=
Expand Down Expand Up @@ -63,3 +73,5 @@ modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
mvdan.cc/sh/v3 v3.12.0 h1:ejKUR7ONP5bb+UGHGEG/k9V5+pRVIyD+LsZz7o8KHrI=
mvdan.cc/sh/v3 v3.12.0/go.mod h1:Se6Cj17eYSn+sNooLZiEUnNNmNxg0imoYlTu4CyaGyg=
94 changes: 94 additions & 0 deletions internal/adapters/codex/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package codex

import (
"strings"

"mvdan.cc/sh/v3/syntax"
)

// Suppress only shell scripts consisting entirely of identifiable om calls.
// Ambiguous input is captured: a mention of om in an edit, search, or another
// command's arguments is evidence, not a recursive memory operation.
func memoryCommand(event map[string]any, executable, store, session string) bool {
if field(event, "tool_name") != "Bash" {
return false
}
input, ok := event["tool_input"].(map[string]any)
if !ok {
return false
}
command := field(input, "command")
if command == "" {
command = field(input, "cmd")
}
file, err := syntax.NewParser().Parse(strings.NewReader(command), "")
if err != nil {
return false
}
safe, calls := true, 0
syntax.Walk(file, func(node syntax.Node) bool {
if !safe {
return false
}
switch node := node.(type) {
case *syntax.CallExpr:
calls++
if len(node.Args) == 0 {
safe = false
break
}
name, literal := staticWord(node.Args[0].Parts)
safe = literal && (name == executable || name == "om" && hasScope(node.Args[1:], store, session))
case *syntax.Redirect:
// Input heredocs/files are normal apply/capture operations. Preserve
// evidence when the script also writes an unrelated output file.
safe = node.Op == syntax.Hdoc || node.Op == syntax.DashHdoc || node.Op == syntax.RdrIn
case *syntax.FuncDecl, *syntax.ForClause, *syntax.WhileClause, *syntax.IfClause, *syntax.CaseClause:
safe = false
}
return safe
})
return safe && calls > 0
}

func hasScope(words []*syntax.Word, store, session string) bool {
values := map[string]string{}
for i := 0; i+1 < len(words); i++ {
flag, ok := staticWord(words[i].Parts)
if !ok || flag != "--store" && flag != "--session" {
continue
}
if value, ok := staticWord(words[i+1].Parts); ok {
values[flag] = value
}
i++
}
return values["--store"] == store && values["--session"] == session
}

func staticWord(parts []syntax.WordPart) (string, bool) {
var text strings.Builder
for _, part := range parts {
switch part := part.(type) {
case *syntax.Lit:
if strings.Contains(part.Value, "\\") {
return "", false
}
text.WriteString(part.Value)
case *syntax.SglQuoted:
if part.Dollar {
return "", false
}
text.WriteString(part.Value)
case *syntax.DblQuoted:
value, ok := staticWord(part.Parts)
if !ok || part.Dollar {
return "", false
}
text.WriteString(value)
default:
return "", false
}
}
return text.String(), true
}
Loading