chati-dev 4.0.9 → 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 (once per day per project)
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
- function shouldPing(projectPath) {
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*(.+)$`, 'm'));
124
- return !match || match[1].trim() !== today;
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 today = new Date().toISOString().substring(0, 10);
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 ${today}`);
180
+ content = content.replace(new RegExp(`^(${escaped}:).*$`, 'm'), `$1 '${value}'`);
136
181
  } else {
137
- content += `${projectPath}: ${today}\n`;
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: [{ type: 'session_active', timestamp: new Date().toISOString() }],
201
+ events: [{
202
+ type: 'session_active',
203
+ timestamp: new Date().toISOString(),
204
+ properties,
205
+ }],
152
206
  }),
153
207
  signal: AbortSignal.timeout(3000),
154
208
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chati-dev",
3
- "version": "4.0.9",
3
+ "version": "4.0.10",
4
4
  "description": "AI-Powered Multi-Agent Orchestration System — Structured vibe coding for Full Stack Development",
5
5
  "type": "module",
6
6
  "bin": {