pyre-agent-kit 2.0.20 → 2.0.22

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/dist/cli.js CHANGED
@@ -47,6 +47,7 @@ const fs = __importStar(require("fs"));
47
47
  const path = __importStar(require("path"));
48
48
  const web3_js_1 = require("@solana/web3.js");
49
49
  const index_1 = require("./index");
50
+ const pyre_world_kit_1 = require("pyre-world-kit");
50
51
  // ─── Constants ────────────────────────────────────────────────────
51
52
  const CONFIG_PATH = path.join(process.env.HOME ?? '.', '.pyre-agent.json');
52
53
  const BANNER = `
@@ -340,7 +341,29 @@ async function runAgent(config) {
340
341
  };
341
342
  process.on('SIGINT', shutdown);
342
343
  process.on('SIGTERM', shutdown);
343
- // Auto-save every 10 ticks
344
+ // Action tracking for checkpoints
345
+ const CHECKPOINT_EVERY = 20;
346
+ const ALL_ACTIONS = [
347
+ 'join', 'defect', 'rally', 'launch', 'message',
348
+ 'stronghold', 'war_loan', 'repay_loan', 'siege', 'ascend', 'raze', 'tithe',
349
+ 'infiltrate', 'fud',
350
+ ];
351
+ const actionCounts = new Array(14).fill(0);
352
+ const recentMemos = [];
353
+ // Seed counts from registry profile if available
354
+ try {
355
+ const reg = await (0, pyre_world_kit_1.getRegistryProfile)(connection, keypair.publicKey.toBase58());
356
+ if (reg) {
357
+ const seed = [
358
+ reg.joins, reg.defects, reg.rallies, reg.launches, reg.messages,
359
+ reg.reinforces, reg.war_loans, reg.repay_loans, reg.sieges,
360
+ reg.ascends, reg.razes, reg.tithes, reg.infiltrates, reg.fuds,
361
+ ];
362
+ for (let i = 0; i < seed.length; i++)
363
+ actionCounts[i] = Math.max(actionCounts[i], seed[i]);
364
+ }
365
+ }
366
+ catch { /* no profile yet */ }
344
367
  let tickCount = 0;
345
368
  while (running) {
346
369
  try {
@@ -350,11 +373,47 @@ async function runAgent(config) {
350
373
  const msg = result.message ? ` "${result.message}"` : '';
351
374
  const brain = result.usedLLM ? 'LLM' : 'RNG';
352
375
  console.log(` [${ts()}] #${tickCount} [${brain}] ${result.action.toUpperCase()} ${result.faction ?? ''}${msg} — ${status}`);
376
+ // Track actions for checkpoint
377
+ if (result.success) {
378
+ const idx = ALL_ACTIONS.indexOf(result.action);
379
+ if (idx >= 0)
380
+ actionCounts[idx]++;
381
+ if (result.message?.trim()) {
382
+ recentMemos.push(result.message);
383
+ if (recentMemos.length > 10)
384
+ recentMemos.shift();
385
+ }
386
+ }
353
387
  // Auto-save state every 10 ticks
354
388
  if (tickCount % 10 === 0) {
355
389
  const saved = agent.serialize();
356
390
  fs.writeFileSync(statePath, JSON.stringify(saved, null, 2));
357
391
  }
392
+ // Checkpoint to pyre_world every N ticks
393
+ if (tickCount % CHECKPOINT_EVERY === 0) {
394
+ try {
395
+ const personality = agent.personality;
396
+ const summary = recentMemos.length > 0
397
+ ? `${personality}: ${recentMemos.slice(-5).join('. ')}`.slice(0, 256)
398
+ : personality;
399
+ const pub = keypair.publicKey.toBase58();
400
+ const cpResult = await (0, pyre_world_kit_1.buildCheckpointTransaction)(connection, {
401
+ signer: pub,
402
+ creator: pub,
403
+ joins: actionCounts[0], defects: actionCounts[1], rallies: actionCounts[2],
404
+ launches: actionCounts[3], messages: actionCounts[4], fuds: actionCounts[13],
405
+ infiltrates: actionCounts[12], reinforces: actionCounts[5],
406
+ war_loans: actionCounts[6], repay_loans: actionCounts[7], sieges: actionCounts[8],
407
+ ascends: actionCounts[9], razes: actionCounts[10], tithes: actionCounts[11],
408
+ personality_summary: summary,
409
+ });
410
+ await (0, index_1.sendAndConfirm)(connection, keypair, cpResult);
411
+ console.log(` [${ts()}] Checkpointed to pyre_world (${actionCounts.reduce((a, b) => a + b, 0)} total actions)`);
412
+ }
413
+ catch (e) {
414
+ console.error(` [${ts()}] Checkpoint failed: ${e.message?.slice(0, 60)}`);
415
+ }
416
+ }
358
417
  }
359
418
  catch (e) {
360
419
  console.error(` [${ts()}] Tick error: ${e.message}`);
package/dist/registry.js CHANGED
@@ -9,23 +9,34 @@ const tx_1 = require("./tx");
9
9
  */
10
10
  async function ensureRegistryProfile(connection, agent, log) {
11
11
  const short = agent.publicKey.slice(0, 8);
12
+ // Try to fetch existing profile
12
13
  try {
13
14
  const existing = await (0, pyre_world_kit_1.getRegistryProfile)(connection, agent.publicKey);
14
15
  if (existing) {
15
16
  log(`[${short}] registry profile found (${existing.address.slice(0, 8)}), last checkpoint: ${existing.last_checkpoint > 0 ? new Date(existing.last_checkpoint * 1000).toISOString().slice(0, 10) : 'never'}`);
16
17
  return existing;
17
18
  }
18
- // Create new profile
19
+ }
20
+ catch {
21
+ // Fetch failed — profile may or may not exist, try to register below
22
+ }
23
+ // Try to create — if it already exists, init will fail, that's fine
24
+ try {
19
25
  const result = await (0, pyre_world_kit_1.buildRegisterAgentTransaction)(connection, {
20
26
  creator: agent.publicKey,
21
27
  });
22
28
  await (0, tx_1.sendAndConfirm)(connection, agent.keypair, result);
23
29
  log(`[${short}] created registry profile`);
24
- // Fetch the newly created profile
30
+ }
31
+ catch {
32
+ // Already exists or insufficient funds — either way, try to fetch
33
+ }
34
+ // Final fetch attempt
35
+ try {
25
36
  return await (0, pyre_world_kit_1.getRegistryProfile)(connection, agent.publicKey);
26
37
  }
27
- catch (err) {
28
- log(`[${short}] registry profile setup failed (${err.message?.slice(0, 60)})`);
38
+ catch {
39
+ log(`[${short}] registry profile unavailable`);
29
40
  return null;
30
41
  }
31
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pyre-agent-kit",
3
- "version": "2.0.20",
3
+ "version": "2.0.22",
4
4
  "description": "Autonomous agent kit for Pyre — plug in your own LLM and play pyre.world",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",