@cueloop/schema 0.1.0-alpha.17 → 0.1.0-alpha.18
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/package.json +1 -1
- package/src/herdr.test.ts +37 -0
- package/src/herdr.ts +43 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { detectHerdr, insideHerdr, returnPaneFor } from "./herdr";
|
|
3
|
+
|
|
4
|
+
describe("detectHerdr", () => {
|
|
5
|
+
test("null outside herdr, context inside", () => {
|
|
6
|
+
expect(detectHerdr({})).toBeNull();
|
|
7
|
+
expect(detectHerdr({ HERDR_ENV: "1", HERDR_PANE_ID: "p1" })).toBeNull();
|
|
8
|
+
expect(detectHerdr({ HERDR_ENV: "1", HERDR_PANE_ID: "p1", HERDR_BIN_PATH: "/x/herdr" })).toEqual({
|
|
9
|
+
paneId: "p1",
|
|
10
|
+
binPath: "/x/herdr",
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe("insideHerdr", () => {
|
|
16
|
+
test("true only when HERDR_ENV is exactly 1", () => {
|
|
17
|
+
expect(insideHerdr({})).toBeFalse();
|
|
18
|
+
expect(insideHerdr({ HERDR_ENV: "0" })).toBeFalse();
|
|
19
|
+
expect(insideHerdr({ HERDR_ENV: "1" })).toBeTrue();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("returnPaneFor", () => {
|
|
24
|
+
test("outside herdr there is never a return target", () => {
|
|
25
|
+
expect(returnPaneFor("w1:p1", {})).toBeUndefined();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("env override wins, session meta is the fallback", () => {
|
|
29
|
+
const inside = { HERDR_ENV: "1", HERDR_PANE_ID: "w1:p9" };
|
|
30
|
+
expect(returnPaneFor("w1:p1", inside)).toBe("w1:p1");
|
|
31
|
+
expect(returnPaneFor("w1:p1", { ...inside, CUELOOP_RETURN_PANE: "w1:p2" })).toBe("w1:p2");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("returning to our own pane is a no-op", () => {
|
|
35
|
+
expect(returnPaneFor("w1:p1", { HERDR_ENV: "1", HERDR_PANE_ID: "w1:p1" })).toBeUndefined();
|
|
36
|
+
});
|
|
37
|
+
});
|
package/src/herdr.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The herdr ambient env contract, single-sourced. A process running inside a
|
|
3
|
+
* herdr pane sees HERDR_ENV=1 plus the pane id and the herdr binary path.
|
|
4
|
+
* Both the agent-side reporter (adapters) and the reviewer-side return-focus
|
|
5
|
+
* (client) read this contract; decoding it in one place stops the two sides
|
|
6
|
+
* drifting on which vars are required. Pure: no IO, env is only the default
|
|
7
|
+
* argument so callers can pass a fixture.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface HerdrContext {
|
|
11
|
+
paneId: string;
|
|
12
|
+
binPath: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type HerdrEnv = Record<string, string | undefined>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The pane's full contract - pane id and binary path - or null outside a
|
|
19
|
+
* functioning herdr. Required by anything that spawns the herdr CLI.
|
|
20
|
+
*/
|
|
21
|
+
export function detectHerdr(env: HerdrEnv = process.env): HerdrContext | null {
|
|
22
|
+
if (env.HERDR_ENV !== "1") return null;
|
|
23
|
+
const paneId = env.HERDR_PANE_ID;
|
|
24
|
+
const binPath = env.HERDR_BIN_PATH;
|
|
25
|
+
if (!paneId || !binPath) return null;
|
|
26
|
+
return { paneId, binPath };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** True whenever this process runs inside a herdr pane. */
|
|
30
|
+
export function insideHerdr(env: HerdrEnv = process.env): boolean {
|
|
31
|
+
return env.HERDR_ENV === "1";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The pane a closing review should hand focus back to: the opener's
|
|
36
|
+
* CUELOOP_RETURN_PANE, or the session's recorded pane, but never this pane
|
|
37
|
+
* itself. Undefined outside herdr or when the only candidate is our own pane.
|
|
38
|
+
*/
|
|
39
|
+
export function returnPaneFor(sessionHerdrPane?: string, env: HerdrEnv = process.env): string | undefined {
|
|
40
|
+
if (!insideHerdr(env)) return undefined;
|
|
41
|
+
const pane = env.CUELOOP_RETURN_PANE ?? sessionHerdrPane;
|
|
42
|
+
return pane && pane !== env.HERDR_PANE_ID ? pane : undefined;
|
|
43
|
+
}
|
package/src/index.ts
CHANGED