This commit is contained in:
Timothy Jaeryang Baek committed 2026-07-15 15:31:27 -04:00
1 parent fbc33282e4
commit 0db561b6c7
9 files changed
+141 -11

No files matched your search

+4
View File
@@ -66,6 +66,10 @@ CHAT_COMPACT_TOKEN_THRESHOLD = int(os.environ.get("CHAT_COMPACT_TOKEN_THRESHOLD"
# Claude SDK stdout JSON buffer; chat/tool output caps apply later after parsing.
CLAUDE_CODE_MAX_BUFFER_SIZE = _env_int("CPTR_CLAUDE_CODE_MAX_BUFFER_SIZE", 128 * 1024 * 1024)
# ── Workspace storage ───────────────────────────────────────
WORKSPACE_AUTO_GITIGNORE_DOT_CPTR_ENV = os.environ.get("CPTR_AUTO_GITIGNORE_DOT_CPTR")
WORKSPACE_AUTO_GITIGNORE_DOT_CPTR = _env_bool("CPTR_AUTO_GITIGNORE_DOT_CPTR", "true")
# ── Execute timeout ─────────────────────────────────────────
# Default wait (seconds) for run_command / check_task when the caller
# doesn't pass an explicit wait value. None = return immediately.
+1 -1
View File
@@ -93,4 +93,4 @@
"tippy.js": "^6.3.7",
"xlsx": "^0.18.5"
}
}
}
+2 -2
View File
@@ -29,8 +29,8 @@
--app-fg: #525252;
--app-fg-muted: color-mix(in oklab, var(--app-fg) 62%, var(--app-bg));
--app-fg-subtle: color-mix(in oklab, var(--app-fg) 48%, var(--app-bg));
--app-border: color-mix(in oklab, var(--app-fg) 7%, transparent);
--app-divider: color-mix(in oklab, var(--app-fg) 5%, transparent);
--app-border: color-mix(in oklab, var(--app-fg) 5%, transparent);
--app-divider: color-mix(in oklab, var(--app-fg) 3.5%, transparent);
--app-hover: color-mix(in oklab, var(--app-fg) 6%, transparent);
--app-active: color-mix(in oklab, var(--app-fg) 7%, transparent);
--app-ui-font: var(--font-sans);
@@ -0,0 +1,69 @@
<script lang="ts">
import { onMount } from 'svelte';
import { toast } from 'svelte-sonner';
import { getAdminConfig, updateConfig } from '$lib/apis/admin';
import { t } from '$lib/i18n';
import Spinner from '$lib/components/common/Spinner.svelte';
import ToggleSwitch from '$lib/components/common/ToggleSwitch.svelte';
let loading = $state(true);
let saving = $state(false);
let autoGitignoreDotCptr = $state(true);
onMount(async () => {
try {
const config = await getAdminConfig();
autoGitignoreDotCptr = config['workspace.auto_gitignore_dot_cptr'] !== false;
} catch {
toast.error($t('admin.failedToLoadConfig'));
} finally {
loading = false;
}
});
async function save() {
saving = true;
try {
await updateConfig({ 'workspace.auto_gitignore_dot_cptr': autoGitignoreDotCptr });
toast.success($t('settings.saved'));
} catch {
toast.error($t('admin.failedToSave'));
} finally {
saving = false;
}
}
</script>
<div class="flex flex-col min-h-full">
<h2 class="text-sm font-medium text-gray-900 dark:text-white mb-4">{$t('admin.workspace')}</h2>
{#if loading}
<div class="flex justify-center py-8"><Spinner size={16} /></div>
{:else}
<div class="flex flex-col gap-2.5">
<label class="flex items-center justify-between cursor-pointer">
<span class="text-xs text-gray-600 dark:text-gray-400"
>{$t('admin.workspaceAutoGitignoreDotCptr')}</span
>
<ToggleSwitch
value={autoGitignoreDotCptr}
onchange={(value) => {
autoGitignoreDotCptr = value;
}}
disabled={saving}
/>
</label>
<p class="text-[0.6875rem] text-gray-400 dark:text-gray-600 -mt-1">
{$t('admin.workspaceAutoGitignoreDotCptrHint')}
</p>
</div>
<div class="mt-auto pt-6 flex justify-end">
<button
class="text-[0.8125rem] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100 disabled:opacity-50"
onclick={save}
disabled={saving}>{$t('settings.save')}</button
>
</div>
{/if}
</div>
@@ -21,6 +21,7 @@
import AdminWeb from './Admin/Web.svelte';
import ToolServers from './Admin/ToolServers.svelte';
import Subagents from './Admin/Subagents.svelte';
import Workspace from './Admin/Workspace.svelte';
import { session } from '$lib/session';
import { t } from '$lib/i18n';
@@ -43,7 +44,8 @@
| 'images'
| 'web'
| 'toolservers'
| 'subagents';
| 'subagents'
| 'workspace';
interface Props {
onclose: () => void;
@@ -71,6 +73,7 @@
'web',
'toolservers',
'subagents',
'workspace',
'memory',
'skills'
];
@@ -99,6 +102,7 @@
{ id: 'web', label: $t('admin.web'), icon: 'globe' },
{ id: 'toolservers', label: $t('admin.toolServers'), icon: 'plug' },
{ id: 'subagents', label: $t('admin.subagents'), icon: 'user' },
{ id: 'workspace', label: $t('admin.workspace'), icon: 'folder' },
{ id: 'memory', label: $t('settings.memory'), icon: 'brain' },
{ id: 'skills', label: 'Skills', icon: 'spark' }
]);
@@ -218,6 +222,8 @@
<ToolServers />
{:else if activeTab === 'subagents'}
<Subagents />
{:else if activeTab === 'workspace'}
<Workspace />
{/if}
</div>
</Modal>
@@ -274,6 +274,9 @@
"admin.minCharsPassword": "Min 6 characters",
"admin.connections": "Connections",
"admin.agents": "Agents",
"admin.workspace": "Workspace",
"admin.workspaceAutoGitignoreDotCptr": "Add .cptr to .gitignore",
"admin.workspaceAutoGitignoreDotCptrHint": "Keeps local chats, memory, caches, and generated assets out of git by default. Turn this off if you want to track .cptr and manage exclusions inside .cptr/.gitignore.",
"admin.agentsRefresh": "Refresh",
"admin.agentsAddProfile": "Add profile",
"admin.agentsDeleteProfile": "Delete",
+2 -2
View File
@@ -72,8 +72,8 @@ def _get_user(request: Request) -> str:
def _workspace_audio_cache_dir(workspace: str | None, kind: str) -> Path | None:
# Voice samples are project context, so they live under the workspace .cptr
# folder and move with the project. That keeps STT and TTS artifacts available
# for reuse, debugging, and the local data flywheel while ensure_cptr_gitignored
# keeps them out of git.
# for reuse, debugging, and the local data flywheel. By default,
# ensure_cptr_gitignored keeps them out of git.
if not workspace:
return None
ws = Path(workspace).expanduser().resolve()
+20 -5
View File
@@ -11,6 +11,7 @@ from typing import List, Optional
from fastapi import APIRouter, HTTPException, Request
from pydantic import BaseModel
from cptr.utils.json_parser import extract_json
from cptr.utils.git import (
GitError,
branches,
@@ -153,6 +154,23 @@ The summary must be imperative, under 72 characters, and have no trailing period
The description should be one short paragraph explaining the meaningful change. Do not invent details."""
def _parse_commit_message_response(text: str) -> tuple[str, str]:
message = extract_json(text)
summary = str(message.get("summary", "")).strip() if isinstance(message, dict) else ""
description = str(message.get("description", "")).strip() if isinstance(message, dict) else ""
if summary:
return summary.splitlines()[0][:72], description
lines = [
line.strip()
for line in text.strip().splitlines()
if line.strip() and not line.strip().startswith("```")
]
if not lines:
return "", ""
return lines[0][:72], "\n".join(lines[1:]).strip()
class CheckoutRequest(BaseModel):
root: str
branch: str
@@ -260,7 +278,6 @@ async def generate_commit_message(body: CommitMessageRequest, request: Request):
from cptr.utils.chat_task import _default_base_url
from cptr.utils.config import _get_jwt_secret
from cptr.utils.crypto import decrypt_key
from cptr.utils.json_parser import extract_json
from cptr.utils.model_targets import ApiModelTarget, resolve_model_target
from cptr.models import Config
@@ -285,12 +302,10 @@ async def generate_commit_message(body: CommitMessageRequest, request: Request):
)
except Exception as e:
raise HTTPException(status_code=502, detail="Could not generate a commit message") from e
message = extract_json(text)
summary = str(message.get("summary", "")).strip().splitlines()[0] if isinstance(message, dict) else ""
description = str(message.get("description", "")).strip() if isinstance(message, dict) else ""
summary, description = _parse_commit_message_response(text)
if not summary:
raise HTTPException(status_code=502, detail="Could not generate a commit message")
return {"summary": summary[:72], "description": description}
return {"summary": summary, "description": description}
@router.post("/checkout")
+33
View File
@@ -4,9 +4,30 @@ from __future__ import annotations
from pathlib import Path
from cptr import env
from cptr.utils.config import load_config
def auto_gitignore_cptr_enabled() -> bool:
if env.WORKSPACE_AUTO_GITIGNORE_DOT_CPTR_ENV is not None:
return env.WORKSPACE_AUTO_GITIGNORE_DOT_CPTR
config = load_config()
value = None
workspace = config.get("workspace", {})
if isinstance(workspace, dict):
value = workspace.get("auto_gitignore_dot_cptr")
app_config = config.get("app_config", {})
if isinstance(app_config, dict):
value = app_config.get("workspace.auto_gitignore_dot_cptr", value)
return _bool_config(value, default=True)
def ensure_cptr_gitignored(workspace: str | Path) -> None:
"""If workspace is a git repo, ensure .cptr is listed in .gitignore."""
if not auto_gitignore_cptr_enabled():
return
ws = Path(workspace)
if not (ws / ".git").exists():
return
@@ -26,3 +47,15 @@ def ensure_cptr_gitignored(workspace: str | Path) -> None:
gitignore.write_text(content, encoding="utf-8")
else:
gitignore.write_text(f"{entry}\n", encoding="utf-8")
def _bool_config(value: object, default: bool) -> bool:
if isinstance(value, bool):
return value
if isinstance(value, str):
normalized = value.strip().lower()
if normalized in {"true", "1", "yes", "on"}:
return True
if normalized in {"false", "0", "no", "off"}:
return False
return default