@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,94 +0,0 @@
1
- import WebSocket from "ws";
2
-
3
- export interface WebSocketConfig {
4
- url: string;
5
- token: string;
6
- onMessage: (data: WebSocketEvent) => void;
7
- onConnect?: () => void;
8
- onDisconnect?: () => void;
9
- onError?: (error: Error) => void;
10
- }
11
-
12
- export interface WebSocketEvent {
13
- type: string;
14
- [key: string]: unknown;
15
- }
16
-
17
- export class AgentWebSocket {
18
- private ws: WebSocket | null = null;
19
- private config: WebSocketConfig;
20
- private reconnectAttempts = 0;
21
- private maxReconnectAttempts = 10;
22
- private reconnectDelay = 1000;
23
- private shouldReconnect = true;
24
-
25
- constructor(config: WebSocketConfig) {
26
- this.config = config;
27
- }
28
-
29
- connect(): void {
30
- if (this.ws?.readyState === WebSocket.OPEN) {
31
- return;
32
- }
33
-
34
- const wsUrl = `${this.config.url}?token=${this.config.token}`;
35
-
36
- this.ws = new WebSocket(wsUrl);
37
-
38
- this.ws.on("open", () => {
39
- this.reconnectAttempts = 0;
40
- this.config.onConnect?.();
41
- });
42
-
43
- this.ws.on("message", (data) => {
44
- try {
45
- const event = JSON.parse(data.toString()) as WebSocketEvent;
46
- this.config.onMessage(event);
47
- } catch (error) {
48
- console.error("Failed to parse WebSocket message:", error);
49
- }
50
- });
51
-
52
- this.ws.on("close", () => {
53
- this.config.onDisconnect?.();
54
- this.scheduleReconnect();
55
- });
56
-
57
- this.ws.on("error", (error) => {
58
- this.config.onError?.(error);
59
- });
60
- }
61
-
62
- private scheduleReconnect(): void {
63
- if (!this.shouldReconnect) {
64
- return;
65
- }
66
-
67
- if (this.reconnectAttempts >= this.maxReconnectAttempts) {
68
- console.error("Max reconnect attempts reached");
69
- return;
70
- }
71
-
72
- this.reconnectAttempts++;
73
- const delay = this.reconnectDelay * 2 ** (this.reconnectAttempts - 1);
74
-
75
- setTimeout(() => {
76
- console.log(
77
- `Reconnecting... (attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts})`,
78
- );
79
- this.connect();
80
- }, delay);
81
- }
82
-
83
- disconnect(): void {
84
- this.shouldReconnect = false;
85
- if (this.ws) {
86
- this.ws.close();
87
- this.ws = null;
88
- }
89
- }
90
-
91
- isConnected(): boolean {
92
- return this.ws?.readyState === WebSocket.OPEN;
93
- }
94
- }
package/src/index.ts DELETED
@@ -1,10 +0,0 @@
1
- // Re-export core modules for programmatic usage
2
-
3
- export * from "./config/loader.js";
4
- export * from "./config/schema.js";
5
- export { AgentDaemon } from "./core/daemon.js";
6
- export { Heartbeat } from "./core/heartbeat.js";
7
- export * from "./core/injector.js";
8
- export * from "./core/registry.js";
9
- export * from "./core/tmux.js";
10
- export { AgentWebSocket } from "./core/websocket.js";
package/src/utils/jwt.ts DELETED
@@ -1,87 +0,0 @@
1
- /**
2
- * JWT utilities for token management
3
- * Note: We only decode the payload, we don't verify signatures here
4
- * (verification happens on the hub side)
5
- */
6
-
7
- export interface TokenPayload {
8
- sub: string; // Agent ID
9
- actorType: string; // "agent"
10
- workspaceScopes: string[];
11
- iat: number; // Issued at (Unix timestamp)
12
- exp: number; // Expiration (Unix timestamp)
13
- }
14
-
15
- /**
16
- * Decode a JWT token without verifying the signature
17
- */
18
- export function decodeToken(token: string): TokenPayload | null {
19
- try {
20
- const parts = token.split(".");
21
- if (parts.length !== 3) {
22
- return null;
23
- }
24
-
25
- const payload = parts[1];
26
- const decoded = Buffer.from(payload, "base64url").toString("utf-8");
27
- return JSON.parse(decoded) as TokenPayload;
28
- } catch {
29
- return null;
30
- }
31
- }
32
-
33
- /**
34
- * Get the expiration date from a token
35
- */
36
- export function getTokenExpiry(token: string): Date | null {
37
- const payload = decodeToken(token);
38
- if (!payload || !payload.exp) {
39
- return null;
40
- }
41
-
42
- return new Date(payload.exp * 1000);
43
- }
44
-
45
- /**
46
- * Check if a token is expired
47
- */
48
- export function isTokenExpired(token: string): boolean {
49
- const expiry = getTokenExpiry(token);
50
- if (!expiry) {
51
- return true;
52
- }
53
-
54
- return expiry.getTime() <= Date.now();
55
- }
56
-
57
- /**
58
- * Check if a token will expire within the given milliseconds
59
- */
60
- export function isTokenExpiringSoon(token: string, withinMs: number): boolean {
61
- const expiry = getTokenExpiry(token);
62
- if (!expiry) {
63
- return true;
64
- }
65
-
66
- return expiry.getTime() <= Date.now() + withinMs;
67
- }
68
-
69
- /**
70
- * Get the agent ID from a token
71
- */
72
- export function getAgentIdFromToken(token: string): string | null {
73
- const payload = decodeToken(token);
74
- return payload?.sub ?? null;
75
- }
76
-
77
- /**
78
- * Get time remaining until token expires in milliseconds
79
- */
80
- export function getTokenTimeRemaining(token: string): number {
81
- const expiry = getTokenExpiry(token);
82
- if (!expiry) {
83
- return 0;
84
- }
85
-
86
- return Math.max(0, expiry.getTime() - Date.now());
87
- }
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "outDir": "dist",
5
- "rootDir": "src"
6
- },
7
- "include": ["src/**/*"]
8
- }
package/vitest.config.ts DELETED
@@ -1,12 +0,0 @@
1
- import { defineConfig } from "vitest/config";
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- environment: "node",
7
- include: ["src/__tests__/**/*.test.ts"],
8
- coverage: {
9
- reporter: ["text", "json", "html"],
10
- },
11
- },
12
- });