oc-flight-deck 0.10.1 → 0.10.2
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 +7 -0
- package/package.json +1 -1
- package/src/tui/clipboard.ts +135 -30
- package/src/tui/host-clipboard.ts +9 -0
- package/src/tui/index.tsx +18 -13
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@ All notable changes to this project are documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.10.2] - 2026-10-02
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- The `ses` row's click-to-copy now actually copies. It previously treated the renderer's OSC52 `attempted` status as success and reported "Sent the full session id ... to the clipboard" - but `attempted` only proves a local dispatch was issued, and the terminal may never act on it (verified: the bytes are emitted and the clipboard is left unchanged). The copy now prefers the host clipboard backend and reports success only when that write is confirmed (`written`); the OSC52 path is a best-effort dispatch that is never reported as a copy. Every non-confirmed outcome states plainly that the id was not copied.
|
|
13
|
+
|
|
8
14
|
## [0.10.1] - 2026-10-02
|
|
9
15
|
|
|
10
16
|
### Fixed
|
|
@@ -17,5 +23,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
17
23
|
|
|
18
24
|
- Opt-in `ses` sidebar row: shows the full session id (the rail wraps it), and a mouse click copies that same full id and reports the outcome - a confirmation naming the id when the copy was sent, a distinct failure message when the terminal cannot take it. Off by default, and degrades gracefully when the terminal cannot copy.
|
|
19
25
|
|
|
26
|
+
[0.10.2]: https://github.com/nathwn12/oc-flight-deck/compare/v0.10.1...v0.10.2
|
|
20
27
|
[0.10.1]: https://github.com/nathwn12/oc-flight-deck/compare/v0.10.0...v0.10.1
|
|
21
28
|
[0.10.0]: https://github.com/nathwn12/oc-flight-deck/compare/v0.9.0...v0.10.0
|
package/package.json
CHANGED
package/src/tui/clipboard.ts
CHANGED
|
@@ -1,32 +1,63 @@
|
|
|
1
1
|
// The one clipboard write in the plugin: a session id, copied on a gesture.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
// renderer OpenTUI already hands the plugin and writes OSC52 directly. That is
|
|
5
|
-
// not a sanctioned plugin API, so it is kept to a single narrow function and
|
|
6
|
-
// two rules hold it in place:
|
|
3
|
+
// Two transports are available, and they are not equals:
|
|
7
4
|
//
|
|
8
|
-
// 1.
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
5
|
+
// 1. The process host clipboard (`createHostClipboard`). This is a real write
|
|
6
|
+
// through the OS clipboard, it resolves asynchronously, and it can report
|
|
7
|
+
// `written` - a status that means the platform completed the copy. Only
|
|
8
|
+
// this transport may ever be reported to the user as a success.
|
|
9
|
+
// 2. OSC52 through the renderer (`createRendererClipboardAdapter`). This is a
|
|
10
|
+
// fire-and-forget escape sequence emitted on the terminal's wire. Its
|
|
11
|
+
// `attempted` status confirms only that a local dispatch was issued - the
|
|
12
|
+
// terminal is free to ignore it, and on this machine's Windows Terminal it
|
|
13
|
+
// does, so an independent read still sees the old clipboard. It is kept as
|
|
14
|
+
// a best-effort fallback and is NEVER reported as a verified copy.
|
|
12
15
|
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
16
|
+
// The gesture is still the one and only trigger: there is no render-time,
|
|
17
|
+
// background, or automatic write, ever. And nothing here may throw out of the
|
|
18
|
+
// caller's mouse handler: every backend call is wrapped, and a backend that is
|
|
19
|
+
// missing, refuses, or throws degrades to a definite non-success result.
|
|
17
20
|
|
|
18
21
|
import { createRendererClipboardAdapter } from "@opentui/core";
|
|
22
|
+
import { createHostClipboard } from "./host-clipboard.js";
|
|
19
23
|
|
|
20
24
|
type RendererBoundary = Parameters<typeof createRendererClipboardAdapter>[0];
|
|
21
25
|
|
|
22
26
|
/**
|
|
23
|
-
*
|
|
27
|
+
* The outcome of a copy gesture.
|
|
24
28
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
29
|
+
* `verified` is true only when the host backend reported `written`. Every other
|
|
30
|
+
* value - including an OSC52 dispatch that was merely issued - is false, so the
|
|
31
|
+
* caller can never accidentally treat a best-effort attempt as a real copy.
|
|
28
32
|
*/
|
|
29
|
-
export
|
|
33
|
+
export interface CopyResult {
|
|
34
|
+
/** True only for a verified host write. */
|
|
35
|
+
readonly verified: boolean;
|
|
36
|
+
/** How the copy was carried, or why it was not. */
|
|
37
|
+
readonly outcome:
|
|
38
|
+
| "written"
|
|
39
|
+
| "unsupported"
|
|
40
|
+
| "cancelled"
|
|
41
|
+
| "timed-out"
|
|
42
|
+
| "failed"
|
|
43
|
+
| "osc52-dispatched"
|
|
44
|
+
| "no-backend";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The subset of the host clipboard service this path uses. */
|
|
48
|
+
interface HostClipboardLike {
|
|
49
|
+
writeText(text: string): Promise<{ readonly status: string }>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** A factory for the host clipboard; injectable so tests can stand in a fake. */
|
|
53
|
+
type HostClipboardFactory = () => HostClipboardLike;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Determine the OSC52 dispatch outcome for `text`, or `false` when the
|
|
57
|
+
* renderer cannot take it. Kept separate so the renderer type can stay
|
|
58
|
+
* `unknown` at the public boundary.
|
|
59
|
+
*/
|
|
60
|
+
function dispatchOsc52(renderer: unknown, text: string): boolean {
|
|
30
61
|
if (renderer === undefined || renderer === null) return false;
|
|
31
62
|
try {
|
|
32
63
|
const terminal = createRendererClipboardAdapter(renderer as RendererBoundary);
|
|
@@ -36,28 +67,102 @@ export function copyToClipboard(renderer: unknown, text: string): boolean {
|
|
|
36
67
|
}
|
|
37
68
|
}
|
|
38
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Write `text` to the clipboard, preferring the verified host backend.
|
|
72
|
+
*
|
|
73
|
+
* Resolution:
|
|
74
|
+
* 1. Try the host clipboard write and await it. `written` -> `verified: true`.
|
|
75
|
+
* 2. If the host is unavailable or reports anything other than `written`, issue
|
|
76
|
+
* the OSC52 fallback and report `osc52-dispatched`. That is a best-effort
|
|
77
|
+
* dispatch, NOT a verified copy, so `verified` stays false.
|
|
78
|
+
* 3. If neither transport can take the write, report `no-backend`.
|
|
79
|
+
*
|
|
80
|
+
* Never throws: a backend that rejects, is missing, or throws a synchronous
|
|
81
|
+
* error collapses into a definite non-success result.
|
|
82
|
+
*
|
|
83
|
+
* @param renderer The host renderer, or `undefined` when the host gave none.
|
|
84
|
+
* @param text The text to copy. Empty text is rejected by the host backend and
|
|
85
|
+
* degrades to the fallback rather than throwing.
|
|
86
|
+
* @param createHost Optional factory for the host clipboard, for tests.
|
|
87
|
+
*/
|
|
88
|
+
export async function copyToClipboard(
|
|
89
|
+
renderer: unknown,
|
|
90
|
+
text: string,
|
|
91
|
+
createHost: HostClipboardFactory = createHostClipboard,
|
|
92
|
+
): Promise<CopyResult> {
|
|
93
|
+
// 1. The verified path: a real host write that can report back `written`.
|
|
94
|
+
let hostReached = true;
|
|
95
|
+
let hostStatus: string = "failed";
|
|
96
|
+
try {
|
|
97
|
+
const host = createHost();
|
|
98
|
+
try {
|
|
99
|
+
const result = await host.writeText(text);
|
|
100
|
+
hostStatus = result.status;
|
|
101
|
+
} catch {
|
|
102
|
+
// The service exists but the write itself failed or rejected: a definite
|
|
103
|
+
// host failure, never an exception out of this call.
|
|
104
|
+
hostStatus = "failed";
|
|
105
|
+
}
|
|
106
|
+
} catch {
|
|
107
|
+
// The factory itself threw: there is no host service at all.
|
|
108
|
+
hostReached = false;
|
|
109
|
+
}
|
|
110
|
+
if (hostStatus === "written") return { verified: true, outcome: "written" };
|
|
111
|
+
|
|
112
|
+
// 2. Best-effort fallback: dispatch OSC52 and never call it a verified copy.
|
|
113
|
+
if (dispatchOsc52(renderer, text)) return { verified: false, outcome: "osc52-dispatched" };
|
|
114
|
+
|
|
115
|
+
// 3. No transport took the write. Report it plainly by the host's own reason
|
|
116
|
+
// when the host was reachable, otherwise that there was no backend at all.
|
|
117
|
+
if (!hostReached) return { verified: false, outcome: "no-backend" };
|
|
118
|
+
const outcome =
|
|
119
|
+
hostStatus === "unsupported" ||
|
|
120
|
+
hostStatus === "cancelled" ||
|
|
121
|
+
hostStatus === "timed-out" ||
|
|
122
|
+
hostStatus === "failed"
|
|
123
|
+
? hostStatus
|
|
124
|
+
: "failed";
|
|
125
|
+
return { verified: false, outcome };
|
|
126
|
+
}
|
|
127
|
+
|
|
39
128
|
/**
|
|
40
129
|
* The confirmation for a copy gesture, as a host-toast description.
|
|
41
130
|
*
|
|
42
|
-
* Split from {@link copyToClipboard} so the
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* guaranteed. The failure text names the terminal's inability and carries no id
|
|
49
|
-
* at all, because nothing was copied, so a silent no-op can never masquerade as
|
|
50
|
-
* a success.
|
|
131
|
+
* Split from {@link copyToClipboard} so the wordings are pure and tested
|
|
132
|
+
* directly. Success is claimed ONLY for a verified host write, and only then
|
|
133
|
+
* does the message name the full `id`. Every other outcome - an OSC52 dispatch
|
|
134
|
+
* included - is a distinct non-success that does not claim the id is on the
|
|
135
|
+
* clipboard: it is better to say the copy could not be confirmed than to imply
|
|
136
|
+
* one that was never verified.
|
|
51
137
|
*/
|
|
52
138
|
export function copyFeedback(
|
|
53
|
-
|
|
139
|
+
result: CopyResult,
|
|
54
140
|
id: string,
|
|
55
141
|
): {
|
|
56
142
|
readonly ok: boolean;
|
|
57
143
|
readonly variant: "success" | "error";
|
|
58
144
|
readonly message: string;
|
|
59
145
|
} {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
146
|
+
if (result.verified) {
|
|
147
|
+
return { ok: true, variant: "success", message: `Copied the full session id ${id} to the clipboard.` };
|
|
148
|
+
}
|
|
149
|
+
switch (result.outcome) {
|
|
150
|
+
case "osc52-dispatched":
|
|
151
|
+
return {
|
|
152
|
+
ok: false,
|
|
153
|
+
variant: "error",
|
|
154
|
+
message: "Sent the session id to the terminal, but could not confirm it was copied.",
|
|
155
|
+
};
|
|
156
|
+
case "unsupported":
|
|
157
|
+
return { ok: false, variant: "error", message: "This terminal cannot copy to the clipboard." };
|
|
158
|
+
case "cancelled":
|
|
159
|
+
return { ok: false, variant: "error", message: "The clipboard copy was cancelled." };
|
|
160
|
+
case "timed-out":
|
|
161
|
+
return { ok: false, variant: "error", message: "The clipboard copy timed out." };
|
|
162
|
+
case "failed":
|
|
163
|
+
return { ok: false, variant: "error", message: "Could not copy the session id to the clipboard." };
|
|
164
|
+
case "no-backend":
|
|
165
|
+
default:
|
|
166
|
+
return { ok: false, variant: "error", message: "No clipboard is available to copy the session id." };
|
|
167
|
+
}
|
|
63
168
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// The host-clipboard seam, split from `./clipboard.ts` for one reason: the
|
|
2
|
+
// render tests mount the real JSX in a real headless renderer, where mocking
|
|
3
|
+
// all of `@opentui/core` would break the renderer itself. This module is the
|
|
4
|
+
// only thing those tests replace, so they can stand in a fake host write while
|
|
5
|
+
// the renderer and the OSC52 adapter stay real.
|
|
6
|
+
//
|
|
7
|
+
// Production always resolves to the real process host clipboard.
|
|
8
|
+
|
|
9
|
+
export { createHostClipboard } from "@opentui/core";
|
package/src/tui/index.tsx
CHANGED
|
@@ -110,19 +110,24 @@ export default Plugin.define({
|
|
|
110
110
|
return (
|
|
111
111
|
<box
|
|
112
112
|
onMouseUp={() => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
113
|
+
void (async () => {
|
|
114
|
+
// Everything, the copy included, sits inside the try: a backend
|
|
115
|
+
// that throws or rejects must degrade to a failure result, never
|
|
116
|
+
// an exception out of the mouse handler.
|
|
117
|
+
try {
|
|
118
|
+
const result = await copyToClipboard(context.renderer, copyId);
|
|
119
|
+
const fb = copyFeedback(result, copyId);
|
|
120
|
+
context.ui.toast.show({
|
|
121
|
+
title: "Flight Deck",
|
|
122
|
+
message: fb.message,
|
|
123
|
+
variant: fb.variant,
|
|
124
|
+
duration: 1500,
|
|
125
|
+
});
|
|
126
|
+
} catch {
|
|
127
|
+
// A confirmation must never be able to break the click that
|
|
128
|
+
// produced it, nor the panel it confirms.
|
|
129
|
+
}
|
|
130
|
+
})();
|
|
126
131
|
}}
|
|
127
132
|
>
|
|
128
133
|
{text}
|