@byokit/herdr 0.1.0-next.dbe7142

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +202 -0
  3. package/README.md +18 -0
  4. package/dist/agents.d.ts +7 -0
  5. package/dist/agents.js +141 -0
  6. package/dist/approvals.d.ts +24 -0
  7. package/dist/approvals.js +81 -0
  8. package/dist/cli.d.ts +10 -0
  9. package/dist/cli.js +89 -0
  10. package/dist/close.d.ts +4 -0
  11. package/dist/close.js +85 -0
  12. package/dist/constants.d.ts +2 -0
  13. package/dist/constants.js +5 -0
  14. package/dist/device.d.ts +40 -0
  15. package/dist/device.js +128 -0
  16. package/dist/generated/events.d.ts +371 -0
  17. package/dist/generated/events.js +3 -0
  18. package/dist/generated/methods.d.ts +2299 -0
  19. package/dist/generated/methods.js +3 -0
  20. package/dist/generated/report.json +50 -0
  21. package/dist/index.d.ts +3 -0
  22. package/dist/index.js +4 -0
  23. package/dist/kit.d.ts +73 -0
  24. package/dist/kit.js +209 -0
  25. package/dist/link.d.ts +24 -0
  26. package/dist/link.js +324 -0
  27. package/dist/notices.d.ts +14 -0
  28. package/dist/notices.js +88 -0
  29. package/dist/socket.d.ts +2 -0
  30. package/dist/socket.js +137 -0
  31. package/dist/supervise.d.ts +17 -0
  32. package/dist/supervise.js +137 -0
  33. package/dist/terminal.d.ts +6 -0
  34. package/dist/terminal.js +105 -0
  35. package/dist/testing/contract.d.ts +9 -0
  36. package/dist/testing/contract.js +308 -0
  37. package/dist/testing/fake-herdr/bin.d.ts +5 -0
  38. package/dist/testing/fake-herdr/bin.js +210 -0
  39. package/dist/testing/fake-herdr/server.d.ts +21 -0
  40. package/dist/testing/fake-herdr/server.js +604 -0
  41. package/dist/testing/fake-herdr/world.d.ts +84 -0
  42. package/dist/testing/fake-herdr/world.js +85 -0
  43. package/dist/testing/index.d.ts +4 -0
  44. package/dist/testing/index.js +7 -0
  45. package/dist/types.d.ts +115 -0
  46. package/dist/types.js +3 -0
  47. package/dist/words.d.ts +10 -0
  48. package/dist/words.js +18 -0
  49. package/dist/words.json +19 -0
  50. package/package.json +60 -0
@@ -0,0 +1,85 @@
1
+ // The deterministic herd the fake serves (docs/runtime-kits.md 6.8): 1 workspace, 1 tab, 2 panes —
2
+ // `w1:p1` a plain shell, `w1:p2` an agent of the first kind. Ids follow the live Herdr
3
+ // `workspace:pane` shape so close guards and filtered subscriptions bind. Ported from muxr
4
+ // `perf/fake-herdr/world.mjs` with the multi-tab herd and perf fixtures removed.
5
+ export const COLS = 80;
6
+ export const ROWS = 24;
7
+ export function paneRect(indexInTab, panesInTab) {
8
+ const height = Math.max(1, Math.floor(ROWS / panesInTab));
9
+ const y = indexInTab * height;
10
+ return {
11
+ x: 0,
12
+ y,
13
+ width: COLS,
14
+ height: indexInTab === panesInTab - 1 ? ROWS - y : height,
15
+ };
16
+ }
17
+ export function agentRecord(o) {
18
+ return {
19
+ pane_id: o.paneId,
20
+ tab_id: o.tabId,
21
+ workspace_id: o.workspaceId,
22
+ cwd: o.cwd,
23
+ foreground_cwd: o.cwd,
24
+ name: o.name,
25
+ agent: o.kind,
26
+ display_agent: o.name,
27
+ agent_status: 'idle',
28
+ interactive_ready: true,
29
+ launch_pending: false,
30
+ revision: o.revision,
31
+ agent_session: { source: `herdr:${o.kind}`, agent: o.kind, kind: 'id', value: `gen-${o.paneId}` },
32
+ };
33
+ }
34
+ export function createWorld(o) {
35
+ const workspace = {
36
+ workspace_id: 'w1',
37
+ label: o.cwd,
38
+ focused: true,
39
+ worktree: {
40
+ repo_key: 'fake-herdr',
41
+ repo_name: 'fake-herdr',
42
+ repo_root: o.cwd,
43
+ checkout_path: o.cwd,
44
+ is_linked_worktree: false,
45
+ },
46
+ };
47
+ const tab = { tab_id: 'w1:t1', workspace_id: 'w1', label: 'main' };
48
+ const shell = {
49
+ pane_id: 'w1:p1',
50
+ tab_id: tab.tab_id,
51
+ workspace_id: 'w1',
52
+ cwd: o.cwd,
53
+ foreground_cwd: o.cwd,
54
+ label: 'zsh',
55
+ terminal_title: `zsh · ${o.cwd}`,
56
+ terminal_title_stripped: `zsh · ${o.cwd}`,
57
+ focused: true,
58
+ tokens: {},
59
+ rect: paneRect(0, 2),
60
+ text: ['ready.'],
61
+ };
62
+ const kind = o.kinds[0] ?? 'pi';
63
+ const agentPane = {
64
+ ...shell,
65
+ pane_id: 'w1:p2',
66
+ focused: false,
67
+ rect: paneRect(1, 2),
68
+ agent_status: 'idle',
69
+ label: kind,
70
+ terminal_title: `${kind} · ${kind}`,
71
+ terminal_title_stripped: `${kind} · ${kind}`,
72
+ };
73
+ const agent = agentRecord({
74
+ paneId: agentPane.pane_id, tabId: tab.tab_id, workspaceId: 'w1', cwd: o.cwd,
75
+ name: kind, kind, revision: 0,
76
+ });
77
+ return { cwd: o.cwd, workspaces: [workspace], tabs: [tab], panes: [shell, agentPane], agents: [agent] };
78
+ }
79
+ export function relayoutTab(world, tabId) {
80
+ const panes = world.panes.filter((pane) => pane.tab_id === tabId);
81
+ panes.forEach((pane, index) => { pane.rect = paneRect(index, panes.length); });
82
+ }
83
+ export function freezeWorld(world) {
84
+ return JSON.parse(JSON.stringify(world));
85
+ }
@@ -0,0 +1,4 @@
1
+ export { startFakeHerdr, type FakeHerdr, type FakeHerdrOptions } from './fake-herdr/server.ts';
2
+ export { writeBinShim, main as fakeHerdrBinMain } from './fake-herdr/bin.ts';
3
+ export { createWorld, type FakeWorld } from './fake-herdr/world.ts';
4
+ export { herdrContract, type HerdrContractBench } from './contract.ts';
@@ -0,0 +1,7 @@
1
+ // The kit's fake Herdr and contract suite (docs/runtime-kits.md 6.8). Built in H6; H3/H5 run the
2
+ // contract against the fake, H9 against the real pinned Herdr. Tests import this by relative path —
3
+ // the package's public exports stay the kit surface.
4
+ export { startFakeHerdr } from "./fake-herdr/server.js";
5
+ export { writeBinShim, main as fakeHerdrBinMain } from "./fake-herdr/bin.js";
6
+ export { createWorld } from "./fake-herdr/world.js";
7
+ export { herdrContract } from "./contract.js";
@@ -0,0 +1,115 @@
1
+ export type HerdrState = {
2
+ phase: 'stopped' | 'connecting' | 'ready' | 'reconnecting' | 'needs-update' | 'missing' | 'failed';
3
+ why?: 'binary' | 'socket' | 'version' | 'server-exited';
4
+ };
5
+ export type HerdrKitOptions = {
6
+ mode: 'adopt';
7
+ bin: string;
8
+ socketPath: string;
9
+ env?: Record<string, string>;
10
+ path?: string[];
11
+ transport?: HerdrTransport;
12
+ onState?: (s: HerdrState) => void;
13
+ } | {
14
+ mode: 'own';
15
+ bin: string;
16
+ stateDir: string;
17
+ env?: Record<string, string>;
18
+ path?: string[];
19
+ transport?: HerdrTransport;
20
+ onState?: (s: HerdrState) => void;
21
+ };
22
+ export interface HerdrTransport {
23
+ call(method: string, params: Record<string, unknown>, timeoutMs?: number): Promise<unknown>;
24
+ subscribe(subs: {
25
+ type: string;
26
+ [k: string]: unknown;
27
+ }[], on: (e: HerdrEvent) => void, onError: (code: string, message: string) => void): () => void;
28
+ close(): void;
29
+ }
30
+ export type HerdrEvent = {
31
+ type: string;
32
+ [k: string]: unknown;
33
+ };
34
+ export type { HerdrMethods, HerdrMethod, HerdrParams, HerdrResult } from './generated/methods.ts';
35
+ export type { HerdrEvents, HerdrEventName, HerdrEventOf, HerdrSubscription } from './generated/events.ts';
36
+ export type AgentStatus = 'idle' | 'working' | 'blocked' | 'done' | 'unknown';
37
+ export type AgentRef = {
38
+ paneId: string;
39
+ name?: string;
40
+ };
41
+ export type StartAgent = {
42
+ kind: string;
43
+ cwd: string;
44
+ name?: string;
45
+ place: {
46
+ workspace: 'new';
47
+ label?: string;
48
+ } | {
49
+ tab: 'new';
50
+ workspaceId: string;
51
+ label?: string;
52
+ } | {
53
+ split: string;
54
+ direction: 'right' | 'down';
55
+ } | {
56
+ pane: string;
57
+ };
58
+ worktree?: {
59
+ branch: string;
60
+ base?: string;
61
+ };
62
+ args?: string[];
63
+ env?: Record<string, string>;
64
+ timeoutMs?: number;
65
+ };
66
+ export type PromptReceipt = {
67
+ paneId: string;
68
+ terminalId: string;
69
+ revision: number;
70
+ status: AgentStatus;
71
+ };
72
+ export type BlockedAgent = {
73
+ paneId: string;
74
+ workspaceId: string;
75
+ tabId: string;
76
+ kind?: string;
77
+ revision: number;
78
+ prompt: string;
79
+ since: number;
80
+ };
81
+ export type HerdrSnapshot = {
82
+ connected: boolean;
83
+ workspaces: {
84
+ id: string;
85
+ label: string;
86
+ tabs: {
87
+ id: string;
88
+ label: string;
89
+ panes: {
90
+ id: string;
91
+ cwd?: string;
92
+ agent?: {
93
+ kind?: string;
94
+ name?: string;
95
+ status: AgentStatus;
96
+ revision: number;
97
+ launchPending?: boolean;
98
+ interactiveReady?: boolean;
99
+ };
100
+ }[];
101
+ }[];
102
+ }[];
103
+ };
104
+ export type TerminalSession = {
105
+ ready: Promise<void>;
106
+ onFrame(fn: (line: string) => void): () => void;
107
+ send(line: string): void;
108
+ close(): void;
109
+ pause(): void;
110
+ resume(): void;
111
+ exited: Promise<{
112
+ code: number | null;
113
+ stderrTail: string;
114
+ }>;
115
+ };
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ // The kit's public types (docs/runtime-kits.md 6.2). H1 freezes these signatures; the generated method table (H2)
2
+ // replaces the placeholder pass-through types below without changing any signature.
3
+ export {};
@@ -0,0 +1,10 @@
1
+ import WORDS from './words.json' with { type: 'json' };
2
+ import type { AgentStatus, HerdrState } from './types.ts';
3
+ export type WordKey = keyof typeof WORDS;
4
+ export { WORDS };
5
+ /** A sentence with its `{slots}` filled. */
6
+ export declare const words: (key: WordKey, vars?: Record<string, string>) => string;
7
+ /** The sentence for a kit state; a stopped kit has nothing to say yet. */
8
+ export declare const stateWords: (s: HerdrState) => string;
9
+ /** The sentence for an agent's status. */
10
+ export declare const agentWords: (s: AgentStatus | "starting") => string;
package/dist/words.js ADDED
@@ -0,0 +1,18 @@
1
+ // Every sentence a person can see, in one file other languages can read too (words.json, table 6.9). Plain words
2
+ // only: no commands, paths, model ids or error codes (docs/runtime-kits.md 4.3); H8's words test holds the line.
3
+ import WORDS from './words.json' with { type: 'json' };
4
+ export { WORDS };
5
+ /** A sentence with its `{slots}` filled. */
6
+ export const words = (key, vars = {}) => WORDS[key].replace(/\{(\w+)\}/g, (_, k) => vars[k] ?? `{${k}}`);
7
+ const PHASE_KEY = {
8
+ connecting: 'herdr.connecting', ready: 'herdr.ready', reconnecting: 'herdr.reconnecting',
9
+ 'needs-update': 'herdr.needsUpdate', missing: 'herdr.missing', failed: 'herdr.failed',
10
+ };
11
+ /** The sentence for a kit state; a stopped kit has nothing to say yet. */
12
+ export const stateWords = (s) => (s.phase === 'stopped' ? '' : words(PHASE_KEY[s.phase]));
13
+ const STATUS_KEY = {
14
+ starting: 'agent.starting', idle: 'agent.idle', working: 'agent.working',
15
+ blocked: 'agent.blocked', done: 'agent.done', unknown: 'agent.unknown',
16
+ };
17
+ /** The sentence for an agent's status. */
18
+ export const agentWords = (s) => words(STATUS_KEY[s]);
@@ -0,0 +1,19 @@
1
+ {
2
+ "herdr.missing": "This computer needs Herdr installed first.",
3
+ "herdr.connecting": "Connecting to Herdr…",
4
+ "herdr.ready": "Connected to Herdr.",
5
+ "herdr.reconnecting": "Herdr isn't answering. Trying again by itself.",
6
+ "herdr.needsUpdate": "Herdr on this computer needs an update to work with this app.",
7
+ "herdr.failed": "Herdr couldn't start on this computer. Restart the app to try again.",
8
+ "agent.starting": "Starting…",
9
+ "agent.idle": "Ready for you.",
10
+ "agent.working": "Working.",
11
+ "agent.blocked": "Waiting for your answer.",
12
+ "agent.done": "Finished.",
13
+ "agent.unknown": "Running.",
14
+ "agent.signIn": "Sign in inside {agent}: follow its own steps on the screen.",
15
+ "agent.notReady": "This helper isn't ready yet. Try again in a moment.",
16
+ "approval.stale": "That question already changed. Look again before answering.",
17
+ "close.wouldWiden": "Closing this would close more than you picked. Close the bigger one instead.",
18
+ "link.notAllowed": "This device can't do that. Ask the person at the computer."
19
+ }
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@byokit/herdr",
3
+ "version": "0.1.0-next.dbe7142",
4
+ "description": "Drive the Herdr on this computer — workspaces, tabs, panes, agents and blocked-approval answers — from an app, or hand it to a phone over @byokit/link.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/umeranjum17/byokit.git",
10
+ "directory": "packages/herdr"
11
+ },
12
+ "engines": {
13
+ "node": ">=22.18"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ },
20
+ "./device": {
21
+ "react-native": {
22
+ "types": "./dist/device.d.ts",
23
+ "default": "./dist/device.js"
24
+ },
25
+ "browser": {
26
+ "types": "./dist/device.d.ts",
27
+ "default": "./dist/device.js"
28
+ },
29
+ "types": "./dist/device.d.ts",
30
+ "default": "./dist/device.js"
31
+ },
32
+ "./link": {
33
+ "types": "./dist/link.d.ts",
34
+ "default": "./dist/link.js"
35
+ },
36
+ "./testing": {
37
+ "types": "./dist/testing/index.d.ts",
38
+ "default": "./dist/testing/index.js"
39
+ }
40
+ },
41
+ "files": [
42
+ "dist",
43
+ "README.md",
44
+ "LICENSE",
45
+ "CHANGELOG.md"
46
+ ],
47
+ "scripts": {
48
+ "prepack": "tsc -b && node ../../scripts/fix-words-dts.cjs"
49
+ },
50
+ "dependencies": {
51
+ "@byokit/link": "0.3.1",
52
+ "@byokit/relay": "0.1.3",
53
+ "@byokit/reach": "0.2.0",
54
+ "@byokit/seal": "0.1.0",
55
+ "ws": "8.21.3"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public"
59
+ }
60
+ }