agentleFS
jamesctuckerjamesctucker/moraine/.agents/skills/sync-upstream/SKILL.md

sync-upstream

Skill1 starsChanged 8 days agoMITView on GitHub

Sync this workspace with the upstream Moraine template repo, preserving your personalizations. Use when user says "sync with upstream", "pull upstream changes", "update from upstream", or "keep my fork current".

  • Deletes or force-pushes

19 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use start-mission, improve-codebase-architecture and 1 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • parkchuSkill

    start-mission

    넥스트스텝(NextStep) 미션을 처음 시작할 때, 미션 저장소를 fork·clone하고 최초 작업 브랜치(step1 등)까지 만들어 준다. gh CLI로 fork하고 clone까지 이어서 처리하며, gh가 없거나 인증이 안 돼 있으면 브라우저 Fork 안내로 폴백한다. 이미 fork/clone돼 있으면 재사용하고 이어서 진행한다(재실행 안전). 사용자가 "미션 시작하려는데 저장소 세팅해줘", "새 미션 시작할래", "fork부터 해줘", "/nextstep:start-mission" 등으로 요청할 때 사용한다.

    Also in 3 projects that use this

  • GoogleSkill

    improve-codebase-architecture

    Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.

    Also in 3 projects that use this

  • GoogleSkill

    tdd

    Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.

    Also in 3 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

30 rules. 0 are common, 16 are distinctive, and 14 are very specific to this project.

  • 0

    Common

    Most of the 14 edited versions we read keep these.

  • 16

    Distinctive

    This author's own choices. Worth a look.

  • 14

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If this fails (missing remote), check the origin remote to infer the source:

    line 24
  2. Very specific:

    If origin is your own repo (forked from jamesctucker/moraine, or cloned from it and repointed — the two setups the README recommends), add:

    line 30
  3. Very specific:

    If origin came from a different user's repo (e.g., you forked from a friend who forked jamesctucker), ask the user which upstream they want …

    line 36
  4. Distinctive:

    If anything is uncommitted or staged, stop and tell the user: "Working tree is dirty.

    line 44
  5. Very specific:

    If CURRENT_BRANCH is not main, tell the user: "You're on $CURRENT_BRANCH.

    line 52
  6. Distinctive:

    If they decline, proceed on the current branch — but remind them in the final report.

    line 54
  7. Distinctive:

    If the output is empty, tell the user "Already up to date — no upstream changes to sync" and exit.

    line 79
  8. Distinctive:

    If there are changes, list them so the user sees what's coming:

    line 81
  9. Distinctive:

    If the file was deleted upstream, remove it locally:

    line 147
  10. Very specific:

    Edge case — user-local changes to SAFE files: Check git diff HEAD -- <file> before checking out upstream.

    line 155
  11. Very specific:

    If upstream added a new [CUSTOMIZE] section, include it

    line 175
  12. Very specific:

    If upstream removed or moved a [CUSTOMIZE] section, surface it to the user — don't silently drop their content

    line 176
  13. Distinctive:

    If upstream and user both changed the same non-marked section, prefer upstream (structural) but note the conflict

    line 184
  14. Distinctive:

    Wait for the user's choice per file.

    line 205
  15. Very specific:

    If the user chose "Show me the raw diff", print diff <file> <(git show upstream/main:<file>) and re-ask.

    line 207
  16. Distinctive:

    If upstream changed any of these, stop and surface to the user.

    line 213
  17. Distinctive:

    If upstream added a new file in a SAFE directory (e.g., new skill, new script), just take it:

    line 219
  18. Distinctive:

    If upstream added a new file in a USER-OWNED directory, surface it to the user and ask.

    line 226
  19. Distinctive:

    After all files are staged:

    line 230
  20. Very specific:

    If upstream changed scripts/setup or requirements.txt, reinstall the Python dependencies into the workspace venv:

    line 240
  21. Very specific:

    If upstream changed .opencode-version:

    line 248
  22. Very specific:

    If they don't match, tell the user: "Upstream updated OpenCode to $EXPECTED.

    line 255
  23. Very specific:

    Run the same checks as scripts/setup:

    line 259
  24. Very specific:

    If anything fails, stop and tell the user.

    line 267
  25. Distinctive:

    If smoke test passed (or user chose to proceed despite warnings):

    line 271
  26. Distinctive:

    After committing, print a clear summary:

    line 286
  27. Distinctive:

    If something fails and you've already staged some changes:

    line 315
  28. Distinctive:

    If the user says "stop", "cancel", or "abort" at any point:

    line 323
  29. Very specific:

    If git diff HEAD..upstream/main --stat | tail -1 shows more than ~50 files changed, warn the user: "This is a large upstream sync ($N …

    line 334
  30. Distinctive:

    If the user has local commits between syncs, those are preserved in the backup branch

    line 342

“Common” is measured: kept by at least 6 in 10 of the 14 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Sync with Upstream

When to use

User wants to pull changes from the upstream Moraine repo into their clone or fork while preserving their personalizations (AGENTS.md customizations, MCP server selection, wiki content, etc.).

Overview

This is a merge operation, not a reset. The goal is to take upstream improvements (new skills, script fixes, cron updates) while keeping the user's personal content intact. For files with [CUSTOMIZE] markers the agent proposes a merge that keeps the marked regions; for markerless config it applies explicit preservation rules (e.g. the user's MCP server set). Every personalized file is shown to the user for approval — nothing personalized is auto-overwritten.

Pre-flight

1. Verify upstream remote

git remote get-url upstream

If this fails (missing remote), check the origin remote to infer the source:

ORIGIN_URL=$(git remote get-url origin)

If origin is your own repo (forked from jamesctucker/moraine, or cloned from it and repointed — the two setups the README recommends), add:

git remote add upstream https://github.com/jamesctucker/moraine.git

If origin came from a different user's repo (e.g., you forked from a friend who forked jamesctucker), ask the user which upstream they want to sync from before adding the remote. Don't assume.

2. Check working tree is clean

git status --porcelain

If anything is uncommitted or staged, stop and tell the user: "Working tree is dirty. Commit or stash your changes before syncing." Do not proceed.

Also check the current branch: Ops should happen on main. If the user is on a feature branch, warn them and offer to switch:

CURRENT_BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null || echo "")

If CURRENT_BRANCH is not main, tell the user: "You're on $CURRENT_BRANCH. Syncing here will commit upstream changes to this branch. Switch to main first? [Y/n]"

If they decline, proceed on the current branch — but remind them in the final report.

3. Create a backup branch

This is the escape hatch — if the sync goes wrong, the user can always reset to this branch.

BACKUP_BRANCH="backup-pre-sync-$(date +%Y%m%d-%H%M%S)"
git branch "$BACKUP_BRANCH"

Tell the user: "Created backup branch \"$BACKUP_BRANCH\". If anything goes wrong: git reset --hard $BACKUP_BRANCH"

4. Fetch upstream

git fetch upstream

5. Detect if there's anything to sync

git diff HEAD..upstream/main --name-only

If the output is empty, tell the user "Already up to date — no upstream changes to sync" and exit.

If there are changes, list them so the user sees what's coming:

Upstream changes detected:
  M  scripts/setup
  M  .agents/skills/session-handoff/SKILL.md
  A  packs/<pack>/skills/new-skill/SKILL.md
  ...

Classify changes

For each changed file, classify into one of three buckets based on the path:

SAFE — structural files, auto-take upstream

These files are pure upstream code. The user should not have personalized them. If local changes exist, they were probably accidental — but always check (see "Auto-merge SAFE files" below for the safety check).

  • scripts/** (setup, the moraine CLI, core workspace scripts)
  • .agents/skills/<id>/** for each core skill upstream ships; any other real folder there is the user's (see USER-OWNED)
  • packs/<pack>/** for every pack except local: skills, scripts, jobs, pack.yaml
  • .opencode/plugins/** (plugin scaffolding)
  • .opencode/opencode.json outside mcp.servers (shell-safety permissions)
  • CLAUDE.md, .claude/settings.json (the Claude import and permission mirror; the rest of .claude/ is gitignored sync state)
  • .opencode-version
  • tests/**
  • .husky/** (git hooks) — treat as SAFE but always check for user-local changes; users sometimes customize pre-push
  • .github/**
  • .editorconfig, .gitattributes, .gitignore, .nvmrc
  • .sembleignore
  • package.json, bun.lock, pyproject.toml, requirements.txt at the repo root (the automation pack's runner copies are SAFE via packs/<pack>/** above)
  • LICENSE

PERSONALIZED — files with [CUSTOMIZE] markers or user-edited config

These files have structure that upstream maintains, but contain [CUSTOMIZE] sections where the user adds their own content. The agent should propose a merge, not auto-take upstream.

  • AGENTS.md — has [CUSTOMIZE] markers for remote access
  • packs/<pack>/AGENTS.md — when it carries [CUSTOMIZE] markers (a pack's issue-tracker section does)
  • README.md — user-edited setup notes and integrations (no markers; whole file is user-owned in spirit)
  • .opencode/opencode.json — permissions come from upstream; only the mcp.servers block is preserved (see the rule below)
  • repos/README.md and repos/*.md — the user's repo registry (pointer files)
  • memory/README.md (if user customized stubs)
  • artifacts/README.md

USER-OWNED — user creates all content, upstream should never touch

These paths belong to the user. Never write to one yourself — not a stub, not a fix — and if an upstream change touches one, stop and surface it: it is either a template update (acceptable) or a mistake (flag it).

  • moraine.yaml — harnesses, enabled packs, and the user's MCP servers
  • packs/local/** — the user's own pack
  • .agents/skills/<id>/ for any skill upstream does not ship as core
  • wiki/**
  • memory/sessions/**, memory/staging/**, memory/reviews/**
  • artifacts/** (except README.md and _TEMPLATE.md)
  • repos/<repo>/** (sub-repos)

Auto-merge SAFE files

For each SAFE file that has upstream changes:

git checkout upstream/main -- <file>
git add <file>

If the file was deleted upstream, remove it locally:

git rm <file>

Track which files were auto-merged and report them at the end.

Edge case — user-local changes to SAFE files: Check git diff HEAD -- <file> before checking out upstream. If the user has local modifications, do not auto-overwrite — move it to the PERSONALIZED list and ask the user.

Smart-merge PERSONALIZED files

For each PERSONALIZED file:

1. Read both versions

git show upstream/main:<file> > /tmp/upstream-version
cat <file>  # current version

2. Identify the merge structure

Markers are a convention, not a machine-enforced boundary: AGENTS.md uses them consistently, opencode.json has none (it gets the MCP-preservation rule below instead). For files that do carry them (AGENTS.md, and a pack's AGENTS.md when it has them):

  • The user's content lives between <!-- [CUSTOMIZE] ... --> markers
  • Upstream changes outside those markers should be taken
  • User content inside those markers should be preserved
  • If upstream added a new [CUSTOMIZE] section, include it
  • If upstream removed or moved a [CUSTOMIZE] section, surface it to the user — don't silently drop their content

3. Propose a merged version

Construct the merged file in /tmp/<file>-merged. Use your judgment:

  • Take upstream's structural changes (new sections, bug fixes, rewording)
  • Preserve user's content inside [CUSTOMIZE] blocks
  • If upstream and user both changed the same non-marked section, prefer upstream (structural) but note the conflict

For opencode.json: upstream owns everything except the mcp.servers block, which moraine sync writes from moraine.yaml and the enabled packs. Take upstream's changes outside that block and leave the local block alone. The user's server list lives in moraine.yaml, which is user-owned and is never merged. After the merge, run python3 scripts/moraine sync to regenerate the block.

4. Show the user the diff

diff <file> /tmp/<file>-merged

Present this clearly. Then ask, per file:

AGENTS.md has upstream changes. I've proposed a merge that preserves
your [CUSTOMIZE] sections. Options:
  1. Use my proposed merge (recommended)
  2. Take upstream version (discard your changes)
  3. Keep your version (skip upstream changes)
  4. Show me the raw diff

Wait for the user's choice per file. Apply it: copy the chosen version to the actual file path and git add it.

If the user chose "Show me the raw diff", print diff <file> <(git show upstream/main:<file>) and re-ask.

USER-OWNED files

For files in any USER-OWNED path (moraine.yaml, packs/local/, wiki/, memory/sessions/, artifacts/ except README.md and _TEMPLATE.md):

If upstream changed any of these, stop and surface to the user. This shouldn't happen in normal operation. Possible causes:

  • Template update added a new stub to wiki/ or memory/ — show user, ask if they want it
  • Mistake (upstream accidentally committed personal content) — flag it, don't apply

New files (added upstream)

If upstream added a new file in a SAFE directory (e.g., new skill, new script), just take it:

git checkout upstream/main -- <new-file>
git add <new-file>

If upstream added a new file in a USER-OWNED directory, surface it to the user and ask.

Verify the merge

After all files are staged:

1. Resync and dependencies

Upstream may have moved skills or changed a pack manifest, so relink first:

python3 scripts/moraine sync

If upstream changed scripts/setup or requirements.txt, reinstall the Python dependencies into the workspace venv:

bash scripts/setup --yes

2. OpenCode version check

If upstream changed .opencode-version:

INSTALLED=$(opencode --version 2>/dev/null || echo "none")
EXPECTED=$(cat .opencode-version)

If they don't match, tell the user: "Upstream updated OpenCode to $EXPECTED. You have $INSTALLED. Run bash scripts/setup to install the matching version."

3. Smoke test

Run the same checks as scripts/setup:

python3 scripts/workspace/session-index.py --help 2>/dev/null || echo "session-index broken"
python3 scripts/workspace/validate.py || echo "validate failed"
python3 scripts/workspace/health-check.py --quick || echo "health check failed"

If anything fails, stop and tell the user. Offer to abort: git reset --hard $BACKUP_BRANCH.

Commit

If smoke test passed (or user chose to proceed despite warnings):

UPSTREAM_SHA=$(git rev-parse --short upstream/main)
git commit -m "Sync with upstream ($UPSTREAM_SHA)

Auto-merged: <list of SAFE files>
Smart-merged: <list of PERSONALIZED files with user choices>
Skipped: <list of USER-OWNED files if any>

Backup branch: $BACKUP_BRANCH"

Report

After committing, print a clear summary:

✓ Synced with upstream (abc1234)

Auto-merged (safe files):
  scripts/setup
  .agents/skills/sync-upstream/SKILL.md
  ...

Smart-merged (personalized):
  AGENTS.md — preserved your [CUSTOMIZE] sections
  .opencode/opencode.json — kept your mcp.servers block (moraine sync rerun)

New files added:
  packs/<pack>/skills/new-skill/SKILL.md

Skipped (user-owned, no upstream changes):
  wiki/, memory/sessions/

Smoke test: all passed

Backup: git reset --hard $BACKUP_BRANCH if anything looks wrong

Failure modes

Merge went wrong mid-way

If something fails and you've already staged some changes:

  1. Tell the user what failed
  2. Offer to abort: git reset --hard $BACKUP_BRANCH (discards all staged changes)
  3. Or offer to commit what's been merged so far and let them clean up manually

User cancels

If the user says "stop", "cancel", or "abort" at any point:

git reset --hard $BACKUP_BRANCH
git checkout main  # or whatever branch they were on

Tell them: "Aborted. Nothing was changed. Backup branch is still there if you want to inspect."

Upstream has diverged significantly

If git diff HEAD..upstream/main --stat | tail -1 shows more than ~50 files changed, warn the user: "This is a large upstream sync ($N files). Consider reviewing [upstream changes](https://github.com/jamesctucker/moraine/compare/$(git rev-parse --short HEAD)...upstream/main) first. Proceed?"

For very large syncs, suggest doing it file-by-file across multiple sessions.

Notes

  • This skill runs destructive git operations only after explicit user approval (except git checkout upstream/main -- <safe-file> for SAFE files with no local changes, which is documented as auto-take behavior)
  • The backup branch is never deleted by this skill — the user can clean up old backups with git branch -D backup-pre-sync-* later
  • If the user has local commits between syncs, those are preserved in the backup branch
  • Merges normally happen on main, matching the "personal repo" mental model where the user works directly on main. If the user insists on syncing from a feature branch, the commit lands there — warn in the report.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.