@miadi/tide 0.6.14 → 0.6.15
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 +1 -1
- package/src/client.ts +113 -11
package/package.json
CHANGED
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?:
|
|
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(
|
|
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, ...
|
|
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 => ({
|
|
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
|
}
|
|
@@ -691,6 +714,41 @@ async function tmuxTargetResolved(
|
|
|
691
714
|
return stdout.split("\n").some((line) => line.trim() === target)
|
|
692
715
|
}
|
|
693
716
|
|
|
717
|
+
/**
|
|
718
|
+
* tmux refuses one command of about 16 KB ("command too long", tmux 3.7c, measured
|
|
719
|
+
* 2026-11-16 on gaia: 15,752 bytes typed intact, 16 KB refused). A longer message is
|
|
720
|
+
* typed as several `send-keys -l` calls of at most this many UTF-8 bytes each
|
|
721
|
+
* (jgwill/Miadi#1031).
|
|
722
|
+
*/
|
|
723
|
+
export const LITERAL_PART_BYTES = 8000
|
|
724
|
+
|
|
725
|
+
/** UTF-8 length of one code point, without Buffer or TextEncoder. */
|
|
726
|
+
function utf8Bytes(codePoint: number): number {
|
|
727
|
+
return codePoint < 0x80 ? 1 : codePoint < 0x800 ? 2 : codePoint < 0x10000 ? 3 : 4
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* A message cut into parts of at most `maxBytes` UTF-8 bytes, never inside a
|
|
732
|
+
* character. Joined, the parts are the message. An empty message is one empty part.
|
|
733
|
+
*/
|
|
734
|
+
export function splitLiteral(message: string, maxBytes = LITERAL_PART_BYTES): string[] {
|
|
735
|
+
const parts: string[] = []
|
|
736
|
+
let current = ""
|
|
737
|
+
let bytes = 0
|
|
738
|
+
for (const ch of message) {
|
|
739
|
+
const size = utf8Bytes(ch.codePointAt(0) ?? 0)
|
|
740
|
+
if (current && bytes + size > maxBytes) {
|
|
741
|
+
parts.push(current)
|
|
742
|
+
current = ""
|
|
743
|
+
bytes = 0
|
|
744
|
+
}
|
|
745
|
+
current += ch
|
|
746
|
+
bytes += size
|
|
747
|
+
}
|
|
748
|
+
parts.push(current)
|
|
749
|
+
return parts
|
|
750
|
+
}
|
|
751
|
+
|
|
694
752
|
/**
|
|
695
753
|
* Build the exact `tmux send-keys` argv pair for a steer WITHOUT executing it.
|
|
696
754
|
* Pure — safe for client-side previews and dry-run plans. `submit_command` is
|
|
@@ -816,11 +874,18 @@ export async function sendKeys(
|
|
|
816
874
|
target: plan.target,
|
|
817
875
|
resolveTarget: gate.resolveTarget ?? (() => tmuxTargetResolved(plan.target, bin, runOpts)),
|
|
818
876
|
})
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
877
|
+
// `literal_command` is the whole message; a message over LITERAL_PART_BYTES is typed
|
|
878
|
+
// as that command once per part, in order (jgwill/Miadi#1031).
|
|
879
|
+
const parts = splitLiteral(message)
|
|
880
|
+
for (const [index, part] of parts.entries()) {
|
|
881
|
+
try {
|
|
882
|
+
await pExecFile(bin, [...plan.literal_command.slice(0, -1), part], runOpts)
|
|
883
|
+
} catch (err) {
|
|
884
|
+
const msg = err instanceof Error ? err.message : String(err)
|
|
885
|
+
const where = parts.length > 1 ? `, part ${index + 1} of ${parts.length}` : ""
|
|
886
|
+
throw new TideError(`tmux send-keys to ${plan.target} failed (typing literal text${where}): ${msg}`, err)
|
|
887
|
+
}
|
|
888
|
+
if (index < parts.length - 1) await new Promise((resolve) => setTimeout(resolve, 40))
|
|
824
889
|
}
|
|
825
890
|
if (plan.submit_command) {
|
|
826
891
|
// A TUI (claude, ptpython) brackets a fast literal burst as a paste, and the
|
|
@@ -1389,6 +1454,43 @@ export async function readyDraft(
|
|
|
1389
1454
|
}
|
|
1390
1455
|
}
|
|
1391
1456
|
|
|
1457
|
+
export interface TideDraftRun {
|
|
1458
|
+
id: string
|
|
1459
|
+
/** Enter was typed. False: tide held, and `reason` says why. */
|
|
1460
|
+
sent: boolean
|
|
1461
|
+
reason: string | null
|
|
1462
|
+
/** What tide completed before Enter, as labels: `a single quote closed`, … */
|
|
1463
|
+
completion: string[]
|
|
1464
|
+
line: string
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
/** A draft's `changed_at` as `tide drafts list --json` gives it: ISO UTC with microseconds and offset. */
|
|
1468
|
+
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})$/
|
|
1469
|
+
|
|
1470
|
+
/**
|
|
1471
|
+
* Run a mctgo draft now (`tide.draft.run`, ironsilk ≥ 0.9.78 for `seen`): tide completes a line left
|
|
1472
|
+
* incomplete and presses Enter once at its prompt. `by` names who runs it. `agent` is a
|
|
1473
|
+
* scheduler seat (R3): tide then runs only a draft flagged judged, and never in front of a
|
|
1474
|
+
* focused terminal. `seen` is the `changed_at` the person was shown: a draft changed since is
|
|
1475
|
+
* refused, so Enter sends only what they saw. A hold is an answer with `sent: false`; refusals are `TideError`s of kind `exit`.
|
|
1476
|
+
*/
|
|
1477
|
+
export async function runDraft(ref: string, opts: TideRunOptions & { by?: string; agent?: boolean; seen?: string } = {}): Promise<TideDraftRun> {
|
|
1478
|
+
const id = draftRef(ref)
|
|
1479
|
+
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`)
|
|
1480
|
+
const args = ["drafts", "run", id, ...byArgs(opts.by), ...(opts.agent ? ["--agent"] : []), ...(opts.seen ? ["--seen", opts.seen] : [])]
|
|
1481
|
+
// Ctrl-C, the prompt, the paste and the guard take seconds.
|
|
1482
|
+
const line = await runDraftVerb(args, { ...opts, timeoutMs: opts.timeoutMs ?? 45_000 })
|
|
1483
|
+
// tide.draft.run <id> <pane> sent | held: <reason> [completed: <a>; <b>]
|
|
1484
|
+
const m = /^tide\.draft\.run\s+([0-9a-f]+)\s+\S+\s+(sent|held: (.*?))(?:\s{2}completed: (.*))?$/.exec(line)
|
|
1485
|
+
return {
|
|
1486
|
+
id: m?.[1] ?? id.replace(/^draft:/, ""),
|
|
1487
|
+
sent: m?.[2] === "sent",
|
|
1488
|
+
reason: m?.[3] ?? (m ? null : line),
|
|
1489
|
+
completion: m?.[4] ? m[4].split("; ") : [],
|
|
1490
|
+
line,
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1392
1494
|
/** End a draft's ready flag (`tide.draft.unreadied`). It stays at its prompt, unsent. */
|
|
1393
1495
|
export async function unreadyDraft(ref: string, opts: TideRunOptions & { by?: string } = {}): Promise<{ id: string; line: string }> {
|
|
1394
1496
|
const id = draftRef(ref)
|