@agent-relay/spawner 0.1.0
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.
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +552 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +193 -0
- package/dist/types.js.map +1 -0
- package/package.json +47 -0
- package/src/index.ts +8 -0
- package/src/types.test.ts +385 -0
- package/src/types.ts +228 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spawner Types
|
|
3
|
+
*
|
|
4
|
+
* Zod schemas for agent spawning and lifecycle management types.
|
|
5
|
+
* These types are used across the spawner, daemon, and dashboard.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
|
|
10
|
+
// =============================================================================
|
|
11
|
+
// Enums and Basic Types
|
|
12
|
+
// =============================================================================
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* When shadow agents should activate
|
|
16
|
+
*/
|
|
17
|
+
export const SpeakOnTriggerSchema = z.enum([
|
|
18
|
+
'SESSION_END',
|
|
19
|
+
'CODE_WRITTEN',
|
|
20
|
+
'REVIEW_REQUEST',
|
|
21
|
+
'EXPLICIT_ASK',
|
|
22
|
+
'ALL_MESSAGES',
|
|
23
|
+
]);
|
|
24
|
+
export type SpeakOnTrigger = z.infer<typeof SpeakOnTriggerSchema>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Shadow role preset names
|
|
28
|
+
*/
|
|
29
|
+
export const ShadowRolePresetSchema = z.enum(['reviewer', 'auditor', 'active']);
|
|
30
|
+
export type ShadowRolePreset = z.infer<typeof ShadowRolePresetSchema>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Shadow execution mode
|
|
34
|
+
*/
|
|
35
|
+
export const ShadowModeSchema = z.enum(['subagent', 'process']);
|
|
36
|
+
export type ShadowMode = z.infer<typeof ShadowModeSchema>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Policy source types
|
|
40
|
+
*/
|
|
41
|
+
export const PolicySourceSchema = z.enum(['repo', 'local', 'workspace', 'default']);
|
|
42
|
+
export type PolicySource = z.infer<typeof PolicySourceSchema>;
|
|
43
|
+
|
|
44
|
+
// =============================================================================
|
|
45
|
+
// Policy Types
|
|
46
|
+
// =============================================================================
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Policy decision result
|
|
50
|
+
*/
|
|
51
|
+
export const PolicyDecisionSchema = z.object({
|
|
52
|
+
allowed: z.boolean(),
|
|
53
|
+
reason: z.string(),
|
|
54
|
+
policySource: PolicySourceSchema,
|
|
55
|
+
});
|
|
56
|
+
export type PolicyDecision = z.infer<typeof PolicyDecisionSchema>;
|
|
57
|
+
|
|
58
|
+
// =============================================================================
|
|
59
|
+
// Spawn Request/Result Types
|
|
60
|
+
// =============================================================================
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Request to spawn a new agent
|
|
64
|
+
*/
|
|
65
|
+
export const SpawnRequestSchema = z.object({
|
|
66
|
+
/** Worker agent name (must be unique) */
|
|
67
|
+
name: z.string(),
|
|
68
|
+
/** CLI tool (e.g., 'claude', 'claude:opus', 'codex', 'gemini') */
|
|
69
|
+
cli: z.string(),
|
|
70
|
+
/** Initial task to inject after spawn */
|
|
71
|
+
task: z.string(),
|
|
72
|
+
/** Optional team name for organization */
|
|
73
|
+
team: z.string().optional(),
|
|
74
|
+
/** Working directory (defaults to project root) */
|
|
75
|
+
cwd: z.string().optional(),
|
|
76
|
+
/** Name of requesting agent (for policy enforcement) */
|
|
77
|
+
spawnerName: z.string().optional(),
|
|
78
|
+
/** Interactive mode - disables auto-accept of permission prompts */
|
|
79
|
+
interactive: z.boolean().optional(),
|
|
80
|
+
/** Shadow execution mode (subagent = no extra process) */
|
|
81
|
+
shadowMode: ShadowModeSchema.optional(),
|
|
82
|
+
/** Primary agent to shadow (if this agent is a shadow) */
|
|
83
|
+
shadowOf: z.string().optional(),
|
|
84
|
+
/** Shadow agent profile to use (for subagent mode) */
|
|
85
|
+
shadowAgent: z.string().optional(),
|
|
86
|
+
/** When to trigger the shadow (for subagent mode) */
|
|
87
|
+
shadowTriggers: z.array(SpeakOnTriggerSchema).optional(),
|
|
88
|
+
/** When the shadow should speak (default: ['EXPLICIT_ASK']) */
|
|
89
|
+
shadowSpeakOn: z.array(SpeakOnTriggerSchema).optional(),
|
|
90
|
+
/** User ID for per-user credential storage in shared workspaces */
|
|
91
|
+
userId: z.string().optional(),
|
|
92
|
+
});
|
|
93
|
+
export type SpawnRequest = z.infer<typeof SpawnRequestSchema>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Result of a spawn operation
|
|
97
|
+
*/
|
|
98
|
+
export const SpawnResultSchema = z.object({
|
|
99
|
+
success: z.boolean(),
|
|
100
|
+
name: z.string(),
|
|
101
|
+
/** PID of the spawned process (for pty-based workers) */
|
|
102
|
+
pid: z.number().optional(),
|
|
103
|
+
error: z.string().optional(),
|
|
104
|
+
/** Policy decision details if spawn was blocked by policy */
|
|
105
|
+
policyDecision: PolicyDecisionSchema.optional(),
|
|
106
|
+
});
|
|
107
|
+
export type SpawnResult = z.infer<typeof SpawnResultSchema>;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Information about an active worker
|
|
111
|
+
*/
|
|
112
|
+
export const WorkerInfoSchema = z.object({
|
|
113
|
+
name: z.string(),
|
|
114
|
+
cli: z.string(),
|
|
115
|
+
task: z.string(),
|
|
116
|
+
/** Optional team name this agent belongs to */
|
|
117
|
+
team: z.string().optional(),
|
|
118
|
+
spawnedAt: z.number(),
|
|
119
|
+
/** PID of the pty process */
|
|
120
|
+
pid: z.number().optional(),
|
|
121
|
+
});
|
|
122
|
+
export type WorkerInfo = z.infer<typeof WorkerInfoSchema>;
|
|
123
|
+
|
|
124
|
+
// =============================================================================
|
|
125
|
+
// Shadow Agent Types
|
|
126
|
+
// =============================================================================
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Primary agent configuration for spawnWithShadow
|
|
130
|
+
*/
|
|
131
|
+
export const PrimaryAgentConfigSchema = z.object({
|
|
132
|
+
/** Agent name */
|
|
133
|
+
name: z.string(),
|
|
134
|
+
/** CLI command (default: 'claude') */
|
|
135
|
+
command: z.string().optional(),
|
|
136
|
+
/** Initial task to send to the agent */
|
|
137
|
+
task: z.string().optional(),
|
|
138
|
+
/** Team name to organize under */
|
|
139
|
+
team: z.string().optional(),
|
|
140
|
+
});
|
|
141
|
+
export type PrimaryAgentConfig = z.infer<typeof PrimaryAgentConfigSchema>;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Shadow agent configuration for spawnWithShadow
|
|
145
|
+
*/
|
|
146
|
+
export const ShadowAgentConfigSchema = z.object({
|
|
147
|
+
/** Shadow agent name */
|
|
148
|
+
name: z.string(),
|
|
149
|
+
/** CLI command (default: same as primary) */
|
|
150
|
+
command: z.string().optional(),
|
|
151
|
+
/** Role preset (reviewer, auditor, active) or custom prompt */
|
|
152
|
+
role: z.string().optional(),
|
|
153
|
+
/** Custom speakOn triggers (overrides role preset) */
|
|
154
|
+
speakOn: z.array(SpeakOnTriggerSchema).optional(),
|
|
155
|
+
/** Custom prompt for the shadow agent */
|
|
156
|
+
prompt: z.string().optional(),
|
|
157
|
+
});
|
|
158
|
+
export type ShadowAgentConfig = z.infer<typeof ShadowAgentConfigSchema>;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Request for spawning a primary agent with its shadow
|
|
162
|
+
*/
|
|
163
|
+
export const SpawnWithShadowRequestSchema = z.object({
|
|
164
|
+
/** Primary agent configuration */
|
|
165
|
+
primary: PrimaryAgentConfigSchema,
|
|
166
|
+
/** Shadow agent configuration */
|
|
167
|
+
shadow: ShadowAgentConfigSchema,
|
|
168
|
+
});
|
|
169
|
+
export type SpawnWithShadowRequest = z.infer<typeof SpawnWithShadowRequestSchema>;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Result from spawnWithShadow
|
|
173
|
+
*/
|
|
174
|
+
export const SpawnWithShadowResultSchema = z.object({
|
|
175
|
+
success: z.boolean(),
|
|
176
|
+
/** Primary agent spawn result */
|
|
177
|
+
primary: SpawnResultSchema.optional(),
|
|
178
|
+
/** Shadow agent spawn result */
|
|
179
|
+
shadow: SpawnResultSchema.optional(),
|
|
180
|
+
/** Error message if overall operation failed */
|
|
181
|
+
error: z.string().optional(),
|
|
182
|
+
});
|
|
183
|
+
export type SpawnWithShadowResult = z.infer<typeof SpawnWithShadowResultSchema>;
|
|
184
|
+
|
|
185
|
+
// =============================================================================
|
|
186
|
+
// Bridge/Multi-Project Types
|
|
187
|
+
// =============================================================================
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Project configuration for multi-project orchestration
|
|
191
|
+
*/
|
|
192
|
+
export const ProjectConfigSchema = z.object({
|
|
193
|
+
/** Absolute path to project root */
|
|
194
|
+
path: z.string(),
|
|
195
|
+
/** Project identifier (derived from path hash) */
|
|
196
|
+
id: z.string(),
|
|
197
|
+
/** Socket path for this project's daemon */
|
|
198
|
+
socketPath: z.string(),
|
|
199
|
+
/** Lead agent name (auto-generated from dirname if not specified) */
|
|
200
|
+
leadName: z.string(),
|
|
201
|
+
/** CLI tool to use (default: claude) */
|
|
202
|
+
cli: z.string(),
|
|
203
|
+
});
|
|
204
|
+
export type ProjectConfig = z.infer<typeof ProjectConfigSchema>;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Bridge configuration for multi-project coordination
|
|
208
|
+
*/
|
|
209
|
+
export const BridgeConfigSchema = z.object({
|
|
210
|
+
/** Projects to bridge */
|
|
211
|
+
projects: z.array(ProjectConfigSchema),
|
|
212
|
+
/** CLI override for all projects */
|
|
213
|
+
cliOverride: z.string().optional(),
|
|
214
|
+
});
|
|
215
|
+
export type BridgeConfig = z.infer<typeof BridgeConfigSchema>;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Lead agent information
|
|
219
|
+
*/
|
|
220
|
+
export const LeadInfoSchema = z.object({
|
|
221
|
+
/** Lead agent name */
|
|
222
|
+
name: z.string(),
|
|
223
|
+
/** Project this lead manages */
|
|
224
|
+
projectId: z.string(),
|
|
225
|
+
/** Whether lead is currently connected */
|
|
226
|
+
connected: z.boolean(),
|
|
227
|
+
});
|
|
228
|
+
export type LeadInfo = z.infer<typeof LeadInfoSchema>;
|