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
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"""
|
|
2
|
+
intent_sensor.py - Real-Time Zero-Latency User Intent Sensor & Adaptive Router for K-CLI
|
|
3
|
+
Project Bankai v1.0.0
|
|
4
|
+
|
|
5
|
+
Classifies user prompts in microseconds (<0.1ms) into high-level operational intents:
|
|
6
|
+
1. CHAT / CONVERSATION: Direct ultra-fast streaming response without heavy agent tool overhead.
|
|
7
|
+
2. PLAN / ARCHITECTURE: Generates step-by-step milestone execution blueprints.
|
|
8
|
+
3. BUILD / CODE: Full agentic code generator with surgical AST verification and test execution.
|
|
9
|
+
4. TRIAGE / CRASH: Instant stack trace diagnosis and incident auto-healing.
|
|
10
|
+
5. IMMUNITY / CHAOS: Edge-case resilience probing and defensive inoculation.
|
|
11
|
+
6. EXPLAIN / KNOWLEDGE: Semantic codebase & devdocs retrieval.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import re
|
|
17
|
+
from dataclasses import dataclass
|
|
18
|
+
from enum import Enum
|
|
19
|
+
from typing import Optional, Tuple
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class UserIntent(str, Enum):
|
|
23
|
+
CHAT = "chat" # Casual conversation, greetings, simple Q&A
|
|
24
|
+
PLAN = "plan" # Strategy, architectural design, milestones
|
|
25
|
+
BUILD = "build" # Writing new code, features, refactoring
|
|
26
|
+
TRIAGE = "triage" # Debugging errors, stack traces, exceptions
|
|
27
|
+
IMMUNITY = "immunity" # Chaos edge-cases, security audits
|
|
28
|
+
EXPLAIN = "explain" # Codebase walkthrough, concept explanations
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ExecutionStrategy(str, Enum):
|
|
32
|
+
DIRECT_FAST_STREAM = "direct_fast_stream" # Sub-second streaming, bypasses heavy tool chain
|
|
33
|
+
PLANNING_BLUEPRINT = "planning_blueprint" # Structured blueprint generation
|
|
34
|
+
FULL_AGENTIC_BUILD = "full_agentic_build" # Full multi-turn verification loop
|
|
35
|
+
INCIDENT_AUTOHEAL = "incident_autoheal" # Root cause analysis & surgical repair
|
|
36
|
+
CHAOS_INOCULATION = "chaos_inoculation" # AST chaos probe & test generator
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass
|
|
40
|
+
class IntentSensorResult:
|
|
41
|
+
intent: UserIntent
|
|
42
|
+
confidence: float
|
|
43
|
+
mode_label: str
|
|
44
|
+
execution_strategy: ExecutionStrategy
|
|
45
|
+
skip_heavy_tools: bool
|
|
46
|
+
reasoning: str
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class IntentSensor:
|
|
50
|
+
"""
|
|
51
|
+
Sub-millisecond heuristic intent classifier for adaptive routing.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
# Regex patterns for fast-path detection
|
|
55
|
+
CHAT_GREETINGS = re.compile(
|
|
56
|
+
r"^(hi|hello|hey|hey there|yo|greetings|howdy|sup|what's up|good (morning|afternoon|evening)|who are you|what is your name|how are you|how's it going|what can you do|thanks|thank you|thanks a lot|cool|awesome|great|bye|goodbye)\b",
|
|
57
|
+
re.IGNORECASE,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
CHAT_SIMPLE_QA = re.compile(
|
|
61
|
+
r"^(what is|who is|when was|define|meaning of|tell me a joke|tell me about yourself|are you ai|are you real)\b",
|
|
62
|
+
re.IGNORECASE,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
PLAN_PATTERNS = re.compile(
|
|
66
|
+
r"\b(plan|design|architect|roadmap|strategy|blueprint|breakdown|milestones|architecture diagram|how should we structure|best approach to|how to structure)\b",
|
|
67
|
+
re.IGNORECASE,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
TRIAGE_PATTERNS = re.compile(
|
|
71
|
+
r"(traceback \(most recent call last\)|panic:|error:|exception:|failed with exit code|nullpointerexception|typeerror:|syntaxerror:|valueerror:|keyerror:|segmentation fault)",
|
|
72
|
+
re.IGNORECASE,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
IMMUNITY_PATTERNS = re.compile(
|
|
76
|
+
r"\b(chaos|immunity|inoculate|brittle|edge[- ]?case|security audit|vulnerability|redos|sql injection|sanitize|hardening)\b",
|
|
77
|
+
re.IGNORECASE,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
EXPLAIN_PATTERNS = re.compile(
|
|
81
|
+
r"\b(explain|walkthrough|how does|does (the|this|my)|is (the|this|my)|look solid|review|audit|check (my|the|this)|how to use|documentation for)\b",
|
|
82
|
+
re.IGNORECASE,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
BUILD_PATTERNS = re.compile(
|
|
86
|
+
r"\b(build|create|implement|write|generate|add|refactor|fix|update|modify|scaffold|endpoint|api|database|write code|code up)\b",
|
|
87
|
+
re.IGNORECASE,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
@classmethod
|
|
91
|
+
def sense(cls, prompt: str) -> IntentSensorResult:
|
|
92
|
+
text = prompt.strip()
|
|
93
|
+
if not text:
|
|
94
|
+
return IntentSensorResult(
|
|
95
|
+
intent=UserIntent.CHAT,
|
|
96
|
+
confidence=1.0,
|
|
97
|
+
mode_label="💬 Fast Chat",
|
|
98
|
+
execution_strategy=ExecutionStrategy.DIRECT_FAST_STREAM,
|
|
99
|
+
skip_heavy_tools=True,
|
|
100
|
+
reasoning="Empty prompt defaults to conversational fast stream.",
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
# 1. Check for Crash / Triage (Highest priority if stacktrace detected)
|
|
104
|
+
if cls.TRIAGE_PATTERNS.search(text):
|
|
105
|
+
return IntentSensorResult(
|
|
106
|
+
intent=UserIntent.TRIAGE,
|
|
107
|
+
confidence=0.98,
|
|
108
|
+
mode_label="🚨 Incident Auto-Heal",
|
|
109
|
+
execution_strategy=ExecutionStrategy.INCIDENT_AUTOHEAL,
|
|
110
|
+
skip_heavy_tools=False,
|
|
111
|
+
reasoning="Detected exception stack trace or error log.",
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
# 2. Check for Planning / Strategy (Priority over simple question words)
|
|
115
|
+
if cls.PLAN_PATTERNS.search(text) and not any(w in text.lower() for w in ("implement", "write code", "fix")):
|
|
116
|
+
return IntentSensorResult(
|
|
117
|
+
intent=UserIntent.PLAN,
|
|
118
|
+
confidence=0.90,
|
|
119
|
+
mode_label="📐 Architectural Planner",
|
|
120
|
+
execution_strategy=ExecutionStrategy.PLANNING_BLUEPRINT,
|
|
121
|
+
skip_heavy_tools=True,
|
|
122
|
+
reasoning="Strategic planning request. Synthesizing architecture blueprint without file modifications.",
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
# 3. Check for Chaos / Immunity / Security
|
|
126
|
+
if cls.IMMUNITY_PATTERNS.search(text):
|
|
127
|
+
return IntentSensorResult(
|
|
128
|
+
intent=UserIntent.IMMUNITY,
|
|
129
|
+
confidence=0.92,
|
|
130
|
+
mode_label="🛡️ Chaos & Security Immunity",
|
|
131
|
+
execution_strategy=ExecutionStrategy.CHAOS_INOCULATION,
|
|
132
|
+
skip_heavy_tools=False,
|
|
133
|
+
reasoning="Chaos edge-case probing or security hardening requested.",
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
# 4. Check for Greetings / Chit-Chat / Quick Q&A
|
|
137
|
+
if cls.CHAT_GREETINGS.match(text) or (cls.CHAT_SIMPLE_QA.match(text) and len(text.split()) < 12 and not cls.BUILD_PATTERNS.search(text)):
|
|
138
|
+
return IntentSensorResult(
|
|
139
|
+
intent=UserIntent.CHAT,
|
|
140
|
+
confidence=0.95,
|
|
141
|
+
mode_label="⚡ Instant Conversation",
|
|
142
|
+
execution_strategy=ExecutionStrategy.DIRECT_FAST_STREAM,
|
|
143
|
+
skip_heavy_tools=True,
|
|
144
|
+
reasoning="Direct conversation query. Bypassing heavy agentic tools for sub-second latency.",
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
# 4. Check for Chaos / Immunity / Security
|
|
148
|
+
if cls.IMMUNITY_PATTERNS.search(text):
|
|
149
|
+
return IntentSensorResult(
|
|
150
|
+
intent=UserIntent.IMMUNITY,
|
|
151
|
+
confidence=0.92,
|
|
152
|
+
mode_label="🛡️ Chaos & Security Immunity",
|
|
153
|
+
execution_strategy=ExecutionStrategy.CHAOS_INOCULATION,
|
|
154
|
+
skip_heavy_tools=False,
|
|
155
|
+
reasoning="Chaos edge-case probing or security hardening requested.",
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
# 5. Check for Codebase Walkthrough / Explanations
|
|
159
|
+
if cls.EXPLAIN_PATTERNS.search(text) and not any(w in text.lower() for w in ("create", "build", "write code")):
|
|
160
|
+
return IntentSensorResult(
|
|
161
|
+
intent=UserIntent.EXPLAIN,
|
|
162
|
+
confidence=0.88,
|
|
163
|
+
mode_label="📖 Codebase Q&A",
|
|
164
|
+
execution_strategy=ExecutionStrategy.DIRECT_FAST_STREAM,
|
|
165
|
+
skip_heavy_tools=True,
|
|
166
|
+
reasoning="Explanatory Q&A query with semantic doc retrieval.",
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
# 6. Default to Autonomous Builder
|
|
170
|
+
return IntentSensorResult(
|
|
171
|
+
intent=UserIntent.BUILD,
|
|
172
|
+
confidence=0.85,
|
|
173
|
+
mode_label="🔨 Autonomous Builder",
|
|
174
|
+
execution_strategy=ExecutionStrategy.FULL_AGENTIC_BUILD,
|
|
175
|
+
skip_heavy_tools=False,
|
|
176
|
+
reasoning="Engineering coding task requiring AST verification and surgical tool execution.",
|
|
177
|
+
)
|