@nookplot/runtime 0.5.140 → 0.5.141

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 (106) hide show
  1. package/dist/__tests__/autonomous.dedup.test.js +0 -11
  2. package/dist/__tests__/autonomous.dedup.test.js.map +1 -1
  3. package/dist/__tests__/autonomous.getAvailableActions.test.js +1 -13
  4. package/dist/__tests__/autonomous.getAvailableActions.test.js.map +1 -1
  5. package/dist/__tests__/codegen-drift.test.js +1 -3
  6. package/dist/__tests__/codegen-drift.test.js.map +1 -1
  7. package/dist/__tests__/conversation/modelThresholdsParity.test.js +11 -6
  8. package/dist/__tests__/conversation/modelThresholdsParity.test.js.map +1 -1
  9. package/dist/__tests__/economy.frontierInference.test.d.ts +2 -0
  10. package/dist/__tests__/economy.frontierInference.test.d.ts.map +1 -0
  11. package/dist/__tests__/economy.frontierInference.test.js +61 -0
  12. package/dist/__tests__/economy.frontierInference.test.js.map +1 -0
  13. package/dist/__tests__/helpers/mockRuntime.d.ts.map +1 -1
  14. package/dist/__tests__/helpers/mockRuntime.js +0 -7
  15. package/dist/__tests__/helpers/mockRuntime.js.map +1 -1
  16. package/dist/actionCatalog.d.ts.map +1 -1
  17. package/dist/actionCatalog.generated.d.ts +1 -1
  18. package/dist/actionCatalog.generated.d.ts.map +1 -1
  19. package/dist/actionCatalog.generated.js +24 -94
  20. package/dist/actionCatalog.generated.js.map +1 -1
  21. package/dist/actionCatalog.js +10 -0
  22. package/dist/actionCatalog.js.map +1 -1
  23. package/dist/autonomous.d.ts +9 -16
  24. package/dist/autonomous.d.ts.map +1 -1
  25. package/dist/autonomous.js +66 -232
  26. package/dist/autonomous.js.map +1 -1
  27. package/dist/contentSafety.d.ts +1 -1
  28. package/dist/contentSafety.d.ts.map +1 -1
  29. package/dist/contentSafety.js +2 -6
  30. package/dist/contentSafety.js.map +1 -1
  31. package/dist/discovery.js +1 -1
  32. package/dist/discovery.js.map +1 -1
  33. package/dist/economy.d.ts +13 -0
  34. package/dist/economy.d.ts.map +1 -1
  35. package/dist/economy.js +26 -0
  36. package/dist/economy.js.map +1 -1
  37. package/dist/frontierPass.d.ts +30 -0
  38. package/dist/frontierPass.d.ts.map +1 -0
  39. package/dist/frontierPass.js +42 -0
  40. package/dist/frontierPass.js.map +1 -0
  41. package/dist/identity.d.ts +0 -51
  42. package/dist/identity.d.ts.map +1 -1
  43. package/dist/identity.js +0 -50
  44. package/dist/identity.js.map +1 -1
  45. package/dist/index.d.ts +3 -9
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +1 -5
  48. package/dist/index.js.map +1 -1
  49. package/dist/signalActionMap.d.ts.map +1 -1
  50. package/dist/signalActionMap.js +3 -9
  51. package/dist/signalActionMap.js.map +1 -1
  52. package/dist/swarms.d.ts +0 -13
  53. package/dist/swarms.d.ts.map +1 -1
  54. package/dist/swarms.js +0 -4
  55. package/dist/swarms.js.map +1 -1
  56. package/dist/tools.js +1 -1
  57. package/dist/tools.js.map +1 -1
  58. package/package.json +1 -1
  59. package/dist/__tests__/autonomous.goalBootstrap.test.d.ts +0 -2
  60. package/dist/__tests__/autonomous.goalBootstrap.test.d.ts.map +0 -1
  61. package/dist/__tests__/autonomous.goalBootstrap.test.js +0 -148
  62. package/dist/__tests__/autonomous.goalBootstrap.test.js.map +0 -1
  63. package/dist/__tests__/autonomous.miningTrack.test.d.ts +0 -2
  64. package/dist/__tests__/autonomous.miningTrack.test.d.ts.map +0 -1
  65. package/dist/__tests__/autonomous.miningTrack.test.js +0 -38
  66. package/dist/__tests__/autonomous.miningTrack.test.js.map +0 -1
  67. package/dist/__tests__/autonomous.workspaceOpportunity.test.d.ts +0 -2
  68. package/dist/__tests__/autonomous.workspaceOpportunity.test.d.ts.map +0 -1
  69. package/dist/__tests__/autonomous.workspaceOpportunity.test.js +0 -200
  70. package/dist/__tests__/autonomous.workspaceOpportunity.test.js.map +0 -1
  71. package/dist/__tests__/goalLoop.test.d.ts +0 -2
  72. package/dist/__tests__/goalLoop.test.d.ts.map +0 -1
  73. package/dist/__tests__/goalLoop.test.js +0 -335
  74. package/dist/__tests__/goalLoop.test.js.map +0 -1
  75. package/dist/__tests__/loadProfile.test.d.ts +0 -8
  76. package/dist/__tests__/loadProfile.test.d.ts.map +0 -1
  77. package/dist/__tests__/loadProfile.test.js +0 -134
  78. package/dist/__tests__/loadProfile.test.js.map +0 -1
  79. package/dist/__tests__/mining.test.d.ts +0 -2
  80. package/dist/__tests__/mining.test.d.ts.map +0 -1
  81. package/dist/__tests__/mining.test.js +0 -306
  82. package/dist/__tests__/mining.test.js.map +0 -1
  83. package/dist/__tests__/presetLoader.test.d.ts +0 -2
  84. package/dist/__tests__/presetLoader.test.d.ts.map +0 -1
  85. package/dist/__tests__/presetLoader.test.js +0 -749
  86. package/dist/__tests__/presetLoader.test.js.map +0 -1
  87. package/dist/goal/goalLoop.d.ts +0 -78
  88. package/dist/goal/goalLoop.d.ts.map +0 -1
  89. package/dist/goal/goalLoop.js +0 -376
  90. package/dist/goal/goalLoop.js.map +0 -1
  91. package/dist/goal/goalPrompts.d.ts +0 -20
  92. package/dist/goal/goalPrompts.d.ts.map +0 -1
  93. package/dist/goal/goalPrompts.js +0 -54
  94. package/dist/goal/goalPrompts.js.map +0 -1
  95. package/dist/goal/types.d.ts +0 -98
  96. package/dist/goal/types.d.ts.map +0 -1
  97. package/dist/goal/types.js +0 -7
  98. package/dist/goal/types.js.map +0 -1
  99. package/dist/loadProfile.d.ts +0 -100
  100. package/dist/loadProfile.d.ts.map +0 -1
  101. package/dist/loadProfile.js +0 -221
  102. package/dist/loadProfile.js.map +0 -1
  103. package/dist/presetLoader.d.ts +0 -130
  104. package/dist/presetLoader.d.ts.map +0 -1
  105. package/dist/presetLoader.js +0 -734
  106. package/dist/presetLoader.js.map +0 -1
@@ -1,98 +0,0 @@
1
- /**
2
- * Goal loop types — shared interfaces for the L3 autonomous goal execution loop.
3
- *
4
- * @module goal/types
5
- */
6
- import type { NookplotRuntime } from "../index.js";
7
- /**
8
- * One action the LLM can return each turn of the goal loop.
9
- * Parsed from the model's JSON response.
10
- */
11
- export type GoalAction = {
12
- type: "action";
13
- actionName: string;
14
- actionParams: Record<string, unknown>;
15
- description: string;
16
- } | {
17
- type: "complete";
18
- title: string;
19
- body: string;
20
- domain: string;
21
- description: string;
22
- } | {
23
- type: "noop";
24
- description: string;
25
- } | {
26
- type: "needs_capability";
27
- description: string;
28
- suggestedPreset?: string;
29
- };
30
- /**
31
- * Terminal state of a GoalLoop.run() invocation. Always one of the four
32
- * outcomes — the loop never throws for normal termination conditions.
33
- */
34
- export type GoalResult = {
35
- outcome: "complete";
36
- artifact: {
37
- title: string;
38
- body: string;
39
- domain: string;
40
- };
41
- stepsExecuted: number;
42
- spentNook: bigint;
43
- } | {
44
- outcome: "blocked_budget";
45
- spentNook: bigint;
46
- } | {
47
- outcome: "blocked_stuck";
48
- stuckReason: string;
49
- spentNook: bigint;
50
- } | {
51
- outcome: "blocked_capability";
52
- capabilityNeeded: string;
53
- suggestedPreset?: string;
54
- spentNook: bigint;
55
- };
56
- /**
57
- * Configuration for a single run of the GoalLoop.
58
- */
59
- export interface GoalLoopOptions {
60
- runtime: NookplotRuntime;
61
- goal: string;
62
- /** Soft cap — loop continues past this but emits a warning. */
63
- budgetNook: bigint;
64
- parentSwarmId?: string | null;
65
- /** Hard stop on step count. Default 20. */
66
- maxSteps?: number;
67
- /** Hard stop on consecutive no-op responses. Default 3. */
68
- maxConsecutiveNoops?: number;
69
- /** Hard stop on consecutive identical step descriptions. Default 3. */
70
- maxReformulations?: number;
71
- /** Optional verbose logging. */
72
- verbose?: boolean;
73
- /**
74
- * Optional LLM caller — defaults to runtime.economy.inference or a runtime
75
- * provided by the consumer. The caller is abstracted because different
76
- * environments wire inference differently (platform / BYOK / Ollama).
77
- */
78
- inferenceCall?: (input: {
79
- systemPrompt: string;
80
- userPrompt: string;
81
- maxTokens: number;
82
- temperature: number;
83
- }) => Promise<{
84
- content: string;
85
- costNook?: number;
86
- }>;
87
- }
88
- /**
89
- * Result of executing a single step within the goal loop.
90
- * costNook is optional because many actions are free (off-chain tools).
91
- */
92
- export interface StepExecutionResult {
93
- ok: boolean;
94
- output: string;
95
- costNook: number;
96
- error?: string;
97
- }
98
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/goal/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,UAAU,GAClB;IACE,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,WAAW,EAAE,MAAM,CAAC;CACrB,GACD;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB,GACD;IACE,IAAI,EAAE,kBAAkB,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEN;;;GAGG;AACH,MAAM,MAAM,UAAU,GAClB;IACE,OAAO,EAAE,UAAU,CAAC;IACpB,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1D,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,OAAO,EAAE,gBAAgB,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,OAAO,EAAE,eAAe,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,OAAO,EAAE,oBAAoB,CAAC;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEN;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,eAAe,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,uEAAuE;IACvE,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gCAAgC;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE;QACtB,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;KACrB,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACvD;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
@@ -1,7 +0,0 @@
1
- /**
2
- * Goal loop types — shared interfaces for the L3 autonomous goal execution loop.
3
- *
4
- * @module goal/types
5
- */
6
- export {};
7
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/goal/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -1,100 +0,0 @@
1
- /**
2
- * Profile-aware credential loading for @nookplot/runtime.
3
- *
4
- * The SDK normally takes `{ apiKey, gatewayUrl }` at instantiation —
5
- * developers pass keys directly. This helper is for developers who want
6
- * the SDK to read from `~/.nookplot/` like @nookplot/cli and @nookplot/mcp
7
- * do, so a user running multiple forged agents can point the SDK at
8
- * whichever scope is active in their shell.
9
- *
10
- * Reads from the same files the rest of the Nookplot stack uses:
11
- * ~/.nookplot/credentials.json ← creator API key (shared)
12
- * ~/.nookplot/profiles/<name>/profile.json ← per-agent scope
13
- * ~/.nookplot/active-profile ← sticky default (CLI-written)
14
- *
15
- * Resolution order:
16
- * 1. Explicit `name` argument to loadProfile()
17
- * 2. NOOKPLOT_PROFILE env var
18
- * 3. Sticky default from ~/.nookplot/active-profile
19
- * 4. null (load default creds only, no scope)
20
- *
21
- * @module loadProfile
22
- *
23
- * @example Basic usage — pick up whatever profile is active
24
- * ```ts
25
- * import { NookplotRuntime } from "@nookplot/runtime";
26
- * import { loadProfile } from "@nookplot/runtime/loadProfile";
27
- *
28
- * const creds = loadProfile(); // respects NOOKPLOT_PROFILE env + sticky default
29
- * if (!creds) throw new Error("No credentials — run `nookplot register` first");
30
- *
31
- * const runtime = new NookplotRuntime({
32
- * apiKey: creds.apiKey,
33
- * gatewayUrl: creds.gatewayUrl,
34
- * });
35
- * ```
36
- *
37
- * @example Explicit profile override
38
- * ```ts
39
- * const creds = loadProfile("jeffs-researcher");
40
- * ```
41
- *
42
- * @example Multi-agent — run two SDK instances in parallel
43
- * ```ts
44
- * const researcherCreds = loadProfile("jeffs-researcher");
45
- * const writerCreds = loadProfile("jeffs-writer");
46
- *
47
- * const researcher = new NookplotRuntime({ apiKey: researcherCreds!.apiKey, ... });
48
- * const writer = new NookplotRuntime({ apiKey: writerCreds!.apiKey, ... });
49
- * // Both clients share the creator's API key but scope to different forged agents.
50
- * ```
51
- */
52
- export interface LoadedProfile {
53
- /** Creator's API key (shared across all forged agents owned by this creator). */
54
- apiKey: string;
55
- /** Creator's wallet address. */
56
- address: string;
57
- /** Creator's private key — only read if developer passes { requirePrivateKey }. */
58
- privateKey: string;
59
- /** Gateway base URL, honoring NOOKPLOT_GATEWAY_URL env if set. */
60
- gatewayUrl: string;
61
- /** Present when a profile was active — the forged agent's address to scope to. */
62
- scopedAgentAddress?: string;
63
- /** Present when a profile was active — the profile's name (for logging). */
64
- profileName?: string;
65
- /** Display name of the creator (not the scoped forged agent). */
66
- displayName?: string;
67
- }
68
- /**
69
- * Resolve the active profile name in priority order.
70
- * Exported for testing + for developers who want to see which profile
71
- * WOULD be used without actually loading credentials.
72
- */
73
- export declare function resolveActiveProfileName(explicitName?: string): string | null;
74
- /**
75
- * Load credentials, optionally merging a named profile's scope on top.
76
- *
77
- * Returns null if no `credentials.json` exists — the developer should
78
- * surface a clear "run `nookplot register` first" message in that case.
79
- *
80
- * Does not throw on invalid profiles — if the named profile doesn't
81
- * exist or is malformed, falls back to plain creator-direct credentials
82
- * (matches @nookplot/mcp's fail-open behavior so stale env vars don't
83
- * break unrelated commands).
84
- */
85
- export declare function loadProfile(name?: string): LoadedProfile | null;
86
- /**
87
- * List all profiles registered on the local machine. Each entry includes
88
- * the profile name + its metadata. Useful for SDK consumers who want to
89
- * enumerate the user's forged agents programmatically.
90
- *
91
- * Returns an empty array if ~/.nookplot/profiles doesn't exist. Never
92
- * throws — invalid profiles are silently skipped.
93
- */
94
- export declare function listProfiles(): Array<{
95
- name: string;
96
- scopedAgentAddress: string;
97
- displayName?: string;
98
- hermesProfile?: string;
99
- }>;
100
- //# sourceMappingURL=loadProfile.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"loadProfile.d.ts","sourceRoot":"","sources":["../src/loadProfile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAMH,MAAM,WAAW,aAAa;IAC5B,iFAAiF;IACjF,MAAM,EAAE,MAAM,CAAC;IACf,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,UAAU,EAAE,MAAM,CAAC;IACnB,kEAAkE;IAClE,UAAU,EAAE,MAAM,CAAC;IACnB,kFAAkF;IAClF,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,4EAA4E;IAC5E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iEAAiE;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAsBD;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAa7E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAwE/D;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,IAAI,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,kBAAkB,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CA8BhI"}
@@ -1,221 +0,0 @@
1
- /**
2
- * Profile-aware credential loading for @nookplot/runtime.
3
- *
4
- * The SDK normally takes `{ apiKey, gatewayUrl }` at instantiation —
5
- * developers pass keys directly. This helper is for developers who want
6
- * the SDK to read from `~/.nookplot/` like @nookplot/cli and @nookplot/mcp
7
- * do, so a user running multiple forged agents can point the SDK at
8
- * whichever scope is active in their shell.
9
- *
10
- * Reads from the same files the rest of the Nookplot stack uses:
11
- * ~/.nookplot/credentials.json ← creator API key (shared)
12
- * ~/.nookplot/profiles/<name>/profile.json ← per-agent scope
13
- * ~/.nookplot/active-profile ← sticky default (CLI-written)
14
- *
15
- * Resolution order:
16
- * 1. Explicit `name` argument to loadProfile()
17
- * 2. NOOKPLOT_PROFILE env var
18
- * 3. Sticky default from ~/.nookplot/active-profile
19
- * 4. null (load default creds only, no scope)
20
- *
21
- * @module loadProfile
22
- *
23
- * @example Basic usage — pick up whatever profile is active
24
- * ```ts
25
- * import { NookplotRuntime } from "@nookplot/runtime";
26
- * import { loadProfile } from "@nookplot/runtime/loadProfile";
27
- *
28
- * const creds = loadProfile(); // respects NOOKPLOT_PROFILE env + sticky default
29
- * if (!creds) throw new Error("No credentials — run `nookplot register` first");
30
- *
31
- * const runtime = new NookplotRuntime({
32
- * apiKey: creds.apiKey,
33
- * gatewayUrl: creds.gatewayUrl,
34
- * });
35
- * ```
36
- *
37
- * @example Explicit profile override
38
- * ```ts
39
- * const creds = loadProfile("jeffs-researcher");
40
- * ```
41
- *
42
- * @example Multi-agent — run two SDK instances in parallel
43
- * ```ts
44
- * const researcherCreds = loadProfile("jeffs-researcher");
45
- * const writerCreds = loadProfile("jeffs-writer");
46
- *
47
- * const researcher = new NookplotRuntime({ apiKey: researcherCreds!.apiKey, ... });
48
- * const writer = new NookplotRuntime({ apiKey: writerCreds!.apiKey, ... });
49
- * // Both clients share the creator's API key but scope to different forged agents.
50
- * ```
51
- */
52
- import { existsSync, readFileSync } from "node:fs";
53
- import { homedir } from "node:os";
54
- import { join } from "node:path";
55
- function nookplotDir() {
56
- return join(homedir(), ".nookplot");
57
- }
58
- function credentialsPath() {
59
- return join(nookplotDir(), "credentials.json");
60
- }
61
- function profilePath(name) {
62
- return join(nookplotDir(), "profiles", name, "profile.json");
63
- }
64
- function activeProfilePath() {
65
- return join(nookplotDir(), "active-profile");
66
- }
67
- /**
68
- * Resolve the active profile name in priority order.
69
- * Exported for testing + for developers who want to see which profile
70
- * WOULD be used without actually loading credentials.
71
- */
72
- export function resolveActiveProfileName(explicitName) {
73
- if (explicitName)
74
- return explicitName;
75
- const env = process.env.NOOKPLOT_PROFILE;
76
- if (env)
77
- return env;
78
- try {
79
- if (existsSync(activeProfilePath())) {
80
- const content = readFileSync(activeProfilePath(), "utf-8").trim();
81
- if (content)
82
- return content;
83
- }
84
- }
85
- catch {
86
- // Permissions error or disk issue — fall through
87
- }
88
- return null;
89
- }
90
- /**
91
- * Load credentials, optionally merging a named profile's scope on top.
92
- *
93
- * Returns null if no `credentials.json` exists — the developer should
94
- * surface a clear "run `nookplot register` first" message in that case.
95
- *
96
- * Does not throw on invalid profiles — if the named profile doesn't
97
- * exist or is malformed, falls back to plain creator-direct credentials
98
- * (matches @nookplot/mcp's fail-open behavior so stale env vars don't
99
- * break unrelated commands).
100
- */
101
- export function loadProfile(name) {
102
- // 1. Load base credentials — the shared creator API key.
103
- if (!existsSync(credentialsPath()))
104
- return null;
105
- let creds;
106
- try {
107
- creds = JSON.parse(readFileSync(credentialsPath(), "utf-8"));
108
- }
109
- catch {
110
- return null;
111
- }
112
- if (!creds.apiKey || !creds.address || !creds.privateKey || !creds.gatewayUrl) {
113
- return null;
114
- }
115
- // 2. Honor NOOKPLOT_GATEWAY_URL env if set (matches SDK + MCP convention).
116
- const gatewayUrl = process.env.NOOKPLOT_GATEWAY_URL ?? creds.gatewayUrl;
117
- // 3. Resolve profile (if any) and read its scope.
118
- const profileName = resolveActiveProfileName(name);
119
- if (!profileName) {
120
- return {
121
- apiKey: creds.apiKey,
122
- address: creds.address,
123
- privateKey: creds.privateKey,
124
- gatewayUrl,
125
- displayName: creds.displayName,
126
- };
127
- }
128
- const pPath = profilePath(profileName);
129
- if (!existsSync(pPath)) {
130
- // Stale profile reference — fall back to creator-direct. Matches
131
- // @nookplot/mcp's fail-open pattern.
132
- return {
133
- apiKey: creds.apiKey,
134
- address: creds.address,
135
- privateKey: creds.privateKey,
136
- gatewayUrl,
137
- displayName: creds.displayName,
138
- };
139
- }
140
- try {
141
- const p = JSON.parse(readFileSync(pPath, "utf-8"));
142
- if (typeof p.scopedAgentAddress !== "string" || p.scopedAgentAddress.length === 0) {
143
- // Malformed profile — fall back.
144
- return {
145
- apiKey: creds.apiKey,
146
- address: creds.address,
147
- privateKey: creds.privateKey,
148
- gatewayUrl,
149
- displayName: creds.displayName,
150
- };
151
- }
152
- return {
153
- apiKey: creds.apiKey,
154
- address: creds.address,
155
- privateKey: creds.privateKey,
156
- gatewayUrl,
157
- scopedAgentAddress: p.scopedAgentAddress,
158
- profileName,
159
- displayName: creds.displayName,
160
- };
161
- }
162
- catch {
163
- // JSON parse error on profile — fall back to creator-direct.
164
- return {
165
- apiKey: creds.apiKey,
166
- address: creds.address,
167
- privateKey: creds.privateKey,
168
- gatewayUrl,
169
- displayName: creds.displayName,
170
- };
171
- }
172
- }
173
- /**
174
- * List all profiles registered on the local machine. Each entry includes
175
- * the profile name + its metadata. Useful for SDK consumers who want to
176
- * enumerate the user's forged agents programmatically.
177
- *
178
- * Returns an empty array if ~/.nookplot/profiles doesn't exist. Never
179
- * throws — invalid profiles are silently skipped.
180
- */
181
- export function listProfiles() {
182
- const dir = join(nookplotDir(), "profiles");
183
- if (!existsSync(dir))
184
- return [];
185
- const out = [];
186
- try {
187
- const { readdirSync, statSync } = require("node:fs");
188
- for (const name of readdirSync(dir).sort()) {
189
- const full = join(dir, name);
190
- try {
191
- if (!statSync(full).isDirectory())
192
- continue;
193
- }
194
- catch {
195
- continue;
196
- }
197
- const pPath = join(full, "profile.json");
198
- if (!existsSync(pPath))
199
- continue;
200
- try {
201
- const p = JSON.parse(readFileSync(pPath, "utf-8"));
202
- if (typeof p.scopedAgentAddress !== "string")
203
- continue;
204
- out.push({
205
- name,
206
- scopedAgentAddress: p.scopedAgentAddress,
207
- displayName: p.displayName,
208
- hermesProfile: p.hermesProfile,
209
- });
210
- }
211
- catch {
212
- // Skip invalid profiles
213
- }
214
- }
215
- }
216
- catch {
217
- // Missing dir or perms — return empty
218
- }
219
- return out;
220
- }
221
- //# sourceMappingURL=loadProfile.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"loadProfile.js","sourceRoot":"","sources":["../src/loadProfile.ts"],"names":[],"mappings":"AAAA;;;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AAE,CAAC;YAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YAC7B,IAAI,CAAC;gBACH,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE;oBAAE,SAAS;YAC9C,CAAC;YAAC,MAAM,CAAC;gBAAC,SAAS;YAAC,CAAC;YACrB,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;YACzC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;gBAAE,SAAS;YACjC,IAAI,CAAC;gBACH,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAgB,CAAC;gBAClE,IAAI,OAAO,CAAC,CAAC,kBAAkB,KAAK,QAAQ;oBAAE,SAAS;gBACvD,GAAG,CAAC,IAAI,CAAC;oBACP,IAAI;oBACJ,kBAAkB,EAAE,CAAC,CAAC,kBAAkB;oBACxC,WAAW,EAAE,CAAC,CAAC,WAAW;oBAC1B,aAAa,EAAE,CAAC,CAAC,aAAa;iBAC/B,CAAC,CAAC;YACL,CAAC;YAAC,MAAM,CAAC;gBACP,wBAAwB;YAC1B,CAAC;QACH,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,sCAAsC;IACxC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,130 +0,0 @@
1
- /**
2
- * PresetLoader — loads forge preset data into agent memory at boot.
3
- *
4
- * Reads the preset section of nookplot.yaml, fetches data per source via
5
- * the gateway's forge data endpoint, runs content scanning, and ingests
6
- * items as preset-tagged memories. Supports layered ingestion: RAG when
7
- * available, memory.import() fallback.
8
- *
9
- * Features:
10
- * - Content scanning (sanitizeForPrompt) on every item
11
- * - Idempotent loading via .preset-loaded.json manifest
12
- * - Configurable failure policy (abort / continue / retry)
13
- * - Boot progress events via EventEmitter
14
- * - Self-awareness memory generation
15
- *
16
- * @module presetLoader
17
- */
18
- import { EventEmitter } from "node:events";
19
- import type { NookplotRuntime } from "./index.js";
20
- export interface PresetConfig {
21
- id: string;
22
- version?: number;
23
- trustLevel?: "verified" | "scanned" | "raw";
24
- failurePolicy?: "abort" | "continue";
25
- maxCostNook?: number;
26
- sources?: Array<{
27
- type: string;
28
- label?: string;
29
- config: Record<string, unknown>;
30
- }>;
31
- }
32
- export interface PresetLoadResult {
33
- sources: Array<{
34
- type: string;
35
- label: string;
36
- itemsLoaded: number;
37
- itemsBlocked: number;
38
- itemsSkipped: number;
39
- method: "memory" | "rag" | "prompt";
40
- status: "loaded" | "partial" | "failed";
41
- error?: string;
42
- costNook: number;
43
- }>;
44
- totalItems: number;
45
- totalBlocked: number;
46
- totalCostNook: number;
47
- ragAvailable: boolean;
48
- presetVersion: number;
49
- loadedAt: string;
50
- }
51
- export type PresetLoadEvent = {
52
- phase: "estimating";
53
- message: string;
54
- } | {
55
- phase: "fetching";
56
- source: string;
57
- progress: string;
58
- } | {
59
- phase: "scanning";
60
- source: string;
61
- blocked: number;
62
- } | {
63
- phase: "ingesting";
64
- source: string;
65
- method: "memory" | "rag";
66
- } | {
67
- phase: "complete";
68
- result: PresetLoadResult;
69
- } | {
70
- phase: "error";
71
- source: string;
72
- error: string;
73
- };
74
- export declare class PresetLoader extends EventEmitter {
75
- private runtime;
76
- private configPath;
77
- private loading;
78
- constructor(runtime: NookplotRuntime, configPath?: string);
79
- /**
80
- * Build x-preset-hmac header so the gateway trusts isPreset/presetId fields.
81
- * HMAC = SHA-256(apiKey, "preset-ingest:" + agent_address).
82
- */
83
- private presetIngestHeaders;
84
- /**
85
- * Load all preset data sources. Called once at agent boot.
86
- * Concurrent calls are coalesced — only the first triggers a fetch,
87
- * subsequent callers await the same promise (prevents double-pay).
88
- */
89
- load(): Promise<PresetLoadResult>;
90
- private _doLoad;
91
- /**
92
- * Check if preset data was already loaded (idempotent reboot check).
93
- */
94
- isLoaded(): Promise<boolean>;
95
- /**
96
- * Map preset source type to knowledge graph knowledge_type.
97
- */
98
- private mapSourceToKnowledgeType;
99
- /**
100
- * Map preset source type to knowledge graph source_type.
101
- */
102
- private mapSourceToKGSourceType;
103
- /**
104
- * Ingest a KnowledgeAggregateV1 into the knowledge graph as structured items.
105
- * Same decomposition as ingestAggregate but targets the KG endpoint.
106
- */
107
- private ingestAggregateToKG;
108
- /**
109
- * Ingest a KnowledgeAggregateV1 as structured memories.
110
- * Uses 5-7x fewer memory slots than equivalent raw traces:
111
- * - Synthesis → semantic memory (importance 0.9)
112
- * - Each keyInsight → procedural memory (confidence-weighted)
113
- * - Each reasoning pattern → procedural memory
114
- * - Contradictions → self_model memory
115
- *
116
- * Returns the number of memories stored.
117
- */
118
- private ingestAggregate;
119
- private readConfig;
120
- private readManifest;
121
- private writeManifest;
122
- /**
123
- * Lightweight client-side severity assessment.
124
- * Full ContentScanner runs server-side; this is a first pass.
125
- */
126
- private assessSeverity;
127
- private emptyResult;
128
- private manifestToResult;
129
- }
130
- //# sourceMappingURL=presetLoader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"presetLoader.d.ts","sourceRoot":"","sources":["../src/presetLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAKlD,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,UAAU,GAAG,SAAS,GAAG,KAAK,CAAC;IAC5C,aAAa,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC,MAAM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