chati-dev 4.0.8 → 4.0.10
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.
|
@@ -20,6 +20,7 @@ import { homedir } from 'os';
|
|
|
20
20
|
const API_BASE = 'https://chati.dev/api';
|
|
21
21
|
const TELEMETRY_ENDPOINT = 'https://chati.dev/api/telemetry';
|
|
22
22
|
const CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
|
|
23
|
+
const PING_THROTTLE_MS = 5 * 60 * 1000; // 5 minutes
|
|
23
24
|
|
|
24
25
|
const GLOBAL_DIR = join(homedir(), '.chati-dev');
|
|
25
26
|
const LICENSE_PATH = join(GLOBAL_DIR, 'license.yaml');
|
|
@@ -97,16 +98,17 @@ async function main() {
|
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
// ---------------------------------------------------------------------------
|
|
100
|
-
// Session Ping (
|
|
101
|
+
// Session Ping (5-min throttle with phase-change detection)
|
|
101
102
|
// ---------------------------------------------------------------------------
|
|
102
103
|
|
|
103
104
|
async function allowWithPing(licenseKey) {
|
|
104
105
|
const projectPath = process.cwd();
|
|
105
106
|
const projectName = basename(projectPath) || 'unknown';
|
|
107
|
+
const session = readSessionContext();
|
|
106
108
|
|
|
107
|
-
if (shouldPing(projectPath)) {
|
|
108
|
-
recordPing(projectPath); // sync — prevents duplicate pings even if fetch fails
|
|
109
|
-
const pingPromise = sendSessionPing(licenseKey, projectName);
|
|
109
|
+
if (shouldPing(projectPath, session)) {
|
|
110
|
+
recordPing(projectPath, session); // sync — prevents duplicate pings even if fetch fails
|
|
111
|
+
const pingPromise = sendSessionPing(licenseKey, projectName, session);
|
|
110
112
|
allow();
|
|
111
113
|
await pingPromise; // keep process alive until ping completes (max 3s)
|
|
112
114
|
} else {
|
|
@@ -114,41 +116,93 @@ async function allowWithPing(licenseKey) {
|
|
|
114
116
|
}
|
|
115
117
|
}
|
|
116
118
|
|
|
117
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Reads .chati/session.yaml from cwd to extract pipeline phase, agent, and project type.
|
|
121
|
+
* Returns {} on any error (fail silently — this is optional enrichment).
|
|
122
|
+
*/
|
|
123
|
+
function readSessionContext() {
|
|
124
|
+
try {
|
|
125
|
+
const sessionPath = join(process.cwd(), '.chati', 'session.yaml');
|
|
126
|
+
if (!existsSync(sessionPath)) return {};
|
|
127
|
+
const raw = readFileSync(sessionPath, 'utf-8');
|
|
128
|
+
|
|
129
|
+
// project.state → pipeline_phase
|
|
130
|
+
const stateMatch = raw.match(/^\s+state:\s*(.+)$/m);
|
|
131
|
+
const pipeline_phase = stateMatch ? stateMatch[1].trim().replace(/^["']|["']$/g, '') : null;
|
|
132
|
+
|
|
133
|
+
// current_agent (top-level)
|
|
134
|
+
const agentMatch = raw.match(/^current_agent:\s*(.+)$/m);
|
|
135
|
+
const current_agent = agentMatch ? agentMatch[1].trim().replace(/^["']|["']$/g, '') : null;
|
|
136
|
+
|
|
137
|
+
// project.type → project_type
|
|
138
|
+
const typeMatch = raw.match(/^\s+type:\s*(.+)$/m);
|
|
139
|
+
const project_type = typeMatch ? typeMatch[1].trim().replace(/^["']|["']$/g, '') : null;
|
|
140
|
+
|
|
141
|
+
return { pipeline_phase, current_agent, project_type };
|
|
142
|
+
} catch { return {}; }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Pings.yaml format: '/path/to/project': '2026-03-22T21:00:00.000Z|discover|greenfield-wu'
|
|
147
|
+
* Ping if: (1) no entry, (2) >5 min ago, OR (3) phase/agent changed
|
|
148
|
+
*/
|
|
149
|
+
function shouldPing(projectPath, session = {}) {
|
|
118
150
|
try {
|
|
119
151
|
if (!existsSync(PINGS_PATH)) return true;
|
|
120
152
|
const content = readFileSync(PINGS_PATH, 'utf-8');
|
|
121
|
-
const today = new Date().toISOString().substring(0, 10);
|
|
122
153
|
const escaped = projectPath.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
123
|
-
const match = content.match(new RegExp(`^${escaped}:\\s*(
|
|
124
|
-
|
|
154
|
+
const match = content.match(new RegExp(`^${escaped}:\\s*'?([^'\\n]+)'?$`, 'm'));
|
|
155
|
+
if (!match) return true;
|
|
156
|
+
|
|
157
|
+
const [timestamp, lastPhase, lastAgent] = match[1].trim().split('|');
|
|
158
|
+
const age = Date.now() - new Date(timestamp).getTime();
|
|
159
|
+
if (age > PING_THROTTLE_MS) return true;
|
|
160
|
+
|
|
161
|
+
// Phase or agent changed → ping immediately
|
|
162
|
+
if (session.pipeline_phase && session.pipeline_phase !== lastPhase) return true;
|
|
163
|
+
if (session.current_agent && session.current_agent !== lastAgent) return true;
|
|
164
|
+
|
|
165
|
+
return false;
|
|
125
166
|
} catch { return false; } // fail closed — don't add latency on parse error
|
|
126
167
|
}
|
|
127
168
|
|
|
128
|
-
function recordPing(projectPath) {
|
|
169
|
+
function recordPing(projectPath, session = {}) {
|
|
129
170
|
try {
|
|
130
171
|
mkdirSync(GLOBAL_DIR, { recursive: true });
|
|
131
|
-
const
|
|
172
|
+
const timestamp = new Date().toISOString();
|
|
173
|
+
const phase = session.pipeline_phase ?? '';
|
|
174
|
+
const agent = session.current_agent ?? '';
|
|
175
|
+
const value = `${timestamp}|${phase}|${agent}`;
|
|
176
|
+
|
|
132
177
|
let content = existsSync(PINGS_PATH) ? readFileSync(PINGS_PATH, 'utf-8') : '';
|
|
133
178
|
const escaped = projectPath.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
134
179
|
if (new RegExp(`^${escaped}:`, 'm').test(content)) {
|
|
135
|
-
content = content.replace(new RegExp(`^(${escaped}:).*$`, 'm'), `$1 ${
|
|
180
|
+
content = content.replace(new RegExp(`^(${escaped}:).*$`, 'm'), `$1 '${value}'`);
|
|
136
181
|
} else {
|
|
137
|
-
content += `${projectPath}: ${
|
|
182
|
+
content += `${projectPath}: '${value}'\n`;
|
|
138
183
|
}
|
|
139
184
|
writeFileSync(PINGS_PATH, content);
|
|
140
185
|
} catch {} // fail silently
|
|
141
186
|
}
|
|
142
187
|
|
|
143
|
-
async function sendSessionPing(licenseKey, projectName) {
|
|
188
|
+
async function sendSessionPing(licenseKey, projectName, session = {}) {
|
|
144
189
|
try {
|
|
190
|
+
const properties = {};
|
|
191
|
+
if (session.pipeline_phase) properties.pipeline_phase = session.pipeline_phase;
|
|
192
|
+
if (session.current_agent) properties.current_agent = session.current_agent;
|
|
193
|
+
if (session.project_type) properties.project_type = session.project_type;
|
|
194
|
+
|
|
145
195
|
await fetch(TELEMETRY_ENDPOINT, {
|
|
146
196
|
method: 'POST',
|
|
147
197
|
headers: { 'Content-Type': 'application/json' },
|
|
148
198
|
body: JSON.stringify({
|
|
149
199
|
license_key: licenseKey,
|
|
150
200
|
project_name: projectName,
|
|
151
|
-
events: [{
|
|
201
|
+
events: [{
|
|
202
|
+
type: 'session_active',
|
|
203
|
+
timestamp: new Date().toISOString(),
|
|
204
|
+
properties,
|
|
205
|
+
}],
|
|
152
206
|
}),
|
|
153
207
|
signal: AbortSignal.timeout(3000),
|
|
154
208
|
});
|
|
@@ -18,39 +18,6 @@ You are the **Chati.dev Orchestrator**, the single entry point for the Chati.dev
|
|
|
18
18
|
|
|
19
19
|
When the user invokes `/chati`, execute this sequence:
|
|
20
20
|
|
|
21
|
-
### Pre-Flight: License Check
|
|
22
|
-
|
|
23
|
-
FIRST — before anything else:
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
1. Read ~/.chati-dev/license.yaml
|
|
27
|
-
|
|
28
|
-
If file is MISSING or status = "MISSING":
|
|
29
|
-
Say:
|
|
30
|
-
"Welcome to chati.dev! Before we start, I need to activate your license.
|
|
31
|
-
|
|
32
|
-
Option 1 — Paste your license key below.
|
|
33
|
-
Option 2 — Get a free 14-day trial: https://chati.dev/pricing
|
|
34
|
-
|
|
35
|
-
Enter your key (or press Enter if you just received one via email):"
|
|
36
|
-
|
|
37
|
-
→ User provides key
|
|
38
|
-
→ Run: `npx chati-dev activate --key={key}`
|
|
39
|
-
→ Re-read ~/.chati-dev/license.yaml
|
|
40
|
-
→ If status = VALID: "✓ Activated! Let's build." → proceed to Step 1
|
|
41
|
-
→ If error: show error message, ask to try again (max 3 attempts, then stop)
|
|
42
|
-
|
|
43
|
-
If status = "EXPIRED":
|
|
44
|
-
Say:
|
|
45
|
-
"Your chati.dev license has expired.
|
|
46
|
-
Renew at https://chati.dev/pricing
|
|
47
|
-
After renewing, run: npx chati-dev activate --key=YOUR-KEY"
|
|
48
|
-
→ STOP. Do not proceed.
|
|
49
|
-
|
|
50
|
-
If status = "VALID":
|
|
51
|
-
→ Proceed silently. Zero mention of license in normal flow.
|
|
52
|
-
```
|
|
53
|
-
|
|
54
21
|
### Step 1: Load Context
|
|
55
22
|
```
|
|
56
23
|
1. Read .chati/session.yaml
|