Skip to content
Open
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
30 changes: 20 additions & 10 deletions .github/workflows/sync-screenpipe-fork.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: Sync screenpipe fork

# Keeps AnkushMalaker/screenpipe's `chronicle` branch rebased directly onto
# upstream screenpipe/screenpipe main. The branch carries Chronicle's complete
# patch stack; the former `custom/linux-timeline-stability` base branch was
# folded into it and deleted in August 2026.
# Keeps AnkushMalaker/screenpipe's `chronicle-recorder` branch rebased directly
# onto upstream screenpipe/screenpipe main. The historical `chronicle` branch
# is left intact.
#
# This lives in chronicle rather than in the fork itself for two reasons:
# `schedule` only fires from a repo's default branch, so hosting it in the fork
Expand Down Expand Up @@ -38,14 +37,14 @@ env:

jobs:
rebase:
name: Rebase chronicle onto upstream/main
name: Rebase chronicle-recorder onto upstream/main
runs-on: ubuntu-latest
steps:
- name: Check out the fork's Chronicle branch
uses: actions/checkout@v4
with:
repository: ${{ env.FORK }}
ref: chronicle
ref: chronicle-recorder
# Full history: a rebase needs the merge base with its target, which a
# shallow clone does not have.
fetch-depth: 0
Expand Down Expand Up @@ -92,7 +91,7 @@ jobs:
(github.event_name == 'schedule' ||
(inputs.push && inputs.push != 'false'))
env:
BRANCH: chronicle
BRANCH: chronicle-recorder
run: |
# --force-with-lease, never plain --force: the rebase rewrote history,
# but this still refuses if the branch moved since checkout (e.g. a
Expand All @@ -104,7 +103,7 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
BEHIND: ${{ steps.diverge.outputs.behind }}
BRANCH: chronicle
BRANCH: chronicle-recorder
ONTO: upstream/main
run: |
title="screenpipe fork: $BRANCH needs manual conflict resolution"
Expand All @@ -117,9 +116,14 @@ jobs:
"The fork was left untouched. Resolve it locally:" \
"" \
'```' \
"cd untracked/screenpipe && SYNC_BRANCH=$BRANCH ./sync-fork.sh" \
"git clone --branch $BRANCH https://github.com/$FORK.git screenpipe-sync" \
"cd screenpipe-sync" \
'expected=$(git rev-parse HEAD)' \
"git fetch --no-tags $UPSTREAM main" \
'git rebase FETCH_HEAD' \
"# fix conflicts, then: git add <files> && git rebase --continue" \
"SYNC_BRANCH=$BRANCH ./sync-fork.sh --push" \
"# Run the affected tests and review the diff before publishing." \
"git push --force-with-lease=refs/heads/$BRANCH:\$expected origin HEAD:refs/heads/$BRANCH" \
'```' \
"" \
"Run: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID")
Expand All @@ -128,3 +132,9 @@ jobs:
else
gh issue create --repo "$GITHUB_REPOSITORY" --title "$title" --body "$body"
fi

- name: Fail on rebase conflict
if: always() && steps.rebase.outputs.clean == 'false'
run: |
echo "::error::rebase conflicted; the fork was left unchanged. See the conflict issue and run logs."
exit 1
89 changes: 29 additions & 60 deletions docs/screenpipe-fork-sync.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,51 @@
# Screenpipe fork sync

Chronicle consumes the `chronicle` branch of
[`AnkushMalaker/screenpipe`](https://github.com/AnkushMalaker/screenpipe). It is
a single patch stack rebased directly onto `screenpipe/screenpipe`'s `main`.
The older `custom/linux-timeline-stability` intermediate branch no longer
exists; its commits were folded into `chronicle` in August 2026.
Chronicle's recorder source is the `chronicle-recorder` branch of
[`AnkushMalaker/screenpipe`](https://github.com/AnkushMalaker/screenpipe), based
directly on upstream `screenpipe/screenpipe` `main`. The historical `chronicle`
branch remains intact; the new branch does not replay its old history.

## Automated sync

`.github/workflows/sync-screenpipe-fork.yml` runs daily and can also be started
manually. It:

1. checks out the fork's `chronicle` branch with full history;
2. fetches only `main` from upstream;
3. rebases `chronicle` onto `upstream/main` when it is behind;
4. pushes with `--force-with-lease`; and
5. opens or updates a Chronicle issue if the rebase conflicts.
`.github/workflows/sync-screenpipe-fork.yml` runs daily from Chronicle's default
branch, `dev`, and can also be started manually. It checks out `chronicle-recorder`
with full history, fetches upstream `main`, and rebases when upstream advances.
A successful rebase pushes with `--force-with-lease`; conflicts leave the fork
unchanged, open or update a Chronicle issue, and fail the workflow after the issue
reporting step. A reporting error also leaves the workflow failed. This workflow checks whether the
rebase applies; it does not build, install, or validate the recorder on a device.

The workflow needs the `SCREENPIPE_FORK_TOKEN` repository secret with write
access to `AnkushMalaker/screenpipe`. A manual dry run can be dispatched with:
access to the fork. Start a manual dry run with:

```bash
gh workflow run sync-screenpipe-fork.yml -F push=false
gh workflow run sync-screenpipe-fork.yml --ref dev -F push=false
```

Use `-F`, not `-f`, so GitHub receives a boolean rather than the truthy string
`"false"`.
Use `-F` to send a boolean. The workflow also rejects the string `"false"`.

## Local sync and conflict recovery

The fork is normally cloned at `untracked/screenpipe` with the upstream remote
named `origin` and the writable fork remote named `fork`. The script resolves
the remotes by URL, so their names are not a contract.

First check divergence without changing the worktree:

```bash
cd untracked/screenpipe
./sync-fork.sh --check
```

Then rebase locally. The script uses `--autostash` because Tauri builds commonly
leave generated schema changes in the worktree:

```bash
./sync-fork.sh
```

If Git stops on a conflict, resolve it, stage the resolved files, and continue:
Use a fresh directory to preserve existing work. The commands below use `origin`
for the writable fork and fetch upstream directly by URL:

```bash
git add <files>
git rebase --continue
git clone --branch chronicle-recorder https://github.com/AnkushMalaker/screenpipe.git screenpipe-sync
cd screenpipe-sync
expected=$(git rev-parse HEAD)
git fetch --no-tags https://github.com/screenpipe/screenpipe main
git rebase FETCH_HEAD
```

Run tests appropriate to the touched Screenpipe areas (see the fork's
`AGENTS.md` and `TESTING.md`), then publish the rewritten branch:
Resolve conflicts, stage only the resolved files, and run `git rebase --continue`.
Use `git rebase --abort` to abandon the attempt. Review the diff and run tests
appropriate to the affected recorder areas before publishing. A clean rebase alone
does not prove capture, privacy, or audio behavior.

```bash
./sync-fork.sh --push
git push --force-with-lease=refs/heads/chronicle-recorder:$expected origin HEAD:refs/heads/chronicle-recorder
```

The push deliberately uses `--force-with-lease`. Never replace it with an
unconditional force push.

## Topology invariant

The automation and `untracked/screenpipe/sync-fork.sh` must agree on this
relationship:

```text
screenpipe/screenpipe main -> AnkushMalaker/screenpipe chronicle
```

When changing the branch topology, update both files together and verify the
remote branches with:

```bash
git -C untracked/screenpipe ls-remote --heads fork chronicle
git -C untracked/screenpipe ls-remote --heads origin main
```
The explicit expected commit protects concurrent changes to the remote branch.
Never replace it with an unconditional force push. Keep the workflow and this
runbook aligned; the recorder branch does not require a custom sync script.
150 changes: 150 additions & 0 deletions tests/unit/test_screenpipe_sync_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# screenpipe — AI that knows everything you've seen, said, or heard
# https://screenpipe.com

"""Exercise the workflow's actual rebase/report shell without network access."""

import os
import re
import subprocess
import tempfile
import unittest
from pathlib import Path

WORKFLOW = (
Path(__file__).resolve().parents[2] / ".github/workflows/sync-screenpipe-fork.yml"
)


def step(text, name):
block = text.split(f" - name: {name}\n", 1)[1].split("\n - name:", 1)[0]
script = block.split(" run: |\n", 1)[1]
return block, "\n".join(line[10:] for line in script.splitlines() if line.strip())


class ScreenpipeSyncWorkflowTests(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
self.root = Path(self.temp.name)
self.text = WORKFLOW.read_text()
self.env = {
**os.environ,
"GIT_CONFIG_GLOBAL": "/dev/null",
"GIT_CONFIG_NOSYSTEM": "1",
}
self.git("init", "-b", "main")
self.git("config", "user.name", "Test")
self.git("config", "user.email", "test@example.invalid")
(self.root / "capture").write_text("base\n")
self.git("add", "capture")
self.git("commit", "-m", "base")
self.git("checkout", "-b", "chronicle-recorder")
(self.root / "capture").write_text("fork\n")
self.git("commit", "-am", "fork")
self.original = self.git("rev-parse", "HEAD")
self.git("checkout", "main")

def git(self, *args):
return subprocess.check_output(
["git", *args],
cwd=self.root,
env=self.env,
stderr=subprocess.DEVNULL,
text=True,
).strip()

def shell(self, script, **env):
return subprocess.run(
["bash", "-eo", "pipefail", "-c", script],
cwd=self.root,
env={**self.env, **env},
capture_output=True,
text=True,
)

def rebase(self, conflict):
(self.root / ("capture" if conflict else "upstream")).write_text("upstream\n")
self.git("add", ".")
self.git("commit", "-m", "upstream")
self.git("checkout", "chronicle-recorder")
output = self.root / "output"
result = self.shell(
step(self.text, "Rebase")[1], ONTO="main", GITHUB_OUTPUT=str(output)
)
return result, output.read_text()

def test_conflict_restores_fork_reports_then_fails(self):
result, output = self.rebase(conflict=True)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn("clean=false", output)
self.assertEqual(self.git("rev-parse", "HEAD"), self.original)
self.assertFalse((self.root / ".git/rebase-merge").exists())
stub = self.root / "bin"
stub.mkdir()
gh = stub / "gh"
gh.write_text(
'#!/bin/bash\nif [ "$2" = list ]; then exit 0; fi\nprintf "%s\\n" "$@" >> "$REPORT_LOG"\n'
)
gh.chmod(0o755)
report = self.root / "report"
result = self.shell(
step(self.text, "Open an issue on conflict")[1],
PATH=f'{stub}:{os.environ["PATH"]}',
REPORT_LOG=str(report),
BRANCH="chronicle-recorder",
ONTO="upstream/main",
FORK="example/fork",
UPSTREAM="https://example.invalid/upstream",
BEHIND="1",
GITHUB_REPOSITORY="example/chronicle",
GITHUB_SERVER_URL="https://example.invalid",
GITHUB_RUN_ID="1",
)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn("create", report.read_text())
self.assertIn("chronicle-recorder", report.read_text())
self.assertNotIn("sync-fork.sh", report.read_text())
block, script = step(self.text, "Fail on rebase conflict")
self.assertIn("if: always() && steps.rebase.outputs.clean == 'false'", block)
self.assertLess(
self.text.index("- name: Open an issue"),
self.text.index("- name: Fail on rebase"),
)
self.assertNotEqual(self.shell(script).returncode, 0)

def test_clean_rebase_keeps_both_changes(self):
result, output = self.rebase(conflict=False)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn("clean=true", output)
self.assertEqual((self.root / "capture").read_text(), "fork\n")
self.assertEqual((self.root / "upstream").read_text(), "upstream\n")
self.assertNotEqual(self.git("rev-parse", "HEAD"), self.original)

def test_branch_lease_and_manual_dry_run_guards(self):
self.assertIn("ref: chronicle-recorder\n", self.text)
self.assertEqual(
re.findall(r"BRANCH: (\S+)", self.text), ["chronicle-recorder"] * 2
)
block, script = step(self.text, "Push rebased branch")
self.assertIn("steps.rebase.outputs.clean == 'true'", block)
self.assertIn("inputs.push && inputs.push != 'false'", block)
self.assertIn('git push --force-with-lease origin "HEAD:$BRANCH"', script)
for name in re.findall(r"^ - name: (.+)$", self.text, re.M):
if (
" run: |"
not in self.text.split(f" - name: {name}\n", 1)[1].split(
"\n - name:", 1
)[0]
):
continue
result = subprocess.run(
["bash", "-n"],
input=step(self.text, name)[1],
text=True,
capture_output=True,
)
self.assertEqual(result.returncode, 0, result.stderr)


if __name__ == "__main__":
unittest.main()
Loading