@miadi/tide 0.6.4 → 0.6.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miadi/tide",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
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,7 +15,7 @@
15
15
  "src"
16
16
  ],
17
17
  "dependencies": {
18
- "@miadi/annotate-core": "^0.3.0",
18
+ "@miadi/annotate-core": "^0.3.1",
19
19
  "@miadi/tide-contract": "0.3.5"
20
20
  },
21
21
  "keywords": [
package/src/annotate.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // review into its tmux pane — the web leg of the plannotator review loop.
3
3
  //
4
4
  // This module owns NO resolution and NO delivery logic of its own. Both belong
5
- // to /opt/gaia/linux_migration/11-plannotator-tmux-review.sh (jgwill/gaia#80),
5
+ // to the review script (jgwill/gaia#80; installed by miadi-tide in /usr/lib/miadi-tide),
6
6
  // which already proves the reply belongs to the pane, keeps every run in a
7
7
  // durable vessel, refuses to paste while a human is typing, and pastes with
8
8
  // bracketed paste so a multi-line review does not submit itself line by line.
@@ -53,6 +53,9 @@ import type {
53
53
 
54
54
  const pExecFile = promisify(execFile)
55
55
 
56
+ /** The copy the miadi-tide package installs, beside its pane-write guard. */
57
+ export const PACKAGED_REVIEW_SCRIPT = "/usr/lib/miadi-tide/plannotator-tmux-review.sh"
58
+ /** The source checkout on gaia, used when the package is not installed. */
56
59
  export const DEFAULT_REVIEW_SCRIPT = "/opt/gaia/linux_migration/11-plannotator-tmux-review.sh"
57
60
  export const REVIEW_SCRIPT_ENV = "PLANNOTATOR_TMUX_REVIEW_SCRIPT"
58
61
  /** The script's own override for where run vessels live. Same name, same meaning. */
@@ -150,8 +153,12 @@ export interface DeliverResult extends DeliverOutcome {
150
153
  log: string[]
151
154
  }
152
155
 
153
- export function resolveReviewScript(env: NodeJS.ProcessEnv = process.env): string {
154
- return env[REVIEW_SCRIPT_ENV]?.trim() || DEFAULT_REVIEW_SCRIPT
156
+ /** `$PLANNOTATOR_TMUX_REVIEW_SCRIPT` → the miadi-tide package's copy → gaia's checkout. */
157
+ export function resolveReviewScript(
158
+ env: NodeJS.ProcessEnv = process.env,
159
+ exists: (p: string) => boolean = existsSync,
160
+ ): string {
161
+ return env[REVIEW_SCRIPT_ENV]?.trim() || (exists(PACKAGED_REVIEW_SCRIPT) ? PACKAGED_REVIEW_SCRIPT : DEFAULT_REVIEW_SCRIPT)
155
162
  }
156
163
 
157
164
  /** Mirrors the script: `$PLANNOTATOR_TMUX_REVIEW_DIR` → `$XDG_STATE_HOME/…` → `~/.local/state/…`. */
package/src/client.ts CHANGED
@@ -616,6 +616,59 @@ export function buildSendKeysPlan(
616
616
  }
617
617
  }
618
618
 
619
+ /**
620
+ * The keys a person may press in a pane from the cockpit, one at a time: enough to
621
+ * answer an agent's question (move through its choices, confirm one). Nothing else
622
+ * is reachable this way. Tab and Shift-Tab in particular stay out: in a Claude
623
+ * prompt they change the permission mode (jgwill/Miadi#817).
624
+ */
625
+ export const PANE_KEYS = ["Up", "Down", "Enter"] as const
626
+ export type PaneKey = (typeof PANE_KEYS)[number]
627
+
628
+ const TMUX_KEY_NAME: Record<PaneKey, string> = { Up: "Up", Down: "Down", Enter: "C-m" }
629
+
630
+ export function isPaneKey(value: unknown): value is PaneKey {
631
+ return typeof value === "string" && (PANE_KEYS as readonly string[]).includes(value)
632
+ }
633
+
634
+ /** The exact `tmux send-keys` argv for one key, without executing it. */
635
+ export function buildPaneKeyPlan(pane: string, key: PaneKey): { target: string; key: PaneKey; command: string[] } {
636
+ const target = normalizePaneTarget(pane)
637
+ return { target, key, command: ["send-keys", "-t", target, TMUX_KEY_NAME[key]] }
638
+ }
639
+
640
+ /**
641
+ * Press one key in a tmux pane, exactly once: no literal text and no repeated
642
+ * Enter (sendKeys repeats its Enter for a pasted message; for a menu that would
643
+ * answer the next question too). Steer-gated like sendKeys. tmux only.
644
+ */
645
+ export async function sendPaneKey(
646
+ pane: string,
647
+ key: PaneKey,
648
+ opts: Pick<SendKeysOptions, "timeoutMs" | "cwd" | "gate"> = {},
649
+ ): Promise<{ target: string; key: PaneKey; command: string[]; sent_at: string }> {
650
+ if (!isPaneKey(key)) throw new TideError(`key must be one of ${PANE_KEYS.join(", ")}`)
651
+ if (HERDR_PANE_ID_PATTERN.test(pane.trim())) {
652
+ throw new TideError(`"${pane.trim()}" is a herdr pane id: keys are sent to tmux panes only`)
653
+ }
654
+ const plan = buildPaneKeyPlan(pane, key)
655
+ const bin = resolveTmuxBin()
656
+ const runOpts = { timeout: opts.timeoutMs ?? 10_000, cwd: opts.cwd }
657
+ const gate = acceptGateOverrides(opts.gate)
658
+ await requireSteerGate({
659
+ ...gate,
660
+ target: plan.target,
661
+ resolveTarget: gate.resolveTarget ?? (() => tmuxTargetResolved(plan.target, bin, runOpts)),
662
+ })
663
+ try {
664
+ await pExecFile(bin, plan.command, runOpts)
665
+ } catch (err) {
666
+ const msg = err instanceof Error ? err.message : String(err)
667
+ throw new TideError(`tmux send-keys ${plan.command[3]} to ${plan.target} failed: ${msg}`, err)
668
+ }
669
+ return { ...plan, sent_at: new Date().toISOString() }
670
+ }
671
+
619
672
  /**
620
673
  * Operator cockpit — steer a pane by typing `message` into it via `tmux send-keys`.
621
674
  * Robust and simple: no shell, no Python spawn, no reviewed-proposal artifact.