@drico2008/fincli 0.1.3 → 0.2.2
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.
- package/LICENSE +21 -0
- package/README.md +909 -684
- package/fincli/__init__.py +3 -3
- package/fincli/app/agents/__init__.py +5 -0
- package/fincli/app/agents/registry.py +76 -0
- package/fincli/app/analysis/ai_prompts.py +23 -16
- package/fincli/app/analysis/analyzer.py +107 -100
- package/fincli/app/analysis/assistant_context.py +187 -160
- package/fincli/app/analysis/backtest.py +179 -0
- package/fincli/app/analysis/gameplay_plan.py +79 -0
- package/fincli/app/analysis/indicators.py +1 -1
- package/fincli/app/analysis/market_structure.py +1 -1
- package/fincli/app/analysis/multi_timeframe.py +180 -0
- package/fincli/app/analysis/trading_methods.py +144 -0
- package/fincli/app/cli/commands.py +105 -77
- package/fincli/app/cli/router.py +2143 -1121
- package/fincli/app/connectors/__init__.py +5 -0
- package/fincli/app/connectors/catalog.py +148 -0
- package/fincli/app/connectors/news_connectors.py +412 -0
- package/fincli/app/modules/alerts.py +80 -0
- package/fincli/app/modules/economic_calendar.py +374 -1
- package/fincli/app/modules/reports.py +151 -0
- package/fincli/app/modules/scanner.py +111 -93
- package/fincli/app/modules/session_history.py +113 -0
- package/fincli/app/modules/transactions.py +84 -84
- package/fincli/app/modules/user_profile.py +84 -0
- package/fincli/app/plugins/loader.py +72 -0
- package/fincli/app/providers/ai/anthropic_provider.py +8 -7
- package/fincli/app/providers/ai/gemini_provider.py +8 -7
- package/fincli/app/providers/ai/groq_provider.py +8 -7
- package/fincli/app/providers/ai/huggingface_provider.py +8 -7
- package/fincli/app/providers/ai/manager.py +60 -60
- package/fincli/app/providers/ai/openai_provider.py +8 -7
- package/fincli/app/providers/ai/openrouter_provider.py +8 -7
- package/fincli/app/providers/ai/together_provider.py +8 -7
- package/fincli/app/providers/market/alphavantage_provider.py +194 -0
- package/fincli/app/providers/market/base.py +98 -77
- package/fincli/app/providers/market/custom_provider.py +186 -169
- package/fincli/app/providers/market/manager.py +85 -2
- package/fincli/app/providers/market/news_provider.py +4 -4
- package/fincli/app/providers/market/symbols.py +143 -0
- package/fincli/app/providers/market/twelvedata_provider.py +167 -167
- package/fincli/app/providers/market/yfinance_provider.py +1 -1
- package/fincli/app/research/__init__.py +7 -0
- package/fincli/app/research/engine.py +75 -0
- package/fincli/app/research/formatter.py +22 -0
- package/fincli/app/research/models.py +18 -0
- package/fincli/app/research/prompt_builder.py +47 -0
- package/fincli/app/services/macro_data.py +50 -0
- package/fincli/app/services/market_data.py +203 -203
- package/fincli/app/services/news_aggregator.py +90 -0
- package/fincli/app/services/web_research.py +267 -0
- package/fincli/app/storage/cache.py +2 -2
- package/fincli/app/storage/config.py +122 -88
- package/fincli/app/storage/database.py +201 -85
- package/fincli/app/storage/secrets.py +12 -3
- package/fincli/app/tui/components.py +68 -50
- package/fincli/app/tui/layout.py +270 -258
- package/fincli/app/tui/market_provider_selector.py +6 -1
- package/fincli/app/tui/model_selector.py +11 -3
- package/fincli/app/tui/theme.py +134 -74
- package/fincli/app/utils/formatting.py +125 -12
- package/npm/bin/fincli.js +9 -2
- package/package.json +23 -23
- package/pyproject.toml +35 -35
|
@@ -1,101 +1,217 @@
|
|
|
1
|
-
"""SQLite storage for FinCLI local data."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
from contextlib import closing
|
|
7
|
-
import sqlite3
|
|
8
|
-
from typing import Iterable
|
|
9
|
-
|
|
10
|
-
from fincli.app.storage.config import APP_DIR
|
|
11
|
-
from fincli.app.utils.errors import StorageError
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
DB_FILE = APP_DIR / "fincli.db"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class FinCLIDatabase:
|
|
18
|
-
"""Small SQLite wrapper for watchlist, portfolio, and journal data."""
|
|
19
|
-
|
|
20
|
-
def __init__(self, db_file: Path = DB_FILE) -> None:
|
|
21
|
-
self.db_file = db_file
|
|
22
|
-
self.db_file.parent.mkdir(parents=True, exist_ok=True)
|
|
23
|
-
self.initialize()
|
|
24
|
-
|
|
25
|
-
def connect(self) -> sqlite3.Connection:
|
|
26
|
-
connection = sqlite3.connect(self.db_file)
|
|
27
|
-
connection.row_factory = sqlite3.Row
|
|
28
|
-
return connection
|
|
29
|
-
|
|
30
|
-
def initialize(self) -> None:
|
|
31
|
-
try:
|
|
32
|
-
with closing(self.connect()) as db:
|
|
33
|
-
with db:
|
|
34
|
-
db.executescript(
|
|
35
|
-
"""
|
|
36
|
-
CREATE TABLE IF NOT EXISTS watchlist (
|
|
37
|
-
symbol TEXT PRIMARY KEY,
|
|
38
|
-
group_name TEXT DEFAULT 'default',
|
|
39
|
-
created_at TEXT DEFAULT CURRENT_TIMESTAMP
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
CREATE TABLE IF NOT EXISTS portfolio_positions (
|
|
43
|
-
symbol TEXT PRIMARY KEY,
|
|
44
|
-
quantity REAL NOT NULL,
|
|
45
|
-
average_price REAL NOT NULL,
|
|
46
|
-
currency TEXT DEFAULT 'USD',
|
|
47
|
-
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
|
|
48
|
-
updated_at TEXT DEFAULT CURRENT_TIMESTAMP
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
CREATE TABLE IF NOT EXISTS journal_entries (
|
|
52
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
53
|
-
instrument TEXT NOT NULL,
|
|
54
|
-
bias TEXT DEFAULT '',
|
|
55
|
-
entry_reason TEXT DEFAULT '',
|
|
56
|
-
exit_reason TEXT DEFAULT '',
|
|
57
|
-
result TEXT DEFAULT '',
|
|
58
|
-
emotion TEXT DEFAULT '',
|
|
59
|
-
lesson TEXT DEFAULT '',
|
|
60
|
-
tags TEXT DEFAULT '',
|
|
61
|
-
created_at TEXT DEFAULT CURRENT_TIMESTAMP
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
CREATE TABLE IF NOT EXISTS portfolio_transactions (
|
|
1
|
+
"""SQLite storage for FinCLI local data."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from contextlib import closing
|
|
7
|
+
import sqlite3
|
|
8
|
+
from typing import Iterable
|
|
9
|
+
|
|
10
|
+
from fincli.app.storage.config import APP_DIR
|
|
11
|
+
from fincli.app.utils.errors import StorageError
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
DB_FILE = APP_DIR / "fincli.db"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class FinCLIDatabase:
|
|
18
|
+
"""Small SQLite wrapper for watchlist, portfolio, and journal data."""
|
|
19
|
+
|
|
20
|
+
def __init__(self, db_file: Path = DB_FILE) -> None:
|
|
21
|
+
self.db_file = db_file
|
|
22
|
+
self.db_file.parent.mkdir(parents=True, exist_ok=True)
|
|
23
|
+
self.initialize()
|
|
24
|
+
|
|
25
|
+
def connect(self) -> sqlite3.Connection:
|
|
26
|
+
connection = sqlite3.connect(self.db_file)
|
|
27
|
+
connection.row_factory = sqlite3.Row
|
|
28
|
+
return connection
|
|
29
|
+
|
|
30
|
+
def initialize(self) -> None:
|
|
31
|
+
try:
|
|
32
|
+
with closing(self.connect()) as db:
|
|
33
|
+
with db:
|
|
34
|
+
db.executescript(
|
|
35
|
+
"""
|
|
36
|
+
CREATE TABLE IF NOT EXISTS watchlist (
|
|
37
|
+
symbol TEXT PRIMARY KEY,
|
|
38
|
+
group_name TEXT DEFAULT 'default',
|
|
39
|
+
created_at TEXT DEFAULT CURRENT_TIMESTAMP
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
CREATE TABLE IF NOT EXISTS portfolio_positions (
|
|
43
|
+
symbol TEXT PRIMARY KEY,
|
|
44
|
+
quantity REAL NOT NULL,
|
|
45
|
+
average_price REAL NOT NULL,
|
|
46
|
+
currency TEXT DEFAULT 'USD',
|
|
47
|
+
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
|
|
48
|
+
updated_at TEXT DEFAULT CURRENT_TIMESTAMP
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
CREATE TABLE IF NOT EXISTS journal_entries (
|
|
52
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
53
|
+
instrument TEXT NOT NULL,
|
|
54
|
+
bias TEXT DEFAULT '',
|
|
55
|
+
entry_reason TEXT DEFAULT '',
|
|
56
|
+
exit_reason TEXT DEFAULT '',
|
|
57
|
+
result TEXT DEFAULT '',
|
|
58
|
+
emotion TEXT DEFAULT '',
|
|
59
|
+
lesson TEXT DEFAULT '',
|
|
60
|
+
tags TEXT DEFAULT '',
|
|
61
|
+
created_at TEXT DEFAULT CURRENT_TIMESTAMP
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
CREATE TABLE IF NOT EXISTS portfolio_transactions (
|
|
65
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
66
|
+
action TEXT NOT NULL,
|
|
67
|
+
symbol TEXT NOT NULL,
|
|
68
|
+
quantity REAL NOT NULL,
|
|
69
|
+
price REAL NOT NULL,
|
|
70
|
+
currency TEXT DEFAULT 'USD',
|
|
71
|
+
realized_pnl REAL DEFAULT 0,
|
|
72
|
+
created_at TEXT DEFAULT CURRENT_TIMESTAMP
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
CREATE TABLE IF NOT EXISTS market_cache (
|
|
76
|
+
namespace TEXT NOT NULL,
|
|
77
|
+
cache_key TEXT NOT NULL,
|
|
78
|
+
payload TEXT NOT NULL,
|
|
79
|
+
expires_at REAL NOT NULL,
|
|
80
|
+
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
|
|
81
|
+
PRIMARY KEY (namespace, cache_key)
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
CREATE TABLE IF NOT EXISTS sessions (
|
|
85
|
+
id TEXT PRIMARY KEY,
|
|
86
|
+
title TEXT NOT NULL,
|
|
87
|
+
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
|
|
88
|
+
updated_at TEXT DEFAULT CURRENT_TIMESTAMP
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
CREATE TABLE IF NOT EXISTS session_events (
|
|
92
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
93
|
+
session_id TEXT NOT NULL,
|
|
94
|
+
command TEXT NOT NULL,
|
|
95
|
+
status TEXT NOT NULL,
|
|
96
|
+
output_preview TEXT DEFAULT '',
|
|
97
|
+
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
|
|
98
|
+
FOREIGN KEY (session_id) REFERENCES sessions(id) ON DELETE CASCADE
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
CREATE TABLE IF NOT EXISTS alerts (
|
|
65
102
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
66
|
-
action TEXT NOT NULL,
|
|
67
103
|
symbol TEXT NOT NULL,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
104
|
+
condition TEXT NOT NULL,
|
|
105
|
+
target REAL NOT NULL,
|
|
106
|
+
note TEXT DEFAULT '',
|
|
107
|
+
active INTEGER DEFAULT 1,
|
|
108
|
+
triggered_at TEXT DEFAULT '',
|
|
72
109
|
created_at TEXT DEFAULT CURRENT_TIMESTAMP
|
|
73
110
|
);
|
|
74
111
|
|
|
75
|
-
CREATE TABLE IF NOT EXISTS
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
112
|
+
CREATE TABLE IF NOT EXISTS user_profile (
|
|
113
|
+
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
114
|
+
name TEXT NOT NULL,
|
|
115
|
+
equity REAL NOT NULL,
|
|
116
|
+
currency TEXT NOT NULL,
|
|
117
|
+
leverage TEXT NOT NULL,
|
|
118
|
+
years_in_investment REAL NOT NULL,
|
|
119
|
+
gameplay TEXT NOT NULL,
|
|
120
|
+
updated_at TEXT DEFAULT CURRENT_TIMESTAMP
|
|
82
121
|
);
|
|
83
122
|
"""
|
|
84
123
|
)
|
|
124
|
+
_migrate_user_profile_schema(db)
|
|
85
125
|
except sqlite3.Error as exc:
|
|
86
126
|
raise StorageError("Database lokal gagal diinisialisasi.") from exc
|
|
87
|
-
|
|
88
|
-
def execute(self, sql: str, params: Iterable[object] = ()) -> None:
|
|
89
|
-
try:
|
|
90
|
-
with closing(self.connect()) as db:
|
|
91
|
-
with db:
|
|
92
|
-
db.execute(sql, tuple(params))
|
|
93
|
-
except sqlite3.Error as exc:
|
|
94
|
-
raise StorageError("Operasi database gagal.") from exc
|
|
95
|
-
|
|
127
|
+
|
|
128
|
+
def execute(self, sql: str, params: Iterable[object] = ()) -> None:
|
|
129
|
+
try:
|
|
130
|
+
with closing(self.connect()) as db:
|
|
131
|
+
with db:
|
|
132
|
+
db.execute(sql, tuple(params))
|
|
133
|
+
except sqlite3.Error as exc:
|
|
134
|
+
raise StorageError("Operasi database gagal.") from exc
|
|
135
|
+
|
|
96
136
|
def query(self, sql: str, params: Iterable[object] = ()) -> list[sqlite3.Row]:
|
|
97
137
|
try:
|
|
98
138
|
with closing(self.connect()) as db:
|
|
99
139
|
return list(db.execute(sql, tuple(params)).fetchall())
|
|
100
140
|
except sqlite3.Error as exc:
|
|
101
141
|
raise StorageError("Query database gagal.") from exc
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _migrate_user_profile_schema(db: sqlite3.Connection) -> None:
|
|
145
|
+
"""Normalize older user_profile schemas to the v0.2.2 canonical shape."""
|
|
146
|
+
|
|
147
|
+
columns = {str(row["name"]) for row in db.execute("PRAGMA table_info(user_profile)").fetchall()}
|
|
148
|
+
canonical = {"id", "name", "equity", "currency", "leverage", "years_in_investment", "gameplay", "updated_at"}
|
|
149
|
+
if canonical.issubset(columns):
|
|
150
|
+
return
|
|
151
|
+
|
|
152
|
+
rows = list(db.execute("SELECT * FROM user_profile").fetchall())
|
|
153
|
+
legacy_profile = _legacy_profile_payload(rows[0]) if rows else None
|
|
154
|
+
db.execute("DROP TABLE user_profile")
|
|
155
|
+
db.execute(
|
|
156
|
+
"""
|
|
157
|
+
CREATE TABLE user_profile (
|
|
158
|
+
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
159
|
+
name TEXT NOT NULL,
|
|
160
|
+
equity REAL NOT NULL,
|
|
161
|
+
currency TEXT NOT NULL,
|
|
162
|
+
leverage TEXT NOT NULL,
|
|
163
|
+
years_in_investment REAL NOT NULL,
|
|
164
|
+
gameplay TEXT NOT NULL,
|
|
165
|
+
updated_at TEXT DEFAULT CURRENT_TIMESTAMP
|
|
166
|
+
)
|
|
167
|
+
"""
|
|
168
|
+
)
|
|
169
|
+
if legacy_profile is None:
|
|
170
|
+
return
|
|
171
|
+
db.execute(
|
|
172
|
+
"""
|
|
173
|
+
INSERT INTO user_profile (id, name, equity, currency, leverage, years_in_investment, gameplay, updated_at)
|
|
174
|
+
VALUES (1, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
|
175
|
+
""",
|
|
176
|
+
legacy_profile,
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def _legacy_profile_payload(row: sqlite3.Row) -> tuple[object, ...]:
|
|
181
|
+
keys = set(row.keys())
|
|
182
|
+
name = row["name"] if "name" in keys else "User"
|
|
183
|
+
equity = row["equity"] if "equity" in keys else row["equity_amount"] if "equity_amount" in keys else 0
|
|
184
|
+
currency = row["currency"] if "currency" in keys else row["equity_currency"] if "equity_currency" in keys else "USD"
|
|
185
|
+
leverage = row["leverage"] if "leverage" in keys else "1:1"
|
|
186
|
+
years = (
|
|
187
|
+
row["years_in_investment"]
|
|
188
|
+
if "years_in_investment" in keys
|
|
189
|
+
else row["experience_years"]
|
|
190
|
+
if "experience_years" in keys
|
|
191
|
+
else 0
|
|
192
|
+
)
|
|
193
|
+
gameplay = _normalize_legacy_gameplay(str(row["gameplay"])) if "gameplay" in keys else _classify_legacy_gameplay(float(equity))
|
|
194
|
+
return (name, equity, currency, leverage, years, gameplay)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _normalize_legacy_gameplay(value: str) -> str:
|
|
198
|
+
normalized = value.strip().lower().replace("-", "_").replace(" ", "_")
|
|
199
|
+
return {
|
|
200
|
+
"scalper": "Scalper",
|
|
201
|
+
"intra_day": "Intra day",
|
|
202
|
+
"intraday": "Intra day",
|
|
203
|
+
"day_trade": "Day trade",
|
|
204
|
+
"day_trader": "Day trade",
|
|
205
|
+
"swing": "Swing/Investor",
|
|
206
|
+
"investor": "Swing/Investor",
|
|
207
|
+
}.get(normalized, value.strip() or "Scalper")
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _classify_legacy_gameplay(equity: float) -> str:
|
|
211
|
+
if equity <= 400:
|
|
212
|
+
return "Scalper"
|
|
213
|
+
if equity <= 1000:
|
|
214
|
+
return "Intra day"
|
|
215
|
+
if equity <= 5000:
|
|
216
|
+
return "Day trade"
|
|
217
|
+
return "Swing/Investor"
|
|
@@ -12,9 +12,15 @@ from fincli.app.utils.errors import ConfigError
|
|
|
12
12
|
SECRETS_FILE = APP_DIR / "secrets.env"
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
def load_local_secrets(
|
|
15
|
+
def load_local_secrets(
|
|
16
|
+
path: Path | None = None,
|
|
17
|
+
*,
|
|
18
|
+
override: bool = False,
|
|
19
|
+
override_keys: set[str] | None = None,
|
|
20
|
+
) -> None:
|
|
16
21
|
"""Load persisted secrets into process environment."""
|
|
17
22
|
path = path or SECRETS_FILE
|
|
23
|
+
override_keys = override_keys or set()
|
|
18
24
|
if not path.exists():
|
|
19
25
|
return
|
|
20
26
|
for line in path.read_text(encoding="utf-8").splitlines():
|
|
@@ -24,7 +30,7 @@ def load_local_secrets(path: Path | None = None, *, override: bool = False) -> N
|
|
|
24
30
|
key, value = stripped.split("=", 1)
|
|
25
31
|
key = key.strip()
|
|
26
32
|
value = _unquote(value.strip())
|
|
27
|
-
if key and (override or key not in os.environ):
|
|
33
|
+
if key and (override or key in override_keys or key not in os.environ or os.environ.get(key, "") == ""):
|
|
28
34
|
os.environ[key] = value
|
|
29
35
|
|
|
30
36
|
|
|
@@ -72,8 +78,11 @@ def read_secrets(path: Path | None = None) -> dict[str, str]:
|
|
|
72
78
|
def secret_source(env_key: str, path: Path | None = None) -> str:
|
|
73
79
|
"""Return a display-safe source for a secret."""
|
|
74
80
|
path = path or SECRETS_FILE
|
|
81
|
+
current = os.getenv(env_key)
|
|
82
|
+
if not current:
|
|
83
|
+
return "-"
|
|
75
84
|
if env_key in os.environ:
|
|
76
|
-
if
|
|
85
|
+
if read_secrets(path).get(env_key) == current:
|
|
77
86
|
return "~/.fincli/secrets.env"
|
|
78
87
|
return "environment/.env"
|
|
79
88
|
return "-"
|
|
@@ -1,55 +1,73 @@
|
|
|
1
|
-
"""Reusable TUI components."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from rich.markdown import Markdown
|
|
6
|
-
from rich.panel import Panel
|
|
7
|
-
from rich.table import Table
|
|
8
|
-
from rich.text import Text
|
|
1
|
+
"""Reusable TUI components."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from rich.markdown import Markdown
|
|
6
|
+
from rich.panel import Panel
|
|
7
|
+
from rich.table import Table
|
|
8
|
+
from rich.text import Text
|
|
9
9
|
from textual.widgets import Static
|
|
10
|
-
|
|
11
|
-
from fincli.app.cli.commands import CommandSpec
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class CommandPalette(Static):
|
|
15
|
-
"""Slash command palette shown near the command input."""
|
|
16
|
-
|
|
17
|
-
def render_commands(self, commands: list[CommandSpec], query: str = "") -> None:
|
|
18
|
-
table = Table.grid(expand=True)
|
|
19
|
-
table.add_column("Command", style="white", no_wrap=True, ratio=1)
|
|
20
|
-
table.add_column("Description", style="bright_black", justify="right", ratio=3)
|
|
21
|
-
|
|
22
|
-
for index, command in enumerate(commands):
|
|
23
|
-
command_text = command.name
|
|
24
|
-
description = command.description
|
|
25
|
-
if index == 0:
|
|
26
|
-
command_text = f"[black on cyan]> {command.name}[/]"
|
|
27
|
-
description = f"[black on cyan]{command.description}[/]"
|
|
28
|
-
table.add_row(command_text, description)
|
|
29
|
-
|
|
30
|
-
if len(commands) > 6:
|
|
31
|
-
table.add_row("[bright_black]v more[/]", "[bright_black]Ketik command lebih spesifik[/]")
|
|
32
|
-
|
|
33
|
-
title = f"[cyan]>[/] {query or '/'}"
|
|
34
|
-
self.update(Panel(table, title=title, border_style="bright_black", padding=(0, 1)))
|
|
35
|
-
|
|
36
|
-
def clear_palette(self) -> None:
|
|
37
|
-
self.update("")
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def format_user_message(message: str) -> Panel:
|
|
41
|
-
text = Text()
|
|
42
|
-
text.append("> ", style="bold cyan")
|
|
43
|
-
text.append(message, style="bold white")
|
|
44
|
-
return Panel(text, border_style="#2f332f", style="on #2b2f2b", padding=(0, 1))
|
|
10
|
+
|
|
11
|
+
from fincli.app.cli.commands import CommandSpec
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class CommandPalette(Static):
|
|
15
|
+
"""Slash command palette shown near the command input."""
|
|
16
|
+
|
|
17
|
+
def render_commands(self, commands: list[CommandSpec], query: str = "") -> None:
|
|
18
|
+
table = Table.grid(expand=True)
|
|
19
|
+
table.add_column("Command", style="white", no_wrap=True, ratio=1)
|
|
20
|
+
table.add_column("Description", style="bright_black", justify="right", ratio=3)
|
|
21
|
+
|
|
22
|
+
for index, command in enumerate(commands):
|
|
23
|
+
command_text = command.name
|
|
24
|
+
description = command.description
|
|
25
|
+
if index == 0:
|
|
26
|
+
command_text = f"[black on cyan]> {command.name}[/]"
|
|
27
|
+
description = f"[black on cyan]{command.description}[/]"
|
|
28
|
+
table.add_row(command_text, description)
|
|
29
|
+
|
|
30
|
+
if len(commands) > 6:
|
|
31
|
+
table.add_row("[bright_black]v more[/]", "[bright_black]Ketik command lebih spesifik[/]")
|
|
32
|
+
|
|
33
|
+
title = f"[cyan]>[/] {query or '/'}"
|
|
34
|
+
self.update(Panel(table, title=title, border_style="bright_black", padding=(0, 1)))
|
|
35
|
+
|
|
36
|
+
def clear_palette(self) -> None:
|
|
37
|
+
self.update("")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def format_user_message(message: str) -> Panel:
|
|
41
|
+
text = Text()
|
|
42
|
+
text.append("> ", style="bold cyan")
|
|
43
|
+
text.append(message, style="bold white")
|
|
44
|
+
return Panel(text, border_style="#2f332f", style="on #2b2f2b", padding=(0, 1))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def format_thinking_message(message: str) -> Text:
|
|
48
|
+
text = Text()
|
|
49
|
+
text.append("> Thinking: ", style="dim")
|
|
50
|
+
text.append(message, style="italic dim")
|
|
51
|
+
return text
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def format_ai_message(message: str) -> Markdown:
|
|
55
|
+
return Markdown(message)
|
|
45
56
|
|
|
46
57
|
|
|
47
|
-
def
|
|
48
|
-
|
|
49
|
-
text.append("> Thinking: ", style="dim")
|
|
50
|
-
text.append(message, style="italic dim")
|
|
51
|
-
return text
|
|
58
|
+
def write_output_entry(log: object, renderable: object) -> None:
|
|
59
|
+
"""Write one output entry with a single blank line separator.
|
|
52
60
|
|
|
61
|
+
No visual barrier characters are emitted here; Rich/Textual renderables keep
|
|
62
|
+
their own borders if they need one.
|
|
63
|
+
"""
|
|
53
64
|
|
|
54
|
-
|
|
55
|
-
|
|
65
|
+
items = getattr(log, "items", None)
|
|
66
|
+
if isinstance(items, list) and items:
|
|
67
|
+
log.write("")
|
|
68
|
+
log.write(renderable)
|
|
69
|
+
return
|
|
70
|
+
line_count = getattr(log, "line_count", 0)
|
|
71
|
+
if isinstance(line_count, int) and line_count > 0:
|
|
72
|
+
log.write("")
|
|
73
|
+
log.write(renderable)
|