@nookplot/runtime 0.5.136 → 0.5.138

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 (101) hide show
  1. package/dist/__tests__/autonomous.getAvailableActions.test.js +1 -4
  2. package/dist/__tests__/autonomous.getAvailableActions.test.js.map +1 -1
  3. package/dist/__tests__/autonomous.v11OpenSignals.test.d.ts +14 -0
  4. package/dist/__tests__/autonomous.v11OpenSignals.test.d.ts.map +1 -0
  5. package/dist/__tests__/autonomous.v11OpenSignals.test.js +71 -0
  6. package/dist/__tests__/autonomous.v11OpenSignals.test.js.map +1 -0
  7. package/dist/__tests__/codegen-drift.test.js +1 -3
  8. package/dist/__tests__/codegen-drift.test.js.map +1 -1
  9. package/dist/__tests__/connection.autoReauth.test.d.ts +19 -0
  10. package/dist/__tests__/connection.autoReauth.test.d.ts.map +1 -0
  11. package/dist/__tests__/connection.autoReauth.test.js +182 -0
  12. package/dist/__tests__/connection.autoReauth.test.js.map +1 -0
  13. package/dist/__tests__/conversation/modelThresholdsParity.test.js +11 -6
  14. package/dist/__tests__/conversation/modelThresholdsParity.test.js.map +1 -1
  15. package/dist/__tests__/helpers/mockRuntime.d.ts.map +1 -1
  16. package/dist/__tests__/helpers/mockRuntime.js +0 -7
  17. package/dist/__tests__/helpers/mockRuntime.js.map +1 -1
  18. package/dist/__tests__/sandbox.test.js +24 -24
  19. package/dist/actionCatalog.generated.d.ts +1 -1
  20. package/dist/actionCatalog.generated.d.ts.map +1 -1
  21. package/dist/actionCatalog.generated.js +23 -108
  22. package/dist/actionCatalog.generated.js.map +1 -1
  23. package/dist/autonomous.d.ts +1 -15
  24. package/dist/autonomous.d.ts.map +1 -1
  25. package/dist/autonomous.js +37 -181
  26. package/dist/autonomous.js.map +1 -1
  27. package/dist/connection.d.ts +26 -2
  28. package/dist/connection.d.ts.map +1 -1
  29. package/dist/connection.js +109 -5
  30. package/dist/connection.js.map +1 -1
  31. package/dist/contentSafety.d.ts +1 -1
  32. package/dist/contentSafety.d.ts.map +1 -1
  33. package/dist/contentSafety.js +2 -6
  34. package/dist/contentSafety.js.map +1 -1
  35. package/dist/conversation/modelLimits.js +17 -17
  36. package/dist/discovery.js +1 -1
  37. package/dist/discovery.js.map +1 -1
  38. package/dist/identity.d.ts +0 -51
  39. package/dist/identity.d.ts.map +1 -1
  40. package/dist/identity.js +0 -50
  41. package/dist/identity.js.map +1 -1
  42. package/dist/index.d.ts +1 -9
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +0 -5
  45. package/dist/index.js.map +1 -1
  46. package/dist/signalActionMap.d.ts.map +1 -1
  47. package/dist/signalActionMap.js +30 -0
  48. package/dist/signalActionMap.js.map +1 -1
  49. package/dist/swarms.d.ts +0 -13
  50. package/dist/swarms.d.ts.map +1 -1
  51. package/dist/swarms.js +0 -4
  52. package/dist/swarms.js.map +1 -1
  53. package/dist/tools.js +1 -1
  54. package/dist/tools.js.map +1 -1
  55. package/dist/types.d.ts +13 -0
  56. package/dist/types.d.ts.map +1 -1
  57. package/package.json +2 -2
  58. package/dist/__tests__/autonomous.goalBootstrap.test.d.ts +0 -2
  59. package/dist/__tests__/autonomous.goalBootstrap.test.d.ts.map +0 -1
  60. package/dist/__tests__/autonomous.goalBootstrap.test.js +0 -148
  61. package/dist/__tests__/autonomous.goalBootstrap.test.js.map +0 -1
  62. package/dist/__tests__/autonomous.miningTrack.test.d.ts +0 -2
  63. package/dist/__tests__/autonomous.miningTrack.test.d.ts.map +0 -1
  64. package/dist/__tests__/autonomous.miningTrack.test.js +0 -38
  65. package/dist/__tests__/autonomous.miningTrack.test.js.map +0 -1
  66. package/dist/__tests__/goalLoop.test.d.ts +0 -2
  67. package/dist/__tests__/goalLoop.test.d.ts.map +0 -1
  68. package/dist/__tests__/goalLoop.test.js +0 -335
  69. package/dist/__tests__/goalLoop.test.js.map +0 -1
  70. package/dist/__tests__/loadProfile.test.d.ts +0 -8
  71. package/dist/__tests__/loadProfile.test.d.ts.map +0 -1
  72. package/dist/__tests__/loadProfile.test.js +0 -134
  73. package/dist/__tests__/loadProfile.test.js.map +0 -1
  74. package/dist/__tests__/mining.test.d.ts +0 -2
  75. package/dist/__tests__/mining.test.d.ts.map +0 -1
  76. package/dist/__tests__/mining.test.js +0 -306
  77. package/dist/__tests__/mining.test.js.map +0 -1
  78. package/dist/__tests__/presetLoader.test.d.ts +0 -2
  79. package/dist/__tests__/presetLoader.test.d.ts.map +0 -1
  80. package/dist/__tests__/presetLoader.test.js +0 -749
  81. package/dist/__tests__/presetLoader.test.js.map +0 -1
  82. package/dist/goal/goalLoop.d.ts +0 -78
  83. package/dist/goal/goalLoop.d.ts.map +0 -1
  84. package/dist/goal/goalLoop.js +0 -376
  85. package/dist/goal/goalLoop.js.map +0 -1
  86. package/dist/goal/goalPrompts.d.ts +0 -20
  87. package/dist/goal/goalPrompts.d.ts.map +0 -1
  88. package/dist/goal/goalPrompts.js +0 -54
  89. package/dist/goal/goalPrompts.js.map +0 -1
  90. package/dist/goal/types.d.ts +0 -98
  91. package/dist/goal/types.d.ts.map +0 -1
  92. package/dist/goal/types.js +0 -7
  93. package/dist/goal/types.js.map +0 -1
  94. package/dist/loadProfile.d.ts +0 -100
  95. package/dist/loadProfile.d.ts.map +0 -1
  96. package/dist/loadProfile.js +0 -221
  97. package/dist/loadProfile.js.map +0 -1
  98. package/dist/presetLoader.d.ts +0 -130
  99. package/dist/presetLoader.d.ts.map +0 -1
  100. package/dist/presetLoader.js +0 -734
  101. 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";
@@ -243,21 +242,6 @@ export class AutonomousAgent {
243
242
  if (this.verbose) {
244
243
  console.log("[autonomous] AutonomousAgent started — handling signals + actions");
245
244
  }
246
- // Pre-load tool categories so the LLM always has web_search +
247
- // search_knowledge visible without a browse_tools cold-start.
248
- // Saves ~1 LLM turn per goal-driven agent and simplifies the first
249
- // step for reactive agents too (CLAUDE.md rule — small code change).
250
- this.loadedCategories.add("tools");
251
- this.loadedCategories.add("discovery");
252
- this.loadedCategories.add("knowledge");
253
- // Goal bootstrap — run the GoalLoop in background if this agent was
254
- // forged with initial_goal set (L1 swarm auto-deploy). Failures are
255
- // non-fatal: the agent continues in normal reactive mode.
256
- this.maybeBootstrapGoal().catch((err) => {
257
- if (this.verbose) {
258
- console.error("[autonomous] Goal bootstrap failed:", err);
259
- }
260
- });
261
245
  }
262
246
  /** Stop the autonomous agent. */
263
247
  stop() {
@@ -267,157 +251,6 @@ export class AutonomousAgent {
267
251
  }
268
252
  }
269
253
  // ================================================================
270
- // Goal bootstrap (L3 — migration 247)
271
- // ================================================================
272
- /**
273
- * Check whether this agent has an initial_goal + pending status, and
274
- * if so, spin up a GoalLoop in the background. Non-blocking — start()
275
- * returns immediately so WebSocket signal subscriptions are live even
276
- * while the goal loop is running its first step.
277
- */
278
- async maybeBootstrapGoal() {
279
- let goalConfig;
280
- try {
281
- goalConfig = await this.runtime.identity.getGoal();
282
- }
283
- catch (err) {
284
- if (this.verbose) {
285
- console.error("[autonomous] getGoal failed — treating as no goal:", err);
286
- }
287
- return;
288
- }
289
- if (!goalConfig || !goalConfig.initialGoal)
290
- return;
291
- if (goalConfig.goalStatus !== "pending") {
292
- if (this.verbose) {
293
- console.log(`[autonomous] Skipping goal bootstrap — status is ${goalConfig.goalStatus}, not 'pending'`);
294
- }
295
- return;
296
- }
297
- if (this.verbose) {
298
- console.log(`[autonomous] Goal bootstrap: "${goalConfig.initialGoal.slice(0, 80)}..." budget=${goalConfig.goalBudgetNook ?? "unlimited"}`);
299
- }
300
- // Transition status atomically before running the loop. If the
301
- // gateway rejects (network, permissions), bail out — we do not want
302
- // to run the loop with a mismatched DB state.
303
- try {
304
- await this.runtime.identity.updateGoalStatus("in_progress");
305
- }
306
- catch (err) {
307
- if (this.verbose) {
308
- console.error("[autonomous] Failed to transition goal → in_progress:", err);
309
- }
310
- return;
311
- }
312
- const budgetNook = goalConfig.goalBudgetNook ? BigInt(goalConfig.goalBudgetNook) : 0n;
313
- const loopOptions = {
314
- runtime: this.runtime,
315
- goal: goalConfig.initialGoal,
316
- budgetNook,
317
- parentSwarmId: goalConfig.goalParentSwarmId,
318
- verbose: this.verbose,
319
- };
320
- const loop = new GoalLoop(loopOptions);
321
- let result;
322
- try {
323
- result = await loop.run();
324
- }
325
- catch (err) {
326
- const msg = err instanceof Error ? err.message : String(err);
327
- if (this.verbose) {
328
- console.error("[autonomous] GoalLoop threw:", err);
329
- }
330
- // Transition to failed so the UI reflects the error.
331
- await this.runtime.identity.updateGoalStatus("failed").catch(() => { });
332
- await this.runtime.identity.createPendingTask({
333
- reason: "unclear_goal",
334
- description: `Goal loop crashed: ${msg.slice(0, 400)}`,
335
- parentSwarmId: goalConfig.goalParentSwarmId,
336
- }).catch(() => { });
337
- return;
338
- }
339
- await this.handleGoalResult(result, goalConfig);
340
- }
341
- /**
342
- * Dispatch on the terminal state of a GoalLoop run:
343
- * - complete → store artifact in private KG, pause agent
344
- * - blocked_budget → create pending task (budget_exhausted), pause
345
- * - blocked_stuck → create pending task (stuck_3x), pause
346
- * - blocked_capability → create pending task (needs_capability), pause
347
- */
348
- async handleGoalResult(result, goalConfig) {
349
- if (result.outcome === "complete") {
350
- // Store deliverable in private KG
351
- let artifactId = null;
352
- try {
353
- const storeResult = (await this.runtime.connection.request("POST", "/v1/agents/me/knowledge", {
354
- contentText: result.artifact.body,
355
- title: result.artifact.title,
356
- domain: result.artifact.domain,
357
- visibility: "private",
358
- knowledgeType: "fact",
359
- sourceType: "import",
360
- metadata: {
361
- goal: goalConfig.initialGoal,
362
- parentSwarmId: goalConfig.goalParentSwarmId,
363
- stepsExecuted: result.stepsExecuted,
364
- spentNook: result.spentNook.toString(),
365
- },
366
- }));
367
- artifactId = storeResult?.id ?? null;
368
- }
369
- catch (err) {
370
- if (this.verbose) {
371
- console.error("[autonomous] Failed to store goal artifact:", err);
372
- }
373
- }
374
- try {
375
- await this.runtime.identity.completeGoal(artifactId ?? "unknown");
376
- }
377
- catch (err) {
378
- if (this.verbose) {
379
- console.error("[autonomous] completeGoal failed:", err);
380
- }
381
- }
382
- // Q3: agent pauses after completion, does not stay reactive
383
- this.stop();
384
- return;
385
- }
386
- if (result.outcome === "blocked_budget") {
387
- // initialGoal is non-null here — maybeBootstrapGoal returned early otherwise.
388
- const goalText = goalConfig.initialGoal ?? "(unknown)";
389
- await this.runtime.identity.createPendingTask({
390
- reason: "budget_exhausted",
391
- description: `Needs top-off to continue goal: ${goalText.slice(0, 300)}`,
392
- parentSwarmId: goalConfig.goalParentSwarmId,
393
- }).catch(() => { });
394
- await this.runtime.identity.updateGoalStatus("paused_awaiting_topoff").catch(() => { });
395
- this.stop();
396
- return;
397
- }
398
- if (result.outcome === "blocked_stuck") {
399
- await this.runtime.identity.createPendingTask({
400
- reason: "stuck_3x",
401
- description: result.stuckReason,
402
- parentSwarmId: goalConfig.goalParentSwarmId,
403
- }).catch(() => { });
404
- await this.runtime.identity.updateGoalStatus("blocked_needs_decision").catch(() => { });
405
- this.stop();
406
- return;
407
- }
408
- if (result.outcome === "blocked_capability") {
409
- await this.runtime.identity.createPendingTask({
410
- reason: "needs_capability",
411
- description: result.capabilityNeeded,
412
- suggestedPresetId: result.suggestedPreset,
413
- parentSwarmId: goalConfig.goalParentSwarmId,
414
- }).catch(() => { });
415
- await this.runtime.identity.updateGoalStatus("blocked_needs_decision").catch(() => { });
416
- this.stop();
417
- return;
418
- }
419
- }
420
- // ================================================================
421
254
  // Signal handling (proactive.signal)
422
255
  // ================================================================
423
256
  /**
@@ -648,7 +481,9 @@ export class AutonomousAgent {
648
481
  case "community_gap":
649
482
  await this.handleCommunityGap(data);
650
483
  break;
651
- // DD-7: directive case removed — swarm coordination uses DMs
484
+ case "directive":
485
+ await this.handleDirective(data);
486
+ break;
652
487
  case "files_committed":
653
488
  await this.handleFilesCommitted(data);
654
489
  break;
@@ -2179,7 +2014,40 @@ export class AutonomousAgent {
2179
2014
  console.error("[autonomous] Community gap handling failed:", err);
2180
2015
  }
2181
2016
  }
2182
- // DD-7: handleDirective removed — swarm coordination uses DMs exclusively
2017
+ async handleDirective(data) {
2018
+ const directiveContent = data.messagePreview ?? "";
2019
+ const channelId = data.channelId;
2020
+ const community = data.community ?? "general";
2021
+ try {
2022
+ const prompt = `${UNTRUSTED_CONTENT_INSTRUCTION}\n\n` +
2023
+ "You received a directive on Nookplot.\n" +
2024
+ `Directive:\n${wrapUntrusted(directiveContent, "directive")}\n\n` +
2025
+ "Follow the directive and compose your response.\n" +
2026
+ "If it asks you to post, write the post content.\n" +
2027
+ "If it asks you to discuss, write a discussion message.\n" +
2028
+ "If you can't follow this directive, respond with exactly: [SKIP]\n\n" +
2029
+ "Your response (under 500 chars):";
2030
+ const response = await this.generateResponse(prompt);
2031
+ const content = response?.trim() ?? "";
2032
+ if (content && content !== "[SKIP]") {
2033
+ if (channelId) {
2034
+ await this.runtime.channels.send(channelId, content);
2035
+ if (this.verbose)
2036
+ console.log(`[autonomous] ✓ Directive response sent to channel ${channelId.slice(0, 12)}`);
2037
+ }
2038
+ else {
2039
+ const title = content.slice(0, 100);
2040
+ await this.runtime.memory.publishKnowledge({ title, body: content, community });
2041
+ if (this.verbose)
2042
+ console.log(`[autonomous] ✓ Directive response posted in ${community}`);
2043
+ }
2044
+ }
2045
+ }
2046
+ catch (err) {
2047
+ if (this.verbose)
2048
+ console.error("[autonomous] Directive handling failed:", err);
2049
+ }
2050
+ }
2183
2051
  // ================================================================
2184
2052
  // Project collaboration signal handlers
2185
2053
  // ================================================================
@@ -2866,18 +2734,6 @@ export class AutonomousAgent {
2866
2734
  triggers: this.doomLoopTriggers,
2867
2735
  actionType,
2868
2736
  });
2869
- // Track C.2: also push to gateway as fire-and-forget telemetry so
2870
- // ops dashboards can answer "which tools most often misbehave?"
2871
- // and "is this agent stuck right now?" — see
2872
- // gateway/src/services/doomLoopMetrics.ts. Errors are swallowed so
2873
- // a backend outage never blocks the runtime's recovery path.
2874
- void this.runtime.connection
2875
- .request("POST", "/v1/agents/me/doom-loop-event", {
2876
- offender: doomOffender,
2877
- triggers: this.doomLoopTriggers,
2878
- actionType,
2879
- })
2880
- .catch(() => { });
2881
2737
  if (this.doomLoopTriggers >= AUTONOMOUS_DOOM_LOOP_MAX_TRIGGERS) {
2882
2738
  if (this.verbose) {
2883
2739
  console.warn(`[autonomous] ✗ doom loop on '${doomOffender}' (${this.doomLoopTriggers} triggers) — aborting cycle`);