@theaileverage/marionette 0.2.2 → 0.3.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.
@@ -1,5 +1,5 @@
1
1
  export declare const HERDR_PROTOCOL: 22;
2
- export declare const HERDR_SCHEMA_SHA256: "5fb46b13fdaf39c88cf699b9806685868c7ee6b0142523d84391b1606416dc0a";
2
+ export declare const HERDR_SCHEMA_SHA256: '5fb46b13fdaf39c88cf699b9806685868c7ee6b0142523d84391b1606416dc0a';
3
3
  export declare namespace RequestTypes {
4
4
  type AgentPromptParams = {
5
5
  target: string;
@@ -1904,7 +1904,7 @@ export interface HerdrParams {
1904
1904
  'plugin.pane.focus': RequestTypes.PluginPaneFocusParams;
1905
1905
  'plugin.pane.close': RequestTypes.PluginPaneCloseParams;
1906
1906
  }
1907
- export declare const HERDR_METHODS: readonly ["ping", "server.stop", "server.live_handoff", "server.reload_config", "server.agent_manifests", "server.reload_agent_manifests", "notification.show", "product_announcement.dismiss", "release_notes.dismiss", "command.invoke", "client.window_title.set", "client.window_title.clear", "client_shell.surface.set", "session.snapshot", "workspace.create", "workspace.list", "workspace.get", "workspace.focus", "workspace.rename", "workspace.move", "workspace.move_block", "workspace.report_metadata", "workspace.close", "worktree.list", "worktree.create", "worktree.open", "worktree.remove", "tab.create", "tab.list", "tab.get", "tab.focus", "tab.rename", "tab.move", "tab.close", "agent.list", "agent.get", "agent.read", "agent.explain", "agent.send_keys", "agent.rename", "agent.view.set", "agent.view.clear", "agent.focus", "agent.start", "agent.prompt", "agent.wait", "pane.split", "pane.swap", "pane.move", "pane.zoom", "pane.layout", "pane.process_info", "layout.export", "layout.apply", "layout.set_split_ratio", "pane.neighbor", "pane.edges", "pane.focus_direction", "pane.resize", "pane.scroll", "pane.edit_scrollback", "pane.selection.read", "pane.copy_motion", "pane.copy_search", "pane.list", "pane.current", "pane.get", "pane.focus", "pane.input.set", "pane.link.activate", "pane.rename", "pane.send_text", "pane.send_keys", "pane.send_input", "pane.read", "pane.graphics.set", "pane.graphics.clear", "pane.graphics.info", "pane.report_agent", "pane.report_agent_session", "pane.report_metadata", "pane.clear_agent_authority", "pane.release_agent", "pane.close", "popup.close", "events.subscribe", "events.wait", "pane.wait_for_output", "integration.list", "integration.install", "integration.uninstall", "plugin.link", "plugin.list", "plugin.unlink", "plugin.enable", "plugin.disable", "plugin.action.list", "plugin.action.invoke", "plugin.log.list", "plugin.pane.open", "plugin.pane.focus", "plugin.pane.close"];
1907
+ export declare const HERDR_METHODS: readonly ['ping', 'server.stop', 'server.live_handoff', 'server.reload_config', 'server.agent_manifests', 'server.reload_agent_manifests', 'notification.show', 'product_announcement.dismiss', 'release_notes.dismiss', 'command.invoke', 'client.window_title.set', 'client.window_title.clear', 'client_shell.surface.set', 'session.snapshot', 'workspace.create', 'workspace.list', 'workspace.get', 'workspace.focus', 'workspace.rename', 'workspace.move', 'workspace.move_block', 'workspace.report_metadata', 'workspace.close', 'worktree.list', 'worktree.create', 'worktree.open', 'worktree.remove', 'tab.create', 'tab.list', 'tab.get', 'tab.focus', 'tab.rename', 'tab.move', 'tab.close', 'agent.list', 'agent.get', 'agent.read', 'agent.explain', 'agent.send_keys', 'agent.rename', 'agent.view.set', 'agent.view.clear', 'agent.focus', 'agent.start', 'agent.prompt', 'agent.wait', 'pane.split', 'pane.swap', 'pane.move', 'pane.zoom', 'pane.layout', 'pane.process_info', 'layout.export', 'layout.apply', 'layout.set_split_ratio', 'pane.neighbor', 'pane.edges', 'pane.focus_direction', 'pane.resize', 'pane.scroll', 'pane.edit_scrollback', 'pane.selection.read', 'pane.copy_motion', 'pane.copy_search', 'pane.list', 'pane.current', 'pane.get', 'pane.focus', 'pane.input.set', 'pane.link.activate', 'pane.rename', 'pane.send_text', 'pane.send_keys', 'pane.send_input', 'pane.read', 'pane.graphics.set', 'pane.graphics.clear', 'pane.graphics.info', 'pane.report_agent', 'pane.report_agent_session', 'pane.report_metadata', 'pane.clear_agent_authority', 'pane.release_agent', 'pane.close', 'popup.close', 'events.subscribe', 'events.wait', 'pane.wait_for_output', 'integration.list', 'integration.install', 'integration.uninstall', 'plugin.link', 'plugin.list', 'plugin.unlink', 'plugin.enable', 'plugin.disable', 'plugin.action.list', 'plugin.action.invoke', 'plugin.log.list', 'plugin.pane.open', 'plugin.pane.focus', 'plugin.pane.close'];
1908
1908
  export type HerdrMethod = keyof HerdrParams;
1909
1909
  export type HerdrResult = ResponseTypes.ResponseResult;
1910
1910
  export type HerdrEvent = {
@@ -1,11 +1,12 @@
1
- import { type HerdrMethod, type HerdrParams, type HerdrResult, type ResponseTypes, type RequestTypes } from './herdr-protocol.js';
1
+ import type { HerdrJson } from './herdr-transport.js';
2
+ import { type HerdrMethod, type HerdrParams, type HerdrResult, type RequestTypes, type ResponseTypes } from './herdr-protocol.js';
2
3
  import { HerdrEventStream, HerdrGraphicsStream, type GraphicsStreamParams } from './herdr-streams.js';
3
4
  import { type RequestOptions, type StreamOptions } from './herdr-transport.js';
4
5
  export * from './herdr-protocol.js';
6
+ export { HerdrEventStream, HerdrGraphicsStream } from './herdr-streams.js';
7
+ export type { GraphicsFileFrame, GraphicsFrame, GraphicsFrameAck, GraphicsStreamParams, } from './herdr-streams.js';
5
8
  export { HerdrError } from './herdr-transport.js';
6
9
  export type { RequestOptions, StreamOptions } from './herdr-transport.js';
7
- export { HerdrEventStream, HerdrGraphicsStream } from './herdr-streams.js';
8
- export type { GraphicsStreamParams, GraphicsFrame, GraphicsFileFrame, GraphicsFrameAck, } from './herdr-streams.js';
9
10
  export type Pane = ResponseTypes.PaneInfo;
10
11
  export type Agent = ResponseTypes.AgentInfo;
11
12
  export type PaneLayout = ResponseTypes.PaneLayoutSnapshot;
@@ -22,17 +23,17 @@ export interface LaunchOptions {
22
23
  env?: Record<string, string>;
23
24
  focus?: boolean;
24
25
  }
25
- export interface WaitOptions {
26
+ export type WaitOptions = {
26
27
  timeout_ms: number;
27
28
  until?: ('idle' | 'working' | 'blocked' | 'done' | 'unknown')[];
28
- }
29
+ };
29
30
  /** Explicit connection selection, typed wire APIs, and small convenience helpers. */
30
31
  export declare class HerdrClient {
31
32
  readonly socketPath: string;
32
33
  constructor(socketPath: string);
33
34
  static fromEnv(env?: NodeJS.ProcessEnv): HerdrClient;
34
35
  /** Escape hatch for future one-shot methods. Streams require their dedicated transports. */
35
- call<T = unknown>(method: string, params?: Record<string, unknown>, timeoutMs?: number): Promise<T>;
36
+ call<T = unknown>(method: string, params?: Record<string, HerdrJson | undefined>, timeoutMs?: number, signal?: AbortSignal): Promise<T>;
36
37
  /** All schema-defined one-shot methods with exact typed parameter objects. */
37
38
  request<M extends RequestMethod>(method: M, ...args: RequestArgs<M>): Promise<HerdrResult>;
38
39
  subscribe(subscriptions: RequestTypes.Subscription[], options?: StreamOptions): Promise<HerdrEventStream>;
@@ -79,7 +80,7 @@ export declare class HerdrClient {
79
80
  layout: PaneLayout;
80
81
  }>;
81
82
  split: (paneId: string, options: LaunchOptions & {
82
- direction: "right" | "down";
83
+ direction: 'right' | 'down';
83
84
  ratio?: number;
84
85
  }) => Promise<{
85
86
  pane: Pane;
package/dist/herdr-sdk.js CHANGED
@@ -2,8 +2,8 @@ import { HERDR_METHODS, } from './herdr-protocol.js';
2
2
  import { HerdrEventStream, HerdrGraphicsStream, } from './herdr-streams.js';
3
3
  import { socketRequest, validateSocketPath, } from './herdr-transport.js';
4
4
  export * from './herdr-protocol.js';
5
- export { HerdrError } from './herdr-transport.js';
6
5
  export { HerdrEventStream, HerdrGraphicsStream } from './herdr-streams.js';
6
+ export { HerdrError } from './herdr-transport.js';
7
7
  /** Respect server waits; the transport must not time out an otherwise valid long wait. */
8
8
  function deadline(method, params) {
9
9
  if (method === 'agent.start')
@@ -30,16 +30,15 @@ export class HerdrClient {
30
30
  return new HerdrClient(env.HERDR_SOCKET_PATH);
31
31
  }
32
32
  /** Escape hatch for future one-shot methods. Streams require their dedicated transports. */
33
- call(method, params = {}, timeoutMs = 10000) {
33
+ call(method, params = {}, timeoutMs = 10000, signal) {
34
34
  if (method === 'events.subscribe' || method === 'pane.graphics.stream')
35
35
  return Promise.reject(new TypeError('Use subscribe(), graphicsStream(), or api for a streaming method'));
36
- return socketRequest(this.socketPath, method, params, { timeoutMs });
36
+ return socketRequest(this.socketPath, method, params, { timeoutMs, signal });
37
37
  }
38
38
  /** All schema-defined one-shot methods with exact typed parameter objects. */
39
39
  request(method, ...args) {
40
40
  const [params = {}, options = {}] = args;
41
- if (!HERDR_METHODS.includes(method) ||
42
- method === 'events.subscribe')
41
+ if (!HERDR_METHODS.some((known) => known === method) || String(method) === 'events.subscribe')
43
42
  return Promise.reject(new TypeError('Unknown one-shot method; use call() for extensions or subscribe() for events'));
44
43
  return socketRequest(this.socketPath, method, params, {
45
44
  ...options,
@@ -53,6 +52,8 @@ export class HerdrClient {
53
52
  return HerdrGraphicsStream.open(this.socketPath, params, options);
54
53
  }
55
54
  /** One-to-one method names, including streams, for discovery and generated agent code. */
55
+ // SAFETY: Every generated method is installed below with its matching request transport;
56
+ // the two streaming methods are explicitly routed to their dedicated transports.
56
57
  api = Object.freeze(Object.fromEntries([
57
58
  ...HERDR_METHODS.map((method) => [
58
59
  method,
@@ -98,7 +99,12 @@ export class HerdrClient {
98
99
  agent = {
99
100
  start: (paneId, name, kind, args = [], timeoutMs = 30000) => this.call('agent.start', { pane_id: paneId, name, kind, args, timeout_ms: timeoutMs }, timeoutMs + 5000),
100
101
  get: (target) => this.call('agent.get', { target }),
101
- prompt: (target, text, wait) => this.call('agent.prompt', { target, text, ...(wait ? { wait } : {}) }, wait ? wait.timeout_ms + 5000 : 10000),
102
+ prompt: (target, text, wait) => {
103
+ const params = { target, text };
104
+ if (wait)
105
+ params.wait = wait;
106
+ return this.call('agent.prompt', params, wait ? wait.timeout_ms + 5000 : 10000);
107
+ },
102
108
  wait: (target, options) => this.call('agent.wait', { target, ...options }, options.timeout_ms + 5000),
103
109
  sendKeys: (target, keys) => this.call('agent.send_keys', { target, keys }),
104
110
  };
@@ -1,5 +1,5 @@
1
- import { type StreamOptions } from './herdr-transport.js';
2
1
  import type { HerdrEvent, HerdrResult, RequestTypes } from './herdr-protocol.js';
2
+ import { type StreamOptions } from './herdr-transport.js';
3
3
  export declare class HerdrEventStream implements AsyncIterableIterator<HerdrEvent> {
4
4
  private connection;
5
5
  private constructor();
@@ -11,11 +11,11 @@ export declare class HerdrEventStream implements AsyncIterableIterator<HerdrEven
11
11
  return(): Promise<IteratorResult<HerdrEvent>>;
12
12
  }
13
13
  /** This wire method is documented but omitted from Herdr 0.9.0's exported JSON schema. */
14
- export interface GraphicsStreamParams {
14
+ export type GraphicsStreamParams = {
15
15
  pane_id: string;
16
16
  layer_id?: string | null;
17
17
  z_index?: number;
18
- }
18
+ };
19
19
  export interface GraphicsFrame {
20
20
  format: RequestTypes.PaneGraphicsFormat;
21
21
  image_width: number;
@@ -31,12 +31,14 @@ export class HerdrEventStream {
31
31
  const value = await this.connection.read();
32
32
  if (value === undefined)
33
33
  return { done: true, value: undefined };
34
+ // The published SDK has no runtime dependencies; validate its wire envelope here.
35
+ // oxlint-disable-next-line anti-slop/no-runtime-typeof -- Dependency-free JSON protocol boundary.
34
36
  if (!value || typeof value.event !== 'string' || !Object.hasOwn(value, 'data')) {
35
37
  const error = new HerdrError('herdr_invalid_response', 'Expected a Herdr event envelope');
36
38
  this.connection.fail(error, true);
37
39
  throw error;
38
40
  }
39
- return { done: false, value: value };
41
+ return { done: false, value };
40
42
  }
41
43
  close() {
42
44
  this.connection.close();
@@ -56,12 +58,14 @@ function frameHeader(frame) {
56
58
  integer(frame.image_height, 'image_height', 1, 0xffffffff);
57
59
  if (!['png', 'rgb', 'rgba', 'bgra'].includes(frame.format))
58
60
  throw new TypeError('Invalid frame format');
59
- return {
61
+ const header = {
60
62
  format: frame.format,
61
63
  image_width: frame.image_width,
62
64
  image_height: frame.image_height,
63
- ...(frame.placement ? { placement: frame.placement } : {}),
64
65
  };
66
+ if (frame.placement)
67
+ header.placement = frame.placement;
68
+ return header;
65
69
  }
66
70
  function encodeHeader(header) {
67
71
  const line = JSON.stringify(header) + '\n';
@@ -1,3 +1,7 @@
1
+ /** JSON payload accepted by the dependency-free wire transport, including omitted object fields. */
2
+ export type HerdrJson = string | number | boolean | null | HerdrJson[] | {
3
+ [key: string]: HerdrJson | undefined;
4
+ };
1
5
  export declare class HerdrError extends Error {
2
6
  code: string;
3
7
  constructor(code: string, message: string);
@@ -45,6 +49,6 @@ export declare class JsonConnection {
45
49
  read(): Promise<any>;
46
50
  write(data: string | Uint8Array): Promise<void>;
47
51
  within<T>(timeoutMs: number | null, action: () => Promise<T>): Promise<T>;
48
- start(method: string, params: unknown, timeoutMs: number | null): Promise<any>;
52
+ start(method: string, params: Record<string, HerdrJson | undefined>, timeoutMs: number | null): Promise<any>;
49
53
  }
50
- export declare function socketRequest<T>(socketPath: string, method: string, params: unknown, options?: RequestOptions): Promise<T>;
54
+ export declare function socketRequest<T>(socketPath: string, method: string, params: Record<string, HerdrJson | undefined>, options?: RequestOptions): Promise<T>;
@@ -1,5 +1,5 @@
1
- import net from 'node:net';
2
1
  import { randomUUID } from 'node:crypto';
2
+ import net from 'node:net';
3
3
  import { isAbsolute } from 'node:path';
4
4
  export class HerdrError extends Error {
5
5
  code;
@@ -224,7 +224,7 @@ export async function socketRequest(socketPath, method, params, options = {}) {
224
224
  JSON.stringify(params);
225
225
  const connection = new JsonConnection(socketPath, options);
226
226
  try {
227
- return (await connection.start(method, params, timeoutMs));
227
+ return await connection.start(method, params, timeoutMs);
228
228
  }
229
229
  finally {
230
230
  connection.close();