@nookplot/runtime 0.5.119 → 0.5.120

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 (98) hide show
  1. package/dist/__tests__/autonomous.getAvailableActions.test.js +4 -7
  2. package/dist/__tests__/autonomous.getAvailableActions.test.js.map +1 -1
  3. package/dist/__tests__/codegen-drift.test.js +1 -3
  4. package/dist/__tests__/codegen-drift.test.js.map +1 -1
  5. package/dist/__tests__/conversation/modelThresholdsParity.test.js +11 -6
  6. package/dist/__tests__/conversation/modelThresholdsParity.test.js.map +1 -1
  7. package/dist/__tests__/helpers/mockRuntime.d.ts.map +1 -1
  8. package/dist/__tests__/helpers/mockRuntime.js +0 -7
  9. package/dist/__tests__/helpers/mockRuntime.js.map +1 -1
  10. package/dist/__tests__/sandbox.test.js +24 -24
  11. package/dist/actionCatalog.generated.d.ts +1 -1
  12. package/dist/actionCatalog.generated.d.ts.map +1 -1
  13. package/dist/actionCatalog.generated.js +33 -178
  14. package/dist/actionCatalog.generated.js.map +1 -1
  15. package/dist/autonomous.d.ts +1 -25
  16. package/dist/autonomous.d.ts.map +1 -1
  17. package/dist/autonomous.js +38 -217
  18. package/dist/autonomous.js.map +1 -1
  19. package/dist/bounties.js +1 -1
  20. package/dist/bounties.js.map +1 -1
  21. package/dist/connection.d.ts +1 -1
  22. package/dist/connection.d.ts.map +1 -1
  23. package/dist/connection.js +1 -2
  24. package/dist/connection.js.map +1 -1
  25. package/dist/contentSafety.d.ts +1 -1
  26. package/dist/contentSafety.d.ts.map +1 -1
  27. package/dist/contentSafety.js +2 -6
  28. package/dist/contentSafety.js.map +1 -1
  29. package/dist/conversation/modelLimits.js +17 -17
  30. package/dist/discovery.js +1 -1
  31. package/dist/discovery.js.map +1 -1
  32. package/dist/identity.d.ts +0 -51
  33. package/dist/identity.d.ts.map +1 -1
  34. package/dist/identity.js +0 -50
  35. package/dist/identity.js.map +1 -1
  36. package/dist/index.d.ts +0 -13
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +0 -10
  39. package/dist/index.js.map +1 -1
  40. package/dist/signalActionMap.d.ts.map +1 -1
  41. package/dist/signalActionMap.js +14 -21
  42. package/dist/signalActionMap.js.map +1 -1
  43. package/dist/swarms.d.ts +0 -13
  44. package/dist/swarms.d.ts.map +1 -1
  45. package/dist/swarms.js +0 -4
  46. package/dist/swarms.js.map +1 -1
  47. package/dist/tools.d.ts.map +1 -1
  48. package/dist/tools.js +2 -7
  49. package/dist/tools.js.map +1 -1
  50. package/package.json +1 -1
  51. package/dist/__tests__/autonomous.goalBootstrap.test.d.ts +0 -2
  52. package/dist/__tests__/autonomous.goalBootstrap.test.d.ts.map +0 -1
  53. package/dist/__tests__/autonomous.goalBootstrap.test.js +0 -148
  54. package/dist/__tests__/autonomous.goalBootstrap.test.js.map +0 -1
  55. package/dist/__tests__/autonomous.miningTrack.test.d.ts +0 -2
  56. package/dist/__tests__/autonomous.miningTrack.test.d.ts.map +0 -1
  57. package/dist/__tests__/autonomous.miningTrack.test.js +0 -38
  58. package/dist/__tests__/autonomous.miningTrack.test.js.map +0 -1
  59. package/dist/__tests__/goalLoop.test.d.ts +0 -2
  60. package/dist/__tests__/goalLoop.test.d.ts.map +0 -1
  61. package/dist/__tests__/goalLoop.test.js +0 -335
  62. package/dist/__tests__/goalLoop.test.js.map +0 -1
  63. package/dist/__tests__/loadProfile.test.d.ts +0 -8
  64. package/dist/__tests__/loadProfile.test.d.ts.map +0 -1
  65. package/dist/__tests__/loadProfile.test.js +0 -134
  66. package/dist/__tests__/loadProfile.test.js.map +0 -1
  67. package/dist/__tests__/mining.test.d.ts +0 -2
  68. package/dist/__tests__/mining.test.d.ts.map +0 -1
  69. package/dist/__tests__/mining.test.js +0 -306
  70. package/dist/__tests__/mining.test.js.map +0 -1
  71. package/dist/__tests__/presetLoader.test.d.ts +0 -2
  72. package/dist/__tests__/presetLoader.test.d.ts.map +0 -1
  73. package/dist/__tests__/presetLoader.test.js +0 -749
  74. package/dist/__tests__/presetLoader.test.js.map +0 -1
  75. package/dist/goal/goalLoop.d.ts +0 -78
  76. package/dist/goal/goalLoop.d.ts.map +0 -1
  77. package/dist/goal/goalLoop.js +0 -376
  78. package/dist/goal/goalLoop.js.map +0 -1
  79. package/dist/goal/goalPrompts.d.ts +0 -20
  80. package/dist/goal/goalPrompts.d.ts.map +0 -1
  81. package/dist/goal/goalPrompts.js +0 -54
  82. package/dist/goal/goalPrompts.js.map +0 -1
  83. package/dist/goal/types.d.ts +0 -98
  84. package/dist/goal/types.d.ts.map +0 -1
  85. package/dist/goal/types.js +0 -7
  86. package/dist/goal/types.js.map +0 -1
  87. package/dist/loadProfile.d.ts +0 -100
  88. package/dist/loadProfile.d.ts.map +0 -1
  89. package/dist/loadProfile.js +0 -221
  90. package/dist/loadProfile.js.map +0 -1
  91. package/dist/mining.d.ts +0 -155
  92. package/dist/mining.d.ts.map +0 -1
  93. package/dist/mining.js +0 -365
  94. package/dist/mining.js.map +0 -1
  95. package/dist/presetLoader.d.ts +0 -130
  96. package/dist/presetLoader.d.ts.map +0 -1
  97. package/dist/presetLoader.js +0 -734
  98. package/dist/presetLoader.js.map +0 -1
@@ -44,7 +44,6 @@ import { wrapUntrusted, sanitizeForPrompt, UNTRUSTED_CONTENT_INSTRUCTION } from
44
44
  import { getAvailableActionsFromMap } from "./signalActionMap.js";
45
45
  import { getCategoryListing, getToolsInCategory } from "./actionCatalog.js";
46
46
  import { WakeUpStack } from "./wakeUpStack.js";
47
- import { GoalLoop } from "./goal/goalLoop.js";
48
47
  import { hooks as defaultHooks } from "./hooks.js";
49
48
  import { guardrails as defaultGuardrails, GuardrailTripped, InputGuardrailTripped, } from "./guardrails.js";
50
49
  import { buildCorrectivePrompt, checkForDoomLoopFromSignatures, makeSignature, } from "./doomLoop.js";
@@ -95,10 +94,6 @@ const ON_CHAIN_ACTIONS = new Set([
95
94
  "vote_kick_guild_member",
96
95
  "mining_counter_argument", "mining_defend_trace",
97
96
  "claim_mining_subtask", "submit_subtask_trace",
98
- // RLM trajectory submission — symmetric with submit_reasoning_trace per
99
- // roadmap §1h Decision 11. Approval-gates the submission before the gateway
100
- // pipes the artifact through /submit-solution → submitRlmTrajectory.
101
- "submit_rlm",
102
97
  // API marketplace on-chain actions use existing service/* prepare endpoints
103
98
  // Social (missing)
104
99
  "remove_vote", "revoke_attestation",
@@ -144,29 +139,6 @@ const ON_CHAIN_ACTIONS = new Set([
144
139
  export function getAvailableActions(signalType, loadedCategories) {
145
140
  return getAvailableActionsFromMap(signalType, loadedCategories ?? new Set());
146
141
  }
147
- /**
148
- * Maps a `mining_opportunity` signal's optional `track` field to the
149
- * track-specific action set the agent's brain should consider. Values are
150
- * comma-joined strings ready to drop into the prompt's "Available actions"
151
- * line.
152
- *
153
- * Unknown / missing track falls back to the generic mining action list —
154
- * preserves pre-Phase-3 behaviour for callers that don't set `track`.
155
- */
156
- export function availableActionsForTrack(track) {
157
- switch (track) {
158
- case "knowledge":
159
- return "discover_mining_challenges, get_mining_challenge, submit_reasoning_trace, upload_mining_content";
160
- case "embedding":
161
- return "list_embedding_challenges, submit_embeddings";
162
- case "rlm":
163
- return "discover_mining_challenges, get_mining_challenge, rlm_repl_exec, rlm_repl_llm_query, rlm_repl_finalize";
164
- case "gradient":
165
- return "discover_mining_challenges, get_mining_challenge"; // gradient solver still TBD
166
- default:
167
- return "discover_mining_challenges, get_mining_challenge, submit_reasoning_trace, upload_mining_content";
168
- }
169
- }
170
142
  export class AutonomousAgent {
171
143
  runtime;
172
144
  verbose;
@@ -239,21 +211,6 @@ export class AutonomousAgent {
239
211
  if (this.verbose) {
240
212
  console.log("[autonomous] AutonomousAgent started — handling signals + actions");
241
213
  }
242
- // Pre-load tool categories so the LLM always has web_search +
243
- // search_knowledge visible without a browse_tools cold-start.
244
- // Saves ~1 LLM turn per goal-driven agent and simplifies the first
245
- // step for reactive agents too (CLAUDE.md rule — small code change).
246
- this.loadedCategories.add("tools");
247
- this.loadedCategories.add("discovery");
248
- this.loadedCategories.add("knowledge");
249
- // Goal bootstrap — run the GoalLoop in background if this agent was
250
- // forged with initial_goal set (L1 swarm auto-deploy). Failures are
251
- // non-fatal: the agent continues in normal reactive mode.
252
- this.maybeBootstrapGoal().catch((err) => {
253
- if (this.verbose) {
254
- console.error("[autonomous] Goal bootstrap failed:", err);
255
- }
256
- });
257
214
  }
258
215
  /** Stop the autonomous agent. */
259
216
  stop() {
@@ -263,157 +220,6 @@ export class AutonomousAgent {
263
220
  }
264
221
  }
265
222
  // ================================================================
266
- // Goal bootstrap (L3 — migration 247)
267
- // ================================================================
268
- /**
269
- * Check whether this agent has an initial_goal + pending status, and
270
- * if so, spin up a GoalLoop in the background. Non-blocking — start()
271
- * returns immediately so WebSocket signal subscriptions are live even
272
- * while the goal loop is running its first step.
273
- */
274
- async maybeBootstrapGoal() {
275
- let goalConfig;
276
- try {
277
- goalConfig = await this.runtime.identity.getGoal();
278
- }
279
- catch (err) {
280
- if (this.verbose) {
281
- console.error("[autonomous] getGoal failed — treating as no goal:", err);
282
- }
283
- return;
284
- }
285
- if (!goalConfig || !goalConfig.initialGoal)
286
- return;
287
- if (goalConfig.goalStatus !== "pending") {
288
- if (this.verbose) {
289
- console.log(`[autonomous] Skipping goal bootstrap — status is ${goalConfig.goalStatus}, not 'pending'`);
290
- }
291
- return;
292
- }
293
- if (this.verbose) {
294
- console.log(`[autonomous] Goal bootstrap: "${goalConfig.initialGoal.slice(0, 80)}..." budget=${goalConfig.goalBudgetNook ?? "unlimited"}`);
295
- }
296
- // Transition status atomically before running the loop. If the
297
- // gateway rejects (network, permissions), bail out — we do not want
298
- // to run the loop with a mismatched DB state.
299
- try {
300
- await this.runtime.identity.updateGoalStatus("in_progress");
301
- }
302
- catch (err) {
303
- if (this.verbose) {
304
- console.error("[autonomous] Failed to transition goal → in_progress:", err);
305
- }
306
- return;
307
- }
308
- const budgetNook = goalConfig.goalBudgetNook ? BigInt(goalConfig.goalBudgetNook) : 0n;
309
- const loopOptions = {
310
- runtime: this.runtime,
311
- goal: goalConfig.initialGoal,
312
- budgetNook,
313
- parentSwarmId: goalConfig.goalParentSwarmId,
314
- verbose: this.verbose,
315
- };
316
- const loop = new GoalLoop(loopOptions);
317
- let result;
318
- try {
319
- result = await loop.run();
320
- }
321
- catch (err) {
322
- const msg = err instanceof Error ? err.message : String(err);
323
- if (this.verbose) {
324
- console.error("[autonomous] GoalLoop threw:", err);
325
- }
326
- // Transition to failed so the UI reflects the error.
327
- await this.runtime.identity.updateGoalStatus("failed").catch(() => { });
328
- await this.runtime.identity.createPendingTask({
329
- reason: "unclear_goal",
330
- description: `Goal loop crashed: ${msg.slice(0, 400)}`,
331
- parentSwarmId: goalConfig.goalParentSwarmId,
332
- }).catch(() => { });
333
- return;
334
- }
335
- await this.handleGoalResult(result, goalConfig);
336
- }
337
- /**
338
- * Dispatch on the terminal state of a GoalLoop run:
339
- * - complete → store artifact in private KG, pause agent
340
- * - blocked_budget → create pending task (budget_exhausted), pause
341
- * - blocked_stuck → create pending task (stuck_3x), pause
342
- * - blocked_capability → create pending task (needs_capability), pause
343
- */
344
- async handleGoalResult(result, goalConfig) {
345
- if (result.outcome === "complete") {
346
- // Store deliverable in private KG
347
- let artifactId = null;
348
- try {
349
- const storeResult = (await this.runtime.connection.request("POST", "/v1/agents/me/knowledge", {
350
- contentText: result.artifact.body,
351
- title: result.artifact.title,
352
- domain: result.artifact.domain,
353
- visibility: "private",
354
- knowledgeType: "fact",
355
- sourceType: "import",
356
- metadata: {
357
- goal: goalConfig.initialGoal,
358
- parentSwarmId: goalConfig.goalParentSwarmId,
359
- stepsExecuted: result.stepsExecuted,
360
- spentNook: result.spentNook.toString(),
361
- },
362
- }));
363
- artifactId = storeResult?.id ?? null;
364
- }
365
- catch (err) {
366
- if (this.verbose) {
367
- console.error("[autonomous] Failed to store goal artifact:", err);
368
- }
369
- }
370
- try {
371
- await this.runtime.identity.completeGoal(artifactId ?? "unknown");
372
- }
373
- catch (err) {
374
- if (this.verbose) {
375
- console.error("[autonomous] completeGoal failed:", err);
376
- }
377
- }
378
- // Q3: agent pauses after completion, does not stay reactive
379
- this.stop();
380
- return;
381
- }
382
- if (result.outcome === "blocked_budget") {
383
- // initialGoal is non-null here — maybeBootstrapGoal returned early otherwise.
384
- const goalText = goalConfig.initialGoal ?? "(unknown)";
385
- await this.runtime.identity.createPendingTask({
386
- reason: "budget_exhausted",
387
- description: `Needs top-off to continue goal: ${goalText.slice(0, 300)}`,
388
- parentSwarmId: goalConfig.goalParentSwarmId,
389
- }).catch(() => { });
390
- await this.runtime.identity.updateGoalStatus("paused_awaiting_topoff").catch(() => { });
391
- this.stop();
392
- return;
393
- }
394
- if (result.outcome === "blocked_stuck") {
395
- await this.runtime.identity.createPendingTask({
396
- reason: "stuck_3x",
397
- description: result.stuckReason,
398
- parentSwarmId: goalConfig.goalParentSwarmId,
399
- }).catch(() => { });
400
- await this.runtime.identity.updateGoalStatus("blocked_needs_decision").catch(() => { });
401
- this.stop();
402
- return;
403
- }
404
- if (result.outcome === "blocked_capability") {
405
- await this.runtime.identity.createPendingTask({
406
- reason: "needs_capability",
407
- description: result.capabilityNeeded,
408
- suggestedPresetId: result.suggestedPreset,
409
- parentSwarmId: goalConfig.goalParentSwarmId,
410
- }).catch(() => { });
411
- await this.runtime.identity.updateGoalStatus("blocked_needs_decision").catch(() => { });
412
- this.stop();
413
- return;
414
- }
415
- }
416
- // ================================================================
417
223
  // Signal handling (proactive.signal)
418
224
  // ================================================================
419
225
  /**
@@ -644,7 +450,9 @@ export class AutonomousAgent {
644
450
  case "community_gap":
645
451
  await this.handleCommunityGap(data);
646
452
  break;
647
- // DD-7: directive case removed — swarm coordination uses DMs
453
+ case "directive":
454
+ await this.handleDirective(data);
455
+ break;
648
456
  case "files_committed":
649
457
  await this.handleFilesCommitted(data);
650
458
  break;
@@ -1290,12 +1098,6 @@ export class AutonomousAgent {
1290
1098
  const challengeId = meta.challengeId ?? "";
1291
1099
  const difficulty = meta.difficulty ?? "";
1292
1100
  const domainTags = meta.domainTags ?? [];
1293
- // Phase 3d: optional `track` discriminator routes the prompt's "Available
1294
- // actions" hint to the right per-track action set so the agent's brain
1295
- // suggests the appropriate solver tool. `track` is informational — the
1296
- // existing dispatch surface still handles every action via the unified
1297
- // POST /v1/actions/execute route.
1298
- const track = meta.track ?? "";
1299
1101
  try {
1300
1102
  let prompt = `${UNTRUSTED_CONTENT_INSTRUCTION}\n\nA mining opportunity was found on Nookplot.\n`;
1301
1103
  if (opportunityType === "open_challenge") {
@@ -1303,10 +1105,8 @@ export class AutonomousAgent {
1303
1105
  prompt += `Challenge: ${sanitizeForPrompt(challengeId)}\n`;
1304
1106
  prompt += `Difficulty: ${difficulty}\n`;
1305
1107
  prompt += `Domains: ${domainTags.join(", ")}\n\n`;
1306
- if (track)
1307
- prompt += `Track: ${sanitizeForPrompt(track)}\n`;
1308
1108
  prompt += "Should you attempt this challenge? Consider your expertise and current staking tier.\n";
1309
- prompt += `Available actions: ${availableActionsForTrack(track)}\n`;
1109
+ prompt += "Available actions: discover_mining_challenges, get_mining_challenge, submit_reasoning_trace, upload_mining_content\n";
1310
1110
  }
1311
1111
  else if (opportunityType === "unclaimed_royalties") {
1312
1112
  prompt += `Type: Unclaimed mining rewards\n`;
@@ -2171,7 +1971,40 @@ export class AutonomousAgent {
2171
1971
  console.error("[autonomous] Community gap handling failed:", err);
2172
1972
  }
2173
1973
  }
2174
- // DD-7: handleDirective removed — swarm coordination uses DMs exclusively
1974
+ async handleDirective(data) {
1975
+ const directiveContent = data.messagePreview ?? "";
1976
+ const channelId = data.channelId;
1977
+ const community = data.community ?? "general";
1978
+ try {
1979
+ const prompt = `${UNTRUSTED_CONTENT_INSTRUCTION}\n\n` +
1980
+ "You received a directive on Nookplot.\n" +
1981
+ `Directive:\n${wrapUntrusted(directiveContent, "directive")}\n\n` +
1982
+ "Follow the directive and compose your response.\n" +
1983
+ "If it asks you to post, write the post content.\n" +
1984
+ "If it asks you to discuss, write a discussion message.\n" +
1985
+ "If you can't follow this directive, respond with exactly: [SKIP]\n\n" +
1986
+ "Your response (under 500 chars):";
1987
+ const response = await this.generateResponse(prompt);
1988
+ const content = response?.trim() ?? "";
1989
+ if (content && content !== "[SKIP]") {
1990
+ if (channelId) {
1991
+ await this.runtime.channels.send(channelId, content);
1992
+ if (this.verbose)
1993
+ console.log(`[autonomous] ✓ Directive response sent to channel ${channelId.slice(0, 12)}`);
1994
+ }
1995
+ else {
1996
+ const title = content.slice(0, 100);
1997
+ await this.runtime.memory.publishKnowledge({ title, body: content, community });
1998
+ if (this.verbose)
1999
+ console.log(`[autonomous] ✓ Directive response posted in ${community}`);
2000
+ }
2001
+ }
2002
+ }
2003
+ catch (err) {
2004
+ if (this.verbose)
2005
+ console.error("[autonomous] Directive handling failed:", err);
2006
+ }
2007
+ }
2175
2008
  // ================================================================
2176
2009
  // Project collaboration signal handlers
2177
2010
  // ================================================================
@@ -2858,18 +2691,6 @@ export class AutonomousAgent {
2858
2691
  triggers: this.doomLoopTriggers,
2859
2692
  actionType,
2860
2693
  });
2861
- // Track C.2: also push to gateway as fire-and-forget telemetry so
2862
- // ops dashboards can answer "which tools most often misbehave?"
2863
- // and "is this agent stuck right now?" — see
2864
- // gateway/src/services/doomLoopMetrics.ts. Errors are swallowed so
2865
- // a backend outage never blocks the runtime's recovery path.
2866
- void this.runtime.connection
2867
- .request("POST", "/v1/agents/me/doom-loop-event", {
2868
- offender: doomOffender,
2869
- triggers: this.doomLoopTriggers,
2870
- actionType,
2871
- })
2872
- .catch(() => { });
2873
2694
  if (this.doomLoopTriggers >= AUTONOMOUS_DOOM_LOOP_MAX_TRIGGERS) {
2874
2695
  if (this.verbose) {
2875
2696
  console.warn(`[autonomous] ✗ doom loop on '${doomOffender}' (${this.doomLoopTriggers} triggers) — aborting cycle`);