@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,225 +0,0 @@
1
- /**
2
- * Runner Module
3
- * Handles model resolution, validation, and runner-specific configuration
4
- */
5
-
6
- import { execSync } from "node:child_process";
7
-
8
- // ============================================================================
9
- // Types
10
- // ============================================================================
11
-
12
- export type RunnerType = "opencode" | "claude" | "custom";
13
-
14
- export interface RunnerConfig {
15
- type: RunnerType;
16
- command: string;
17
- model: string;
18
- env: Record<string, string>;
19
- }
20
-
21
- export interface ModelResolutionInput {
22
- cliModel?: string;
23
- agentModel?: string;
24
- defaultModel: string;
25
- command: string;
26
- }
27
-
28
- // ============================================================================
29
- // Runner Detection
30
- // ============================================================================
31
-
32
- /**
33
- * Detects the runner type from the command
34
- */
35
- export function detectRunner(command: string): RunnerType {
36
- const cmd = command.toLowerCase().trim();
37
-
38
- if (cmd === "opencode" || cmd.startsWith("opencode ")) {
39
- return "opencode";
40
- }
41
-
42
- if (cmd === "claude" || cmd.startsWith("claude ")) {
43
- return "claude";
44
- }
45
-
46
- return "custom";
47
- }
48
-
49
- // ============================================================================
50
- // Model Resolution
51
- // ============================================================================
52
-
53
- /**
54
- * Resolves the effective model from CLI > agent config > defaults
55
- */
56
- export function resolveModel(input: ModelResolutionInput): string {
57
- // Priority: CLI flag > agent config > default
58
- return input.cliModel || input.agentModel || input.defaultModel;
59
- }
60
-
61
- // ============================================================================
62
- // OpenCode Integration
63
- // ============================================================================
64
-
65
- let cachedOpenCodeModels: string[] | null = null;
66
-
67
- /**
68
- * Gets available OpenCode models (cached)
69
- */
70
- export function getOpenCodeModels(): string[] {
71
- if (cachedOpenCodeModels) {
72
- return cachedOpenCodeModels;
73
- }
74
-
75
- try {
76
- const output = execSync("opencode models 2>/dev/null", {
77
- encoding: "utf-8",
78
- timeout: 10000,
79
- });
80
-
81
- cachedOpenCodeModels = output
82
- .split("\n")
83
- .map((line) => line.trim())
84
- .filter((line) => line.length > 0 && !line.startsWith("#"));
85
-
86
- return cachedOpenCodeModels;
87
- } catch {
88
- // OpenCode not available or failed
89
- return [];
90
- }
91
- }
92
-
93
- /**
94
- * Validates that a model is available in OpenCode
95
- */
96
- export function validateOpenCodeModel(model: string): { valid: boolean; error?: string } {
97
- const models = getOpenCodeModels();
98
-
99
- // If we couldn't get models list, allow any (graceful degradation)
100
- if (models.length === 0) {
101
- return { valid: true };
102
- }
103
-
104
- if (models.includes(model)) {
105
- return { valid: true };
106
- }
107
-
108
- // Check for partial match (e.g., "claude-sonnet-4" matches "anthropic/claude-sonnet-4")
109
- const partialMatch = models.find(
110
- (m) => m.endsWith(`/${model}`) || m === model || m.split("/").pop() === model,
111
- );
112
-
113
- if (partialMatch) {
114
- return { valid: true };
115
- }
116
-
117
- return {
118
- valid: false,
119
- error: `Model "${model}" not found in OpenCode. Run 'opencode models' to see available models.`,
120
- };
121
- }
122
-
123
- // Common model aliases to their full OpenCode names
124
- const MODEL_ALIASES: Record<string, string> = {
125
- "claude-sonnet-4": "anthropic/claude-sonnet-4-5",
126
- "claude-sonnet-4-5": "anthropic/claude-sonnet-4-5",
127
- "claude-opus-4": "anthropic/claude-opus-4-5",
128
- "claude-opus-4-5": "anthropic/claude-opus-4-5",
129
- "claude-haiku-4": "anthropic/claude-haiku-4-5",
130
- "claude-haiku-4-5": "anthropic/claude-haiku-4-5",
131
- "gpt-4o": "openai/gpt-4o",
132
- "gpt-4": "openai/gpt-4",
133
- o3: "openai/o3",
134
- "o3-mini": "openai/o3-mini",
135
- codex: "openai/codex",
136
- };
137
-
138
- /**
139
- * Normalizes a model name for OpenCode
140
- * e.g., "claude-sonnet-4" -> "anthropic/claude-sonnet-4-5" if that's what OpenCode expects
141
- */
142
- export function normalizeOpenCodeModel(model: string): string {
143
- // Check hardcoded aliases first (works even if opencode not installed)
144
- if (MODEL_ALIASES[model]) {
145
- return MODEL_ALIASES[model];
146
- }
147
-
148
- // Already has provider prefix
149
- if (model.includes("/")) {
150
- return model;
151
- }
152
-
153
- const models = getOpenCodeModels();
154
-
155
- // Direct match
156
- if (models.includes(model)) {
157
- return model;
158
- }
159
-
160
- // Try to find full path version
161
- const fullPath = models.find((m) => m.endsWith(`/${model}`) || m.split("/").pop() === model);
162
-
163
- return fullPath || model;
164
- }
165
-
166
- // ============================================================================
167
- // Runner Configuration
168
- // ============================================================================
169
-
170
- /**
171
- * Builds the complete runner configuration including environment variables
172
- */
173
- export function buildRunnerConfig(input: ModelResolutionInput): RunnerConfig {
174
- const runnerType = detectRunner(input.command);
175
- const model = resolveModel(input);
176
- const env: Record<string, string> = {};
177
-
178
- switch (runnerType) {
179
- case "opencode": {
180
- // Validate model for OpenCode
181
- const validation = validateOpenCodeModel(model);
182
- if (!validation.valid) {
183
- console.warn(`Warning: ${validation.error}`);
184
- }
185
-
186
- // Normalize and set OPENCODE_MODEL
187
- const normalizedModel = normalizeOpenCodeModel(model);
188
- env.OPENCODE_MODEL = normalizedModel;
189
- break;
190
- }
191
-
192
- case "claude": {
193
- // Claude CLI uses ANTHROPIC_MODEL or similar
194
- // For now, just pass the model - Claude CLI will handle it
195
- env.CLAUDE_MODEL = model;
196
- break;
197
- }
198
-
199
- case "custom":
200
- // Custom runners don't get automatic model env
201
- // User is responsible for configuring their tool
202
- break;
203
- }
204
-
205
- return {
206
- type: runnerType,
207
- command: input.command,
208
- model,
209
- env,
210
- };
211
- }
212
-
213
- /**
214
- * Gets a human-readable runner name
215
- */
216
- export function getRunnerDisplayName(runnerType: RunnerType): string {
217
- switch (runnerType) {
218
- case "opencode":
219
- return "OpenCode";
220
- case "claude":
221
- return "Claude CLI";
222
- case "custom":
223
- return "Custom";
224
- }
225
- }