Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

docs: add GitHub Actions and PM2 documentation

Adam Eivyfd596d571c1e
diff --git a/docs/GITHUB_ACTIONS.md b/docs/GITHUB_ACTIONS.md
new file mode 100644
index 0000000000..995ca10d75
--- /dev/null
+++ b/docs/GITHUB_ACTIONS.md
@@ -0,0 +1,311 @@
+# GitHub Actions Pattern
+
+This document describes the recommended GitHub Actions workflow pattern for PortOS sub-projects.
+
+## Overview
+
+The pattern uses two workflows:
+1. **CI Workflow** (`ci.yml`) - Tests, linting, and auto version bumps on `dev`
+2. **Release Workflow** (`release.yml`) - Creates releases when merging to `main`
+
+## Branch Strategy
+
+| Branch | Purpose |
+|--------|---------|
+| `main` | Production releases only |
+| `dev` | Active development |
+
+## CI Workflow (`ci.yml`)
+
+### Trigger Configuration
+
+```yaml
+name: CI
+
+on:
+ pull_request:
+ branches: [main, dev]
+ push:
+ branches: [dev]
+
+permissions:
+ contents: write
+```
+
+### Jobs
+
+#### 1. Test Job
+
+Runs tests on PRs and pushes. Uses `[skip ci]` detection to avoid infinite loops from auto-commits.
+
+```yaml
+jobs:
+ test:
+ runs-on: ubuntu-latest
+ if: "!contains(github.event.head_commit.message, '[skip ci]')"
+
+ strategy:
+ matrix:
+ node-version: [20.x]
+
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Use Node.js ${{ matrix.node-version }}
+ uses: actions/setup-node@v4
+ with:
+ node-version: ${{ matrix.node-version }}
+ cache: 'npm'
+
+ - name: Install dependencies
+ run: npm ci
+ # For monorepos, install each workspace:
+ # run: npm run install:all
+
+ - name: Run tests
+ run: npm test
+
+ - name: Build
+ run: npm run build
+```
+
+#### 2. Lint Job
+
+Runs in parallel with tests for faster feedback.
+
+```yaml
+ lint:
+ runs-on: ubuntu-latest
+ if: "!contains(github.event.head_commit.message, '[skip ci]')"
+
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Use Node.js 20.x
+ uses: actions/setup-node@v4
+ with:
+ node-version: 20.x
+ cache: 'npm'
+
+ - name: Install dependencies
+ run: npm ci
+
+ - name: Check for syntax errors
+ run: node --check src/index.js
+```
+
+#### 3. Version Bump Job
+
+Auto-increments patch version after successful tests on `dev` branch.
+
+```yaml
+ bump-build:
+ runs-on: ubuntu-latest
+ needs: [test, lint]
+ # Only on push to dev, skip if already a version bump commit
+ if: github.event_name == 'push' && github.ref == 'refs/heads/dev' && !contains(github.event.head_commit.message, '[skip ci]')
+
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ token: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Configure git
+ run: |
+ git config user.name "github-actions[bot]"
+ git config user.email "github-actions[bot]@users.noreply.github.com"
+
+ - name: Bump patch version
+ run: |
+ CURRENT_VERSION=$(node -p "require('./package.json').version")
+
+ MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1)
+ MINOR=$(echo $CURRENT_VERSION | cut -d. -f2)
+ PATCH=$(echo $CURRENT_VERSION | cut -d. -f3)
+
+ NEW_PATCH=$((PATCH + 1))
+ NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
+
+ npm version $NEW_VERSION --no-git-tag-version
+
+ git add package.json package-lock.json
+ git commit -m "build: bump version to $NEW_VERSION [skip ci]"
+ git push
+```
+
+**Monorepo variant** - Update all package.json files:
+
+```yaml
+ - name: Bump patch version
+ run: |
+ CURRENT_VERSION=$(node -p "require('./package.json').version")
+
+ MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1)
+ MINOR=$(echo $CURRENT_VERSION | cut -d. -f2)
+ PATCH=$(echo $CURRENT_VERSION | cut -d. -f3)
+
+ NEW_PATCH=$((PATCH + 1))
+ NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
+
+ npm version $NEW_VERSION --no-git-tag-version
+ cd client && npm version $NEW_VERSION --no-git-tag-version && cd ..
+ cd server && npm version $NEW_VERSION --no-git-tag-version && cd ..
+
+ git add package.json package-lock.json client/package.json server/package.json
+ git commit -m "build: bump version to $NEW_VERSION [skip ci]"
+ git push
+```
+
+## Release Workflow (`release.yml`)
+
+### Trigger Configuration
+
+```yaml
+name: Release
+
+on:
+ push:
+ branches: [main]
+
+permissions:
+ contents: write
+```
+
+### Release Job
+
+Creates a GitHub release with changelog when code is merged to `main`.
+
+```yaml
+jobs:
+ release:
+ runs-on: ubuntu-latest
+ if: "!contains(github.event.head_commit.message, '[skip ci]')"
+
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+ token: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Use Node.js 20.x
+ uses: actions/setup-node@v4
+ with:
+ node-version: 20.x
+
+ - name: Configure git
+ run: |
+ git config user.name "github-actions[bot]"
+ git config user.email "github-actions[bot]@users.noreply.github.com"
+
+ - name: Get version from package.json
+ id: package-version
+ run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
+
+ - name: Check if tag exists
+ id: tag-check
+ run: |
+ if git rev-parse "v${{ steps.package-version.outputs.version }}" >/dev/null 2>&1; then
+ echo "exists=true" >> $GITHUB_OUTPUT
+ else
+ echo "exists=false" >> $GITHUB_OUTPUT
+ fi
+
+ - name: Generate changelog
+ id: changelog
+ if: steps.tag-check.outputs.exists == 'false'
+ run: |
+ PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || git rev-list --max-parents=0 HEAD)
+ CHANGELOG=$(git log $PREV_TAG..HEAD --pretty=format:"- %s" --no-merges | grep -v "\[skip ci\]" | head -50)
+
+ echo "changelog<<EOF" >> $GITHUB_OUTPUT
+ echo "$CHANGELOG" >> $GITHUB_OUTPUT
+ echo "EOF" >> $GITHUB_OUTPUT
+
+ - name: Create Release
+ if: steps.tag-check.outputs.exists == 'false'
+ uses: softprops/action-gh-release@v2
+ with:
+ tag_name: v${{ steps.package-version.outputs.version }}
+ name: v${{ steps.package-version.outputs.version }}
+ body: |
+ ## Changes
+
+ ${{ steps.changelog.outputs.changelog }}
+
+ ## Installation
+
+ ```bash
+ git clone https://github.com/YOUR_ORG/YOUR_REPO.git
+ cd YOUR_REPO
+ npm install
+ npm start
+ ```
+ draft: false
+ prerelease: false
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Prep dev branch for next release
+ if: steps.tag-check.outputs.exists == 'false'
+ run: |
+ CURRENT_VERSION=${{ steps.package-version.outputs.version }}
+
+ MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1)
+ MINOR=$(echo $CURRENT_VERSION | cut -d. -f2)
+
+ NEW_MINOR=$((MINOR + 1))
+ NEW_VERSION="$MAJOR.$NEW_MINOR.0"
+
+ git fetch origin dev
+ git checkout dev
+
+ npm version $NEW_VERSION --no-git-tag-version
+
+ git add package.json package-lock.json
+ git commit -m "build: prep v$NEW_VERSION for next release [skip ci]"
+ git push origin dev
+```
+
+## Key Patterns
+
+### Skip CI Marker
+
+Use `[skip ci]` in commit messages to prevent CI from running:
+- Auto-version bump commits include this automatically
+- Use manually for non-code changes (docs, configs)
+
+### Version Strategy
+
+- **Patch** (0.0.X): Auto-incremented on every successful push to `dev`
+- **Minor** (0.X.0): Auto-incremented when merging to `main` (release)
+- **Major** (X.0.0): Manually updated for breaking changes
+
+### Changelog Generation
+
+The release workflow auto-generates changelogs from commit messages between tags, excluding `[skip ci]` commits.
+
+### Git Configuration
+
+Always configure git identity in workflows that make commits:
+
+```yaml
+- name: Configure git
+ run: |
+ git config user.name "github-actions[bot]"
+ git config user.email "github-actions[bot]@users.noreply.github.com"
+```
+
+## Working with Auto-Commits
+
+Since CI auto-commits version bumps, always rebase before pushing:
+
+```bash
+git pull --rebase --autostash && git push
+```
+
+## Adapting for Your Project
+
+1. Copy `.github/workflows/ci.yml` and `.github/workflows/release.yml`
+2. Update the installation instructions in the release body
+3. For monorepos, add the additional package.json update steps
+4. Adjust test and build commands for your project structure
diff --git a/docs/PM2.md b/docs/PM2.md
new file mode 100644
index 0000000000..e3d4152fff
--- /dev/null
+++ b/docs/PM2.md
@@ -0,0 +1,316 @@
+# PM2 Configuration Pattern
+
+This document describes the recommended PM2 configuration pattern for PortOS sub-projects.
+
+## Overview
+
+PM2 is a process manager for Node.js applications. We use `ecosystem.config.cjs` files to define process configurations declaratively.
+
+## File Format
+
+Use CommonJS format (`.cjs`) for ecosystem files to ensure compatibility across all environments:
+
+```javascript
+module.exports = {
+ apps: [
+ // Process definitions go here
+ ]
+};
+```
+
+## Basic Process Definition
+
+```javascript
+module.exports = {
+ apps: [
+ {
+ name: 'my-app',
+ script: 'server/index.js',
+ cwd: __dirname,
+ interpreter: 'node',
+ ports: { api: 5570 },
+ env: {
+ NODE_ENV: 'development',
+ PORT: 5570,
+ HOST: '0.0.0.0'
+ },
+ watch: false,
+ max_memory_restart: '500M'
+ }
+ ]
+};
+```
+
+## Configuration Fields
+
+### Required Fields
+
+| Field | Description |
+|-------|-------------|
+| `name` | Unique process name (used by PM2 for identification) |
+| `script` | Path to the entry script |
+| `cwd` | Working directory (use `__dirname` for relative paths) |
+
+### Recommended Fields
+
+| Field | Description | Default |
+|-------|-------------|---------|
+| `interpreter` | Node interpreter path | `'node'` |
+| `ports` | Port allocation object (PortOS convention) | - |
+| `env` | Environment variables | `{}` |
+| `watch` | Enable file watching | `false` |
+| `max_memory_restart` | Restart if memory exceeds threshold | - |
+
+### Resilience Fields
+
+For services that should auto-recover from failures:
+
+```javascript
+{
+ autorestart: true,
+ max_restarts: 10,
+ min_uptime: '10s',
+ restart_delay: 5000
+}
+```
+
+| Field | Description |
+|-------|-------------|
+| `autorestart` | Restart on crash |
+| `max_restarts` | Maximum consecutive restarts before giving up |
+| `min_uptime` | Minimum uptime before considering "stable" |
+| `restart_delay` | Delay (ms) between restart attempts |
+
+## Port Allocation Convention
+
+Define all ports in a `ports` object for documentation and PortOS integration:
+
+```javascript
+{
+ name: 'my-app',
+ // PortOS convention: define all ports used by this process
+ ports: { api: 5570, health: 5571 },
+ env: {
+ PORT: 5570,
+ HEALTH_PORT: 5571
+ }
+}
+```
+
+### Common Port Labels
+
+- `api` - REST API server
+- `ui` - Web UI / frontend
+- `cdp` - Chrome DevTools Protocol
+- `health` - Health check endpoint
+- `ws` - WebSocket server
+
+See `PORTS.md` for the full port allocation guide.
+
+## Common Patterns
+
+### Server Process
+
+```javascript
+{
+ name: 'myapp-server',
+ script: 'server/index.js',
+ cwd: __dirname,
+ interpreter: 'node',
+ ports: { api: 5570 },
+ env: {
+ NODE_ENV: 'development',
+ PORT: 5570,
+ HOST: '0.0.0.0'
+ },
+ watch: false,
+ max_memory_restart: '500M'
+}
+```
+
+### Vite Dev Server (React/Vue UI)
+
+```javascript
+{
+ name: 'myapp-client',
+ script: 'node_modules/.bin/vite',
+ cwd: `${__dirname}/client`,
+ args: '--host 0.0.0.0 --port 5571',
+ ports: { ui: 5571 },
+ env: {
+ NODE_ENV: 'development'
+ },
+ watch: false
+}
+```
+
+### Background Daemon
+
+```javascript
+{
+ name: 'myapp-worker',
+ script: 'worker/index.js',
+ cwd: __dirname,
+ interpreter: 'node',
+ ports: {}, // No ports if internal-only
+ env: {
+ NODE_ENV: 'development'
+ },
+ watch: false,
+ autorestart: true,
+ max_restarts: 10,
+ min_uptime: '10s',
+ restart_delay: 5000
+}
+```
+
+### Multi-Port Service
+
+```javascript
+{
+ name: 'myapp-browser',
+ script: '.browser/server.js',
+ cwd: __dirname,
+ interpreter: 'node',
+ ports: { cdp: 5572, health: 5573 },
+ env: {
+ NODE_ENV: 'development',
+ CDP_PORT: 5572,
+ PORT: 5573
+ },
+ watch: false,
+ autorestart: true,
+ max_restarts: 10,
+ min_uptime: '10s',
+ restart_delay: 5000
+}
+```
+
+## PM2 Commands
+
+### Starting/Stopping
+
+```bash
+# Start all processes defined in ecosystem file
+pm2 start ecosystem.config.cjs
+
+# Restart all processes
+pm2 restart ecosystem.config.cjs
+
+# Stop all processes
+pm2 stop ecosystem.config.cjs
+```
+
+### Monitoring
+
+```bash
+# View process list
+pm2 list
+
+# View logs
+pm2 logs
+
+# View logs for specific process
+pm2 logs myapp-server
+```
+
+### Important Rules
+
+1. **Never use `pm2 kill` or `pm2 delete all`** - This affects all PM2 processes on the system, not just yours
+
+2. **Always use ecosystem file** for restart/stop operations:
+ ```bash
+ pm2 restart ecosystem.config.cjs # Correct
+ pm2 restart all # Dangerous - affects all apps
+ ```
+
+3. **Use `pm2 save`** after changes to persist the process list:
+ ```bash
+ pm2 start ecosystem.config.cjs
+ pm2 save
+ ```
+
+## Complete Example
+
+Here's a complete ecosystem file for a typical monorepo:
+
+```javascript
+module.exports = {
+ apps: [
+ {
+ name: 'myapp-server',
+ script: 'server/index.js',
+ cwd: __dirname,
+ interpreter: 'node',
+ ports: { api: 5570 },
+ env: {
+ NODE_ENV: 'development',
+ PORT: 5570,
+ HOST: '0.0.0.0'
+ },
+ watch: false,
+ max_memory_restart: '500M'
+ },
+ {
+ name: 'myapp-client',
+ script: 'node_modules/.bin/vite',
+ cwd: `${__dirname}/client`,
+ args: '--host 0.0.0.0 --port 5571',
+ ports: { ui: 5571 },
+ env: {
+ NODE_ENV: 'development'
+ },
+ watch: false
+ },
+ {
+ name: 'myapp-worker',
+ script: 'worker/index.js',
+ cwd: __dirname,
+ interpreter: 'node',
+ ports: {},
+ env: {
+ NODE_ENV: 'development'
+ },
+ watch: false,
+ autorestart: true,
+ max_restarts: 10,
+ min_uptime: '10s',
+ restart_delay: 5000
+ }
+ ]
+};
+```
+
+## Environment-Specific Configuration
+
+For different environments (dev/prod), use environment blocks:
+
+```javascript
+{
+ name: 'myapp-server',
+ script: 'server/index.js',
+ env: {
+ NODE_ENV: 'development',
+ PORT: 5570
+ },
+ env_production: {
+ NODE_ENV: 'production',
+ PORT: 5570
+ }
+}
+```
+
+Start with specific environment:
+```bash
+pm2 start ecosystem.config.cjs --env production
+```
+
+## Integration with PortOS
+
+When your app follows these patterns, PortOS can:
+- Display port allocations in the apps list
+- Track process health and memory usage
+- Provide one-click restart/stop controls
+- Show consolidated logs
+
+Register your ecosystem file with PortOS to enable management features.