@agentmeshhq/agent 0.2.0 → 0.2.1

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 (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +39 -0
  3. package/dist/__tests__/orphan-process.test.d.ts +11 -0
  4. package/dist/__tests__/orphan-process.test.js +286 -0
  5. package/dist/__tests__/orphan-process.test.js.map +1 -0
  6. package/dist/__tests__/runner.test.js +16 -0
  7. package/dist/__tests__/runner.test.js.map +1 -1
  8. package/dist/__tests__/watchdog.test.js +138 -12
  9. package/dist/__tests__/watchdog.test.js.map +1 -1
  10. package/dist/cli/index.js +0 -0
  11. package/dist/cli/status.js +11 -0
  12. package/dist/cli/status.js.map +1 -1
  13. package/dist/cli/stop.js +7 -2
  14. package/dist/cli/stop.js.map +1 -1
  15. package/dist/config/schema.d.ts +4 -2
  16. package/dist/core/daemon/assignment-message.d.ts +12 -0
  17. package/dist/core/daemon/assignment-message.js +36 -0
  18. package/dist/core/daemon/assignment-message.js.map +1 -0
  19. package/dist/core/daemon/bootstrap.d.ts +35 -0
  20. package/dist/core/daemon/bootstrap.js +52 -0
  21. package/dist/core/daemon/bootstrap.js.map +1 -0
  22. package/dist/core/daemon/crash-log.d.ts +16 -0
  23. package/dist/core/daemon/crash-log.js +24 -0
  24. package/dist/core/daemon/crash-log.js.map +1 -0
  25. package/dist/core/daemon/health-policy.d.ts +21 -0
  26. package/dist/core/daemon/health-policy.js +32 -0
  27. package/dist/core/daemon/health-policy.js.map +1 -0
  28. package/dist/core/daemon/sandbox-config.d.ts +9 -0
  29. package/dist/core/daemon/sandbox-config.js +17 -0
  30. package/dist/core/daemon/sandbox-config.js.map +1 -0
  31. package/dist/core/daemon/state.d.ts +33 -0
  32. package/dist/core/daemon/state.js +77 -0
  33. package/dist/core/daemon/state.js.map +1 -0
  34. package/dist/core/daemon/tmux-session.d.ts +17 -0
  35. package/dist/core/daemon/tmux-session.js +34 -0
  36. package/dist/core/daemon/tmux-session.js.map +1 -0
  37. package/dist/core/daemon/workspace.d.ts +10 -0
  38. package/dist/core/daemon/workspace.js +51 -0
  39. package/dist/core/daemon/workspace.js.map +1 -0
  40. package/dist/core/daemon.d.ts +0 -6
  41. package/dist/core/daemon.js +123 -244
  42. package/dist/core/daemon.js.map +1 -1
  43. package/dist/core/injector.js +6 -0
  44. package/dist/core/injector.js.map +1 -1
  45. package/dist/core/runner/build.d.ts +9 -0
  46. package/dist/core/runner/build.js +53 -0
  47. package/dist/core/runner/build.js.map +1 -0
  48. package/dist/core/runner/detect.d.ts +5 -0
  49. package/dist/core/runner/detect.js +14 -0
  50. package/dist/core/runner/detect.js.map +1 -0
  51. package/dist/core/runner/index.d.ts +5 -0
  52. package/dist/core/runner/index.js +5 -0
  53. package/dist/core/runner/index.js.map +1 -0
  54. package/dist/core/runner/model.d.ts +5 -0
  55. package/dist/core/runner/model.js +7 -0
  56. package/dist/core/runner/model.js.map +1 -0
  57. package/dist/core/runner/opencode-models.d.ts +15 -0
  58. package/dist/core/runner/opencode-models.js +70 -0
  59. package/dist/core/runner/opencode-models.js.map +1 -0
  60. package/dist/core/runner/types.d.ts +19 -0
  61. package/dist/core/runner/types.js +8 -0
  62. package/dist/core/runner/types.js.map +1 -0
  63. package/dist/core/runner.d.ts +5 -47
  64. package/dist/core/runner.js +5 -167
  65. package/dist/core/runner.js.map +1 -1
  66. package/dist/core/tmux-runtime.d.ts +13 -0
  67. package/dist/core/tmux-runtime.js +72 -0
  68. package/dist/core/tmux-runtime.js.map +1 -0
  69. package/dist/core/tmux.d.ts +7 -1
  70. package/dist/core/tmux.js +75 -45
  71. package/dist/core/tmux.js.map +1 -1
  72. package/dist/core/watchdog.d.ts +18 -1
  73. package/dist/core/watchdog.js +78 -29
  74. package/dist/core/watchdog.js.map +1 -1
  75. package/package.json +30 -11
  76. package/dist/cli/inbox.d.ts +0 -5
  77. package/dist/cli/inbox.js +0 -123
  78. package/dist/cli/inbox.js.map +0 -1
  79. package/dist/cli/issue.d.ts +0 -42
  80. package/dist/cli/issue.js +0 -297
  81. package/dist/cli/issue.js.map +0 -1
  82. package/dist/cli/ready.d.ts +0 -5
  83. package/dist/cli/ready.js +0 -131
  84. package/dist/cli/ready.js.map +0 -1
  85. package/dist/cli/sync.d.ts +0 -8
  86. package/dist/cli/sync.js +0 -154
  87. package/dist/cli/sync.js.map +0 -1
  88. package/dist/core/issue-cache.d.ts +0 -44
  89. package/dist/core/issue-cache.js +0 -75
  90. package/dist/core/issue-cache.js.map +0 -1
  91. package/src/__tests__/context.test.ts +0 -464
  92. package/src/__tests__/injector.test.ts +0 -29
  93. package/src/__tests__/jwt.test.ts +0 -112
  94. package/src/__tests__/loader.test.ts +0 -239
  95. package/src/__tests__/runner.test.ts +0 -104
  96. package/src/__tests__/sandbox.test.ts +0 -435
  97. package/src/__tests__/watchdog.test.ts +0 -368
  98. package/src/cli/attach.ts +0 -22
  99. package/src/cli/build.ts +0 -145
  100. package/src/cli/config.ts +0 -148
  101. package/src/cli/context.ts +0 -231
  102. package/src/cli/deploy.ts +0 -155
  103. package/src/cli/index.ts +0 -376
  104. package/src/cli/init.ts +0 -75
  105. package/src/cli/list.ts +0 -70
  106. package/src/cli/local.ts +0 -183
  107. package/src/cli/logs.ts +0 -64
  108. package/src/cli/migrate.ts +0 -212
  109. package/src/cli/nudge.ts +0 -81
  110. package/src/cli/restart.ts +0 -59
  111. package/src/cli/slack.ts +0 -70
  112. package/src/cli/start.ts +0 -118
  113. package/src/cli/status.ts +0 -91
  114. package/src/cli/stop.ts +0 -48
  115. package/src/cli/test.ts +0 -143
  116. package/src/cli/token.ts +0 -188
  117. package/src/cli/whoami.ts +0 -142
  118. package/src/config/loader.ts +0 -121
  119. package/src/config/schema.ts +0 -68
  120. package/src/context/handoff.ts +0 -122
  121. package/src/context/index.ts +0 -8
  122. package/src/context/schema.ts +0 -111
  123. package/src/context/storage.ts +0 -197
  124. package/src/core/daemon.ts +0 -1317
  125. package/src/core/heartbeat.ts +0 -129
  126. package/src/core/injector.ts +0 -292
  127. package/src/core/registry.ts +0 -159
  128. package/src/core/runner.ts +0 -225
  129. package/src/core/sandbox.ts +0 -547
  130. package/src/core/session-id.ts +0 -111
  131. package/src/core/tmux.ts +0 -405
  132. package/src/core/watchdog.ts +0 -238
  133. package/src/core/websocket.ts +0 -94
  134. package/src/index.ts +0 -10
  135. package/src/utils/jwt.ts +0 -87
  136. package/tsconfig.json +0 -8
  137. package/vitest.config.ts +0 -12
@@ -1,122 +0,0 @@
1
- /**
2
- * Context Handoff Module
3
- * Functions for sharing context between agents via handoffs
4
- */
5
-
6
- import type { AgentContext } from "./schema.js";
7
- import { loadContext } from "./storage.js";
8
-
9
- /**
10
- * Minimal context for handoff (excludes sensitive/large data)
11
- */
12
- export interface HandoffContext {
13
- /** Working directory */
14
- workdir: string;
15
- /** Git branch if in a repo */
16
- gitBranch?: string;
17
- /** Current goal being worked on */
18
- currentGoal?: string;
19
- /** Active tasks (in_progress and pending) */
20
- activeTasks: Array<{
21
- content: string;
22
- status: "in_progress" | "pending";
23
- priority: string;
24
- }>;
25
- /** Recent accomplishments */
26
- recentAccomplishments: string[];
27
- /** Key topics from conversation */
28
- topics: string[];
29
- /** Any custom context data */
30
- custom?: Record<string, unknown>;
31
- }
32
-
33
- /**
34
- * Extracts handoff-relevant context from full agent context
35
- */
36
- export function extractHandoffContext(context: AgentContext): HandoffContext {
37
- return {
38
- workdir: context.workingState.workdir,
39
- gitBranch: context.workingState.gitBranch,
40
- currentGoal: context.tasks.currentGoal,
41
- activeTasks: context.tasks.tasks
42
- .filter((t) => t.status === "in_progress" || t.status === "pending")
43
- .map((t) => ({
44
- content: t.content,
45
- status: t.status as "in_progress" | "pending",
46
- priority: t.priority,
47
- })),
48
- recentAccomplishments: context.conversation.accomplishments.slice(0, 5),
49
- topics: context.conversation.topics.slice(0, 10),
50
- custom: Object.keys(context.custom).length > 0 ? context.custom : undefined,
51
- };
52
- }
53
-
54
- /**
55
- * Gets handoff context for an agent by ID
56
- */
57
- export function getHandoffContextForAgent(agentId: string): HandoffContext | null {
58
- const context = loadContext(agentId);
59
- if (!context) {
60
- return null;
61
- }
62
- return extractHandoffContext(context);
63
- }
64
-
65
- /**
66
- * Serializes handoff context to a string for inclusion in API calls
67
- */
68
- export function serializeHandoffContext(context: HandoffContext): string {
69
- return JSON.stringify(context);
70
- }
71
-
72
- /**
73
- * Parses handoff context from a string (received from API)
74
- */
75
- export function parseHandoffContext(contextString: string): HandoffContext | null {
76
- try {
77
- return JSON.parse(contextString) as HandoffContext;
78
- } catch {
79
- return null;
80
- }
81
- }
82
-
83
- /**
84
- * Generates a human-readable summary of handoff context
85
- */
86
- export function formatHandoffContextSummary(context: HandoffContext): string {
87
- const lines: string[] = [];
88
-
89
- if (context.workdir) {
90
- lines.push(`Working directory: ${context.workdir}`);
91
- }
92
- if (context.gitBranch) {
93
- lines.push(`Git branch: ${context.gitBranch}`);
94
- }
95
- if (context.currentGoal) {
96
- lines.push(`Current goal: ${context.currentGoal}`);
97
- }
98
-
99
- if (context.activeTasks.length > 0) {
100
- lines.push("");
101
- lines.push("Active tasks:");
102
- for (const task of context.activeTasks) {
103
- const icon = task.status === "in_progress" ? ">" : "-";
104
- lines.push(` ${icon} ${task.content}`);
105
- }
106
- }
107
-
108
- if (context.recentAccomplishments.length > 0) {
109
- lines.push("");
110
- lines.push("Recent accomplishments:");
111
- for (const acc of context.recentAccomplishments) {
112
- lines.push(` - ${acc}`);
113
- }
114
- }
115
-
116
- if (context.topics.length > 0) {
117
- lines.push("");
118
- lines.push(`Topics: ${context.topics.join(", ")}`);
119
- }
120
-
121
- return lines.join("\n");
122
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Context Module
3
- * Agent context persistence for cross-session state management
4
- */
5
-
6
- export * from "./handoff.js";
7
- export * from "./schema.js";
8
- export * from "./storage.js";
@@ -1,111 +0,0 @@
1
- /**
2
- * Agent Context Schema
3
- * Defines the structure for persisting agent context across sessions
4
- */
5
-
6
- export const CONTEXT_VERSION = 1;
7
- export const CONTEXT_DIR = `${process.env.HOME}/.agentmesh/context`;
8
-
9
- /**
10
- * Summary of conversation history for context restoration
11
- */
12
- export interface ConversationSummary {
13
- /** Total messages in the conversation */
14
- messageCount: number;
15
- /** Key topics discussed */
16
- topics: string[];
17
- /** Summary of what was accomplished */
18
- accomplishments: string[];
19
- /** Last 5 user messages (truncated) */
20
- recentMessages: Array<{
21
- role: "user" | "assistant";
22
- content: string;
23
- timestamp: string;
24
- }>;
25
- }
26
-
27
- /**
28
- * Current working state of the agent
29
- */
30
- export interface WorkingState {
31
- /** Current working directory */
32
- workdir: string;
33
- /** Recently accessed files */
34
- recentFiles: string[];
35
- /** Open file paths being edited */
36
- openFiles: string[];
37
- /** Git branch if in a repo */
38
- gitBranch?: string;
39
- /** Git status summary */
40
- gitStatus?: string;
41
- }
42
-
43
- /**
44
- * In-progress task state from TodoWrite
45
- */
46
- export interface TaskState {
47
- /** Active tasks */
48
- tasks: Array<{
49
- content: string;
50
- status: "pending" | "in_progress" | "completed" | "cancelled";
51
- priority: "high" | "medium" | "low";
52
- }>;
53
- /** Overall goal being worked on */
54
- currentGoal?: string;
55
- }
56
-
57
- /**
58
- * Custom key-value store for agent-specific context
59
- */
60
- export interface CustomContext {
61
- [key: string]: unknown;
62
- }
63
-
64
- /**
65
- * Full agent context structure
66
- */
67
- export interface AgentContext {
68
- /** Schema version for migration support */
69
- version: number;
70
- /** Agent ID this context belongs to */
71
- agentId: string;
72
- /** Agent name */
73
- agentName: string;
74
- /** When this context was last saved */
75
- savedAt: string;
76
- /** Conversation summary */
77
- conversation: ConversationSummary;
78
- /** Current working state */
79
- workingState: WorkingState;
80
- /** Task state */
81
- tasks: TaskState;
82
- /** Custom context data */
83
- custom: CustomContext;
84
- }
85
-
86
- /**
87
- * Creates an empty context for a new agent
88
- */
89
- export function createEmptyContext(agentId: string, agentName: string): AgentContext {
90
- return {
91
- version: CONTEXT_VERSION,
92
- agentId,
93
- agentName,
94
- savedAt: new Date().toISOString(),
95
- conversation: {
96
- messageCount: 0,
97
- topics: [],
98
- accomplishments: [],
99
- recentMessages: [],
100
- },
101
- workingState: {
102
- workdir: process.cwd(),
103
- recentFiles: [],
104
- openFiles: [],
105
- },
106
- tasks: {
107
- tasks: [],
108
- },
109
- custom: {},
110
- };
111
- }
@@ -1,197 +0,0 @@
1
- /**
2
- * Context Storage Module
3
- * Handles saving and loading agent context to/from disk
4
- */
5
-
6
- import * as fs from "node:fs";
7
- import * as path from "node:path";
8
- import { type AgentContext, CONTEXT_DIR, CONTEXT_VERSION, createEmptyContext } from "./schema.js";
9
-
10
- /**
11
- * Ensures the context directory exists
12
- */
13
- export function ensureContextDir(): void {
14
- if (!fs.existsSync(CONTEXT_DIR)) {
15
- fs.mkdirSync(CONTEXT_DIR, { recursive: true });
16
- }
17
- }
18
-
19
- /**
20
- * Gets the context file path for an agent
21
- */
22
- export function getContextPath(agentId: string): string {
23
- return path.join(CONTEXT_DIR, `${agentId}.json`);
24
- }
25
-
26
- /**
27
- * Saves agent context to disk
28
- */
29
- export function saveContext(context: AgentContext): void {
30
- ensureContextDir();
31
- const contextPath = getContextPath(context.agentId);
32
-
33
- // Update savedAt timestamp
34
- context.savedAt = new Date().toISOString();
35
-
36
- fs.writeFileSync(contextPath, JSON.stringify(context, null, 2));
37
- }
38
-
39
- /**
40
- * Loads agent context from disk
41
- * Returns null if context doesn't exist or is invalid
42
- */
43
- export function loadContext(agentId: string): AgentContext | null {
44
- const contextPath = getContextPath(agentId);
45
-
46
- try {
47
- if (!fs.existsSync(contextPath)) {
48
- return null;
49
- }
50
-
51
- const content = fs.readFileSync(contextPath, "utf-8");
52
- const context = JSON.parse(content) as AgentContext;
53
-
54
- // Validate version
55
- if (context.version !== CONTEXT_VERSION) {
56
- // In the future, we can migrate old versions here
57
- console.warn(`Context version mismatch: expected ${CONTEXT_VERSION}, got ${context.version}`);
58
- return null;
59
- }
60
-
61
- return context;
62
- } catch (error) {
63
- console.error(`Failed to load context for agent ${agentId}:`, error);
64
- return null;
65
- }
66
- }
67
-
68
- /**
69
- * Loads context or creates a new empty one
70
- */
71
- export function loadOrCreateContext(agentId: string, agentName: string): AgentContext {
72
- const existing = loadContext(agentId);
73
- if (existing) {
74
- return existing;
75
- }
76
- return createEmptyContext(agentId, agentName);
77
- }
78
-
79
- /**
80
- * Deletes agent context from disk
81
- */
82
- export function deleteContext(agentId: string): boolean {
83
- const contextPath = getContextPath(agentId);
84
-
85
- try {
86
- if (fs.existsSync(contextPath)) {
87
- fs.unlinkSync(contextPath);
88
- return true;
89
- }
90
- return false;
91
- } catch (error) {
92
- console.error(`Failed to delete context for agent ${agentId}:`, error);
93
- return false;
94
- }
95
- }
96
-
97
- /**
98
- * Lists all saved context files
99
- */
100
- export function listContexts(): Array<{ agentId: string; savedAt: string }> {
101
- ensureContextDir();
102
-
103
- try {
104
- const files = fs.readdirSync(CONTEXT_DIR);
105
- const contexts: Array<{ agentId: string; savedAt: string }> = [];
106
-
107
- for (const file of files) {
108
- if (!file.endsWith(".json")) continue;
109
-
110
- const agentId = file.replace(".json", "");
111
- const context = loadContext(agentId);
112
- if (context) {
113
- contexts.push({
114
- agentId,
115
- savedAt: context.savedAt,
116
- });
117
- }
118
- }
119
-
120
- return contexts.sort((a, b) => new Date(b.savedAt).getTime() - new Date(a.savedAt).getTime());
121
- } catch {
122
- return [];
123
- }
124
- }
125
-
126
- /**
127
- * Updates specific fields in the context
128
- */
129
- export function updateContext(
130
- agentId: string,
131
- updates: Partial<Omit<AgentContext, "version" | "agentId" | "savedAt">>,
132
- ): AgentContext | null {
133
- const context = loadContext(agentId);
134
- if (!context) {
135
- return null;
136
- }
137
-
138
- const updated: AgentContext = {
139
- ...context,
140
- ...updates,
141
- // Preserve these fields
142
- version: CONTEXT_VERSION,
143
- agentId: context.agentId,
144
- savedAt: new Date().toISOString(),
145
- };
146
-
147
- saveContext(updated);
148
- return updated;
149
- }
150
-
151
- /**
152
- * Exports context to a specified file path
153
- */
154
- export function exportContext(agentId: string, outputPath: string): boolean {
155
- const context = loadContext(agentId);
156
- if (!context) {
157
- return false;
158
- }
159
-
160
- try {
161
- fs.writeFileSync(outputPath, JSON.stringify(context, null, 2));
162
- return true;
163
- } catch (error) {
164
- console.error(`Failed to export context:`, error);
165
- return false;
166
- }
167
- }
168
-
169
- /**
170
- * Imports context from a file path
171
- */
172
- export function importContext(inputPath: string): AgentContext | null {
173
- try {
174
- if (!fs.existsSync(inputPath)) {
175
- console.error(`File not found: ${inputPath}`);
176
- return null;
177
- }
178
-
179
- const content = fs.readFileSync(inputPath, "utf-8");
180
- const context = JSON.parse(content) as AgentContext;
181
-
182
- // Validate required fields
183
- if (!context.agentId || !context.agentName) {
184
- console.error("Invalid context file: missing agentId or agentName");
185
- return null;
186
- }
187
-
188
- // Update version and save
189
- context.version = CONTEXT_VERSION;
190
- saveContext(context);
191
-
192
- return context;
193
- } catch (error) {
194
- console.error(`Failed to import context:`, error);
195
- return null;
196
- }
197
- }