@ian-pascoe/pi-minimal-subagents 0.1.0 → 0.2.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/README.md +77 -9
- package/package.json +6 -6
- package/src/minimal-subagents-capabilities.ts +8 -8
- package/src/minimal-subagents-config.ts +222 -73
- package/src/minimal-subagents-context.ts +7 -1
- package/src/minimal-subagents-coordinator.ts +943 -116
- package/src/minimal-subagents-delivery-ledger.ts +529 -0
- package/src/minimal-subagents-extension.ts +382 -64
- package/src/minimal-subagents-fork-lifecycle.ts +22 -12
- package/src/minimal-subagents-message-envelope.ts +20 -0
- package/src/minimal-subagents-registry-wire.ts +269 -0
- package/src/minimal-subagents-registry.ts +1505 -132
- package/src/minimal-subagents-render-contract.ts +301 -0
- package/src/minimal-subagents-rendering.ts +513 -372
- package/src/minimal-subagents-session-wire.ts +42 -0
- package/src/minimal-subagents-sessions.ts +437 -101
- package/src/minimal-subagents-shutdown.ts +1 -1
- package/src/minimal-subagents-tool-schemas.ts +21 -7
- package/src/minimal-subagents-tools.ts +75 -25
- package/src/minimal-subagents-types.ts +76 -21
- package/src/minimal-subagents-ui.ts +214 -23
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import type { JsonValue } from "@earendil-works/pi-ai";
|
|
2
|
+
import { Type, type Static } from "typebox";
|
|
3
|
+
|
|
4
|
+
/** Establishes Pi's recursive JSON owner type before Registry envelope parsing. */
|
|
5
|
+
export const RegistryJsonValueWireSchema = Type.Unsafe<JsonValue>({});
|
|
6
|
+
|
|
7
|
+
const NonnegativeNumberSchema = Type.Number({ minimum: 0 });
|
|
8
|
+
const NonEmptyStringSchema = Type.String({ minLength: 1 });
|
|
9
|
+
const TurnStatusSchema = Type.Union([
|
|
10
|
+
Type.Literal("completed"),
|
|
11
|
+
Type.Literal("failed"),
|
|
12
|
+
Type.Literal("cancelled"),
|
|
13
|
+
Type.Literal("interrupted"),
|
|
14
|
+
]);
|
|
15
|
+
const ThinkingLevelSchema = Type.Union([
|
|
16
|
+
Type.Literal("off"),
|
|
17
|
+
Type.Literal("minimal"),
|
|
18
|
+
Type.Literal("low"),
|
|
19
|
+
Type.Literal("medium"),
|
|
20
|
+
Type.Literal("high"),
|
|
21
|
+
Type.Literal("xhigh"),
|
|
22
|
+
Type.Literal("max"),
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
/** Parses persisted model usage without coercion. */
|
|
26
|
+
export const RegistryUsageWireSchema = Type.Object({
|
|
27
|
+
input: NonnegativeNumberSchema,
|
|
28
|
+
output: NonnegativeNumberSchema,
|
|
29
|
+
cacheRead: NonnegativeNumberSchema,
|
|
30
|
+
cacheWrite: NonnegativeNumberSchema,
|
|
31
|
+
totalTokens: NonnegativeNumberSchema,
|
|
32
|
+
cacheWrite1h: Type.Optional(NonnegativeNumberSchema),
|
|
33
|
+
reasoning: Type.Optional(NonnegativeNumberSchema),
|
|
34
|
+
cost: Type.Object({
|
|
35
|
+
input: NonnegativeNumberSchema,
|
|
36
|
+
output: NonnegativeNumberSchema,
|
|
37
|
+
cacheRead: NonnegativeNumberSchema,
|
|
38
|
+
cacheWrite: NonnegativeNumberSchema,
|
|
39
|
+
total: NonnegativeNumberSchema,
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/** Parses persisted terminal turn results without coercion. */
|
|
44
|
+
export const RegistryTurnResultWireSchema = Type.Object({
|
|
45
|
+
agent_id: NonEmptyStringSchema,
|
|
46
|
+
turn_id: NonEmptyStringSchema,
|
|
47
|
+
status: TurnStatusSchema,
|
|
48
|
+
output: Type.String(),
|
|
49
|
+
error: Type.Optional(Type.String()),
|
|
50
|
+
usage: Type.Optional(RegistryUsageWireSchema),
|
|
51
|
+
elapsed_ms: Type.Optional(NonnegativeNumberSchema),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const ToolSelectionWireSchema = Type.Union([
|
|
55
|
+
Type.Literal("none"),
|
|
56
|
+
Type.Literal("read"),
|
|
57
|
+
Type.Literal("modify"),
|
|
58
|
+
Type.Array(NonEmptyStringSchema),
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
/** Parses persisted immutable Launch Contracts without coercion. */
|
|
62
|
+
export const RegistryLaunchContractWireSchema = Type.Object({
|
|
63
|
+
session_context: Type.Union([
|
|
64
|
+
Type.Literal("inherit"),
|
|
65
|
+
Type.Literal("compact"),
|
|
66
|
+
Type.Literal("omit"),
|
|
67
|
+
]),
|
|
68
|
+
project_context: Type.Union([Type.Literal("inherit"), Type.Literal("omit")]),
|
|
69
|
+
model: Type.String(),
|
|
70
|
+
thinking_level: ThinkingLevelSchema,
|
|
71
|
+
tools: Type.Optional(ToolSelectionWireSchema),
|
|
72
|
+
ordinary_tools: Type.Array(NonEmptyStringSchema),
|
|
73
|
+
delegation: Type.Optional(Type.Union([Type.Literal("none"), Type.Literal("fanout")])),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
/** Parses the recent-message projection stored on one agent. */
|
|
77
|
+
export const RegistryRecentMessageWireSchema = Type.Object({
|
|
78
|
+
source_agent_id: NonEmptyStringSchema,
|
|
79
|
+
turn_id: NonEmptyStringSchema,
|
|
80
|
+
content: Type.String(),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/** Parses one persisted Registry agent without applying cross-field semantics. */
|
|
84
|
+
export const RegistryAgentWireSchema = Type.Object({
|
|
85
|
+
agent_id: NonEmptyStringSchema,
|
|
86
|
+
friendly_id: NonEmptyStringSchema,
|
|
87
|
+
parent_id: NonEmptyStringSchema,
|
|
88
|
+
created_at: Type.String(),
|
|
89
|
+
task: Type.Optional(Type.String()),
|
|
90
|
+
latest_activity_at: Type.Optional(Type.String()),
|
|
91
|
+
spawn_entry_id: NonEmptyStringSchema,
|
|
92
|
+
session_file: Type.Optional(NonEmptyStringSchema),
|
|
93
|
+
session_id: Type.Optional(NonEmptyStringSchema),
|
|
94
|
+
session_leaf_id: Type.Optional(NonEmptyStringSchema),
|
|
95
|
+
clone_error: Type.Optional(NonEmptyStringSchema),
|
|
96
|
+
launch_contract: RegistryLaunchContractWireSchema,
|
|
97
|
+
capability_ceiling: Type.Array(NonEmptyStringSchema),
|
|
98
|
+
active_turn_id: Type.Optional(NonEmptyStringSchema),
|
|
99
|
+
active_turn_started_at: Type.Optional(Type.String()),
|
|
100
|
+
latest_result: Type.Optional(RegistryTurnResultWireSchema),
|
|
101
|
+
availability: Type.Union([Type.Literal("available"), Type.Literal("unavailable")]),
|
|
102
|
+
missing_dependencies: Type.Array(NonEmptyStringSchema),
|
|
103
|
+
unavailable_reason: Type.Optional(NonEmptyStringSchema),
|
|
104
|
+
recent_messages: Type.Array(RegistryRecentMessageWireSchema),
|
|
105
|
+
deleted: Type.Optional(Type.Boolean()),
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
/** Parses one terminal Delivery Ledger item without applying ownership semantics. */
|
|
109
|
+
export const RegistryTerminalDeliveryWireSchema = Type.Object({
|
|
110
|
+
source_agent_id: NonEmptyStringSchema,
|
|
111
|
+
source_turn_id: NonEmptyStringSchema,
|
|
112
|
+
destination_agent_id: NonEmptyStringSchema,
|
|
113
|
+
path: Type.Union([Type.Literal("wait"), Type.Literal("message")]),
|
|
114
|
+
settled: Type.Boolean(),
|
|
115
|
+
sequence: Type.Optional(Type.Number()),
|
|
116
|
+
result: Type.Optional(RegistryTurnResultWireSchema),
|
|
117
|
+
error: Type.Optional(Type.String()),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const CoordinatorMessageDetailsWireSchema = Type.Object({
|
|
121
|
+
source_agent_id: NonEmptyStringSchema,
|
|
122
|
+
destination_agent_id: Type.Optional(NonEmptyStringSchema),
|
|
123
|
+
source_turn_id: NonEmptyStringSchema,
|
|
124
|
+
message_id: NonEmptyStringSchema,
|
|
125
|
+
delivery_id: Type.Optional(NonEmptyStringSchema),
|
|
126
|
+
status: Type.Optional(TurnStatusSchema),
|
|
127
|
+
elapsed_ms: Type.Optional(NonnegativeNumberSchema),
|
|
128
|
+
usage: Type.Optional(RegistryUsageWireSchema),
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
/** Parses the persisted Coordination Message envelope. */
|
|
132
|
+
export const RegistryCoordinatorMessageWireSchema = Type.Object({
|
|
133
|
+
customType: Type.Union([
|
|
134
|
+
Type.Literal("minimal-subagents.message"),
|
|
135
|
+
Type.Literal("minimal-subagents.result"),
|
|
136
|
+
]),
|
|
137
|
+
content: Type.String(),
|
|
138
|
+
details: CoordinatorMessageDetailsWireSchema,
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
/** Parses one Coordination Message Delivery Ledger item. */
|
|
142
|
+
export const RegistryCoordinationDeliveryWireSchema = Type.Object({
|
|
143
|
+
delivery_id: NonEmptyStringSchema,
|
|
144
|
+
sequence: Type.Number(),
|
|
145
|
+
destination_agent_id: NonEmptyStringSchema,
|
|
146
|
+
path: Type.Union([Type.Literal("wait"), Type.Literal("message")]),
|
|
147
|
+
settled: Type.Boolean(),
|
|
148
|
+
message: RegistryCoordinatorMessageWireSchema,
|
|
149
|
+
error: Type.Optional(Type.String()),
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
/** Parses a persisted Registry checkpoint before semantic validation. */
|
|
153
|
+
export const RegistrySnapshotWireSchema = Type.Object({
|
|
154
|
+
agents: Type.Array(RegistryAgentWireSchema),
|
|
155
|
+
tombstones: Type.Array(NonEmptyStringSchema),
|
|
156
|
+
deliveries: Type.Array(RegistryTerminalDeliveryWireSchema),
|
|
157
|
+
coordination_deliveries: Type.Optional(Type.Array(RegistryCoordinationDeliveryWireSchema)),
|
|
158
|
+
wait_claimed_turns: Type.Optional(Type.Array(NonEmptyStringSchema)),
|
|
159
|
+
next_delivery_sequence: Type.Optional(Type.Number()),
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
/** Parses loose envelope fields so diagnostics retain their stable ownership. */
|
|
163
|
+
export const RegistryLooseEnvelopeWireSchema = Type.Object({
|
|
164
|
+
version: Type.Unknown(),
|
|
165
|
+
root_session_id: NonEmptyStringSchema,
|
|
166
|
+
timestamp: Type.String(),
|
|
167
|
+
event: Type.Unknown(),
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
/** Parses the event discriminant independently from its payload. */
|
|
171
|
+
export const RegistryEventDiscriminantWireSchema = Type.Object({
|
|
172
|
+
event: Type.String(),
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
/** Parses the common Registry envelope fields before event-specific parsing. */
|
|
176
|
+
export const RegistryEnvelopeWireSchema = Type.Object({
|
|
177
|
+
version: Type.Union([Type.Literal(1), Type.Literal(2)]),
|
|
178
|
+
root_session_id: NonEmptyStringSchema,
|
|
179
|
+
timestamp: Type.String(),
|
|
180
|
+
event: Type.String(),
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
/** Parses the root identity early enough to ignore foreign-root records silently. */
|
|
184
|
+
export const RegistryRootProbeWireSchema = Type.Object({
|
|
185
|
+
root_session_id: Type.String(),
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
/** Parses the checkpoint event payload. */
|
|
189
|
+
export const RegistryCheckpointEventWireSchema = Type.Object({
|
|
190
|
+
snapshot: RegistrySnapshotWireSchema,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
/** Parses the agent-created event payload. */
|
|
194
|
+
export const RegistryAgentCreatedEventWireSchema = Type.Object({
|
|
195
|
+
agent: RegistryAgentWireSchema,
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
/** Parses the turn-started event payload. */
|
|
199
|
+
export const RegistryTurnStartedEventWireSchema = Type.Object({
|
|
200
|
+
agent_id: NonEmptyStringSchema,
|
|
201
|
+
turn_id: NonEmptyStringSchema,
|
|
202
|
+
started_at: Type.String(),
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
/** Parses the turn-settled event payload. */
|
|
206
|
+
export const RegistryTurnSettledEventWireSchema = Type.Object({
|
|
207
|
+
result: RegistryTurnResultWireSchema,
|
|
208
|
+
settled_at: Type.Optional(Type.String()),
|
|
209
|
+
session_leaf_id: Type.Optional(NonEmptyStringSchema),
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
/** Parses the terminal delivery-pending event payload. */
|
|
213
|
+
export const RegistryDeliveryPendingEventWireSchema = Type.Object({
|
|
214
|
+
delivery: RegistryTerminalDeliveryWireSchema,
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
/** Parses the terminal delivery-settled event payload. */
|
|
218
|
+
export const RegistryDeliverySettledEventWireSchema = Type.Object({
|
|
219
|
+
source_agent_id: NonEmptyStringSchema,
|
|
220
|
+
source_turn_id: NonEmptyStringSchema,
|
|
221
|
+
error: Type.Optional(Type.String()),
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
/** Parses the terminal delivery-pruned event payload. */
|
|
225
|
+
export const RegistryDeliveryPrunedEventWireSchema = Type.Object({
|
|
226
|
+
source_agent_id: NonEmptyStringSchema,
|
|
227
|
+
source_turn_id: NonEmptyStringSchema,
|
|
228
|
+
reason: Type.Literal("retention-limit"),
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
/** Parses the Coordination Message delivery-pending event payload. */
|
|
232
|
+
export const RegistryCoordinationPendingEventWireSchema = Type.Object({
|
|
233
|
+
delivery: RegistryCoordinationDeliveryWireSchema,
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
/** Parses the Coordination Message delivery-settled event payload. */
|
|
237
|
+
export const RegistryCoordinationSettledEventWireSchema = Type.Object({
|
|
238
|
+
delivery_id: NonEmptyStringSchema,
|
|
239
|
+
error: Type.Optional(Type.String()),
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
/** Parses the wait-claim and wait-release event payload. */
|
|
243
|
+
export const RegistryDeliveryTurnEventWireSchema = Type.Object({
|
|
244
|
+
source_agent_id: NonEmptyStringSchema,
|
|
245
|
+
source_turn_id: NonEmptyStringSchema,
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
/** Parses the recent-message activity event payload. */
|
|
249
|
+
export const RegistryMessageRecordedEventWireSchema = Type.Object({
|
|
250
|
+
agent_id: NonEmptyStringSchema,
|
|
251
|
+
message: RegistryRecentMessageWireSchema,
|
|
252
|
+
recorded_at: Type.Optional(Type.String()),
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
/** Parses the subtree-deletion event payload. */
|
|
256
|
+
export const RegistryAgentDeletedEventWireSchema = Type.Object({
|
|
257
|
+
agent_ids: Type.Array(NonEmptyStringSchema),
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
export type RegistryAgentWire = Static<typeof RegistryAgentWireSchema>;
|
|
261
|
+
export type RegistryCoordinationDeliveryWire = Static<
|
|
262
|
+
typeof RegistryCoordinationDeliveryWireSchema
|
|
263
|
+
>;
|
|
264
|
+
export type RegistryCoordinatorMessageWire = Static<typeof RegistryCoordinatorMessageWireSchema>;
|
|
265
|
+
export type RegistryLaunchContractWire = Static<typeof RegistryLaunchContractWireSchema>;
|
|
266
|
+
export type RegistryRecentMessageWire = Static<typeof RegistryRecentMessageWireSchema>;
|
|
267
|
+
export type RegistrySnapshotWire = Static<typeof RegistrySnapshotWireSchema>;
|
|
268
|
+
export type RegistryTerminalDeliveryWire = Static<typeof RegistryTerminalDeliveryWireSchema>;
|
|
269
|
+
export type RegistryTurnResultWire = Static<typeof RegistryTurnResultWireSchema>;
|