@tomradex/pty-host 0.22.0 → 0.23.1
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/dist/agents.d.ts +1 -1
- package/dist/detection.d.ts +86 -0
- package/dist/host.d.ts +12 -1
- package/dist/index.d.ts +16 -3
- package/dist/keys.d.ts +3 -0
- package/dist/manifests-tomrade.d.ts +4 -0
- package/dist/manifests.d.ts +6 -0
- package/dist/pane.d.ts +17 -0
- package/dist/protocol.d.ts +1 -0
- package/dist/screens.d.ts +9 -0
- package/dist/status.d.ts +33 -0
- package/package.json +7 -3
package/dist/agents.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare function shortCommand(row: Pick<ProcessRow, "name" | "cmdline">):
|
|
|
20
20
|
export declare function agentOfProcess(row: Pick<ProcessRow, "name" | "cmdline">): string | null;
|
|
21
21
|
/** The agent running in a pane: the nearest one under its root, or the root itself. */
|
|
22
22
|
export declare function agentIn(root: Pick<ProcessRow, "name" | "cmdline"> | undefined, below: ProcessRow[]): string | null;
|
|
23
|
-
/** What the title says of
|
|
23
|
+
/** What the title alone says of an agent herdr has no detection manifest for: only Claude's spinner reads as working. */
|
|
24
24
|
export declare function titleStatus(agent: string | null, title: string | null): TerminalStatus;
|
|
25
25
|
export declare function strippedTitle(title: string | null): string | null;
|
|
26
26
|
//# sourceMappingURL=agents.d.ts.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** The manifest engine this reads (`min_engine_version`): 3 has `top_non_empty_lines`. */
|
|
2
|
+
export declare const ENGINE_VERSION = 3;
|
|
3
|
+
type ScreenState = "idle" | "working" | "blocked" | "unknown";
|
|
4
|
+
/** Matchers that all have to hold: `contains` (any case), `regex` on the region, `line_regex` on one of its lines. */
|
|
5
|
+
interface ManifestGate {
|
|
6
|
+
all?: ManifestGate[];
|
|
7
|
+
any?: ManifestGate[];
|
|
8
|
+
not?: ManifestGate[];
|
|
9
|
+
contains?: string[];
|
|
10
|
+
regex?: string[];
|
|
11
|
+
line_regex?: string[];
|
|
12
|
+
}
|
|
13
|
+
interface ManifestRule extends ManifestGate {
|
|
14
|
+
id: string;
|
|
15
|
+
state?: ScreenState;
|
|
16
|
+
priority?: number;
|
|
17
|
+
region?: string;
|
|
18
|
+
visible_idle?: boolean;
|
|
19
|
+
visible_blocker?: boolean;
|
|
20
|
+
visible_working?: boolean;
|
|
21
|
+
/** A screen that says nothing of the state (a transcript viewer): the state stays what it was. */
|
|
22
|
+
skip_state_update?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface AgentManifest {
|
|
25
|
+
id: string;
|
|
26
|
+
version?: string;
|
|
27
|
+
min_engine_version?: number;
|
|
28
|
+
updated_at?: string;
|
|
29
|
+
aliases?: string[];
|
|
30
|
+
rules: ManifestRule[];
|
|
31
|
+
}
|
|
32
|
+
/** What a rule can look at: the pane's live bottom (as `detectionText` reads it), its title and its last OSC 9 progress. */
|
|
33
|
+
export interface DetectionInput {
|
|
34
|
+
screen: string;
|
|
35
|
+
oscTitle: string;
|
|
36
|
+
oscProgress: string;
|
|
37
|
+
}
|
|
38
|
+
export interface Detection {
|
|
39
|
+
state: ScreenState;
|
|
40
|
+
/** The rule that decided it; null when none matched and the agent is idle by default. */
|
|
41
|
+
rule: string | null;
|
|
42
|
+
skip: boolean;
|
|
43
|
+
visibleIdle: boolean;
|
|
44
|
+
visibleBlocker: boolean;
|
|
45
|
+
visibleWorking: boolean;
|
|
46
|
+
}
|
|
47
|
+
interface Gate {
|
|
48
|
+
all: Gate[];
|
|
49
|
+
any: Gate[];
|
|
50
|
+
not: Gate[];
|
|
51
|
+
contains: string[];
|
|
52
|
+
regex: RegExp[];
|
|
53
|
+
lineRegex: RegExp[];
|
|
54
|
+
}
|
|
55
|
+
interface Rule {
|
|
56
|
+
id: string;
|
|
57
|
+
state: ScreenState;
|
|
58
|
+
priority: number;
|
|
59
|
+
region: string;
|
|
60
|
+
skip: boolean;
|
|
61
|
+
visibleIdle: boolean;
|
|
62
|
+
visibleBlocker: boolean;
|
|
63
|
+
visibleWorking: boolean;
|
|
64
|
+
gate: Gate;
|
|
65
|
+
}
|
|
66
|
+
export interface CompiledManifest {
|
|
67
|
+
id: string;
|
|
68
|
+
aliases: string[];
|
|
69
|
+
version: string | null;
|
|
70
|
+
/** Highest priority first, herdr's order among equals: the first that matches is the one herdr picks. */
|
|
71
|
+
rules: Rule[];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A Rust `regex` pattern as a JavaScript RegExp in Unicode mode: flags leading the pattern (`(?i)`, `(?ms)`) become its
|
|
75
|
+
* flags; `\x{…}`, `\A`, `\z` and Unicode's `\d`, `\w`, `\b` are spelled as JavaScript reads them. What has no
|
|
76
|
+
* spelling here (flags mid-pattern, nested classes, class set operations) is refused.
|
|
77
|
+
*/
|
|
78
|
+
export declare function rustRegex(pattern: string): RegExp;
|
|
79
|
+
/** The text a rule's region names, cut from the input as herdr cuts it. */
|
|
80
|
+
export declare function regionText(input: DetectionInput, region: string): string;
|
|
81
|
+
/** A manifest ready to read screens with; throws on one this engine cannot read, naming the rule. */
|
|
82
|
+
export declare function compileManifest(manifest: AgentManifest): CompiledManifest;
|
|
83
|
+
/** How a known agent's pane reads: the first rule (by priority) that matches, else idle. */
|
|
84
|
+
export declare function detect(manifest: CompiledManifest, input: DetectionInput): Detection;
|
|
85
|
+
export {};
|
|
86
|
+
//# sourceMappingURL=detection.d.ts.map
|
package/dist/host.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import net from "node:net";
|
|
|
2
2
|
import { type ProcessRow } from "./agents.js";
|
|
3
3
|
import { type LaunchParams } from "./protocol.js";
|
|
4
4
|
import { Pane, type Pty } from "./pane.js";
|
|
5
|
+
import { type ReadTiming } from "./status.js";
|
|
5
6
|
/** Starts a program on a pseudo-terminal. */
|
|
6
7
|
export type SpawnPty = (file: string, args: string[], opts: {
|
|
7
8
|
cwd: string;
|
|
@@ -29,6 +30,7 @@ export interface HostOptions {
|
|
|
29
30
|
/** Reads the machine's process table, for what runs in each pane; without it the host names no agent. */
|
|
30
31
|
scan?: () => Promise<ProcessRow[]>;
|
|
31
32
|
scanTiming?: Partial<ScanTiming>;
|
|
33
|
+
readTiming?: Partial<ReadTiming>;
|
|
32
34
|
}
|
|
33
35
|
export interface ScanTiming {
|
|
34
36
|
/** Scans are at least this far apart. */
|
|
@@ -56,6 +58,9 @@ export declare class Host {
|
|
|
56
58
|
private lastScan;
|
|
57
59
|
private soon;
|
|
58
60
|
private readonly timing;
|
|
61
|
+
/** The agent in each pane, by the table they were found in. */
|
|
62
|
+
private agents;
|
|
63
|
+
private readonly screens;
|
|
59
64
|
constructor(opts: HostOptions);
|
|
60
65
|
/** One scan at a time, never one while no pane is open; a scan that fails keeps the table there was. */
|
|
61
66
|
private rescan;
|
|
@@ -66,7 +71,11 @@ export declare class Host {
|
|
|
66
71
|
/** Waits for the scan running now or about to; for tests. */
|
|
67
72
|
settled(): Promise<void>;
|
|
68
73
|
private processesOf;
|
|
69
|
-
/**
|
|
74
|
+
/** The agent the process table shows in a pane, worked out once per table. */
|
|
75
|
+
private agentOf;
|
|
76
|
+
/** Whether anyone listens for the pane's agent status; only then is its screen read as it draws. */
|
|
77
|
+
private following;
|
|
78
|
+
/** A pane as `pane.get` and `pane.list` give it: the agent the process table shows in it, and how that agent reads on its screen. */
|
|
70
79
|
private info;
|
|
71
80
|
private processInfo;
|
|
72
81
|
private armIdle;
|
|
@@ -75,6 +84,8 @@ export declare class Host {
|
|
|
75
84
|
private pane;
|
|
76
85
|
handle(method: string, params: Record<string, unknown>): Promise<unknown>;
|
|
77
86
|
launch(params: LaunchParams): Pane;
|
|
87
|
+
private retitled;
|
|
88
|
+
private drew;
|
|
78
89
|
/** Ends the pane's whole process tree; resolves once the pane is gone. */
|
|
79
90
|
close(pane: Pane): Promise<void>;
|
|
80
91
|
private exited;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context, Service } from "cordis";
|
|
2
|
-
import { type TerminalBridge, type TerminalLaunch, type TerminalMode, type TerminalPaneEvent, type TerminalPaneInfo, type TerminalProcess, type TerminalProvider, type TerminalRevive, type TerminalScrollPosition, type TerminalStream } from "@tomradex/contracts";
|
|
2
|
+
import { type TerminalBridge, type TerminalInput, type TerminalLaunch, type TerminalMode, type TerminalPaneEvent, type TerminalPaneInfo, type TerminalProcess, type TerminalProvider, type TerminalRevive, type TerminalScrollPosition, type TerminalStream } from "@tomradex/contracts";
|
|
3
3
|
export { hostCall } from "./client.js";
|
|
4
4
|
export { pipePath, PROTOCOL, PtyHostError } from "./protocol.js";
|
|
5
5
|
export { defaultShell, onPath } from "./shell.js";
|
|
@@ -53,6 +53,8 @@ export declare class PtyHost extends Service implements TerminalProvider {
|
|
|
53
53
|
private reviving;
|
|
54
54
|
private readonly listeners;
|
|
55
55
|
private readonly watched;
|
|
56
|
+
/** What each watched pane's listeners were last told of its agent, as `agent:status`. */
|
|
57
|
+
private readonly told;
|
|
56
58
|
private global;
|
|
57
59
|
private readonly terminals;
|
|
58
60
|
constructor(ctx: Context, config?: PtyHostConfig);
|
|
@@ -87,20 +89,31 @@ export declare class PtyHost extends Service implements TerminalProvider {
|
|
|
87
89
|
private ok;
|
|
88
90
|
closePane(paneId: string): Promise<boolean>;
|
|
89
91
|
paneAlive(paneId: string): Promise<boolean | null>;
|
|
90
|
-
/** The agent the host sees in each pane, by its processes; an agent's title without the glyph it leads with. */
|
|
92
|
+
/** The agent the host sees in each pane, by its processes, and how it reads on its screen; an agent's title without the glyph it leads with. */
|
|
91
93
|
panes(): Promise<TerminalPaneInfo[] | null>;
|
|
92
94
|
/** What runs under a pane's root, nearest first; none from a host older than that, or one that cannot tell. */
|
|
93
95
|
processes(paneId: string): Promise<TerminalProcess[]>;
|
|
94
96
|
/** Typed into the pane, then Enter a moment later, as a person would. */
|
|
95
97
|
prompt(paneId: string, text: string): Promise<boolean>;
|
|
98
|
+
/** Keystrokes into a pane, the text first and the keys a moment later; the host refuses a key name it does not know. */
|
|
99
|
+
sendInput(paneId: string, input: TerminalInput): Promise<boolean>;
|
|
96
100
|
readTail(paneId: string, lines?: number): Promise<string | null>;
|
|
97
101
|
onScroll(paneId: string, listener: (scroll: TerminalScrollPosition) => void): () => void;
|
|
98
102
|
scrollTo(paneId: string, offset: number): Promise<boolean>;
|
|
99
103
|
onPane(listener: (event: TerminalPaneEvent) => void): () => void;
|
|
100
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* The host tells every pane's end and its agent's status on one stream, so following a pane is remembering it — and
|
|
106
|
+
* hearing how its agent reads now, so a change made while nobody listened is not missed.
|
|
107
|
+
*/
|
|
101
108
|
watch(paneId: string): () => void;
|
|
102
109
|
watching(): string[];
|
|
103
110
|
private exited;
|
|
111
|
+
/**
|
|
112
|
+
* How the host reads a watched pane's agent — its screen, by herdr's manifests — told once per change. Display only,
|
|
113
|
+
* as herdr's: code link lets a session's own hooks speak over it, and nothing types into a pane on its word.
|
|
114
|
+
*/
|
|
115
|
+
private status;
|
|
116
|
+
private tell;
|
|
104
117
|
private startGlobal;
|
|
105
118
|
private stopGlobal;
|
|
106
119
|
/** A host just started: the stream waiting out its backoff subscribes now. */
|
package/dist/keys.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AgentManifest } from "./detection.js";
|
|
2
|
+
/** The herdr commit the manifests came from. */
|
|
3
|
+
export declare const HERDR_COMMIT = "2713feb56e9c9db33992db0a262c68f7426d46dd";
|
|
4
|
+
/** herdr's agent detection manifests, by file. */
|
|
5
|
+
export declare const MANIFESTS: Record<string, AgentManifest>;
|
|
6
|
+
//# sourceMappingURL=manifests.d.ts.map
|
package/dist/pane.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Terminal as HeadlessTerminal } from "@xterm/headless";
|
|
2
2
|
import type { TerminalFrame, TerminalMode, TerminalMouse, TerminalScroll } from "@tomradex/contracts";
|
|
3
|
+
import type { DetectionInput } from "./detection.js";
|
|
3
4
|
import { type PaneInfo } from "./protocol.js";
|
|
4
5
|
import { type Screen } from "./render.js";
|
|
5
6
|
/** What the host needs of a pseudo-terminal: node-pty's, or a test's stand-in. */
|
|
@@ -44,6 +45,11 @@ export declare class Pane {
|
|
|
44
45
|
private readonly hooks;
|
|
45
46
|
readonly term: HeadlessTerminal;
|
|
46
47
|
title: string | null;
|
|
48
|
+
/** Counts what changed the screen or title, so a reading of an unchanged pane is skipped. */
|
|
49
|
+
revision: number;
|
|
50
|
+
/** The title and the last OSC 9 report as the agent sent them, for detection. */
|
|
51
|
+
private oscTitle;
|
|
52
|
+
private oscProgress;
|
|
47
53
|
offset: number;
|
|
48
54
|
exited: boolean;
|
|
49
55
|
private readonly attachments;
|
|
@@ -61,6 +67,7 @@ export declare class Pane {
|
|
|
61
67
|
onScroll(pane: Pane, scroll: ScrollState): void;
|
|
62
68
|
onExit(pane: Pane): void;
|
|
63
69
|
onTitle?(pane: Pane): void;
|
|
70
|
+
onOutput?(pane: Pane): void;
|
|
64
71
|
}, scrollback?: number);
|
|
65
72
|
get pid(): number;
|
|
66
73
|
private maxOffset;
|
|
@@ -69,6 +76,16 @@ export declare class Pane {
|
|
|
69
76
|
/** The screen the view shows now. */
|
|
70
77
|
screen(): Screen;
|
|
71
78
|
private modes;
|
|
79
|
+
/**
|
|
80
|
+
* The pane's live bottom as herdr's detection reads it, whatever the view is scrolled to: a screen's height of rows
|
|
81
|
+
* ending at the last one with something on it (or the cursor's, if lower), each without trailing blanks, the blank
|
|
82
|
+
* rows at the end dropped. On the alternate screen, the whole screen.
|
|
83
|
+
*/
|
|
84
|
+
detectionText(): string;
|
|
85
|
+
/** What an agent's detection manifest reads of the pane. */
|
|
86
|
+
detectionInput(): DetectionInput;
|
|
87
|
+
/** Progress another agent reported says nothing of the one that took its place. */
|
|
88
|
+
forgetProgress(): void;
|
|
72
89
|
/** The last lines with something on them, styling stripped. */
|
|
73
90
|
tail(lines: number): string;
|
|
74
91
|
/** Attaches a window once everything written so far is on the screen: `ready` hears it took, then the window is painted the screen whole. */
|
package/dist/protocol.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export interface PaneInfo {
|
|
|
30
30
|
};
|
|
31
31
|
/** The coding agent the host sees running in the pane; absent from a host older than that. */
|
|
32
32
|
agent?: string | null;
|
|
33
|
+
/** How that agent reads on the pane's screen and title, by herdr's detection manifests (by its title alone from a host before them). */
|
|
33
34
|
agent_status?: TerminalStatus;
|
|
34
35
|
}
|
|
35
36
|
/** What `pane.process_info` gives, in herdr's shape: the pane's processes, nearest first. */
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type CompiledManifest } from "./detection.js";
|
|
2
|
+
export { detect, type CompiledManifest, type Detection, type DetectionInput } from "./detection.js";
|
|
3
|
+
/** The manifest for an agent, by its id or an alias: herdr's, else Tomrade's own; null for none, or one this engine cannot read. */
|
|
4
|
+
export declare function manifestOf(agent: string, log?: (line: string) => void): CompiledManifest | null;
|
|
5
|
+
/** Whether Tomrade reads this agent itself, herdr having no manifest for it. */
|
|
6
|
+
export declare const ownManifest: (agent: string) => boolean;
|
|
7
|
+
/** Which of those agents a foreground command line runs, itself or as a script Node or Bun runs; null for anything else. */
|
|
8
|
+
export declare function ownAgentOfCommand(cmdline: string | undefined): string | null;
|
|
9
|
+
//# sourceMappingURL=screens.d.ts.map
|
package/dist/status.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { TerminalStatus } from "@tomradex/contracts";
|
|
2
|
+
import type { Pane } from "./pane.js";
|
|
3
|
+
export { manifestOf } from "./screens.js";
|
|
4
|
+
export interface ReadTiming {
|
|
5
|
+
/** A pane's screen is read at most this often. */
|
|
6
|
+
readMs: number;
|
|
7
|
+
/** Working that turns to an idle the screen does not show outright is held this long first: a spinner between frames is not a stop (herdr's pending idle). */
|
|
8
|
+
idleHoldMs: number;
|
|
9
|
+
}
|
|
10
|
+
export declare const READ_TIMING: ReadTiming;
|
|
11
|
+
export declare class AgentScreens {
|
|
12
|
+
private readonly opts;
|
|
13
|
+
private readonly readings;
|
|
14
|
+
private readonly timing;
|
|
15
|
+
constructor(opts: {
|
|
16
|
+
/** A pane's agent or its status changed. */
|
|
17
|
+
told(pane: Pane, agent: string | null, status: TerminalStatus): void;
|
|
18
|
+
log?: (line: string) => void;
|
|
19
|
+
timing?: Partial<ReadTiming>;
|
|
20
|
+
});
|
|
21
|
+
/** How the pane's agent reads now: its screen read again first if it changed. */
|
|
22
|
+
status(pane: Pane, agent: string | null): TerminalStatus;
|
|
23
|
+
/** The pane drew, retitled or found another agent: read it again, at most every `readMs`. */
|
|
24
|
+
changed(pane: Pane, agent: string | null): void;
|
|
25
|
+
forget(paneId: string): void;
|
|
26
|
+
dispose(): void;
|
|
27
|
+
/** A pane's reading, started afresh when another agent runs there. */
|
|
28
|
+
private reading;
|
|
29
|
+
private schedule;
|
|
30
|
+
private read;
|
|
31
|
+
private tell;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=status.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomradex/pty-host",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "Haoyuan Tang",
|
|
6
6
|
"engines": {
|
|
@@ -21,14 +21,18 @@
|
|
|
21
21
|
".": {
|
|
22
22
|
"types": "./dist/index.d.ts",
|
|
23
23
|
"default": "./dist/runtime.js"
|
|
24
|
+
},
|
|
25
|
+
"./screens": {
|
|
26
|
+
"types": "./dist/screens.d.ts",
|
|
27
|
+
"default": "./dist/runtime.js"
|
|
24
28
|
}
|
|
25
29
|
},
|
|
26
30
|
"files": [
|
|
27
31
|
"dist"
|
|
28
32
|
],
|
|
29
33
|
"dependencies": {
|
|
30
|
-
"@tomradex/contracts": "0.
|
|
31
|
-
"@tomradex/domain": "0.2.
|
|
34
|
+
"@tomradex/contracts": "0.23.1",
|
|
35
|
+
"@tomradex/domain": "0.2.30",
|
|
32
36
|
"cordis": "4.0.0-rc.8"
|
|
33
37
|
},
|
|
34
38
|
"peerDependencies": {
|