@miadi/tide 0.3.0 → 0.4.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Miadi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miadi/tide",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Typed client boundary for the ironsilk `tide` runtime. Daemon Unix-socket transport with CLI fallback.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -15,15 +15,15 @@
15
15
  "src"
16
16
  ],
17
17
  "dependencies": {
18
- "@miadi/tide-contract": "0.2.4"
19
- },
20
- "scripts": {
21
- "test": "d=$(mktemp -d \"${TMPDIR:-/tmp}/miadi-tide-test.XXXXXX\") && trap 'rm -rf \"$d\"' EXIT && ../../node_modules/.bin/tsc -p tsconfig.test.json --outDir \"$d\" && node --test \"$d\"/packages/tide/test/*.test.js"
18
+ "@miadi/tide-contract": "0.3.0"
22
19
  },
23
20
  "keywords": [
24
21
  "miadi",
25
22
  "tide",
26
23
  "ironsilk",
27
24
  "operator-cockpit"
28
- ]
29
- }
25
+ ],
26
+ "scripts": {
27
+ "test": "d=$(mktemp -d \"${TMPDIR:-/tmp}/miadi-tide-test.XXXXXX\") && trap 'rm -rf \"$d\"' EXIT && ../../node_modules/.bin/tsc -p tsconfig.test.json --outDir \"$d\" && node --test \"$d\"/packages/tide/test/*.test.js"
28
+ }
29
+ }
package/src/client.ts CHANGED
@@ -217,6 +217,9 @@ export interface PeekOptions extends TideRunOptions {
217
217
  multiplexer?: Multiplexer
218
218
  /** herdr only: durable pane label, re-resolved to the current pane id at action time. */
219
219
  paneLabel?: string
220
+ /** herdr only: the session the pane lives in. Reads are session-scoped for the
221
+ * same reason writes are — see SendKeysOptions.session. */
222
+ session?: string
220
223
  /** herdr only: injected command runner (tests). */
221
224
  runner?: HerdrCommandRunner
222
225
  }
@@ -304,6 +307,16 @@ export interface SendKeysOptions extends TideRunOptions {
304
307
  * action time (herdr ids are session-scoped and reset on herdr restart).
305
308
  */
306
309
  paneLabel?: string
310
+ /**
311
+ * herdr only: the session the pane lives in (`herdr --session <name> …`).
312
+ * herdr pane ids are session-scoped and the CLI reaches `default` without
313
+ * this, so omitting it for a pane in another session addresses whatever wears
314
+ * that id in `default` — or nothing, which is how a live pane reported itself
315
+ * gone on 2026-08-05. tmux pane ids (`%127`) are server-global and need no
316
+ * session, which is why the tmux path refuses this option rather than
317
+ * ignoring it.
318
+ */
319
+ session?: string
307
320
  /** herdr only: injected command runner (tests). */
308
321
  runner?: HerdrCommandRunner
309
322
  /**
@@ -377,9 +390,11 @@ export async function sendKeys(
377
390
  }
378
391
  // herdr-only options on the tmux path would silently steer the raw tmux
379
392
  // pane — the wrong-pane hazard labels exist to prevent. Fail loudly instead.
380
- if (opts.paneLabel !== undefined || opts.runner !== undefined) {
393
+ if (opts.paneLabel !== undefined || opts.runner !== undefined || opts.session !== undefined) {
381
394
  throw new TideError(
382
- `sendKeys: "paneLabel"/"runner" are herdr-only options — pass multiplexer: "herdr"`,
395
+ `sendKeys: "paneLabel"/"runner"/"session" are herdr-only options — pass multiplexer: "herdr". ` +
396
+ `tmux pane ids (%127) are server-global, so a tmux target needs no session; accepting one ` +
397
+ `here would mean honouring it nowhere.`,
383
398
  )
384
399
  }
385
400
  // Wrong-multiplexer dispatch assertion (EP152 wave-2 W2): a herdr-shaped id
@@ -407,6 +422,11 @@ export async function sendKeys(
407
422
  throw new TideError(`tmux send-keys to ${plan.target} failed (typing literal text): ${msg}`, err)
408
423
  }
409
424
  if (plan.submit_command) {
425
+ // A TUI (claude, ptpython) brackets a fast literal burst as a paste, and the
426
+ // first Enter only closes the paste — the message stays staged on the prompt.
427
+ // Let the pane settle, submit, then submit once more: the repeat is a no-op
428
+ // for a shell and the difference between staged and sent for a TUI.
429
+ await new Promise((resolve) => setTimeout(resolve, 200))
410
430
  try {
411
431
  await pExecFile(bin, plan.submit_command, runOpts)
412
432
  } catch (err) {
@@ -416,6 +436,13 @@ export async function sendKeys(
416
436
  err,
417
437
  )
418
438
  }
439
+ await new Promise((resolve) => setTimeout(resolve, 150))
440
+ try {
441
+ await pExecFile(bin, plan.submit_command, runOpts)
442
+ } catch {
443
+ // Best-effort repeat: the first Enter landed, so a failure here must not
444
+ // report as an unsubmitted message.
445
+ }
419
446
  }
420
447
  return { ...plan, sent_at: new Date().toISOString() }
421
448
  }
package/src/herdr.ts CHANGED
@@ -63,6 +63,28 @@ export type HerdrCommandRunner = (
63
63
  export interface HerdrRunOptions extends TideRunOptions {
64
64
  /** Injected command runner; defaults to `execFile` against the herdr binary. */
65
65
  runner?: HerdrCommandRunner
66
+ /**
67
+ * The herdr session to address, as `herdr --session <name> …`.
68
+ *
69
+ * WHY THIS EXISTS. Every verb in this module invoked `herdr` bare, which
70
+ * reaches the `default` session and only that one. Pane ids are session-scoped
71
+ * (see the header note), so a caller holding `w1T:p1` from a session named
72
+ * `stcbot` was asking `default` about an id that means something else there —
73
+ * or nothing at all. On 2026-08-05 a voice card published from a non-default
74
+ * session refused its own reply with "that pane is gone": the address was
75
+ * right, the session was dropped between the card and the CLI.
76
+ *
77
+ * Omitted keeps the historical behaviour byte-for-byte (`default`).
78
+ */
79
+ session?: string
80
+ }
81
+
82
+ /** Prefix `--session <name>` when the caller named one. Applied in exactly two
83
+ * places — `runHerdr` for the read verbs, and the send-keys plan for the write
84
+ * ones — so a previewed argv and an executed argv cannot disagree. */
85
+ function withSession(args: readonly string[], session?: string): string[] {
86
+ const named = typeof session === "string" ? session.trim() : ""
87
+ return named ? ["--session", named, ...args] : [...args]
66
88
  }
67
89
 
68
90
  /** Resolve the herdr binary: `TIDE_HERDR_BIN` env → `herdr` (on PATH). */
@@ -112,10 +134,13 @@ function describeRunnerError(err: unknown): string {
112
134
  async function runHerdr(args: string[], opts: HerdrRunOptions): Promise<HerdrCommandResult> {
113
135
  const runner = makeRunner(opts)
114
136
  try {
115
- return await runner(resolveHerdrBin(), args)
137
+ return await runner(resolveHerdrBin(), withSession(args, opts.session))
116
138
  } catch (err) {
139
+ // The verb is read off the ORIGINAL args, not the session-prefixed ones —
140
+ // otherwise every failure would report itself as "herdr --session <name>".
117
141
  const verb = args.length >= 2 ? `${args[0]} ${args[1]}` : "operation"
118
- throw new TideError(`herdr ${verb} failed: ${describeRunnerError(err)}`, err)
142
+ const where = opts.session ? ` in session "${opts.session}"` : ""
143
+ throw new TideError(`herdr ${verb}${where} failed: ${describeRunnerError(err)}`, err)
119
144
  }
120
145
  }
121
146
 
@@ -492,16 +517,21 @@ function makeHerdrSendKeysPlan(
492
517
  message: string,
493
518
  submit: boolean,
494
519
  paneLabel?: string,
520
+ session?: string,
495
521
  ): TideHerdrSendKeysResult {
496
522
  const plan: TideHerdrSendKeysResult = {
497
523
  multiplexer: "herdr",
498
524
  target,
499
525
  message,
526
+ // The session is prefixed INTO the argv, not carried beside it, so there is
527
+ // no way to execute the plan and reach a different session than the one the
528
+ // plan says it is addressing.
500
529
  submitted: submit,
501
- literal_command: ["pane", "send-text", target, message],
502
- submit_command: submit ? ["pane", "send-keys", target, "Enter"] : null,
530
+ literal_command: withSession(["pane", "send-text", target, message], session),
531
+ submit_command: submit ? withSession(["pane", "send-keys", target, "Enter"], session) : null,
503
532
  }
504
533
  if (paneLabel !== undefined) plan.pane_label = paneLabel
534
+ if (session !== undefined && session.trim()) plan.session = session.trim()
505
535
  return plan
506
536
  }
507
537
 
@@ -515,8 +545,9 @@ export function buildHerdrSendKeysPlan(
515
545
  message: string,
516
546
  submit = true,
517
547
  paneLabel?: string,
548
+ session?: string,
518
549
  ): TideHerdrSendKeysResult {
519
- return makeHerdrSendKeysPlan(normalizeHerdrPaneTarget(pane), message, submit, paneLabel)
550
+ return makeHerdrSendKeysPlan(normalizeHerdrPaneTarget(pane), message, submit, paneLabel, session)
520
551
  }
521
552
 
522
553
  /**
@@ -556,7 +587,7 @@ export async function sendKeysViaHerdr(
556
587
  target,
557
588
  resolveTarget: gate.resolveTarget ?? herdrTargetResolved(target, opts.paneLabel !== undefined, opts),
558
589
  })
559
- const plan = makeHerdrSendKeysPlan(target, message, opts.submit ?? true, opts.paneLabel)
590
+ const plan = makeHerdrSendKeysPlan(target, message, opts.submit ?? true, opts.paneLabel, opts.session)
560
591
  const runner = makeRunner(opts)
561
592
  const bin = resolveHerdrBin()
562
593
  try {
@@ -568,6 +599,10 @@ export async function sendKeysViaHerdr(
568
599
  )
569
600
  }
570
601
  if (plan.submit_command) {
602
+ // Same paste-staging contract as the tmux path: a TUI holds the text as
603
+ // "[Pasted text]" after the first Enter. Settle, submit, submit again —
604
+ // the repeat is a no-op everywhere else.
605
+ await new Promise((resolve) => setTimeout(resolve, 200))
571
606
  try {
572
607
  await runner(bin, plan.submit_command)
573
608
  } catch (err) {
@@ -576,6 +611,12 @@ export async function sendKeysViaHerdr(
576
611
  err,
577
612
  )
578
613
  }
614
+ await new Promise((resolve) => setTimeout(resolve, 150))
615
+ try {
616
+ await runner(bin, plan.submit_command)
617
+ } catch {
618
+ // Best-effort repeat: the first Enter landed.
619
+ }
579
620
  }
580
621
  return { ...plan, sent_at: new Date().toISOString() }
581
622
  }
package/src/index.ts CHANGED
@@ -11,6 +11,10 @@ export {
11
11
  readNavigatorPosture,
12
12
  evaluateSteerGate,
13
13
  requireSteerGate,
14
+ // The narrow, named exception to the line above: an authenticated human's
15
+ // presence answering the gate (William's ruling 2026-08-02). The raw
16
+ // brander stays unexported.
17
+ humanConsentSteerGate,
14
18
  } from "./steer-gate"
15
19
  export type {
16
20
  SteerPostureMode,
package/src/steer-gate.ts CHANGED
@@ -223,6 +223,24 @@ export function trustSteerGateProbes(overrides: SteerGateOverrides): SteerGateOv
223
223
  return branded
224
224
  }
225
225
 
226
+ /**
227
+ * William's ruling, 2026-08-02: the controller lease gates AGENTS, never the
228
+ * authenticated human. A server route that has ALREADY authenticated a person
229
+ * (writer token, or a named tailnet identity) may declare that presence here —
230
+ * the person's authentication is the consent, so posture and TTY answer as
231
+ * satisfied while target liveness still applies. This is the one sanctioned
232
+ * way for HTTP-derived code to answer those questions (W10a stands: the raw
233
+ * brander is not a consumer API), and it exists so the voice portal's reply
234
+ * button is not a dead end by default. `source` must name the route and the
235
+ * gate that authenticated the person — it is what a refused-audit reads later.
236
+ */
237
+ export function humanConsentSteerGate(source: string): SteerGateOverrides {
238
+ return trustSteerGateProbes({
239
+ readPosture: () => ({ mode: "controller", source: `authenticated-human: ${source}` }),
240
+ isInteractive: () => true,
241
+ })
242
+ }
243
+
226
244
  function isTrustedSteerGateProbes(gate: SteerGateOverrides): boolean {
227
245
  return (gate as Record<PropertyKey, unknown>)[TRUSTED_PROBES] === true
228
246
  }