@aiaiaichain/agent 0.1.5 → 0.1.7

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 (121) hide show
  1. package/dist/api/ExtensionAPI.d.ts +0 -1
  2. package/dist/api/ExtensionAPI.js +3 -7
  3. package/dist/api/Registry.d.ts +0 -1
  4. package/dist/api/Registry.js +54 -57
  5. package/dist/cli.d.ts +0 -1
  6. package/dist/cli.js +684 -685
  7. package/dist/core/AgentDir.d.ts +1 -1
  8. package/dist/core/AgentDir.js +45 -39
  9. package/dist/core/ChainConfig.d.ts +0 -1
  10. package/dist/core/ChainConfig.js +51 -55
  11. package/dist/core/EnvLoader.d.ts +4 -1
  12. package/dist/core/EnvLoader.js +97 -84
  13. package/dist/core/SystemMonitor.d.ts +0 -1
  14. package/dist/core/SystemMonitor.js +72 -85
  15. package/dist/index.d.ts +0 -1
  16. package/dist/index.js +19 -26
  17. package/dist/loader.d.ts +0 -1
  18. package/dist/loader.js +64 -67
  19. package/dist/mcp/entry.d.ts +0 -1
  20. package/dist/mcp/entry.js +3 -6
  21. package/dist/mcp/server.d.ts +0 -1
  22. package/dist/mcp/server.js +152 -156
  23. package/dist/models/CostTracker.d.ts +0 -1
  24. package/dist/models/CostTracker.js +58 -61
  25. package/dist/models/ModelRegistry.d.ts +0 -1
  26. package/dist/models/ModelRegistry.js +195 -155
  27. package/dist/providers/ProviderRegistry.d.ts +0 -1
  28. package/dist/providers/ProviderRegistry.js +33 -36
  29. package/dist/runner/AgentRunner.d.ts +0 -1
  30. package/dist/runner/AgentRunner.js +180 -184
  31. package/dist/runner/ModelClient.d.ts +0 -1
  32. package/dist/runner/ModelClient.js +133 -134
  33. package/dist/runner/SwarmRouter.d.ts +0 -1
  34. package/dist/runner/SwarmRouter.js +18 -22
  35. package/dist/runner/ToolDispatcher.d.ts +0 -1
  36. package/dist/runner/ToolDispatcher.js +30 -33
  37. package/dist/scheduler/AgentScheduler.d.ts +0 -1
  38. package/dist/scheduler/AgentScheduler.js +99 -103
  39. package/dist/session/ContextStore.d.ts +1 -1
  40. package/dist/session/ContextStore.js +76 -78
  41. package/dist/session/GoalManager.d.ts +0 -1
  42. package/dist/session/GoalManager.js +96 -100
  43. package/dist/session/MemoryStore.d.ts +2 -1
  44. package/dist/session/MemoryStore.js +108 -87
  45. package/dist/session/SessionManager.d.ts +5 -4
  46. package/dist/session/SessionManager.js +83 -62
  47. package/dist/session/SessionStore.d.ts +0 -1
  48. package/dist/session/SessionStore.js +112 -116
  49. package/dist/setup/SetupWizard.d.ts +0 -1
  50. package/dist/setup/SetupWizard.js +61 -64
  51. package/dist/tools/CrossTools.d.ts +0 -1
  52. package/dist/tools/CrossTools.js +140 -144
  53. package/dist/tools/GmgnIntegration.d.ts +0 -1
  54. package/dist/tools/GmgnIntegration.js +220 -230
  55. package/dist/tools/MarketSentiment.d.ts +0 -1
  56. package/dist/tools/MarketSentiment.js +213 -195
  57. package/dist/tools/NewsSentiment.d.ts +0 -1
  58. package/dist/tools/NewsSentiment.js +126 -130
  59. package/dist/tools/PriceFeed.d.ts +6 -1
  60. package/dist/tools/PriceFeed.js +201 -133
  61. package/dist/tools/TechnicalAnalysis.d.ts +1 -2
  62. package/dist/tools/TechnicalAnalysis.js +248 -216
  63. package/dist/tools/TechnicalAnalysis.worker.d.ts +25 -0
  64. package/dist/tools/TechnicalAnalysis.worker.js +92 -0
  65. package/dist/tools/TokenCalendar.d.ts +0 -1
  66. package/dist/tools/TokenCalendar.js +63 -68
  67. package/dist/tools/TokenSecurityScanner.d.ts +0 -1
  68. package/dist/tools/TokenSecurityScanner.js +93 -96
  69. package/dist/tools/TransactionSim.d.ts +0 -1
  70. package/dist/tools/TransactionSim.js +65 -71
  71. package/dist/tui/App.d.ts +0 -1
  72. package/dist/tui/App.js +895 -824
  73. package/dist/tui/ModelSelector.d.ts +0 -1
  74. package/dist/tui/ModelSelector.js +46 -49
  75. package/dist/tui/REPL.d.ts +0 -1
  76. package/dist/tui/REPL.js +222 -210
  77. package/dist/tui/Sparkline.d.ts +0 -1
  78. package/dist/tui/Sparkline.js +36 -37
  79. package/dist/tui/StatusBar.d.ts +0 -1
  80. package/dist/tui/StatusBar.js +9 -10
  81. package/dist/tui/ThemePresets.d.ts +0 -1
  82. package/dist/tui/ThemePresets.js +99 -103
  83. package/dist/tui/theme.d.ts +0 -1
  84. package/dist/tui/theme.js +50 -31
  85. package/dist/util/clipboard.d.ts +0 -1
  86. package/dist/util/clipboard.js +16 -20
  87. package/dist/util/commandSuggest.d.ts +0 -1
  88. package/dist/util/commandSuggest.js +34 -38
  89. package/dist/util/confirmation.d.ts +0 -1
  90. package/dist/util/confirmation.js +8 -11
  91. package/dist/util/errorHandler.d.ts +0 -1
  92. package/dist/util/errorHandler.js +20 -23
  93. package/dist/util/errors.d.ts +59 -0
  94. package/dist/util/errors.js +93 -0
  95. package/dist/util/logger.d.ts +0 -1
  96. package/dist/util/logger.js +30 -33
  97. package/dist/util/processManager.d.ts +0 -1
  98. package/dist/util/processManager.js +33 -36
  99. package/dist/util/resilientFetch.d.ts +6 -1
  100. package/dist/util/resilientFetch.js +134 -80
  101. package/dist/util/responseCache.d.ts +0 -1
  102. package/dist/util/responseCache.js +36 -45
  103. package/dist/util/rpc.d.ts +16 -0
  104. package/dist/util/rpc.js +69 -0
  105. package/dist/util/safeLog.d.ts +0 -1
  106. package/dist/util/safeLog.js +52 -53
  107. package/dist/util/scheduler.d.ts +0 -1
  108. package/dist/util/scheduler.js +53 -58
  109. package/dist/util/webhooks.d.ts +0 -1
  110. package/dist/util/webhooks.js +54 -58
  111. package/dist/wallet/ActionFeed.d.ts +3 -3
  112. package/dist/wallet/ActionFeed.js +189 -187
  113. package/dist/wallet/AgentWallet.d.ts +9 -7
  114. package/dist/wallet/AgentWallet.js +121 -141
  115. package/dist/wallet/ProfitTracker.d.ts +0 -1
  116. package/dist/wallet/ProfitTracker.js +71 -74
  117. package/package.json +12 -7
  118. package/scripts/build-esbuild.mjs +40 -0
  119. package/scripts/bundle-dts.mjs +58 -0
  120. package/scripts/minify.mjs +44 -0
  121. package/scripts/postinstall.js +27 -0
@@ -20,4 +20,3 @@ export declare class SwarmRouter {
20
20
  runConcurrent(tasks: SubAgentTask[], _sessionCtx: SessionContext): Promise<SubAgentResult[]>;
21
21
  private runSingle;
22
22
  }
23
- //# sourceMappingURL=SwarmRouter.d.ts.map
@@ -1,24 +1,20 @@
1
- /**
2
- * SwarmRouter — parallel sub-agent orchestration.
3
- * Routes tasks to appropriate model tiers for parallel execution.
4
- */
1
+
5
2
  export class SwarmRouter {
6
- registry;
7
- constructor(registry) {
8
- this.registry = registry;
9
- }
10
- async runConcurrent(tasks, _sessionCtx) {
11
- return Promise.all(tasks.map(t => this.runSingle(t)));
12
- }
13
- async runSingle(task) {
14
- try {
15
- // For v1, just execute the task via the available tools
16
- // This is simplified — real parallel model calls would go through ModelClient
17
- return { taskId: task.id, output: `[${task.tier}] ${task.prompt}` };
18
- }
19
- catch (e) {
20
- return { taskId: task.id, output: "", error: e instanceof Error ? e.message : String(e) };
21
- }
22
- }
3
+ registry;
4
+ constructor(registry) {
5
+ this.registry = registry;
6
+ }
7
+ async runConcurrent(tasks, _sessionCtx) {
8
+ return Promise.all(tasks.map(t => this.runSingle(t)));
9
+ }
10
+ async runSingle(task) {
11
+ try {
12
+
13
+
14
+ return { taskId: task.id, output: `[${task.tier}] ${task.prompt}` };
15
+ }
16
+ catch (e) {
17
+ return { taskId: task.id, output: "", error: e instanceof Error ? e.message : String(e) };
18
+ }
19
+ }
23
20
  }
24
- //# sourceMappingURL=SwarmRouter.js.map
@@ -10,4 +10,3 @@ export declare class ToolDispatcher {
10
10
  listTools(): ToolDef[];
11
11
  getTool(name: string): ToolDef | undefined;
12
12
  }
13
- //# sourceMappingURL=ToolDispatcher.d.ts.map
@@ -1,34 +1,31 @@
1
- /**
2
- * ToolDispatcher — dispatches tool calls from the AI to registered tool handlers.
3
- */
1
+
4
2
  export class ToolDispatcher {
5
- registry;
6
- constructor(registry) {
7
- this.registry = registry;
8
- }
9
- async dispatch(toolName, params) {
10
- const tool = this.registry.getTool(toolName);
11
- if (!tool) {
12
- return {
13
- content: [{ type: "text", text: `Unknown tool: "${toolName}"` }],
14
- isError: true,
15
- };
16
- }
17
- try {
18
- return await tool.execute(`invoke-${Date.now()}`, params);
19
- }
20
- catch (e) {
21
- return {
22
- content: [{ type: "text", text: `Tool "${toolName}" error: ${e instanceof Error ? e.message : String(e)}` }],
23
- isError: true,
24
- };
25
- }
26
- }
27
- listTools() {
28
- return this.registry.listTools();
29
- }
30
- getTool(name) {
31
- return this.registry.getTool(name);
32
- }
33
- }
34
- //# sourceMappingURL=ToolDispatcher.js.map
3
+ registry;
4
+ constructor(registry) {
5
+ this.registry = registry;
6
+ }
7
+ async dispatch(toolName, params) {
8
+ const tool = this.registry.getTool(toolName);
9
+ if (!tool) {
10
+ return {
11
+ content: [{ type: "text", text: `Unknown tool: "${toolName}"` }],
12
+ isError: true,
13
+ };
14
+ }
15
+ try {
16
+ return await tool.execute(`invoke-${Date.now()}`, params);
17
+ }
18
+ catch (e) {
19
+ return {
20
+ content: [{ type: "text", text: `Tool "${toolName}" error: ${e instanceof Error ? e.message : String(e)}` }],
21
+ isError: true,
22
+ };
23
+ }
24
+ }
25
+ listTools() {
26
+ return this.registry.listTools();
27
+ }
28
+ getTool(name) {
29
+ return this.registry.getTool(name);
30
+ }
31
+ }
@@ -45,4 +45,3 @@ export declare class AgentScheduler {
45
45
  removeTaskTool(_id: string, params: Record<string, unknown>): Promise<ToolResult>;
46
46
  }
47
47
  export declare const agentScheduler: AgentScheduler;
48
- //# sourceMappingURL=AgentScheduler.d.ts.map
@@ -1,111 +1,107 @@
1
- /**
2
- * AgentScheduler — cron and price-triggered scheduled tasks.
3
- * Persisted to ~/.aiaiai/memory/schedule.json
4
- */
1
+
5
2
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
6
3
  import { resolve } from "node:path";
7
4
  import { Type } from "@sinclair/typebox";
8
5
  import { AgentDir } from "../core/AgentDir.js";
9
6
  const SCHEDULE_PATH = resolve(AgentDir.getHome(), "memory", "schedule.json");
10
7
  export class AgentScheduler {
11
- tasks = [];
12
- interval = null;
13
- onTask;
14
- constructor() {
15
- this.load();
16
- }
17
- load() {
18
- try {
19
- if (existsSync(SCHEDULE_PATH)) {
20
- this.tasks = JSON.parse(readFileSync(SCHEDULE_PATH, "utf-8"));
21
- }
22
- }
23
- catch {
24
- this.tasks = [];
25
- }
26
- }
27
- save() {
28
- try {
29
- writeFileSync(SCHEDULE_PATH, JSON.stringify(this.tasks, null, 2), "utf-8");
30
- }
31
- catch { /* non-fatal */ }
32
- }
33
- addTask(name, prompt, intervalSeconds) {
34
- const task = {
35
- id: `task-${Date.now()}-${Math.random().toString(36).slice(2, 5)}`,
36
- name,
37
- prompt,
38
- cron: intervalSeconds ? String(intervalSeconds) : undefined,
39
- enabled: true,
40
- createdAt: Date.now(),
41
- };
42
- this.tasks.push(task);
43
- this.save();
44
- return task;
45
- }
46
- removeTask(id) {
47
- const idx = this.tasks.findIndex(t => t.id === id);
48
- if (idx === -1)
49
- return false;
50
- this.tasks.splice(idx, 1);
51
- this.save();
52
- return true;
53
- }
54
- listTasks() {
55
- return [...this.tasks];
56
- }
57
- start(onTask) {
58
- this.onTask = onTask;
59
- if (this.interval)
60
- clearInterval(this.interval);
61
- this.interval = setInterval(() => {
62
- const now = Date.now();
63
- for (const task of this.tasks) {
64
- if (!task.enabled || !task.cron)
65
- continue;
66
- const interval = parseInt(task.cron) * 1000;
67
- if (!task.lastRun || (now - task.lastRun) >= interval) {
68
- task.lastRun = now;
69
- this.save();
70
- this.onTask?.(task);
71
- }
72
- }
73
- }, 10_000); // Check every 10 seconds
74
- }
75
- stop() {
76
- if (this.interval) {
77
- clearInterval(this.interval);
78
- this.interval = null;
79
- }
80
- }
81
- // ── Tools ───────────────────────────────────────────────────────────────
82
- addTaskParams = Type.Object({
83
- name: Type.String({ description: "Task name" }),
84
- prompt: Type.String({ description: "Prompt to run when task fires" }),
85
- interval: Type.Optional(Type.Number({ description: "Run every N seconds" })),
86
- });
87
- listTasksParams = Type.Object({
88
- enabled_only: Type.Optional(Type.Boolean({ default: false })),
89
- });
90
- removeTaskParams = Type.Object({
91
- id: Type.String({ description: "Task ID to remove" }),
92
- });
93
- async addTaskTool(_id, params) {
94
- const task = this.addTask(params.name, params.prompt, params.interval);
95
- return { content: [{ type: "text", text: `Task "${task.name}" created (${task.id})` }] };
96
- }
97
- async listTasksTool(_id, params) {
98
- const enabledOnly = params.enabled_only || false;
99
- const tasks = enabledOnly ? this.tasks.filter(t => t.enabled) : this.tasks;
100
- if (tasks.length === 0)
101
- return { content: [{ type: "text", text: "No scheduled tasks." }] };
102
- const lines = tasks.map(t => ` ${t.enabled ? "🟢" : "⏸️"} ${t.id} — ${t.name}${t.cron ? ` (every ${t.cron}s)` : ""}`);
103
- return { content: [{ type: "text", text: `Scheduled Tasks (${tasks.length}):\n${lines.join("\n")}` }] };
104
- }
105
- async removeTaskTool(_id, params) {
106
- const ok = this.removeTask(params.id);
107
- return { content: [{ type: "text", text: ok ? `Task ${params.id} removed` : `Task ${params.id} not found` }] };
108
- }
8
+ tasks = [];
9
+ interval = null;
10
+ onTask;
11
+ constructor() {
12
+ this.load();
13
+ }
14
+ load() {
15
+ try {
16
+ if (existsSync(SCHEDULE_PATH)) {
17
+ this.tasks = JSON.parse(readFileSync(SCHEDULE_PATH, "utf-8"));
18
+ }
19
+ }
20
+ catch {
21
+ this.tasks = [];
22
+ }
23
+ }
24
+ save() {
25
+ try {
26
+ writeFileSync(SCHEDULE_PATH, JSON.stringify(this.tasks, null, 2), "utf-8");
27
+ }
28
+ catch { }
29
+ }
30
+ addTask(name, prompt, intervalSeconds) {
31
+ const task = {
32
+ id: `task-${Date.now()}-${Math.random().toString(36).slice(2, 5)}`,
33
+ name,
34
+ prompt,
35
+ cron: intervalSeconds ? String(intervalSeconds) : undefined,
36
+ enabled: true,
37
+ createdAt: Date.now(),
38
+ };
39
+ this.tasks.push(task);
40
+ this.save();
41
+ return task;
42
+ }
43
+ removeTask(id) {
44
+ const idx = this.tasks.findIndex(t => t.id === id);
45
+ if (idx === -1)
46
+ return false;
47
+ this.tasks.splice(idx, 1);
48
+ this.save();
49
+ return true;
50
+ }
51
+ listTasks() {
52
+ return [...this.tasks];
53
+ }
54
+ start(onTask) {
55
+ this.onTask = onTask;
56
+ if (this.interval)
57
+ clearInterval(this.interval);
58
+ this.interval = setInterval(() => {
59
+ const now = Date.now();
60
+ for (const task of this.tasks) {
61
+ if (!task.enabled || !task.cron)
62
+ continue;
63
+ const interval = parseInt(task.cron) * 1000;
64
+ if (!task.lastRun || (now - task.lastRun) >= interval) {
65
+ task.lastRun = now;
66
+ this.save();
67
+ this.onTask?.(task);
68
+ }
69
+ }
70
+ }, 10_000);
71
+ }
72
+ stop() {
73
+ if (this.interval) {
74
+ clearInterval(this.interval);
75
+ this.interval = null;
76
+ }
77
+ }
78
+
79
+ addTaskParams = Type.Object({
80
+ name: Type.String({ description: "Task name" }),
81
+ prompt: Type.String({ description: "Prompt to run when task fires" }),
82
+ interval: Type.Optional(Type.Number({ description: "Run every N seconds" })),
83
+ });
84
+ listTasksParams = Type.Object({
85
+ enabled_only: Type.Optional(Type.Boolean({ default: false })),
86
+ });
87
+ removeTaskParams = Type.Object({
88
+ id: Type.String({ description: "Task ID to remove" }),
89
+ });
90
+ async addTaskTool(_id, params) {
91
+ const task = this.addTask(params.name, params.prompt, params.interval);
92
+ return { content: [{ type: "text", text: `Task "${task.name}" created (${task.id})` }] };
93
+ }
94
+ async listTasksTool(_id, params) {
95
+ const enabledOnly = params.enabled_only || false;
96
+ const tasks = enabledOnly ? this.tasks.filter(t => t.enabled) : this.tasks;
97
+ if (tasks.length === 0)
98
+ return { content: [{ type: "text", text: "No scheduled tasks." }] };
99
+ const lines = tasks.map(t => ` ${t.enabled ? "🟢" : "⏸️"} ${t.id} — ${t.name}${t.cron ? ` (every ${t.cron}s)` : ""}`);
100
+ return { content: [{ type: "text", text: `Scheduled Tasks (${tasks.length}):\n${lines.join("\n")}` }] };
101
+ }
102
+ async removeTaskTool(_id, params) {
103
+ const ok = this.removeTask(params.id);
104
+ return { content: [{ type: "text", text: ok ? `Task ${params.id} removed` : `Task ${params.id} not found` }] };
105
+ }
109
106
  }
110
107
  export const agentScheduler = new AgentScheduler();
111
- //# sourceMappingURL=AgentScheduler.js.map
@@ -12,6 +12,7 @@ export interface TaskContext {
12
12
  }
13
13
  export declare class ContextStore {
14
14
  private basePath;
15
+ private activeContexts;
15
16
  constructor();
16
17
  saveTask(taskId: string, data: Record<string, unknown>): void;
17
18
  readTask(taskId: string): TaskContext | null;
@@ -25,4 +26,3 @@ export declare class ContextStore {
25
26
  listTasksTool(): Promise<ToolResult>;
26
27
  }
27
28
  export declare const contextStore: ContextStore;
28
- //# sourceMappingURL=ContextStore.d.ts.map
@@ -1,85 +1,83 @@
1
- /**
2
- * ContextStore — persistent task context folders.
3
- * Allows multi-step operations to store and retrieve intermediate state.
4
- */
1
+
5
2
  import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync } from "node:fs";
6
3
  import { resolve } from "node:path";
7
4
  import { Type } from "@sinclair/typebox";
8
5
  import { AgentDir } from "../core/AgentDir.js";
9
6
  export class ContextStore {
10
- basePath;
11
- constructor() {
12
- this.basePath = resolve(AgentDir.getHome(), "sessions", "tasks");
13
- if (!existsSync(this.basePath))
14
- mkdirSync(this.basePath, { recursive: true });
15
- }
16
- saveTask(taskId, data) {
17
- const ctx = {
18
- taskId,
19
- data,
20
- createdAt: Date.now(),
21
- updatedAt: Date.now(),
22
- };
23
- writeFileSync(resolve(this.basePath, `${taskId}.json`), JSON.stringify(ctx, null, 2), "utf-8");
24
- }
25
- readTask(taskId) {
26
- const p = resolve(this.basePath, `${taskId}.json`);
27
- if (!existsSync(p))
28
- return null;
29
- try {
30
- return JSON.parse(readFileSync(p, "utf-8"));
31
- }
32
- catch {
33
- return null;
34
- }
35
- }
36
- listTasks() {
37
- if (!existsSync(this.basePath))
38
- return [];
39
- try {
40
- return readdirSync(this.basePath)
41
- .filter(f => f.endsWith(".json"))
42
- .map(f => {
43
- try {
44
- return JSON.parse(readFileSync(resolve(this.basePath, f), "utf-8"));
45
- }
46
- catch {
47
- return null;
48
- }
49
- })
50
- .filter(Boolean);
51
- }
52
- catch {
53
- return [];
54
- }
55
- }
56
- keepTask(taskId) {
57
- const ctx = this.readTask(taskId);
58
- if (!ctx)
59
- return false;
60
- ctx.keep = true;
61
- ctx.updatedAt = Date.now();
62
- writeFileSync(resolve(this.basePath, `${taskId}.json`), JSON.stringify(ctx, null, 2), "utf-8");
63
- return true;
64
- }
65
- // ── Tools ───────────────────────────────────────────────────────────────
66
- readContextParams = Type.Object({
67
- taskId: Type.String({ description: "Task ID from a previous multi-step operation" }),
68
- });
69
- listTasksParams = Type.Object({});
70
- async readContextTool(_id, params) {
71
- const ctx = this.readTask(params.taskId);
72
- if (!ctx)
73
- return { content: [{ type: "text", text: `Task "${params.taskId}" not found.` }] };
74
- return { content: [{ type: "text", text: JSON.stringify(ctx.data, null, 2) }] };
75
- }
76
- async listTasksTool() {
77
- const tasks = this.listTasks();
78
- if (tasks.length === 0)
79
- return { content: [{ type: "text", text: "No saved tasks." }] };
80
- const lines = tasks.map(t => ` ${t.taskId} — ${Object.keys(t.data).length} keys (${new Date(t.updatedAt).toLocaleString()})${t.keep ? " 🔒" : ""}`);
81
- return { content: [{ type: "text", text: `Tasks (${tasks.length}):\n${lines.join("\n")}` }] };
82
- }
7
+ basePath;
8
+
9
+ activeContexts = new Map();
10
+ constructor() {
11
+ this.basePath = resolve(AgentDir.getHome(), "sessions", "tasks");
12
+ if (!existsSync(this.basePath))
13
+ mkdirSync(this.basePath, { recursive: true });
14
+ }
15
+ saveTask(taskId, data) {
16
+ const ctx = {
17
+ taskId,
18
+ data,
19
+ createdAt: Date.now(),
20
+ updatedAt: Date.now(),
21
+ };
22
+ writeFileSync(resolve(this.basePath, `${taskId}.json`), JSON.stringify(ctx, null, 2), "utf-8");
23
+ }
24
+ readTask(taskId) {
25
+ const p = resolve(this.basePath, `${taskId}.json`);
26
+ if (!existsSync(p))
27
+ return null;
28
+ try {
29
+ return JSON.parse(readFileSync(p, "utf-8"));
30
+ }
31
+ catch {
32
+ return null;
33
+ }
34
+ }
35
+ listTasks() {
36
+ if (!existsSync(this.basePath))
37
+ return [];
38
+ try {
39
+ return readdirSync(this.basePath)
40
+ .filter(f => f.endsWith(".json"))
41
+ .map(f => {
42
+ try {
43
+ return JSON.parse(readFileSync(resolve(this.basePath, f), "utf-8"));
44
+ }
45
+ catch {
46
+ return null;
47
+ }
48
+ })
49
+ .filter(Boolean);
50
+ }
51
+ catch {
52
+ return [];
53
+ }
54
+ }
55
+ keepTask(taskId) {
56
+ const ctx = this.readTask(taskId);
57
+ if (!ctx)
58
+ return false;
59
+ ctx.keep = true;
60
+ ctx.updatedAt = Date.now();
61
+ writeFileSync(resolve(this.basePath, `${taskId}.json`), JSON.stringify(ctx, null, 2), "utf-8");
62
+ return true;
63
+ }
64
+
65
+ readContextParams = Type.Object({
66
+ taskId: Type.String({ description: "Task ID from a previous multi-step operation" }),
67
+ });
68
+ listTasksParams = Type.Object({});
69
+ async readContextTool(_id, params) {
70
+ const ctx = this.readTask(params.taskId);
71
+ if (!ctx)
72
+ return { content: [{ type: "text", text: `Task "${params.taskId}" not found.` }] };
73
+ return { content: [{ type: "text", text: JSON.stringify(ctx.data, null, 2) }] };
74
+ }
75
+ async listTasksTool() {
76
+ const tasks = this.listTasks();
77
+ if (tasks.length === 0)
78
+ return { content: [{ type: "text", text: "No saved tasks." }] };
79
+ const lines = tasks.map(t => ` ${t.taskId} — ${Object.keys(t.data).length} keys (${new Date(t.updatedAt).toLocaleString()})${t.keep ? " 🔒" : ""}`);
80
+ return { content: [{ type: "text", text: `Tasks (${tasks.length}):\n${lines.join("\n")}` }] };
81
+ }
83
82
  }
84
83
  export const contextStore = new ContextStore();
85
- //# sourceMappingURL=ContextStore.js.map
@@ -40,4 +40,3 @@ export declare class GoalManager {
40
40
  addGoalNoteTool(_id: string, params: Record<string, unknown>): Promise<ToolResult>;
41
41
  }
42
42
  export declare const goalManager: GoalManager;
43
- //# sourceMappingURL=GoalManager.d.ts.map