@restranger/repi-subagents 0.0.0-stage → 0.0.1-92401bd
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 +284 -2
- package/package.json +41 -5
- package/src/agent-file.ts +297 -0
- package/src/agent-schema.ts +90 -0
- package/src/child-guard.ts +151 -0
- package/src/command.ts +255 -0
- package/src/default-agents.ts +409 -0
- package/src/discovery.ts +354 -0
- package/src/extensions.ts +119 -0
- package/src/fleet-ui.ts +617 -0
- package/src/format.ts +974 -0
- package/src/frontmatter.ts +302 -0
- package/src/index.ts +112 -0
- package/src/manager.ts +1192 -0
- package/src/model-resolver.ts +58 -0
- package/src/overrides.ts +693 -0
- package/src/plugin.ts +568 -0
- package/src/prompt.ts +184 -0
- package/src/registry.ts +71 -0
- package/src/session.ts +304 -0
- package/src/status-widget.ts +65 -0
- package/src/tool-policy.ts +77 -0
- package/src/tools.ts +554 -0
- package/src/types.ts +163 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/** Public data model for declarative subagents. */
|
|
2
|
+
|
|
3
|
+
import type { PluginDiagnostic, PluginDiagnosticLevel } from "@restranger/repi-lib";
|
|
4
|
+
|
|
5
|
+
export type AgentSource = "builtin" | "user" | "project";
|
|
6
|
+
|
|
7
|
+
export type AgentDiagnosticLevel = PluginDiagnosticLevel;
|
|
8
|
+
|
|
9
|
+
/** Same shape as every other plugin diagnostic; the file path is always known here. */
|
|
10
|
+
export interface AgentDiagnostic extends PluginDiagnostic {
|
|
11
|
+
readonly path: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** `undefined` = the default built-in tool set; `"*"` = every parent tool; `[]` = no tools. */
|
|
15
|
+
export type AgentToolSpec = readonly string[] | "*" | undefined;
|
|
16
|
+
|
|
17
|
+
export type AgentPromptMode = "append" | "replace";
|
|
18
|
+
|
|
19
|
+
export interface AgentDefinition {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly description: string;
|
|
22
|
+
/** Tool allowlist declared in frontmatter. */
|
|
23
|
+
readonly tools: AgentToolSpec;
|
|
24
|
+
readonly disallowedTools: readonly string[];
|
|
25
|
+
/** `inherit` (or absent) means the parent's model. */
|
|
26
|
+
readonly model?: string;
|
|
27
|
+
/** Fallback models to try in order if the primary model fails. */
|
|
28
|
+
readonly fallbackModels?: readonly string[];
|
|
29
|
+
readonly thinking?: string;
|
|
30
|
+
/** 0 or absent means unlimited; values below 2 are raised to 2 (one turn cannot answer). */
|
|
31
|
+
readonly maxTurns?: number;
|
|
32
|
+
readonly background?: boolean;
|
|
33
|
+
/** Whether the Markdown body is appended to Pi's prompt or replaces it. */
|
|
34
|
+
readonly promptMode: AgentPromptMode;
|
|
35
|
+
readonly color?: string;
|
|
36
|
+
/** Markdown body after the frontmatter. */
|
|
37
|
+
readonly systemPrompt: string;
|
|
38
|
+
readonly source: AgentSource;
|
|
39
|
+
readonly filePath: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface AgentScanResult {
|
|
43
|
+
readonly agents: readonly AgentDefinition[];
|
|
44
|
+
readonly diagnostics: readonly AgentDiagnostic[];
|
|
45
|
+
/** Directories that were scanned, in ascending priority order. */
|
|
46
|
+
readonly directories: readonly string[];
|
|
47
|
+
/** JSON override files that were read, lowest priority first. */
|
|
48
|
+
readonly configFiles?: readonly string[];
|
|
49
|
+
/** Maximum concurrent subagent runs configured via JSON override layers. */
|
|
50
|
+
readonly maxConcurrent?: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type SubagentRunStatus = "queued" | "running" | "completed" | "failed" | "aborted";
|
|
54
|
+
|
|
55
|
+
export interface SubagentUsage {
|
|
56
|
+
readonly input?: number;
|
|
57
|
+
readonly output?: number;
|
|
58
|
+
readonly total?: number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** One tool call (or a non-tool phase) worth showing in the widget and fleet inspector. */
|
|
62
|
+
export interface SubagentActivity {
|
|
63
|
+
/** Tool name, or `thinking` while the child is between tools. */
|
|
64
|
+
readonly tool: string;
|
|
65
|
+
/** Compact argument preview, such as a command or grep pattern. */
|
|
66
|
+
readonly detail?: string;
|
|
67
|
+
readonly at: number;
|
|
68
|
+
readonly error?: boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** One recorded tool execution step made by the child session. */
|
|
72
|
+
export interface SubagentStep {
|
|
73
|
+
readonly id: string;
|
|
74
|
+
readonly tool: string;
|
|
75
|
+
readonly detail?: string;
|
|
76
|
+
readonly startedAt: number;
|
|
77
|
+
readonly finishedAt?: number;
|
|
78
|
+
readonly durationMs?: number;
|
|
79
|
+
readonly isError?: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Immutable view of one run; safe to hand to tools and the widget. */
|
|
83
|
+
export interface SubagentRunSnapshot {
|
|
84
|
+
readonly id: string;
|
|
85
|
+
readonly agent: string;
|
|
86
|
+
readonly description: string;
|
|
87
|
+
readonly task: string;
|
|
88
|
+
readonly parentSessionId: string;
|
|
89
|
+
readonly cwd: string;
|
|
90
|
+
readonly status: SubagentRunStatus;
|
|
91
|
+
/** Current subagent phase while running: 'running', 'compacting' (manual), or 'auto-compacting'. */
|
|
92
|
+
readonly phase?: "running" | "compacting" | "auto-compacting";
|
|
93
|
+
readonly background: boolean;
|
|
94
|
+
readonly createdAt: number;
|
|
95
|
+
readonly startedAt?: number;
|
|
96
|
+
readonly finishedAt?: number;
|
|
97
|
+
/** The parent has already read this run's result, so the prompt stops asking for it. */
|
|
98
|
+
readonly collected?: boolean;
|
|
99
|
+
readonly result?: string;
|
|
100
|
+
readonly error?: string;
|
|
101
|
+
readonly turns: number;
|
|
102
|
+
readonly toolCalls: number;
|
|
103
|
+
readonly usage?: SubagentUsage;
|
|
104
|
+
readonly maxTurns?: number;
|
|
105
|
+
/** Color assigned to the agent (from frontmatter or auto-assigned palette). */
|
|
106
|
+
readonly color?: string;
|
|
107
|
+
/** Model identifier or display name the child ran on. */
|
|
108
|
+
readonly model?: string;
|
|
109
|
+
/** 1-based index of the model attempt this snapshot describes. */
|
|
110
|
+
readonly attempt?: number;
|
|
111
|
+
/** Total model attempts configured for this run (primary + fallbacks). */
|
|
112
|
+
readonly attempts?: number;
|
|
113
|
+
/** The harness stopped the child at its turn ceiling. */
|
|
114
|
+
readonly turnLimitReached?: boolean;
|
|
115
|
+
/** Non-fatal setup notes, such as requested tools the parent does not expose. */
|
|
116
|
+
readonly diagnostics?: readonly string[];
|
|
117
|
+
/** Latest tool/phase activity, for the status widget and fleet inspector. */
|
|
118
|
+
readonly activity?: SubagentActivity;
|
|
119
|
+
/** Small ring buffer of recent tool calls, oldest first. */
|
|
120
|
+
readonly recentActivity?: readonly SubagentActivity[];
|
|
121
|
+
/** Complete chronological list of child tool calls and steps. */
|
|
122
|
+
readonly steps?: readonly SubagentStep[];
|
|
123
|
+
/** Extension modules re-created for this child (source labels, not full paths). */
|
|
124
|
+
readonly extensions?: readonly string[];
|
|
125
|
+
/** Reason the model stopped generation: "end_turn", "stop_sequence", "length", "error", etc. */
|
|
126
|
+
readonly stopReason?: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Type guard to check if an unknown value is a valid SubagentRunSnapshot. */
|
|
130
|
+
export function isSubagentSnapshot(value: unknown): value is SubagentRunSnapshot {
|
|
131
|
+
return (
|
|
132
|
+
typeof value === "object" &&
|
|
133
|
+
value !== null &&
|
|
134
|
+
typeof (value as Partial<SubagentRunSnapshot>).agent === "string" &&
|
|
135
|
+
typeof (value as Partial<SubagentRunSnapshot>).status === "string"
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface SpawnSubagentRequest {
|
|
140
|
+
readonly agent: string;
|
|
141
|
+
readonly task: string;
|
|
142
|
+
readonly description?: string;
|
|
143
|
+
readonly background?: boolean;
|
|
144
|
+
readonly model?: string;
|
|
145
|
+
readonly fallbackModels?: readonly string[];
|
|
146
|
+
readonly maxTurns?: number;
|
|
147
|
+
readonly cwd: string;
|
|
148
|
+
readonly parentSessionId: string;
|
|
149
|
+
readonly parentModel?: unknown;
|
|
150
|
+
/** Parent ModelRuntime, so child sessions keep provider registrations and auth. */
|
|
151
|
+
readonly parentModelRuntime?: unknown;
|
|
152
|
+
readonly parentThinkingLevel?: string;
|
|
153
|
+
readonly parentModelRegistry?: {
|
|
154
|
+
find(provider: string, modelId: string): unknown;
|
|
155
|
+
getAll(): readonly unknown[];
|
|
156
|
+
getAvailable?(): readonly unknown[];
|
|
157
|
+
};
|
|
158
|
+
readonly signal?: AbortSignal;
|
|
159
|
+
/** Foreground progress sink; called on every run change so the tool can stream `onUpdate`. */
|
|
160
|
+
readonly onUpdate?: (snapshot: SubagentRunSnapshot) => void;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export type ModelResolution = { readonly model?: unknown; readonly error?: string };
|