@miadi/tide 0.1.1 → 0.1.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/README.md +18 -3
- package/package.json +1 -1
- package/src/client.ts +89 -0
- package/src/types.ts +24 -0
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Typed client boundary between Miadi and the **ironsilk `tide`** runtime (histori
|
|
|
5
5
|
`exec("/home/jgi/anaconda3/bin/tide …")` calls.
|
|
6
6
|
|
|
7
7
|
Grounded in `foundations/terminal-workspace-orchestration/` (Decision C) and
|
|
8
|
-
`rispecs/
|
|
8
|
+
`rispecs/tide-runtime/05-ui-surface.spec.md` (daemon-socket transport).
|
|
9
9
|
|
|
10
10
|
## Runtime dependency — install `tide`
|
|
11
11
|
|
|
@@ -28,7 +28,7 @@ is outside the server's `PATH`. The daemon socket is resolved separately via
|
|
|
28
28
|
## Verbs
|
|
29
29
|
|
|
30
30
|
```ts
|
|
31
|
-
import { getContext, getTerminals, detect, peek, steerProposal, send, pingDaemon, describeTransport, TideError } from "@miadi/tide"
|
|
31
|
+
import { getContext, getTerminals, detect, peek, steerProposal, send, sendKeys, buildSendKeysPlan, pingDaemon, describeTransport, TideError } from "@miadi/tide"
|
|
32
32
|
|
|
33
33
|
const snapshot = await getContext() // R2 live context (daemon socket → CLI fallback)
|
|
34
34
|
const terminals = await getTerminals() // operator terminals inventory (CLI, read-only)
|
|
@@ -37,10 +37,25 @@ const scroll = await peek("56", 80) // operator peek %56 (CLI)
|
|
|
37
37
|
const proposal = await steerProposal("56", "continue from checkpoint") // (CLI)
|
|
38
38
|
const sent = await send("56", "continue") // guarded --run, controller mode (CLI)
|
|
39
39
|
|
|
40
|
+
// Direct, simple steer transport — `tmux send-keys` via execFile (no shell, no Python):
|
|
41
|
+
const keyed = await sendKeys("56", "continue") // types text + Enter
|
|
42
|
+
const noEnter = await sendKeys("56", "ls -la", { submit: false })// types text, leaves it unsubmitted
|
|
43
|
+
const plan = buildSendKeysPlan("56", "ls -la", false) // pure dry-run plan (no execution)
|
|
44
|
+
|
|
40
45
|
const up = await pingDaemon() // daemon liveness (ping → pong)
|
|
41
46
|
const how = describeTransport() // { transport: "socket"|"cli", socketPath, socketAvailable }
|
|
42
47
|
```
|
|
43
48
|
|
|
49
|
+
### `sendKeys` — the operator cockpit's primary steer path
|
|
50
|
+
|
|
51
|
+
`sendKeys(pane, message, { submit })` drives **`tmux send-keys` directly** through `execFile`
|
|
52
|
+
with argument arrays (no shell, no escaping, no Python spawn, no reviewed-proposal artifact) —
|
|
53
|
+
the simple, robust transport behind `POST /api/tide/steer`. `submit` (default `true`) controls
|
|
54
|
+
the trailing Enter (`C-m`): set it `false` to type content into the pane and leave it on the
|
|
55
|
+
prompt for a human to review and submit. `buildSendKeysPlan(...)` returns the exact `tmux` argv
|
|
56
|
+
pair without executing — used for the cockpit's inline command preview. The tmux binary is
|
|
57
|
+
resolved via `TIDE_TMUX_BIN` -> `tmux` on `PATH`.
|
|
58
|
+
|
|
44
59
|
`getTerminals` and `detect` are the read-only surface behind `GET /api/tide/terminals`
|
|
45
60
|
and `GET /api/tide/detect` — the typed half of operator-terminal triage and manual
|
|
46
61
|
domain assignment (jgwill/Miadi#382). The write-back half (assign a pane to a domain)
|
|
@@ -65,7 +80,7 @@ is deferred to the runtime + a guarded route.
|
|
|
65
80
|
- **`cli`**: force the CLI.
|
|
66
81
|
|
|
67
82
|
`peek` / `steerProposal` / `send` are **CLI-only**: the daemon exposes `get_context` / `ping` /
|
|
68
|
-
`detect`, not the operator mutation verbs. They join the socket path when the runtime adds those
|
|
83
|
+
`detect`, not the operator mutation verbs. `sendKeys` is independent of both — it talks to `tmux` directly. They join the socket path when the runtime adds those
|
|
69
84
|
actions — verb signatures are the stable surface; only the transport underneath changes.
|
|
70
85
|
|
|
71
86
|
### Wire protocol (mirrors `hermes_navigator/daemon.py`)
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
TidePeekResult,
|
|
21
21
|
TideSendResult,
|
|
22
22
|
TideSteerResult,
|
|
23
|
+
TideSendKeysResult,
|
|
23
24
|
} from "./types"
|
|
24
25
|
import {
|
|
25
26
|
daemonRequest,
|
|
@@ -226,3 +227,91 @@ export function send(pane: string, message: string, opts?: TideRunOptions): Prom
|
|
|
226
227
|
{ timeoutMs: 10_000, ...opts },
|
|
227
228
|
)
|
|
228
229
|
}
|
|
230
|
+
|
|
231
|
+
// ── Direct send-keys (simple, robust steer transport) ───────────────────────
|
|
232
|
+
//
|
|
233
|
+
// The operator cockpit's primary steer path. Instead of the heavier reviewed
|
|
234
|
+
// `steer-proposal` → `send --run` pipeline (which always submits Enter and spawns
|
|
235
|
+
// Python), this drives `tmux send-keys` directly via `execFile` with ARGUMENT
|
|
236
|
+
// ARRAYS (no shell, no escaping). One verb, one round-trip, and the caller decides
|
|
237
|
+
// whether to submit Enter — the affordance the cockpit's "send Enter" checkbox needs.
|
|
238
|
+
|
|
239
|
+
/** Resolve the tmux binary: `TIDE_TMUX_BIN` env → `tmux` (on PATH). */
|
|
240
|
+
function resolveTmuxBin(): string {
|
|
241
|
+
return process.env.TIDE_TMUX_BIN?.trim() || "tmux"
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Normalize a pane reference to a `%`-prefixed tmux pane id (e.g. "56" → "%56"). */
|
|
245
|
+
export function normalizePaneTarget(pane: string): string {
|
|
246
|
+
const trimmed = pane.trim()
|
|
247
|
+
return trimmed.startsWith("%") ? trimmed : `%${trimmed}`
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export interface SendKeysOptions extends TideRunOptions {
|
|
251
|
+
/**
|
|
252
|
+
* Append a trailing Enter (`C-m`) after typing the literal text. Default true.
|
|
253
|
+
* When false the text is left on the pane's prompt unsubmitted, so a human can
|
|
254
|
+
* review and press Enter — the "send Enter after content" cockpit toggle.
|
|
255
|
+
*/
|
|
256
|
+
submit?: boolean
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Build the exact `tmux send-keys` argv pair for a steer WITHOUT executing it.
|
|
261
|
+
* Pure — safe for client-side previews and dry-run plans. `submit_command` is
|
|
262
|
+
* null when `submit` is false (nothing is submitted).
|
|
263
|
+
*/
|
|
264
|
+
export function buildSendKeysPlan(
|
|
265
|
+
pane: string,
|
|
266
|
+
message: string,
|
|
267
|
+
submit = true,
|
|
268
|
+
): TideSendKeysResult {
|
|
269
|
+
const target = normalizePaneTarget(pane)
|
|
270
|
+
return {
|
|
271
|
+
target,
|
|
272
|
+
message,
|
|
273
|
+
submitted: submit,
|
|
274
|
+
// `-l` types the bytes literally (no tmux key-name interpretation).
|
|
275
|
+
literal_command: ["send-keys", "-l", "-t", target, message],
|
|
276
|
+
submit_command: submit ? ["send-keys", "-t", target, "C-m"] : null,
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Operator cockpit — steer a pane by typing `message` into it via `tmux send-keys`.
|
|
282
|
+
* Robust and simple: no shell, no Python spawn, no reviewed-proposal artifact.
|
|
283
|
+
* Set `submit: false` to type the content without pressing Enter.
|
|
284
|
+
*
|
|
285
|
+
* Two tmux invocations when submitting: the literal text is typed first, then a
|
|
286
|
+
* separate `C-m` submits it. If the literal step succeeds but the submit step
|
|
287
|
+
* fails, the text is already on the pane's prompt (unsubmitted) — the thrown
|
|
288
|
+
* `TideError` names which step failed so the caller can surface that partial state.
|
|
289
|
+
*/
|
|
290
|
+
export async function sendKeys(
|
|
291
|
+
pane: string,
|
|
292
|
+
message: string,
|
|
293
|
+
opts: SendKeysOptions = {},
|
|
294
|
+
): Promise<TideSendKeysResult> {
|
|
295
|
+
const submit = opts.submit ?? true
|
|
296
|
+
const plan = buildSendKeysPlan(pane, message, submit)
|
|
297
|
+
const bin = resolveTmuxBin()
|
|
298
|
+
const runOpts = { timeout: opts.timeoutMs ?? 10_000, cwd: opts.cwd }
|
|
299
|
+
try {
|
|
300
|
+
await pExecFile(bin, plan.literal_command, runOpts)
|
|
301
|
+
} catch (err) {
|
|
302
|
+
const msg = err instanceof Error ? err.message : String(err)
|
|
303
|
+
throw new TideError(`tmux send-keys to ${plan.target} failed (typing literal text): ${msg}`, err)
|
|
304
|
+
}
|
|
305
|
+
if (plan.submit_command) {
|
|
306
|
+
try {
|
|
307
|
+
await pExecFile(bin, plan.submit_command, runOpts)
|
|
308
|
+
} catch (err) {
|
|
309
|
+
const msg = err instanceof Error ? err.message : String(err)
|
|
310
|
+
throw new TideError(
|
|
311
|
+
`tmux send-keys to ${plan.target} failed (submitting Enter; literal text was typed but left unsubmitted): ${msg}`,
|
|
312
|
+
err,
|
|
313
|
+
)
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return { ...plan, sent_at: new Date().toISOString() }
|
|
317
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -90,3 +90,27 @@ export interface TideSteerResult {
|
|
|
90
90
|
export interface TideSendResult {
|
|
91
91
|
[key: string]: unknown
|
|
92
92
|
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Result of a direct `tmux send-keys` performed by `sendKeys()`/`buildSendKeysPlan()`.
|
|
96
|
+
* This is the simple, robust transport the operator cockpit uses to steer a pane
|
|
97
|
+
* without the heavier reviewed-proposal pipeline.
|
|
98
|
+
*
|
|
99
|
+
* `submitted` reflects the "send Enter after content" toggle: when false, the
|
|
100
|
+
* literal text is typed into the pane but NOT submitted (no trailing `C-m`),
|
|
101
|
+
* leaving it on the prompt for the human to review and press Enter themselves.
|
|
102
|
+
*/
|
|
103
|
+
export interface TideSendKeysResult {
|
|
104
|
+
/** Resolved tmux pane target, always `%`-prefixed (e.g. "%56"). */
|
|
105
|
+
target: string
|
|
106
|
+
/** The literal text typed into the pane. */
|
|
107
|
+
message: string
|
|
108
|
+
/** Whether a trailing Enter (`C-m`) was sent after the literal text. */
|
|
109
|
+
submitted: boolean
|
|
110
|
+
/** Exact `tmux send-keys -l` argv used to type the literal text (no shell). */
|
|
111
|
+
literal_command: string[]
|
|
112
|
+
/** Exact `tmux send-keys … C-m` argv used to submit, or null when `submitted` is false. */
|
|
113
|
+
submit_command: string[] | null
|
|
114
|
+
/** ISO timestamp the keys were sent (omitted on a dry-run plan). */
|
|
115
|
+
sent_at?: string
|
|
116
|
+
}
|