Skip to content

feat: /dewey-publish — sweep all knowledge artifacts (learnings/compiled/knowledge) from every git state into one chore PR #132

Closed

Description

@jflowers

Summary

Add /dewey-publish — a slash command backed by a deterministic CLI core (dewey artifacts plan|sync) that sweeps every Dewey knowledge artifact (.uf/dewey/learnings/, .uf/dewey/compiled/, .uf/dewey/knowledge/) out of every git state it can be stranded in — working tree (untracked/ignored/staged), stashes (tracked and untracked parts), and unpushed commits on any local branch — into one chore PR against the remote default branch.

Non-negotiable property: non-destructive. No stash is popped, applied, or dropped; no working-tree file is moved or modified; the user's checkout is never touched.

Outcome (the goal — implementation may adapt)

An agent or human can run /dewey-publish at any time and know that:

  1. Every knowledge artifact that exists anywhere in this repository's git universe ends up preserved on the remote default branch.
  2. Nothing in the working tree or stash stack changed (verifiable: git status and git stash list identical before/after).
  3. The result is one reviewable chore PR whose body groups artifacts by tag.
  4. Re-running with nothing new produces an explicit "nothing to publish" result (idempotent).

If a better mechanism than the proposed CLI/worktree choreography below achieves these outcomes, use it — the outcomes are the contract.

Background — verified facts

  • Artifact layout: learnings at .uf/dewey/learnings/{tag}-{YYYYMMDDTHHMMSS}-{author}.md (identity = filename; YAML frontmatter: tag, category, created_at, identity, tier: draft, author), dual-written by the store_learning MCP tool (tools/learning.go:350). Compiled articles at .uf/dewey/compiled/{tag}.md (tier draft). Curated knowledge at the knowledge-store path (default .uf/dewey/knowledge/{store}/, tier curated).
  • Artifacts are currently invisible to git (the bare-dewey .gitignore bug, see companion issue). Consequences: plain git stash never captured them; they exist only as untracked/ignored working-tree files, inside stashes created with unusual flags, inside unpushed branch commits, or nowhere but the local disk. The sweep must cover all of those states regardless of the gitignore fix.
  • The running MCP server owns the store: exclusive syscall.Flock(LOCK_EX|LOCK_NB) on .uf/dewey/dewey.lock held for the server's lifetime (store/store.go:105-120). Every store-opening CLI command fails beside it. Therefore the sweep must not open the DB — it is pure git-subprocess work, which is also what makes it safe to run anytime.
  • A running server only notices merged artifacts after restart: reIngestLearnings runs at serve startup (main.go:1072). The command should say so (merge → pull → restart).
  • Isolation requirement: any temp checkout used for the chore branch must live outside the vault and outside any configured disk source path so the file watcher / indexer never observes churn. An OS-tempdir git worktree satisfies this.

Determinism governance (applies to implementation)

Per .opencode/uf/packs/determinism.md and the determinism-first skill: mechanical work (enumeration, dedup, hashing, git choreography, commit-message templating, output rendering) must live in an executable tool with tests (DE-001/DE-003), not in prose steps. Judgment products (gate approvals, conflict-resolution choices, PR-body composition) arrive as parameters from the command layer (DE-005). tasks.md must carry DE-007 seam-verification tasks (registration surfaces, documented output shapes, write→read round-trips).

Current implementation direction (adaptable)

dewey artifacts plan --json (new, DB-free)

Enumerate and dedup, emitting stable golden-testable JSON:

  • working-tree files under the three artifact dirs (including git-ignored ones)
  • stash contents: git stash list; per stash, git ls-tree -r stash@{N} -- <dirs> plus the untracked-parts commit stash@{N}^3 when present; content via git show stash@{N}:<path> — never pop/apply/drop
  • unpushed commits on any branch: git log --all --not --remotes filtered to pathspecs (added/modified)
  • dedup against the fetched remote base tree (git ls-tree -r <base> -- <dirs>) and across sources by identity filename
  • same-identity/different-content collision detection via sha256, surfaced for the human gate
  • detection of the bare-dewey gitignore bug (via git check-ignore), flagging the one-line fix for inclusion in the chore PR (skip if already fixed upstream)

Output shape (illustrative): {base, artifacts: [{identity, tag, dir, source_state, sha256}], conflicts: [{identity, variants: [...]}], gitignore_fix_needed, summary}.

dewey artifacts sync --plan <file>

  • create a temp git worktree under the OS tempdir from the fetched base; branch chore/dewey-artifacts-YYYYMMDD
  • write the planned files, apply the gitignore fix when flagged, commit with a tool-rendered Conventional Commit message (chore: ...), print worktree path + branch
  • refuse to proceed on unresolved conflicts (fail closed)
  • leave push/PR to the calling layer

/dewey-publish command (.opencode/commands/dewey-publish.md, added to slash_commands.go)

Thin judgment layer: fetch base (uf git_fetch plugin tool, raw git fetch fallback) → run plan → print the plan (visibility) → MANDATORY GATE (approve; resolve collisions by choosing among sha256-identified variants) → run sync → push (uf git_push, raw fallback) → PR via uf_finale_create_pr (gh fallback), body grouping identities by tag → clean up temp worktree → note the merge/pull/restart pickup path. Per the user's technology decision: prefer uf plugin tools for remote mutations when available, fall back to raw git/gh otherwise.

Acceptance criteria

  • Twice-test: two runs over an unchanged repo produce byte-identical plan JSON.
  • Fixture-repo tests cover all four stranded states: working tree, stash tracked part, stash ^3 untracked part, unpushed branch commit.
  • Tests assert zero mutation of stash stack and working tree across the full flow.
  • Collisions fail closed until resolved through the gate.
  • The chore PR contains only artifact files (+ optional one-line .gitignore fix).
  • The whole flow works while the Dewey MCP server is running (no store access anywhere in the path).
  • DE-007 seam tasks present in tasks.md; round-trip test: plan → sync → git show of artifacts in the temp worktree.
  • CI parity per AGENTS.md (build, vet, go test -race -count=1, golangci-lint, gaze thresholds); review-council APPROVE before the feature PR.

Constraints

  • Packaging decision: single OpenSpec change (opsx/ branch) together with the /dewey-distill issue (filed separately) and feat: /dewey-configure slash command to configure sources.yaml #122 — adjust packaging if scope demands, the outcomes are what matter.
  • All 37 inherited graphthulhu MCP tools unchanged; no CGO; pure-Go dependencies only.
  • dewey CLI gains a new command group; existing commands and outputs unchanged.

Out of scope (follow-ups)

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

Metadata

Metadata

Assignees

Labels

enhancementfeature

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions