@x-otto/subagent 0.0.0-stage → 0.4.0-beta.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.
@@ -0,0 +1,4 @@
1
+ {
2
+ "version": 1,
3
+ "revision": "13ec97df06274f963a44e80bbb471f16"
4
+ }
@@ -0,0 +1,345 @@
1
+ import * as _$_x_otto_kernel0 from "@x-otto/kernel";
2
+ import { AgentSessionRegistry, AgentTool, ArtifactFencingRecord, ArtifactReceipt, ArtifactStorePort, CallerCapability, Clock, DeliveryOutcome, Id, IssuedExecutionRootRecord, JobCancelCause, JobRegistry, JobSlotReservation, JobWaitReportPort, ModelAvailabilityService, ModelCatalog, PersonaRef, PluginManifest, Ports, RecoverySnapshot, SessionManager, SessionMeta, SubagentAcceptedFollowupReceipt, SubagentChildSessions, SubagentControlCapability, SubagentDelegation, SubagentFollowupAddress, SubagentLimits, SubagentMode, SubagentOwnerDisposer, SubagentProvider, SubagentProviderRegistry, SubagentRun, SubagentSnapshot, SubagentStartRequest, SubagentStarted, ToolSchema, ToolViewConstraint } from "@x-otto/kernel";
3
+ import * as _$_x_otto_universal0 from "@x-otto/universal";
4
+ import { SlotWaitOptions } from "@x-otto/jobs";
5
+ import { ResourceOwnerRegistry } from "@x-otto/residency";
6
+ import { SubagentWorkspaceRoots as SubagentWorkspaceRoots$1 } from "@x-otto/subagent";
7
+
8
+ //#region src/persona.d.ts
9
+ interface PersonaDeclaration {
10
+ readonly instructions: string;
11
+ readonly preset?: string;
12
+ readonly tools?: readonly string[];
13
+ readonly excludeTools?: readonly string[];
14
+ readonly model?: string;
15
+ readonly effort?: string;
16
+ readonly cwd?: string;
17
+ }
18
+ interface PersonaCompilation {
19
+ readonly ref: PersonaRef;
20
+ readonly toolView: ToolViewConstraint;
21
+ readonly cwd?: string;
22
+ }
23
+ interface PersonaResolver {
24
+ resolve(ref: PersonaRef): Promise<PersonaDeclaration | undefined>;
25
+ available?(): readonly PersonaRef[];
26
+ }
27
+ type PersonaResolution = {
28
+ readonly ok: true;
29
+ readonly compilation: PersonaCompilation;
30
+ } | {
31
+ readonly ok: false;
32
+ readonly reason: string;
33
+ };
34
+ declare function compilePersona(ref: PersonaRef, declaration: PersonaDeclaration): PersonaCompilation;
35
+ declare function resolvePersona(resolver: PersonaResolver, ref: PersonaRef): Promise<PersonaResolution>;
36
+ //#endregion
37
+ //#region src/in-process.d.ts
38
+ interface SubagentWorkspaceRoots {
39
+ allocate(input: {
40
+ parentCwd: string;
41
+ label?: string;
42
+ ownerSessionId?: string;
43
+ branch?: string;
44
+ baseRevision?: string;
45
+ }): Promise<string | undefined>;
46
+ rebindOwner?(root: string, ownerSessionId: string): Promise<void>;
47
+ release?(root: string): Promise<void>;
48
+ seal?(root: string): Promise<ArtifactReceipt | undefined>;
49
+ }
50
+ interface InProcessProviderDeps {
51
+ personas?: PersonaResolver;
52
+ workspaceRoots?: SubagentWorkspaceRoots;
53
+ ids?: () => string;
54
+ random?: () => number;
55
+ sessions: () => AgentSessionRegistry;
56
+ models: () => ModelCatalog;
57
+ availability?: () => ModelAvailabilityService | undefined;
58
+ allowedModels?: () => readonly string[];
59
+ recoveryOf?: (sessionId: string) => RecoverySnapshot | undefined;
60
+ clock?: () => number;
61
+ claimSession?: (sessionId: string) => Promise<SessionClaimOutcome>;
62
+ diagnose?: (code: string, message: string) => void;
63
+ }
64
+ type SessionClaimOutcome = boolean | {
65
+ readonly ok: true;
66
+ } | {
67
+ readonly ok: false;
68
+ readonly message?: string;
69
+ readonly contended?: boolean;
70
+ };
71
+ declare function createInProcessProvider(deps: InProcessProviderDeps): SubagentProvider;
72
+ //#endregion
73
+ //#region src/component.d.ts
74
+ interface SubagentComponentOptions {
75
+ ports: Ports;
76
+ limits?: SubagentLimits;
77
+ workspaceRoots?: SubagentWorkspaceRoots;
78
+ personas?: PersonaResolver;
79
+ claimSession?: (sessionId: string) => Promise<SessionClaimOutcome>;
80
+ }
81
+ declare const Subagent: _$_x_otto_universal0.ComponentDefinition<SubagentComponentOptions>;
82
+ //#endregion
83
+ //#region src/control-state.d.ts
84
+ interface SpawnInfo {
85
+ parentSessionId: string;
86
+ originTurn: number | undefined;
87
+ }
88
+ type TicketReservation = {
89
+ kind: 'none';
90
+ } | {
91
+ kind: 'held';
92
+ sessionId: string;
93
+ };
94
+ type TicketPhase = {
95
+ kind: 'pending';
96
+ reservation: TicketReservation;
97
+ } | {
98
+ kind: 'cancelled';
99
+ cause: JobCancelCause;
100
+ reservation: TicketReservation;
101
+ } | {
102
+ kind: 'handed-off';
103
+ reservation: TicketReservation;
104
+ } | {
105
+ kind: 'handed-off-cancelled';
106
+ cause: JobCancelCause;
107
+ reservation: TicketReservation;
108
+ } | {
109
+ kind: 'abandoned';
110
+ cause: JobCancelCause;
111
+ reservation: TicketReservation;
112
+ } | {
113
+ kind: 'retiring';
114
+ cause: JobCancelCause;
115
+ reservation: TicketReservation;
116
+ run: SubagentRun;
117
+ };
118
+ interface StartingRecord {
119
+ parentSessionId: string;
120
+ phase: TicketPhase;
121
+ controller: AbortController;
122
+ settlement: Promise<void>;
123
+ settle: () => void;
124
+ }
125
+ declare class SubagentControlState {
126
+ readonly starting: Set<StartingRecord>;
127
+ readonly reservations: Set<string>;
128
+ readonly admitting: Map<string, number>;
129
+ readonly retiring: Map<string, Promise<void>>;
130
+ readonly spawnedBy: Map<string, SpawnInfo>;
131
+ disposed: boolean;
132
+ disposal: Promise<void> | undefined;
133
+ subagentRevision: number;
134
+ bumpSubagentRevision(): void;
135
+ }
136
+ //#endregion
137
+ //#region src/errors.d.ts
138
+ declare class SubagentDelegationError extends Error {
139
+ readonly code: string | undefined;
140
+ constructor(message: string, code?: string);
141
+ }
142
+ //#endregion
143
+ //#region src/control.d.ts
144
+ type SubagentControl = SubagentProviderRegistry & SubagentDelegation & SubagentChildSessions & SubagentOwnerDisposer & SubagentControlCapability;
145
+ interface SubagentControlOptions {
146
+ clock: Clock;
147
+ limits?: SubagentLimits;
148
+ admission?: {
149
+ reserve?(parentSessionId: string): Promise<JobSlotReservation | 'queue' | undefined>;
150
+ };
151
+ slotWait?: SlotWaitOptions;
152
+ fanOutLimit?: () => number | undefined;
153
+ tasks: () => JobRegistry;
154
+ sessions: () => AgentSessionRegistry;
155
+ emit: (timing: string, payload: unknown) => void;
156
+ meta?: (sessionId: string) => Promise<SessionMeta | null>;
157
+ processOwners?: () => ResourceOwnerRegistry | undefined;
158
+ observe?: (name: string, timing: string, handler: (input: unknown) => void) => () => void;
159
+ }
160
+ declare class SubagentControlImpl implements SubagentControl {
161
+ private readonly providerTable;
162
+ private readonly governor;
163
+ private readonly options;
164
+ private readonly state;
165
+ private readonly queue;
166
+ private readonly followupOps;
167
+ private readonly releaseOps;
168
+ private readonly fanOutLimit;
169
+ constructor(options: SubagentControlOptions, state?: SubagentControlState);
170
+ queueDepth: () => number;
171
+ retireQueue: () => void;
172
+ drainQueued: (limit?: number) => Promise<readonly string[]>;
173
+ registerProvider: (provider: SubagentProvider) => (() => void);
174
+ providers: () => string[];
175
+ delegationDepthLimit: () => number;
176
+ start: (request: SubagentStartRequest, mode: SubagentMode, provider?: string) => Promise<SubagentStarted>;
177
+ private settleTicket;
178
+ detachRun: (runId: string, options?: {
179
+ deliverIfSettled?: boolean;
180
+ }) => boolean;
181
+ cancelRun: (runId: string, cause: JobCancelCause) => boolean;
182
+ followup: (id: string, text: string, caller: CallerCapability, expectedJobKey?: string) => Promise<DeliveryOutcome>;
183
+ followupReceipt: (address: SubagentFollowupAddress, text: string, caller: CallerCapability, expectedJobKey?: string) => Promise<SubagentAcceptedFollowupReceipt>;
184
+ capabilityOf: (sessionId: string) => CallerCapability;
185
+ revision: () => number;
186
+ list: (caller: string) => SubagentSnapshot[];
187
+ private delegationJobOwnerOf;
188
+ private delegationJobsOf;
189
+ private ownedRunsOf;
190
+ private activeRunsOf;
191
+ private occupiedRunsOf;
192
+ private noteAdmitting;
193
+ releaseParent: (parentSessionId: string) => Promise<void>;
194
+ dispose(): Promise<void>;
195
+ private openTicket;
196
+ private closeTicket;
197
+ private detachTicket;
198
+ private forwardSignal;
199
+ private retireLateTicket;
200
+ private selectProvider;
201
+ private reserveThrough;
202
+ private assertResumeOwnership;
203
+ private isOwnedBy;
204
+ private cancelSafely;
205
+ private assertStartLive;
206
+ private startCancelled;
207
+ private discardLateRun;
208
+ private noteSpawnedBy;
209
+ private ancestryOf;
210
+ private attachOwner;
211
+ private observeRun;
212
+ private emitSafely;
213
+ private diagnose;
214
+ private assertCapabilities;
215
+ }
216
+ //#endregion
217
+ //#region src/persona-source.d.ts
218
+ declare const PERSONA_CONTRIBUTION_KEY = "personas";
219
+ declare function personaDeclarationOf(record: Record<string, unknown>): PersonaDeclaration | undefined;
220
+ declare function personasOfManifest(manifest: PluginManifest): readonly Record<string, unknown>[];
221
+ declare function personaDeclarationOfManifest(manifest: PluginManifest, personaId: string): PersonaDeclaration | undefined;
222
+ type PersonaManifestLookup = (ref: PersonaRef) => PluginManifest | undefined | Promise<PluginManifest | undefined>;
223
+ declare function personaRefsOfManifest(manifest: PluginManifest): PersonaRef[];
224
+ declare function createManifestPersonaResolver(lookup: PersonaManifestLookup, globalManifests?: () => readonly PluginManifest[]): PersonaResolver;
225
+ //#endregion
226
+ //#region src/tools.d.ts
227
+ declare const SUBAGENT_SCHEMA: ToolSchema<{
228
+ prompt: string;
229
+ mode?: "sync" | "background" | undefined;
230
+ start_target?: "fresh" | "fork" | "resume" | undefined;
231
+ resume_session_id?: string | undefined;
232
+ readonly?: boolean | undefined;
233
+ isolation?: "auto" | "in-place" | "worktree" | undefined;
234
+ model?: string | undefined;
235
+ label?: string | undefined;
236
+ provider?: string | undefined;
237
+ effort?: _$_x_otto_kernel0.ThinkingLevel | undefined;
238
+ tasks?: string[] | undefined;
239
+ persona?: {
240
+ plugin_id: string;
241
+ persona_id: string;
242
+ scope?: "global" | undefined;
243
+ } | undefined;
244
+ }>;
245
+ type SubagentArgs = ReturnType<typeof SUBAGENT_SCHEMA.parse>;
246
+ declare function createSubagentTool(control: () => SubagentControl, sessions?: () => SessionManager | undefined, personas?: readonly PersonaRef[], jobs?: () => JobRegistry | undefined, waitReportOf?: () => JobWaitReportPort | undefined): AgentTool<SubagentArgs>;
247
+ //#endregion
248
+ //#region src/workspaces/artifact-store.d.ts
249
+ interface ArtifactStoreOptions {
250
+ id: Id;
251
+ fencing?: FencingCheck;
252
+ root(): string;
253
+ now(): number;
254
+ }
255
+ interface PruneArtifactsInput {
256
+ keepCount: number;
257
+ maxAgeMs: number;
258
+ now?: () => number;
259
+ }
260
+ interface FencingCheck {
261
+ leaseOf(receipt: ArtifactReceipt): ArtifactFencingRecord | undefined;
262
+ }
263
+ interface PruneArtifactsReport {
264
+ readonly removed: readonly string[];
265
+ readonly kept: number;
266
+ }
267
+ interface PersistArtifactsInput {
268
+ leaseId: string;
269
+ generation: number;
270
+ ownerSessionId?: string;
271
+ baseRevision?: string;
272
+ files: readonly string[];
273
+ patch: string;
274
+ }
275
+ interface ListPendingReport {
276
+ readonly receipts: readonly ArtifactReceipt[];
277
+ readonly unreadable: number;
278
+ }
279
+ declare function createArtifactStore(options: ArtifactStoreOptions): {
280
+ listPending(): Promise<ListPendingReport>;
281
+ markConsumed(receiptId: string): Promise<void>;
282
+ persistComplete(input: PersistArtifactsInput): Promise<ArtifactReceipt>;
283
+ prune(input: PruneArtifactsInput): Promise<PruneArtifactsReport>;
284
+ toPort(): ArtifactStorePort;
285
+ verify(receipt: ArtifactReceipt): Promise<boolean>;
286
+ };
287
+ type ArtifactStore = ReturnType<typeof createArtifactStore>;
288
+ //#endregion
289
+ //#region src/workspaces/subagent-workspaces.d.ts
290
+ declare const SUBAGENT_WORKTREES_DIRNAME = "subagent-worktrees";
291
+ declare const EXECUTION_ROOT_RECORDS_DIRNAME = "subagent-execution-roots";
292
+ interface IssuedExecutionRoot extends IssuedExecutionRootRecord {
293
+ readonly pid?: number;
294
+ readonly bootId?: string;
295
+ readonly processStartedAt?: number;
296
+ readonly heartbeatAt?: number;
297
+ }
298
+ type ExecutionRootLiveness = 'alive' | 'dead' | 'unverifiable';
299
+ interface RestoredExecutionRoot extends IssuedExecutionRoot {
300
+ readonly liveness: ExecutionRootLiveness;
301
+ }
302
+ interface ExecutionRootLivenessOptions {
303
+ platform?: string;
304
+ bootId?(): string;
305
+ ownStartedAt?(): number | undefined;
306
+ probeStartedAt?(pid: number): number | undefined;
307
+ }
308
+ interface SubagentWorkspaceOptions {
309
+ clock: Clock;
310
+ id: Id;
311
+ baseDir(): string;
312
+ report?(message: string): void;
313
+ }
314
+ declare const SUBAGENT_ARTIFACTS_DIRNAME = "subagent-artifacts";
315
+ declare const ORPHAN_WORKTREE_MAX_AGE_MS: number;
316
+ declare function executionRootLiveness(record: IssuedExecutionRoot, options?: ExecutionRootLivenessOptions): ExecutionRootLiveness;
317
+ declare function createSubagentWorkspaceRoots(options: SubagentWorkspaceOptions): SubagentWorkspaceRoots$1 & {
318
+ issuedRoots(): readonly string[];
319
+ restoredRoots(): readonly RestoredExecutionRoot[];
320
+ executionLeases(): readonly IssuedExecutionRoot[];
321
+ baseRevisionOf(root: string): string | undefined;
322
+ seal(root: string): Promise<ArtifactReceipt | undefined>;
323
+ artifactStore(): ArtifactStore;
324
+ pruneArtifacts(): Promise<PruneArtifactsReport>;
325
+ sweepOrphanWorktrees(): Promise<OrphanWorktreeSweepReport>;
326
+ rebindOwner(root: string, ownerSessionId: string): Promise<void>;
327
+ };
328
+ interface OrphanWorktreeSweepReport {
329
+ readonly scanned: number;
330
+ readonly removed: number;
331
+ readonly keptRecent: number;
332
+ readonly skippedActive: number;
333
+ }
334
+ declare function sweepOrphanWorktrees(baseDir: string, active: ReadonlySet<string>, options?: {
335
+ maxAgeMs?: number;
336
+ now?: () => number;
337
+ }): Promise<OrphanWorktreeSweepReport>;
338
+ interface IsolatedArtifacts {
339
+ readonly root: string;
340
+ readonly files: readonly string[];
341
+ readonly patch: string;
342
+ }
343
+ declare function collectIsolatedArtifacts(root: string, baseRevision: string): Promise<IsolatedArtifacts>;
344
+ //#endregion
345
+ export { type ArtifactStore, EXECUTION_ROOT_RECORDS_DIRNAME, type ExecutionRootLiveness, type InProcessProviderDeps, type IsolatedArtifacts, type IssuedExecutionRoot, ORPHAN_WORKTREE_MAX_AGE_MS, type OrphanWorktreeSweepReport, PERSONA_CONTRIBUTION_KEY, type PersonaCompilation, type PersonaDeclaration, type PersonaManifestLookup, type PersonaResolution, type PersonaResolver, type RestoredExecutionRoot, SUBAGENT_ARTIFACTS_DIRNAME, SUBAGENT_WORKTREES_DIRNAME, type SessionClaimOutcome, Subagent, type SubagentComponentOptions, type SubagentControl, SubagentControlImpl, type SubagentControlOptions, SubagentDelegationError, type SubagentWorkspaceOptions, type SubagentWorkspaceRoots, collectIsolatedArtifacts, compilePersona, createArtifactStore, createInProcessProvider, createManifestPersonaResolver, createSubagentTool, createSubagentWorkspaceRoots, executionRootLiveness, personaDeclarationOf, personaDeclarationOfManifest, personaRefsOfManifest, personasOfManifest, resolvePersona, sweepOrphanWorktrees };