@termwright/mcp 0.2.0 → 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.
Files changed (55) hide show
  1. package/README.md +109 -28
  2. package/dist/bin.js +2 -1
  3. package/dist/bin.js.map +1 -1
  4. package/dist/chunk-R2N52YYH.js +629 -0
  5. package/dist/chunk-R2N52YYH.js.map +1 -0
  6. package/dist/{chunk-IPNUAUAN.js → chunk-ROMJP5D3.js} +595 -482
  7. package/dist/chunk-ROMJP5D3.js.map +1 -0
  8. package/dist/docs-85fGFORb.d.ts +13 -0
  9. package/dist/docs.d.ts +1 -0
  10. package/dist/docs.js +7 -0
  11. package/dist/docs.js.map +1 -0
  12. package/dist/index.d.ts +50 -28
  13. package/dist/index.js +9 -7
  14. package/package.json +11 -8
  15. package/dist/chunk-2J5WHI6X.js +0 -2000
  16. package/dist/chunk-2J5WHI6X.js.map +0 -1
  17. package/dist/chunk-36C7A7DW.js +0 -2685
  18. package/dist/chunk-36C7A7DW.js.map +0 -1
  19. package/dist/chunk-3PLOAM2C.js +0 -2427
  20. package/dist/chunk-3PLOAM2C.js.map +0 -1
  21. package/dist/chunk-57GYK2EF.js +0 -2991
  22. package/dist/chunk-57GYK2EF.js.map +0 -1
  23. package/dist/chunk-ABLJBL5P.js +0 -2687
  24. package/dist/chunk-ABLJBL5P.js.map +0 -1
  25. package/dist/chunk-BOOUADRN.js +0 -1938
  26. package/dist/chunk-BOOUADRN.js.map +0 -1
  27. package/dist/chunk-BPWIETN5.js +0 -2983
  28. package/dist/chunk-BPWIETN5.js.map +0 -1
  29. package/dist/chunk-CMQB5G7R.js +0 -2968
  30. package/dist/chunk-CMQB5G7R.js.map +0 -1
  31. package/dist/chunk-I4B53KZ7.js +0 -2955
  32. package/dist/chunk-I4B53KZ7.js.map +0 -1
  33. package/dist/chunk-IPNUAUAN.js.map +0 -1
  34. package/dist/chunk-KZWL2S6E.js +0 -2869
  35. package/dist/chunk-KZWL2S6E.js.map +0 -1
  36. package/dist/chunk-LB2QBYW4.js +0 -2686
  37. package/dist/chunk-LB2QBYW4.js.map +0 -1
  38. package/dist/chunk-MR3AXSXL.js +0 -1977
  39. package/dist/chunk-MR3AXSXL.js.map +0 -1
  40. package/dist/chunk-NVSZXEZU.js +0 -2688
  41. package/dist/chunk-NVSZXEZU.js.map +0 -1
  42. package/dist/chunk-PD2WKAFE.js +0 -2531
  43. package/dist/chunk-PD2WKAFE.js.map +0 -1
  44. package/dist/chunk-PGY4ZDLD.js +0 -1843
  45. package/dist/chunk-PGY4ZDLD.js.map +0 -1
  46. package/dist/chunk-QDIAASH7.js +0 -2982
  47. package/dist/chunk-QDIAASH7.js.map +0 -1
  48. package/dist/chunk-UZWFLJGG.js +0 -2873
  49. package/dist/chunk-UZWFLJGG.js.map +0 -1
  50. package/dist/chunk-VFYTROYG.js +0 -2825
  51. package/dist/chunk-VFYTROYG.js.map +0 -1
  52. package/dist/chunk-ZTHKAJKT.js +0 -2981
  53. package/dist/chunk-ZTHKAJKT.js.map +0 -1
  54. package/dist/chunk-ZZULGRRE.js +0 -2991
  55. package/dist/chunk-ZZULGRRE.js.map +0 -1
@@ -0,0 +1,13 @@
1
+ /** One file of the emitted package, keyed by its path inside the directory. */
2
+ interface SkillFile {
3
+ readonly path: string;
4
+ readonly contents: string;
5
+ }
6
+ /** Renders the committed tool inventories from the same registry the server exposes. */
7
+ declare function renderMcpToolSurfaceMarkdown(): string;
8
+ /** Builds the agent-skill package in memory. */
9
+ declare function buildAgentSkill(): readonly SkillFile[];
10
+ /** Writes the package into `directory`, creating it if needed. Returns the paths written. */
11
+ declare function writeAgentSkill(directory: string): Promise<readonly string[]>;
12
+
13
+ export { type SkillFile as S, buildAgentSkill as b, renderMcpToolSurfaceMarkdown as r, writeAgentSkill as w };
package/dist/docs.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { r as renderMcpToolSurfaceMarkdown } from './docs-85fGFORb.js';
package/dist/docs.js ADDED
@@ -0,0 +1,7 @@
1
+ import {
2
+ renderMcpToolSurfaceMarkdown
3
+ } from "./chunk-ROMJP5D3.js";
4
+ export {
5
+ renderMcpToolSurfaceMarkdown
6
+ };
7
+ //# sourceMappingURL=docs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { TermwrightErrorCode, TerminalHarness, AppLogEvent, ExitStatus, EnvMode, LaunchOptions, AppLogSource, Locator } from '@termwright/driver';
1
+ import { TermwrightErrorCode, TerminalHarness, SemanticLocatorRef, AppLogEvent, ExitStatus, EnvMode, LaunchOptions, AppLogSource, AnyLocator } from '@termwright/driver';
2
2
  import { z } from 'zod';
3
+ export { S as SkillFile, b as buildAgentSkill, w as writeAgentSkill } from './docs-85fGFORb.js';
3
4
  import { SemanticSnapshot, Rect, SemanticState, SemanticNode, SemanticRole } from '@termwright/protocol';
4
5
  export { Rect, SEMANTIC_ROLES, SemanticNode, SemanticRole, SemanticSnapshot, SemanticState } from '@termwright/protocol';
5
6
  import { Server } from 'node:http';
@@ -151,16 +152,6 @@ declare function buildAgentContext(): AgentContext;
151
152
  /** The one-screen cheat sheet printed by `termwright-mcp usage`. */
152
153
  declare function buildUsage(): string;
153
154
 
154
- /** One file of the emitted package, keyed by its path inside the directory. */
155
- interface SkillFile {
156
- readonly path: string;
157
- readonly contents: string;
158
- }
159
- /** Builds the agent-skill package in memory. */
160
- declare function buildAgentSkill(): readonly SkillFile[];
161
- /** Writes the package into `directory`, creating it if needed. Returns the paths written. */
162
- declare function writeAgentSkill(directory: string): Promise<readonly string[]>;
163
-
164
155
  /** Where the CLI writes. Injectable so tests never touch the real streams. */
165
156
  interface CliIo {
166
157
  readonly out: (text: string) => void;
@@ -186,8 +177,6 @@ declare function main(): Promise<void>;
186
177
 
187
178
  /** The driver's view of the visible grid. */
188
179
  type ScreenSnapshot = ReturnType<TerminalHarness['screen']>;
189
- /** Session capabilities as reported after the semantic handshake window. */
190
- type SessionCapabilities = ReturnType<TerminalHarness['capabilities']>;
191
180
  /** State flags an agent may filter on; the value type follows {@link SemanticState}. */
192
181
  declare const FILTERABLE_STATES: readonly ["disabled", "focused", "selected", "checked", "expanded", "modal", "busy", "hidden", "readonly"];
193
182
  /** Signals `terminal.signal` accepts, mirroring `TerminalHarness['signal']`. */
@@ -225,20 +214,20 @@ declare function diffSemantic(before: SemanticSnapshot | null, after: SemanticSn
225
214
  * ```
226
215
  * Terminal t1 100x30 revision 42
227
216
  * semanticTree: available
228
- * dialog "Permission" ref=n7@42 bounds=(8,20,40,9) modal
229
- * button "Approve" ref=n8@42 bounds=(14,23,11,1) focused
217
+ * dialog "Permission" ref=semantic:n7@42 bounds=(8,20,40,9) modal
218
+ * button "Approve" ref=semantic:n8@42 bounds=(14,23,11,1) focused
230
219
  * visible text:
231
220
  * <grid text>
232
221
  * ```
233
222
  *
234
223
  * `bounds` is `(row,column,width,height)` — the field order of the protocol's
235
- * `Rect`. Refs are `<nodeId>@<semanticRevision>`, byte-identical to the refs the
224
+ * `Rect`. Refs are `semantic:<nodeId>@<semanticRevision>`, byte-identical to the refs the
236
225
  * driver puts on `ResolvedTarget`, so a ref can be quoted back to any tool.
237
226
  */
238
227
 
239
228
  /** One line of the ref list, plus the structured fields behind it. */
240
229
  interface RefEntry {
241
- readonly ref: string;
230
+ readonly ref: SemanticLocatorRef;
242
231
  readonly role: string;
243
232
  readonly name: string;
244
233
  readonly depth: number;
@@ -246,10 +235,12 @@ interface RefEntry {
246
235
  readonly flags: readonly string[];
247
236
  readonly testId?: string;
248
237
  readonly value?: string;
238
+ readonly applicationScroll?: string;
239
+ readonly paintedRegion?: string;
249
240
  }
250
- /** Formats `n8@42` for a node observed at `revision`. */
251
- declare function formatRef(nodeId: string, revision: number): string;
252
- /** Splits `n8@42` back into its parts; returns `null` for anything else. */
241
+ /** Formats an explicitly semantic ref for a node observed at `revision`. */
242
+ declare function formatRef(nodeId: string, revision: number): SemanticLocatorRef;
243
+ /** Splits a semantic ref back into its parts; screen refs are rejected. */
253
244
  declare function parseRef(ref: string): {
254
245
  readonly nodeId: string;
255
246
  readonly revision: number;
@@ -294,6 +285,13 @@ interface CompactSnapshotOptions {
294
285
  /** Renders the normative compact snapshot. */
295
286
  declare function formatCompactSnapshot(options: CompactSnapshotOptions): string;
296
287
 
288
+ /** Bounded fixed-window admission policy, keyed by the TCP peer address. */
289
+ interface HttpRateLimitOptions {
290
+ readonly windowMs?: number;
291
+ readonly maxRequests?: number;
292
+ readonly maxClients?: number;
293
+ }
294
+
297
295
  /**
298
296
  * The application's own log, on the session timeline.
299
297
  *
@@ -357,6 +355,8 @@ declare class LogBuffer {
357
355
  get size(): number;
358
356
  /** Records one driver event. */
359
357
  append(event: AppLogEvent): void;
358
+ /** Advances the cursor for source events that were explicitly reported lost. */
359
+ omit(count: number): void;
360
360
  /**
361
361
  * Everything after `cursor`, newest-biased and bounded.
362
362
  *
@@ -459,6 +459,8 @@ interface TerminalEntry {
459
459
  readonly directory: string;
460
460
  readonly command: readonly string[];
461
461
  exit: ExitStatus | null;
462
+ /** Backend/lifecycle failure is not a fabricated process exit. */
463
+ exitFailure?: unknown;
462
464
  closed: boolean;
463
465
  history: RevisionRecord[];
464
466
  /** The application's own log, buffered for `terminal.capture_since`. */
@@ -540,6 +542,8 @@ interface RegisteredSession<T> {
540
542
  readonly attachment: T;
541
543
  /** Clock reading of the last request that named this session. */
542
544
  lastSeenAt: number;
545
+ /** One shared cleanup transaction; retained on failure so callers observe it. */
546
+ closing?: Promise<void>;
543
547
  }
544
548
  /** Options for {@link SessionRegistry}. */
545
549
  interface SessionRegistryOptions<T> {
@@ -556,6 +560,8 @@ interface SessionRegistryOptions<T> {
556
560
  readonly disposeAttachment?: (attachment: T) => Promise<void> | void;
557
561
  /** Called after an idle session was torn down, for the server log. */
558
562
  readonly onExpired?: (key: string) => void;
563
+ /** Receives managed sweeper failures; never an unhandled rejection. */
564
+ readonly onBackgroundError?: (error: unknown) => void;
559
565
  }
560
566
  /**
561
567
  * Sessions keyed by `Mcp-Session-Id` (or `stdio` for the stdio transport).
@@ -633,12 +639,26 @@ interface HttpServerHandle {
633
639
  server: McpServer;
634
640
  }>;
635
641
  readonly port: number;
642
+ /** Per-launch bearer required by every HTTP request. Never put it in a URL. */
643
+ readonly authToken: string;
636
644
  close(): Promise<void>;
637
645
  }
638
646
  /** Options for {@link serveHttp}. */
639
647
  interface HttpServeOptions extends ServeOptions {
640
648
  readonly port?: number;
641
649
  readonly host?: string;
650
+ /**
651
+ * Explicit acknowledgement that a non-loopback bind exposes process launch,
652
+ * terminal input and filesystem-backed trace tools to the network.
653
+ */
654
+ readonly allowNonLoopback?: boolean;
655
+ /**
656
+ * Browser origins allowed to call the endpoint. Non-browser MCP clients omit
657
+ * `Origin`; any presented origin is rejected unless it appears here exactly.
658
+ */
659
+ readonly allowedOrigins?: readonly string[];
660
+ /** Per-peer request ceiling. The limiter's identity map is bounded too. */
661
+ readonly rateLimit?: HttpRateLimitOptions;
642
662
  /** Path the MCP endpoint listens on. Defaults to `/mcp`. */
643
663
  readonly path?: string;
644
664
  /**
@@ -696,7 +716,7 @@ interface ScreenshotRequest {
696
716
  *
697
717
  * Failures are typed rather than thrown as raw errors: a scale out of range is
698
718
  * `usage`, an image over the ceiling is `capacity`, and a renderer that cannot
699
- * run at all (no font, no rasteriser) is `unsupported-action` — each with the
719
+ * run at all (no font, no rasteriser) is `capability-unavailable` — each with the
700
720
  * next thing to try.
701
721
  */
702
722
  declare function renderScreenshot(frame: ScreenFrame, request?: ScreenshotRequest): ScreenshotImage;
@@ -785,16 +805,18 @@ declare const TRACE_TOOLS: readonly ToolDefinition[];
785
805
  * from zod-parsed arguments, where an absent key is present-and-undefined.
786
806
  */
787
807
  interface TargetInput {
788
- /** A ref from a previous snapshot: `n8@42`, or `grid:1,2,9,1@7`. */
808
+ /** A domain-tagged ref: `semantic:n8@42`, or `screen:1,2,9,1@7`. */
789
809
  readonly ref?: string | undefined;
790
- /** The Textual-style CSS dialect, e.g. `dialog button#approve:focused`. */
810
+ /** Termwright Semantic Selector Language, e.g. `dialog button#approve:focused`. */
791
811
  readonly selector?: string | undefined;
792
812
  readonly role?: SemanticRole | undefined;
793
813
  /** Accessible name; `/…/flags` is read as a regular expression. */
794
814
  readonly name?: string | undefined;
795
815
  readonly testId?: string | undefined;
796
- /** Visible text (grid matching when there is no semantic tree). */
816
+ /** Text carried by a semantic node. Requires a semantic tree. */
797
817
  readonly text?: string | undefined;
818
+ /** Text rendered in the physical terminal grid. */
819
+ readonly screenText?: string | undefined;
798
820
  /** Label text (`labelledBy`, else name). */
799
821
  readonly label?: string | undefined;
800
822
  readonly exact?: boolean | undefined;
@@ -809,18 +831,18 @@ interface TargetInput {
809
831
  declare function textOrRegExp(value: string): string | RegExp;
810
832
  /**
811
833
  * Builds the locator described by `input`. Precedence is `ref`, `selector`,
812
- * `testId`, `role`, `label`, `text` — the order from most to least specific.
834
+ * `testId`, `role`, `label`, `text`, `screenText` — the order from most to least specific.
813
835
  *
814
836
  * Every branch hands straight to a driver factory; nothing here matches, waits
815
837
  * or decides staleness.
816
838
  */
817
- declare function buildLocator(harness: TerminalHarness, input: TargetInput): Locator;
839
+ declare function buildLocator(harness: TerminalHarness, input: TargetInput): AnyLocator;
818
840
 
819
841
  /** Identity reported over MCP and by `--version`. Kept in step with package.json. */
820
842
  declare const SERVER_NAME = "termwright";
821
843
  /** Package version. */
822
- declare const SERVER_VERSION = "0.1.0";
844
+ declare const SERVER_VERSION = "0.3.0";
823
845
  /** Version of the `agent-context` document shape (independent of the package). */
824
846
  declare const AGENT_CONTEXT_VERSION = 1;
825
847
 
826
- export { AGENT_CONTEXT_VERSION, type AgentContext, type AgentContextTool, type CliIo, type CompactSnapshotOptions, EXIT_CODES, type ErrorKind, type ErrorPayload, FILTERABLE_STATES, type HttpServeOptions, type HttpServerHandle, type JsonSchema, type LaunchRequest, MCP_LIMITS, McpError, type OpenTrace, type RefEntry, type RegisteredSession, type RevisionRecord, type RowChange, type RunningServer, SCREENSHOT_LIMITS, SERVER_NAME, SERVER_VERSION, SIGNALS, type ScreenSnapshot, type ScreenshotImage, type ScreenshotRequest, type ServeOptions, type SessionCapabilities, SessionRegistry, type SessionStores, type SkillFile, type SubtreeChange, TERMINAL_TOOLS, TOOLS, TRACE_LIMITS, TRACE_TOOLS, type TargetInput, type TerminalEntry, TerminalStore, type TerminalStoreOptions, type ToolContext, type ToolDefinition, type ToolOutcome, TraceStore, type TraceStoreOptions, buildAgentContext, buildAgentSkill, buildLocator, buildUsage, closeSessionStores, createSessionStores, createTermwrightMcpServer, defineTool, diffRows, diffSemantic, exitCodeFor, formatBounds, formatCompactSnapshot, formatNodeLine, formatRef, main, noSessionError, parseRef, refEntries, renderErrorPayload, renderScreenshot, runCli, serveHttp, serveInMemory, serveStdio, stateFlags, textOrRegExp, toErrorPayload, toRefEntry, toolByName, usageError, walkSnapshot, writeAgentSkill };
848
+ export { AGENT_CONTEXT_VERSION, type AgentContext, type AgentContextTool, type CliIo, type CompactSnapshotOptions, EXIT_CODES, type ErrorKind, type ErrorPayload, FILTERABLE_STATES, type HttpRateLimitOptions, type HttpServeOptions, type HttpServerHandle, type JsonSchema, type LaunchRequest, MCP_LIMITS, McpError, type OpenTrace, type RefEntry, type RegisteredSession, type RevisionRecord, type RowChange, type RunningServer, SCREENSHOT_LIMITS, SERVER_NAME, SERVER_VERSION, SIGNALS, type ScreenSnapshot, type ScreenshotImage, type ScreenshotRequest, type ServeOptions, SessionRegistry, type SessionStores, type SubtreeChange, TERMINAL_TOOLS, TOOLS, TRACE_LIMITS, TRACE_TOOLS, type TargetInput, type TerminalEntry, TerminalStore, type TerminalStoreOptions, type ToolContext, type ToolDefinition, type ToolOutcome, TraceStore, type TraceStoreOptions, buildAgentContext, buildLocator, buildUsage, closeSessionStores, createSessionStores, createTermwrightMcpServer, defineTool, diffRows, diffSemantic, exitCodeFor, formatBounds, formatCompactSnapshot, formatNodeLine, formatRef, main, noSessionError, parseRef, refEntries, renderErrorPayload, renderScreenshot, runCli, serveHttp, serveInMemory, serveStdio, stateFlags, textOrRegExp, toErrorPayload, toRefEntry, toolByName, usageError, walkSnapshot };
package/dist/index.js CHANGED
@@ -1,3 +1,11 @@
1
+ import {
2
+ createTermwrightMcpServer,
3
+ main,
4
+ runCli,
5
+ serveHttp,
6
+ serveInMemory,
7
+ serveStdio
8
+ } from "./chunk-R2N52YYH.js";
1
9
  import {
2
10
  AGENT_CONTEXT_VERSION,
3
11
  EXIT_CODES,
@@ -22,7 +30,6 @@ import {
22
30
  buildUsage,
23
31
  closeSessionStores,
24
32
  createSessionStores,
25
- createTermwrightMcpServer,
26
33
  defineTool,
27
34
  diffRows,
28
35
  diffSemantic,
@@ -31,16 +38,11 @@ import {
31
38
  formatCompactSnapshot,
32
39
  formatNodeLine,
33
40
  formatRef,
34
- main,
35
41
  noSessionError,
36
42
  parseRef,
37
43
  refEntries,
38
44
  renderErrorPayload,
39
45
  renderScreenshot,
40
- runCli,
41
- serveHttp,
42
- serveInMemory,
43
- serveStdio,
44
46
  stateFlags,
45
47
  textOrRegExp,
46
48
  toErrorPayload,
@@ -49,7 +51,7 @@ import {
49
51
  usageError,
50
52
  walkSnapshot,
51
53
  writeAgentSkill
52
- } from "./chunk-IPNUAUAN.js";
54
+ } from "./chunk-ROMJP5D3.js";
53
55
  export {
54
56
  AGENT_CONTEXT_VERSION,
55
57
  EXIT_CODES,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@termwright/mcp",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "thin MCP server over the public driver API",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "type": "module",
12
12
  "engines": {
13
- "node": ">=22"
13
+ "node": "^22.0.0 || ^24.0.0"
14
14
  },
15
15
  "exports": {
16
16
  ".": {
@@ -27,14 +27,17 @@
27
27
  "dependencies": {
28
28
  "@modelcontextprotocol/sdk": "^1.30.0",
29
29
  "zod": "^4.0.0",
30
- "@termwright/driver": "0.2.0",
31
- "@termwright/protocol": "0.2.0",
32
- "@termwright/screenshot": "0.2.0",
33
- "@termwright/trace": "0.2.0"
30
+ "@termwright/driver": "0.3.0",
31
+ "@termwright/protocol": "0.3.0",
32
+ "@termwright/screenshot": "0.3.0",
33
+ "@termwright/trace": "0.3.0"
34
+ },
35
+ "devDependencies": {
36
+ "@termwright/resource-broker": "0.3.0"
34
37
  },
35
38
  "scripts": {
36
- "build": "tsup src/index.ts src/bin.ts --format esm --dts --sourcemap",
39
+ "build": "tsup src/index.ts src/bin.ts src/docs.ts --format esm --dts --sourcemap --clean",
37
40
  "typecheck": "tsc --noEmit",
38
- "test": "vitest run"
41
+ "test": "pnpm --dir ../.. test -- -- --run packages/mcp"
39
42
  }
40
43
  }