@muzi3/herdr 0.1.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/LICENSE +201 -0
- package/README.md +49 -0
- package/extensions/index.ts +257 -0
- package/package.json +41 -0
- package/skills/herdr-guide/SKILL.md +99 -0
- package/skills/herdr-guide/agents/openai.yaml +3 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# @muzi3/herdr
|
|
2
|
+
|
|
3
|
+
[Herdr](https://herdr.dev/) 相关的官方 guide skill 与一个扩展打包为一个 pi package。
|
|
4
|
+
|
|
5
|
+
| 资源 | 类型 | 说明 |
|
|
6
|
+
|------|------|------|
|
|
7
|
+
| `herdr-guide` | user-invoked 向导 | 引导用户理解、安装、配置与排查 Herdr(`herdr.dev/agent-guide.md`) |
|
|
8
|
+
| `herdr-agent-state` | 扩展 | 通过 Herdr 的 pane socket 上报 agent 状态(working / blocked / idle)及会话引用,供 Herdr 面板展示 |
|
|
9
|
+
|
|
10
|
+
## 来源与许可
|
|
11
|
+
|
|
12
|
+
两者内容均来自 Herdr 官方,上游仓库为 [herdrdev/herdr](https://github.com/herdrdev/herdr):
|
|
13
|
+
|
|
14
|
+
- `herdr-guide` 引导 skill —— 官方 [`herdr.dev/agent-guide.md`](https://herdr.dev/agent-guide.md),教 agent 引导用户理解/配置/排障 Herdr
|
|
15
|
+
- `herdr-agent-state` 扩展 —— Herdr 官方 `pi` 集成的 bundled 扩展,由 `herdr integration install pi` 自动写入 `~/.pi/agent/extensions/herdr-agent-state.ts`(若设置 `PI_CODING_AGENT_DIR` 则写入 `$PI_CODING_AGENT_DIR/extensions/`)
|
|
16
|
+
|
|
17
|
+
Herdr 以 [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0) 许可发布,本包保留其许可声明,详见 `LICENSE`。
|
|
18
|
+
|
|
19
|
+
> 扩展源文件由 Herdr 集成管理,重装或更新集成时会覆盖;请在旁边添加自定义 hooks 而非编辑它。
|
|
20
|
+
|
|
21
|
+
## 安装
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pi install npm:@muzi3/herdr
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 用法
|
|
28
|
+
|
|
29
|
+
- 用户询问 Herdr 是什么、怎么安装/配置/使用,或排查 agent 未识别、快捷键失效等问题时,触发 `herdr-guide` 引导(`/herdr-guide`)
|
|
30
|
+
- 触发词:`herdr` / `herdr 安装` / `herdr 配置` / `终端工作区` / `agent 状态检测` 等
|
|
31
|
+
|
|
32
|
+
### 扩展环境变量
|
|
33
|
+
|
|
34
|
+
扩展需在 Herdr 集成环境中运行,依赖以下环境变量:
|
|
35
|
+
|
|
36
|
+
| 变量 | 说明 |
|
|
37
|
+
|------|------|
|
|
38
|
+
| `HERDR_ENV` | 为 `1` 时启用 |
|
|
39
|
+
| `HERDR_SOCKET_PATH` | Herdr pane socket 路径 |
|
|
40
|
+
| `HERDR_PANE_ID` | 当前 pane id |
|
|
41
|
+
|
|
42
|
+
未设置这些变量时扩展静默跳过。扩展行为:`agent_start` / `agent_settled` 时上报 `working` / `idle`,`herdr:blocked` 事件上报 `blocked`,`session_start` 时上报会话引用。
|
|
43
|
+
|
|
44
|
+
## 参考
|
|
45
|
+
|
|
46
|
+
- 官方文档:<https://herdr.dev/docs/>
|
|
47
|
+
- 引导 guide 原文:<https://herdr.dev/agent-guide.md>
|
|
48
|
+
- 集成文档(Pi 章节):<https://herdr.dev/docs/integrations/>
|
|
49
|
+
- 上游仓库:<https://github.com/herdrdev/herdr>
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
// installed by herdr
|
|
2
|
+
// managed by herdr; reinstalling or updating the integration overwrites this file.
|
|
3
|
+
// add custom hooks/plugins beside this file instead of editing it.
|
|
4
|
+
// HERDR_INTEGRATION_ID=pi
|
|
5
|
+
// HERDR_INTEGRATION_VERSION=8
|
|
6
|
+
// @ts-nocheck
|
|
7
|
+
|
|
8
|
+
import net from "node:net";
|
|
9
|
+
|
|
10
|
+
const HERDR_ENV = process.env.HERDR_ENV;
|
|
11
|
+
const socketPath = process.env.HERDR_SOCKET_PATH;
|
|
12
|
+
const socketEndpoint =
|
|
13
|
+
process.platform === "win32" && socketPath ? `\\\\.\\pipe\\${socketPath}` : socketPath;
|
|
14
|
+
const paneId = process.env.HERDR_PANE_ID;
|
|
15
|
+
const source = "herdr:pi";
|
|
16
|
+
|
|
17
|
+
function enabled() {
|
|
18
|
+
return HERDR_ENV === "1" && !!socketPath && !!paneId;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function sendRequestAttempt(request: unknown, timeoutMs: number): Promise<boolean> {
|
|
22
|
+
if (!enabled()) {
|
|
23
|
+
return Promise.resolve(true);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
let done = false;
|
|
28
|
+
let timeout: ReturnType<typeof setTimeout> | undefined;
|
|
29
|
+
const finish = (delivered: boolean) => {
|
|
30
|
+
if (done) return;
|
|
31
|
+
done = true;
|
|
32
|
+
if (timeout) {
|
|
33
|
+
clearTimeout(timeout);
|
|
34
|
+
}
|
|
35
|
+
socket.destroy();
|
|
36
|
+
resolve(delivered);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const socket = net.createConnection(socketEndpoint!);
|
|
40
|
+
socket.on("error", () => finish(false));
|
|
41
|
+
socket.on("connect", () => socket.write(`${JSON.stringify(request)}\n`));
|
|
42
|
+
socket.on("data", () => finish(true));
|
|
43
|
+
socket.on("end", () => finish(false));
|
|
44
|
+
timeout = setTimeout(() => finish(false), timeoutMs);
|
|
45
|
+
timeout.unref?.();
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function sendRequest(request: unknown): Promise<void> {
|
|
50
|
+
if (await sendRequestAttempt(request, 500)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
await sendRequestAttempt(request, 1500);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type AgentState = "working" | "blocked" | "idle";
|
|
57
|
+
|
|
58
|
+
type QueuedState = {
|
|
59
|
+
state: AgentState;
|
|
60
|
+
message?: string;
|
|
61
|
+
seq: number;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
let reportSeq = Date.now() * 1000;
|
|
65
|
+
let currentAgentSessionId: string | undefined;
|
|
66
|
+
let currentAgentSessionPath: string | undefined;
|
|
67
|
+
|
|
68
|
+
function nextReportSeq(): number {
|
|
69
|
+
reportSeq += 1;
|
|
70
|
+
return reportSeq;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function updateSessionRef(ctx: any): void {
|
|
74
|
+
try {
|
|
75
|
+
const file = ctx?.sessionManager?.getSessionFile?.();
|
|
76
|
+
currentAgentSessionPath =
|
|
77
|
+
typeof file === "string" && file.startsWith("/") ? file : undefined;
|
|
78
|
+
} catch {
|
|
79
|
+
currentAgentSessionPath = undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
const id = ctx?.sessionManager?.getSessionId?.();
|
|
84
|
+
currentAgentSessionId = typeof id === "string" && id.length > 0 ? id : undefined;
|
|
85
|
+
} catch {
|
|
86
|
+
currentAgentSessionId = undefined;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function withSessionRef(params: Record<string, unknown>): Record<string, unknown> {
|
|
91
|
+
if (currentAgentSessionPath) {
|
|
92
|
+
return { ...params, agent_session_path: currentAgentSessionPath };
|
|
93
|
+
}
|
|
94
|
+
if (currentAgentSessionId) {
|
|
95
|
+
return { ...params, agent_session_id: currentAgentSessionId };
|
|
96
|
+
}
|
|
97
|
+
return params;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function currentSessionRef(): Record<string, unknown> | undefined {
|
|
101
|
+
if (currentAgentSessionPath) {
|
|
102
|
+
return { agent_session_path: currentAgentSessionPath };
|
|
103
|
+
}
|
|
104
|
+
if (currentAgentSessionId) {
|
|
105
|
+
return { agent_session_id: currentAgentSessionId };
|
|
106
|
+
}
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function reportSession(sessionStartSource?: string): Promise<void> {
|
|
111
|
+
const sessionRef = currentSessionRef();
|
|
112
|
+
if (!sessionRef) {
|
|
113
|
+
return Promise.resolve();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return sendRequest({
|
|
117
|
+
id: `${source}:session:${Date.now()}:${Math.random().toString(36).slice(2)}`,
|
|
118
|
+
method: "pane.report_agent_session",
|
|
119
|
+
params: {
|
|
120
|
+
pane_id: paneId,
|
|
121
|
+
source,
|
|
122
|
+
agent: "pi",
|
|
123
|
+
seq: nextReportSeq(),
|
|
124
|
+
session_start_source: sessionStartSource,
|
|
125
|
+
...sessionRef,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function sendState(state: AgentState, message?: string, seq = nextReportSeq()): Promise<void> {
|
|
131
|
+
return sendRequest({
|
|
132
|
+
id: `${source}:${Date.now()}:${Math.random().toString(36).slice(2)}`,
|
|
133
|
+
method: "pane.report_agent",
|
|
134
|
+
params: withSessionRef({
|
|
135
|
+
pane_id: paneId,
|
|
136
|
+
source,
|
|
137
|
+
agent: "pi",
|
|
138
|
+
state,
|
|
139
|
+
message,
|
|
140
|
+
seq,
|
|
141
|
+
}),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
let sendInFlight = false;
|
|
146
|
+
let queuedState: QueuedState | undefined;
|
|
147
|
+
|
|
148
|
+
function queueState(state: AgentState, message?: string): void {
|
|
149
|
+
queuedState = { state, message, seq: nextReportSeq() };
|
|
150
|
+
if (!sendInFlight) {
|
|
151
|
+
void drainStateQueue();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function drainStateQueue(): Promise<void> {
|
|
156
|
+
if (sendInFlight) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
sendInFlight = true;
|
|
161
|
+
try {
|
|
162
|
+
while (queuedState) {
|
|
163
|
+
const next = queuedState;
|
|
164
|
+
queuedState = undefined;
|
|
165
|
+
await sendState(next.state, next.message, next.seq);
|
|
166
|
+
}
|
|
167
|
+
} finally {
|
|
168
|
+
sendInFlight = false;
|
|
169
|
+
if (queuedState) {
|
|
170
|
+
void drainStateQueue();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export default function (pi) {
|
|
176
|
+
if (!enabled()) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
let agentActive = false;
|
|
181
|
+
let blockedCount = 0;
|
|
182
|
+
let blockedMessage: string | undefined;
|
|
183
|
+
let lastState: AgentState | undefined;
|
|
184
|
+
let lastMessage: string | undefined;
|
|
185
|
+
let rootSession = false;
|
|
186
|
+
|
|
187
|
+
function desiredState() {
|
|
188
|
+
if (blockedCount > 0) {
|
|
189
|
+
return { state: "blocked" as const, message: blockedMessage };
|
|
190
|
+
}
|
|
191
|
+
if (agentActive) {
|
|
192
|
+
return { state: "working" as const, message: undefined };
|
|
193
|
+
}
|
|
194
|
+
return { state: "idle" as const, message: undefined };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function publishState(force = false) {
|
|
198
|
+
const next = desiredState();
|
|
199
|
+
if (!force && next.state === lastState && next.message === lastMessage) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
lastState = next.state;
|
|
203
|
+
lastMessage = next.message;
|
|
204
|
+
queueState(next.state, next.message);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
pi.events.on("herdr:blocked", (data) => {
|
|
208
|
+
if (!rootSession) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (!data?.active) {
|
|
212
|
+
blockedCount = Math.max(0, blockedCount - 1);
|
|
213
|
+
if (blockedCount === 0) {
|
|
214
|
+
blockedMessage = undefined;
|
|
215
|
+
}
|
|
216
|
+
publishState();
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
blockedCount += 1;
|
|
221
|
+
blockedMessage = data.label;
|
|
222
|
+
publishState();
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
pi.on("session_start", async (event, ctx) => {
|
|
226
|
+
// TUI only: RPC/JSON/print modes are headless (no PTY herdr can display),
|
|
227
|
+
// and RPC still reports hasUI=true, so mode is the reliable gate.
|
|
228
|
+
if (ctx?.mode !== "tui") {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
rootSession = true;
|
|
232
|
+
updateSessionRef(ctx);
|
|
233
|
+
await reportSession(event?.reason);
|
|
234
|
+
// A reload can replace this extension mid-run without emitting another agent_start.
|
|
235
|
+
agentActive = ctx?.isIdle?.() === false;
|
|
236
|
+
publishState(true);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
pi.on("agent_start", (_event, ctx) => {
|
|
240
|
+
if (!rootSession) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
updateSessionRef(ctx);
|
|
244
|
+
void reportSession();
|
|
245
|
+
agentActive = true;
|
|
246
|
+
publishState();
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
pi.on("agent_settled", (_event, ctx) => {
|
|
250
|
+
if (!rootSession || ctx?.isIdle?.() !== true) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
agentActive = false;
|
|
255
|
+
publishState();
|
|
256
|
+
});
|
|
257
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@muzi3/herdr",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Herdr for pi: the herdr operate skill (control Herdr from inside a pane), the herdr-guide skill (teach a human to set up and troubleshoot Herdr), and the herdr-agent-state extension (report agent state to Herdr).",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package",
|
|
7
|
+
"pi",
|
|
8
|
+
"skill",
|
|
9
|
+
"herdr",
|
|
10
|
+
"terminal-multiplexer",
|
|
11
|
+
"tmux",
|
|
12
|
+
"agent",
|
|
13
|
+
"guide",
|
|
14
|
+
"setup",
|
|
15
|
+
"troubleshooting",
|
|
16
|
+
"agent-state",
|
|
17
|
+
"pane",
|
|
18
|
+
"integration"
|
|
19
|
+
],
|
|
20
|
+
"license": "Apache-2.0",
|
|
21
|
+
"pi": {
|
|
22
|
+
"extensions": [
|
|
23
|
+
"./extensions"
|
|
24
|
+
],
|
|
25
|
+
"skills": [
|
|
26
|
+
"./skills"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"extensions",
|
|
31
|
+
"skills"
|
|
32
|
+
],
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://codeberg.org/muzi/pi-packages.git",
|
|
36
|
+
"directory": "packages/herdr"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: herdr-guide
|
|
3
|
+
description: Guide a human through understanding, installing, setting up, or troubleshooting Herdr (the terminal workspace manager for coding agents). Use when the user asks what Herdr is, how to install/set up/configure Herdr, why an agent is not detected or a keybinding/state looks wrong, or wants a walkthrough of Herdr concepts. 触发词:Herdr、herdr 安装、herdr 配置、herdr 教程、终端工作区、终端多路复用、agent 面板、agent 状态检测、herdr 排障.
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Herdr agent guide
|
|
8
|
+
|
|
9
|
+
Use this guide to help a human understand, set up, or troubleshoot Herdr. It covers Herdr's concept model, setup path, and diagnosis recipes. Canonical documentation lives at <https://herdr.dev/docs/>. Point the human there for more detail, and verify any command you are unsure about against those pages instead of guessing.
|
|
10
|
+
|
|
11
|
+
If you are running *inside* a Herdr pane (the environment variable `HERDR_ENV=1` is set), Herdr also ships a skill file that teaches you to control Herdr through the `herdr` CLI: <https://raw.githubusercontent.com/herdrdev/herdr/master/skills/herdr/SKILL.md>. That file teaches you to operate Herdr; this one teaches you to guide a human.
|
|
12
|
+
|
|
13
|
+
## What Herdr is
|
|
14
|
+
|
|
15
|
+
Herdr is a terminal workspace manager for AI coding agents. Like tmux, it is a multiplexer: a background server owns real terminal processes, and clients attach to render them. Panes keep running when the human detaches, closes the terminal, or disconnects SSH.
|
|
16
|
+
|
|
17
|
+
Unlike tmux, Herdr is mouse-first and agent-aware. The whole UI is clickable — panes, tabs, workspaces, split borders, right-click menus. Herdr detects coding agents running inside panes and shows each one's state in a sidebar, so the human can see across all their projects which agent is `working`, which is `blocked` waiting for input, and which is `done`. A CLI and a local socket API let scripts and agents drive Herdr programmatically.
|
|
18
|
+
|
|
19
|
+
## Concept model
|
|
20
|
+
|
|
21
|
+
Teach these in this order:
|
|
22
|
+
|
|
23
|
+
- **Session** — a persistent background server namespace. Running `herdr` attaches to the default session. Named sessions (`herdr session attach work`) are fully separate runtime namespaces; most people only need the default.
|
|
24
|
+
- **Workspace** — the project-level container. One per repo, task, or investigation. Owns tabs and panes. The sidebar rolls agent states up per workspace.
|
|
25
|
+
- **Tab** — a layout inside a workspace, for separating views like `agents`, `logs`, `server`.
|
|
26
|
+
- **Pane** — a real terminal. Splittable right or down. Survives client detach.
|
|
27
|
+
- **Agent** — a process Herdr recognizes inside a pane. States: `working`, `blocked`, `done`, `idle`, `unknown`.
|
|
28
|
+
- **Modes** — terminal mode sends keys to the focused pane; prefix mode (`ctrl+b`, then one action key) sends one command to Herdr; navigate mode is a persistent navigation surface.
|
|
29
|
+
|
|
30
|
+
Full concepts page: <https://herdr.dev/docs/concepts/>
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
Linux and macOS:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
curl -fsSL https://herdr.dev/install.sh | sh
|
|
38
|
+
herdr
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Windows PowerShell:
|
|
42
|
+
|
|
43
|
+
```powershell
|
|
44
|
+
powershell -ExecutionPolicy Bypass -c "irm https://herdr.dev/install.ps1 | iex"
|
|
45
|
+
herdr
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Homebrew, mise, and Nix installs, verification, and manual downloads: <https://herdr.dev/docs/install/>. Direct installs use the stable channel by default and update with `herdr update`; preview is opt-in. Package-manager installs update through that package manager. Check the version with `herdr --version`.
|
|
49
|
+
|
|
50
|
+
## First-run walkthrough
|
|
51
|
+
|
|
52
|
+
Check your environment first. If `HERDR_ENV=1` is set, you are already running inside a Herdr pane. The human is already attached, so skip step 1 and never tell them to run `herdr` from your pane; Herdr blocks nested launches by design. Start with step 2, and consider the skill file below.
|
|
53
|
+
|
|
54
|
+
Walk the human through this sequence:
|
|
55
|
+
|
|
56
|
+
1. `cd` into a project and run `herdr`. It launches or attaches to the default background session and creates a workspace automatically. First run shows an onboarding flow.
|
|
57
|
+
2. Start their coding agent in the pane — `claude`, `codex`, or any supported agent (full list: <https://herdr.dev/docs/agents/>). Herdr detects it automatically; the sidebar shows its state. Install the matching integration when available. Depending on the agent, it provides lifecycle state, native session restore, or both. For example, `herdr integration install claude` adds native session restore, while Claude's state still comes from screen detection.
|
|
58
|
+
3. Start with the mouse: click panes and tabs to focus, drag split borders, right-click for menus, drag-select to copy. No keybindings are required to use Herdr.
|
|
59
|
+
4. Split panes: right-click menu, or `prefix+v` (right) / `prefix+minus` (down). New tab: `prefix+c`.
|
|
60
|
+
5. Detach with `prefix+q` (press `ctrl+b`, release, press `q`) or close the terminal window. Everything keeps running. Reattach later with `herdr`.
|
|
61
|
+
6. To actually stop everything: `herdr server stop`.
|
|
62
|
+
|
|
63
|
+
## The keyboard story
|
|
64
|
+
|
|
65
|
+
New users do not need to learn keybindings; the mouse covers everything. When the human wants keyboard control:
|
|
66
|
+
|
|
67
|
+
- The prefix key is `ctrl+b` by default. `prefix+?` shows every active binding live.
|
|
68
|
+
- The guided keyboard page covers the prefix, the bindings to learn first, and a vetted prefix-free setup using `ctrl+alt` chords: <https://herdr.dev/docs/keyboard/>. Recommend it over improvising.
|
|
69
|
+
- Every binding, including the prefix itself, is configurable under `[keys]` in the config file.
|
|
70
|
+
- If a direct chord does nothing, the OS or the outer terminal consumed it before Herdr could see it. The keyboard page explains which chords are safe and why.
|
|
71
|
+
|
|
72
|
+
## Install the Herdr skill into yourself
|
|
73
|
+
|
|
74
|
+
Herdr ships `skills/herdr/SKILL.md` (<https://raw.githubusercontent.com/herdrdev/herdr/master/skills/herdr/SKILL.md>), which teaches a coding agent to control Herdr from inside a pane: splitting panes, running commands without stealing focus, reading output, and waiting on other agents.
|
|
75
|
+
|
|
76
|
+
Once the human is set up, offer to install it for your coding agent so future sessions can control Herdr directly. For agents supported by the open skills CLI, use `npx skills add herdrdev/herdr --skill herdr -g`. For agents without a skill system, add the GitHub copy above to their global custom instructions. Ask the human before writing to their config locations, and use the GitHub copy above as the source of truth.
|
|
77
|
+
|
|
78
|
+
## Configuration
|
|
79
|
+
|
|
80
|
+
- Config file: `~/.config/herdr/config.toml` on Linux and macOS; `%APPDATA%\herdr\config.toml` on Windows. Herdr works without one.
|
|
81
|
+
- Print the full default config: `herdr --default-config`.
|
|
82
|
+
- Apply edits to a running server: `herdr server reload-config` (or the global menu → reload config).
|
|
83
|
+
- Main areas: `[keys]` keybindings, `[theme]` themes, `[ui]` sidebar and UI behavior, `[terminal]` shell defaults, `[update]` channel.
|
|
84
|
+
- Full reference: <https://herdr.dev/docs/configuration/>
|
|
85
|
+
|
|
86
|
+
## Diagnosis recipes
|
|
87
|
+
|
|
88
|
+
- **Agent not detected or wrong state:** Run `herdr agent list` to see what Herdr sees and `herdr agent explain <pane> --json` to see why the detector classified a pane that way. Integrations can provide lifecycle state, native session restore, or both; check `herdr integration status` and the agent support table before assuming an integration replaces screen detection. Details: <https://herdr.dev/docs/agents/> and <https://herdr.dev/docs/integrations/>
|
|
89
|
+
- **A keybinding does nothing:** the outer terminal or desktop environment owns that chord. Point the human to <https://herdr.dev/docs/keyboard/> to pick a safe one or free the chord in their terminal settings.
|
|
90
|
+
- **Something looks wrong at startup or with the socket API:** Default-session logs live in `~/.config/herdr/` on Linux and macOS and `%APPDATA%\herdr\` on Windows. Named-session logs live under `sessions/<name>/` inside that directory. `herdr status`, `herdr status server`, and `herdr status client` summarize the runtime.
|
|
91
|
+
- **Remote use:** SSH to the machine and run `herdr` there (works like tmux), or attach as a thin local client with `herdr --remote <host>`. Trade-offs: <https://herdr.dev/docs/how-to-work/>
|
|
92
|
+
- **What survives a detach, restart, or update:** <https://herdr.dev/docs/session-state/>
|
|
93
|
+
|
|
94
|
+
## Rules for you
|
|
95
|
+
|
|
96
|
+
- Do not invent keybindings, config keys, or CLI flags. The ones in this file are accurate as of writing; for anything else, read the linked docs page first.
|
|
97
|
+
- Teach mouse before keyboard for humans new to multiplexers.
|
|
98
|
+
- Herdr is not tmux: do not give tmux commands, tmux config syntax, or `.tmux.conf` advice for Herdr questions.
|
|
99
|
+
- For automation, scripting, or controlling Herdr from code, point to the CLI reference (<https://herdr.dev/docs/cli-reference/>) and socket API (<https://herdr.dev/docs/socket-api/>).
|