@yandy0725/pi-subagents 0.6.0 → 0.8.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 +39 -13
- package/README.zh.md +37 -11
- package/package.json +4 -4
- package/src/config/custom-agents.ts +1 -0
- package/src/config/invocation-config.ts +5 -9
- package/src/config/model-tiers.ts +12 -55
- package/src/index.ts +4 -3
- package/src/lifecycle/create-subagent-session.ts +37 -16
- package/src/lifecycle/parent-snapshot.ts +0 -3
- package/src/lifecycle/subagent-manager.ts +3 -0
- package/src/lifecycle/subagent-session.ts +28 -0
- package/src/lifecycle/subagent.ts +51 -1
- package/src/lifecycle/turn-limits.ts +9 -2
- package/src/observation/notification.ts +1 -1
- package/src/service/service-adapter.ts +4 -0
- package/src/service/service.ts +2 -0
- package/src/session/prompts.ts +53 -56
- package/src/session/session-config.ts +14 -8
- package/src/settings.ts +52 -6
- package/src/tools/agent-tool.ts +20 -14
- package/src/tools/background-spawner.ts +1 -0
- package/src/tools/foreground-runner.ts +1 -0
- package/src/tools/helpers.ts +1 -1
- package/src/tools/result-renderer.ts +1 -1
- package/src/tools/spawn-config.ts +7 -21
- package/src/types.ts +4 -1
- package/src/ui/display.ts +3 -2
- package/src/ui/subagents-settings.ts +17 -0
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
import type { Model } from "@earendil-works/pi-ai";
|
|
11
11
|
import type { AgentTypeRegistry } from "../config/agent-types";
|
|
12
12
|
import { resolveAgentInvocationConfig } from "../config/invocation-config";
|
|
13
|
-
import {
|
|
14
|
-
import { normalizeMaxTurns } from "../lifecycle/turn-limits";
|
|
13
|
+
import { normalizeMaxTurns, normalizeTimeoutSeconds } from "../lifecycle/turn-limits";
|
|
15
14
|
import { resolveInvocationModel } from "../session/model-resolver";
|
|
16
15
|
import type { AgentInvocation, SubagentType, ThinkingLevel } from "../types";
|
|
17
16
|
import { type AgentDetails, buildInvocationTags, getDisplayName, getPromptModeLabel } from "../ui/display";
|
|
@@ -47,6 +46,7 @@ export interface SpawnExecution {
|
|
|
47
46
|
description: string;
|
|
48
47
|
model: Model<any> | undefined;
|
|
49
48
|
effectiveMaxTurns: number | undefined;
|
|
49
|
+
effectiveTimeoutSeconds: number | undefined;
|
|
50
50
|
thinking: ThinkingLevel | undefined;
|
|
51
51
|
inheritContext: boolean;
|
|
52
52
|
runInBackground: boolean;
|
|
@@ -82,7 +82,7 @@ export function resolveSpawnConfig(
|
|
|
82
82
|
params: Record<string, unknown>,
|
|
83
83
|
registry: AgentTypeRegistry,
|
|
84
84
|
modelInfo: ModelInfo,
|
|
85
|
-
settings: { readonly defaultMaxTurns: number | undefined; readonly
|
|
85
|
+
settings: { readonly defaultMaxTurns: number | undefined; readonly defaultTimeoutSeconds: number | undefined },
|
|
86
86
|
): ResolvedSpawnConfig | SpawnConfigError {
|
|
87
87
|
const rawType = params.subagent_type as SubagentType;
|
|
88
88
|
const resolved = registry.resolveType(rawType);
|
|
@@ -97,26 +97,9 @@ export function resolveSpawnConfig(
|
|
|
97
97
|
|
|
98
98
|
const displayName = getDisplayName(subagentType, registry);
|
|
99
99
|
|
|
100
|
-
// `model` and `model_tier` are two ways to express the same choice — never both.
|
|
101
|
-
const tierInput = params.model_tier;
|
|
102
|
-
if (params.model != null && tierInput != null) {
|
|
103
|
-
return { error: 'Specify either "model" or "model_tier" (capability tier), not both.' };
|
|
104
|
-
}
|
|
105
|
-
|
|
106
100
|
// Merge agent config defaults with tool-call params
|
|
107
101
|
const customConfig = registry.resolveAgentConfig(subagentType);
|
|
108
|
-
|
|
109
|
-
// A model pinned by the agent type wins over tool-call params, so the tier is
|
|
110
|
-
// only resolved when it can actually apply (mirrors how a locked config model
|
|
111
|
-
// makes an unresolvable `model` param a silent no-op).
|
|
112
|
-
let tierModel: string | undefined;
|
|
113
|
-
if (tierInput != null && customConfig?.model == null) {
|
|
114
|
-
const tierResolution = resolveModelTier(tierInput, settings.modelTiers);
|
|
115
|
-
if (tierResolution.error) return { error: tierResolution.error };
|
|
116
|
-
tierModel = tierResolution.model;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const resolvedConfig = resolveAgentInvocationConfig(customConfig, params, tierModel);
|
|
102
|
+
const resolvedConfig = resolveAgentInvocationConfig(customConfig, params);
|
|
120
103
|
|
|
121
104
|
// Resolve model
|
|
122
105
|
const resolution = resolveInvocationModel(
|
|
@@ -136,11 +119,13 @@ export function resolveSpawnConfig(
|
|
|
136
119
|
const modelName = resolveModelName(model ?? modelInfo.parentModel);
|
|
137
120
|
|
|
138
121
|
const effectiveMaxTurns = normalizeMaxTurns(resolvedConfig.maxTurns ?? settings.defaultMaxTurns);
|
|
122
|
+
const effectiveTimeoutSeconds = normalizeTimeoutSeconds(resolvedConfig.timeout ?? settings.defaultTimeoutSeconds);
|
|
139
123
|
|
|
140
124
|
const agentInvocation: AgentInvocation = {
|
|
141
125
|
modelName,
|
|
142
126
|
thinking,
|
|
143
127
|
maxTurns: normalizeMaxTurns(resolvedConfig.maxTurns),
|
|
128
|
+
timeout: normalizeTimeoutSeconds(resolvedConfig.timeout),
|
|
144
129
|
inheritContext,
|
|
145
130
|
runInBackground,
|
|
146
131
|
};
|
|
@@ -164,6 +149,7 @@ export function resolveSpawnConfig(
|
|
|
164
149
|
description: params.description as string,
|
|
165
150
|
model,
|
|
166
151
|
effectiveMaxTurns,
|
|
152
|
+
effectiveTimeoutSeconds,
|
|
167
153
|
thinking,
|
|
168
154
|
inheritContext,
|
|
169
155
|
runInBackground,
|
package/src/types.ts
CHANGED
|
@@ -50,6 +50,8 @@ export interface AgentConfig extends AgentIdentity, AgentPromptConfig {
|
|
|
50
50
|
model?: string;
|
|
51
51
|
thinking?: ThinkingLevel;
|
|
52
52
|
maxTurns?: number;
|
|
53
|
+
/** Wall-clock timeout in seconds; 0 = unlimited. */
|
|
54
|
+
timeout?: number;
|
|
53
55
|
/** Default for spawn: fork parent conversation. undefined = caller decides. */
|
|
54
56
|
inheritContext?: boolean;
|
|
55
57
|
/** Default for spawn: run in background. undefined = caller decides. */
|
|
@@ -67,6 +69,8 @@ export interface AgentInvocation {
|
|
|
67
69
|
modelName?: string;
|
|
68
70
|
thinking?: ThinkingLevel;
|
|
69
71
|
maxTurns?: number;
|
|
72
|
+
/** Normalized wall-clock timeout in seconds (display value; undefined = unlimited). */
|
|
73
|
+
timeout?: number;
|
|
70
74
|
inheritContext?: boolean;
|
|
71
75
|
runInBackground?: boolean;
|
|
72
76
|
}
|
|
@@ -83,7 +87,6 @@ export interface SessionContext {
|
|
|
83
87
|
readonly cwd: string;
|
|
84
88
|
readonly model: unknown;
|
|
85
89
|
readonly modelRegistry: ModelRegistry | undefined;
|
|
86
|
-
getSystemPrompt(): string;
|
|
87
90
|
readonly sessionManager: {
|
|
88
91
|
getSessionFile(): string | undefined;
|
|
89
92
|
getSessionId(): string;
|
package/src/ui/display.ts
CHANGED
|
@@ -117,10 +117,10 @@ export function getDisplayName(type: SubagentType, registry: AgentConfigLookup):
|
|
|
117
117
|
return config.displayName ?? config.name;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
/** Short label for prompt mode: "
|
|
120
|
+
/** Short label for prompt mode: "append" for append, nothing for replace (the default). */
|
|
121
121
|
export function getPromptModeLabel(type: SubagentType, registry: AgentConfigLookup): string | undefined {
|
|
122
122
|
const config = registry.resolveAgentConfig(type);
|
|
123
|
-
return config.promptMode === "append" ? "
|
|
123
|
+
return config.promptMode === "append" ? "append" : undefined;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
/** Mode label is not included — callers add it where they want it. */
|
|
@@ -131,6 +131,7 @@ export function buildInvocationTags(invocation: AgentInvocation | undefined): {
|
|
|
131
131
|
if (invocation.inheritContext) tags.push("inherit context");
|
|
132
132
|
if (invocation.runInBackground) tags.push("background");
|
|
133
133
|
if (invocation.maxTurns != null) tags.push(`max turns: ${invocation.maxTurns}`);
|
|
134
|
+
if (invocation.timeout != null) tags.push(`timeout: ${invocation.timeout}s`);
|
|
134
135
|
return { modelName: invocation.modelName, tags };
|
|
135
136
|
}
|
|
136
137
|
|
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
export interface SubagentsSettingsManager {
|
|
5
5
|
readonly maxConcurrent: number;
|
|
6
6
|
readonly defaultMaxTurns: number | undefined;
|
|
7
|
+
readonly defaultTimeoutSeconds: number | undefined;
|
|
7
8
|
readonly graceTurns: number;
|
|
8
9
|
applyMaxConcurrent(n: number): { message: string; level: "info" | "warning" };
|
|
9
10
|
applyDefaultMaxTurns(n: number): { message: string; level: "info" | "warning" };
|
|
11
|
+
applyDefaultTimeoutSeconds(n: number): { message: string; level: "info" | "warning" };
|
|
10
12
|
applyGraceTurns(n: number): { message: string; level: "info" | "warning" };
|
|
11
13
|
}
|
|
12
14
|
|
|
@@ -32,6 +34,7 @@ export class SubagentsSettingsHandler {
|
|
|
32
34
|
const choice = await ui.select("Settings", [
|
|
33
35
|
`Max concurrency (current: ${this.settings.maxConcurrent})`,
|
|
34
36
|
`Default max turns (current: ${this.settings.defaultMaxTurns ?? "unlimited"})`,
|
|
37
|
+
`Default timeout (current: ${this.settings.defaultTimeoutSeconds != null ? `${this.settings.defaultTimeoutSeconds}s` : "unlimited"})`,
|
|
35
38
|
`Grace turns (current: ${this.settings.graceTurns})`,
|
|
36
39
|
]);
|
|
37
40
|
if (!choice) return;
|
|
@@ -61,6 +64,20 @@ export class SubagentsSettingsHandler {
|
|
|
61
64
|
ui.notify("Must be 0 (unlimited) or a positive integer.", "warning");
|
|
62
65
|
}
|
|
63
66
|
}
|
|
67
|
+
} else if (choice.startsWith("Default timeout")) {
|
|
68
|
+
const val = await ui.input(
|
|
69
|
+
"Default timeout in seconds (0 = unlimited)",
|
|
70
|
+
String(this.settings.defaultTimeoutSeconds ?? 0),
|
|
71
|
+
);
|
|
72
|
+
if (val) {
|
|
73
|
+
const n = parseInt(val, 10);
|
|
74
|
+
if (n >= 0) {
|
|
75
|
+
const toast = this.settings.applyDefaultTimeoutSeconds(n);
|
|
76
|
+
ui.notify(toast.message, toast.level);
|
|
77
|
+
} else {
|
|
78
|
+
ui.notify("Must be 0 (unlimited) or a positive integer.", "warning");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
64
81
|
} else if (choice.startsWith("Grace turns")) {
|
|
65
82
|
const val = await ui.input("Grace turns after wrap-up steer", String(this.settings.graceTurns));
|
|
66
83
|
if (val) {
|