cnagent 2.0.5 → 2.0.7

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.
Files changed (2) hide show
  1. package/bin/cn +67 -1
  2. package/package.json +1 -1
package/bin/cn CHANGED
@@ -11,7 +11,7 @@ const { execSync, spawn } = require('child_process');
11
11
  const path = require('path');
12
12
  const fs = require('fs');
13
13
 
14
- const VERSION = '2.0.5';
14
+ const VERSION = '2.0.7';
15
15
 
16
16
  // Colors (respects NO_COLOR)
17
17
  const noColor = process.env.NO_COLOR !== undefined;
@@ -248,11 +248,15 @@ if (command === 'update') {
248
248
  const latest = execSync('npm view cnagent version', { encoding: 'utf8' }).trim();
249
249
  if (VERSION === latest) {
250
250
  ok(`Already up to date (v${VERSION})`);
251
+ // Still write runtime.md if in a hub
252
+ writeRuntimeMd(findHubPath(), latest);
251
253
  process.exit(0);
252
254
  }
253
255
  info(`Updating cnagent v${VERSION} → v${latest}...`);
254
256
  execSync('npm install -g cnagent@latest', { stdio: 'inherit' });
255
257
  ok(`Updated to v${latest}`);
258
+ // Write runtime.md if in a hub
259
+ writeRuntimeMd(findHubPath(), latest);
256
260
  } catch (e) {
257
261
  fail('Update failed. Try: npm install -g cnagent@latest');
258
262
  process.exit(1);
@@ -260,6 +264,68 @@ if (command === 'update') {
260
264
  process.exit(0);
261
265
  }
262
266
 
267
+ // Write state/runtime.md after update
268
+ function writeRuntimeMd(hubPath, cnVersion) {
269
+ if (!hubPath) return; // Not in a hub, skip
270
+
271
+ const runtimePath = path.join(hubPath, 'state', 'runtime.md');
272
+ const stateDir = path.join(hubPath, 'state');
273
+
274
+ // Ensure state/ exists
275
+ if (!fs.existsSync(stateDir)) {
276
+ fs.mkdirSync(stateDir, { recursive: true });
277
+ }
278
+
279
+ // Get template info
280
+ let templateVersion = 'unknown';
281
+ let templateCommit = 'unknown';
282
+ try {
283
+ const pkgPath = path.join(__dirname, '..', 'package.json');
284
+ if (fs.existsSync(pkgPath)) {
285
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
286
+ templateVersion = pkg.version || 'unknown';
287
+ }
288
+ templateCommit = execSync('git rev-parse --short HEAD 2>/dev/null || echo unknown', {
289
+ encoding: 'utf8',
290
+ cwd: hubPath
291
+ }).trim();
292
+ } catch {}
293
+
294
+ // Gather runtime info
295
+ const nodeVersion = process.version;
296
+ const platform = `${process.platform} ${process.arch}`;
297
+ const hubName = deriveName(hubPath);
298
+
299
+ let peerCount = 0;
300
+ try {
301
+ const peersPath = path.join(hubPath, 'state', 'peers.md');
302
+ if (fs.existsSync(peersPath)) {
303
+ const content = fs.readFileSync(peersPath, 'utf8');
304
+ peerCount = (content.match(/- name:/g) || []).length;
305
+ }
306
+ } catch {}
307
+
308
+ const content = `# Runtime State
309
+
310
+ Auto-generated by \`cn update\`. Do not edit manually.
311
+
312
+ \`\`\`yaml
313
+ session_start: ${new Date().toISOString()}
314
+ cn_version: ${cnVersion}
315
+ template_version: ${templateVersion}
316
+ template_commit: ${templateCommit}
317
+ node_version: ${nodeVersion}
318
+ platform: ${platform}
319
+ hub_name: ${hubName}
320
+ hub_path: ${hubPath}
321
+ peer_count: ${peerCount}
322
+ \`\`\`
323
+ `;
324
+
325
+ fs.writeFileSync(runtimePath, content);
326
+ info(`Wrote ${runtimePath}`);
327
+ }
328
+
263
329
  // Find hub
264
330
  const hubPath = findHubPath();
265
331
  if (!hubPath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cnagent",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
4
4
  "description": "Coherent Network agent CLI — everything runs through cn",
5
5
  "keywords": [
6
6
  "cn-agent",