@nookplot/runtime 0.5.108 → 0.5.110

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 (91) hide show
  1. package/dist/__tests__/autonomous.getAvailableActions.test.js +7 -4
  2. package/dist/__tests__/autonomous.getAvailableActions.test.js.map +1 -1
  3. package/dist/__tests__/autonomous.goalBootstrap.test.d.ts +2 -0
  4. package/dist/__tests__/autonomous.goalBootstrap.test.d.ts.map +1 -0
  5. package/dist/__tests__/autonomous.goalBootstrap.test.js +148 -0
  6. package/dist/__tests__/autonomous.goalBootstrap.test.js.map +1 -0
  7. package/dist/__tests__/conversation/modelThresholdsParity.test.js +6 -11
  8. package/dist/__tests__/conversation/modelThresholdsParity.test.js.map +1 -1
  9. package/dist/__tests__/goalLoop.test.d.ts +2 -0
  10. package/dist/__tests__/goalLoop.test.d.ts.map +1 -0
  11. package/dist/__tests__/goalLoop.test.js +224 -0
  12. package/dist/__tests__/goalLoop.test.js.map +1 -0
  13. package/dist/__tests__/helpers/mockRuntime.d.ts.map +1 -1
  14. package/dist/__tests__/helpers/mockRuntime.js +7 -0
  15. package/dist/__tests__/helpers/mockRuntime.js.map +1 -1
  16. package/dist/__tests__/lineage.test.d.ts +2 -0
  17. package/dist/__tests__/lineage.test.d.ts.map +1 -0
  18. package/dist/__tests__/lineage.test.js +131 -0
  19. package/dist/__tests__/lineage.test.js.map +1 -0
  20. package/dist/__tests__/loadProfile.test.d.ts +8 -0
  21. package/dist/__tests__/loadProfile.test.d.ts.map +1 -0
  22. package/dist/__tests__/loadProfile.test.js +134 -0
  23. package/dist/__tests__/loadProfile.test.js.map +1 -0
  24. package/dist/__tests__/presetLoader.test.d.ts +2 -0
  25. package/dist/__tests__/presetLoader.test.d.ts.map +1 -0
  26. package/dist/__tests__/presetLoader.test.js +749 -0
  27. package/dist/__tests__/presetLoader.test.js.map +1 -0
  28. package/dist/__tests__/sandbox.test.js +24 -24
  29. package/dist/actionCatalog.generated.d.ts +1 -1
  30. package/dist/actionCatalog.generated.d.ts.map +1 -1
  31. package/dist/actionCatalog.generated.js +31 -1
  32. package/dist/actionCatalog.generated.js.map +1 -1
  33. package/dist/autonomous.d.ts +15 -1
  34. package/dist/autonomous.d.ts.map +1 -1
  35. package/dist/autonomous.js +195 -37
  36. package/dist/autonomous.js.map +1 -1
  37. package/dist/connection.d.ts +1 -1
  38. package/dist/connection.d.ts.map +1 -1
  39. package/dist/connection.js +2 -1
  40. package/dist/connection.js.map +1 -1
  41. package/dist/contentSafety.d.ts +1 -1
  42. package/dist/contentSafety.d.ts.map +1 -1
  43. package/dist/contentSafety.js +6 -2
  44. package/dist/contentSafety.js.map +1 -1
  45. package/dist/conversation/modelLimits.js +17 -17
  46. package/dist/discovery.js +1 -1
  47. package/dist/discovery.js.map +1 -1
  48. package/dist/goal/goalLoop.d.ts +75 -0
  49. package/dist/goal/goalLoop.d.ts.map +1 -0
  50. package/dist/goal/goalLoop.js +347 -0
  51. package/dist/goal/goalLoop.js.map +1 -0
  52. package/dist/goal/goalPrompts.d.ts +20 -0
  53. package/dist/goal/goalPrompts.d.ts.map +1 -0
  54. package/dist/goal/goalPrompts.js +54 -0
  55. package/dist/goal/goalPrompts.js.map +1 -0
  56. package/dist/goal/types.d.ts +98 -0
  57. package/dist/goal/types.d.ts.map +1 -0
  58. package/dist/goal/types.js +7 -0
  59. package/dist/goal/types.js.map +1 -0
  60. package/dist/identity.d.ts +51 -0
  61. package/dist/identity.d.ts.map +1 -1
  62. package/dist/identity.js +50 -0
  63. package/dist/identity.js.map +1 -1
  64. package/dist/index.d.ts +10 -2
  65. package/dist/index.d.ts.map +1 -1
  66. package/dist/index.js +6 -1
  67. package/dist/index.js.map +1 -1
  68. package/dist/lineage.d.ts +69 -0
  69. package/dist/lineage.d.ts.map +1 -0
  70. package/dist/lineage.js +72 -0
  71. package/dist/lineage.js.map +1 -0
  72. package/dist/loadProfile.d.ts +100 -0
  73. package/dist/loadProfile.d.ts.map +1 -0
  74. package/dist/loadProfile.js +221 -0
  75. package/dist/loadProfile.js.map +1 -0
  76. package/dist/presetLoader.d.ts +130 -0
  77. package/dist/presetLoader.d.ts.map +1 -0
  78. package/dist/presetLoader.js +734 -0
  79. package/dist/presetLoader.js.map +1 -0
  80. package/dist/signalActionMap.d.ts.map +1 -1
  81. package/dist/signalActionMap.js +6 -12
  82. package/dist/signalActionMap.js.map +1 -1
  83. package/dist/signing.d.ts +30 -0
  84. package/dist/signing.d.ts.map +1 -1
  85. package/dist/signing.js +55 -0
  86. package/dist/signing.js.map +1 -1
  87. package/dist/swarms.d.ts +13 -0
  88. package/dist/swarms.d.ts.map +1 -1
  89. package/dist/swarms.js +4 -0
  90. package/dist/swarms.js.map +1 -1
  91. package/package.json +60 -61
@@ -44,6 +44,7 @@ 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";
47
48
  import { hooks as defaultHooks } from "./hooks.js";
48
49
  import { guardrails as defaultGuardrails, GuardrailTripped, InputGuardrailTripped, } from "./guardrails.js";
49
50
  // ----------------------------------------------------------------
@@ -112,6 +113,8 @@ const ON_CHAIN_ACTIONS = new Set([
112
113
  // Mining guild treasury (on-chain)
113
114
  "deposit_guild_mining_treasury", "claim_guild_mining_treasury",
114
115
  "claim_pending_guild_mining_treasury",
116
+ // Ecosystem partner protocols (raw-tx, agent pays own gas)
117
+ "ecosystem_stake_tokens", "ecosystem_claim_rewards",
115
118
  ]);
116
119
  /**
117
120
  * Get the list of available actions for a given signal type.
@@ -194,6 +197,21 @@ export class AutonomousAgent {
194
197
  if (this.verbose) {
195
198
  console.log("[autonomous] AutonomousAgent started — handling signals + actions");
196
199
  }
200
+ // Pre-load tool categories so the LLM always has web_search +
201
+ // search_knowledge visible without a browse_tools cold-start.
202
+ // Saves ~1 LLM turn per goal-driven agent and simplifies the first
203
+ // step for reactive agents too (CLAUDE.md rule — small code change).
204
+ this.loadedCategories.add("tools");
205
+ this.loadedCategories.add("discovery");
206
+ this.loadedCategories.add("knowledge");
207
+ // Goal bootstrap — run the GoalLoop in background if this agent was
208
+ // forged with initial_goal set (L1 swarm auto-deploy). Failures are
209
+ // non-fatal: the agent continues in normal reactive mode.
210
+ this.maybeBootstrapGoal().catch((err) => {
211
+ if (this.verbose) {
212
+ console.error("[autonomous] Goal bootstrap failed:", err);
213
+ }
214
+ });
197
215
  }
198
216
  /** Stop the autonomous agent. */
199
217
  stop() {
@@ -203,6 +221,157 @@ export class AutonomousAgent {
203
221
  }
204
222
  }
205
223
  // ================================================================
224
+ // Goal bootstrap (L3 — migration 247)
225
+ // ================================================================
226
+ /**
227
+ * Check whether this agent has an initial_goal + pending status, and
228
+ * if so, spin up a GoalLoop in the background. Non-blocking — start()
229
+ * returns immediately so WebSocket signal subscriptions are live even
230
+ * while the goal loop is running its first step.
231
+ */
232
+ async maybeBootstrapGoal() {
233
+ let goalConfig;
234
+ try {
235
+ goalConfig = await this.runtime.identity.getGoal();
236
+ }
237
+ catch (err) {
238
+ if (this.verbose) {
239
+ console.error("[autonomous] getGoal failed — treating as no goal:", err);
240
+ }
241
+ return;
242
+ }
243
+ if (!goalConfig || !goalConfig.initialGoal)
244
+ return;
245
+ if (goalConfig.goalStatus !== "pending") {
246
+ if (this.verbose) {
247
+ console.log(`[autonomous] Skipping goal bootstrap — status is ${goalConfig.goalStatus}, not 'pending'`);
248
+ }
249
+ return;
250
+ }
251
+ if (this.verbose) {
252
+ console.log(`[autonomous] Goal bootstrap: "${goalConfig.initialGoal.slice(0, 80)}..." budget=${goalConfig.goalBudgetNook ?? "unlimited"}`);
253
+ }
254
+ // Transition status atomically before running the loop. If the
255
+ // gateway rejects (network, permissions), bail out — we do not want
256
+ // to run the loop with a mismatched DB state.
257
+ try {
258
+ await this.runtime.identity.updateGoalStatus("in_progress");
259
+ }
260
+ catch (err) {
261
+ if (this.verbose) {
262
+ console.error("[autonomous] Failed to transition goal → in_progress:", err);
263
+ }
264
+ return;
265
+ }
266
+ const budgetNook = goalConfig.goalBudgetNook ? BigInt(goalConfig.goalBudgetNook) : 0n;
267
+ const loopOptions = {
268
+ runtime: this.runtime,
269
+ goal: goalConfig.initialGoal,
270
+ budgetNook,
271
+ parentSwarmId: goalConfig.goalParentSwarmId,
272
+ verbose: this.verbose,
273
+ };
274
+ const loop = new GoalLoop(loopOptions);
275
+ let result;
276
+ try {
277
+ result = await loop.run();
278
+ }
279
+ catch (err) {
280
+ const msg = err instanceof Error ? err.message : String(err);
281
+ if (this.verbose) {
282
+ console.error("[autonomous] GoalLoop threw:", err);
283
+ }
284
+ // Transition to failed so the UI reflects the error.
285
+ await this.runtime.identity.updateGoalStatus("failed").catch(() => { });
286
+ await this.runtime.identity.createPendingTask({
287
+ reason: "unclear_goal",
288
+ description: `Goal loop crashed: ${msg.slice(0, 400)}`,
289
+ parentSwarmId: goalConfig.goalParentSwarmId,
290
+ }).catch(() => { });
291
+ return;
292
+ }
293
+ await this.handleGoalResult(result, goalConfig);
294
+ }
295
+ /**
296
+ * Dispatch on the terminal state of a GoalLoop run:
297
+ * - complete → store artifact in private KG, pause agent
298
+ * - blocked_budget → create pending task (budget_exhausted), pause
299
+ * - blocked_stuck → create pending task (stuck_3x), pause
300
+ * - blocked_capability → create pending task (needs_capability), pause
301
+ */
302
+ async handleGoalResult(result, goalConfig) {
303
+ if (result.outcome === "complete") {
304
+ // Store deliverable in private KG
305
+ let artifactId = null;
306
+ try {
307
+ const storeResult = (await this.runtime.connection.request("POST", "/v1/agents/me/knowledge", {
308
+ contentText: result.artifact.body,
309
+ title: result.artifact.title,
310
+ domain: result.artifact.domain,
311
+ visibility: "private",
312
+ knowledgeType: "fact",
313
+ sourceType: "import",
314
+ metadata: {
315
+ goal: goalConfig.initialGoal,
316
+ parentSwarmId: goalConfig.goalParentSwarmId,
317
+ stepsExecuted: result.stepsExecuted,
318
+ spentNook: result.spentNook.toString(),
319
+ },
320
+ }));
321
+ artifactId = storeResult?.id ?? null;
322
+ }
323
+ catch (err) {
324
+ if (this.verbose) {
325
+ console.error("[autonomous] Failed to store goal artifact:", err);
326
+ }
327
+ }
328
+ try {
329
+ await this.runtime.identity.completeGoal(artifactId ?? "unknown");
330
+ }
331
+ catch (err) {
332
+ if (this.verbose) {
333
+ console.error("[autonomous] completeGoal failed:", err);
334
+ }
335
+ }
336
+ // Q3: agent pauses after completion, does not stay reactive
337
+ this.stop();
338
+ return;
339
+ }
340
+ if (result.outcome === "blocked_budget") {
341
+ // initialGoal is non-null here — maybeBootstrapGoal returned early otherwise.
342
+ const goalText = goalConfig.initialGoal ?? "(unknown)";
343
+ await this.runtime.identity.createPendingTask({
344
+ reason: "budget_exhausted",
345
+ description: `Needs top-off to continue goal: ${goalText.slice(0, 300)}`,
346
+ parentSwarmId: goalConfig.goalParentSwarmId,
347
+ }).catch(() => { });
348
+ await this.runtime.identity.updateGoalStatus("paused_awaiting_topoff").catch(() => { });
349
+ this.stop();
350
+ return;
351
+ }
352
+ if (result.outcome === "blocked_stuck") {
353
+ await this.runtime.identity.createPendingTask({
354
+ reason: "stuck_3x",
355
+ description: result.stuckReason,
356
+ parentSwarmId: goalConfig.goalParentSwarmId,
357
+ }).catch(() => { });
358
+ await this.runtime.identity.updateGoalStatus("blocked_needs_decision").catch(() => { });
359
+ this.stop();
360
+ return;
361
+ }
362
+ if (result.outcome === "blocked_capability") {
363
+ await this.runtime.identity.createPendingTask({
364
+ reason: "needs_capability",
365
+ description: result.capabilityNeeded,
366
+ suggestedPresetId: result.suggestedPreset,
367
+ parentSwarmId: goalConfig.goalParentSwarmId,
368
+ }).catch(() => { });
369
+ await this.runtime.identity.updateGoalStatus("blocked_needs_decision").catch(() => { });
370
+ this.stop();
371
+ return;
372
+ }
373
+ }
374
+ // ================================================================
206
375
  // Signal handling (proactive.signal)
207
376
  // ================================================================
208
377
  /**
@@ -433,9 +602,7 @@ export class AutonomousAgent {
433
602
  case "community_gap":
434
603
  await this.handleCommunityGap(data);
435
604
  break;
436
- case "directive":
437
- await this.handleDirective(data);
438
- break;
605
+ // DD-7: directive case removed — swarm coordination uses DMs
439
606
  case "files_committed":
440
607
  await this.handleFilesCommitted(data);
441
608
  break;
@@ -1954,40 +2121,7 @@ export class AutonomousAgent {
1954
2121
  console.error("[autonomous] Community gap handling failed:", err);
1955
2122
  }
1956
2123
  }
1957
- async handleDirective(data) {
1958
- const directiveContent = data.messagePreview ?? "";
1959
- const channelId = data.channelId;
1960
- const community = data.community ?? "general";
1961
- try {
1962
- const prompt = `${UNTRUSTED_CONTENT_INSTRUCTION}\n\n` +
1963
- "You received a directive on Nookplot.\n" +
1964
- `Directive:\n${wrapUntrusted(directiveContent, "directive")}\n\n` +
1965
- "Follow the directive and compose your response.\n" +
1966
- "If it asks you to post, write the post content.\n" +
1967
- "If it asks you to discuss, write a discussion message.\n" +
1968
- "If you can't follow this directive, respond with exactly: [SKIP]\n\n" +
1969
- "Your response (under 500 chars):";
1970
- const response = await this.generateResponse(prompt);
1971
- const content = response?.trim() ?? "";
1972
- if (content && content !== "[SKIP]") {
1973
- if (channelId) {
1974
- await this.runtime.channels.send(channelId, content);
1975
- if (this.verbose)
1976
- console.log(`[autonomous] ✓ Directive response sent to channel ${channelId.slice(0, 12)}`);
1977
- }
1978
- else {
1979
- const title = content.slice(0, 100);
1980
- await this.runtime.memory.publishKnowledge({ title, body: content, community });
1981
- if (this.verbose)
1982
- console.log(`[autonomous] ✓ Directive response posted in ${community}`);
1983
- }
1984
- }
1985
- }
1986
- catch (err) {
1987
- if (this.verbose)
1988
- console.error("[autonomous] Directive handling failed:", err);
1989
- }
1990
- }
2124
+ // DD-7: handleDirective removed — swarm coordination uses DMs exclusively
1991
2125
  // ================================================================
1992
2126
  // Project collaboration signal handlers
1993
2127
  // ================================================================
@@ -2715,6 +2849,30 @@ export class AutonomousAgent {
2715
2849
  });
2716
2850
  return;
2717
2851
  }
2852
+ // ── Intercept ecosystem raw-tx actions ──
2853
+ // External partner contracts (BOTCOIN, etc.) don't trust Nookplot's
2854
+ // EIP-2771 forwarder. The gateway returns { txRequests, meta } instead
2855
+ // of a ForwardRequest, and the agent signs+submits with own wallet.
2856
+ if (actionType === "ecosystem_stake_tokens" || actionType === "ecosystem_claim_rewards") {
2857
+ const { prepareSignSend } = await import("./signing.js");
2858
+ const preparePath = actionType === "ecosystem_stake_tokens"
2859
+ ? "/v1/prepare/ecosystem/stake-tokens"
2860
+ : "/v1/prepare/ecosystem/claim-rewards";
2861
+ const sendResult = await prepareSignSend(this.runtime.connection, preparePath, args);
2862
+ const hashes = sendResult.txHashes ?? [];
2863
+ txHash = hashes.length > 0 ? hashes[hashes.length - 1] : undefined;
2864
+ result = { txHashes: hashes, meta: sendResult.meta };
2865
+ result = await guardrails.runOutput(actionType, result);
2866
+ hooks.emitFireAndForget("tool_output", { toolName: actionType, args, result });
2867
+ if (actionId)
2868
+ await this.runtime.proactive.completeAction(actionId, txHash, result);
2869
+ if (this.verbose)
2870
+ console.log(`[autonomous] ✓ ${actionType}${txHash ? ` tx=${txHash}` : ""}`);
2871
+ hooks.emitFireAndForget("action_end", {
2872
+ actionType, args, result, durationMs: Date.now() - startTime, actionId, txHash,
2873
+ });
2874
+ return;
2875
+ }
2718
2876
  // ── Unified dispatch via POST /v1/actions/execute ──
2719
2877
  // The gateway's ToolDispatcher routes the call to the correct internal
2720
2878
  // endpoint, replacing the 2000+ line switch statement that was here before.