@miadi/tide 0.6.14 → 0.6.16

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 +1 -1
  2. package/src/client.ts +129 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miadi/tide",
3
- "version": "0.6.14",
3
+ "version": "0.6.16",
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"
package/src/client.ts CHANGED
@@ -390,13 +390,26 @@ export interface TideDialogueEntry {
390
390
  kind: "prompt" | "queued" | "command" | "text" | "tools" | "compact"
391
391
  text: string
392
392
  at: string
393
- tools?: { name: string; brief: string }[]
393
+ tools?: TideDialogueTool[]
394
+ }
395
+
396
+ /** One tool call of a dialogue entry (jgwill/Miadi#726, verbatim fields jgwill/Miadi#1031). */
397
+ export interface TideDialogueTool {
398
+ name: string
399
+ brief: string
400
+ /** The call has no result yet: it runs, or waits for the person (ironsilk ≥ 0.9.81). */
401
+ pending?: boolean
402
+ /** Verbatim reading only: the whole input, as JSON text. */
403
+ input?: string
404
+ /** Verbatim reading only: the whole result. */
405
+ result?: string
406
+ is_error?: boolean
394
407
  }
395
408
 
396
409
  export interface TideTranscriptResult {
397
410
  target: string
398
411
  pane_id: string | null
399
- agent: { kind?: string; state?: string; session_id?: string; name?: string; cwd?: string } | null
412
+ agent: { kind?: string; state?: string; status?: string; updated_at?: number | null; session_id?: string; name?: string; cwd?: string } | null
400
413
  transcript: string | null
401
414
  /** Entries in the whole dialogue; `entries` holds the newest `limit` of them. */
402
415
  total: number
@@ -411,10 +424,15 @@ export interface TideTranscriptResult {
411
424
  * screenful; this is the conversation. `pane` is the numeric index (no `%`).
412
425
  * `limit` 0 returns every entry.
413
426
  */
414
- export async function transcript(pane: string, limit = 0, opts?: TideRunOptions): Promise<TideTranscriptResult> {
427
+ export async function transcript(
428
+ pane: string,
429
+ limit = 0,
430
+ opts?: TideRunOptions & { verbatim?: boolean },
431
+ ): Promise<TideTranscriptResult> {
432
+ const { verbatim, ...runOpts } = opts ?? {}
415
433
  const result = await runTideJson<TideTranscriptResult>(
416
- ["operator", "transcript", `%${pane}`, "--limit", String(limit), "--format", "json"],
417
- { timeoutMs: 20_000, ...opts },
434
+ ["operator", "transcript", `%${pane}`, "--limit", String(limit), "--format", "json", ...(verbatim ? ["--verbatim"] : [])],
435
+ { timeoutMs: 20_000, ...runOpts },
418
436
  )
419
437
  // Redacted here as in peek(), for an ironsilk older than 0.9.41 (jgwill/Miadi#745).
420
438
  if (!Array.isArray(result.entries)) return result
@@ -423,7 +441,12 @@ export async function transcript(pane: string, limit = 0, opts?: TideRunOptions)
423
441
  entries: result.entries.map(entry => ({
424
442
  ...entry,
425
443
  text: sanitizeSecrets(entry.text ?? ""),
426
- ...(entry.tools ? { tools: entry.tools.map(tool => ({ ...tool, brief: sanitizeSecrets(tool.brief ?? "") })) } : {}),
444
+ ...(entry.tools ? { tools: entry.tools.map(tool => ({
445
+ ...tool,
446
+ brief: sanitizeSecrets(tool.brief ?? ""),
447
+ ...(typeof tool.input === "string" ? { input: sanitizeSecrets(tool.input) } : {}),
448
+ ...(typeof tool.result === "string" ? { result: sanitizeSecrets(tool.result) } : {}),
449
+ })) } : {}),
427
450
  })),
428
451
  }
429
452
  }
@@ -463,6 +486,10 @@ export interface CompanionOpenOptions {
463
486
  seat?: string
464
487
  /** The person's word to rename the existing session `-arch-<yyMMddHHmm>` and open a new one. */
465
488
  archive?: boolean
489
+ /** The model the seat's agent starts on, `claude-<family>-<version>` (ironsilk ≥ 0.9.85). */
490
+ model?: string
491
+ /** Start the seat's agent in Code Mode, CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 (ironsilk ≥ 0.9.85). */
492
+ codeMode?: boolean
466
493
  /** Act instead of returning the plan. */
467
494
  run?: boolean
468
495
  timeoutMs?: number
@@ -494,9 +521,14 @@ export async function openCompanion(opts: CompanionOpenOptions): Promise<TideCom
494
521
  throw new TideError(`companion ${name} must be letters, digits, '.', '_' or '-': ${JSON.stringify(value)}`)
495
522
  }
496
523
  }
524
+ if (opts.model !== undefined && !/^claude-[a-z0-9]+(?:-[a-z0-9]+)*$/.test(opts.model)) {
525
+ throw new TideError(`companion model must be a model id such as claude-fable-5-2: ${JSON.stringify(opts.model)}`)
526
+ }
497
527
  const args = ["companion", "open", "--episode", opts.episode, "--format", "json"]
498
528
  if (opts.seat) args.push("--seat", opts.seat)
499
529
  if (opts.archive) args.push("--archive")
530
+ if (opts.model) args.push("--model", opts.model)
531
+ if (opts.codeMode) args.push("--code-mode")
500
532
  if (opts.run) args.push("--run")
501
533
  const bin = await resolveTideBin()
502
534
  const timeoutMs = opts.timeoutMs ?? (opts.run ? 420_000 : 30_000)
@@ -691,6 +723,41 @@ async function tmuxTargetResolved(
691
723
  return stdout.split("\n").some((line) => line.trim() === target)
692
724
  }
693
725
 
726
+ /**
727
+ * tmux refuses one command of about 16 KB ("command too long", tmux 3.7c, measured
728
+ * 2026-11-16 on gaia: 15,752 bytes typed intact, 16 KB refused). A longer message is
729
+ * typed as several `send-keys -l` calls of at most this many UTF-8 bytes each
730
+ * (jgwill/Miadi#1031).
731
+ */
732
+ export const LITERAL_PART_BYTES = 8000
733
+
734
+ /** UTF-8 length of one code point, without Buffer or TextEncoder. */
735
+ function utf8Bytes(codePoint: number): number {
736
+ return codePoint < 0x80 ? 1 : codePoint < 0x800 ? 2 : codePoint < 0x10000 ? 3 : 4
737
+ }
738
+
739
+ /**
740
+ * A message cut into parts of at most `maxBytes` UTF-8 bytes, never inside a
741
+ * character. Joined, the parts are the message. An empty message is one empty part.
742
+ */
743
+ export function splitLiteral(message: string, maxBytes = LITERAL_PART_BYTES): string[] {
744
+ const parts: string[] = []
745
+ let current = ""
746
+ let bytes = 0
747
+ for (const ch of message) {
748
+ const size = utf8Bytes(ch.codePointAt(0) ?? 0)
749
+ if (current && bytes + size > maxBytes) {
750
+ parts.push(current)
751
+ current = ""
752
+ bytes = 0
753
+ }
754
+ current += ch
755
+ bytes += size
756
+ }
757
+ parts.push(current)
758
+ return parts
759
+ }
760
+
694
761
  /**
695
762
  * Build the exact `tmux send-keys` argv pair for a steer WITHOUT executing it.
696
763
  * Pure — safe for client-side previews and dry-run plans. `submit_command` is
@@ -816,11 +883,18 @@ export async function sendKeys(
816
883
  target: plan.target,
817
884
  resolveTarget: gate.resolveTarget ?? (() => tmuxTargetResolved(plan.target, bin, runOpts)),
818
885
  })
819
- try {
820
- await pExecFile(bin, plan.literal_command, runOpts)
821
- } catch (err) {
822
- const msg = err instanceof Error ? err.message : String(err)
823
- throw new TideError(`tmux send-keys to ${plan.target} failed (typing literal text): ${msg}`, err)
886
+ // `literal_command` is the whole message; a message over LITERAL_PART_BYTES is typed
887
+ // as that command once per part, in order (jgwill/Miadi#1031).
888
+ const parts = splitLiteral(message)
889
+ for (const [index, part] of parts.entries()) {
890
+ try {
891
+ await pExecFile(bin, [...plan.literal_command.slice(0, -1), part], runOpts)
892
+ } catch (err) {
893
+ const msg = err instanceof Error ? err.message : String(err)
894
+ const where = parts.length > 1 ? `, part ${index + 1} of ${parts.length}` : ""
895
+ throw new TideError(`tmux send-keys to ${plan.target} failed (typing literal text${where}): ${msg}`, err)
896
+ }
897
+ if (index < parts.length - 1) await new Promise((resolve) => setTimeout(resolve, 40))
824
898
  }
825
899
  if (plan.submit_command) {
826
900
  // A TUI (claude, ptpython) brackets a fast literal burst as a paste, and the
@@ -1112,6 +1186,11 @@ export interface TeamSessionOptions extends TideRunOptions {
1112
1186
  /** A name `teamStartChoices` offers, or null for a shell alone. */
1113
1187
  launch: string | null
1114
1188
  remote?: boolean
1189
+ /**
1190
+ * Code Mode: `--env CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1 --no-remote` (chronicle-tui ≥ 0.27.1).
1191
+ * It does not start with Remote Control, so `remote` is ignored while it is on.
1192
+ */
1193
+ codeMode?: boolean
1115
1194
  /** The first prompt, pasted once the agent is ready. */
1116
1195
  prompt?: string | null
1117
1196
  /** Start it; without this the answer is the plan. */
@@ -1186,7 +1265,8 @@ export function startTeamSession(opts: TeamSessionOptions): Promise<TeamSessionA
1186
1265
  const args = ["new", opts.team, opts.session, "--cwd", opts.cwd, "--json"]
1187
1266
  if (opts.launch === null) args.push("--no-launch")
1188
1267
  else args.push("--launch", opts.launch)
1189
- if (opts.remote && opts.launch !== null) args.push("--remote")
1268
+ if (opts.codeMode && opts.launch !== null) args.push("--env", "CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1", "--no-remote")
1269
+ else if (opts.remote && opts.launch !== null) args.push("--remote")
1190
1270
  const prompt = opts.launch !== null && opts.prompt ? opts.prompt : undefined
1191
1271
  if (prompt !== undefined) args.push("--prompt-file", "-")
1192
1272
  if (!opts.run) args.push("--dry-run")
@@ -1389,6 +1469,43 @@ export async function readyDraft(
1389
1469
  }
1390
1470
  }
1391
1471
 
1472
+ export interface TideDraftRun {
1473
+ id: string
1474
+ /** Enter was typed. False: tide held, and `reason` says why. */
1475
+ sent: boolean
1476
+ reason: string | null
1477
+ /** What tide completed before Enter, as labels: `a single quote closed`, … */
1478
+ completion: string[]
1479
+ line: string
1480
+ }
1481
+
1482
+ /** A draft's `changed_at` as `tide drafts list --json` gives it: ISO UTC with microseconds and offset. */
1483
+ export const DRAFT_SEEN_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|[+-]\d{2}:\d{2})$/
1484
+
1485
+ /**
1486
+ * Run a mctgo draft now (`tide.draft.run`, ironsilk ≥ 0.9.78 for `seen`): tide completes a line left
1487
+ * incomplete and presses Enter once at its prompt. `by` names who runs it. `agent` is a
1488
+ * scheduler seat (R3): tide then runs only a draft flagged judged, and never in front of a
1489
+ * focused terminal. `seen` is the `changed_at` the person was shown: a draft changed since is
1490
+ * refused, so Enter sends only what they saw. A hold is an answer with `sent: false`; refusals are `TideError`s of kind `exit`.
1491
+ */
1492
+ export async function runDraft(ref: string, opts: TideRunOptions & { by?: string; agent?: boolean; seen?: string } = {}): Promise<TideDraftRun> {
1493
+ const id = draftRef(ref)
1494
+ if (opts.seen !== undefined && !DRAFT_SEEN_PATTERN.test(opts.seen)) throw new TideError(`"${opts.seen}" is not a changed_at as tide drafts list gives it`)
1495
+ const args = ["drafts", "run", id, ...byArgs(opts.by), ...(opts.agent ? ["--agent"] : []), ...(opts.seen ? ["--seen", opts.seen] : [])]
1496
+ // Ctrl-C, the prompt, the paste and the guard take seconds.
1497
+ const line = await runDraftVerb(args, { ...opts, timeoutMs: opts.timeoutMs ?? 45_000 })
1498
+ // tide.draft.run <id> <pane> sent | held: <reason> [completed: <a>; <b>]
1499
+ const m = /^tide\.draft\.run\s+([0-9a-f]+)\s+\S+\s+(sent|held: (.*?))(?:\s{2}completed: (.*))?$/.exec(line)
1500
+ return {
1501
+ id: m?.[1] ?? id.replace(/^draft:/, ""),
1502
+ sent: m?.[2] === "sent",
1503
+ reason: m?.[3] ?? (m ? null : line),
1504
+ completion: m?.[4] ? m[4].split("; ") : [],
1505
+ line,
1506
+ }
1507
+ }
1508
+
1392
1509
  /** End a draft's ready flag (`tide.draft.unreadied`). It stays at its prompt, unsent. */
1393
1510
  export async function unreadyDraft(ref: string, opts: TideRunOptions & { by?: string } = {}): Promise<{ id: string; line: string }> {
1394
1511
  const id = draftRef(ref)