pi-herdr-subagents-lite 0.12.0 → 0.12.2
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/CHANGELOG.md +9 -1
- package/package.json +1 -1
- package/src/config/index.ts +6 -148
- package/src/config/paths.ts +18 -0
- package/src/config/reader.ts +106 -0
- package/src/config/types.ts +26 -0
- package/src/herdr/index.ts +12 -85
- package/src/herdr/parse.ts +31 -0
- package/src/herdr/types.ts +54 -0
- package/src/tool/schema.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
本文件记录用户可见变更;未发版的小节标「未发布」。更细的过程见 git log。破坏性变更标 **BREAKING**。0.5.2 及更早的变更见旧仓 `setwhite/pi-herdr-subagents-lite` 的 tag `v0.3.0`–`v0.5.2`。
|
|
4
4
|
|
|
5
|
-
## 0.12.
|
|
5
|
+
## 0.12.2 — 2026-11-28
|
|
6
|
+
|
|
7
|
+
- `tools` 参数的说明补一句「有 codemode 就保留」:纯名字列表会整份替换默认工具集,读说明的模型做只读委派时以前照字面写 `read,bash`,子代理就丢了 codemode。无运行时变更。
|
|
8
|
+
|
|
9
|
+
## 0.12.1 — 2026-11-28
|
|
10
|
+
|
|
11
|
+
- 无运行时变更:0.12.0 的 npm 产物取自拆分前的提交,CHANGELOG 还标着「未发布」。本版按最终提交重发,差别只在内部文件拆分。
|
|
12
|
+
|
|
13
|
+
## 0.12.0 — 2026-11-28
|
|
6
14
|
|
|
7
15
|
按 [v2 契约](docs/specs/0002_v2_architecture_spec.md) 重写,模块只剩 `config` / `herdr` / `run` / `tool` / `extension`。
|
|
8
16
|
|
package/package.json
CHANGED
package/src/config/index.ts
CHANGED
|
@@ -1,152 +1,14 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { configFile } from "./paths.ts";
|
|
3
|
+
import { isRaw, type Raw, Reader } from "./reader.ts";
|
|
4
|
+
import { CONFIG_KEYS, type Config } from "./types.ts";
|
|
4
5
|
|
|
5
|
-
export
|
|
6
|
-
export type ShutdownReason
|
|
6
|
+
export { agentDir, configFile, dataDir, runsDir } from "./paths.ts";
|
|
7
|
+
export type { Config, ShutdownReason } from "./types.ts";
|
|
8
|
+
export { CONFIG_KEYS, SHUTDOWN_REASONS } from "./types.ts";
|
|
7
9
|
|
|
8
|
-
export const CONFIG_KEYS = [
|
|
9
|
-
"enabled",
|
|
10
|
-
"toolName",
|
|
11
|
-
"excludeTools",
|
|
12
|
-
"maxConcurrent",
|
|
13
|
-
"summaryMaxChars",
|
|
14
|
-
"aggregateWindowMs",
|
|
15
|
-
"interruptGraceMs",
|
|
16
|
-
"closeChildrenOn",
|
|
17
|
-
"runRetentionMs",
|
|
18
|
-
] as const;
|
|
19
|
-
|
|
20
|
-
export interface Config {
|
|
21
|
-
enabled: boolean;
|
|
22
|
-
toolName: string;
|
|
23
|
-
excludeTools: string[];
|
|
24
|
-
maxConcurrent: number;
|
|
25
|
-
summaryMaxChars: number;
|
|
26
|
-
aggregateWindowMs: number;
|
|
27
|
-
interruptGraceMs: number;
|
|
28
|
-
closeChildrenOn: ShutdownReason[];
|
|
29
|
-
runRetentionMs: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const TOOL_NAME = /^[a-z][a-z0-9_]{0,31}$/;
|
|
33
10
|
const DAY_MS = 86_400_000;
|
|
34
11
|
|
|
35
|
-
export function agentDir(): string {
|
|
36
|
-
return process.env.PI_CODING_AGENT_DIR ?? join(homedir(), ".pi", "agent");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function dataDir(agentDirectory: string): string {
|
|
40
|
-
return join(agentDirectory, "pi-herdr-subagents-lite");
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function runsDir(agentDirectory: string): string {
|
|
44
|
-
return join(dataDir(agentDirectory), "runs");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
type Raw = Record<string, unknown>;
|
|
48
|
-
|
|
49
|
-
function isRaw(value: unknown): value is Raw {
|
|
50
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
class Reader {
|
|
54
|
-
readonly problems: string[] = [];
|
|
55
|
-
readonly raw: Raw;
|
|
56
|
-
|
|
57
|
-
constructor(raw: Raw) {
|
|
58
|
-
this.raw = raw;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
unknownKeys(known: readonly string[]): void {
|
|
62
|
-
for (const key of Object.keys(this.raw)) {
|
|
63
|
-
if (!known.includes(key)) {
|
|
64
|
-
this.problems.push(`${key}: unknown key`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
boolean(key: string, fallback: boolean): boolean {
|
|
70
|
-
const value = this.raw[key];
|
|
71
|
-
if (value === undefined) {
|
|
72
|
-
return fallback;
|
|
73
|
-
}
|
|
74
|
-
if (typeof value !== "boolean") {
|
|
75
|
-
this.problems.push(`${key}: expected boolean`);
|
|
76
|
-
return fallback;
|
|
77
|
-
}
|
|
78
|
-
return value;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
integer(key: string, fallback: number, min: number, max: number): number {
|
|
82
|
-
const value = this.raw[key];
|
|
83
|
-
if (value === undefined) {
|
|
84
|
-
return fallback;
|
|
85
|
-
}
|
|
86
|
-
if (typeof value !== "number" || !Number.isInteger(value)) {
|
|
87
|
-
this.problems.push(`${key}: expected integer`);
|
|
88
|
-
return fallback;
|
|
89
|
-
}
|
|
90
|
-
if (value < min || value > max) {
|
|
91
|
-
this.problems.push(`${key}: expected ${min}..${max}`);
|
|
92
|
-
return fallback;
|
|
93
|
-
}
|
|
94
|
-
return value;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
toolName(): string {
|
|
98
|
-
const value = this.raw.toolName;
|
|
99
|
-
if (value === undefined) {
|
|
100
|
-
return "subagent";
|
|
101
|
-
}
|
|
102
|
-
if (typeof value !== "string" || !TOOL_NAME.test(value)) {
|
|
103
|
-
this.problems.push(`toolName: expected a name matching ${TOOL_NAME.source}`);
|
|
104
|
-
return "subagent";
|
|
105
|
-
}
|
|
106
|
-
return value;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
excludeTools(): string[] {
|
|
110
|
-
const value = this.raw.excludeTools;
|
|
111
|
-
if (value === undefined) {
|
|
112
|
-
return ["ask"];
|
|
113
|
-
}
|
|
114
|
-
if (!Array.isArray(value)) {
|
|
115
|
-
this.problems.push("excludeTools: expected array");
|
|
116
|
-
return ["ask"];
|
|
117
|
-
}
|
|
118
|
-
const picked: string[] = [];
|
|
119
|
-
for (const item of value) {
|
|
120
|
-
if (typeof item === "string" && item.trim() !== "") {
|
|
121
|
-
picked.push(item);
|
|
122
|
-
} else {
|
|
123
|
-
this.problems.push(`excludeTools: expected a non-empty string, got ${JSON.stringify(item)}`);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return picked;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
reasons(): ShutdownReason[] {
|
|
130
|
-
const value = this.raw.closeChildrenOn;
|
|
131
|
-
if (value === undefined) {
|
|
132
|
-
return ["quit", "reload"];
|
|
133
|
-
}
|
|
134
|
-
if (!Array.isArray(value)) {
|
|
135
|
-
this.problems.push("closeChildrenOn: expected array");
|
|
136
|
-
return ["quit", "reload"];
|
|
137
|
-
}
|
|
138
|
-
const picked: ShutdownReason[] = [];
|
|
139
|
-
for (const item of value) {
|
|
140
|
-
if (typeof item === "string" && (SHUTDOWN_REASONS as readonly string[]).includes(item)) {
|
|
141
|
-
picked.push(item as ShutdownReason);
|
|
142
|
-
} else {
|
|
143
|
-
this.problems.push(`closeChildrenOn: unknown value ${JSON.stringify(item)}`);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return picked;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
12
|
function parse(raw: Raw, file: string): Config {
|
|
151
13
|
const reader = new Reader(raw);
|
|
152
14
|
reader.unknownKeys(CONFIG_KEYS);
|
|
@@ -189,10 +51,6 @@ function readRaw(file: string): Raw {
|
|
|
189
51
|
return parsed;
|
|
190
52
|
}
|
|
191
53
|
|
|
192
|
-
export function configFile(agentDirectory: string): string {
|
|
193
|
-
return join(dataDir(agentDirectory), "config.json");
|
|
194
|
-
}
|
|
195
|
-
|
|
196
54
|
export function loadConfig(agentDirectory: string): Config {
|
|
197
55
|
const file = configFile(agentDirectory);
|
|
198
56
|
return parse(readRaw(file), file);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
export function agentDir(): string {
|
|
5
|
+
return process.env.PI_CODING_AGENT_DIR ?? join(homedir(), ".pi", "agent");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function dataDir(agentDirectory: string): string {
|
|
9
|
+
return join(agentDirectory, "pi-herdr-subagents-lite");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function runsDir(agentDirectory: string): string {
|
|
13
|
+
return join(dataDir(agentDirectory), "runs");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function configFile(agentDirectory: string): string {
|
|
17
|
+
return join(dataDir(agentDirectory), "config.json");
|
|
18
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { SHUTDOWN_REASONS, type ShutdownReason } from "./types.ts";
|
|
2
|
+
|
|
3
|
+
const TOOL_NAME = /^[a-z][a-z0-9_]{0,31}$/;
|
|
4
|
+
|
|
5
|
+
export type Raw = Record<string, unknown>;
|
|
6
|
+
|
|
7
|
+
export function isRaw(value: unknown): value is Raw {
|
|
8
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class Reader {
|
|
12
|
+
readonly problems: string[] = [];
|
|
13
|
+
readonly raw: Raw;
|
|
14
|
+
|
|
15
|
+
constructor(raw: Raw) {
|
|
16
|
+
this.raw = raw;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
unknownKeys(known: readonly string[]): void {
|
|
20
|
+
for (const key of Object.keys(this.raw)) {
|
|
21
|
+
if (!known.includes(key)) {
|
|
22
|
+
this.problems.push(`${key}: unknown key`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
boolean(key: string, fallback: boolean): boolean {
|
|
28
|
+
const value = this.raw[key];
|
|
29
|
+
if (value === undefined) {
|
|
30
|
+
return fallback;
|
|
31
|
+
}
|
|
32
|
+
if (typeof value !== "boolean") {
|
|
33
|
+
this.problems.push(`${key}: expected boolean`);
|
|
34
|
+
return fallback;
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
integer(key: string, fallback: number, min: number, max: number): number {
|
|
40
|
+
const value = this.raw[key];
|
|
41
|
+
if (value === undefined) {
|
|
42
|
+
return fallback;
|
|
43
|
+
}
|
|
44
|
+
if (typeof value !== "number" || !Number.isInteger(value)) {
|
|
45
|
+
this.problems.push(`${key}: expected integer`);
|
|
46
|
+
return fallback;
|
|
47
|
+
}
|
|
48
|
+
if (value < min || value > max) {
|
|
49
|
+
this.problems.push(`${key}: expected ${min}..${max}`);
|
|
50
|
+
return fallback;
|
|
51
|
+
}
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
toolName(): string {
|
|
56
|
+
const value = this.raw.toolName;
|
|
57
|
+
if (value === undefined) {
|
|
58
|
+
return "subagent";
|
|
59
|
+
}
|
|
60
|
+
if (typeof value !== "string" || !TOOL_NAME.test(value)) {
|
|
61
|
+
this.problems.push(`toolName: expected a name matching ${TOOL_NAME.source}`);
|
|
62
|
+
return "subagent";
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
excludeTools(): string[] {
|
|
68
|
+
const value = this.raw.excludeTools;
|
|
69
|
+
if (value === undefined) {
|
|
70
|
+
return ["ask"];
|
|
71
|
+
}
|
|
72
|
+
if (!Array.isArray(value)) {
|
|
73
|
+
this.problems.push("excludeTools: expected array");
|
|
74
|
+
return ["ask"];
|
|
75
|
+
}
|
|
76
|
+
const picked: string[] = [];
|
|
77
|
+
for (const item of value) {
|
|
78
|
+
if (typeof item === "string" && item.trim() !== "") {
|
|
79
|
+
picked.push(item);
|
|
80
|
+
} else {
|
|
81
|
+
this.problems.push(`excludeTools: expected a non-empty string, got ${JSON.stringify(item)}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return picked;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
reasons(): ShutdownReason[] {
|
|
88
|
+
const value = this.raw.closeChildrenOn;
|
|
89
|
+
if (value === undefined) {
|
|
90
|
+
return ["quit", "reload"];
|
|
91
|
+
}
|
|
92
|
+
if (!Array.isArray(value)) {
|
|
93
|
+
this.problems.push("closeChildrenOn: expected array");
|
|
94
|
+
return ["quit", "reload"];
|
|
95
|
+
}
|
|
96
|
+
const picked: ShutdownReason[] = [];
|
|
97
|
+
for (const item of value) {
|
|
98
|
+
if (typeof item === "string" && (SHUTDOWN_REASONS as readonly string[]).includes(item)) {
|
|
99
|
+
picked.push(item as ShutdownReason);
|
|
100
|
+
} else {
|
|
101
|
+
this.problems.push(`closeChildrenOn: unknown value ${JSON.stringify(item)}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return picked;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const SHUTDOWN_REASONS = ["new", "resume", "fork", "quit", "reload"] as const;
|
|
2
|
+
export type ShutdownReason = (typeof SHUTDOWN_REASONS)[number];
|
|
3
|
+
|
|
4
|
+
export const CONFIG_KEYS = [
|
|
5
|
+
"enabled",
|
|
6
|
+
"toolName",
|
|
7
|
+
"excludeTools",
|
|
8
|
+
"maxConcurrent",
|
|
9
|
+
"summaryMaxChars",
|
|
10
|
+
"aggregateWindowMs",
|
|
11
|
+
"interruptGraceMs",
|
|
12
|
+
"closeChildrenOn",
|
|
13
|
+
"runRetentionMs",
|
|
14
|
+
] as const;
|
|
15
|
+
|
|
16
|
+
export interface Config {
|
|
17
|
+
enabled: boolean;
|
|
18
|
+
toolName: string;
|
|
19
|
+
excludeTools: string[];
|
|
20
|
+
maxConcurrent: number;
|
|
21
|
+
summaryMaxChars: number;
|
|
22
|
+
aggregateWindowMs: number;
|
|
23
|
+
interruptGraceMs: number;
|
|
24
|
+
closeChildrenOn: ShutdownReason[];
|
|
25
|
+
runRetentionMs: number;
|
|
26
|
+
}
|
package/src/herdr/index.ts
CHANGED
|
@@ -1,95 +1,22 @@
|
|
|
1
|
+
import { MUTATION_MS, nested, QUERY_MS, resultOf, text } from "./parse.ts";
|
|
1
2
|
import type { RequestOptions, Transport } from "./socket.ts";
|
|
2
3
|
import { createTransport, HerdrError } from "./socket.ts";
|
|
4
|
+
import type { AgentStatus, HerdrClient } from "./types.ts";
|
|
3
5
|
|
|
4
6
|
export { socketEndpoint } from "./endpoint.ts";
|
|
7
|
+
export type {
|
|
8
|
+
AgentState,
|
|
9
|
+
AgentStatus,
|
|
10
|
+
CreatedWorktree,
|
|
11
|
+
CreateTabInput,
|
|
12
|
+
HerdrClient,
|
|
13
|
+
PaneState,
|
|
14
|
+
SplitPaneInput,
|
|
15
|
+
StartAgentInput,
|
|
16
|
+
} from "./types.ts";
|
|
5
17
|
export type { Transport };
|
|
6
18
|
export { HerdrError };
|
|
7
19
|
|
|
8
|
-
export type AgentStatus = "idle" | "working" | "blocked" | "done" | "unknown";
|
|
9
|
-
|
|
10
|
-
export interface PaneState {
|
|
11
|
-
paneId: string;
|
|
12
|
-
agentStatus: AgentStatus;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** herdr 的启动就绪状态:interactive_ready 只有在 agent.get 里才会被推进。 */
|
|
16
|
-
export interface AgentState {
|
|
17
|
-
status: AgentStatus;
|
|
18
|
-
interactiveReady: boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface CreateTabInput {
|
|
22
|
-
cwd: string;
|
|
23
|
-
label: string;
|
|
24
|
-
env: Record<string, string>;
|
|
25
|
-
workspaceId?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface CreatedWorktree {
|
|
29
|
-
workspaceId: string;
|
|
30
|
-
tabId: string;
|
|
31
|
-
paneId: string;
|
|
32
|
-
path: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface SplitPaneInput {
|
|
36
|
-
paneId: string;
|
|
37
|
-
cwd: string;
|
|
38
|
-
env: Record<string, string>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface StartAgentInput {
|
|
42
|
-
name: string;
|
|
43
|
-
paneId: string;
|
|
44
|
-
args: string[];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** 扩展唯一的 herdr 依赖面。run 模块只认这个接口。 */
|
|
48
|
-
export interface HerdrClient {
|
|
49
|
-
createTab(input: CreateTabInput): Promise<string>;
|
|
50
|
-
createWorktree(input: { cwd: string; label: string }): Promise<CreatedWorktree>;
|
|
51
|
-
splitPane(input: SplitPaneInput): Promise<string>;
|
|
52
|
-
removeWorktree(workspaceId: string): Promise<void>;
|
|
53
|
-
startAgent(input: StartAgentInput): Promise<void>;
|
|
54
|
-
getAgent(target: string): Promise<AgentState>;
|
|
55
|
-
prompt(target: string, text: string): Promise<void>;
|
|
56
|
-
sendKeys(target: string, keys: string[]): Promise<void>;
|
|
57
|
-
waitAgent(target: string, until: AgentStatus[], timeoutMs?: number): Promise<AgentStatus>;
|
|
58
|
-
closePane(paneId: string): Promise<void>;
|
|
59
|
-
listPanes(): Promise<PaneState[]>;
|
|
60
|
-
close(): void;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const QUERY_MS = 20_000;
|
|
64
|
-
const MUTATION_MS = 120_000;
|
|
65
|
-
|
|
66
|
-
function resultOf(value: unknown, type: string): Record<string, unknown> {
|
|
67
|
-
if (typeof value !== "object" || value === null) {
|
|
68
|
-
throw new HerdrError("herdr_protocol", `empty result, expected ${type}`);
|
|
69
|
-
}
|
|
70
|
-
const record = value as Record<string, unknown>;
|
|
71
|
-
if (record.type !== type) {
|
|
72
|
-
throw new HerdrError("herdr_protocol", `expected ${type}, got ${String(record.type)}`);
|
|
73
|
-
}
|
|
74
|
-
return record;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function nested(record: Record<string, unknown>, key: string): Record<string, unknown> {
|
|
78
|
-
const value = record[key];
|
|
79
|
-
if (typeof value !== "object" || value === null) {
|
|
80
|
-
throw new HerdrError("herdr_protocol", `${key}: expected object`);
|
|
81
|
-
}
|
|
82
|
-
return value as Record<string, unknown>;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function text(record: Record<string, unknown>, key: string): string {
|
|
86
|
-
const value = record[key];
|
|
87
|
-
if (typeof value !== "string" || value === "") {
|
|
88
|
-
throw new HerdrError("herdr_protocol", `${key}: expected non-empty string`);
|
|
89
|
-
}
|
|
90
|
-
return value;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
20
|
export function createHerdrClient(endpoint: string): HerdrClient {
|
|
94
21
|
const transport: Transport = createTransport(endpoint);
|
|
95
22
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { HerdrError } from "./socket.ts";
|
|
2
|
+
|
|
3
|
+
export const QUERY_MS = 20_000;
|
|
4
|
+
export const MUTATION_MS = 120_000;
|
|
5
|
+
|
|
6
|
+
export function resultOf(value: unknown, type: string): Record<string, unknown> {
|
|
7
|
+
if (typeof value !== "object" || value === null) {
|
|
8
|
+
throw new HerdrError("herdr_protocol", `empty result, expected ${type}`);
|
|
9
|
+
}
|
|
10
|
+
const record = value as Record<string, unknown>;
|
|
11
|
+
if (record.type !== type) {
|
|
12
|
+
throw new HerdrError("herdr_protocol", `expected ${type}, got ${String(record.type)}`);
|
|
13
|
+
}
|
|
14
|
+
return record;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function nested(record: Record<string, unknown>, key: string): Record<string, unknown> {
|
|
18
|
+
const value = record[key];
|
|
19
|
+
if (typeof value !== "object" || value === null) {
|
|
20
|
+
throw new HerdrError("herdr_protocol", `${key}: expected object`);
|
|
21
|
+
}
|
|
22
|
+
return value as Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function text(record: Record<string, unknown>, key: string): string {
|
|
26
|
+
const value = record[key];
|
|
27
|
+
if (typeof value !== "string" || value === "") {
|
|
28
|
+
throw new HerdrError("herdr_protocol", `${key}: expected non-empty string`);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export type AgentStatus = "idle" | "working" | "blocked" | "done" | "unknown";
|
|
2
|
+
|
|
3
|
+
export interface PaneState {
|
|
4
|
+
paneId: string;
|
|
5
|
+
agentStatus: AgentStatus;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** herdr 的启动就绪状态:interactive_ready 只有在 agent.get 里才会被推进。 */
|
|
9
|
+
export interface AgentState {
|
|
10
|
+
status: AgentStatus;
|
|
11
|
+
interactiveReady: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface CreateTabInput {
|
|
15
|
+
cwd: string;
|
|
16
|
+
label: string;
|
|
17
|
+
env: Record<string, string>;
|
|
18
|
+
workspaceId?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface CreatedWorktree {
|
|
22
|
+
workspaceId: string;
|
|
23
|
+
tabId: string;
|
|
24
|
+
paneId: string;
|
|
25
|
+
path: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface SplitPaneInput {
|
|
29
|
+
paneId: string;
|
|
30
|
+
cwd: string;
|
|
31
|
+
env: Record<string, string>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface StartAgentInput {
|
|
35
|
+
name: string;
|
|
36
|
+
paneId: string;
|
|
37
|
+
args: string[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** 扩展唯一的 herdr 依赖面。run 模块只认这个接口。 */
|
|
41
|
+
export interface HerdrClient {
|
|
42
|
+
createTab(input: CreateTabInput): Promise<string>;
|
|
43
|
+
createWorktree(input: { cwd: string; label: string }): Promise<CreatedWorktree>;
|
|
44
|
+
splitPane(input: SplitPaneInput): Promise<string>;
|
|
45
|
+
removeWorktree(workspaceId: string): Promise<void>;
|
|
46
|
+
startAgent(input: StartAgentInput): Promise<void>;
|
|
47
|
+
getAgent(target: string): Promise<AgentState>;
|
|
48
|
+
prompt(target: string, text: string): Promise<void>;
|
|
49
|
+
sendKeys(target: string, keys: string[]): Promise<void>;
|
|
50
|
+
waitAgent(target: string, until: AgentStatus[], timeoutMs?: number): Promise<AgentStatus>;
|
|
51
|
+
closePane(paneId: string): Promise<void>;
|
|
52
|
+
listPanes(): Promise<PaneState[]>;
|
|
53
|
+
close(): void;
|
|
54
|
+
}
|
package/src/tool/schema.ts
CHANGED
|
@@ -50,7 +50,7 @@ export const parameters = Type.Unsafe<SubagentParameters>({
|
|
|
50
50
|
worktree: { type: "boolean", description: "Set true when child may write to this repo." },
|
|
51
51
|
tools: {
|
|
52
52
|
...strings,
|
|
53
|
-
description: "Replaces default tool set.",
|
|
53
|
+
description: "Replaces default tool set; keep codemode if present.",
|
|
54
54
|
},
|
|
55
55
|
skills: {
|
|
56
56
|
...strings,
|