Skip to content

feat: add greplica graph promote to commit working memory into main - #109

Open
burrows99 wants to merge 2 commits into
Autoloops:mainfrom
burrows99:feat/graph-promote
Open

feat: add greplica graph promote to commit working memory into main#109
burrows99 wants to merge 2 commits into
Autoloops:mainfrom
burrows99:feat/graph-promote

Conversation

@burrows99

Copy link
Copy Markdown

What

Adds greplica graph promote, which commits the working scope into main.

Working memory (the working scope) is where a session's new claims, flows,
components and edges land. Until now nothing moved them into the committed
main scope, so working memory grew without bound and the line between stable
repo facts and active session edits kept blurring (#22).

graph promote moves every working membership into main under one new main
memory commit, then clears working:

$ greplica graph promote
Promoted working memory into main.
Memory commit: mc_...
Components: 2
Flows: 0
Claims: 2
Edges: 2
Working scope cleared.

Running it again is a no-op:

$ greplica graph promote
Working memory is already empty. Nothing to promote.

The design fork: supersession

readGraph decides which claims are live by walking supersedes edges across
the union of main and working (activeSubjectKeys). A working claim usually
supersedes an older main claim through a supersedes edge. If promote moved the
claim but left that edge behind, clearing working would bring the stale main
claim back to life.

So promote moves every working membership together, claims and their edges, under
one main memory commit. The supersedes edge lands in main next to the new claim
and the retired claim stays retired. check-graph-promote.js asserts exactly
this: it seeds a v1 claim in main, a v2 claim plus a supersedes edge in working,
promotes, and checks that v1 is still retired once working is emptied.

I raised this fork on the issue and went with emptying working (dropping the
working memberships) rather than leaving a tombstone commit. I can switch to a
tombstone if maintainers prefer that.

Scope of this first pass

The issue sketches graph promote [--scope <scope_id>]. Today there is one fixed
working scope per repo (requireWorkingScope), so there is no other scope to
target yet. This pass promotes the whole working scope with no flag; a --scope
selector fits once session or branch scopes exist (#20).

Layering and safety

  • apps/cli/main.ts: the graph promote command, handler and printer.
  • libs/knowledge-graph/service.ts: promoteWorking orchestration.
  • libs/storage/sqlite/repository.ts: promoteWorkingToMain, one transaction.
  • libs/knowledge-graph/graph-promote.ts: the pure countPromotedSubjects tally.
  • scripts/check-graph-promote.js: smoke test, wired into npm test.

Object rows are keyed by (repo_id, id) since #107 and are left untouched.
Both scopes belong to the same repo, so promotion only re-homes memberships,
never object rows.

Testing

  • npm run typecheck clean.
  • npm test green, including the new check-graph-promote.js.
  • Ran the real CLI end to end (apply to working, promote, promote again, read).

Before and after demos are in the thread below.

Closes #22

Working memory (the working scope) kept accumulating with no way to move it
into the committed main scope, so the boundary between stable repo facts and
active session edits kept blurring. This adds `greplica graph promote`.

It moves every working-scope membership into the main scope under one new main
memory commit, then clears working. Claims travel together with their edges, so
a `supersedes` edge that retires a main claim is promoted along with its new
claim and the retirement survives once working is empty. Object rows are keyed
by (repo_id, id) and are left in place; both scopes belong to the same repo, so
promotion only re-homes this repo's memberships. Running it on an empty working
scope is a no-op.

A scripts/check-graph-promote.js smoke test covers the move, the cleared working
scope, the preserved supersession, and the no-op, and is wired into npm test.

Closes Autoloops#22

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@burrows99

Copy link
Copy Markdown
Author

After demo: the same flow now works. graph promote moves working memory into main and clears working, and a second run confirms working is empty.

after.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: Add command to promote working memory to main scope (greplica graph promote)

1 participant