ttyglass 1.0.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [1.0.0] - 2026-09-13
10
+
11
+ ### Added
12
+
13
+ - Run an arbitrary TUI command through a real PTY or Windows ConPTY session and interact with it from a local browser.
14
+ - Preview terminal output with built-in color schemes and dynamic or exact fixed terminal dimensions.
15
+ - Collect bounded, structured application diagnostics separately from terminal output using a dependency-free HTTP contract.
16
+ - Send diagnostics from TypeScript directly or through a JSON-line sink compatible with loggers such as Pino.
17
+ - Guide Codex and Claude Code through safe visual TUI inspection with packaged agent skills.
18
+
19
+ ### Security
20
+
21
+ - Restrict the observer and diagnostics service to loopback, authenticate each session with a fresh token, validate browser origins, and terminate the owned terminal process tree when the session ends.
22
+
23
+ [Unreleased]: https://github.com/MrMaxie/ttyglass/compare/v1.0.0...HEAD
24
+ [1.0.0]: https://github.com/MrMaxie/ttyglass/releases/tag/v1.0.0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ # ttyglass
2
+
3
+ <p align="center">
4
+ <img src="assets/ttyglass-logo.svg" alt="ttyglass" width="240">
5
+ </p>
6
+
7
+ <p align="center">
8
+ Run a real terminal UI in a local browser for visual testing, interaction debugging, and agent-assisted review.
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/ttyglass"><img src="https://img.shields.io/npm/v/ttyglass" alt="npm version"></a>
13
+ <a href="https://github.com/MrMaxie/ttyglass/actions/workflows/publish.yml"><img src="https://github.com/MrMaxie/ttyglass/actions/workflows/publish.yml/badge.svg" alt="CI"></a>
14
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-blue" alt="Apache 2.0 license"></a>
15
+ </p>
16
+
17
+ ttyglass is a native Nim executable that wraps any TUI command in a real PTY or Windows ConPTY session and mirrors it into an authenticated browser page on `127.0.0.1`. The observed project does not need ttyglass configuration, a ttyglass dependency, or source changes.
18
+
19
+ ## Quick start
20
+
21
+ Run a TUI without installing ttyglass:
22
+
23
+ ```sh
24
+ npx ttyglass --open -- lazygit
25
+ ```
26
+
27
+ Or run a project command from another directory:
28
+
29
+ ```sh
30
+ npx ttyglass --open --cwd ../my-app -- npm run tui
31
+ ```
32
+
33
+ Everything before `--` configures ttyglass. Everything after `--` is the command and its arguments.
34
+
35
+ ## Why ttyglass
36
+
37
+ - Observe the real TUI instead of a reconstructed screenshot or text dump.
38
+ - Send keyboard input and resize the underlying PTY from the browser.
39
+ - Preview ANSI output with Catppuccin Mocha, Gruvbox Dark, Nord, Dracula, or Tokyo Night.
40
+ - Switch between a terminal that follows the browser and an exact fixed row and column size.
41
+ - Keep application diagnostics outside the terminal without changing the TUI layout.
42
+ - Give Codex or Claude Code a browser surface it can inspect and interact with safely.
43
+ - Run against an arbitrary project without adding ttyglass to that project.
44
+
45
+ The server binds only to loopback and uses a fresh token for the browser and diagnostics connections. The terminal process is scoped to that ttyglass session.
46
+
47
+ ## Installation
48
+
49
+ The quickest option is `npx`:
50
+
51
+ ```sh
52
+ npx ttyglass -- <command> [arguments...]
53
+ ```
54
+
55
+ Install the command globally if you use it often:
56
+
57
+ ```sh
58
+ npm install --global ttyglass
59
+ ttyglass -- <command> [arguments...]
60
+ ```
61
+
62
+ Nub users can run the same package without installing it:
63
+
64
+ ```sh
65
+ nubx -y ttyglass -- <command> [arguments...]
66
+ ```
67
+
68
+ ttyglass currently requires Node.js 24.18.0.
69
+
70
+ Prebuilt executables are provided for Windows x64, Linux x64 with glibc, macOS x64, and macOS arm64. npm selects the matching optional package; installing ttyglass does not compile Nim or native code.
71
+
72
+ ## Usage
73
+
74
+ ```text
75
+ ttyglass [options] -- <command> [arguments...]
76
+ ```
77
+
78
+ Examples:
79
+
80
+ ```sh
81
+ npx ttyglass -- lazygit
82
+ npx ttyglass --open -- btop
83
+ npx ttyglass --cwd ../app -- npm run tui
84
+ npx ttyglass --port 4173 -- cargo run
85
+ ```
86
+
87
+ ttyglass prints an authenticated URL such as `http://127.0.0.1:4173/#token=...`. Open that exact URL unless `--open` already opened it.
88
+
89
+ | Option | Description |
90
+ | --- | --- |
91
+ | `--cwd <path>` | Run the observed command from this directory. |
92
+ | `--port <number>` | Use a fixed loopback port instead of an available port. |
93
+ | `--diagnostics-limit <count>` | Keep between 1 and 5000 application diagnostic entries. The default is 500. |
94
+ | `--open` | Open the authenticated browser URL after startup. |
95
+ | `--no-open` | Print the URL without opening a browser. This is the default. |
96
+ | `-h`, `--help` | Show command help. |
97
+ | `--version` | Show the installed package version. |
98
+
99
+ ## Terminal display
100
+
101
+ Open Display to change how the observed terminal is rendered. Color schemes remap ANSI, indexed, and application-supplied RGB colors inside the TUI without changing the ttyglass interface.
102
+
103
+ Dynamic sizing follows the available browser space. Fixed sizing keeps the exact columns and rows you enter and makes the browser terminal viewport scrollable when necessary. Opening Diagnostics never covers terminal content.
104
+
105
+ ## Application diagnostics
106
+
107
+ Every observed command receives `TTYGLASS_DIAGNOSTICS_URL` and `TTYGLASS_DIAGNOSTICS_TOKEN`. The application can send JSON or newline-delimited JSON to that loopback endpoint using only its language standard library.
108
+
109
+ Diagnostics are optional, bounded in memory, and visible only for the current session. ttyglass does not put its own lifecycle or resize events in the Diagnostics panel.
110
+
111
+ See [Diagnostics without a ttyglass library](docs/diagnostics.md) for the record format and dependency-free Node.js and Python examples.
112
+
113
+ ## TypeScript API
114
+
115
+ TypeScript applications can import a direct diagnostic sender or a JSON-line sink compatible with loggers such as Pino:
116
+
117
+ ```ts
118
+ import { createTtyglassSink, sendTtyglassDiagnostic } from 'ttyglass';
119
+
120
+ await sendTtyglassDiagnostic({
121
+ source: 'checkout',
122
+ level: 'info',
123
+ event: 'screen.loaded',
124
+ fields: { items: 3 },
125
+ });
126
+
127
+ const sink = createTtyglassSink({ source: 'checkout' });
128
+ ```
129
+
130
+ Both APIs are no-ops by default outside a ttyglass session. See [Optional TypeScript diagnostics](docs/typescript.md) for integration details.
131
+
132
+ ## Agent use
133
+
134
+ The npm package includes dedicated [Codex and Claude Code skills](skills/README.md). They explain how an agent should start ttyglass, inspect the rendered TUI, collect diagnostics, state what it actually verified, and clean up the session.
135
+
136
+ ## Development
137
+
138
+ The runtime core is Nim 2.2.12. It owns the CLI, local server, WebSocket transport, diagnostics ingestion, PTY or ConPTY bridge, process cleanup, and embedded browser assets. TypeScript is limited to the npm launcher, optional diagnostics helpers, tests, and repository scripts. Svelte is limited to the browser UI.
139
+
140
+ ```sh
141
+ nimble install --depsOnly --accept
142
+ nub install
143
+ just fmt
144
+ just check
145
+ just build
146
+ just test
147
+ just package-check
148
+ ```
149
+
150
+ `just package-check` builds the publishable tarball, validates its contents, runs the packaged CLI through `npx`, exercises a real terminal and diagnostics session, and imports the public TypeScript API from a clean consumer project.
151
+
152
+ Native dependencies are pinned in `ttyglass.nimble` and `nimble.lock`. npm and frontend dependencies are pinned in their manifests and `nub.lock`.
153
+
154
+ Releases follow [Semantic Versioning](https://semver.org/). See [CHANGELOG.md](CHANGELOG.md) for notable changes.
155
+
156
+ ## License
157
+
158
+ ttyglass is licensed under the [Apache License 2.0](LICENSE).
@@ -0,0 +1,41 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="92 92 328 334" role="img" aria-label="TTYGlass logo">
2
+ <path fill="#6EADBC" fill-rule="evenodd" d="
3
+ M156 92
4
+ C118 92 92 118 92 156
5
+ V318
6
+ C92 343 104 362 125 373
7
+ L154 327
8
+ H150
9
+ C142 327 136 321 136 313
10
+ V169
11
+ C136 157 145 148 157 148
12
+ H355
13
+ C367 148 376 157 376 169
14
+ V313
15
+ C376 321 370 327 362 327
16
+ H358
17
+ L387 373
18
+ C408 362 420 343 420 318
19
+ V156
20
+ C420 118 394 92 356 92
21
+ Z
22
+
23
+ M220 278
24
+ H292
25
+ L311 306
26
+ H201
27
+ Z
28
+
29
+ M194 322
30
+ H318
31
+ L344 360
32
+ H168
33
+ Z
34
+
35
+ M163 377
36
+ H349
37
+ L382 426
38
+ H130
39
+ Z
40
+ "/>
41
+ </svg>
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from 'node:child_process';
3
+ import { createRequire } from 'node:module';
4
+ import { dirname, resolve } from 'node:path';
5
+ const targets = new Map([
6
+ ['win32:x64', { executable: 'ttyglass.exe', packageName: '@maxiedev/ttyglass-win32-x64' }],
7
+ ['linux:x64', { executable: 'ttyglass', packageName: '@maxiedev/ttyglass-linux-x64-gnu' }],
8
+ ['darwin:x64', { executable: 'ttyglass', packageName: '@maxiedev/ttyglass-darwin-x64' }],
9
+ ['darwin:arm64', { executable: 'ttyglass', packageName: '@maxiedev/ttyglass-darwin-arm64' }],
10
+ ]);
11
+ const target = targets.get(`${process.platform}:${process.arch}`);
12
+ if (target === undefined) {
13
+ process.stderr.write(`ttyglass: unsupported platform ${process.platform}/${process.arch}\n`);
14
+ process.exitCode = 1;
15
+ }
16
+ else {
17
+ const require = createRequire(import.meta.url);
18
+ let manifestPath;
19
+ try {
20
+ manifestPath = require.resolve(`${target.packageName}/package.json`);
21
+ }
22
+ catch {
23
+ process.stderr.write(`ttyglass: the native package ${target.packageName} is missing. Reinstall ttyglass without --no-optional.\n`);
24
+ process.exit(1);
25
+ }
26
+ const executable = resolve(dirname(manifestPath), 'bin', target.executable);
27
+ const child = spawn(executable, process.argv.slice(2), {
28
+ stdio: 'inherit',
29
+ windowsHide: true,
30
+ });
31
+ child.once('error', (error) => {
32
+ process.stderr.write(`ttyglass: could not start the native executable: ${error.message}\n`);
33
+ process.exitCode = 1;
34
+ });
35
+ child.once('exit', (code, signal) => {
36
+ if (signal !== null) {
37
+ process.kill(process.pid, signal);
38
+ return;
39
+ }
40
+ process.exitCode = code ?? 1;
41
+ });
42
+ }
43
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAO7C,MAAM,OAAO,GAAG,IAAI,GAAG,CAAuB;IAC5C,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,8BAA8B,EAAE,CAAC;IAC1F,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,kCAAkC,EAAE,CAAC;IAC1F,CAAC,YAAY,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,+BAA+B,EAAE,CAAC;IACxF,CAAC,cAAc,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,iCAAiC,EAAE,CAAC;CAC7F,CAAC,CAAC;AAEH,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AAClE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;IACzB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC,OAAO,CAAC,QAAQ,IA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,IAAI,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { DiagnosticRecord } from './types.js';
2
+ export interface SendDiagnosticOptions {
3
+ endpoint?: string;
4
+ token?: string;
5
+ timeoutMilliseconds?: number;
6
+ throwOnError?: boolean;
7
+ fetchImplementation?: typeof fetch;
8
+ }
9
+ export interface TtyglassSinkOptions extends SendDiagnosticOptions {
10
+ source?: string;
11
+ onError?: (error: unknown) => void;
12
+ }
13
+ export interface TtyglassSink {
14
+ write(chunk: string | Uint8Array): boolean;
15
+ flush(): Promise<void>;
16
+ }
17
+ export declare function sendTtyglassDiagnostic(record: DiagnosticRecord, options?: SendDiagnosticOptions): Promise<boolean>;
18
+ export declare function createTtyglassSink(options?: TtyglassSinkOptions): TtyglassSink;
19
+ //# sourceMappingURL=diagnostics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEpE,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,mBAAmB,CAAC,EAAE,OAAO,KAAK,CAAC;CACpC;AAED,MAAM,WAAW,mBAAoB,SAAQ,qBAAqB;IAChE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACpC;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC;IAC3C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAgCD,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,gBAAgB,EACxB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,OAAO,CAAC,CA2BlB;AAwCD,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,mBAAwB,GAAG,YAAY,CAqClF"}
@@ -0,0 +1,126 @@
1
+ const pinoLevels = new Map([
2
+ [10, 'trace'],
3
+ [20, 'debug'],
4
+ [30, 'info'],
5
+ [40, 'warn'],
6
+ [50, 'error'],
7
+ [60, 'fatal'],
8
+ ]);
9
+ function isLoopbackEndpoint(endpoint) {
10
+ try {
11
+ const url = new URL(endpoint);
12
+ return (url.protocol === 'http:' &&
13
+ (url.hostname === '127.0.0.1' || url.hostname === 'localhost' || url.hostname === '[::1]'));
14
+ }
15
+ catch {
16
+ return false;
17
+ }
18
+ }
19
+ function resolveConnection(options) {
20
+ const endpoint = options.endpoint ?? process.env.TTYGLASS_DIAGNOSTICS_URL;
21
+ const token = options.token ?? process.env.TTYGLASS_DIAGNOSTICS_TOKEN;
22
+ if (endpoint === undefined || token === undefined || !isLoopbackEndpoint(endpoint)) {
23
+ return undefined;
24
+ }
25
+ return { endpoint, token };
26
+ }
27
+ export async function sendTtyglassDiagnostic(record, options = {}) {
28
+ const connection = resolveConnection(options);
29
+ if (connection === undefined) {
30
+ return false;
31
+ }
32
+ try {
33
+ const fetchImplementation = options.fetchImplementation ?? fetch;
34
+ const response = await fetchImplementation(connection.endpoint, {
35
+ method: 'POST',
36
+ headers: {
37
+ Authorization: `Bearer ${connection.token}`,
38
+ 'Content-Type': 'application/json',
39
+ },
40
+ body: JSON.stringify(record),
41
+ signal: AbortSignal.timeout(options.timeoutMilliseconds ?? 1_000),
42
+ });
43
+ if (!response.ok) {
44
+ throw new Error(`ttyglass diagnostics returned HTTP ${response.status}`);
45
+ }
46
+ return true;
47
+ }
48
+ catch (error) {
49
+ if (options.throwOnError === true) {
50
+ throw error;
51
+ }
52
+ return false;
53
+ }
54
+ }
55
+ function fromJsonLine(line, source) {
56
+ try {
57
+ const parsed = JSON.parse(line);
58
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
59
+ return { ...(source === undefined ? {} : { source }), event: 'log', message: line };
60
+ }
61
+ const input = parsed;
62
+ const fields = { ...input };
63
+ delete fields.time;
64
+ delete fields.level;
65
+ delete fields.name;
66
+ delete fields.source;
67
+ delete fields.event;
68
+ delete fields.msg;
69
+ delete fields.message;
70
+ const time = input.time;
71
+ const recordSource = typeof input.source === 'string' ? input.source : typeof input.name === 'string' ? input.name : source;
72
+ const message = typeof input.message === 'string' ? input.message : typeof input.msg === 'string' ? input.msg : undefined;
73
+ return {
74
+ ...(typeof time === 'string' || typeof time === 'number' ? { time } : {}),
75
+ ...(recordSource === undefined ? {} : { source: recordSource }),
76
+ level: typeof input.level === 'number'
77
+ ? (pinoLevels.get(input.level) ?? 'info')
78
+ : typeof input.level === 'string'
79
+ ? input.level
80
+ : 'info',
81
+ event: typeof input.event === 'string' ? input.event : 'log',
82
+ ...(message === undefined ? {} : { message }),
83
+ fields,
84
+ };
85
+ }
86
+ catch {
87
+ return { ...(source === undefined ? {} : { source }), event: 'log', message: line };
88
+ }
89
+ }
90
+ export function createTtyglassSink(options = {}) {
91
+ let buffered = '';
92
+ let pending = Promise.resolve();
93
+ function enqueue(line) {
94
+ if (line.length === 0) {
95
+ return;
96
+ }
97
+ const record = fromJsonLine(line, options.source);
98
+ pending = pending
99
+ .then(async () => {
100
+ await sendTtyglassDiagnostic(record, { ...options, throwOnError: true });
101
+ })
102
+ .catch((error) => {
103
+ options.onError?.(error);
104
+ });
105
+ }
106
+ return {
107
+ write(chunk) {
108
+ buffered += typeof chunk === 'string' ? chunk : new TextDecoder().decode(chunk);
109
+ for (;;) {
110
+ const newline = buffered.indexOf('\n');
111
+ if (newline < 0) {
112
+ break;
113
+ }
114
+ enqueue(buffered.slice(0, newline).trimEnd());
115
+ buffered = buffered.slice(newline + 1);
116
+ }
117
+ return true;
118
+ },
119
+ async flush() {
120
+ enqueue(buffered.trimEnd());
121
+ buffered = '';
122
+ await pending;
123
+ },
124
+ };
125
+ }
126
+ //# sourceMappingURL=diagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAoBA,MAAM,UAAU,GAAG,IAAI,GAAG,CAA0B;IAClD,CAAC,EAAE,EAAE,OAAO,CAAC;IACb,CAAC,EAAE,EAAE,OAAO,CAAC;IACb,CAAC,EAAE,EAAE,MAAM,CAAC;IACZ,CAAC,EAAE,EAAE,MAAM,CAAC;IACZ,CAAC,EAAE,EAAE,OAAO,CAAC;IACb,CAAC,EAAE,EAAE,OAAO,CAAC;CACd,CAAC,CAAC;AAEH,SAAS,kBAAkB,CAAC,QAAgB;IAC1C,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC9B,OAAO,CACL,GAAG,CAAC,QAAQ,KAAK,OAAO;YACxB,CAAC,GAAG,CAAC,QAAQ,KAAK,WAAW,IAAI,GAAG,CAAC,QAAQ,KAAK,WAAW,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,CAAC,CAC3F,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,OAA8B;IACvD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC;IAC1E,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC;IACtE,IAAI,QAAQ,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnF,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AA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E,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3E,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YACxB,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;IACP,CAAC;IAED,OAAO;QACL,KAAK,CAAC,KAAK;YACT,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAChF,SAAS,CAAC;gBACR,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBACvC,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;oBAChB,MAAM;gBACR,CAAC;gBACD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;gBAC9C,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;YACzC,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KAAK,CAAC,KAAK;YACT,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;YAC5B,QAAQ,GAAG,EAAE,CAAC;YACd,MAAM,OAAO,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ export type { SendDiagnosticOptions, TtyglassSink, TtyglassSinkOptions, } from './diagnostics.js';
2
+ export { createTtyglassSink, sendTtyglassDiagnostic } from './diagnostics.js';
3
+ export type { DiagnosticLevel, DiagnosticRecord, NormalizedDiagnosticRecord, } from './types.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,qBAAqB,EACrB,YAAY,EACZ,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,0BAA0B,GAC3B,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { createTtyglassSink, sendTtyglassDiagnostic } from './diagnostics.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,18 @@
1
+ export type DiagnosticLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
2
+ export interface DiagnosticRecord {
3
+ time?: string | number | Date;
4
+ source?: string;
5
+ level?: DiagnosticLevel | number;
6
+ event?: string;
7
+ message?: string;
8
+ fields?: Record<string, unknown>;
9
+ }
10
+ export interface NormalizedDiagnosticRecord {
11
+ time: string;
12
+ source: string;
13
+ level: DiagnosticLevel;
14
+ event: string;
15
+ message?: string;
16
+ fields: Record<string, unknown>;
17
+ }
18
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAEtF,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,eAAe,GAAG,MAAM,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,eAAe,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,79 @@
1
+ # Diagnostics without a ttyglass library
2
+
3
+ ttyglass keeps application diagnostics separate from the terminal stream and from ttyglass's own process state. The Diagnostics panel contains only records submitted by the observed application. Every observed command receives two environment variables:
4
+
5
+ - `TTYGLASS_DIAGNOSTICS_URL`: a loopback-only HTTP endpoint for the current run.
6
+ - `TTYGLASS_DIAGNOSTICS_TOKEN`: the bearer token for that endpoint.
7
+
8
+ Send either one JSON object with `Content-Type: application/json` or newline-delimited JSON. Use this record shape:
9
+
10
+ ```json
11
+ {
12
+ "time": "2026-09-12T12:00:00.000Z",
13
+ "source": "checkout",
14
+ "level": "info",
15
+ "event": "screen.loaded",
16
+ "message": "Checkout screen is ready",
17
+ "fields": {
18
+ "items": 3
19
+ }
20
+ }
21
+ ```
22
+
23
+ All fields are optional. `level` accepts `trace`, `debug`, `info`, `warn`, `error`, or `fatal`. Unknown top-level fields are ignored. `fields` must contain JSON values, with at most 32 entries per object or array and at most three nested container levels. A request may contain up to 100 records and 64 KiB.
24
+
25
+ ## Node.js standard library
26
+
27
+ ```js
28
+ import { request } from 'node:http';
29
+
30
+ export function ttyglassDiagnostic(record) {
31
+ const endpoint = process.env.TTYGLASS_DIAGNOSTICS_URL;
32
+ const token = process.env.TTYGLASS_DIAGNOSTICS_TOKEN;
33
+ if (!endpoint || !token) return;
34
+
35
+ const body = JSON.stringify(record);
36
+ const outgoing = request(endpoint, {
37
+ method: 'POST',
38
+ headers: {
39
+ Authorization: `Bearer ${token}`,
40
+ 'Content-Type': 'application/json',
41
+ 'Content-Length': Buffer.byteLength(body),
42
+ },
43
+ });
44
+ outgoing.on('error', () => {});
45
+ outgoing.end(body);
46
+ }
47
+ ```
48
+
49
+ ## Python standard library
50
+
51
+ ```python
52
+ import json
53
+ import os
54
+ import urllib.request
55
+
56
+
57
+ def ttyglass_diagnostic(record):
58
+ endpoint = os.environ.get("TTYGLASS_DIAGNOSTICS_URL")
59
+ token = os.environ.get("TTYGLASS_DIAGNOSTICS_TOKEN")
60
+ if not endpoint or not token:
61
+ return
62
+
63
+ body = json.dumps(record).encode("utf-8")
64
+ request = urllib.request.Request(
65
+ endpoint,
66
+ data=body,
67
+ method="POST",
68
+ headers={
69
+ "Authorization": f"Bearer {token}",
70
+ "Content-Type": "application/json",
71
+ },
72
+ )
73
+ try:
74
+ urllib.request.urlopen(request, timeout=1).close()
75
+ except OSError:
76
+ pass
77
+ ```
78
+
79
+ Logging is optional and should never stop the observed application. Do not include secrets, credentials, personal data, or unrelated environment values. ttyglass keeps a bounded in-memory history for the current run and does not upload it.
@@ -0,0 +1,37 @@
1
+ # Optional TypeScript diagnostics
2
+
3
+ The package exports a direct sender and a small writable sink. Both are no-ops by default when the application does not run under ttyglass.
4
+
5
+ ## Direct events
6
+
7
+ ```ts
8
+ import { sendTtyglassDiagnostic } from 'ttyglass';
9
+
10
+ await sendTtyglassDiagnostic({
11
+ source: 'checkout',
12
+ level: 'info',
13
+ event: 'screen.loaded',
14
+ fields: { items: 3 },
15
+ });
16
+ ```
17
+
18
+ ## Pino destination
19
+
20
+ ttyglass does not depend on Pino. Its sink implements the `write(string)` destination contract used by Pino and other JSON-line loggers.
21
+
22
+ ```ts
23
+ import pino from 'pino';
24
+ import { createTtyglassSink } from 'ttyglass';
25
+
26
+ const ttyglass = createTtyglassSink({ source: 'checkout' });
27
+ const logger = pino(ttyglass);
28
+
29
+ logger.info({ items: 3 }, 'Checkout screen is ready');
30
+
31
+ // Flush only when the process already has an orderly shutdown path.
32
+ await ttyglass.flush();
33
+ ```
34
+
35
+ The sink maps Pino numeric levels and moves `time`, `level`, `name`, `msg`, and `message` into ttyglass record fields. Remaining JSON properties become diagnostic `fields`.
36
+
37
+ If a logger cannot accept a writable destination, call `sendTtyglassDiagnostic` from a temporary adapter instead. Remove the adapter when visual debugging no longer needs those events.
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "ttyglass",
3
+ "version": "1.0.0",
4
+ "description": "Observe and debug real terminal user interfaces in a local browser.",
5
+ "keywords": [
6
+ "tui",
7
+ "terminal",
8
+ "pty",
9
+ "debugging",
10
+ "developer-tools"
11
+ ],
12
+ "license": "Apache-2.0",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/MrMaxie/ttyglass.git"
16
+ },
17
+ "homepage": "https://github.com/MrMaxie/ttyglass#readme",
18
+ "bugs": {
19
+ "url": "https://github.com/MrMaxie/ttyglass/issues"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public",
23
+ "provenance": true
24
+ },
25
+ "type": "module",
26
+ "engines": {
27
+ "node": "24.18.0"
28
+ },
29
+ "packageManager": "nub@0.7.5",
30
+ "workspaces": [
31
+ "frontend",
32
+ "packages/*"
33
+ ],
34
+ "bin": {
35
+ "ttyglass": "dist/cli.js"
36
+ },
37
+ "exports": {
38
+ ".": {
39
+ "types": "./dist/index.d.ts",
40
+ "import": "./dist/index.js"
41
+ },
42
+ "./package.json": "./package.json"
43
+ },
44
+ "files": [
45
+ "assets/ttyglass-logo.svg",
46
+ "dist",
47
+ "docs",
48
+ "skills",
49
+ "CHANGELOG.md",
50
+ "LICENSE",
51
+ "README.md"
52
+ ],
53
+ "scripts": {
54
+ "build": "node scripts/clean.ts && nub --filter @ttyglass/frontend run build && node scripts/build-native.ts && tsc -p tsconfig.node.json",
55
+ "check": "nub --filter @ttyglass/frontend run check && biome check src test tests scripts && tsc --noEmit -p tsconfig.node.json && nimble check && nimble c --compileOnly --path:src test/test_diagnostics.nim && nimble c --compileOnly --path:src test/test_ipc.nim",
56
+ "format": "nub --filter @ttyglass/frontend run format && biome format --write src test tests scripts",
57
+ "package:check": "nub run check && nub run test && node scripts/verify-package.ts",
58
+ "package:check:published": "node scripts/verify-package.ts --published",
59
+ "prepack": "nub run build",
60
+ "prepublishOnly": "nub run package:check",
61
+ "pretest": "nub run build",
62
+ "test": "nimble c -r --path:src --nimcache:.local/nimcache/test-diagnostics --out:.local/test-diagnostics test/test_diagnostics.nim && nimble c -r --path:src --nimcache:.local/nimcache/test-ipc --out:.local/test-ipc test/test_ipc.nim && node --test test/*.test.ts",
63
+ "ttyglass": "node dist/cli.js"
64
+ },
65
+ "optionalDependencies": {
66
+ "@maxiedev/ttyglass-darwin-arm64": "1.0.0",
67
+ "@maxiedev/ttyglass-darwin-x64": "1.0.0",
68
+ "@maxiedev/ttyglass-linux-x64-gnu": "1.0.0",
69
+ "@maxiedev/ttyglass-win32-x64": "1.0.0"
70
+ },
71
+ "devDependencies": {
72
+ "@biomejs/biome": "2.5.13",
73
+ "@types/node": "22.20.2",
74
+ "typescript": "7.0.2"
75
+ }
76
+ }
@@ -0,0 +1,8 @@
1
+ # Agent skills
2
+
3
+ ttyglass includes separate skill entrypoints for Codex and Claude Code:
4
+
5
+ - `skills/codex/SKILL.md`
6
+ - `skills/claude/SKILL.md`
7
+
8
+ Copy or link the appropriate directory into the skill location used by the agent installation. Keep the package copy as the source of truth so the agent guidance stays aligned with the installed ttyglass version.
@@ -0,0 +1,28 @@
1
+ ---
2
+ name: ttyglass
3
+ description: Run and inspect a real terminal user interface in ttyglass when Claude Code needs visual evidence, keyboard interaction, resize verification, or separate diagnostics without modifying the observed project.
4
+ ---
5
+
6
+ # Inspect a TUI with ttyglass
7
+
8
+ Use ttyglass to let Claude Code see and operate a real TUI through a local browser. It is for visual assessment, interaction debugging, responsive terminal checks, and diagnostics that must remain separate from the terminal screen.
9
+
10
+ ## Workflow
11
+
12
+ 1. Identify the exact project command that normally starts the TUI. Do not create a mock screen or project-specific wrapper.
13
+ 2. From the tested project directory, run `ttyglass -- <command> <arguments>`. Put ttyglass options before `--` and preserve the tested command after it.
14
+ 3. Read the authenticated loopback URL printed by ttyglass and open that exact URL with an available browser tool.
15
+ 4. Verify the real rendered state before interacting. Exercise only actions authorized by the user.
16
+ 5. Check relevant terminal sizes, keyboard navigation, focus, errors, loading and empty states, and process exit behavior. Use Diagnostics for investigation data, not as a substitute for the visible TUI.
17
+ 6. Capture evidence only when requested or required by the parent task. State which states and sizes were actually observed.
18
+ 7. Close the browser client and stop ttyglass when finished. Confirm the observed process ended.
19
+
20
+ ## Safety
21
+
22
+ - ttyglass is a local observation tool, not authorization to mutate project or external state.
23
+ - Use the exact loopback URL printed for the current run. Never expose it, its fragment token, or diagnostics token outside the local task.
24
+ - Do not put credentials, personal data, complete environment dumps, or unrelated project content in diagnostics.
25
+ - Do not claim native terminal behavior from a static mock or DOM-only recreation. ttyglass must be connected to the real PTY or ConPTY process.
26
+ - If browser automation is unavailable, report that visual interaction remains unverified instead of inferring it from tests.
27
+
28
+ See the package `README.md` for CLI options and `docs/diagnostics.md` for dependency-free diagnostic records.
@@ -0,0 +1,28 @@
1
+ ---
2
+ name: ttyglass
3
+ description: Run and inspect a real terminal user interface in ttyglass when Codex needs visual evidence, keyboard interaction, resize verification, or separate diagnostics without modifying the observed project.
4
+ ---
5
+
6
+ # Inspect a TUI with ttyglass
7
+
8
+ Use ttyglass to let Codex see and operate a real TUI through a local browser. It is for visual assessment, interaction debugging, responsive terminal checks, and diagnostics that must remain separate from the terminal screen.
9
+
10
+ ## Workflow
11
+
12
+ 1. Identify the exact project command that normally starts the TUI. Do not create a mock screen or project-specific wrapper.
13
+ 2. From the tested project directory, run `ttyglass -- <command> <arguments>`. Put ttyglass options before `--` and preserve the tested command after it.
14
+ 3. Read the authenticated loopback URL printed by ttyglass and open that exact URL in the available Codex browser.
15
+ 4. Verify the real rendered state before interacting. Exercise only actions authorized by the user.
16
+ 5. Check relevant terminal sizes, keyboard navigation, focus, errors, loading and empty states, and process exit behavior. Use Diagnostics for investigation data, not as a substitute for the visible TUI.
17
+ 6. Capture evidence only when requested or required by the parent task. State which states and sizes were actually observed.
18
+ 7. Close the browser client and stop ttyglass when finished. Confirm the observed process ended.
19
+
20
+ ## Safety
21
+
22
+ - ttyglass is a local observation tool, not authorization to mutate project or external state.
23
+ - Use the exact loopback URL printed for the current run. Never expose it, its fragment token, or diagnostics token outside the local task.
24
+ - Do not put credentials, personal data, complete environment dumps, or unrelated project content in diagnostics.
25
+ - Do not claim native terminal behavior from a static mock or DOM-only recreation. ttyglass must be connected to the real PTY or ConPTY process.
26
+ - If browser automation is unavailable, report that visual interaction remains unverified instead of inferring it from tests.
27
+
28
+ See the package `README.md` for CLI options and `docs/diagnostics.md` for dependency-free diagnostic records.