diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 8631974..9c47e45 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -5,6 +5,10 @@ on: branches: [main] workflow_dispatch: +concurrency: + group: docker-${{ github.ref }} + cancel-in-progress: false + env: IMAGE: ghcr.io/${{ github.repository }} @@ -14,6 +18,7 @@ permissions: jobs: detect-version-change: + if: github.ref == 'refs/heads/release' runs-on: ubuntu-latest outputs: version_changed: ${{ steps.check.outputs.changed }} @@ -58,9 +63,8 @@ jobs: echo "No version change detected" fi - build-and-push: - needs: detect-version-change - if: needs.detect-version-change.outputs.version_changed == 'true' + build-and-push-dev: + if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest steps: - name: Checkout @@ -76,18 +80,55 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract metadata (tags, labels) + - name: Extract metadata (dev tags, labels) id: meta uses: docker/metadata-action@v5 with: images: ${{ env.IMAGE }} tags: | - type=raw,value=latest - type=raw,value=${{ needs.detect-version-change.outputs.version }} - type=semver,pattern={{major}}.{{minor}},value=v${{ needs.detect-version-change.outputs.version }} - type=sha,prefix= + type=raw,value=dev + type=sha,prefix=dev- - - name: Build and push + - name: Build and push dev image + uses: docker/build-push-action@v6 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + build-and-push-release: + needs: detect-version-change + if: github.ref == 'refs/heads/release' && needs.detect-version-change.outputs.version_changed == 'true' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (release tags, labels) + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.IMAGE }} + tags: | + type=raw,value=latest + type=raw,value=${{ needs.detect-version-change.outputs.version }} + type=semver,pattern={{major}}.{{minor}},value=v${{ needs.detect-version-change.outputs.version }} + + - name: Build and push release image uses: docker/build-push-action@v6 with: context: . diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml new file mode 100644 index 0000000..f9db253 --- /dev/null +++ b/.github/workflows/pypi.yml @@ -0,0 +1,114 @@ +name: Publish to PyPI + +on: + pull_request: + types: [closed] + branches: [release] + +permissions: + contents: read + +jobs: + detect-version-change: + if: github.event.pull_request.merged == true && github.event.pull_request.head.ref == 'main' + runs-on: ubuntu-latest + outputs: + version_changed: ${{ steps.check.outputs.changed }} + version: ${{ steps.check.outputs.version }} + steps: + - name: Checkout current commit + uses: actions/checkout@v4 + with: + fetch-depth: 2 # need parent to diff against + + - name: Check for version bump + id: check + run: | + # Extract version from current commit + CURRENT=$(python3 -c " + import re, pathlib + text = pathlib.Path('pyproject.toml').read_text() + m = re.search(r'^version\s*=\s*\"([^\"]+)\"', text, re.M) + print(m.group(1)) + ") + + # Extract version from previous commit + git show HEAD~1:pyproject.toml > /tmp/prev_pyproject.toml 2>/dev/null || true + if [ -f /tmp/prev_pyproject.toml ]; then + PREVIOUS=$(python3 -c " + import re, pathlib + text = pathlib.Path('/tmp/prev_pyproject.toml').read_text() + m = re.search(r'^version\s*=\s*\"([^\"]+)\"', text, re.M) + print(m.group(1) if m else '') + ") + else + PREVIOUS="" + fi + + echo "current=$CURRENT" + echo "previous=$PREVIOUS" + + if [ "$CURRENT" != "$PREVIOUS" ] && [ -n "$CURRENT" ]; then + echo "changed=true" >> "$GITHUB_OUTPUT" + echo "version=$CURRENT" >> "$GITHUB_OUTPUT" + echo "Version changed: $PREVIOUS -> $CURRENT" + else + echo "changed=false" >> "$GITHUB_OUTPUT" + echo "No version change detected" + fi + + build: + needs: detect-version-change + if: needs.detect-version-change.outputs.version_changed == 'true' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "22" + cache: npm + cache-dependency-path: cptr/frontend/package-lock.json + + - name: Build frontend + working-directory: cptr/frontend + run: | + npm ci + npm run build + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install build tools + run: pip install hatchling build + + - name: Build package + run: python -m build + + - name: Upload dist artifacts + uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/ + + publish: + needs: [detect-version-change, build] + runs-on: ubuntu-latest + environment: pypi # GitHub environment for deployment protection + permissions: + id-token: write # required for trusted publishing (OIDC) + steps: + - name: Download dist artifacts + uses: actions/download-artifact@v4 + with: + name: dist + path: dist/ + + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + # No API token needed - uses OIDC trusted publishing. + # Configure at: https://pypi.org/manage/project/cptr/settings/publishing/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a9a306b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,104 @@ +# ───────────────────────────────────────────────────────────────────────────── +# Release — Create GitHub release from CHANGELOG, trigger Docker builds +# Runs only when main is merged into the release branch and pyproject.toml +# version changes. +# ───────────────────────────────────────────────────────────────────────────── +name: Release + +on: + pull_request: + types: [closed] + branches: [release] + +concurrency: + group: release-${{ github.event.pull_request.base.ref || github.ref }} + cancel-in-progress: false + +jobs: + # ── Detect version bump in pyproject.toml ───────────────────────────────── + detect-version-change: + if: github.event.pull_request.merged == true && github.event.pull_request.head.ref == 'main' + runs-on: ubuntu-latest + outputs: + version_changed: ${{ steps.check.outputs.changed }} + version: ${{ steps.check.outputs.version }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - name: Check for version bump + id: check + run: | + CURRENT=$(python3 -c " + import re, pathlib + text = pathlib.Path('pyproject.toml').read_text() + m = re.search(r'^version\s*=\s*\"([^\"]+)\"', text, re.M) + print(m.group(1)) + ") + + git show HEAD~1:pyproject.toml > /tmp/prev_pyproject.toml 2>/dev/null || true + if [ -f /tmp/prev_pyproject.toml ]; then + PREVIOUS=$(python3 -c " + import re, pathlib + text = pathlib.Path('/tmp/prev_pyproject.toml').read_text() + m = re.search(r'^version\s*=\s*\"([^\"]+)\"', text, re.M) + print(m.group(1) if m else '') + ") + else + PREVIOUS="" + fi + + echo "current=$CURRENT" + echo "previous=$PREVIOUS" + + if [ "$CURRENT" != "$PREVIOUS" ] && [ -n "$CURRENT" ]; then + echo "changed=true" >> "$GITHUB_OUTPUT" + echo "version=$CURRENT" >> "$GITHUB_OUTPUT" + echo "Version changed: $PREVIOUS -> $CURRENT" + else + echo "changed=false" >> "$GITHUB_OUTPUT" + echo "No version change detected" + fi + + # ── Create release and trigger downstream workflows ────────────────────── + publish: + needs: detect-version-change + if: needs.detect-version-change.outputs.version_changed == 'true' + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: write + actions: write + steps: + - uses: actions/checkout@v4 + + - name: Extract release notes from CHANGELOG + run: | + VER="${{ needs.detect-version-change.outputs.version }}" + awk "/^## \[${VER}\]/{found=1; next} /^## \[/{if(found) exit} found{print}" \ + CHANGELOG.md > /tmp/release-notes.md + + - name: Publish GitHub release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + if gh release view "v${{ needs.detect-version-change.outputs.version }}" &>/dev/null; then + echo "Release v${{ needs.detect-version-change.outputs.version }} already exists — skipping creation" + else + gh release create "v${{ needs.detect-version-change.outputs.version }}" \ + --title "v${{ needs.detect-version-change.outputs.version }}" \ + --notes-file /tmp/release-notes.md + fi + + - name: Trigger Docker build + uses: actions/github-script@v7 + with: + script: | + github.rest.actions.createWorkflowDispatch({ + owner: context.repo.owner, + repo: context.repo.repo, + workflow_id: 'docker.yml', + ref: 'release', + }) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f58d93..00c7e42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,15 +5,25 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [0.0.1] - 2026-06-05 +## [0.1.0] - 2026-06-06 ### Added - 🚀 **Initial release.** First public version of cptr: your computer, from anywhere. Code, manage, and control your machine from the web. - 🖥️ **Terminal emulator.** Full PTY-backed terminal accessible from the browser with support for macOS and Linux. -- 💬 **AI chat interface.** Built-in chat panel with multi-provider LLM support (OpenAI, Anthropic, Ollama, and OpenAI-compatible endpoints), tool calling, and streaming responses. -- 🔧 **Tool system.** Extensible tool framework enabling AI agents to interact with the local filesystem, run commands, search the web, and read URLs. -- 📁 **File browser.** Web-based file explorer with directory navigation, file viewing, and management capabilities. +- 💬 **AI chat.** Built-in chat panel with multi-provider LLM support (OpenAI, Anthropic, Ollama, and OpenAI-compatible endpoints), model selector, tool calling, and streaming responses. +- 🔧 **Tool system.** Extensible tool framework enabling AI agents to interact with the local filesystem, run commands, search the web (Brave, DuckDuckGo, Exa, Tavily), and read URLs. Streaming JSON parser for improved tool-calling reliability. +- 📎 **File mentions.** Type `@` in the chat input to mention files with an inline suggestion popup, giving the AI context about your codebase. +- 🔄 **Queued messages.** Queue follow-up messages while the AI is responding — they'll be sent automatically when the current response completes. +- ✏️ **Output editing.** Review and edit AI-generated file changes before applying them. +- 📁 **File browser.** Web-based file explorer with directory navigation, file viewing, file icons by extension, and management capabilities. +- ⌨️ **Keyboard shortcuts.** Customizable keybinding system with a dedicated settings panel, including support for new-tab, quick-open, and other common actions. +- 📐 **Resizable sidebar.** Drag-to-resize sidebar with persistent width and smooth panel resize handles. +- 🔍 **Quick open.** Cmd+K modal with keyboard pill hints for fast file and command navigation. +- 🌐 **Proxy middleware.** Reverse-proxy system for forwarding local ports with automatic port detection and notification. +- 📁 **Workspace management.** Manage multiple project directories from a single instance. +- 📊 **Chat history.** Persistent chat list with automatic title generation, scrolling, and pagination. - 🔐 **Authentication.** Username/password authentication with JWT-based session management. +- 🎨 **Admin settings.** Settings UI for managing AI connections and app configuration. - 🐳 **Docker support.** Multi-stage Dockerfile and GitHub Actions workflow for building and publishing to GHCR. - 📦 **PyPI packaging.** Hatchling-based build with frontend assets bundled into the wheel, published via trusted OIDC publishing. \ No newline at end of file diff --git a/cptr/__init__.py b/cptr/__init__.py index d89833c..b22e6cf 100644 --- a/cptr/__init__.py +++ b/cptr/__init__.py @@ -1 +1 @@ -"""cptr - your computer, from anywhere.""" +"""Your computer, from anywhere.""" diff --git a/cptr/app.py b/cptr/app.py index 727fc19..c4b06db 100644 --- a/cptr/app.py +++ b/cptr/app.py @@ -41,7 +41,7 @@ async def startup(): async def auth_middleware(request: Request, call_next): path = request.url.path # Skip auth for: auth endpoints, health, static assets, HTML pages - if path.startswith("/api/auth") or path == "/api/health" or path == "/api/config" or path == "/manifest.json": + if path.startswith("/api/auth") or path == "/api/health" or path == "/api/config" or path == "/api/changelog" or path == "/manifest.json": return await call_next(request) if path.startswith("/_app/") or not path.startswith("/api/"): return await call_next(request) @@ -175,6 +175,13 @@ async def health(): return {"status": "ok", "uptime_seconds": int(time.time() - START_TIME), "pid": os.getpid()} +@app.get("/api/changelog") +async def get_changelog(): + """Return parsed CHANGELOG.md as structured JSON (max 5 versions).""" + from cptr.utils.changelog import CHANGELOG + return {key: CHANGELOG[key] for idx, key in enumerate(CHANGELOG) if idx < 5} + + # PWA manifest (backend-driven so each instance has its own identity) @app.get("/manifest.json") async def pwa_manifest(): diff --git a/cptr/cli.py b/cptr/cli.py index c79a392..3065a53 100644 --- a/cptr/cli.py +++ b/cptr/cli.py @@ -4,7 +4,7 @@ import uvicorn @click.group() def cli(): - """cptr - your computer, from anywhere.""" + """Your computer, from anywhere.""" pass diff --git a/cptr/frontend/package.json b/cptr/frontend/package.json index 528262c..d5596c6 100644 --- a/cptr/frontend/package.json +++ b/cptr/frontend/package.json @@ -1,7 +1,7 @@ { "name": "frontend", "private": true, - "version": "0.0.1", + "version": "0.1.0", "type": "module", "scripts": { "dev": "vite dev", diff --git a/cptr/frontend/src/lib/components/ChangelogModal.svelte b/cptr/frontend/src/lib/components/ChangelogModal.svelte new file mode 100644 index 0000000..9941ce8 --- /dev/null +++ b/cptr/frontend/src/lib/components/ChangelogModal.svelte @@ -0,0 +1,145 @@ + + +{#if $showChangelog} + +
+
+

What's New

+ {#if selectedData} + {@const [ver, data] = selectedData} +

v{ver} · {formatDate(data.date)}

+ {/if} +
+ + +
+ + {#if versions.length > 1} +
+ {#each versions as [ver], i (ver)} + + {/each} +
+ {/if} + +
+ {#if selectedData} + {@const [_ver, data] = selectedData} +
+ {#each Object.entries(data).filter(([key]) => key !== 'date') as [section, items]} + {#if Array.isArray(items) && items.length > 0} +
+

{section}

+
    + {#each items as entry} +
  • + +
    + {#if entry.title} + {entry.title} + {#if entry.content} + {entry.content} + {/if} + {:else} + {entry.content || entry.raw} + {/if} +
    +
  • + {/each} +
+
+ {/if} + {/each} +
+ {:else if error} +
+

Couldn't load release notes.

+ +
+ {:else} +
+
+ Loading release notes... +
+ {/if} +
+ +
+ +
+
+{/if} diff --git a/cptr/frontend/src/lib/components/Settings/About.svelte b/cptr/frontend/src/lib/components/Settings/About.svelte index 04e3af2..a00beb1 100644 --- a/cptr/frontend/src/lib/components/Settings/About.svelte +++ b/cptr/frontend/src/lib/components/Settings/About.svelte @@ -1,17 +1,6 @@

@@ -20,12 +9,18 @@
- cptrcptr - {#if appVersion} - v{appVersion} showChangelog.set(true)} + class="text-[11px] text-gray-400 dark:text-gray-600 hover:text-gray-500 dark:hover:text-gray-400 font-mono hover:underline cursor-pointer" + >v{$appVersion} {/if}
diff --git a/cptr/frontend/src/lib/components/Sidebar.svelte b/cptr/frontend/src/lib/components/Sidebar.svelte index 700fcc4..f314a0a 100644 --- a/cptr/frontend/src/lib/components/Sidebar.svelte +++ b/cptr/frontend/src/lib/components/Sidebar.svelte @@ -8,6 +8,8 @@ reorderWorkspaces, sidebarOpen, sidebarWidth, + appVersion, + showChangelog, } from '$lib/stores'; import Sortable from 'sortablejs'; import Icon from './Icon.svelte'; @@ -29,7 +31,7 @@ let showAdmin = $state(false); let wsMenuPath = $state(null); let wsMenuAnchor = $state(null); - let appVersion = $state(''); + let menuButtonEl: HTMLButtonElement | undefined = $state(); let wsListEl: HTMLDivElement | undefined = $state(); let sortable: Sortable | null = null; @@ -118,9 +120,6 @@ } onMount(() => { - getWelcome() - .then(d => { appVersion = d.version || ''; }) - .catch(() => {}); // Enable drag-reorder on non-touch devices if (wsListEl && !isTouchDevice()) { @@ -218,7 +217,7 @@ {/if}
- +
{/if}
diff --git a/cptr/frontend/src/lib/components/chat/DictateButton.svelte b/cptr/frontend/src/lib/components/chat/DictateButton.svelte index 5732d69..8573017 100644 --- a/cptr/frontend/src/lib/components/chat/DictateButton.svelte +++ b/cptr/frontend/src/lib/components/chat/DictateButton.svelte @@ -54,7 +54,7 @@ type="button" class="flex items-center justify-center rounded-full p-1 transition-colors duration-100 {recording - ? 'text-red-500 dark:text-red-400 bg-red-50 dark:bg-red-500/10' + ? 'text-gray-400 dark:text-gray-500 bg-gray-50 dark:bg-white/5' : 'text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/5'}" onclick={toggle} > diff --git a/cptr/frontend/src/lib/stores.ts b/cptr/frontend/src/lib/stores.ts index 79674c0..33c8c4f 100644 --- a/cptr/frontend/src/lib/stores.ts +++ b/cptr/frontend/src/lib/stores.ts @@ -73,6 +73,7 @@ export interface UserPreferences { locale: string; workspaceOrder?: string[]; // ordered paths for sidebar drag-reorder keybindings?: Record; // user-customised keyboard shortcuts + version?: string; // last seen app version for changelog } export type Theme = 'dark' | 'light' | 'system'; @@ -120,6 +121,9 @@ export const sidebarOpen = writable(typeof window !== 'undefined' ? window.inner export const sidebarWidth = writable(220); export const theme = writable('dark'); export const toolApprovalMode = writable('auto'); +export const appVersion = writable(''); +export const lastSeenVersion = writable(''); +export const showChangelog = writable(false); /** @deprecated Use toolApprovalMode */ export const autoApproveTools = { subscribe: toolApprovalMode.subscribe, @@ -264,6 +268,7 @@ function persistPreferences(): void { locale: i18next.language, workspaceOrder: get(workspaceOrder), keybindings: get(keybindings), + version: get(lastSeenVersion), }; savePreferences(prefs as unknown as Record).catch(() => {}); }, 300); @@ -280,6 +285,7 @@ function subscribeForPersistence() { toolApprovalMode.subscribe(() => { if (get(stateLoaded)) persistPreferences(); }); workspaceOrder.subscribe(() => { if (get(stateLoaded)) persistPreferences(); }); keybindings.subscribe(() => { if (get(stateLoaded)) persistPreferences(); }); + lastSeenVersion.subscribe(() => { if (get(stateLoaded)) persistPreferences(); }); i18next.on('languageChanged', () => { if (get(stateLoaded)) persistPreferences(); }); } @@ -301,6 +307,7 @@ export async function loadPreferences(): Promise { if (prefs.locale) changeLocale(prefs.locale as string); if (Array.isArray(prefs.workspaceOrder)) workspaceOrder.set(prefs.workspaceOrder as string[]); if (prefs.keybindings) loadKeybindings(prefs.keybindings as Record); + if (prefs.version) lastSeenVersion.set(prefs.version as string); } catch { // First run, no preferences yet } diff --git a/cptr/frontend/src/routes/+layout.svelte b/cptr/frontend/src/routes/+layout.svelte index 87c6fc8..faade90 100644 --- a/cptr/frontend/src/routes/+layout.svelte +++ b/cptr/frontend/src/routes/+layout.svelte @@ -10,12 +10,13 @@ import QuickOpen from '$lib/components/QuickOpen.svelte'; import SettingsModal from '$lib/components/SettingsModal.svelte'; import AuthScreen from '$lib/components/AuthScreen.svelte'; + import ChangelogModal from '$lib/components/ChangelogModal.svelte'; import { Toaster } from 'svelte-sonner'; - import { activeTab, currentWorkspace, stateLoaded, initState, gitReviewOpen, isGitRepo, splitActive, splitCurrentTab, closeGroup } from '$lib/stores'; + import { activeTab, currentWorkspace, stateLoaded, initState, gitReviewOpen, isGitRepo, splitActive, splitCurrentTab, closeGroup, appVersion, lastSeenVersion, showChangelog } from '$lib/stores'; import { matchKeybinding, executeAction } from '$lib/stores/keybindings'; import { systemEvents } from '$lib/stores/systemEvents.svelte'; import { socketStore } from '$lib/stores/socket.svelte'; - import { setSession } from '$lib/session'; + import { setSession, clearSession } from '$lib/session'; import { getSession, getConfig } from '$lib/apis/auth'; import { getGitStatus } from '$lib/apis/git'; import { t } from '$lib/i18n'; @@ -73,6 +74,23 @@ let startupToken = $state(''); + $effect(() => { + if ($stateLoaded && $appVersion) { + const currentVer = $appVersion; + const lastSeen = $lastSeenVersion; + if (lastSeen !== currentVer) { + if (!lastSeen) { + // First-time load: initialize the last seen version to the current version so we don't pop up immediately + lastSeenVersion.set(currentVer); + } else { + // Update: record this version as seen before showing the changelog so it doesn't reopen repeatedly. + lastSeenVersion.set(currentVer); + showChangelog.set(true); + } + } + } + }); + async function checkAuth() { try { const params = new URLSearchParams(window.location.search); @@ -87,6 +105,10 @@ const auth = await getSession(); + getConfig().then(cfg => { + appVersion.set(cfg.version); + }).catch(() => {}); + if (auth.authenticated) { setSession({ user_id: auth.user_id!, @@ -107,6 +129,7 @@ } catch { authState = 'authenticated'; initState(); + refreshChatState(); } } @@ -231,6 +254,7 @@ {#if showSettings} showSettings = false} /> {/if} + {:else}
diff --git a/cptr/frontend/src/routes/+page.svelte b/cptr/frontend/src/routes/+page.svelte index b90402c..5bbd42c 100644 --- a/cptr/frontend/src/routes/+page.svelte +++ b/cptr/frontend/src/routes/+page.svelte @@ -1,7 +1,7 @@