k-cli-for-devs 1.0.0__py3-none-any.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.
- k_cli/__init__.py +77 -0
- k_cli/agents/__init__.py +0 -0
- k_cli/agents/adversarial_swarm.py +338 -0
- k_cli/agents/agent_core.py +255 -0
- k_cli/agents/background_daemon.py +141 -0
- k_cli/agents/orchestrator.py +376 -0
- k_cli/agents/persona.py +649 -0
- k_cli/agents/scaffold_engine.py +121 -0
- k_cli/agents/strands_agent.py +832 -0
- k_cli/agents/subagents.py +1496 -0
- k_cli/cli.py +3297 -0
- k_cli/core/__init__.py +0 -0
- k_cli/core/airgap.py +95 -0
- k_cli/core/credentials.py +548 -0
- k_cli/core/intent_sensor.py +177 -0
- k_cli/core/llm_driver.py +1028 -0
- k_cli/core/model_manager.py +1109 -0
- k_cli/core/models_hub.py +913 -0
- k_cli/core/prompting.py +41 -0
- k_cli/core/sdk.py +322 -0
- k_cli/core/session.py +826 -0
- k_cli/core/smart_router.py +230 -0
- k_cli/core/storage_manager.py +176 -0
- k_cli/core/viewport_engine.py +117 -0
- k_cli/demo/demo_runner.py +579 -0
- k_cli/git/__init__.py +0 -0
- k_cli/git/ai_bisect.py +208 -0
- k_cli/git/conflict_resolver.py +1039 -0
- k_cli/git/git_guard.py +417 -0
- k_cli/git/patcher.py +1175 -0
- k_cli/git/repo_map.py +1780 -0
- k_cli/git/smart_git.py +928 -0
- k_cli/git/verifier.py +969 -0
- k_cli/github/__init__.py +0 -0
- k_cli/github/dedup_engine.py +787 -0
- k_cli/github/github_client.py +1702 -0
- k_cli/github/github_engine.py +641 -0
- k_cli/github/local_hub.py +209 -0
- k_cli/github/pr_watcher.py +129 -0
- k_cli/github/trending.py +205 -0
- k_cli/tools/__init__.py +0 -0
- k_cli/tools/audit.py +79 -0
- k_cli/tools/chaos_immunity.py +377 -0
- k_cli/tools/codebase_qa.py +106 -0
- k_cli/tools/command_runner.py +256 -0
- k_cli/tools/diagram_generator.py +547 -0
- k_cli/tools/doc_retriever.py +1332 -0
- k_cli/tools/feature.py +105 -0
- k_cli/tools/ghost_daemon.py +122 -0
- k_cli/tools/incident_triage.py +1365 -0
- k_cli/tools/mcp_client.py +1846 -0
- k_cli/tools/repo_gardener.py +142 -0
- k_cli/tools/rules.py +109 -0
- k_cli/tools/security.py +52 -0
- k_cli/tools/security_healer.py +999 -0
- k_cli/tools/synapse_graph.py +155 -0
- k_cli/tui/__init__.py +0 -0
- k_cli/tui/diff_viewer.py +223 -0
- k_cli/tui/tui.py +1145 -0
- k_cli/tui/tui_animations.py +648 -0
- k_cli/tui/tui_app.py +2788 -0
- k_cli/ui/__init__.py +10 -0
- k_cli/ui/simple_repl.py +315 -0
- k_cli/web/__init__.py +7 -0
- k_cli/web/server.py +624 -0
- k_cli/web/static/app.js +830 -0
- k_cli/web/static/index.html +495 -0
- k_cli/web/static/monitor.html +189 -0
- k_cli/web/static/style.css +838 -0
- k_cli_for_devs-1.0.0.dist-info/METADATA +461 -0
- k_cli_for_devs-1.0.0.dist-info/RECORD +75 -0
- k_cli_for_devs-1.0.0.dist-info/WHEEL +5 -0
- k_cli_for_devs-1.0.0.dist-info/entry_points.txt +2 -0
- k_cli_for_devs-1.0.0.dist-info/licenses/LICENSE +21 -0
- k_cli_for_devs-1.0.0.dist-info/top_level.txt +1 -0
k_cli/ui/__init__.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""
|
|
2
|
+
k_cli.ui - UI interfaces package for K-CLI for Devs.
|
|
3
|
+
Includes:
|
|
4
|
+
- Tier 1: Fullscreen Cyber Workstation TUI (k_cli.tui.tui_app)
|
|
5
|
+
- Tier 2: Cyber Station Modern Web Dashboard (k_cli.web.server)
|
|
6
|
+
- Tier 3: Streamlined Interactive Terminal REPL (k_cli.ui.simple_repl)
|
|
7
|
+
"""
|
|
8
|
+
from k_cli.ui.simple_repl import SimpleCyberCLI, run_simple_cli
|
|
9
|
+
|
|
10
|
+
__all__ = ["SimpleCyberCLI", "run_simple_cli"]
|
k_cli/ui/simple_repl.py
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
"""
|
|
2
|
+
simple_repl.py - Lightweight, Streamlined Interactive Terminal REPL for K-CLI
|
|
3
|
+
Project Bankai v1.0.0
|
|
4
|
+
|
|
5
|
+
Provides Tier 3 UI for K-CLI:
|
|
6
|
+
- 100% Text-Based & High-Performance (<50ms startup)
|
|
7
|
+
- Full mouse click support and scroll navigation
|
|
8
|
+
- Slash commands: /plan, /audit, /strands, /immune, /models, /keys, /rules, /clear, /exit
|
|
9
|
+
- Real-time token streaming with color-coded persona badges
|
|
10
|
+
- Powered by the same underlying Project Bankai engine (IntentSensor, LLMDriver, Verifier, Orchestrator)
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
import sys
|
|
17
|
+
import time
|
|
18
|
+
import shutil
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
from typing import Optional, List
|
|
21
|
+
|
|
22
|
+
from prompt_toolkit import PromptSession
|
|
23
|
+
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
|
|
24
|
+
from prompt_toolkit.completion import WordCompleter
|
|
25
|
+
from prompt_toolkit.history import FileHistory
|
|
26
|
+
from prompt_toolkit.styles import Style as PtStyle
|
|
27
|
+
|
|
28
|
+
from rich.console import Console
|
|
29
|
+
from rich.markdown import Markdown
|
|
30
|
+
from rich.panel import Panel
|
|
31
|
+
from rich.text import Text
|
|
32
|
+
from rich.table import Table
|
|
33
|
+
from rich.live import Live
|
|
34
|
+
|
|
35
|
+
from k_cli.core.credentials import CredentialsManager, DevPreferencesManager
|
|
36
|
+
from k_cli.core.intent_sensor import IntentSensor, UserIntent
|
|
37
|
+
from k_cli.core.llm_driver import LLMDriver
|
|
38
|
+
from k_cli.core.smart_router import AdaptiveIntentRouter
|
|
39
|
+
from k_cli.tools.rules import load_project_rules
|
|
40
|
+
|
|
41
|
+
console = Console()
|
|
42
|
+
|
|
43
|
+
SLASH_COMMANDS = [
|
|
44
|
+
"/help",
|
|
45
|
+
"/plan",
|
|
46
|
+
"/audit",
|
|
47
|
+
"/strands",
|
|
48
|
+
"/immune",
|
|
49
|
+
"/chaos",
|
|
50
|
+
"/models",
|
|
51
|
+
"/keys",
|
|
52
|
+
"/vault",
|
|
53
|
+
"/rules",
|
|
54
|
+
"/conflict",
|
|
55
|
+
"/github",
|
|
56
|
+
"/clear",
|
|
57
|
+
"/exit",
|
|
58
|
+
"/quit",
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class SimpleCyberCLI:
|
|
63
|
+
"""
|
|
64
|
+
Streamlined, mouse-enabled interactive CLI interface for K-CLI.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
def __init__(
|
|
68
|
+
self,
|
|
69
|
+
workspace_dir: str = ".",
|
|
70
|
+
model_name: Optional[str] = None,
|
|
71
|
+
persona: Optional[str] = None,
|
|
72
|
+
mock_mode: bool = False,
|
|
73
|
+
):
|
|
74
|
+
self.workspace_dir = Path(workspace_dir).resolve()
|
|
75
|
+
self.mock_mode = mock_mode
|
|
76
|
+
CredentialsManager.load_all_credentials()
|
|
77
|
+
self.model_name = model_name or DevPreferencesManager.get_default_model()
|
|
78
|
+
self.persona = persona or DevPreferencesManager.get("default_persona") or "Fullstack AI Systems Engineer"
|
|
79
|
+
|
|
80
|
+
# Setup persistent history
|
|
81
|
+
hist_dir = Path.home() / ".kcli"
|
|
82
|
+
hist_dir.mkdir(parents=True, exist_ok=True)
|
|
83
|
+
self.history_file = hist_dir / "simple_history.txt"
|
|
84
|
+
|
|
85
|
+
self.completer = WordCompleter(SLASH_COMMANDS, ignore_case=True)
|
|
86
|
+
self.pt_style = PtStyle.from_dict({
|
|
87
|
+
"prompt": "bold #00f0ff",
|
|
88
|
+
"model-badge": "#58a6ff",
|
|
89
|
+
"arrow": "#7ee787 bold",
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
self.session = PromptSession(
|
|
93
|
+
history=FileHistory(str(self.history_file)),
|
|
94
|
+
auto_suggest=AutoSuggestFromHistory(),
|
|
95
|
+
completer=self.completer,
|
|
96
|
+
mouse_support=True,
|
|
97
|
+
style=self.pt_style,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
def print_banner(self) -> None:
|
|
101
|
+
from k_cli.core.viewport_engine import ViewportEngine, ViewportMode
|
|
102
|
+
geom = ViewportEngine.compute_geometry()
|
|
103
|
+
console.clear()
|
|
104
|
+
|
|
105
|
+
banner_text = Text()
|
|
106
|
+
banner_text.append("⚡ K-CLI FOR DEVS — STREAMLINED CYBER REPL\n", style="bold cyan")
|
|
107
|
+
if geom.mode != ViewportMode.COMPACT:
|
|
108
|
+
banner_text.append("Project Bankai | Developer: Krishiv Joshi (@krishivjoshi)\n", style="dim")
|
|
109
|
+
banner_text.append(f"• Active Model: {self.model_name} (Adaptive Intent Active)\n", style="bold green")
|
|
110
|
+
banner_text.append(f"• Persona: {self.persona}\n", style="magenta")
|
|
111
|
+
banner_text.append("• Mouse Click & Scroll: ENABLED\n", style="yellow")
|
|
112
|
+
banner_text.append("• Type any prompt or /help. Press Ctrl+C or /exit to quit.", style="dim")
|
|
113
|
+
|
|
114
|
+
panel = Panel(
|
|
115
|
+
banner_text,
|
|
116
|
+
title="[bold cyan]K-CLI SIMPLE UI[/bold cyan]",
|
|
117
|
+
border_style="cyan",
|
|
118
|
+
padding=(0, 1 if geom.mode == ViewportMode.COMPACT else 2),
|
|
119
|
+
width=min(geom.width, 100) if geom.mode != ViewportMode.COMPACT else None,
|
|
120
|
+
)
|
|
121
|
+
console.print(panel)
|
|
122
|
+
console.print()
|
|
123
|
+
|
|
124
|
+
def print_help(self) -> None:
|
|
125
|
+
from k_cli.core.viewport_engine import ViewportEngine
|
|
126
|
+
geom = ViewportEngine.compute_geometry()
|
|
127
|
+
table = Table(
|
|
128
|
+
title="📖 K-CLI Simple REPL Slash Commands",
|
|
129
|
+
border_style="cyan",
|
|
130
|
+
width=min(geom.width, 90) if geom.width > 90 else None,
|
|
131
|
+
)
|
|
132
|
+
table.add_column("Command", style="bold green")
|
|
133
|
+
table.add_column("Description", style="white")
|
|
134
|
+
|
|
135
|
+
table.add_row("/help", "Display this commands directory")
|
|
136
|
+
table.add_row("/plan <TASK>", "Activate Architectural Blueprint planner")
|
|
137
|
+
table.add_row("/audit <TASK>", "Run 5-Model Parallel Consensus Swarm Audit")
|
|
138
|
+
table.add_row("/strands [CRASH]", "Autonomous stack trace triage & auto-healer")
|
|
139
|
+
table.add_row("/immune [FILE]", "Chaos edge-case probe & AST inoculation")
|
|
140
|
+
table.add_row("/models", "List verified online models & switch active model")
|
|
141
|
+
table.add_row("/keys", "View API key & provider configuration status")
|
|
142
|
+
table.add_row("/rules", "View active custom developer instructions (.kclirules)")
|
|
143
|
+
table.add_row("/clear", "Clear screen and reset prompt buffer")
|
|
144
|
+
table.add_row("/exit, /quit", "Exit K-CLI Simple REPL")
|
|
145
|
+
|
|
146
|
+
console.print(table)
|
|
147
|
+
console.print()
|
|
148
|
+
|
|
149
|
+
def handle_models_command(self) -> None:
|
|
150
|
+
from k_cli.core.models_hub import ModelHub
|
|
151
|
+
hub = ModelHub()
|
|
152
|
+
active = hub.get_verified_active_models()
|
|
153
|
+
table = Table(title="🤖 Active Verified Online Models", border_style="cyan")
|
|
154
|
+
table.add_column("Model ID", style="bold cyan")
|
|
155
|
+
table.add_column("Provider", style="yellow")
|
|
156
|
+
table.add_column("Type", style="magenta")
|
|
157
|
+
table.add_column("Status", style="bold green")
|
|
158
|
+
|
|
159
|
+
for m in active:
|
|
160
|
+
table.add_row(m.id, m.provider.value.upper(), "Local SLM" if m.is_local else "Cloud LLM", "✔ ONLINE")
|
|
161
|
+
|
|
162
|
+
console.print(table)
|
|
163
|
+
console.print()
|
|
164
|
+
|
|
165
|
+
def handle_keys_command(self) -> None:
|
|
166
|
+
from k_cli.core.credentials import SUPPORTED_KEYS
|
|
167
|
+
table = Table(title="🔑 Configured API Credentials", border_style="cyan")
|
|
168
|
+
table.add_column("Key Name", style="bold yellow")
|
|
169
|
+
table.add_column("Description", style="white")
|
|
170
|
+
table.add_column("Status", style="bold green")
|
|
171
|
+
|
|
172
|
+
for key_name, label, _ in SUPPORTED_KEYS:
|
|
173
|
+
has_val = bool(os.environ.get(key_name))
|
|
174
|
+
status = "[bold green]✔ Active[/bold green]" if has_val else "[dim red]○ Missing[/dim red]"
|
|
175
|
+
table.add_row(key_name, label, status)
|
|
176
|
+
|
|
177
|
+
console.print(table)
|
|
178
|
+
console.print()
|
|
179
|
+
|
|
180
|
+
def handle_rules_command(self) -> None:
|
|
181
|
+
rules_text = load_project_rules(self.workspace_dir)
|
|
182
|
+
if rules_text:
|
|
183
|
+
console.print(Panel(rules_text, title="[bold green]Active Developer Rules & Instructions[/bold green]", border_style="green"))
|
|
184
|
+
else:
|
|
185
|
+
console.print("[yellow]No custom rules found. Create a .kclirules or K_RULES.md in workspace to customize AI behavior.[/yellow]")
|
|
186
|
+
console.print()
|
|
187
|
+
|
|
188
|
+
def run(self) -> None:
|
|
189
|
+
self.print_banner()
|
|
190
|
+
|
|
191
|
+
while True:
|
|
192
|
+
try:
|
|
193
|
+
# Dynamically construct prompt string
|
|
194
|
+
prompt_str = [
|
|
195
|
+
("class:model-badge", f"[{self.model_name}] "),
|
|
196
|
+
("class:prompt", "k-cli"),
|
|
197
|
+
("class:arrow", " ❯ "),
|
|
198
|
+
]
|
|
199
|
+
user_input = self.session.prompt(prompt_str).strip()
|
|
200
|
+
|
|
201
|
+
if not user_input:
|
|
202
|
+
continue
|
|
203
|
+
|
|
204
|
+
if user_input.lower() in ("/exit", "/quit", "exit", "quit"):
|
|
205
|
+
console.print("[dim cyan]Goodbye! Workstation session persisted.[/dim cyan]")
|
|
206
|
+
break
|
|
207
|
+
|
|
208
|
+
if user_input.lower() == "/clear":
|
|
209
|
+
self.print_banner()
|
|
210
|
+
continue
|
|
211
|
+
|
|
212
|
+
if user_input.lower() == "/help":
|
|
213
|
+
self.print_help()
|
|
214
|
+
continue
|
|
215
|
+
|
|
216
|
+
if user_input.lower() in ("/models", "/model"):
|
|
217
|
+
self.handle_models_command()
|
|
218
|
+
continue
|
|
219
|
+
|
|
220
|
+
if user_input.lower() in ("/keys", "/vault", "/api"):
|
|
221
|
+
self.handle_keys_command()
|
|
222
|
+
continue
|
|
223
|
+
|
|
224
|
+
if user_input.lower() in ("/rules", "/instructions"):
|
|
225
|
+
self.handle_rules_command()
|
|
226
|
+
continue
|
|
227
|
+
|
|
228
|
+
if user_input.startswith("/plan"):
|
|
229
|
+
task = user_input.split(maxsplit=1)[1] if " " in user_input else "Refactor database concurrency architecture"
|
|
230
|
+
console.print(f"[bold cyan]📐 Formulating Milestone Plan for:[/bold cyan] {task}")
|
|
231
|
+
driver = LLMDriver(mock_mode=self.mock_mode)
|
|
232
|
+
plan = driver.generate(f"Create an architectural blueprint and milestone plan for: {task}")
|
|
233
|
+
console.print(Panel(Markdown(plan), title="[bold green]Architectural Blueprint[/bold green]", border_style="green"))
|
|
234
|
+
console.print()
|
|
235
|
+
continue
|
|
236
|
+
|
|
237
|
+
if user_input.startswith("/audit"):
|
|
238
|
+
task = user_input.split(maxsplit=1)[1] if " " in user_input else "Implement high-throughput concurrent ring buffer in Python"
|
|
239
|
+
console.print(f"[bold yellow]🐝 Launching 5+ Multi-Model Swarm Audit for:[/bold yellow] {task}...")
|
|
240
|
+
from k_cli.agents.adversarial_swarm import MultiModelConsensusSwarm
|
|
241
|
+
swarm = MultiModelConsensusSwarm(mock_mode=self.mock_mode)
|
|
242
|
+
report = swarm.audit_and_generate(task_prompt=task)
|
|
243
|
+
console.print(Markdown(report.render_markdown()))
|
|
244
|
+
console.print()
|
|
245
|
+
continue
|
|
246
|
+
|
|
247
|
+
if user_input.startswith("/strands"):
|
|
248
|
+
log_text = user_input.split(maxsplit=1)[1] if " " in user_input else "Traceback: ZeroDivisionError in math_calc.py line 42"
|
|
249
|
+
console.print("[bold red]🚨 Autonomously Triaging & Healing Incident...[/bold red]")
|
|
250
|
+
from k_cli.agents.strands_agent import triage_and_heal_incident
|
|
251
|
+
res = triage_and_heal_incident(log_text, repo_path=str(self.workspace_dir))
|
|
252
|
+
console.print(Panel(res, title="[bold green]Auto-Healer Report[/bold green]", border_style="green"))
|
|
253
|
+
console.print()
|
|
254
|
+
continue
|
|
255
|
+
|
|
256
|
+
if user_input.startswith("/immune") or user_input.startswith("/chaos"):
|
|
257
|
+
target = user_input.split(maxsplit=1)[1] if " " in user_input else None
|
|
258
|
+
from k_cli.tools.chaos_immunity import ChaosImmunityEngine
|
|
259
|
+
engine = ChaosImmunityEngine(repo_path=str(self.workspace_dir))
|
|
260
|
+
if target:
|
|
261
|
+
console.print(f"[bold magenta]🛡️ Inoculating '{target}' against brittle AST patterns...[/bold magenta]")
|
|
262
|
+
rep = engine.inoculate_file(target)
|
|
263
|
+
console.print(Markdown(rep.render_markdown()))
|
|
264
|
+
else:
|
|
265
|
+
console.print("[bold magenta]🛡️ Scanning workspace files for brittle edge cases...[/bold magenta]")
|
|
266
|
+
reports = engine.scan_and_inoculate_repo(max_files=5)
|
|
267
|
+
console.print(f"[bold green]✔ Inoculated {len(reports)} core modules with defensive guards and AST checks.[/bold green]")
|
|
268
|
+
console.print()
|
|
269
|
+
continue
|
|
270
|
+
|
|
271
|
+
# Standard Prompt: Adaptive Intent Sensing & Streaming
|
|
272
|
+
intent_res = IntentSensor.sense(user_input)
|
|
273
|
+
routed_model, route_reason = AdaptiveIntentRouter.resolve_model_for_prompt(user_input, self.model_name)
|
|
274
|
+
|
|
275
|
+
console.print(f"[dim]• Sensed Intent: [bold]{intent_res.mode_label}[/bold] ➔ Routed to [bold cyan]{routed_model}[/bold cyan][/dim]")
|
|
276
|
+
|
|
277
|
+
# Execute with LLMDriver & Developer Instructions
|
|
278
|
+
rules_ctx = load_project_rules(self.workspace_dir)
|
|
279
|
+
driver = LLMDriver(model_name=routed_model, mock_mode=self.mock_mode)
|
|
280
|
+
|
|
281
|
+
full_prompt = f"{rules_ctx}\n\nUser Request: {user_input}" if rules_ctx else user_input
|
|
282
|
+
|
|
283
|
+
with console.status(f"[bold cyan]{intent_res.mode_label}...[/bold cyan]", spinner="dots"):
|
|
284
|
+
response = driver.generate(full_prompt)
|
|
285
|
+
|
|
286
|
+
if intent_res.intent == UserIntent.CHAT:
|
|
287
|
+
console.print(Markdown(response))
|
|
288
|
+
elif intent_res.intent == UserIntent.PLAN:
|
|
289
|
+
console.print(Panel(Markdown(response), title="[bold green]Architectural Blueprint[/bold green]", border_style="green"))
|
|
290
|
+
else:
|
|
291
|
+
console.print(Panel(Markdown(response), title="[bold cyan]K-CLI Agent Response[/bold cyan]", border_style="cyan"))
|
|
292
|
+
|
|
293
|
+
console.print()
|
|
294
|
+
|
|
295
|
+
except (KeyboardInterrupt, EOFError):
|
|
296
|
+
console.print("\n[dim cyan]Session ended.[/dim cyan]")
|
|
297
|
+
break
|
|
298
|
+
except Exception as e:
|
|
299
|
+
console.print(f"[bold red]Error:[/bold red] {e}")
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def run_simple_cli(
|
|
303
|
+
workspace_dir: str = ".",
|
|
304
|
+
model_name: Optional[str] = None,
|
|
305
|
+
persona: Optional[str] = None,
|
|
306
|
+
mock_mode: bool = False,
|
|
307
|
+
) -> None:
|
|
308
|
+
"""Entry point function for launching K-CLI Simple REPL."""
|
|
309
|
+
cli = SimpleCyberCLI(
|
|
310
|
+
workspace_dir=workspace_dir,
|
|
311
|
+
model_name=model_name,
|
|
312
|
+
persona=persona,
|
|
313
|
+
mock_mode=mock_mode,
|
|
314
|
+
)
|
|
315
|
+
cli.run()
|