@miadi/companion-ui 0.0.0-stage → 0.2.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/dist/node.js ADDED
@@ -0,0 +1,199 @@
1
+ /**
2
+ * `@miadi/companion-ui/node` — reads what the companion wrote, on the host that holds it.
3
+ *
4
+ * - Takes are capture bundles in the episode folder: `captures/<take>/capture.json`
5
+ * (`miadi.episode-capture.v1`) and `transcription_<take>_EN.txt` beside it. Only the
6
+ * descriptor and the transcript are read, never the audio and never a digest, so a
7
+ * room with twenty takes of twenty megabytes stays quick.
8
+ * - Replies are the companion phone page's records, one JSON line per reply in
9
+ * `<state>/replies/<episode>.jsonl`, with the person's thumbs in
10
+ * `<state>/replies/feedback/<episode>.jsonl` (jgwill/miadi-orchestration-kit,
11
+ * `claude/mia-episode-companion/phone-capture`). Only id, take, text, seat, session,
12
+ * time, related cards and the thumb leave this module. The reply's origin (user, host,
13
+ * pane, cwd) and its loop record stay on the host.
14
+ * - Forks are the episode's `branches/<name>/` folders that hold a brief: the trunk
15
+ * seat writes the brief when it forks a session to work a branch.
16
+ *
17
+ * Every reader answers an empty list when its folder or file is absent or unreadable.
18
+ */
19
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
20
+ import { homedir } from "node:os";
21
+ import { join } from "node:path";
22
+ const TAKE_ID = /^\d{12}$/;
23
+ const EPISODE_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
24
+ function readJson(file) {
25
+ try {
26
+ const value = JSON.parse(readFileSync(file, "utf8"));
27
+ return value && typeof value === "object" ? value : null;
28
+ }
29
+ catch {
30
+ return null;
31
+ }
32
+ }
33
+ function str(value) {
34
+ return typeof value === "string" && value.trim() ? value.trim() : undefined;
35
+ }
36
+ /** The takes filed in one episode folder, oldest first. */
37
+ export function readCompanionTakes(episodeDir) {
38
+ const captures = join(episodeDir, "captures");
39
+ let names;
40
+ try {
41
+ names = readdirSync(captures, { withFileTypes: true }).filter((e) => e.isDirectory() && TAKE_ID.test(e.name)).map((e) => e.name);
42
+ }
43
+ catch {
44
+ return [];
45
+ }
46
+ const takes = [];
47
+ for (const id of names) {
48
+ const folder = join(captures, id);
49
+ const capture = readJson(join(folder, "capture.json"));
50
+ const audio = (capture?.audio ?? null);
51
+ const outputs = Array.isArray(capture?.transcription?.outputs)
52
+ ? capture.transcription.outputs
53
+ : [];
54
+ const english = outputs.find((o) => str(o.language)?.toLowerCase() === "en");
55
+ const transcriptName = str(english?.filename) ?? `transcription_${id}_EN.txt`;
56
+ let text = "";
57
+ try {
58
+ text = readFileSync(join(folder, transcriptName.replace(/^.*\//, "")), "utf8").trim();
59
+ }
60
+ catch {
61
+ text = "";
62
+ }
63
+ let at = str(capture?.storedAt) ?? "";
64
+ if (!at) {
65
+ try {
66
+ at = statSync(folder).mtime.toISOString();
67
+ }
68
+ catch {
69
+ at = "";
70
+ }
71
+ }
72
+ const purpose = str(readJson(join(folder, "purpose.json"))?.purpose);
73
+ const audioName = str(audio?.filename);
74
+ const audioPath = str(audio?.relativePath) ?? (audioName ? `captures/${id}/${audioName}` : undefined);
75
+ takes.push({
76
+ id,
77
+ at,
78
+ text,
79
+ ...(audioPath && !audioPath.includes("..") && audioPath.startsWith(`captures/${id}/`) ? { audioPath } : {}),
80
+ ...(purpose ? { purpose } : {}),
81
+ });
82
+ }
83
+ return takes.sort((a, b) => a.at.localeCompare(b.at));
84
+ }
85
+ /**
86
+ * Where the companion phone page keeps its replies: `MIADI_PHONE_CAPTURE_STATE_DIR`,
87
+ * else `$XDG_STATE_HOME/miadi-phone-capture`, else `~/.local/state/miadi-phone-capture`,
88
+ * the same order the page itself reads, plus `/replies`.
89
+ */
90
+ export function companionRepliesDir(env = process.env, home = homedir()) {
91
+ const state = env.MIADI_PHONE_CAPTURE_STATE_DIR?.trim()
92
+ || join(env.XDG_STATE_HOME?.trim() || join(home, ".local", "state"), "miadi-phone-capture");
93
+ return join(state, "replies");
94
+ }
95
+ function jsonLines(file) {
96
+ let raw;
97
+ try {
98
+ raw = readFileSync(file, "utf8");
99
+ }
100
+ catch {
101
+ return [];
102
+ }
103
+ const out = [];
104
+ for (const line of raw.split("\n")) {
105
+ if (!line.trim())
106
+ continue;
107
+ try {
108
+ const value = JSON.parse(line);
109
+ if (value && typeof value === "object")
110
+ out.push(value);
111
+ }
112
+ catch {
113
+ // a torn line
114
+ }
115
+ }
116
+ return out;
117
+ }
118
+ function related(value) {
119
+ if (!Array.isArray(value))
120
+ return [];
121
+ return value
122
+ .map((r) => (r && typeof r === "object" ? r : {}))
123
+ .map((r) => ({ label: str(r.label) ?? "", href: str(r.href) ?? "", kind: str(r.kind) }))
124
+ .filter((r) => r.label && /^https?:\/\/\S+$/.test(r.href))
125
+ .map((r) => (r.kind ? { label: r.label, href: r.href, kind: r.kind } : { label: r.label, href: r.href }));
126
+ }
127
+ /** One episode's replies with the person's latest thumb on each, oldest first. */
128
+ export function readCompanionReplies(repliesDir, episode) {
129
+ if (!EPISODE_NAME.test(episode))
130
+ return [];
131
+ const thumbs = new Map();
132
+ for (const entry of jsonLines(join(repliesDir, "feedback", `${episode}.jsonl`))) {
133
+ const reply = str(entry.reply);
134
+ const value = entry.value;
135
+ if (reply && (value === "up" || value === "down" || value === ""))
136
+ thumbs.set(reply, value);
137
+ }
138
+ const replies = [];
139
+ for (const r of jsonLines(join(repliesDir, `${episode}.jsonl`))) {
140
+ const id = str(r.id);
141
+ const text = str(r.text);
142
+ const at = str(r.at);
143
+ if (!id || !text || !at || (r.episode !== undefined && r.episode !== episode))
144
+ continue;
145
+ const origin = (r.origin && typeof r.origin === "object" ? r.origin : {});
146
+ const take = str(r.take);
147
+ const cards = related(r.related);
148
+ const thumb = thumbs.get(id);
149
+ replies.push({
150
+ id,
151
+ take: take && TAKE_ID.test(take) ? take : null,
152
+ text,
153
+ seat: str(r.seat) ?? "",
154
+ ...(str(origin.session) ? { session: str(origin.session) } : {}),
155
+ at,
156
+ ...(cards.length ? { related: cards } : {}),
157
+ ...(thumb ? { feedback: thumb } : {}),
158
+ });
159
+ }
160
+ return replies.sort((a, b) => a.at.localeCompare(b.at));
161
+ }
162
+ /** The forks the companion drove, read from the episode's `branches/<name>/` folders that hold a brief. */
163
+ export function readCompanionForks(episodeDir) {
164
+ const branches = join(episodeDir, "branches");
165
+ if (!existsSync(branches))
166
+ return [];
167
+ const forks = [];
168
+ let names;
169
+ try {
170
+ names = readdirSync(branches, { withFileTypes: true }).filter((e) => e.isDirectory() && EPISODE_NAME.test(e.name)).map((e) => e.name);
171
+ }
172
+ catch {
173
+ return [];
174
+ }
175
+ const byNumber = (prefix) => (a, b) => {
176
+ const n = (name) => Number(new RegExp(`^${prefix}(?:-(\\d+))?\\.md$`).exec(name)?.[1] ?? 1);
177
+ return n(a) - n(b);
178
+ };
179
+ for (const name of names.sort()) {
180
+ let files;
181
+ try {
182
+ files = readdirSync(join(branches, name));
183
+ }
184
+ catch {
185
+ continue;
186
+ }
187
+ const briefs = files.filter((f) => /^brief(?:-\d+)?\.md$/.test(f)).sort(byNumber("brief"));
188
+ if (briefs.length === 0)
189
+ continue;
190
+ const reports = files.filter((f) => /^report(?:-\d+)?\.md$/.test(f)).sort(byNumber("report"));
191
+ forks.push({
192
+ name,
193
+ brief: `branches/${name}/${briefs[0]}`,
194
+ ...(reports.length ? { report: `branches/${name}/${reports.at(-1)}` } : {}),
195
+ });
196
+ }
197
+ return forks;
198
+ }
199
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAGhC,MAAM,OAAO,GAAG,UAAU,CAA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AA;QACnB,IAAI,CAAC;YACH,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAA;QAC3C,CAAC;QAAC,MAAM,CAAC;YACP,SAAQ;QACV,CAAC;QACD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAA;QAC1F,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,SAAQ;QACjC,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAA;QAC7F,KAAK,CAAC,IAAI,CAAC;YACT,IAAI;YACJ,KAAK,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE;YACtC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,IAAI,IAAI,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC5E,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * "Open Mia for this episode": the door to `tide companion open`, for any page.
3
+ *
4
+ * Pressing Enter (or "show plan") asks for the plan and says it in plain words. The gold
5
+ * button carries out that plan, and only that plan: changing the episode, the seat or the
6
+ * archive choice asks again. Opening takes minutes and a proxy may drop the request before
7
+ * tide answers, so while it runs the opener also asks for the plan every few seconds. tide
8
+ * answering "already listening" is the seat being there, whichever answer arrives first.
9
+ *
10
+ * A host that knows its episode passes `episode`, and the number field is not shown. Moved
11
+ * from Miadi `components/tide/companion-opener.tsx` (jgwill/Miadi#714, jgwill/Miadi#737).
12
+ */
13
+ import { type CSSProperties } from "react";
14
+ import { type CompanionPlan, type CompanionTransport } from "./seat.js";
15
+ export interface CompanionOpenerTheme {
16
+ accent: string;
17
+ background: string;
18
+ field: string;
19
+ text: string;
20
+ textDim: string;
21
+ danger: string;
22
+ success: string;
23
+ warning: string;
24
+ mono: string;
25
+ }
26
+ export declare const OPENER_THEME: CompanionOpenerTheme;
27
+ export interface CompanionOpenerProps {
28
+ transport: CompanionTransport;
29
+ /** The episode (number or vessel folder) when the host knows it; otherwise a number field asks. */
30
+ episode?: string;
31
+ /** The seats to offer, the first chosen. Default: the seats tide opens today. */
32
+ seats?: readonly string[];
33
+ /** Where the seat's pane is shown, for the "go to" link. No link when absent or null. */
34
+ paneHref?: (plan: CompanionPlan) => string | null;
35
+ /** Told once the seat listens. */
36
+ onOpened?: (plan: CompanionPlan) => void;
37
+ theme?: Partial<CompanionOpenerTheme>;
38
+ style?: CSSProperties;
39
+ }
40
+ export declare function CompanionOpener({ transport, episode: fixedEpisode, seats, paneHref, onOpened, theme, style }: CompanionOpenerProps): import("react").JSX.Element;
41
+ //# sourceMappingURL=opener.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opener.d.ts","sourceRoot":"","sources":["../src/opener.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AAEH,OAAO,EAA+B,KAAK,aAAa,EAAE,MAAM,OAAO,CAAA;AACvE,OAAO,EAQL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACxB,MAAM,WAAW,CAAA;AAKlB,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;CACb;AAED,eAAO,MAAM,YAAY,EAAE,oBAU1B,CAAA;AAED,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,kBAAkB,CAAA;IAC7B,mGAAmG;IACnG,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,iFAAiF;IACjF,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACzB,yFAAyF;IACzF,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,MAAM,GAAG,IAAI,CAAA;IACjD,kCAAkC;IAClC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAA;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAA;IACrC,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AAED,wBAAgB,eAAe,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,KAAuB,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,oBAAoB,+BAuMpJ"}
package/dist/opener.js ADDED
@@ -0,0 +1,135 @@
1
+ "use client";
2
+ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
3
+ /**
4
+ * "Open Mia for this episode": the door to `tide companion open`, for any page.
5
+ *
6
+ * Pressing Enter (or "show plan") asks for the plan and says it in plain words. The gold
7
+ * button carries out that plan, and only that plan: changing the episode, the seat or the
8
+ * archive choice asks again. Opening takes minutes and a proxy may drop the request before
9
+ * tide answers, so while it runs the opener also asks for the plan every few seconds. tide
10
+ * answering "already listening" is the seat being there, whichever answer arrives first.
11
+ *
12
+ * A host that knows its episode passes `episode`, and the number field is not shown. Moved
13
+ * from Miadi `components/tide/companion-opener.tsx` (jgwill/Miadi#714, jgwill/Miadi#737).
14
+ */
15
+ import { useEffect, useRef, useState } from "react";
16
+ import { COMPANION_SEATS, LISTENING, NOTHING_TO_RUN, sayFault, sayPlan, seatLabel, } from "./seat.js";
17
+ const POLL_MS = 5000;
18
+ const RUN_LIMIT_MS = 8 * 60_000;
19
+ export const OPENER_THEME = {
20
+ accent: "#d4a843",
21
+ background: "#16140e",
22
+ field: "#0e0d09",
23
+ text: "#e8e0c8",
24
+ textDim: "#a89f88",
25
+ danger: "#f87171",
26
+ success: "#4ade80",
27
+ warning: "#e0a030",
28
+ mono: "monospace",
29
+ };
30
+ export function CompanionOpener({ transport, episode: fixedEpisode, seats = COMPANION_SEATS, paneHref, onOpened, theme, style }) {
31
+ const t = { ...OPENER_THEME, ...theme };
32
+ const [typed, setTyped] = useState("");
33
+ const [seat, setSeat] = useState(seats[0] ?? "mia");
34
+ const [archive, setArchive] = useState(false);
35
+ const [busy, setBusy] = useState(null);
36
+ const [planned, setPlanned] = useState(null);
37
+ const [ran, setRan] = useState(null);
38
+ const [elapsed, setElapsed] = useState(0);
39
+ const runId = useRef(0);
40
+ const ep = (fixedEpisode ?? typed).trim();
41
+ const who = seatLabel(seat);
42
+ const key = `${ep}|${seat}|${archive}`;
43
+ const current = planned && planned.key === key ? planned.answer : null;
44
+ const plan = current?.plan ?? null;
45
+ const canRun = !!plan?.state && !NOTHING_TO_RUN.includes(plan.state) && busy === null && !ran;
46
+ const stale = planned !== null && planned.key !== key && ep !== "";
47
+ useEffect(() => {
48
+ if (busy !== "run")
49
+ return;
50
+ const t0 = Date.now();
51
+ const id = setInterval(() => setElapsed(Math.round((Date.now() - t0) / 1000)), 1000);
52
+ return () => clearInterval(id);
53
+ }, [busy]);
54
+ async function askPlan(next = {}) {
55
+ const forSeat = next.seat ?? seat;
56
+ const forArchive = next.archive ?? archive;
57
+ if (!ep || busy)
58
+ return;
59
+ setBusy("plan");
60
+ setRan(null);
61
+ const answer = await transport.open({ episode: ep, seat: forSeat, archive: forArchive });
62
+ setPlanned({ key: `${ep}|${forSeat}|${forArchive}`, answer });
63
+ setBusy(null);
64
+ }
65
+ async function run() {
66
+ if (!canRun)
67
+ return;
68
+ const id = ++runId.current;
69
+ const body = { episode: ep, seat, archive };
70
+ setBusy("run");
71
+ setElapsed(0);
72
+ const started = Date.now();
73
+ let done = false;
74
+ const finish = (answer, listening) => {
75
+ if (done || runId.current !== id)
76
+ return;
77
+ done = true;
78
+ setRan({ answer, listening });
79
+ setBusy(null);
80
+ if (listening || answer.plan?.executed) {
81
+ const p = answer.plan ?? plan;
82
+ if (p)
83
+ onOpened?.(p);
84
+ }
85
+ };
86
+ void transport.open({ ...body, run: true }).then((answer) => {
87
+ // The poll can see the seat listening before tide finishes typing the starter prompt.
88
+ // When tide's own answer arrives after that, it replaces the poll's so the steps show.
89
+ if (done && runId.current === id && answer.plan?.executed) {
90
+ setRan({ answer, listening: true });
91
+ return;
92
+ }
93
+ // tide answered (done, refused, failed) or the route refused: that is the outcome.
94
+ // A dropped connection or a proxy timeout is not: the poll below still watches for the seat.
95
+ if (answer.exitCode !== undefined || (answer.status !== undefined && answer.status < 500))
96
+ finish(answer, false);
97
+ });
98
+ while (!done && runId.current === id && Date.now() - started < RUN_LIMIT_MS) {
99
+ await new Promise((r) => setTimeout(r, POLL_MS));
100
+ if (done)
101
+ return;
102
+ const look = await transport.open({ episode: ep, seat });
103
+ if (look.plan?.state === LISTENING)
104
+ finish(look, true);
105
+ }
106
+ finish({ error: `No answer after ${RUN_LIMIT_MS / 60_000} minutes. Look for ${plan?.session} in the panes.` }, false);
107
+ }
108
+ const shown = ran?.answer ?? current;
109
+ const shownPlan = shown?.plan ?? null;
110
+ const faulted = shown && (shown.error || (shown.status && shown.status >= 400 && shown.status !== 409));
111
+ const openNow = ran && !faulted && (ran.listening || ran.answer.plan?.executed);
112
+ const pane = shownPlan && (openNow || shownPlan.state === LISTENING) ? (paneHref?.(shownPlan) ?? null) : null;
113
+ const box = {
114
+ padding: "12px 14px", border: `1px solid ${t.accent}55`, borderRadius: 8,
115
+ background: t.background, fontFamily: t.mono, fontSize: 13, color: t.textDim, ...style,
116
+ };
117
+ const primary = {
118
+ background: t.accent, color: t.background, border: `1px solid ${t.accent}`, borderRadius: 6,
119
+ padding: "0 16px", minHeight: 40, fontFamily: t.mono, fontSize: 13, fontWeight: 700, cursor: "pointer",
120
+ };
121
+ const secondary = {
122
+ background: "transparent", color: t.accent, border: `1px solid ${t.accent}`, borderRadius: 6,
123
+ padding: "0 14px", minHeight: 40, fontFamily: t.mono, fontSize: 13, cursor: "pointer",
124
+ };
125
+ const fieldId = `companion-episode-${seat}`;
126
+ return (_jsxs("div", { style: box, "data-companion-opener": fixedEpisode ? "episode" : "any", children: [_jsxs("form", { onSubmit: (e) => { e.preventDefault(); if (canRun && !stale)
127
+ void run();
128
+ else
129
+ void askPlan(); }, style: { display: "flex", flexWrap: "wrap", alignItems: "center", gap: 8 }, children: [fixedEpisode ? (_jsxs("span", { style: { color: t.accent, fontWeight: 700 }, children: ["Open ", who, " for this episode"] })) : (_jsxs(_Fragment, { children: [_jsxs("label", { htmlFor: fieldId, style: { color: t.accent, fontWeight: 700 }, children: ["Open ", who] }), _jsx("input", { id: fieldId, value: typed, onChange: (e) => { setTyped(e.target.value); setRan(null); }, placeholder: "episode", inputMode: "numeric", enterKeyHint: "go", autoComplete: "off", "aria-label": "episode number", style: { width: 90, minHeight: 40, background: t.field, color: t.text, border: `1px solid ${t.accent}88`,
130
+ borderRadius: 6, padding: "0 10px", fontFamily: t.mono, fontSize: 15 } })] })), seats.length > 1 && (_jsx("select", { "aria-label": "companion seat", value: seat, disabled: busy !== null, onChange: (e) => { setSeat(e.target.value); setRan(null); if (fixedEpisode)
131
+ void askPlan({ seat: e.target.value }); }, style: { minHeight: 40, background: t.field, color: t.text, border: `1px solid ${t.accent}88`, borderRadius: 6, fontFamily: t.mono }, children: seats.map((s) => _jsx("option", { value: s, children: seatLabel(s) }, s)) })), canRun && !stale ? (_jsxs("button", { type: "submit", style: primary, children: [plan?.state === "create" || plan?.state === "archive-then-create" ? "▶ open " : "▶ re-arm ", plan?.session] })) : (_jsx("button", { type: "submit", disabled: !ep || busy !== null, style: { ...(ep ? primary : secondary), opacity: ep ? 1 : 0.75 }, children: busy === "plan" ? "asking tide…" : busy === "run" ? `opening… ${elapsed}s` : "show plan ↵" })), _jsxs("label", { style: { display: "inline-flex", alignItems: "center", gap: 6, color: t.textDim, fontSize: 12 }, title: "Only on your word: rename the existing session -arch-<yyMMddHHmm> and open a new one", children: [_jsx("input", { type: "checkbox", checked: archive, disabled: busy !== null, onChange: (e) => { setArchive(e.target.checked); void askPlan({ archive: e.target.checked }); } }), "archive the existing session"] })] }), busy === "run" && (_jsxs("div", { style: { marginTop: 10, color: t.accent }, children: ["Opening ", plan?.session, ": starting ", who, ", arming the listener, sending the starter prompt. This takes a minute or two (", elapsed, "s)."] })), stale && busy === null && (_jsxs("div", { style: { marginTop: 10, color: t.textDim }, children: ["Press Enter to see what opening ", fixedEpisode ? "this episode" : `episode ${ep}`, " will do."] })), shown && !stale && busy !== "run" && (_jsxs("div", { style: { marginTop: 10, whiteSpace: "pre-wrap", wordBreak: "break-word", lineHeight: 1.5 }, children: [faulted ? _jsx("div", { style: { color: t.danger }, children: sayFault(shown) }) : null, shown.status === 409 && shown.message ? _jsx("div", { style: { color: t.danger }, children: shown.message }) : null, shownPlan && !faulted && (_jsxs(_Fragment, { children: [shownPlan.episode?.title && !fixedEpisode && (_jsxs("div", { style: { color: t.text }, children: ["episode ", shownPlan.episode.number, " \u00B7 ", shownPlan.episode.title] })), _jsx("div", { style: { color: openNow ? t.success : t.text, marginTop: 2 }, children: openNow ? `${who} is listening in ${shownPlan.session}.` : sayPlan(shownPlan, seat) }), pane && (_jsxs("a", { href: pane, style: { display: "inline-block", marginTop: 6, color: t.accent, textDecoration: "underline" }, children: ["go to ", shownPlan.session, " \u2192"] })), shownPlan.run?.warnings?.map((w) => _jsxs("div", { style: { color: t.warning }, children: ["warning: ", w] }, w)), (shownPlan.commands?.length || shownPlan.run?.steps?.length) ? (_jsxs("details", { style: { marginTop: 6, color: t.textDim }, children: [_jsx("summary", { style: { cursor: "pointer" }, children: shownPlan.run ? "steps taken" : "steps tide will take" }), shownPlan.run?.steps?.length
132
+ ? shownPlan.run.steps.map((s) => _jsxs("div", { children: [s.at.slice(11, 19), " ", s.step] }, `${s.at}-${s.step}`))
133
+ : (_jsx("ol", { style: { margin: "4px 0 0 18px", padding: 0 }, children: shownPlan.commands?.map((c) => _jsx("li", { children: c }, c)) })), !ran && shownPlan.starter_prompt && canRun && (_jsxs("div", { style: { marginTop: 4 }, children: ["starter prompt: ", shownPlan.starter_prompt] }))] })) : null] }))] }))] }));
134
+ }
135
+ //# sourceMappingURL=opener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opener.js","sourceRoot":"","sources":["../src/opener.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAsB,MAAM,OAAO,CAAA;AACvE,OAAO,EACL,eAAe,EACf,SAAS,EACT,cAAc,EACd,QAAQ,EACR,OAAO,EACP,SAAS,GAIV,MAAM,WAAW,CAAA;AAElB,MAAM,OAAO,GAAG,IAAI,CAAA;AACpB,MAAM,YAAY,GAAG,CAAC,GAAG,MAAM,CAAA;AAc/B,MAAM,CAAC,MAAM,YAAY,GAAyB;IAChD,MAAM,EAAE,SAAS;IACjB,UAAU,EAAE,SAAS;IACrB,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,SAAS;IACjB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,WAAW;CAClB,CAAA;AAgBD,MAAM,UAAU,eAAe,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,GAAG,eAAe,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAwB;IACnJ,MAAM,CA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,CAC/E,IACO,CACX,CAAC,CAAC,CAAC,IAAI,IACP,CACJ,IACG,CACP,IACG,CACP,CAAA;AACH,CAAC"}
package/dist/seat.d.ts ADDED
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Opening a companion seat, as data: the plan tide answers (`tide companion open
3
+ * --format json`), the states it names, and the transport a host gives the opener.
4
+ *
5
+ * The opener never holds a URL. A host passes a transport: Miadi passes
6
+ * `httpCompanionTransport("/api/tide/companion")`, a terminal host can call tide.
7
+ * jgwill/Miadi#714 (the seat), jgwill/Miadi#737 (the seat as one capability).
8
+ */
9
+ export type CompanionPlan = {
10
+ /** The seat tide declares: its key, plugin and listener command. */
11
+ seat?: {
12
+ key?: string;
13
+ plugin?: string;
14
+ listener?: string;
15
+ launcher?: string;
16
+ session_pattern?: string;
17
+ };
18
+ state?: string;
19
+ session?: string;
20
+ archive_name?: string | null;
21
+ commands?: string[];
22
+ starter_prompt?: string;
23
+ episode?: {
24
+ number?: number;
25
+ title?: string;
26
+ folder?: string;
27
+ path?: string;
28
+ };
29
+ pane?: {
30
+ pane_id?: string;
31
+ command?: string;
32
+ } | null;
33
+ listener?: {
34
+ state?: string;
35
+ };
36
+ executed?: boolean;
37
+ run?: {
38
+ steps?: {
39
+ at: string;
40
+ step: string;
41
+ }[];
42
+ warnings?: string[];
43
+ pane_id?: string | null;
44
+ };
45
+ };
46
+ export type CompanionAnswer = {
47
+ status?: number;
48
+ exitCode?: number;
49
+ plan?: CompanionPlan | null;
50
+ message?: string;
51
+ error?: string;
52
+ };
53
+ export interface CompanionOpenRequest {
54
+ /** Episode number or vessel folder name. */
55
+ episode: string;
56
+ /** Seat key; tide's default is `mia`. */
57
+ seat?: string;
58
+ /** The person's word to rename the existing session and open a new one. */
59
+ archive?: boolean;
60
+ /** Act on the plan; without it the answer is the plan. */
61
+ run?: boolean;
62
+ }
63
+ /** How the opener reaches tide. A refusal is an answer with `status` and `error`, never a throw. */
64
+ export interface CompanionTransport {
65
+ open(request: CompanionOpenRequest): Promise<CompanionAnswer>;
66
+ }
67
+ /** A transport over an HTTP route that takes the request as its JSON body (Miadi's `/api/tide/companion`). */
68
+ export declare function httpCompanionTransport(url: string, init?: {
69
+ headers?: Record<string, string>;
70
+ }): CompanionTransport;
71
+ /** The seats tide opens today. */
72
+ export declare const COMPANION_SEATS: readonly string[];
73
+ export declare const LISTENING = "re-arm: already listening";
74
+ /** Plan states in which pressing the button would do nothing. */
75
+ export declare const NOTHING_TO_RUN: readonly string[];
76
+ /** `mia` → `Mia`. */
77
+ export declare function seatLabel(seat: string): string;
78
+ /** What the plan will do, in words. tide's own step list stays below it for the detail. */
79
+ export declare function sayPlan(p: CompanionPlan, seat?: string): string;
80
+ /** A refusal from the route, in words the person can act on. */
81
+ export declare function sayFault(a: CompanionAnswer): string;
82
+ /** The tmux session tide names for a seat: `episode-<N>-<seat>-companion`. */
83
+ export declare function companionSessionName(episodeNumber: number | string, seat?: string): string;
84
+ //# sourceMappingURL=seat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seat.d.ts","sourceRoot":"","sources":["../src/seat.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,aAAa,GAAG;IAC1B,oEAAoE;IACpE,IAAI,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IACxG,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IACnB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,C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G,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAO,GAAG,kBAAkB,CAgBvH;AAED,kCAAkC;AAClC,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAAY,CAAA;AAEzD,eAAO,MAAM,SAAS,8BAA8B,CAAA;AAEpD,iEAAiE;AACjE,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAK3C,CAAA;AAED,qBAAqB;AACrB,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,2FAA2F;AAC3F,wBAAgB,OAAO,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,SAAuB,GAAG,MAAM,CA2B7E;AAED,gEAAgE;AAChE,wBAAgB,QAAQ,CAAC,CAAC,EAAE,eAAe,GAAG,MAAM,CAGnD;AAED,8EAA8E;AAC9E,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,SAAQ,GAAG,MAAM,CAEzF"}
package/dist/seat.js ADDED
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Opening a companion seat, as data: the plan tide answers (`tide companion open
3
+ * --format json`), the states it names, and the transport a host gives the opener.
4
+ *
5
+ * The opener never holds a URL. A host passes a transport: Miadi passes
6
+ * `httpCompanionTransport("/api/tide/companion")`, a terminal host can call tide.
7
+ * jgwill/Miadi#714 (the seat), jgwill/Miadi#737 (the seat as one capability).
8
+ */
9
+ /** A transport over an HTTP route that takes the request as its JSON body (Miadi's `/api/tide/companion`). */
10
+ export function httpCompanionTransport(url, init = {}) {
11
+ return {
12
+ async open(request) {
13
+ try {
14
+ const r = await fetch(url, {
15
+ method: "POST",
16
+ headers: { "Content-Type": "application/json", ...(init.headers ?? {}) },
17
+ body: JSON.stringify(request),
18
+ });
19
+ const a = (await r.json().catch(() => ({ error: `HTTP ${r.status}` })));
20
+ return { ...a, status: r.status };
21
+ }
22
+ catch (err) {
23
+ return { error: err instanceof Error ? err.message : String(err) };
24
+ }
25
+ },
26
+ };
27
+ }
28
+ /** The seats tide opens today. */
29
+ export const COMPANION_SEATS = ["mia"];
30
+ export const LISTENING = "re-arm: already listening";
31
+ /** Plan states in which pressing the button would do nothing. */
32
+ export const NOTHING_TO_RUN = [
33
+ LISTENING,
34
+ "re-arm: another seat listens on this episode",
35
+ "re-arm: pane runs something else",
36
+ "archive refused: the seat still listens",
37
+ ];
38
+ /** `mia` → `Mia`. */
39
+ export function seatLabel(seat) {
40
+ return seat ? seat[0].toUpperCase() + seat.slice(1) : seat;
41
+ }
42
+ /** What the plan will do, in words. tide's own step list stays below it for the detail. */
43
+ export function sayPlan(p, seat = p.seat?.key ?? "mia") {
44
+ const s = p.session ?? "the seat";
45
+ const who = seatLabel(seat);
46
+ const plugin = p.seat?.plugin ?? `${seat} companion`;
47
+ const listener = p.seat?.listener ?? "its listener";
48
+ switch (p.state) {
49
+ case "create":
50
+ return `Creates tmux session ${s} in the episode folder, starts ${who} with the ${plugin} plugin, arms ${listener} and sends the starter prompt.`;
51
+ case "archive-then-create":
52
+ return `Renames ${s} to ${p.archive_name ?? "an -arch- name"}, then creates a new ${s} with ${who} listening.`;
53
+ case LISTENING:
54
+ return `${who} already listens on this episode in ${s}. Nothing to open.`;
55
+ case "re-arm: another seat listens on this episode":
56
+ return `Another seat already listens on this episode. Nothing is done.`;
57
+ case "re-arm: start listener":
58
+ return `${s} runs ${who} but the seat is not listening. Arms ${listener}.`;
59
+ case "re-arm: relaunch with --resume":
60
+ return `${s} is a bare shell where ${who} ran before. Resumes that session there and arms ${listener}.`;
61
+ case "re-arm: launch in the existing shell":
62
+ return `${s} is a bare shell. Starts ${who} there, arms ${listener} and sends the starter prompt.`;
63
+ case "re-arm: pane runs something else":
64
+ return `${s} runs ${p.pane?.command ?? "something else"}, so nothing is done. Tick "archive" to rename it and open a new one.`;
65
+ case "archive refused: the seat still listens":
66
+ return `${s} still listens, so it is not archived. Close it with /exit first.`;
67
+ default:
68
+ return p.state ?? "";
69
+ }
70
+ }
71
+ /** A refusal from the route, in words the person can act on. */
72
+ export function sayFault(a) {
73
+ if (a.status === 401)
74
+ return "Sign in at /me first, from the tailnet or with a writer token.";
75
+ return a.error ?? a.message ?? `HTTP ${a.status}`;
76
+ }
77
+ /** The tmux session tide names for a seat: `episode-<N>-<seat>-companion`. */
78
+ export function companionSessionName(episodeNumber, seat = "mia") {
79
+ return `episode-${episodeNumber}-${seat}-companion`;
80
+ }
81
+ //# sourceMappingURL=seat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seat.js","sourceRoot":"","sources":["../src/seat.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAyCH,8GAA8G;AAC9G,MAAM,UAAU,sBAAsB,CAAC,GAAW,EAAE,OAA6C,EAAE;IACjG,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,OAAO;YAChB,IAAI,CAAC;gBACH,MAAM,CAAC,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;oBACzB,MAAM,EAAE,MAAM;oBACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE;oBACxE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;iBAC9B,CAAC,CAAA;gBACF,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAoB,CAAA;gBAC1F,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAA;YACnC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,EAAE,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OA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