@wierdbytes/pi-wierdr 0.0.0-stage → 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.
@@ -0,0 +1,72 @@
1
+ /**
2
+ * How many `@tintinweb/pi-subagents` agents are queued or running right now.
3
+ * They run inside pi, so herdr-core never sees them as child terminals;
4
+ * the count goes out as `agent.subagents` instead. Reads the same
5
+ * `subagents:*` bus events the statusline's chip does, without depending on
6
+ * the package.
7
+ */
8
+
9
+ export const SUBAGENT_EVENTS = {
10
+ CREATED: "subagents:created",
11
+ STARTED: "subagents:started",
12
+ COMPLETED: "subagents:completed",
13
+ FAILED: "subagents:failed",
14
+ } as const;
15
+
16
+ interface Bus {
17
+ on(channel: string, handler: (data: unknown) => void): () => void;
18
+ }
19
+
20
+ const idOf = (data: unknown): string | undefined => {
21
+ const id = (data as { id?: unknown } | null)?.id;
22
+ return typeof id === "string" && id.length > 0 ? id : undefined;
23
+ };
24
+
25
+ export class SubagentCounter {
26
+ private readonly active = new Set<string>();
27
+ private readonly offs: Array<() => void> = [];
28
+
29
+ constructor(private readonly onChange: () => void) {}
30
+
31
+ start(bus: Bus): void {
32
+ if (this.offs.length) return;
33
+ const add = (data: unknown) => {
34
+ const id = idOf(data);
35
+ if (!id || this.active.has(id)) return;
36
+ this.active.add(id);
37
+ this.onChange();
38
+ };
39
+ const remove = (data: unknown) => {
40
+ const id = idOf(data);
41
+ if (!id || !this.active.delete(id)) return;
42
+ this.onChange();
43
+ };
44
+ this.offs.push(
45
+ bus.on(SUBAGENT_EVENTS.CREATED, add),
46
+ bus.on(SUBAGENT_EVENTS.STARTED, add),
47
+ bus.on(SUBAGENT_EVENTS.COMPLETED, remove),
48
+ bus.on(SUBAGENT_EVENTS.FAILED, remove),
49
+ );
50
+ }
51
+
52
+ get count(): number {
53
+ return this.active.size;
54
+ }
55
+
56
+ reset(): void {
57
+ if (this.active.size === 0) return;
58
+ this.active.clear();
59
+ this.onChange();
60
+ }
61
+
62
+ dispose(): void {
63
+ for (const off of this.offs.splice(0)) {
64
+ try {
65
+ off();
66
+ } catch {
67
+ // Unsubscribing never matters enough to disturb pi.
68
+ }
69
+ }
70
+ this.active.clear();
71
+ }
72
+ }
package/index.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @wierdbytes/pi-wierdr — pi for herdr and Wierdr, two halves in one extension:
3
+ *
4
+ * - `herdr/` — model, effort, context, session and cache as `agent.*` labels
5
+ * on pi's herdr-core terminal; Claude / Codex subscription limits
6
+ * as herdr-core's `limits` document; pi's bash commands in
7
+ * herdr-core terminals under pi's (formerly @wierdbytes/pi-herdr)
8
+ * - `agents/` — sub-agents as their own pi in herdr-core terminals nested
9
+ * under this one: Agent / get_subagent_result / steer_subagent /
10
+ * stop_subagent and a pi.events RPC (formerly @wierdbytes/pi-agents)
11
+ *
12
+ * Settings for both: `~/.pi/agent/@wierdbytes/pi-wierdr/settings.json`
13
+ * (`settings.ts`). Outside a herdr-core terminal neither does anything.
14
+ */
15
+
16
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
17
+ import setupAgents from "./agents/index.ts";
18
+ import setupHerdr from "./herdr/index.ts";
19
+
20
+ export default function piWierdr(pi: ExtensionAPI) {
21
+ setupHerdr(pi);
22
+ setupAgents(pi);
23
+ }
package/package.json CHANGED
@@ -1,6 +1,70 @@
1
1
  {
2
2
  "name": "@wierdbytes/pi-wierdr",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "pi for herdr and Wierdr: model, effort, context and cache as agent.* labels on pi's herdr-core terminal, Claude / Codex subscription limits as herdr-core's limits document, pi's bash commands in herdr-core terminals, and sub-agents as their own pi in herdr-core terminals nested under the agent that started them. Replaces @wierdbytes/pi-herdr and @wierdbytes/pi-agents.",
5
+ "type": "module",
6
+ "files": [
7
+ "*.ts",
8
+ "herdr/*.ts",
9
+ "agents/*.ts",
10
+ "!**/*.test.ts",
11
+ "*.md",
12
+ "LICENSE"
13
+ ],
14
+ "keywords": [
15
+ "pi-package",
16
+ "pi",
17
+ "coding-agent",
18
+ "extension",
19
+ "herdr",
20
+ "herdr-core",
21
+ "wierdr",
22
+ "terminal-labels",
23
+ "rate-limits",
24
+ "bash",
25
+ "subagents"
26
+ ],
27
+ "license": "MIT",
28
+ "author": "wierdbytes",
29
+ "homepage": "https://github.com/wierdbytes/wierdr/tree/master/Integrations/pi",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/wierdbytes/wierdr.git",
33
+ "directory": "Integrations/pi"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/wierdbytes/wierdr/issues"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "main": "./index.ts",
42
+ "exports": {
43
+ ".": "./index.ts",
44
+ "./client": "./agents/client.ts"
45
+ },
46
+ "pi": {
47
+ "extensions": [
48
+ "./index.ts"
49
+ ]
50
+ },
51
+ "scripts": {
52
+ "test": "vitest run",
53
+ "test:watch": "vitest"
54
+ },
55
+ "dependencies": {
56
+ "@wierdbytes/pi-common": "^0.5.1"
57
+ },
58
+ "peerDependencies": {
59
+ "@earendil-works/pi-ai": ">=1.5.0",
60
+ "@earendil-works/pi-coding-agent": ">=1.5.0",
61
+ "@earendil-works/pi-tui": ">=1.5.0"
62
+ },
63
+ "devDependencies": {
64
+ "@earendil-works/pi-ai": "^1.5.0",
65
+ "@earendil-works/pi-coding-agent": "^1.5.0",
66
+ "@earendil-works/pi-tui": "^1.5.0",
67
+ "typebox": "^1.1.24",
68
+ "vitest": "^4.0.18"
69
+ }
70
+ }
package/settings.ts ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * `~/.pi/agent/@wierdbytes/pi-wierdr/settings.json`, one file for both
3
+ * halves: `bash` for the herdr side, `agents` for sub-agents. Every key is
4
+ * optional; a missing or broken file means the defaults.
5
+ *
6
+ * Until that file exists, the files of the two packages this one replaced
7
+ * (`@wierdbytes/pi-herdr/settings.json`, `@wierdbytes/pi-agents/settings.json`)
8
+ * are read instead, each for its own half.
9
+ */
10
+
11
+ import { readFileSync } from "node:fs";
12
+ import { join } from "node:path";
13
+ import { getAgentDir } from "@earendil-works/pi-coding-agent";
14
+
15
+ export const packageDir = (): string => join(getAgentDir(), "@wierdbytes", "pi-wierdr");
16
+ export const settingsPath = (): string => join(packageDir(), "settings.json");
17
+
18
+ /** The settings file of the package a half came from, read while pi-wierdr's own doesn't exist. */
19
+ export const legacySettingsPath = (pkg: "pi-herdr" | "pi-agents"): string =>
20
+ join(getAgentDir(), "@wierdbytes", pkg, "settings.json");
21
+
22
+ /** The file's JSON; `undefined` when there is no file, `null` when it can't be read. */
23
+ export function readJson(path: string): unknown {
24
+ let text: string;
25
+ try {
26
+ text = readFileSync(path, "utf8");
27
+ } catch {
28
+ return undefined;
29
+ }
30
+ try {
31
+ return JSON.parse(text);
32
+ } catch {
33
+ return null;
34
+ }
35
+ }