@miadi/tide 0.6.1 → 0.6.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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/client.ts +121 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miadi/tide",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
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"
@@ -16,7 +16,7 @@
16
16
  ],
17
17
  "dependencies": {
18
18
  "@miadi/annotate-core": "^0.2.0",
19
- "@miadi/tide-contract": "0.3.2"
19
+ "@miadi/tide-contract": "0.3.4"
20
20
  },
21
21
  "keywords": [
22
22
  "miadi",
package/src/client.ts CHANGED
@@ -15,6 +15,7 @@ import { promisify } from "node:util"
15
15
  import { readFile } from "node:fs/promises"
16
16
  import { join } from "node:path"
17
17
  import { homedir } from "node:os"
18
+ import { sanitizeSecrets } from "@miadi/tide-contract"
18
19
 
19
20
  import type {
20
21
  ContextSnapshot,
@@ -369,13 +370,61 @@ export async function peek(pane: string, lines = 30, opts: PeekOptions = {}): Pr
369
370
  // Resolve the label here so the result reports the CURRENT pane id, not
370
371
  // the raw (possibly empty) pane argument. Same CLI cost: one list + one read.
371
372
  const target = opts.paneLabel ? await resolveHerdrPaneId(opts.paneLabel, opts) : pane
372
- const text = await readHerdrPane(target, lines, { ...opts, paneLabel: undefined })
373
+ const text = sanitizeSecrets(await readHerdrPane(target, lines, { ...opts, paneLabel: undefined }))
373
374
  return { multiplexer: "herdr", pane: target, lines: text.split("\n"), text }
374
375
  }
375
- return runTideJson<TidePeekResult>(
376
+ const result = await runTideJson<TidePeekResult>(
376
377
  ["operator", "peek", `%${pane}`, "--lines", String(lines), "--format", "json"],
377
378
  { timeoutMs: 8_000, ...opts },
378
379
  )
380
+ // ironsilk redacts its own captures from 0.9.41; an older one on the host does
381
+ // not, so the client redacts too. Redacting twice changes nothing (jgwill/Miadi#745).
382
+ return typeof result.content === "string" ? { ...result, content: sanitizeSecrets(result.content) } : result
383
+ }
384
+
385
+ /** One entry of an agent's dialogue (`tide operator transcript`, jgwill/Miadi#726). */
386
+ export interface TideDialogueEntry {
387
+ /** `human`: prompt, queued (typed while the agent worked) or command. `tools`: a run of tool calls. `note`: a compaction summary. */
388
+ role: "human" | "agent" | "tools" | "note"
389
+ kind: "prompt" | "queued" | "command" | "text" | "tools" | "compact"
390
+ text: string
391
+ at: string
392
+ tools?: { name: string; brief: string }[]
393
+ }
394
+
395
+ export interface TideTranscriptResult {
396
+ target: string
397
+ pane_id: string | null
398
+ agent: { kind?: string; state?: string; session_id?: string; name?: string; cwd?: string } | null
399
+ transcript: string | null
400
+ /** Entries in the whole dialogue; `entries` holds the newest `limit` of them. */
401
+ total: number
402
+ entries: TideDialogueEntry[]
403
+ /** Why there is no dialogue: no agent in the pane, a non-claude agent, no transcript file. */
404
+ error: string | null
405
+ }
406
+
407
+ /**
408
+ * Operator cockpit — the whole dialogue of the agent in a tmux pane, read from its
409
+ * transcript. A Claude Code pane draws on the alternate screen, so `peek` holds one
410
+ * screenful; this is the conversation. `pane` is the numeric index (no `%`).
411
+ * `limit` 0 returns every entry.
412
+ */
413
+ export async function transcript(pane: string, limit = 0, opts?: TideRunOptions): Promise<TideTranscriptResult> {
414
+ const result = await runTideJson<TideTranscriptResult>(
415
+ ["operator", "transcript", `%${pane}`, "--limit", String(limit), "--format", "json"],
416
+ { timeoutMs: 20_000, ...opts },
417
+ )
418
+ // Redacted here as in peek(), for an ironsilk older than 0.9.41 (jgwill/Miadi#745).
419
+ if (!Array.isArray(result.entries)) return result
420
+ return {
421
+ ...result,
422
+ entries: result.entries.map(entry => ({
423
+ ...entry,
424
+ text: sanitizeSecrets(entry.text ?? ""),
425
+ ...(entry.tools ? { tools: entry.tools.map(tool => ({ ...tool, brief: sanitizeSecrets(tool.brief ?? "") })) } : {}),
426
+ })),
427
+ }
379
428
  }
380
429
 
381
430
  /** Operator cockpit — build a reviewed steer proposal (no send). `pane` is the numeric index. */
@@ -404,6 +453,76 @@ export function send(pane: string, message: string, opts?: TideRunOptions): Prom
404
453
  )
405
454
  }
406
455
 
456
+ // ── Companion seats (jgwill/Miadi#714) ──────────────────────────────────────
457
+
458
+ export interface CompanionOpenOptions {
459
+ /** Episode number or vessel folder name. */
460
+ episode: string
461
+ /** Seat key; the runtime's default is `mia`. */
462
+ seat?: string
463
+ /** The person's word to rename the existing session `-arch-<yyMMddHHmm>` and open a new one. */
464
+ archive?: boolean
465
+ /** Act instead of returning the plan. */
466
+ run?: boolean
467
+ timeoutMs?: number
468
+ }
469
+
470
+ export interface TideCompanionOpenResult {
471
+ /** 0 done (or nothing to do), 3 done with warnings, 4 refused, 2 the runtime's controller gate. */
472
+ exitCode: number
473
+ /** `tide companion open --format json` output: the plan, and with `run` the steps taken. */
474
+ plan: Record<string, unknown> | null
475
+ /** The runtime's own words when it printed no JSON. */
476
+ message?: string
477
+ }
478
+
479
+ const COMPANION_ARG = /^[A-Za-z0-9][A-Za-z0-9._-]{0,200}$/
480
+
481
+ /**
482
+ * Open, re-arm or archive an episode's companion seat. Dry run unless `run`.
483
+ *
484
+ * Exit 3 and 4 still carry JSON, so they are answers, not failures. With `run`,
485
+ * the runtime's interactive-terminal requirement is answered by the authenticated
486
+ * person who reached the calling route (William's ruling 2026-08-02, the same one
487
+ * `humanConsentSteerGate` carries); tide's controller mode still applies.
488
+ * Opening a seat waits for its prompt and its listener, so `run` defaults to 7 minutes.
489
+ */
490
+ export async function openCompanion(opts: CompanionOpenOptions): Promise<TideCompanionOpenResult> {
491
+ for (const [name, value] of [["episode", opts.episode], ["seat", opts.seat]] as const) {
492
+ if (value !== undefined && !COMPANION_ARG.test(value)) {
493
+ throw new TideError(`companion ${name} must be letters, digits, '.', '_' or '-': ${JSON.stringify(value)}`)
494
+ }
495
+ }
496
+ const args = ["companion", "open", "--episode", opts.episode, "--format", "json"]
497
+ if (opts.seat) args.push("--seat", opts.seat)
498
+ if (opts.archive) args.push("--archive")
499
+ if (opts.run) args.push("--run")
500
+ const bin = await resolveTideBin()
501
+ const timeoutMs = opts.timeoutMs ?? (opts.run ? 420_000 : 30_000)
502
+ const env = opts.run ? { ...process.env, TIDE_ALLOW_NON_INTERACTIVE_RUN: "1" } : process.env
503
+ const startedAt = Date.now()
504
+ const parse = (stdout: string): Record<string, unknown> | null => {
505
+ try {
506
+ return JSON.parse(stdout) as Record<string, unknown>
507
+ } catch {
508
+ return null
509
+ }
510
+ }
511
+ try {
512
+ const res = await pExecFile(bin, args, { timeout: timeoutMs, env, maxBuffer: 8 * 1024 * 1024 })
513
+ return { exitCode: 0, plan: parse(res.stdout) }
514
+ } catch (err) {
515
+ const e = err as { code?: unknown; killed?: boolean; stdout?: string; stderr?: string }
516
+ if (typeof e.code === "number" && !e.killed) {
517
+ const plan = parse(e.stdout ?? "")
518
+ return plan
519
+ ? { exitCode: e.code, plan }
520
+ : { exitCode: e.code, plan: null, message: `${e.stdout ?? ""}${e.stderr ?? ""}`.trim() }
521
+ }
522
+ throw classifyExecFailure(bin, args, err, Date.now() - startedAt, timeoutMs)
523
+ }
524
+ }
525
+
407
526
  // ── Direct send-keys (simple, robust steer transport) ───────────────────────
408
527
  //
409
528
  // The operator cockpit's primary steer path. Instead of the heavier reviewed