feat(ocm-cli): add --version flag, version display, and publish workflow

This commit is contained in:
Chris Scott committed 2026-05-23 21:42:07 -04:00
1 parent 18bdb16951
commit d59ba90b66
4 files changed
+156 -1

No files matched your search

+70
View File
@@ -0,0 +1,70 @@
name: Publish ocm-cli
on:
push:
branches: [main]
paths:
- 'ocm-cli/**'
workflow_dispatch:
permissions:
contents: read
id-token: write
jobs:
publish:
name: Build and publish @opencode-manager/ocm-cli
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.28.1
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Read package version
id: pkg
working-directory: ocm-cli
run: |
VERSION=$(node -p "require('./package.json').version")
NAME=$(node -p "require('./package.json').name")
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "name=${NAME}" >> $GITHUB_OUTPUT
- name: Check if version already published
id: check
run: |
if npm view "${{ steps.pkg.outputs.name }}@${{ steps.pkg.outputs.version }}" version >/dev/null 2>&1; then
echo "already_published=true" >> $GITHUB_OUTPUT
echo "Version ${{ steps.pkg.outputs.version }} already on npm; skipping publish."
else
echo "already_published=false" >> $GITHUB_OUTPUT
echo "Version ${{ steps.pkg.outputs.version }} not yet on npm; will publish."
fi
- name: Build
if: steps.check.outputs.already_published == 'false'
working-directory: ocm-cli
run: bun scripts/build.ts
- name: Publish to npm
if: steps.check.outputs.already_published == 'false'
working-directory: ocm-cli
run: pnpm publish --access public --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
+74
View File
@@ -0,0 +1,74 @@
# ocm-cli
OpenCode Manager CLI and plugin package.
`ocm` lets a local OpenCode TUI attach to repos hosted by OpenCode Manager. It
can also mirror a local git repo up to Manager or pull a Manager repo back down
to the local working tree.
## Install
```bash
pnpm add -g @opencode-manager/ocm-cli
```
The package exposes the `ocm` binary and an OpenCode plugin entrypoint. Global
installs link the binary through the package manager. Local workspace installs
also create a best-effort `~/.local/bin/ocm` symlink.
## Login
```bash
ocm login <manager-url> [token]
```
The token is stored in macOS Keychain under the `opencode-manager` service. CLI
state is stored at `~/.config/opencode-manager/state.json`.
If `[token]` is omitted, `ocm login` reads it from hidden TTY input or stdin.
## Commands
```bash
ocm
ocm status
ocm list
ocm use <repoId|name>
ocm push [--force] [--create] [--yes]
ocm pull [--force]
ocm logout
```
Running `ocm` with no command tries to match the current git repo's `origin`
against ready Manager repos. If one repo matches, it attaches OpenCode to that
Manager repo. If no repo matches, it falls back to the last selected repo, then
to local `opencode`.
`ocm use <repoId|name>` selects a Manager repo, remembers it as the last repo,
and attaches OpenCode to it.
`ocm push` uploads the current git repo to the matching Manager repo. Use
`--create` to create a Manager repo when no origin match exists, and `--yes` to
confirm creation in non-interactive shells.
`ocm pull` replaces the current working tree with the matching Manager repo. It
refuses to overwrite uncommitted local changes unless `--force` is passed.
## OpenCode plugin
The package default export is an OpenCode plugin entrypoint. Importing the
plugin performs a best-effort local `ocm` symlink install and then returns an
empty plugin object.
```ts
import ocm from '@opencode-manager/ocm-cli'
export default [ocm]
```
## Requirements
- `opencode` available on `PATH`
- `git` and `tar` available on `PATH`
- macOS `security` CLI for Keychain-backed token storage
- An OpenCode Manager URL and bearer token
+11
View File
@@ -7,6 +7,9 @@ import { mirrorUp, mirrorDown, prepareMirror } from '../src/mirror.js'
import type { RemoteRepoSummary } from '../src/mirror.js'
import { getBranchName } from '../src/local-repo.js'
import { resolveTarget } from '../src/resolve-target.js'
import packageJson from '../package.json' with { type: 'json' }
const VERSION = packageJson.version
const USAGE = `ocm - OpenCode Manager workspace launcher
@@ -21,6 +24,7 @@ Usage:
ocm use <repoId|name> Attach to a specific repo and remember it as last
ocm push [--force] [--create] [--yes] Mirror $PWD to the matching Manager repo (or create one)
ocm pull [--force] Mirror the matching Manager repo over $PWD
ocm --version Show the installed ocm version
ocm --help Show this help
`
@@ -155,9 +159,11 @@ async function cmdLogout(): Promise<void> {
async function cmdStatus(): Promise<void> {
const state = readState()
if (!state) {
info(`version: ${VERSION}`)
info('no state. run: ocm login <url>')
return
}
info(`version: ${VERSION}`)
info(`manager url: ${state.managerUrl}`)
info(`token in kc: ${getToken(state.managerUrl) ? 'yes' : 'no'}`)
if (state.lastRepoId !== undefined) {
@@ -377,6 +383,11 @@ async function main(): Promise<void> {
return
}
if (cmd === '--version' || cmd === '-v' || cmd === 'version') {
info(VERSION)
return
}
try {
switch (cmd) {
case undefined:
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@opencode-manager/ocm-cli",
"version": "0.1.0",
"version": "0.1.1",
"description": "OpenCode Manager CLI: attach a local OpenCode TUI to a Manager-hosted repo.",
"license": "MIT",
"repository": {