tokensafe 1.2.0 → 1.3.1
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/README.md +200 -16
- package/bin/agy-tokens +156 -4
- package/bin/tokensafe.js +7 -0
- package/hooks/pre_invocation.py +40 -11
- package/hooks/pre_tool_use.py +23 -3
- package/package.json +7 -3
- package/plugin.json +1 -1
- package/rules/AGENTS.md +6 -0
- package/skills/token-optimizer/SKILL.md +1 -0
- package/src/__init__.py +1 -1
- package/src/agent_firewall.py +146 -0
- package/src/benchmark.py +68 -9
- package/src/cache_normalizer.py +105 -0
- package/src/command_sanitizer.py +21 -12
- package/src/dashboard.py +54 -7
- package/src/diff_slicer.py +120 -0
- package/src/environment_auditor.py +259 -0
- package/src/governor.py +166 -0
- package/src/graph_engine.py +4 -0
- package/src/installer.py +192 -34
- package/src/license_manager.py +157 -23
- package/src/mcp_server.py +59 -7
- package/src/metrics.py +261 -21
- package/src/proxy.py +160 -18
- package/src/version_checker.py +156 -0
- package/src/weekly_digest.py +305 -0
- package/src/mailer.py +0 -327
package/src/mailer.py
DELETED
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
TokenSafe Transactional Email Service.
|
|
3
|
-
Handles transactional emails via ImprovMX SMTP (port 587 TLS)
|
|
4
|
-
with beautiful responsive dark-mode HTML templates and asynchronous delivery.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import os
|
|
8
|
-
import ssl
|
|
9
|
-
import smtplib
|
|
10
|
-
import threading
|
|
11
|
-
from email.mime.multipart import MIMEMultipart
|
|
12
|
-
from email.mime.text import MIMEText
|
|
13
|
-
from typing import Optional, Dict, Any
|
|
14
|
-
|
|
15
|
-
class TokenSafeMailer:
|
|
16
|
-
"""Dispatches transactional notifications (Welcome, Team Seat Invites)."""
|
|
17
|
-
|
|
18
|
-
SMTP_HOST = os.environ.get("SMTP_HOST", "smtp.improvmx.com")
|
|
19
|
-
SMTP_PORT = int(os.environ.get("SMTP_PORT", "587"))
|
|
20
|
-
SMTP_USER = os.environ.get("SMTP_USER", "any-alias-1@tokensafe.dev")
|
|
21
|
-
SMTP_PASS = os.environ.get("SMTP_PASS", "g7Qw8nB1U1Q9")
|
|
22
|
-
SMTP_FROM = os.environ.get("SMTP_FROM", "TokenSafe <support@tokensafe.dev>")
|
|
23
|
-
SMTP_TIMEOUT = 10
|
|
24
|
-
|
|
25
|
-
@classmethod
|
|
26
|
-
def _send_raw(cls, recipient: str, subject: str, text_content: str, html_content: str) -> bool:
|
|
27
|
-
"""Sends an email synchronously via SMTP with STARTTLS."""
|
|
28
|
-
msg = MIMEMultipart("alternative")
|
|
29
|
-
msg["Subject"] = subject
|
|
30
|
-
msg["From"] = cls.SMTP_FROM
|
|
31
|
-
msg["To"] = recipient
|
|
32
|
-
|
|
33
|
-
# Attach plain text and HTML alternatives
|
|
34
|
-
msg.attach(MIMEText(text_content, "plain", "utf-8"))
|
|
35
|
-
msg.attach(MIMEText(html_content, "html", "utf-8"))
|
|
36
|
-
|
|
37
|
-
try:
|
|
38
|
-
server = smtplib.SMTP(cls.SMTP_HOST, cls.SMTP_PORT, timeout=cls.SMTP_TIMEOUT)
|
|
39
|
-
server.ehlo()
|
|
40
|
-
context = ssl.create_default_context()
|
|
41
|
-
server.starttls(context=context)
|
|
42
|
-
server.ehlo()
|
|
43
|
-
server.login(cls.SMTP_USER, cls.SMTP_PASS)
|
|
44
|
-
server.sendmail(cls.SMTP_USER, [recipient], msg.as_string())
|
|
45
|
-
server.quit()
|
|
46
|
-
return True
|
|
47
|
-
except Exception as e:
|
|
48
|
-
# Log error in production
|
|
49
|
-
print(f"[Mailer Error] Failed to send email to {recipient}: {e}")
|
|
50
|
-
return False
|
|
51
|
-
|
|
52
|
-
@classmethod
|
|
53
|
-
def send_async(cls, recipient: str, subject: str, text_content: str, html_content: str):
|
|
54
|
-
"""Dispatches email sending in a non-blocking background daemon thread."""
|
|
55
|
-
thread = threading.Thread(
|
|
56
|
-
target=cls._send_raw,
|
|
57
|
-
args=(recipient, subject, text_content, html_content),
|
|
58
|
-
daemon=True
|
|
59
|
-
)
|
|
60
|
-
thread.start()
|
|
61
|
-
|
|
62
|
-
@classmethod
|
|
63
|
-
def send_welcome_email(cls, recipient: str, license_key: str, tier: str = "solo", is_trial: bool = True):
|
|
64
|
-
"""Sends welcome email with license key and 1-click onboarding instructions."""
|
|
65
|
-
plan_name = "Solo Developer (7-Day Trial)" if tier == "solo" else "Engineering Team (7-Day Trial)"
|
|
66
|
-
subject = f"Welcome to TokenSafe — Your {plan_name} License Key"
|
|
67
|
-
|
|
68
|
-
text_content = f"""Welcome to TokenSafe!
|
|
69
|
-
|
|
70
|
-
Your {plan_name} has been activated.
|
|
71
|
-
|
|
72
|
-
Your License Key:
|
|
73
|
-
{license_key}
|
|
74
|
-
|
|
75
|
-
Quick Setup (1 command):
|
|
76
|
-
npx tokensafe
|
|
77
|
-
|
|
78
|
-
Or connect existing tools:
|
|
79
|
-
tokensafe auth {license_key}
|
|
80
|
-
|
|
81
|
-
Open your cloud dashboard:
|
|
82
|
-
https://tokensafe.dev/dashboard
|
|
83
|
-
|
|
84
|
-
If you need any assistance, simply reply to this email.
|
|
85
|
-
— The TokenSafe Team
|
|
86
|
-
https://tokensafe.dev
|
|
87
|
-
"""
|
|
88
|
-
|
|
89
|
-
html_content = f"""<!DOCTYPE html>
|
|
90
|
-
<html>
|
|
91
|
-
<head>
|
|
92
|
-
<meta charset="utf-8">
|
|
93
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
94
|
-
<title>{subject}</title>
|
|
95
|
-
</head>
|
|
96
|
-
<body style="margin: 0; padding: 0; background-color: #030712; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: #f3f4f6;">
|
|
97
|
-
<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="background-color: #030712; padding: 40px 20px;">
|
|
98
|
-
<tr>
|
|
99
|
-
<td align="center">
|
|
100
|
-
<table role="presentation" width="100%" style="max-width: 580px; background-color: #0f172a; border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 16px; padding: 36px; box-shadow: 0 20px 40px rgba(0,0,0,0.4);">
|
|
101
|
-
|
|
102
|
-
<!-- Logo / Header -->
|
|
103
|
-
<tr>
|
|
104
|
-
<td style="padding-bottom: 24px; border-bottom: 1px solid rgba(255, 255, 255, 0.06);">
|
|
105
|
-
<span style="font-size: 20px; font-weight: 800; color: #ffffff; letter-spacing: -0.5px;">
|
|
106
|
-
Token<span style="color: #10b981;">Safe</span>
|
|
107
|
-
</span>
|
|
108
|
-
<span style="float: right; font-size: 11px; font-weight: 700; color: #10b981; background: rgba(16, 185, 129, 0.1); border: 1px solid rgba(16, 185, 129, 0.2); padding: 4px 10px; border-radius: 999px; text-transform: uppercase;">
|
|
109
|
-
{tier.upper()} ACTIVE
|
|
110
|
-
</span>
|
|
111
|
-
</td>
|
|
112
|
-
</tr>
|
|
113
|
-
|
|
114
|
-
<!-- Title -->
|
|
115
|
-
<tr>
|
|
116
|
-
<td style="padding-top: 28px; padding-bottom: 12px;">
|
|
117
|
-
<h1 style="margin: 0; font-size: 22px; font-weight: 700; color: #ffffff; line-height: 1.3;">
|
|
118
|
-
Welcome to Autonomous Token Economy
|
|
119
|
-
</h1>
|
|
120
|
-
<p style="margin: 8px 0 0; font-size: 14px; color: #94a3b8; line-height: 1.6;">
|
|
121
|
-
Your plan <strong style="color: #f1f5f9;">{plan_name}</strong> is ready. Your agents will now compress context, eliminate stuck loops, and protect token budgets.
|
|
122
|
-
</p>
|
|
123
|
-
</td>
|
|
124
|
-
</tr>
|
|
125
|
-
|
|
126
|
-
<!-- License Key Box -->
|
|
127
|
-
<tr>
|
|
128
|
-
<td style="padding: 20px 0;">
|
|
129
|
-
<div style="background-color: #020617; border: 1px solid rgba(16, 185, 129, 0.3); border-radius: 12px; padding: 18px; text-align: center;">
|
|
130
|
-
<div style="font-size: 11px; font-weight: 600; text-transform: uppercase; color: #94a3b8; letter-spacing: 0.5px; margin-bottom: 8px;">
|
|
131
|
-
Your Cryptographic License Key
|
|
132
|
-
</div>
|
|
133
|
-
<div style="font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; font-weight: 700; color: #34d399; letter-spacing: 0.5px; word-break: break-all;">
|
|
134
|
-
{license_key}
|
|
135
|
-
</div>
|
|
136
|
-
</div>
|
|
137
|
-
</td>
|
|
138
|
-
</tr>
|
|
139
|
-
|
|
140
|
-
<!-- Quick Setup Steps -->
|
|
141
|
-
<tr>
|
|
142
|
-
<td style="padding-bottom: 24px;">
|
|
143
|
-
<h3 style="font-size: 14px; font-weight: 600; color: #e2e8f0; margin: 0 0 12px;">
|
|
144
|
-
🚀 Quick Start (Instant Installation)
|
|
145
|
-
</h3>
|
|
146
|
-
|
|
147
|
-
<!-- Command 1 -->
|
|
148
|
-
<div style="background-color: #020617; border: 1px solid rgba(255, 255, 255, 0.06); border-radius: 8px; padding: 12px 16px; margin-bottom: 10px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; color: #f8fafc;">
|
|
149
|
-
<span style="color: #10b981;">$</span> npx tokensafe
|
|
150
|
-
</div>
|
|
151
|
-
|
|
152
|
-
<!-- Command 2 -->
|
|
153
|
-
<div style="background-color: #020617; border: 1px solid rgba(255, 255, 255, 0.06); border-radius: 8px; padding: 12px 16px; margin-bottom: 16px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; color: #f8fafc;">
|
|
154
|
-
<span style="color: #10b981;">$</span> tokensafe auth {license_key}
|
|
155
|
-
</div>
|
|
156
|
-
|
|
157
|
-
<p style="margin: 0; font-size: 13px; color: #94a3b8; line-height: 1.5;">
|
|
158
|
-
Or install via Python PyPI: <code style="color: #38bdf8; background: rgba(56, 189, 248, 0.1); padding: 2px 6px; border-radius: 4px;">pip install tokensafe</code>. Compatible with Cursor, Claude Desktop, Antigravity, and Codex.
|
|
159
|
-
</p>
|
|
160
|
-
</td>
|
|
161
|
-
</tr>
|
|
162
|
-
|
|
163
|
-
<!-- CTA Button -->
|
|
164
|
-
<tr>
|
|
165
|
-
<td align="center" style="padding: 16px 0 28px;">
|
|
166
|
-
<a href="https://tokensafe.dev/dashboard?key={license_key}" style="display: inline-block; background-color: #10b981; color: #020617; font-size: 14px; font-weight: 700; text-decoration: none; padding: 14px 32px; border-radius: 10px; box-shadow: 0 8px 16px rgba(16, 185, 129, 0.2);">
|
|
167
|
-
Open Cloud Analytics Dashboard →
|
|
168
|
-
</a>
|
|
169
|
-
</td>
|
|
170
|
-
</tr>
|
|
171
|
-
|
|
172
|
-
<!-- Footer -->
|
|
173
|
-
<tr>
|
|
174
|
-
<td style="border-top: 1px solid rgba(255, 255, 255, 0.06); padding-top: 20px; font-size: 12px; color: #64748b; line-height: 1.5;">
|
|
175
|
-
Need help or custom integrations? Just reply to this email or reach us at <a href="mailto:support@tokensafe.dev" style="color: #10b981; text-decoration: none;">support@tokensafe.dev</a>.<br>
|
|
176
|
-
© 2026 TokenSafe. Autonomous Zero-Loss Token Economy.
|
|
177
|
-
</td>
|
|
178
|
-
</tr>
|
|
179
|
-
|
|
180
|
-
</table>
|
|
181
|
-
</td>
|
|
182
|
-
</tr>
|
|
183
|
-
</table>
|
|
184
|
-
</body>
|
|
185
|
-
</html>
|
|
186
|
-
"""
|
|
187
|
-
cls.send_async(recipient, subject, text_content, html_content)
|
|
188
|
-
|
|
189
|
-
@classmethod
|
|
190
|
-
def send_team_invite_email(cls, recipient: str, seat_license_key: str, owner_email: str):
|
|
191
|
-
"""Sends team member onboarding email with instructions on connecting IDEs."""
|
|
192
|
-
subject = f"Your TokenSafe Team Seat License — Invited by {owner_email}"
|
|
193
|
-
|
|
194
|
-
text_content = f"""Hi there!
|
|
195
|
-
|
|
196
|
-
Your team lead ({owner_email}) has granted you a TokenSafe Team developer seat.
|
|
197
|
-
|
|
198
|
-
Your Personal Seat Key:
|
|
199
|
-
{seat_license_key}
|
|
200
|
-
|
|
201
|
-
Setup Guide:
|
|
202
|
-
1. Run the instant setup:
|
|
203
|
-
npx tokensafe
|
|
204
|
-
|
|
205
|
-
2. Connect your personal seat license:
|
|
206
|
-
tokensafe auth {seat_license_key}
|
|
207
|
-
|
|
208
|
-
3. IDE Integrations:
|
|
209
|
-
- Cursor: Extension is activated automatically.
|
|
210
|
-
- Claude Desktop: MCP server is configured in ~/Library/Application Support/Claude/claude_desktop_config.json.
|
|
211
|
-
- Terminal: Run 'tokensafe stats' anytime to see your saved context and tokens.
|
|
212
|
-
|
|
213
|
-
Track your developer economics:
|
|
214
|
-
https://tokensafe.dev/dashboard
|
|
215
|
-
|
|
216
|
-
If you have any questions, contact your team lead ({owner_email}) or reply to this email.
|
|
217
|
-
— The TokenSafe Team
|
|
218
|
-
"""
|
|
219
|
-
|
|
220
|
-
html_content = f"""<!DOCTYPE html>
|
|
221
|
-
<html>
|
|
222
|
-
<head>
|
|
223
|
-
<meta charset="utf-8">
|
|
224
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
225
|
-
<title>{subject}</title>
|
|
226
|
-
</head>
|
|
227
|
-
<body style="margin: 0; padding: 0; background-color: #030712; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: #f3f4f6;">
|
|
228
|
-
<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="background-color: #030712; padding: 40px 20px;">
|
|
229
|
-
<tr>
|
|
230
|
-
<td align="center">
|
|
231
|
-
<table role="presentation" width="100%" style="max-width: 580px; background-color: #0f172a; border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 16px; padding: 36px; box-shadow: 0 20px 40px rgba(0,0,0,0.4);">
|
|
232
|
-
|
|
233
|
-
<!-- Logo / Header -->
|
|
234
|
-
<tr>
|
|
235
|
-
<td style="padding-bottom: 24px; border-bottom: 1px solid rgba(255, 255, 255, 0.06);">
|
|
236
|
-
<span style="font-size: 20px; font-weight: 800; color: #ffffff; letter-spacing: -0.5px;">
|
|
237
|
-
Token<span style="color: #10b981;">Safe</span>
|
|
238
|
-
</span>
|
|
239
|
-
<span style="float: right; font-size: 11px; font-weight: 700; color: #38bdf8; background: rgba(56, 189, 248, 0.1); border: 1px solid rgba(56, 189, 248, 0.2); padding: 4px 10px; border-radius: 999px; text-transform: uppercase;">
|
|
240
|
-
TEAM SEAT INVITE
|
|
241
|
-
</span>
|
|
242
|
-
</td>
|
|
243
|
-
</tr>
|
|
244
|
-
|
|
245
|
-
<!-- Title -->
|
|
246
|
-
<tr>
|
|
247
|
-
<td style="padding-top: 28px; padding-bottom: 12px;">
|
|
248
|
-
<h1 style="margin: 0; font-size: 22px; font-weight: 700; color: #ffffff; line-height: 1.3;">
|
|
249
|
-
You've been added to TokenSafe Team
|
|
250
|
-
</h1>
|
|
251
|
-
<p style="margin: 8px 0 0; font-size: 14px; color: #94a3b8; line-height: 1.6;">
|
|
252
|
-
Team lead <strong style="color: #38bdf8;">{owner_email}</strong> has provisioned a dedicated TokenSafe developer seat for you. Context compression and token guards are now active for your workflow.
|
|
253
|
-
</p>
|
|
254
|
-
</td>
|
|
255
|
-
</tr>
|
|
256
|
-
|
|
257
|
-
<!-- License Key Box -->
|
|
258
|
-
<tr>
|
|
259
|
-
<td style="padding: 20px 0;">
|
|
260
|
-
<div style="background-color: #020617; border: 1px solid rgba(56, 189, 248, 0.3); border-radius: 12px; padding: 18px; text-align: center;">
|
|
261
|
-
<div style="font-size: 11px; font-weight: 600; text-transform: uppercase; color: #94a3b8; letter-spacing: 0.5px; margin-bottom: 8px;">
|
|
262
|
-
Your Dedicated Team Seat Key
|
|
263
|
-
</div>
|
|
264
|
-
<div style="font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; font-weight: 700; color: #38bdf8; letter-spacing: 0.5px; word-break: break-all;">
|
|
265
|
-
{seat_license_key}
|
|
266
|
-
</div>
|
|
267
|
-
</div>
|
|
268
|
-
</td>
|
|
269
|
-
</tr>
|
|
270
|
-
|
|
271
|
-
<!-- Setup Instructions -->
|
|
272
|
-
<tr>
|
|
273
|
-
<td style="padding-bottom: 24px;">
|
|
274
|
-
<h3 style="font-size: 14px; font-weight: 600; color: #e2e8f0; margin: 0 0 12px;">
|
|
275
|
-
⚙️ Quick 3-Step Setup
|
|
276
|
-
</h3>
|
|
277
|
-
|
|
278
|
-
<div style="margin-bottom: 16px;">
|
|
279
|
-
<div style="font-size: 12px; font-weight: 600; color: #cbd5e1; margin-bottom: 4px;">Step 1: Install TokenSafe CLI</div>
|
|
280
|
-
<div style="background-color: #020617; border: 1px solid rgba(255, 255, 255, 0.06); border-radius: 8px; padding: 10px 14px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; color: #f8fafc;">
|
|
281
|
-
<span style="color: #10b981;">$</span> npx tokensafe
|
|
282
|
-
</div>
|
|
283
|
-
</div>
|
|
284
|
-
|
|
285
|
-
<div style="margin-bottom: 16px;">
|
|
286
|
-
<div style="font-size: 12px; font-weight: 600; color: #cbd5e1; margin-bottom: 4px;">Step 2: Bind your seat license</div>
|
|
287
|
-
<div style="background-color: #020617; border: 1px solid rgba(255, 255, 255, 0.06); border-radius: 8px; padding: 10px 14px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; color: #f8fafc;">
|
|
288
|
-
<span style="color: #10b981;">$</span> tokensafe auth {seat_license_key}
|
|
289
|
-
</div>
|
|
290
|
-
</div>
|
|
291
|
-
|
|
292
|
-
<div style="margin-bottom: 16px;">
|
|
293
|
-
<div style="font-size: 12px; font-weight: 600; color: #cbd5e1; margin-bottom: 4px;">Step 3: IDE Agents Automatic Hook</div>
|
|
294
|
-
<ul style="margin: 6px 0 0 18px; padding: 0; font-size: 13px; color: #94a3b8; line-height: 1.6;">
|
|
295
|
-
<li><strong>Cursor / VSCode:</strong> Hooks directly into extension background loop.</li>
|
|
296
|
-
<li><strong>Claude Desktop:</strong> MCP server runs at <code style="color: #34d399;">tokensafe-mcp</code>.</li>
|
|
297
|
-
<li><strong>Terminal:</strong> Check your stats with <code style="color: #38bdf8;">tokensafe stats</code>.</li>
|
|
298
|
-
</ul>
|
|
299
|
-
</div>
|
|
300
|
-
</td>
|
|
301
|
-
</tr>
|
|
302
|
-
|
|
303
|
-
<!-- CTA Button -->
|
|
304
|
-
<tr>
|
|
305
|
-
<td align="center" style="padding: 16px 0 28px;">
|
|
306
|
-
<a href="https://tokensafe.dev/dashboard?key={seat_license_key}" style="display: inline-block; background-color: #0284c7; color: #ffffff; font-size: 14px; font-weight: 700; text-decoration: none; padding: 14px 32px; border-radius: 10px; box-shadow: 0 8px 16px rgba(2, 132, 199, 0.25);">
|
|
307
|
-
View Your Developer Portal →
|
|
308
|
-
</a>
|
|
309
|
-
</td>
|
|
310
|
-
</tr>
|
|
311
|
-
|
|
312
|
-
<!-- Footer -->
|
|
313
|
-
<tr>
|
|
314
|
-
<td style="border-top: 1px solid rgba(255, 255, 255, 0.06); padding-top: 20px; font-size: 12px; color: #64748b; line-height: 1.5;">
|
|
315
|
-
Invited by {owner_email}. Have questions? Contact your team lead or reach us at <a href="mailto:support@tokensafe.dev" style="color: #38bdf8; text-decoration: none;">support@tokensafe.dev</a>.<br>
|
|
316
|
-
© 2026 TokenSafe. Autonomous Zero-Loss Token Economy.
|
|
317
|
-
</td>
|
|
318
|
-
</tr>
|
|
319
|
-
|
|
320
|
-
</table>
|
|
321
|
-
</td>
|
|
322
|
-
</tr>
|
|
323
|
-
</table>
|
|
324
|
-
</body>
|
|
325
|
-
</html>
|
|
326
|
-
"""
|
|
327
|
-
cls.send_async(recipient, subject, text_content, html_content)
|