@miadi/tide 0.6.12 → 0.6.13
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 +14 -6
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -1146,16 +1146,23 @@ function resolveMct(): { bin: string; prefix: string[] } {
|
|
|
1146
1146
|
return { bin: "mct", prefix: [] }
|
|
1147
1147
|
}
|
|
1148
1148
|
|
|
1149
|
-
/**
|
|
1150
|
-
|
|
1149
|
+
/**
|
|
1150
|
+
* Run `mct`, keeping its JSON whatever it exits with: a refusal is exit 4 and still an answer.
|
|
1151
|
+
* `input` is its standard input: a person's first prompt, which on a command line every Unix user
|
|
1152
|
+
* of the host could read in /proc.
|
|
1153
|
+
*/
|
|
1154
|
+
async function runMct<T>(args: string[], timeoutMs: number, input?: string): Promise<T> {
|
|
1151
1155
|
const { bin, prefix } = resolveMct()
|
|
1152
1156
|
const startedAt = Date.now()
|
|
1153
1157
|
let stdout: string
|
|
1154
1158
|
let stderr = ""
|
|
1155
1159
|
try {
|
|
1156
|
-
|
|
1160
|
+
const run = pExecFile(bin, [...prefix, ...args], { timeout: timeoutMs, maxBuffer: 4 * 1024 * 1024 })
|
|
1161
|
+
run.child.stdin?.end(input ?? "")
|
|
1162
|
+
;({ stdout } = await run)
|
|
1157
1163
|
} catch (err) {
|
|
1158
1164
|
const e = err as ExecFileFailure & { code?: unknown; killed?: boolean; stdout?: string }
|
|
1165
|
+
if (e.code === "ENOENT") throw new TideError(`mct is not built in this checkout and not on PATH (${bin}): build @miadi/chronicle-tui, or name it with MIADI_MCT_BIN`, err)
|
|
1159
1166
|
if (typeof e.code !== "number" || e.killed) throw classifyExecFailure(bin, args, err, Date.now() - startedAt, timeoutMs)
|
|
1160
1167
|
stdout = String(e.stdout ?? "")
|
|
1161
1168
|
stderr = String(e.stderr ?? "")
|
|
@@ -1164,7 +1171,7 @@ async function runMct<T>(args: string[], timeoutMs: number): Promise<T> {
|
|
|
1164
1171
|
return JSON.parse(stdout) as T
|
|
1165
1172
|
} catch {
|
|
1166
1173
|
const said = `${stderr}${stdout}`.trim().split("\n")[0]
|
|
1167
|
-
if (/Unknown option|Unexpected list/.test(said)) throw new TideError(`${[bin, ...prefix].join(" ")} is older than @miadi/chronicle-tui 0.23.
|
|
1174
|
+
if (/Unknown option|Unexpected list/.test(said)) throw new TideError(`${[bin, ...prefix].join(" ")} is older than @miadi/chronicle-tui 0.23.1: ${said}`)
|
|
1168
1175
|
throw new TideError(said || `${bin} gave no answer to ${args.join(" ")}`)
|
|
1169
1176
|
}
|
|
1170
1177
|
}
|
|
@@ -1180,10 +1187,11 @@ export function startTeamSession(opts: TeamSessionOptions): Promise<TeamSessionA
|
|
|
1180
1187
|
if (opts.launch === null) args.push("--no-launch")
|
|
1181
1188
|
else args.push("--launch", opts.launch)
|
|
1182
1189
|
if (opts.remote && opts.launch !== null) args.push("--remote")
|
|
1183
|
-
|
|
1190
|
+
const prompt = opts.launch !== null && opts.prompt ? opts.prompt : undefined
|
|
1191
|
+
if (prompt !== undefined) args.push("--prompt-file", "-")
|
|
1184
1192
|
if (!opts.run) args.push("--dry-run")
|
|
1185
1193
|
else if (opts.expect) args.push("--expect", opts.expect)
|
|
1186
|
-
return runMct<TeamSessionAnswer>(args, opts.timeoutMs ?? 30_000)
|
|
1194
|
+
return runMct<TeamSessionAnswer>(args, opts.timeoutMs ?? 30_000, prompt)
|
|
1187
1195
|
}
|
|
1188
1196
|
|
|
1189
1197
|
// ── Drafts being prepared (jgwill/Miadi#691, Episode 548 S2 and H3) ─────────
|