Skip to content

Commit

Permalink
Enhanced Configuration Management and Submodule Handling (#58)
Browse files Browse the repository at this point in the history
- **Local Configuration:** Added `config.local.json` for
project-specific settings.
- **Submodule Enhancements:** Improved detection, handling, and syncing
processes for submodules.
- **CLI Refactor:** Introduced new commands (`auth`, `remote`, `push`)
to streamline project management.
- **Smart Syncing:** Implemented directory-aware syncing for efficient
operations.
- **Session Management:** Externalized session keys to enable
provider-specific configurations.
  • Loading branch information
jahwag authored Aug 28, 2024
1 parent a15b007 commit 480dba7
Show file tree
Hide file tree
Showing 40 changed files with 1,659 additions and 1,697 deletions.
7 changes: 7 additions & 0 deletions .claudesync/config.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"active_provider": "claude.ai",
"active_organization_id": "e731f9fc-edb4-420d-aa35-952e2ce77137",
"active_project_id": "726c9cf7-394f-43f7-aced-bfa64ad2e1fb",
"active_project_name": "ClaudeSync",
"default_sync_category": "all_files"
}
22 changes: 13 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "claudesync"
version = "0.5.3"
version = "0.5.4"
authors = [
{name = "Jahziah Wagner", email = "[email protected]"},
]
Expand All @@ -14,14 +14,18 @@ classifiers = [
"Operating System :: OS Independent",
]
dependencies = [
"click==8.1.7",
"click_completion==0.5.2",
"pathspec==0.12.1",
"pytest==8.3.2",
"python_crontab==3.2.0",
"setuptools==73.0.1",
"sseclient_py==1.8.0",
"tqdm==4.66.5",
"click>=8.1.7",
"click_completion>=0.5.2",
"pathspec>=0.12.1",
"pytest>=8.3.2",
"python_crontab>=3.2.0",
"setuptools>=73.0.1",
"sseclient_py>=1.8.0",
"tqdm>=4.66.5",
"pytest-cov>=5.0.0",
"claudesync>=0.5.4",
"crontab>=1.0.1",
"python-crontab>=3.2.0"
]
keywords = [
"sync",
Expand Down
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ python_crontab>=3.2.0
setuptools>=73.0.1
sseclient_py>=1.8.0
tqdm>=4.66.5
pytest-cov>=5.0.0
pytest-cov>=5.0.0
claudesync>=0.5.4
crontab>=1.0.1
python-crontab>=3.2.0
119 changes: 0 additions & 119 deletions src/claudesync/cli/api.py

This file was deleted.

57 changes: 57 additions & 0 deletions src/claudesync/cli/auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import click

from claudesync.provider_factory import get_provider
from ..exceptions import ProviderError
from ..utils import handle_errors


@click.group()
def auth():
"""Manage authentication."""
pass


@auth.command()
@click.option(
"--provider",
prompt="Choose provider",
type=click.Choice(["claude.ai"], case_sensitive=False),
default="claude.ai",
help="The provider to use for this project",
)
@click.pass_context
@handle_errors
def login(ctx, provider):
"""Authenticate with an AI provider."""
config = ctx.obj
provider_instance = get_provider(config, provider)

try:
session_key, expiry = provider_instance.login()
config.set_session_key(provider, session_key, expiry)
click.echo(
f"Successfully authenticated with {provider}. Session key stored globally."
)
except ProviderError as e:
click.echo(f"Authentication failed: {str(e)}")


@auth.command()
@click.pass_obj
def logout(config):
"""Log out from all AI providers."""
config.clear_all_session_keys()
click.echo("Logged out from all providers successfully.")


@auth.command()
@click.pass_obj
def ls(config):
"""List all authenticated providers."""
authenticated_providers = config.get_providers_with_session_keys()
if authenticated_providers:
click.echo("Authenticated providers:")
for provider in authenticated_providers:
click.echo(f" - {provider}")
else:
click.echo("No authenticated providers found.")
12 changes: 11 additions & 1 deletion src/claudesync/cli/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def add(config, name, description, patterns):
@click.argument("name")
@click.pass_obj
@handle_errors
def remove(config, name):
def rm(config, name):
"""Remove a file category."""
config.remove_file_category(name)
click.echo(f"File category '{name}' removed successfully.")
Expand Down Expand Up @@ -59,3 +59,13 @@ def ls(config):
click.echo("Patterns:")
for pattern in data["patterns"]:
click.echo(f" - {pattern}")


@category.command()
@click.argument("category", required=True)
@click.pass_obj
@handle_errors
def set_default(config, category):
"""Set the default category for synchronization."""
config.set_default_category(category)
click.echo(f"Default sync category set to: {category}")
28 changes: 14 additions & 14 deletions src/claudesync/cli/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def chat():
@chat.command()
@click.pass_obj
@handle_errors
def sync(config):
def pull(config):
"""Synchronize chats and their artifacts from the remote source."""
provider = validate_and_get_provider(config, require_project=True)
sync_chats(provider, config)
Expand Down Expand Up @@ -74,16 +74,16 @@ def delete_all_chats(provider, organization_id):
"""Delete all chats for the given organization."""
if click.confirm("Are you sure you want to delete all chats?"):
total_deleted = 0
with click.progressbar(length=100, label="Deleting chats") as bar:
while True:
chats = provider.get_chat_conversations(organization_id)
if not chats:
break
uuids_to_delete = [chat["uuid"] for chat in chats[:50]]
deleted, _ = delete_chats(provider, organization_id, uuids_to_delete)
total_deleted += deleted
bar.update(len(uuids_to_delete))
click.echo(f"Chat deletion complete. Total chats deleted: {total_deleted}")
with click.progressbar(length=100, label="Deleting chats") as bar:
while True:
chats = provider.get_chat_conversations(organization_id)
if not chats:
break
uuids_to_delete = [chat["uuid"] for chat in chats[:50]]
deleted, _ = delete_chats(provider, organization_id, uuids_to_delete)
total_deleted += deleted
bar.update(len(uuids_to_delete))
click.echo(f"Chat deletion complete. Total chats deleted: {total_deleted}")


def delete_single_chat(provider, organization_id):
Expand Down Expand Up @@ -145,8 +145,8 @@ def confirm_and_delete_chat(provider, organization_id, chat):
@click.option("--project", help="UUID of the project to associate the chat with")
@click.pass_obj
@handle_errors
def create(config, name, project):
"""Create a new chat conversation on the active provider."""
def init(config, name, project):
"""Initializes a new chat conversation on the active provider."""
provider = validate_and_get_provider(config)
organization_id = config.get("active_organization_id")
active_project_id = config.get("active_project_id")
Expand Down Expand Up @@ -186,7 +186,7 @@ def create(config, name, project):
@click.option("--timezone", default="UTC", help="Timezone for the message")
@click.pass_obj
@handle_errors
def send(config, message, chat, timezone):
def message(config, message, chat, timezone):
"""Send a message to a specified chat or create a new chat and send the message."""
provider = validate_and_get_provider(config)
organization_id = config.get("active_organization_id")
Expand Down
12 changes: 9 additions & 3 deletions src/claudesync/cli/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

import click

from .category import category
Expand All @@ -19,7 +21,7 @@ def config():
def set(config, key, value):
"""Set a configuration value."""
# Check if the key exists in the configuration
if key not in config.config:
if key not in config.global_config and key not in config.local_config:
raise ConfigurationError(f"Configuration property '{key}' does not exist.")

# Convert string 'true' and 'false' to boolean
Expand Down Expand Up @@ -59,8 +61,12 @@ def get(config, key):
@handle_errors
def ls(config):
"""List all configuration values."""
for key, value in config.config.items():
click.echo(f"{key}: {value}")
# Combine global and local configurations
combined_config = config.global_config.copy()
combined_config.update(config.local_config)

# Print the combined configuration as JSON
click.echo(json.dumps(combined_config, indent=2, sort_keys=True))


config.add_command(category)
29 changes: 29 additions & 0 deletions src/claudesync/cli/file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import click
from ..utils import handle_errors, validate_and_get_provider


@click.group()
def file():
"""Manage remote project files."""
pass


@file.command()
@click.pass_obj
@handle_errors
def ls(config):
"""List files in the active remote project."""
provider = validate_and_get_provider(config, require_project=True)
active_organization_id = config.get("active_organization_id")
active_project_id = config.get("active_project_id")
files = provider.list_files(active_organization_id, active_project_id)
if not files:
click.echo("No files found in the active project.")
else:
click.echo(
f"Files in project '{config.get('active_project_name')}' (ID: {active_project_id}):"
)
for file in files:
click.echo(
f" - {file['file_name']} (ID: {file['uuid']}, Created: {file['created_at']})"
)
Loading

0 comments on commit 480dba7

Please sign in to comment.