← Catalog

@agimon-ai/po-git

Git worktree sessions for Po: spawn an isolated worktree with its own session and manage it from the parent

Extension

Install

Install with PiG

pig install npm:@agimon-ai/po-git

Install with Pi

pi install npm:@agimon-ai/po-git
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

README

Written by the package's publisher, shown as published in version 0.0.0-alpha.197 (README.md). PiG does not review it.

@agimon-ai/po-git

Git worktree sessions for Po: spawn an isolated worktree with its own session and manage it from the parent.

This package is a composable Po subsystem. Select it through the native distribution configuration.

Requirements

  • Node.js 24 or newer
  • A Po native server host

Install

Add @agimon-ai/po-git to a selected layer in .po/presets.yaml, then run po sync. Native metadata selects its server and browser plugins; there is no standalone Pi entry.

Use

Use the browser worktree controls or an agent session. In code mode, worktrees returns structured records; call discover({ namespace: 'worktrees' }) for the installed signatures. Without code mode, use run_worktree. The worktree guide covers ownership, message delivery and when to refuse cleanup.

New-session dialog

In the web cockpit, po-git replaces the new-session dialog for a git workspace. It offers three choices:

  • Existing branch: a worktree session on a local branch, or on a remote-only branch (a local tracking branch is created). Branches already checked out elsewhere are disabled.
  • New branch: a worktree session on a new branch from a base, preselected to the repository's default branch.
  • No branch: a plain session in the workspace folder.

Worktree sessions opened here start at the top level of the session rail, with no parent. A workspace that is not a git checkout offers the plain session only. For remote devices, creating a worktree session needs the same passkey step-up as any new session.

Sparse checkouts

To offer partial checkouts, add a sparse block to .po/worktree.yaml. Without a sparse policy or profile, existing Git and Rift worktrees need no changes.

sparse:
  profilePattern: profiles/{profile}.json
  baseFolders: [.po, docs]
  excludeFolders: [vendor]

Commit profiles/web.json containing, for example, { "includeFolders": ["apps/web"] }. Po reads profiles from Git at the selected ref, not from uncommitted files. The web checkout includes apps/web and the base folders. full is reserved for a complete checkout. Paths are repository-relative; exclusions limit the cone, not access to the Git object store.

Before the first sparse create, explicitly enable per-worktree Git config in the main repository. With the sparo binary from @agimon-ai/po-sparo, run sparo --policy policy.json init --repo ., where policy.json contains the three fields of the sparse block as a JSON object. This backs up shared Git config before changing it. Po does not run it for you.

metadata.git.sparseProfile sets the workspace checkout profile; metadata.git.extraFolders adds folders. Older workspaces can keep metadata.sparo.profile and extraFolders until they switch. Po uses metadata.sparo only if metadata.git is absent. The launcher's selection.profile chooses the session profile, not its files.

Plugins can inject the workspace service po/git-engine. Its contract and portable factory come from the MIT utility @agimon-ai/po-sparo; operations take an explicit policy, admitted environment and cancellation signal.

Worktree setup

A new worktree has no node_modules or builds. For an ordinary Git or Rift checkout, put the commands that prepare it in .po/worktree.yaml at the repository root:

setup:
  - pnpm install --frozen-lockfile
  - pnpm build

For an engine-managed checkout (a named sparse profile or full), po-git runs sparo install . with the validated policy before the configured commands. Omit the example's pnpm install in that case. Without setup, neither install nor setup runs. Workflow launches skip this runner and own their preparation.

Setup runs in the child's worktree-setup runner, with a wake on exit. setupStage: started confirms the runner accepted the command, not that the build passed. For failed or unconfirmed, inspect the child and runner logs before deciding what to do. The checkout stays in place, even if Runner is missing. Do not spawn it again to retry setup. A malformed configuration is refused before any checkout is created.

Isolated repository workflows

Use worktrees.startWorkflow({ key, attemptId, inputs }) to launch a repository workflow in its own checkout. The worktree guide covers selecting a definition, retrying an attempt and checking its admission. The workflow gets the base remote, branch and commit plus its working branch as PO_GIT_BASE_REMOTE, PO_GIT_BASE_BRANCH, PO_GIT_BASE_SHA and PO_GIT_BRANCH. The corresponding SPARO_* names remain available for existing workflows.

Import an existing Sparo registry

This is a one-time operator action, not startup behavior. On the same host as the checkouts, stop the old po-sparo provider, keep both providers stopped and back up the sparo and git directories under the effective Po home. Do not move checkout directories. Use the public importSparoWorktrees export once per repository, with the repository's absolute root, the admitted home directory and the same explicit PO_HOME if it was overridden.

For a local Node operator, the following adapter uses an absolute, trusted Git executable and the supplied string-valued environment, not the operator shell's credentials. Pass sourceProviderStopped: true only after stopping the provider; the import cannot stop it for you.

import { execFileSync } from 'node:child_process';

import { createNodePlatform } from '@agimon-ai/po-core/nodePlatform';
import { importSparoWorktrees } from '@agimon-ai/po-git';

async function importStoppedRepository({
  repositoryRoot,
  homeDirectory,
  environment,
  gitExecutable,
  sourceProviderStopped,
}) {
  const git = (cwd, ...args) =>
    execFileSync(gitExecutable, ['-C', cwd, ...args], {
      env: environment,
      encoding: 'utf8',
      timeout: 30_000,
    });
  return importSparoWorktrees({
    repositoryRoot,
    homeDirectory,
    environment,
    sourceProviderStopped,
    fs: createNodePlatform({ homeDirectory }).env(repositoryRoot),
    git: {
      async listWorktreePaths(cwd) {
        return git(cwd, 'worktree', 'list', '--porcelain', '-z')
          .split('\0')
          .filter((field) => field.startsWith('worktree '))
          .map((field) => field.slice('worktree '.length));
      },
      async currentBranch(cwd) {
        return git(cwd, 'symbolic-ref', '--quiet', '--short', 'HEAD').trimEnd();
      },
    },
  });
}

Check status, imported, duplicates, source and destination before enabling po-git alone. already-imported means the completion marker exists; a rerun does not resurrect closed checkouts. source-absent imports nothing. A collision, malformed registry, wrong branch or unverifiable checkout (including Rift) refuses the import. Reconcile the evidence rather than forcing it. The old registry, worktree files and per-checkout engine state stay in place. If either provider has written since the backup, do not restore it over newer records.

Package behavior

Review this session's changes

The # git group in the activity dock shows the focused checkout's branch and +added -removed, followed by its worktrees. Regular and worktree sessions use the same diff row, even when they have no child worktrees. The row opens review (g d); the group heading opens worktrees (g w). The counts measure this session's checkout against its base, the way a pull request counts it: every commit since the branch left its base, plus staged, unstaged and untracked work. The base is the worktree's recorded base when the session owns one, then the remote's default branch (origin/HEAD, origin/main, origin/master), then the branch's upstream; with none of those only uncommitted work counts. The count refreshes after every tool call and settled turn; nothing polls.

The lane opens the review tab: changed files grouped by folder on the left, every diff stacked on the right. Select lines, or click a line number, to write a comment under that line; a comment on a removed line points at the old file. Comments queue on the tab, and send review hands them to the agent as one message, queued behind a running turn rather than dropped.

Pull, push and rebase

The review tab's header runs them by hand, one at a time per session:

  • pull fetches, then rebases local commits onto the upstream.
  • rebase fetches the base's remote, then rebases onto the base.
  • push sets the upstream on a first push. A push the remote rejects after a rebase asks first, then forces with --force-with-lease --force-if-includes, which git refuses if the remote holds commits this branch never fetched and integrated.

Pull and rebase refuse uncommitted changes. A rebase that stops on conflicts stays paused and lists the files, with ask agent to resolve and abort rebase.

Remote auth, per workspace

Settings, then repository, then git remote, sets how one workspace's sessions reach the remote when you pull, push or rebase from the cockpit: this machine's own git (the default), an SSH key path (blank uses your ssh config and ssh-agent), or an HTTPS username and token for one host. Worktree sessions use their workspace's setup.

The setup lives outside every repository in ~/.po/git/credentials.json (folder 0700, file 0600). The token is write-only: the page shows only that one is saved. It goes into the environment of one git fetch or git push at a time, only for the host it was entered for, with git's credential helper list emptied first so the macOS keychain never stores it. The agent's own git commands never see these credentials. Saving from a remote device needs passkey step-up. An unknown SSH host is refused: trust it once with ssh -T git@<host> in a terminal.

Help

The session registers codemode-how-to-git as a skill. The guide ships under src/prompts, indexed by llms.txt; it is not bundled into dist.

Development

pnpm exec nx run-many -t lint typecheck build test -p @agimon-ai/po-git

Maintained by Agimon.

License

Functional Source License 1.1, MIT Future License (FSL-1.1-MIT): free for any purpose except a Competing Use; each version converts to MIT two years after release. See LICENSE.