@oai404iao/pi-subagent 0.4.0-alpha.0 → 0.4.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/src/task-path.ts CHANGED
@@ -4,7 +4,6 @@ import type {
4
4
  } from "./types.ts";
5
5
 
6
6
  export const ROOT_TASK_PATH = "/root";
7
- export const LEGACY_TASK_NAMESPACE = ".legacy";
8
7
  export const MAX_TASK_NAME_LENGTH = 64;
9
8
  export const MAX_TASK_PATH_LENGTH = 4096;
10
9
 
@@ -34,7 +33,7 @@ export function validateTaskName(value: string): string {
34
33
  "task_name must contain 1-64 lowercase ASCII letters, digits, hyphens, or underscores and start with a letter or digit",
35
34
  );
36
35
  }
37
- if (value === "root" || value === LEGACY_TASK_NAMESPACE) {
36
+ if (value === "root") {
38
37
  throw new Error(`task_name "${value}" is reserved`);
39
38
  }
40
39
  return value;
@@ -44,21 +43,7 @@ export function validateTaskPath(path: string): string {
44
43
  if (path === ROOT_TASK_PATH) return path;
45
44
  const segments = pathSegments(path);
46
45
  for (let index = 1; index < segments.length; index++) {
47
- const segment = segments[index]!;
48
- if (
49
- index === 1
50
- && segment === LEGACY_TASK_NAMESPACE
51
- ) {
52
- const legacyId = segments[index + 1];
53
- if (!legacyId || !AGENT_ID_PATTERN.test(legacyId)) {
54
- throw new Error(
55
- `legacy task paths must use ${ROOT_TASK_PATH}/${LEGACY_TASK_NAMESPACE}/<agent-id>`,
56
- );
57
- }
58
- index++;
59
- continue;
60
- }
61
- validateTaskName(segment);
46
+ validateTaskName(segments[index]!);
62
47
  }
63
48
  return path;
64
49
  }
@@ -70,29 +55,16 @@ export function taskPath(parentPath: string, name: string): string {
70
55
  return validateTaskPath(path);
71
56
  }
72
57
 
73
- export function legacyTaskPath(agentId: string): string {
74
- if (!AGENT_ID_PATTERN.test(agentId)) {
75
- throw new Error("legacy task path requires a UUIDv7 agent id");
76
- }
77
- return `${ROOT_TASK_PATH}/${LEGACY_TASK_NAMESPACE}/${agentId}`;
78
- }
79
-
80
58
  export function descriptorTaskPath(
81
59
  descriptor: SubagentDescriptor,
82
60
  ): string {
83
- return descriptor.version === 3
84
- ? descriptor.task.path
85
- : legacyTaskPath(descriptor.agentId);
61
+ return descriptor.task.path;
86
62
  }
87
63
 
88
64
  export function descriptorTask(
89
65
  descriptor: SubagentDescriptor,
90
66
  ): SubagentTask {
91
- if (descriptor.version === 3) return { ...descriptor.task };
92
- return {
93
- name: descriptor.agentId,
94
- path: legacyTaskPath(descriptor.agentId),
95
- };
67
+ return { ...descriptor.task };
96
68
  }
97
69
 
98
70
  export function validateDescriptorTask(task: SubagentTask): SubagentTask {
@@ -114,10 +86,7 @@ export function slugTaskName(value: string): string {
114
86
  .replace(/^[-_]+|[-_]+$/g, "")
115
87
  .slice(0, MAX_TASK_NAME_LENGTH)
116
88
  .replace(/[-_]+$/g, "");
117
- const candidate =
118
- !normalized || normalized === "root" || normalized === LEGACY_TASK_NAMESPACE
119
- ? "task"
120
- : normalized;
89
+ const candidate = !normalized || normalized === "root" ? "task" : normalized;
121
90
  return validateTaskName(candidate);
122
91
  }
123
92
 
@@ -165,17 +134,6 @@ export function resolveTaskPath(
165
134
  segments.pop();
166
135
  continue;
167
136
  }
168
- if (segment === LEGACY_TASK_NAMESPACE) {
169
- segments.push(segment);
170
- continue;
171
- }
172
- if (
173
- segments.at(-1) === LEGACY_TASK_NAMESPACE
174
- && AGENT_ID_PATTERN.test(segment)
175
- ) {
176
- segments.push(segment);
177
- continue;
178
- }
179
137
  validateTaskName(segment);
180
138
  segments.push(segment);
181
139
  }
package/src/types.ts CHANGED
@@ -1,13 +1,17 @@
1
1
  import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
2
2
  import type { Usage } from "@earendil-works/pi-ai";
3
3
 
4
+ /** Current on-disk subagent descriptor version. */
5
+ export const DESCRIPTOR_VERSION = 4;
6
+
4
7
  export type AgentScope = "user" | "project" | "both";
5
8
  /** Sources that runtime discovery is allowed to activate. */
6
9
  export type AgentSource = "user" | "project";
7
- /** `bundled` is retained only for reading descriptors written by older releases. */
8
- export type AgentSnapshotSource = AgentSource | "bundled";
9
- export type ReportDelivery = "wakeup" | "quiet";
10
- export type BackgroundProtocol = "legacy" | "mailbox-v2";
10
+ /**
11
+ * Single execution mode. `foreground` waits for every child's final answer;
12
+ * `background` starts durable mailbox children.
13
+ */
14
+ export type RuntimeMode = "foreground" | "background";
11
15
  export type SubagentMode = "one-shot" | "continuable";
12
16
  export type SubagentProviderName = "spawn" | "fork";
13
17
  export type SubagentStopReason = "completed" | "aborted" | "error" | "max-tokens";
@@ -24,12 +28,9 @@ export interface SubagentTask {
24
28
  export interface SubagentSettings {
25
29
  agentScope: AgentScope;
26
30
  maxDepth: number;
27
- enableRunInBackground: boolean;
28
- defaultBackground: boolean;
31
+ runtimeMode: RuntimeMode;
29
32
  maxConcurrentBackgroundRuns: number;
30
33
  maxIdleRuntimes: number;
31
- backgroundProtocol?: BackgroundProtocol;
32
- reportDelivery: ReportDelivery;
33
34
  inheritExtensions: boolean;
34
35
  openAIIdentity: boolean;
35
36
  maxOutputBytes: number;
@@ -53,7 +54,7 @@ export interface AgentSnapshot {
53
54
  model?: string;
54
55
  thinking?: ThinkingLevel;
55
56
  systemPrompt: string;
56
- source: AgentSnapshotSource;
57
+ source: AgentSource;
57
58
  }
58
59
 
59
60
  export interface ResolvedModel {
@@ -64,12 +65,9 @@ export interface ResolvedModel {
64
65
  export interface SubagentRuntimeSnapshot {
65
66
  agentScope: AgentScope;
66
67
  maxDepth: number;
67
- enableRunInBackground: boolean;
68
- defaultBackground: boolean;
68
+ runtimeMode: RuntimeMode;
69
69
  maxConcurrentBackgroundRuns: number;
70
70
  maxIdleRuntimes: number;
71
- backgroundProtocol: BackgroundProtocol;
72
- reportDelivery: ReportDelivery;
73
71
  inheritExtensions: boolean;
74
72
  openAIIdentity: boolean;
75
73
  maxOutputBytes: number;
@@ -96,20 +94,12 @@ interface SubagentDescriptorBase {
96
94
  runtime: SubagentRuntimeSnapshot;
97
95
  }
98
96
 
99
- export interface SubagentDescriptorV2 extends SubagentDescriptorBase {
100
- version: 2;
101
- }
102
-
103
- export interface SubagentDescriptorV3 extends SubagentDescriptorBase {
104
- version: 3;
97
+ export interface SubagentDescriptor extends SubagentDescriptorBase {
98
+ version: typeof DESCRIPTOR_VERSION;
105
99
  task: SubagentTask;
106
100
  context: ContextInheritance;
107
101
  }
108
102
 
109
- export type SubagentDescriptor =
110
- | SubagentDescriptorV2
111
- | SubagentDescriptorV3;
112
-
113
103
  export interface SubagentUsage extends Usage {
114
104
  turns: number;
115
105
  }
@@ -192,11 +182,10 @@ export interface CatalogDiagnostic {
192
182
  export type CatalogEntry = CatalogChild | CatalogDiagnostic;
193
183
 
194
184
  export interface ParentMessageDetails {
195
- kind: "report" | "settled";
185
+ kind: "report";
196
186
  childAgentId: string;
197
187
  taskPath?: string;
198
188
  label: string;
199
- stopReason?: SubagentStopReason;
200
189
  truncated?: boolean;
201
190
  }
202
191