cnagent 2.0.4 → 2.0.6
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/bin/cn +56 -4
- 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.
|
|
14
|
+
const VERSION = '2.0.6';
|
|
15
15
|
|
|
16
16
|
// Colors (respects NO_COLOR)
|
|
17
17
|
const noColor = process.env.NO_COLOR !== undefined;
|
|
@@ -243,11 +243,20 @@ if (command === 'init') {
|
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
if (command === 'update') {
|
|
246
|
-
|
|
246
|
+
// Check if already on latest
|
|
247
247
|
try {
|
|
248
|
+
const latest = execSync('npm view cnagent version', { encoding: 'utf8' }).trim();
|
|
249
|
+
if (VERSION === latest) {
|
|
250
|
+
ok(`Already up to date (v${VERSION})`);
|
|
251
|
+
// Still write runtime.md if in a hub
|
|
252
|
+
writeRuntimeMd(findHubPath(), latest);
|
|
253
|
+
process.exit(0);
|
|
254
|
+
}
|
|
255
|
+
info(`Updating cnagent v${VERSION} → v${latest}...`);
|
|
248
256
|
execSync('npm install -g cnagent@latest', { stdio: 'inherit' });
|
|
249
|
-
ok(
|
|
250
|
-
|
|
257
|
+
ok(`Updated to v${latest}`);
|
|
258
|
+
// Write runtime.md if in a hub
|
|
259
|
+
writeRuntimeMd(findHubPath(), latest);
|
|
251
260
|
} catch (e) {
|
|
252
261
|
fail('Update failed. Try: npm install -g cnagent@latest');
|
|
253
262
|
process.exit(1);
|
|
@@ -255,6 +264,49 @@ if (command === 'update') {
|
|
|
255
264
|
process.exit(0);
|
|
256
265
|
}
|
|
257
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
|
+
const content = `# Runtime State
|
|
295
|
+
|
|
296
|
+
Auto-generated by \`cn update\`. Do not edit manually.
|
|
297
|
+
|
|
298
|
+
\`\`\`yaml
|
|
299
|
+
session_start: ${new Date().toISOString()}
|
|
300
|
+
template_version: ${templateVersion}
|
|
301
|
+
template_commit: ${templateCommit}
|
|
302
|
+
cn_version: ${cnVersion}
|
|
303
|
+
\`\`\`
|
|
304
|
+
`;
|
|
305
|
+
|
|
306
|
+
fs.writeFileSync(runtimePath, content);
|
|
307
|
+
info(`Wrote ${runtimePath}`);
|
|
308
|
+
}
|
|
309
|
+
|
|
258
310
|
// Find hub
|
|
259
311
|
const hubPath = findHubPath();
|
|
260
312
|
if (!hubPath) {
|