codasift 0.1.1__cp312-cp312-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codasift/__init__.py +4 -0
- codasift/core/__init__.py +3 -0
- codasift/core/ai_client.cp312-win_amd64.pyd +0 -0
- codasift/core/auth_cli.cp312-win_amd64.pyd +0 -0
- codasift/core/classifier.cp312-win_amd64.pyd +0 -0
- codasift/core/config_cli.cp312-win_amd64.pyd +0 -0
- codasift/core/config_manager.cp312-win_amd64.pyd +0 -0
- codasift/core/constants.cp312-win_amd64.pyd +0 -0
- codasift/core/diff_extractor.cp312-win_amd64.pyd +0 -0
- codasift/core/exporter.cp312-win_amd64.pyd +0 -0
- codasift/core/gemini_client.cp312-win_amd64.pyd +0 -0
- codasift/core/licensing.cp312-win_amd64.pyd +0 -0
- codasift/core/scanner.cp312-win_amd64.pyd +0 -0
- codasift/core/self_healing.cp312-win_amd64.pyd +0 -0
- codasift/core/sync_cli.cp312-win_amd64.pyd +0 -0
- codasift/core/terminal_utils.cp312-win_amd64.pyd +0 -0
- codasift/core/watcher.cp312-win_amd64.pyd +0 -0
- codasift/languages/__init__.py +42 -0
- codasift/languages/base.cp312-win_amd64.pyd +0 -0
- codasift/languages/python.cp312-win_amd64.pyd +0 -0
- codasift/main.py +924 -0
- codasift-0.1.1.dist-info/METADATA +15 -0
- codasift-0.1.1.dist-info/RECORD +26 -0
- codasift-0.1.1.dist-info/WHEEL +5 -0
- codasift-0.1.1.dist-info/entry_points.txt +2 -0
- codasift-0.1.1.dist-info/top_level.txt +1 -0
codasift/__init__.py
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from codasift.languages.base import BaseLanguage
|
|
2
|
+
from codasift.languages.python import PythonLanguage
|
|
3
|
+
|
|
4
|
+
# Central registry of language plugins — add new language instances here
|
|
5
|
+
REGISTERED_LANGUAGES: list[BaseLanguage] = [
|
|
6
|
+
PythonLanguage(),
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_supported_languages() -> list[BaseLanguage]:
|
|
11
|
+
"""Returns the list of all registered language plugins."""
|
|
12
|
+
return list(REGISTERED_LANGUAGES)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def detect_language(project_path: str) -> BaseLanguage | None:
|
|
16
|
+
"""Returns the first registered language plugin that matches the project."""
|
|
17
|
+
for language in REGISTERED_LANGUAGES:
|
|
18
|
+
if language.detect(project_path):
|
|
19
|
+
return language
|
|
20
|
+
return None
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_language_for_file(file_path: str) -> BaseLanguage | None:
|
|
24
|
+
"""Returns the language plugin responsible for a given file path based on extension."""
|
|
25
|
+
for language in REGISTERED_LANGUAGES:
|
|
26
|
+
if language.is_supported_file(file_path):
|
|
27
|
+
return language
|
|
28
|
+
return None
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def get_supported_language_names() -> list[str]:
|
|
32
|
+
"""Returns the names of all currently registered languages."""
|
|
33
|
+
return [lang.name for lang in REGISTERED_LANGUAGES]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def get_supported_extensions() -> list[str]:
|
|
37
|
+
"""Returns all file extensions handled across all registered languages."""
|
|
38
|
+
exts: list[str] = []
|
|
39
|
+
for lang in REGISTERED_LANGUAGES:
|
|
40
|
+
exts.extend(getattr(lang, "file_extensions", []))
|
|
41
|
+
return exts
|
|
42
|
+
|
|
Binary file
|
|
Binary file
|
codasift/main.py
ADDED
|
@@ -0,0 +1,924 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
from typing import Optional, Dict, Any, List
|
|
4
|
+
import typer
|
|
5
|
+
from codasift.core.terminal_utils import enable_safe_terminal_output
|
|
6
|
+
|
|
7
|
+
enable_safe_terminal_output()
|
|
8
|
+
from codasift.core.scanner import scan
|
|
9
|
+
from codasift.core.exporter import export as run_export
|
|
10
|
+
from codasift.core.licensing import (
|
|
11
|
+
ensure_project_limit_allows,
|
|
12
|
+
has_pro_license,
|
|
13
|
+
LicenseLimitError,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
from codasift import __version__
|
|
17
|
+
from codasift.core.constants import get_api_url, get_frontend_url
|
|
18
|
+
|
|
19
|
+
app = typer.Typer(help="Codasift — Real-time AST code context layer for AI coding assistants.")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _check_and_display_terms_notice() -> None:
|
|
23
|
+
"""
|
|
24
|
+
Displays a non-intrusive first-run shrink-wrap acceptance notice and records acknowledgment.
|
|
25
|
+
Ensures users installing directly via pip/package managers receive contractual notice.
|
|
26
|
+
"""
|
|
27
|
+
try:
|
|
28
|
+
from codasift.core.config_cli import get_global_state, save_global_state
|
|
29
|
+
state = get_global_state()
|
|
30
|
+
current_terms_ver = "2026.1"
|
|
31
|
+
if state.get("accepted_terms_version") != current_terms_ver:
|
|
32
|
+
typer.secho(
|
|
33
|
+
"[Codasift] By using this software, you agree to our Terms of Service "
|
|
34
|
+
f"({get_frontend_url()}/terms) and Privacy Policy ({get_frontend_url()}/privacy). "
|
|
35
|
+
"If you do not agree, you must discontinue use immediately.",
|
|
36
|
+
fg=typer.colors.CYAN,
|
|
37
|
+
dim=True,
|
|
38
|
+
err=True,
|
|
39
|
+
)
|
|
40
|
+
state["accepted_terms_version"] = current_terms_ver
|
|
41
|
+
save_global_state(state)
|
|
42
|
+
except Exception:
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def version_callback(value: bool) -> None:
|
|
47
|
+
if value:
|
|
48
|
+
typer.echo(f"codasift {__version__}")
|
|
49
|
+
raise typer.Exit()
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@app.callback()
|
|
53
|
+
def main_callback(version: Optional[bool] = typer.Option(None, "--version", "-v", help="Show version and exit.",
|
|
54
|
+
callback=version_callback, is_eager=True,)) -> None:
|
|
55
|
+
"""Codasift CLI global callback."""
|
|
56
|
+
_check_and_display_terms_notice()
|
|
57
|
+
try:
|
|
58
|
+
from codasift.core.licensing import flush_pending_cloud_deactivations
|
|
59
|
+
flush_pending_cloud_deactivations()
|
|
60
|
+
except Exception:
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _check_limits_and_exit_if_failed(project_path: str) -> None:
|
|
65
|
+
try:
|
|
66
|
+
ensure_project_limit_allows(project_path)
|
|
67
|
+
except LicenseLimitError as e:
|
|
68
|
+
typer.echo(err=True)
|
|
69
|
+
typer.secho("[Warning] Free Tier Limit Reached", fg=typer.colors.YELLOW, bold=True, err=True)
|
|
70
|
+
|
|
71
|
+
typer.secho("You are trying to run Codasift in a new project: ", nl=False, err=True)
|
|
72
|
+
typer.secho(e.current_project, fg=typer.colors.CYAN, bold=True, err=True)
|
|
73
|
+
|
|
74
|
+
typer.secho("Currently active project: ", nl=False, err=True)
|
|
75
|
+
typer.secho(e.active_project, fg=typer.colors.WHITE, dim=True, err=True)
|
|
76
|
+
|
|
77
|
+
typer.echo(err=True)
|
|
78
|
+
typer.secho("Please purchase Codasift Local Pro ($20 one-time) to unlock unlimited projects:", fg=typer.colors.GREEN, err=True)
|
|
79
|
+
typer.secho(f"{get_frontend_url()}/pricing", fg=typer.colors.CYAN, underline=True, bold=True, err=True)
|
|
80
|
+
|
|
81
|
+
typer.echo(err=True)
|
|
82
|
+
typer.secho("Or activate your license key:", fg=typer.colors.GREEN, err=True)
|
|
83
|
+
typer.secho("codasift activate <KEY>", fg=typer.colors.CYAN, bold=True, err=True)
|
|
84
|
+
typer.echo(err=True)
|
|
85
|
+
raise typer.Exit(code=1)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _format_clean_error(e: Exception, fallback: str = "An unexpected error occurred.") -> str:
|
|
89
|
+
"""Format an exception into a clean user message, suppressing internal traceback leakage."""
|
|
90
|
+
msg = str(e).strip()
|
|
91
|
+
if not msg or "Traceback (most recent call last)" in msg or "File \"" in msg:
|
|
92
|
+
return fallback
|
|
93
|
+
return msg
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@app.command()
|
|
98
|
+
def init(
|
|
99
|
+
path: str = typer.Argument(default=".", help="Path to the project folder to scan."),
|
|
100
|
+
output: Optional[str] = typer.Option(None, "--output", "-o", help="Output file path (default: codasift_context.md)."),
|
|
101
|
+
compact: bool = typer.Option(False, "--compact", help="Generate high-density compact context file optimized for LLM token windows."),
|
|
102
|
+
):
|
|
103
|
+
"""
|
|
104
|
+
Scan a project folder and generate a context file.
|
|
105
|
+
"""
|
|
106
|
+
import os
|
|
107
|
+
import sys
|
|
108
|
+
from codasift.core.exporter import resolve_context_output_path
|
|
109
|
+
from codasift.core.config_cli import get_project_output_path, save_project_output_path
|
|
110
|
+
project_path = os.path.abspath(path or ".")
|
|
111
|
+
|
|
112
|
+
# Enforce local active project limits
|
|
113
|
+
_check_limits_and_exit_if_failed(project_path)
|
|
114
|
+
|
|
115
|
+
# Resolve output path non-destructively with preference persistence
|
|
116
|
+
is_explicit_override = bool(output)
|
|
117
|
+
if not output:
|
|
118
|
+
from codasift.core.config_cli import has_saved_project_output_path
|
|
119
|
+
if has_saved_project_output_path(project_path):
|
|
120
|
+
# Workspace already configured: use last saved md file directly without prompting
|
|
121
|
+
saved_output = get_project_output_path(project_path)
|
|
122
|
+
output = os.path.join(project_path, saved_output) if not os.path.isabs(saved_output) else saved_output
|
|
123
|
+
else:
|
|
124
|
+
# First time in unconfigured workspace: check if default file exists
|
|
125
|
+
default_target = get_project_output_path(project_path)
|
|
126
|
+
target_candidate = os.path.join(project_path, default_target)
|
|
127
|
+
if os.path.exists(target_candidate):
|
|
128
|
+
is_interactive = (
|
|
129
|
+
sys.stdin.isatty()
|
|
130
|
+
or "click" in getattr(type(sys.stdin), "__module__", "")
|
|
131
|
+
or os.environ.get("PYTEST_CURRENT_TEST") is not None
|
|
132
|
+
)
|
|
133
|
+
if is_interactive:
|
|
134
|
+
typer.secho(f"\n[NOTICE] Existing context file '{default_target}' detected.", fg=typer.colors.YELLOW, bold=True)
|
|
135
|
+
overwrite = typer.confirm(f"Do you want to overwrite '{default_target}'?", default=True)
|
|
136
|
+
if overwrite:
|
|
137
|
+
output = target_candidate
|
|
138
|
+
else:
|
|
139
|
+
resolved_output, was_renamed = resolve_context_output_path(project_path, None, default_filename=default_target)
|
|
140
|
+
output = resolved_output
|
|
141
|
+
typer.secho(f"Preserving existing file and saving as: {os.path.basename(output)}", fg=typer.colors.CYAN)
|
|
142
|
+
else:
|
|
143
|
+
resolved_output, was_renamed = resolve_context_output_path(project_path, None, default_filename=default_target)
|
|
144
|
+
output = resolved_output
|
|
145
|
+
if was_renamed:
|
|
146
|
+
typer.secho(f"\n[NOTICE] Existing '{default_target}' detected. Preserving it and saving as: {os.path.basename(resolved_output)}", fg=typer.colors.YELLOW, bold=True)
|
|
147
|
+
typer.secho(f" (Hint: Use -o {default_target} or --output <path> to overwrite or specify a custom destination)", fg=typer.colors.CYAN, dim=True)
|
|
148
|
+
else:
|
|
149
|
+
output = target_candidate
|
|
150
|
+
else:
|
|
151
|
+
resolved_output, was_renamed = resolve_context_output_path(project_path, output, default_filename="codasift_context.md")
|
|
152
|
+
output = resolved_output
|
|
153
|
+
|
|
154
|
+
# Persist resolved output preference into .codasift/config.json
|
|
155
|
+
save_project_output_path(project_path, output)
|
|
156
|
+
if is_explicit_override:
|
|
157
|
+
typer.secho(f"📌 Output target set to: {os.path.basename(output)}", fg=typer.colors.CYAN)
|
|
158
|
+
typer.secho(f" (Saved in .codasift/config.json for future runs unless overridden again)", fg=typer.colors.CYAN, dim=True)
|
|
159
|
+
|
|
160
|
+
typer.secho(f"Scanning project at: {project_path}", fg=typer.colors.CYAN)
|
|
161
|
+
|
|
162
|
+
description = typer.prompt(
|
|
163
|
+
typer.style("Briefly describe your project (press Enter to skip)", fg=typer.colors.CYAN),
|
|
164
|
+
default="",
|
|
165
|
+
show_default=False
|
|
166
|
+
)
|
|
167
|
+
description = description.strip() or "No description provided."
|
|
168
|
+
|
|
169
|
+
if not output.endswith(".md"):
|
|
170
|
+
typer.secho("\n[ERROR] Output file must be a .md file.", fg=typer.colors.RED, bold=True, err=True)
|
|
171
|
+
raise typer.Exit(code=1)
|
|
172
|
+
|
|
173
|
+
try:
|
|
174
|
+
typer.secho("Analysing project...", fg=typer.colors.CYAN)
|
|
175
|
+
result = scan(project_path, description=description)
|
|
176
|
+
|
|
177
|
+
typer.secho("Generating context file...", fg=typer.colors.CYAN)
|
|
178
|
+
output_path = run_export(result, output_path=output, format_type="md", compact=compact)
|
|
179
|
+
|
|
180
|
+
typer.secho("\n" + "=" * 56, fg=typer.colors.GREEN, bold=True)
|
|
181
|
+
typer.secho(" [OK] Context File Generated Successfully! ✨", fg=typer.colors.GREEN, bold=True)
|
|
182
|
+
typer.secho("=" * 56, fg=typer.colors.GREEN, bold=True)
|
|
183
|
+
typer.secho(f" Target File : {output_path}", fg=typer.colors.WHITE, bold=True)
|
|
184
|
+
typer.secho(f" Project : {result.get('project_name', 'Unnamed')}", fg=typer.colors.CYAN)
|
|
185
|
+
typer.secho(f" Language : {result.get('stack', {}).get('language', 'Unknown')}", fg=typer.colors.CYAN)
|
|
186
|
+
typer.secho(f" Functions : {len(result.get('functions', []))} AST symbols detected", fg=typer.colors.CYAN)
|
|
187
|
+
typer.secho("-" * 56, fg=typer.colors.BLACK, dim=True)
|
|
188
|
+
try:
|
|
189
|
+
from codasift.core.auth_cli import load_credentials
|
|
190
|
+
creds = load_credentials()
|
|
191
|
+
except Exception:
|
|
192
|
+
creds = None
|
|
193
|
+
|
|
194
|
+
if creds and creds.get("access_token"):
|
|
195
|
+
user_label = creds.get("email") or creds.get("user_id") or "Active"
|
|
196
|
+
typer.secho(f" 👤 Account : Linked ({user_label})", fg=typer.colors.CYAN)
|
|
197
|
+
else:
|
|
198
|
+
typer.secho(" 💡 Tip: Run `codasift login` to link this terminal to your", fg=typer.colors.YELLOW)
|
|
199
|
+
typer.secho(" web dashboard & manage machine slots.", fg=typer.colors.YELLOW)
|
|
200
|
+
typer.secho("=" * 56 + "\n", fg=typer.colors.GREEN, bold=True)
|
|
201
|
+
|
|
202
|
+
except RuntimeError as e:
|
|
203
|
+
err_text = _format_clean_error(e)
|
|
204
|
+
typer.secho(f"\n[ERROR] {err_text}", fg=typer.colors.RED, bold=True, err=True)
|
|
205
|
+
|
|
206
|
+
if "exceeds max" in err_text.lower() or any(keyword in err_text.lower() for keyword in ("max single file limit", "max total size", "max file limit", "max file size")):
|
|
207
|
+
import sys
|
|
208
|
+
from codasift.core.config_cli import get_project_config_path, scaffold_project_config
|
|
209
|
+
cfg_path = get_project_config_path(project_path)
|
|
210
|
+
typer.echo(err=True)
|
|
211
|
+
typer.secho("💡 Recovery Options:", fg=typer.colors.CYAN, bold=True, err=True)
|
|
212
|
+
typer.secho(" 1. Add large files or heavy directories to .codasiftignore in your project root.", fg=typer.colors.WHITE, err=True)
|
|
213
|
+
typer.secho(f" 2. Increase project size limits in: {cfg_path}", fg=typer.colors.WHITE, err=True)
|
|
214
|
+
typer.secho(" 3. Or run direct limit commands:", fg=typer.colors.WHITE, err=True)
|
|
215
|
+
typer.secho(" - codasift config set max_total_size 200 (Project total in MB)", fg=typer.colors.CYAN, err=True)
|
|
216
|
+
typer.secho(" - codasift config set max_file_size 1500 (Single file in KB)", fg=typer.colors.CYAN, err=True)
|
|
217
|
+
typer.secho(" - codasift config set max_files 25000 (Max file count)", fg=typer.colors.CYAN, err=True)
|
|
218
|
+
|
|
219
|
+
if sys.stdin.isatty() and not os.path.exists(cfg_path):
|
|
220
|
+
typer.echo(err=True)
|
|
221
|
+
if typer.confirm("Would you like to initialize .codasift/config.json with custom limits now?", default=True):
|
|
222
|
+
scaffold_project_config(project_path, force=True, custom_limits={"max_total_size_mb": 200, "max_file_size_kb": 2000})
|
|
223
|
+
typer.secho(f"\n[OK] Created {cfg_path} with 200MB limit.", fg=typer.colors.GREEN, bold=True)
|
|
224
|
+
typer.secho("Please re-run `codasift init` to scan with updated limits.\n", fg=typer.colors.CYAN, bold=True)
|
|
225
|
+
raise typer.Exit(code=1)
|
|
226
|
+
|
|
227
|
+
except Exception as e:
|
|
228
|
+
clean_msg = _format_clean_error(e, fallback="An unexpected error occurred during context generation.")
|
|
229
|
+
typer.secho(f"\n[ERROR] {clean_msg}", fg=typer.colors.RED, bold=True, err=True)
|
|
230
|
+
raise typer.Exit(code=1)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
@app.command()
|
|
236
|
+
def demo(
|
|
237
|
+
path: str = typer.Option("./codasift-demo", "--path", "-p", hidden=True, help="Directory where demo sandbox will be created."),
|
|
238
|
+
force: bool = typer.Option(False, "--force", "-f", help="Overwrite demo directory if it already exists.")
|
|
239
|
+
):
|
|
240
|
+
"""
|
|
241
|
+
Scaffold a sandbox demo project and run an instant first scan (<30s Time-to-Value).
|
|
242
|
+
Always scaffolds strictly into the 'codasift-demo' sandbox folder by default.
|
|
243
|
+
"""
|
|
244
|
+
import os
|
|
245
|
+
import shutil
|
|
246
|
+
|
|
247
|
+
demo_dir = os.path.abspath(path or "codasift-demo")
|
|
248
|
+
dir_name = os.path.basename(demo_dir)
|
|
249
|
+
if os.path.exists(demo_dir):
|
|
250
|
+
if not force and sys.stdin.isatty():
|
|
251
|
+
confirm = typer.confirm(f"Directory '{dir_name}' already exists. Overwrite with fresh demo files?", default=True)
|
|
252
|
+
if not confirm:
|
|
253
|
+
typer.secho("Demo setup cancelled.", fg=typer.colors.YELLOW)
|
|
254
|
+
raise typer.Exit(code=0)
|
|
255
|
+
shutil.rmtree(demo_dir, ignore_errors=True)
|
|
256
|
+
|
|
257
|
+
os.makedirs(os.path.join(demo_dir, "src"), exist_ok=True)
|
|
258
|
+
|
|
259
|
+
# Generate cryptographic machine-bound demo marker
|
|
260
|
+
from codasift.core.licensing import create_demo_marker
|
|
261
|
+
create_demo_marker(demo_dir)
|
|
262
|
+
|
|
263
|
+
# 1. Sample auth service (multi-branch functions with decorators & type hints)
|
|
264
|
+
auth_service_code = '''"""
|
|
265
|
+
Sample Authentication Service for Codasift Demo.
|
|
266
|
+
Demonstrates AST function extraction, dependency signatures, and type annotations.
|
|
267
|
+
"""
|
|
268
|
+
from typing import Optional, Dict, Any
|
|
269
|
+
from functools import wraps
|
|
270
|
+
|
|
271
|
+
def rate_limited(limit_per_minute: int = 60):
|
|
272
|
+
"""Decorator to simulate rate-limiting middleware."""
|
|
273
|
+
def decorator(fn):
|
|
274
|
+
@wraps(fn)
|
|
275
|
+
def wrapper(*args, **kwargs):
|
|
276
|
+
return fn(*args, **kwargs)
|
|
277
|
+
return wrapper
|
|
278
|
+
return decorator
|
|
279
|
+
|
|
280
|
+
class AuthService:
|
|
281
|
+
def __init__(self, token_secret: str = "demo-secret"):
|
|
282
|
+
self.secret = token_secret
|
|
283
|
+
self.sessions: Dict[str, Dict[str, Any]] = {}
|
|
284
|
+
|
|
285
|
+
@rate_limited(limit_per_minute=120)
|
|
286
|
+
def authenticate_user(self, username: str, password_hash: str) -> Optional[Dict[str, Any]]:
|
|
287
|
+
"""Verify user credentials and establish session context."""
|
|
288
|
+
if not username or not password_hash:
|
|
289
|
+
return None
|
|
290
|
+
session = {"user": username, "role": "developer", "tier": "pro"}
|
|
291
|
+
self.sessions[username] = session
|
|
292
|
+
return session
|
|
293
|
+
|
|
294
|
+
def revoke_session(self, username: str) -> bool:
|
|
295
|
+
"""Invalidate active developer session."""
|
|
296
|
+
return self.sessions.pop(username, None) is not None
|
|
297
|
+
'''
|
|
298
|
+
with open(os.path.join(demo_dir, "src", "auth_service.py"), "w", encoding="utf-8") as f:
|
|
299
|
+
f.write(auth_service_code.strip() + "\n")
|
|
300
|
+
|
|
301
|
+
# 2. Sample data pipeline (async stream processor)
|
|
302
|
+
data_pipeline_code = '''"""
|
|
303
|
+
Async Data Pipeline Simulation for Codasift Demo.
|
|
304
|
+
Demonstrates asynchronous generator parsing, error classification, and stream flow.
|
|
305
|
+
"""
|
|
306
|
+
import asyncio
|
|
307
|
+
from typing import AsyncGenerator, List, Dict
|
|
308
|
+
|
|
309
|
+
async def stream_telemetry_events(batch_size: int = 50) -> AsyncGenerator[List[Dict[str, float]], None]:
|
|
310
|
+
"""Simulate streaming telemetry metrics from edge workers."""
|
|
311
|
+
for step in range(3):
|
|
312
|
+
await asyncio.sleep(0.01)
|
|
313
|
+
yield [{"metric_id": float(step * 10 + i), "latency_ms": 1.25 * i} for i in range(batch_size)]
|
|
314
|
+
|
|
315
|
+
def compute_percentiles(samples: List[float], p95: bool = True) -> float:
|
|
316
|
+
"""Calculate latency distribution summary."""
|
|
317
|
+
if not samples:
|
|
318
|
+
return 0.0
|
|
319
|
+
sorted_samples = sorted(samples)
|
|
320
|
+
idx = int(len(sorted_samples) * 0.95) if p95 else int(len(sorted_samples) * 0.50)
|
|
321
|
+
return sorted_samples[min(idx, len(sorted_samples) - 1)]
|
|
322
|
+
'''
|
|
323
|
+
with open(os.path.join(demo_dir, "src", "data_pipeline.py"), "w", encoding="utf-8") as f:
|
|
324
|
+
f.write(data_pipeline_code.strip() + "\n")
|
|
325
|
+
|
|
326
|
+
# 3. Quickstart README
|
|
327
|
+
readme_content = '''# Codasift Sandbox Demo 🚀
|
|
328
|
+
|
|
329
|
+
Welcome to your rapid-evaluation sandbox project!
|
|
330
|
+
|
|
331
|
+
## 30-Second First Run
|
|
332
|
+
1. Start the live file watcher:
|
|
333
|
+
```bash
|
|
334
|
+
codasift watch
|
|
335
|
+
```
|
|
336
|
+
2. Open `src/auth_service.py` in your favorite editor.
|
|
337
|
+
3. Add a new function or modify docstrings, and watch your terminal immediately summarize the AST changes with zero LLM prompt bloat!
|
|
338
|
+
'''
|
|
339
|
+
with open(os.path.join(demo_dir, "README.md"), "w", encoding="utf-8") as f:
|
|
340
|
+
f.write(readme_content.strip() + "\n")
|
|
341
|
+
|
|
342
|
+
typer.secho("\n✨ Codasift Demo Sandbox Created Successfully!", fg=typer.colors.GREEN, bold=True)
|
|
343
|
+
typer.secho(f"Location: {demo_dir}", fg=typer.colors.CYAN)
|
|
344
|
+
typer.secho("Running initial AST scan on demo code...", fg=typer.colors.CYAN)
|
|
345
|
+
|
|
346
|
+
result = scan(demo_dir, description="Codasift Sandbox Starter Demo")
|
|
347
|
+
out_file = os.path.join(demo_dir, "codasift_context.md")
|
|
348
|
+
run_export(result, output_path=out_file, format_type="md")
|
|
349
|
+
|
|
350
|
+
typer.secho("\n" + "=" * 56, fg=typer.colors.GREEN, bold=True)
|
|
351
|
+
typer.secho(" [OK] Initial Demo Scan Complete! ✨", fg=typer.colors.GREEN, bold=True)
|
|
352
|
+
typer.secho("=" * 56, fg=typer.colors.GREEN, bold=True)
|
|
353
|
+
typer.secho(f" Demo Path : {demo_dir}", fg=typer.colors.WHITE, bold=True)
|
|
354
|
+
typer.secho(f" Context File: {out_file}", fg=typer.colors.CYAN)
|
|
355
|
+
typer.secho(f" AST Symbols : {len(result.get('functions', []))} functions discovered", fg=typer.colors.CYAN)
|
|
356
|
+
typer.secho(" Next Steps:", fg=typer.colors.WHITE, bold=True)
|
|
357
|
+
typer.secho(" 1. cd codasift-demo", fg=typer.colors.CYAN)
|
|
358
|
+
typer.secho(" 2. codasift watch", fg=typer.colors.CYAN)
|
|
359
|
+
typer.secho(" 3. Edit src/auth_service.py to see real-time AST diffing!", fg=typer.colors.CYAN)
|
|
360
|
+
typer.secho("-" * 56, fg=typer.colors.BLACK, dim=True)
|
|
361
|
+
try:
|
|
362
|
+
from codasift.core.auth_cli import load_credentials
|
|
363
|
+
creds = load_credentials()
|
|
364
|
+
except Exception:
|
|
365
|
+
creds = None
|
|
366
|
+
|
|
367
|
+
if creds and creds.get("access_token"):
|
|
368
|
+
user_label = creds.get("email") or creds.get("user_id") or "Active"
|
|
369
|
+
typer.secho(f" 👤 Account : Linked ({user_label})", fg=typer.colors.CYAN)
|
|
370
|
+
else:
|
|
371
|
+
typer.secho(" 💡 Tip: Run `codasift login` to link this terminal to your", fg=typer.colors.YELLOW)
|
|
372
|
+
typer.secho(" web dashboard & manage machine slots.", fg=typer.colors.YELLOW)
|
|
373
|
+
typer.secho("=" * 56 + "\n", fg=typer.colors.GREEN, bold=True)
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
@app.command()
|
|
377
|
+
def watch(
|
|
378
|
+
path: str = typer.Argument(default=".", help="Path to the project folder to watch."),
|
|
379
|
+
output: Optional[str] = typer.Option(None, "--output", "-o", help="Output file path (default: codasift_context.md or configured path)."),
|
|
380
|
+
debounce: float = typer.Option(1.0, "--debounce", "-d", help="Debounce delay in seconds."),
|
|
381
|
+
provider: str = typer.Option(None, "--provider", "-p", help="AI provider override ('ollama' or 'gemini')."),
|
|
382
|
+
model: str = typer.Option(None, "--model", "-m", help="AI model override (e.g. 'gemini-3.7-flash')."),
|
|
383
|
+
gemini_key: str = typer.Option(None, "--gemini-key", "-k", help="Google Gemini API key for this session."),
|
|
384
|
+
):
|
|
385
|
+
"""
|
|
386
|
+
Start a background watcher that updates the context file automatically when files change.
|
|
387
|
+
"""
|
|
388
|
+
import os
|
|
389
|
+
import time
|
|
390
|
+
from watchdog.observers import Observer
|
|
391
|
+
from codasift.core.watcher import WorkspaceStateManager, DebouncedEventHandler
|
|
392
|
+
|
|
393
|
+
project_path = os.path.abspath(path or ".")
|
|
394
|
+
|
|
395
|
+
# Enforce local active project limits
|
|
396
|
+
_check_limits_and_exit_if_failed(project_path)
|
|
397
|
+
|
|
398
|
+
# Resolve output path: uses last saved md file from config unless explicitly specified
|
|
399
|
+
if not output:
|
|
400
|
+
from codasift.core.config_cli import get_project_output_path
|
|
401
|
+
output = get_project_output_path(project_path)
|
|
402
|
+
else:
|
|
403
|
+
from codasift.core.config_cli import save_project_output_path
|
|
404
|
+
save_project_output_path(project_path, output)
|
|
405
|
+
typer.secho(f"📌 Output target set to: {os.path.basename(output)}", fg=typer.colors.CYAN)
|
|
406
|
+
typer.secho(f" (Saved in .codasift/config.json for future runs unless overridden again)", fg=typer.colors.CYAN, dim=True)
|
|
407
|
+
|
|
408
|
+
# Resolve output path relative to project path if not absolute
|
|
409
|
+
if not os.path.isabs(output):
|
|
410
|
+
output = os.path.join(project_path, output)
|
|
411
|
+
|
|
412
|
+
from codasift.core.config_cli import resolve_ai_provider, resolve_ai_model, resolve_gemini_api_key
|
|
413
|
+
from codasift.core.ai_client import is_ollama_reachable
|
|
414
|
+
|
|
415
|
+
eff_provider = resolve_ai_provider(provider, project_path)
|
|
416
|
+
eff_model = resolve_ai_model(model, eff_provider, project_path) or "(Default)"
|
|
417
|
+
|
|
418
|
+
typer.secho(f"Starting Codasift Watcher for: {project_path}", fg=typer.colors.CYAN)
|
|
419
|
+
typer.secho(f"Output target: {output}", fg=typer.colors.WHITE, dim=True)
|
|
420
|
+
typer.secho(f"Debounce delay: {debounce}s", fg=typer.colors.WHITE, dim=True)
|
|
421
|
+
if eff_provider == "ollama":
|
|
422
|
+
online = is_ollama_reachable()
|
|
423
|
+
status_text = "Online" if online else "Offline"
|
|
424
|
+
status_fg = typer.colors.GREEN if online else typer.colors.YELLOW
|
|
425
|
+
typer.secho(f"AI Engine: OLLAMA ({eff_model}) [", nl=False, fg=typer.colors.CYAN, bold=True)
|
|
426
|
+
typer.secho(status_text, nl=False, fg=status_fg, bold=True)
|
|
427
|
+
typer.secho("]", fg=typer.colors.CYAN, bold=True)
|
|
428
|
+
if not online:
|
|
429
|
+
typer.secho("💡 Note: Run 'ollama serve' to enable real-time diff summaries.", fg=typer.colors.WHITE, dim=True)
|
|
430
|
+
else:
|
|
431
|
+
has_key = bool(resolve_gemini_api_key(gemini_key, project_path))
|
|
432
|
+
status_text = "Active" if has_key else "Missing Key"
|
|
433
|
+
status_fg = typer.colors.GREEN if has_key else typer.colors.YELLOW
|
|
434
|
+
typer.secho(f"AI Engine: GEMINI ({eff_model}) [", nl=False, fg=typer.colors.GREEN, bold=True)
|
|
435
|
+
typer.secho(status_text, nl=False, fg=status_fg, bold=True)
|
|
436
|
+
typer.secho("]", fg=typer.colors.GREEN, bold=True)
|
|
437
|
+
if not has_key:
|
|
438
|
+
typer.secho("💡 Note: Run 'codasift config set gemini_key <KEY>' to enable Gemini AI.", fg=typer.colors.WHITE, dim=True)
|
|
439
|
+
|
|
440
|
+
try:
|
|
441
|
+
state_manager = WorkspaceStateManager(
|
|
442
|
+
project_path,
|
|
443
|
+
output_path=output,
|
|
444
|
+
cli_provider=provider,
|
|
445
|
+
cli_model=model,
|
|
446
|
+
cli_gemini_key=gemini_key,
|
|
447
|
+
)
|
|
448
|
+
event_handler = DebouncedEventHandler(state_manager, debounce_seconds=debounce)
|
|
449
|
+
|
|
450
|
+
observer = Observer()
|
|
451
|
+
observer.schedule(event_handler, path=state_manager.project_path, recursive=True)
|
|
452
|
+
observer.start()
|
|
453
|
+
|
|
454
|
+
def is_obs_alive() -> bool:
|
|
455
|
+
return observer.is_alive()
|
|
456
|
+
|
|
457
|
+
def restart_obs() -> None:
|
|
458
|
+
nonlocal observer
|
|
459
|
+
try:
|
|
460
|
+
observer.stop()
|
|
461
|
+
except Exception:
|
|
462
|
+
pass
|
|
463
|
+
observer = Observer()
|
|
464
|
+
observer.schedule(event_handler, path=state_manager.project_path, recursive=True)
|
|
465
|
+
observer.start()
|
|
466
|
+
state_manager.rebuild_meta()
|
|
467
|
+
state_manager.commit_changes()
|
|
468
|
+
|
|
469
|
+
from codasift.core.self_healing import ObserverHealthMonitor
|
|
470
|
+
obs_sentinel = ObserverHealthMonitor(is_obs_alive, restart_obs, interval_seconds=15.0)
|
|
471
|
+
obs_sentinel.start()
|
|
472
|
+
|
|
473
|
+
typer.secho("[OK] Watching directory. Press Ctrl+C to stop.", fg=typer.colors.GREEN, bold=True)
|
|
474
|
+
try:
|
|
475
|
+
while True:
|
|
476
|
+
time.sleep(1)
|
|
477
|
+
except KeyboardInterrupt:
|
|
478
|
+
typer.secho("\nStopping watcher...", fg=typer.colors.YELLOW)
|
|
479
|
+
obs_sentinel.stop()
|
|
480
|
+
state_manager.stop()
|
|
481
|
+
observer.stop()
|
|
482
|
+
observer.join()
|
|
483
|
+
typer.secho("[OK] Watcher stopped.", fg=typer.colors.GREEN, bold=True)
|
|
484
|
+
|
|
485
|
+
except Exception as e:
|
|
486
|
+
typer.secho(f"\n[ERROR] Watcher error: {e}", fg=typer.colors.RED, bold=True, err=True)
|
|
487
|
+
raise typer.Exit(code=1)
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
config_app = typer.Typer(
|
|
491
|
+
help="Manage project limits, AI models, and BYOK keys (subcommands: get, set, init, -i).",
|
|
492
|
+
invoke_without_command=True
|
|
493
|
+
)
|
|
494
|
+
app.add_typer(config_app, name="config")
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
@config_app.callback(invoke_without_command=True)
|
|
498
|
+
def config_callback(
|
|
499
|
+
ctx: typer.Context,
|
|
500
|
+
interactive: bool = typer.Option(False, "--interactive", "-i", help="Run interactive configuration wizard."),
|
|
501
|
+
init_flag: bool = typer.Option(False, "--init", help="Scaffold a new .codasift/config.json in project root."),
|
|
502
|
+
key: Optional[str] = typer.Option(None, "--key", "-k", help="Configure Google Gemini API key in secure global state."),
|
|
503
|
+
provider: Optional[str] = typer.Option(None, "--provider", "-p", help="Set active AI provider ('ollama' or 'gemini')."),
|
|
504
|
+
model: Optional[str] = typer.Option(None, "--model", "-m", help="Set default AI model (e.g. 'gemini-3.8-flash' or 'qwen2.5-coder:1.5b')."),
|
|
505
|
+
path: str = typer.Option(".", "--path", help="Path to project directory for local context."),
|
|
506
|
+
):
|
|
507
|
+
"""
|
|
508
|
+
Manage Codasift project limits, ignore configuration, AI providers, and BYOK keys.
|
|
509
|
+
"""
|
|
510
|
+
import os
|
|
511
|
+
from codasift.core.config_cli import (
|
|
512
|
+
set_global_gemini_key,
|
|
513
|
+
set_global_provider,
|
|
514
|
+
set_global_model,
|
|
515
|
+
get_global_state,
|
|
516
|
+
get_full_configuration,
|
|
517
|
+
resolve_ai_provider,
|
|
518
|
+
get_project_config_path,
|
|
519
|
+
scaffold_project_config,
|
|
520
|
+
update_project_ai_provider,
|
|
521
|
+
update_project_ai_model,
|
|
522
|
+
run_interactive_config_wizard,
|
|
523
|
+
)
|
|
524
|
+
from codasift.core.config_manager import get_available_gemini_models
|
|
525
|
+
|
|
526
|
+
if ctx.invoked_subcommand is not None:
|
|
527
|
+
return
|
|
528
|
+
|
|
529
|
+
project_path = os.path.abspath(path)
|
|
530
|
+
|
|
531
|
+
if interactive:
|
|
532
|
+
run_interactive_config_wizard(project_path)
|
|
533
|
+
return
|
|
534
|
+
|
|
535
|
+
actions_performed = False
|
|
536
|
+
|
|
537
|
+
if init_flag:
|
|
538
|
+
target = get_project_config_path(project_path)
|
|
539
|
+
if os.path.exists(target):
|
|
540
|
+
confirm = typer.confirm(f"A configuration file already exists at {target}. Overwrite with default template?", default=False)
|
|
541
|
+
if not confirm:
|
|
542
|
+
typer.secho("\n[CANCELLED] Existing configuration preserved.", fg=typer.colors.YELLOW)
|
|
543
|
+
raise typer.Exit(code=0)
|
|
544
|
+
scaffold_project_config(project_path, force=True)
|
|
545
|
+
typer.secho(f"\n[OK] Project configuration initialized successfully!", fg=typer.colors.GREEN, bold=True)
|
|
546
|
+
typer.secho(f" Config File : {target}", fg=typer.colors.WHITE, bold=True)
|
|
547
|
+
actions_performed = True
|
|
548
|
+
|
|
549
|
+
if key:
|
|
550
|
+
try:
|
|
551
|
+
set_global_gemini_key(key)
|
|
552
|
+
typer.secho("\n[OK] Google Gemini API key saved to global secure state.", fg=typer.colors.GREEN, bold=True)
|
|
553
|
+
actions_performed = True
|
|
554
|
+
except Exception as e:
|
|
555
|
+
typer.secho(f"\n[ERROR] Failed to save Gemini key: {e}", fg=typer.colors.RED, bold=True, err=True)
|
|
556
|
+
raise typer.Exit(code=1)
|
|
557
|
+
|
|
558
|
+
target_project_cfg = get_project_config_path(project_path)
|
|
559
|
+
has_project_file = os.path.exists(target_project_cfg)
|
|
560
|
+
|
|
561
|
+
if provider:
|
|
562
|
+
try:
|
|
563
|
+
if has_project_file:
|
|
564
|
+
p = update_project_ai_provider(project_path, provider)
|
|
565
|
+
typer.secho(f"\n[OK] Default AI provider set to: {p} (project: {target_project_cfg})", fg=typer.colors.GREEN, bold=True)
|
|
566
|
+
else:
|
|
567
|
+
p = set_global_provider(provider)
|
|
568
|
+
typer.secho(f"\n[OK] Default AI provider set to: {p}", fg=typer.colors.GREEN, bold=True)
|
|
569
|
+
actions_performed = True
|
|
570
|
+
except Exception as e:
|
|
571
|
+
typer.secho(f"\n[ERROR] {e}", fg=typer.colors.RED, bold=True, err=True)
|
|
572
|
+
raise typer.Exit(code=1)
|
|
573
|
+
|
|
574
|
+
if model:
|
|
575
|
+
try:
|
|
576
|
+
if provider:
|
|
577
|
+
active_p = provider.strip().lower()
|
|
578
|
+
elif has_project_file:
|
|
579
|
+
active_p = resolve_ai_provider(None, project_path)
|
|
580
|
+
else:
|
|
581
|
+
active_p = get_global_state().get("provider") or "ollama"
|
|
582
|
+
|
|
583
|
+
if active_p == "local":
|
|
584
|
+
active_p = "ollama"
|
|
585
|
+
if has_project_file:
|
|
586
|
+
m = update_project_ai_model(project_path, model, provider=active_p)
|
|
587
|
+
provider_title = "Ollama" if active_p == "ollama" else "Gemini"
|
|
588
|
+
typer.secho(f"\n[OK] Default {provider_title} model set to: {m} (project: {target_project_cfg})", fg=typer.colors.GREEN, bold=True)
|
|
589
|
+
else:
|
|
590
|
+
m = set_global_model(model, provider=active_p)
|
|
591
|
+
provider_title = "Ollama" if active_p == "ollama" else "Gemini"
|
|
592
|
+
typer.secho(f"\n[OK] Default {provider_title} model set to: {m}", fg=typer.colors.GREEN, bold=True)
|
|
593
|
+
actions_performed = True
|
|
594
|
+
except Exception as e:
|
|
595
|
+
typer.secho(f"\n[ERROR] {e}", fg=typer.colors.RED, bold=True, err=True)
|
|
596
|
+
raise typer.Exit(code=1)
|
|
597
|
+
|
|
598
|
+
if not actions_performed:
|
|
599
|
+
cfg = get_full_configuration(project_path)
|
|
600
|
+
typer.echo()
|
|
601
|
+
typer.secho("+------------------------------------------------------------------------+", fg=typer.colors.CYAN)
|
|
602
|
+
typer.secho("| Codasift Project & AI Configuration |", fg=typer.colors.CYAN, bold=True)
|
|
603
|
+
typer.secho("+------------------------------------------------------------------------+", fg=typer.colors.CYAN)
|
|
604
|
+
|
|
605
|
+
# Project configuration section
|
|
606
|
+
config_status = "Custom File Active" if cfg.get("has_project_config") else "Using Built-in Defaults"
|
|
607
|
+
typer.secho(f" Project Config File : {cfg.get('project_config_path')}", fg=typer.colors.WHITE)
|
|
608
|
+
typer.secho(f" Configuration Status: ", nl=False)
|
|
609
|
+
typer.secho(f"{config_status}", fg=typer.colors.GREEN if cfg.get("has_project_config") else typer.colors.YELLOW, bold=True)
|
|
610
|
+
|
|
611
|
+
limits = cfg.get("limits", {})
|
|
612
|
+
typer.secho(f" Max Total Size : {limits.get('max_total_size_mb', 50)} MB")
|
|
613
|
+
typer.secho(f" Max Single File Size: {limits.get('max_file_size_kb', 500)} KB")
|
|
614
|
+
typer.secho(f" Max Scanned Files : {limits.get('max_files', 10000)} files")
|
|
615
|
+
typer.secho(f" Large File Policy : {cfg.get('large_file_policy', 'skeleton')} (skeleton / skip / force_full)")
|
|
616
|
+
typer.echo()
|
|
617
|
+
|
|
618
|
+
# AI Engine section
|
|
619
|
+
typer.secho("AI Engine & Providers:", fg=typer.colors.WHITE, bold=True)
|
|
620
|
+
typer.secho(f" Active Provider : ", nl=False)
|
|
621
|
+
typer.secho(f"{cfg['provider'].upper()} ", fg=typer.colors.GREEN if cfg['provider'] == 'gemini' else typer.colors.CYAN, bold=True, nl=False)
|
|
622
|
+
typer.secho(f"[{cfg.get('provider_origin', 'Built-in Default')}]", fg=typer.colors.WHITE, dim=True)
|
|
623
|
+
typer.secho(f" Configured Model : {cfg['model']} ", nl=False)
|
|
624
|
+
typer.secho(f"[{cfg.get('model_origin', 'Built-in Default')}]", fg=typer.colors.WHITE, dim=True)
|
|
625
|
+
typer.secho(f" Gemini Key Masked : {cfg['gemini_api_key_masked']}")
|
|
626
|
+
typer.secho(f" BYOK Daily Cap : {cfg.get('byok_max_daily_calls', 50)} calls/day ", nl=False)
|
|
627
|
+
typer.secho(f"[{cfg.get('byok_origin', 'Built-in Default')}]", fg=typer.colors.WHITE, dim=True)
|
|
628
|
+
typer.secho(f" Global State File : {cfg['global_state_file']}", fg=typer.colors.WHITE, dim=True)
|
|
629
|
+
typer.echo()
|
|
630
|
+
typer.secho("Available Gemini Models:", fg=typer.colors.WHITE, bold=True)
|
|
631
|
+
for m in get_available_gemini_models():
|
|
632
|
+
tag = " (Recommended)" if m.get("recommended") else ""
|
|
633
|
+
typer.secho(f" • {m['id']}{tag}", fg=typer.colors.CYAN if m.get("recommended") else typer.colors.WHITE)
|
|
634
|
+
typer.echo()
|
|
635
|
+
typer.secho("Quick Commands:", fg=typer.colors.WHITE, bold=True)
|
|
636
|
+
typer.secho(" Interactive wizard: codasift config -i", fg=typer.colors.CYAN)
|
|
637
|
+
typer.secho(" Update a setting : codasift config set <key> <val> (e.g. codasift config set max_total_size 100MB)", fg=typer.colors.WHITE)
|
|
638
|
+
typer.secho(" Inspect a setting : codasift config get <key> (e.g. codasift config get provider)", fg=typer.colors.WHITE)
|
|
639
|
+
typer.secho(" Scaffold config : codasift config init", fg=typer.colors.WHITE)
|
|
640
|
+
typer.secho(" All options : codasift config --help", fg=typer.colors.WHITE, dim=True)
|
|
641
|
+
typer.echo()
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
@config_app.command(name="get")
|
|
645
|
+
def config_get_cmd(
|
|
646
|
+
key: str = typer.Argument(..., help="Configuration key to query (e.g. provider, model, gemini_key, max_files, path)."),
|
|
647
|
+
path: str = typer.Option(".", "--path", help="Path to project directory for local context."),
|
|
648
|
+
):
|
|
649
|
+
"""
|
|
650
|
+
Get the effective value and origin of a configuration setting.
|
|
651
|
+
"""
|
|
652
|
+
import os
|
|
653
|
+
from codasift.core.config_cli import get_config_value
|
|
654
|
+
try:
|
|
655
|
+
canonical_key, val, origin = get_config_value(key, os.path.abspath(path))
|
|
656
|
+
typer.echo(f"{canonical_key} = {val} [{origin}]")
|
|
657
|
+
except Exception as e:
|
|
658
|
+
typer.secho(f"\n[ERROR] {e}", fg=typer.colors.RED, bold=True, err=True)
|
|
659
|
+
raise typer.Exit(code=1)
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
@config_app.command(name="set")
|
|
663
|
+
def config_set_cmd(
|
|
664
|
+
key: str = typer.Argument(..., help="Configuration key to set (e.g. max_total_size, max_file_size, max_files, large_file_policy, provider, model, gemini_key, max_daily_calls)."),
|
|
665
|
+
value: str = typer.Argument(..., help="Value to assign."),
|
|
666
|
+
is_global: bool = typer.Option(False, "--global", "-g", help="Persist globally (~/.codasift/global_state.json)."),
|
|
667
|
+
is_local: bool = typer.Option(False, "--local", "-l", help="Persist locally in project (.codasift/config.json)."),
|
|
668
|
+
path: str = typer.Option(".", "--path", help="Path to project directory for local context."),
|
|
669
|
+
):
|
|
670
|
+
"""
|
|
671
|
+
Set a configuration setting across project or global scope.
|
|
672
|
+
"""
|
|
673
|
+
import os
|
|
674
|
+
from codasift.core.config_cli import set_config_value
|
|
675
|
+
scope = "global" if is_global else ("local" if is_local else "auto")
|
|
676
|
+
try:
|
|
677
|
+
canonical_key, updated_val, applied_scope = set_config_value(
|
|
678
|
+
key=key,
|
|
679
|
+
value=value,
|
|
680
|
+
scope=scope,
|
|
681
|
+
project_path=os.path.abspath(path)
|
|
682
|
+
)
|
|
683
|
+
typer.secho(f"\n[OK] Configuration updated!", fg=typer.colors.GREEN, bold=True)
|
|
684
|
+
typer.secho(f" Setting : {canonical_key} = {updated_val}", fg=typer.colors.WHITE)
|
|
685
|
+
typer.secho(f" Scope : {applied_scope}\n", fg=typer.colors.CYAN)
|
|
686
|
+
except Exception as e:
|
|
687
|
+
typer.secho(f"\n[ERROR] {e}", fg=typer.colors.RED, bold=True, err=True)
|
|
688
|
+
raise typer.Exit(code=1)
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
@config_app.command(name="init")
|
|
692
|
+
def config_init_cmd(
|
|
693
|
+
force: bool = typer.Option(False, "--force", "-f", help="Force overwrite existing configuration without prompting."),
|
|
694
|
+
path: str = typer.Option(".", "--path", help="Path to project directory."),
|
|
695
|
+
):
|
|
696
|
+
"""
|
|
697
|
+
Scaffold a new .codasift/config.json template in the project root.
|
|
698
|
+
"""
|
|
699
|
+
import os
|
|
700
|
+
from codasift.core.config_cli import get_project_config_path, scaffold_project_config
|
|
701
|
+
project_path = os.path.abspath(path)
|
|
702
|
+
target = get_project_config_path(project_path)
|
|
703
|
+
if os.path.exists(target) and not force:
|
|
704
|
+
confirm = typer.confirm(f"A configuration file already exists at {target}. Overwrite with default template?", default=False)
|
|
705
|
+
if not confirm:
|
|
706
|
+
typer.secho("\n[CANCELLED] Existing configuration preserved.", fg=typer.colors.YELLOW)
|
|
707
|
+
raise typer.Exit(code=0)
|
|
708
|
+
scaffold_project_config(project_path, force=True)
|
|
709
|
+
typer.secho(f"\n[OK] Project configuration initialized successfully!", fg=typer.colors.GREEN, bold=True)
|
|
710
|
+
typer.secho(f" Config File : {target}\n", fg=typer.colors.WHITE, bold=True)
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
@app.command("activate")
|
|
714
|
+
def activate(
|
|
715
|
+
key: str = typer.Argument(..., help="Codasift Pro license key string."),
|
|
716
|
+
):
|
|
717
|
+
"""
|
|
718
|
+
Activate your offline Local Pro license.
|
|
719
|
+
"""
|
|
720
|
+
from codasift.core.licensing import (
|
|
721
|
+
verify_license_key,
|
|
722
|
+
load_global_state,
|
|
723
|
+
save_global_state,
|
|
724
|
+
check_online_activation,
|
|
725
|
+
flush_pending_cloud_deactivations,
|
|
726
|
+
)
|
|
727
|
+
|
|
728
|
+
try:
|
|
729
|
+
flush_pending_cloud_deactivations()
|
|
730
|
+
except Exception:
|
|
731
|
+
pass
|
|
732
|
+
|
|
733
|
+
typer.secho("Verifying license key...", fg=typer.colors.CYAN)
|
|
734
|
+
resolved_api = get_api_url()
|
|
735
|
+
clean_key = key.strip()
|
|
736
|
+
payload = verify_license_key(clean_key)
|
|
737
|
+
if not payload:
|
|
738
|
+
typer.secho("[ERROR] Invalid license key signature or corrupt key format.", fg=typer.colors.RED, bold=True, err=True)
|
|
739
|
+
raise typer.Exit(code=1)
|
|
740
|
+
|
|
741
|
+
# Check online activation with backend to ensure machine slots aren't exceeded
|
|
742
|
+
if not check_online_activation(clean_key, api_base_url=resolved_api):
|
|
743
|
+
typer.secho("\n[ERROR] Online activation failed: Machine slot limit reached (3 active machines) or invalid key.", fg=typer.colors.RED, bold=True, err=True)
|
|
744
|
+
typer.secho("To free a machine slot, run `codasift deactivate` on another machine or manage devices in your dashboard.", fg=typer.colors.YELLOW)
|
|
745
|
+
raise typer.Exit(code=1)
|
|
746
|
+
|
|
747
|
+
state = load_global_state()
|
|
748
|
+
state["license_key"] = clean_key
|
|
749
|
+
save_global_state(state)
|
|
750
|
+
|
|
751
|
+
typer.secho("\n[OK] License activated successfully!", fg=typer.colors.GREEN, bold=True)
|
|
752
|
+
typer.secho(f" Owner: {payload['email']}", fg=typer.colors.CYAN)
|
|
753
|
+
typer.secho(f" Tier : {payload['tier'].replace('_', ' ').title()}", fg=typer.colors.CYAN)
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
@app.command()
|
|
757
|
+
def deactivate(
|
|
758
|
+
force: bool = typer.Option(False, "--force", "-y", help="Bypass confirmation prompt for headless/CI deactivation.")
|
|
759
|
+
):
|
|
760
|
+
"""
|
|
761
|
+
Deactivate local Pro license and unlink this machine slot.
|
|
762
|
+
"""
|
|
763
|
+
from codasift.core.licensing import (
|
|
764
|
+
load_global_state,
|
|
765
|
+
save_global_state,
|
|
766
|
+
deactivate_online_license,
|
|
767
|
+
queue_pending_cloud_deactivation,
|
|
768
|
+
)
|
|
769
|
+
resolved_api = get_api_url()
|
|
770
|
+
state = load_global_state()
|
|
771
|
+
old_key = state.get("license_key")
|
|
772
|
+
old_lease = state.get("lease_token")
|
|
773
|
+
if not old_key:
|
|
774
|
+
typer.secho("No active license key found on this machine.", fg=typer.colors.YELLOW)
|
|
775
|
+
return
|
|
776
|
+
|
|
777
|
+
if not force and sys.stdin.isatty():
|
|
778
|
+
typer.secho("\n⚠️ Machine Slot Deactivation Warning", fg=typer.colors.YELLOW, bold=True)
|
|
779
|
+
typer.secho(" • Unlinking this machine frees the slot on your account for another workstation.", fg=typer.colors.WHITE)
|
|
780
|
+
typer.secho(" • Deactivation consumes 1 of your 3 monthly self-serve reallocations (per 30-day window).", fg=typer.colors.WHITE)
|
|
781
|
+
typer.secho(" • Tip: If you only wish to sign out of your user session on this machine,", fg=typer.colors.CYAN)
|
|
782
|
+
typer.secho(" use `codasift logout` instead to preserve your machine slot allocation.\n", fg=typer.colors.CYAN)
|
|
783
|
+
confirmed = typer.confirm("Are you sure you want to deactivate this machine?", default=False)
|
|
784
|
+
if not confirmed:
|
|
785
|
+
typer.secho("Deactivation cancelled. Machine slot preserved.", fg=typer.colors.GREEN)
|
|
786
|
+
return
|
|
787
|
+
|
|
788
|
+
typer.secho("Unlinking machine slot from Codasift server...", fg=typer.colors.CYAN)
|
|
789
|
+
online_success, online_msg = deactivate_online_license(old_key, api_base_url=resolved_api)
|
|
790
|
+
if online_success:
|
|
791
|
+
typer.secho(f"[OK] {online_msg}", fg=typer.colors.GREEN)
|
|
792
|
+
else:
|
|
793
|
+
typer.secho(f"[WARNING] {online_msg}", fg=typer.colors.YELLOW)
|
|
794
|
+
queue_pending_cloud_deactivation(old_key, lease_token=old_lease)
|
|
795
|
+
typer.secho("Cloud slot deactivation has been queued and will auto-sync once online.", fg=typer.colors.CYAN)
|
|
796
|
+
typer.secho("Proceeding with local license removal.", fg=typer.colors.YELLOW)
|
|
797
|
+
|
|
798
|
+
state["license_key"] = None
|
|
799
|
+
state["lease_token"] = None
|
|
800
|
+
save_global_state(state)
|
|
801
|
+
typer.secho("\n[OK] License deactivated successfully on this machine.", fg=typer.colors.GREEN, bold=True)
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
@app.command()
|
|
805
|
+
def export(
|
|
806
|
+
path: str = typer.Argument(default=".", help="Path to the project folder."),
|
|
807
|
+
format: str = typer.Option("md", "--format", "-f", help="Target output format (md, claude, cursor, copilot)."),
|
|
808
|
+
output: str = typer.Option(None, "--output", "-o", help="Custom output file path. Defaults to standard locations."),
|
|
809
|
+
compact: bool = typer.Option(False, "--compact", help="Generate high-density compact context file (for md format)."),
|
|
810
|
+
):
|
|
811
|
+
"""
|
|
812
|
+
Export the scanned project context to specialized AI tool formats.
|
|
813
|
+
"""
|
|
814
|
+
import os
|
|
815
|
+
project_path = os.path.abspath(path or ".")
|
|
816
|
+
|
|
817
|
+
# 1. Enforce tier restrictions
|
|
818
|
+
if format != "md" and not has_pro_license():
|
|
819
|
+
typer.secho("\n[ERROR] Custom export formats (claude, cursor, copilot) require Codasift Pro.", fg=typer.colors.RED, bold=True, err=True)
|
|
820
|
+
typer.secho("Please purchase Local Pro ($20 one-time) to unlock all exporters:", fg=typer.colors.CYAN)
|
|
821
|
+
typer.secho(f"{get_frontend_url()}/pricing", fg=typer.colors.CYAN, underline=True, bold=True)
|
|
822
|
+
typer.secho("\nOr activate your license key using: codasift activate <KEY>", fg=typer.colors.CYAN)
|
|
823
|
+
raise typer.Exit(code=1)
|
|
824
|
+
|
|
825
|
+
# 2. Enforce active project limits
|
|
826
|
+
_check_limits_and_exit_if_failed(project_path)
|
|
827
|
+
|
|
828
|
+
# 3. Resolve default or relative output paths relative to the project directory
|
|
829
|
+
if not output:
|
|
830
|
+
from codasift.core.exporter import resolve_context_output_path
|
|
831
|
+
if format == "md":
|
|
832
|
+
from codasift.core.config_cli import get_project_output_path
|
|
833
|
+
default_target = get_project_output_path(project_path)
|
|
834
|
+
elif format == "claude":
|
|
835
|
+
default_target = "claude_context.xml"
|
|
836
|
+
elif format == "cursor":
|
|
837
|
+
default_target = ".cursorrules"
|
|
838
|
+
elif format == "copilot":
|
|
839
|
+
default_target = os.path.join(".github", "copilot-instructions.md")
|
|
840
|
+
else:
|
|
841
|
+
default_target = f"codasift_context.{format}"
|
|
842
|
+
|
|
843
|
+
output, was_renamed = resolve_context_output_path(project_path, None, default_filename=default_target)
|
|
844
|
+
if was_renamed:
|
|
845
|
+
typer.secho(f"\n[NOTICE] Existing '{default_target}' detected. Preserving it and saving as: {os.path.basename(output)}", fg=typer.colors.YELLOW, bold=True)
|
|
846
|
+
typer.secho(f" (Hint: Use -o {default_target} or --output <path> to overwrite or specify a custom destination)", fg=typer.colors.CYAN, dim=True)
|
|
847
|
+
elif not os.path.isabs(output):
|
|
848
|
+
output = os.path.join(project_path, output)
|
|
849
|
+
|
|
850
|
+
# 4. Perform scan and export
|
|
851
|
+
try:
|
|
852
|
+
typer.secho("Analysing project...", fg=typer.colors.CYAN)
|
|
853
|
+
result = scan(project_path, description="Exported context.")
|
|
854
|
+
|
|
855
|
+
typer.secho(f"Exporting in '{format}' format...", fg=typer.colors.CYAN)
|
|
856
|
+
out_file = run_export(result, output_path=output, format_type=format, compact=compact)
|
|
857
|
+
|
|
858
|
+
typer.secho(f"\n[OK] Context successfully exported to: {out_file}", fg=typer.colors.GREEN, bold=True)
|
|
859
|
+
except Exception as e:
|
|
860
|
+
clean_msg = _format_clean_error(e, fallback="An unexpected error occurred during export.")
|
|
861
|
+
typer.secho(f"\n[ERROR] Export failed: {clean_msg}", fg=typer.colors.RED, bold=True, err=True)
|
|
862
|
+
raise typer.Exit(code=1)
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
@app.command()
|
|
866
|
+
def login(
|
|
867
|
+
port: Optional[int] = typer.Option(None, "--port", "-p", hidden=True, help="Internal debug override for loopback port."),
|
|
868
|
+
):
|
|
869
|
+
"""
|
|
870
|
+
Authenticate your terminal session via browser OAuth / JWT login.
|
|
871
|
+
"""
|
|
872
|
+
import os
|
|
873
|
+
from codasift.core.auth_cli import run_cli_login
|
|
874
|
+
resolved_frontend = get_frontend_url()
|
|
875
|
+
resolved_api = get_api_url()
|
|
876
|
+
success = run_cli_login(frontend_url=resolved_frontend, port=port, api_base_url=resolved_api)
|
|
877
|
+
if not success:
|
|
878
|
+
raise typer.Exit(code=1)
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
@app.command()
|
|
882
|
+
def logout():
|
|
883
|
+
"""
|
|
884
|
+
Revoke active session and purge cached terminal credentials.
|
|
885
|
+
"""
|
|
886
|
+
from codasift.core.auth_cli import run_cli_logout
|
|
887
|
+
resolved_api = get_api_url()
|
|
888
|
+
run_cli_logout(api_base_url=resolved_api)
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
@app.command(hidden=True)
|
|
892
|
+
def sync(
|
|
893
|
+
path: str = typer.Argument(default=".", help="Path to the project folder to sync."),
|
|
894
|
+
):
|
|
895
|
+
"""
|
|
896
|
+
Synchronize local project AST context summary with Codasift Cloud storage.
|
|
897
|
+
"""
|
|
898
|
+
import os
|
|
899
|
+
from codasift.core.sync_cli import run_cli_sync
|
|
900
|
+
resolved_api = get_api_url()
|
|
901
|
+
success = run_cli_sync(project_path=path, api_base_url=resolved_api)
|
|
902
|
+
if not success:
|
|
903
|
+
raise typer.Exit(code=1)
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
@app.command(hidden=True)
|
|
907
|
+
def pull(
|
|
908
|
+
workspace_id: str = typer.Argument(..., help="Unique ID of the workspace context to pull from Codasift Cloud."),
|
|
909
|
+
output: Optional[str] = typer.Option(None, "--output", "-o", help="Custom output file path (e.g., codasift_context.md or my_ws.json)."),
|
|
910
|
+
format_type: str = typer.Option("json", "--format", "-f", help="Output format: 'json' (native AST) or 'md' (markdown context)."),
|
|
911
|
+
):
|
|
912
|
+
"""
|
|
913
|
+
Pull a cloud-synced workspace context snapshot and save locally as JSON or Markdown.
|
|
914
|
+
"""
|
|
915
|
+
import os
|
|
916
|
+
from codasift.core.sync_cli import run_cli_pull
|
|
917
|
+
resolved_api = get_api_url()
|
|
918
|
+
success = run_cli_pull(workspace_id=workspace_id, output=output, format_type=format_type, api_base_url=resolved_api)
|
|
919
|
+
if not success:
|
|
920
|
+
raise typer.Exit(code=1)
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
if __name__ == "__main__":
|
|
924
|
+
app()
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codasift
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: A persistent context layer for AI users.
|
|
5
|
+
Project-URL: Homepage, https://codasift.dev
|
|
6
|
+
Project-URL: Documentation, https://codasift.dev/faq
|
|
7
|
+
Project-URL: Terms of Service, https://codasift.dev/terms
|
|
8
|
+
Project-URL: Privacy Policy, https://codasift.dev/privacy
|
|
9
|
+
Project-URL: Bug Tracker, https://codasift.dev
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Requires-Dist: typer>=0.12.0
|
|
12
|
+
Requires-Dist: watchdog>=4.0.0
|
|
13
|
+
Requires-Dist: cryptography>=42.0.0
|
|
14
|
+
Requires-Dist: google-genai>=1.0.0
|
|
15
|
+
Dynamic: requires-python
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
codasift/__init__.py,sha256=D4zz-q1DoeXLwEYFLjzKeJls7wKm9tlB5qwddLN25PE,86
|
|
2
|
+
codasift/main.py,sha256=hcb-kcaREadx7cdOEeaf1Iw7oe9sCC9-glsE5wDSqTs,45675
|
|
3
|
+
codasift/core/__init__.py,sha256=4SJWCENCiRzV0pvJ3oFI_zPPlS0xhbtpep9vh2ay4V0,37
|
|
4
|
+
codasift/core/ai_client.cp312-win_amd64.pyd,sha256=dKDxmr6mIyAZV7rgPNek463KTwsyJvlgNmc5W2JKb6o,126464
|
|
5
|
+
codasift/core/auth_cli.cp312-win_amd64.pyd,sha256=XZwyFLpXqN_dyFDRwffLY9U013eL3fwt0Nyt8LW-Dl0,165376
|
|
6
|
+
codasift/core/classifier.cp312-win_amd64.pyd,sha256=cHbFfOnW5AB_GVHrSosriv1JfvO_0CU_6KAqlxdwm_g,91136
|
|
7
|
+
codasift/core/config_cli.cp312-win_amd64.pyd,sha256=Jz7DC-Lr9AzB3tOgNKrSf69RA_mxYkhCZbKhyAj-mZ4,277504
|
|
8
|
+
codasift/core/config_manager.cp312-win_amd64.pyd,sha256=Z3DwYPb-hK9sZobYn-Y1sAa-z_1JRXqiekNMU7nz42o,104448
|
|
9
|
+
codasift/core/constants.cp312-win_amd64.pyd,sha256=Magc_Dqrh89AyxVGXhd0yOKKI6qyNupV9WQfisvihqs,47616
|
|
10
|
+
codasift/core/diff_extractor.cp312-win_amd64.pyd,sha256=itoxlFjCxwdPiUfpzrYA4UHrIo2UuoXTWBLrDhF9lCA,92160
|
|
11
|
+
codasift/core/exporter.cp312-win_amd64.pyd,sha256=EvP5HTO-1LDGbDQbntBG704iFSIRKOI_kKyw4hhb4gU,274944
|
|
12
|
+
codasift/core/gemini_client.cp312-win_amd64.pyd,sha256=nKrI84HWoMymzLzWmEzyOwopWPkjmR-8-rAc61wNbiA,108032
|
|
13
|
+
codasift/core/licensing.cp312-win_amd64.pyd,sha256=VrI6W8RbjLck2PvjX9eWXEQ-OE81YqtJKINqPwNERUU,210432
|
|
14
|
+
codasift/core/scanner.cp312-win_amd64.pyd,sha256=D45xror803bjvXuR_rhdh7e3EYgFq7SW2NPTwCA4p1k,176640
|
|
15
|
+
codasift/core/self_healing.cp312-win_amd64.pyd,sha256=wpjIa-37wT1g-rxZbu6Qiz5NEF940hRmIA80EXpXo3w,135168
|
|
16
|
+
codasift/core/sync_cli.cp312-win_amd64.pyd,sha256=VGP5cJp82lkwcCGKjwlqUbm779T9VehR_xAak8CqN68,148992
|
|
17
|
+
codasift/core/terminal_utils.cp312-win_amd64.pyd,sha256=2zj6wkr5WPp2-GV1WcEditvYJTkob9SOjXzbShLuKuI,54784
|
|
18
|
+
codasift/core/watcher.cp312-win_amd64.pyd,sha256=WKz2Bgq9MWSQFq84OuFAR-Gn0fR1AdbxgJTgpmhGfHM,258560
|
|
19
|
+
codasift/languages/__init__.py,sha256=GyUN62JGLhSqXgYcRUc1r3qhy4Ig1tc07D9N5nI-3TA,1453
|
|
20
|
+
codasift/languages/base.cp312-win_amd64.pyd,sha256=XAQJhOQRRxByellUKEUksaB04qvn4Sfh8iH8i4SV2q0,72704
|
|
21
|
+
codasift/languages/python.cp312-win_amd64.pyd,sha256=0v4hFON5deEooOgsAzCL0qlZwKnFSpYXBxJFTIEbvP8,271360
|
|
22
|
+
codasift-0.1.1.dist-info/METADATA,sha256=KdLpEwC93YI3d3Urk1Grs-as2wcLUjGUHIEvdtVBvoQ,557
|
|
23
|
+
codasift-0.1.1.dist-info/WHEEL,sha256=smAfYAdc4xihz0sI8rUsw5fnCPd2yjYFBM0up6OiEDE,101
|
|
24
|
+
codasift-0.1.1.dist-info/entry_points.txt,sha256=1L0Vu7G8Vm0sMGEQExiWXM9EvIwjYB-jy_ww55-FatQ,47
|
|
25
|
+
codasift-0.1.1.dist-info/top_level.txt,sha256=OWD0BEAyn_CQYEWHzUzoZRJq3Pcy7h4U3bOBFlKoCpo,9
|
|
26
|
+
codasift-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
codasift
|