@postshiba/cli 0.0.0-stage → 0.1.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/src/config.js ADDED
@@ -0,0 +1,91 @@
1
+ // @ts-check
2
+
3
+ import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
4
+ import { join } from "node:path";
5
+
6
+ export const DEFAULT_BASE_URL = "https://app.postshiba.com";
7
+
8
+ /**
9
+ * @param {NodeJS.ProcessEnv} [env]
10
+ * @param {string} [configDir]
11
+ */
12
+ export function resolveConfigDir(env = {}, configDir) {
13
+ if (configDir) return configDir;
14
+ if (env.XDG_CONFIG_HOME) return join(env.XDG_CONFIG_HOME, "postshiba");
15
+ const home = env.HOME ?? env.USERPROFILE;
16
+ if (!home) throw new Error("HOME or XDG_CONFIG_HOME is required");
17
+ return join(home, ".config", "postshiba");
18
+ }
19
+
20
+ /**
21
+ * @param {NodeJS.ProcessEnv} [env]
22
+ * @param {string} [configDir]
23
+ */
24
+ export function configFilePath(env, configDir) {
25
+ return join(resolveConfigDir(env, configDir), "config.json");
26
+ }
27
+
28
+ /**
29
+ * @param {NodeJS.ProcessEnv} [env]
30
+ * @param {string} [configDir]
31
+ * @returns {Promise<Record<string, string>>}
32
+ */
33
+ export async function readConfig(env, configDir) {
34
+ try {
35
+ return JSON.parse(await readFile(configFilePath(env, configDir), "utf8"));
36
+ } catch (err) {
37
+ if (err && /** @type {NodeJS.ErrnoException} */ (err).code === "ENOENT") return {};
38
+ throw err;
39
+ }
40
+ }
41
+
42
+ /**
43
+ * @param {NodeJS.ProcessEnv | undefined} env
44
+ * @param {string | undefined} configDir
45
+ * @param {Record<string, string>} data
46
+ */
47
+ export async function writeConfig(env, configDir, data) {
48
+ const dir = resolveConfigDir(env, configDir);
49
+ await mkdir(dir, { recursive: true });
50
+ const file = join(dir, "config.json");
51
+ await writeFile(file, `${JSON.stringify(data, null, 2)}\n`, { mode: 0o600 });
52
+ // writeFile mode is umask-masked; chmod is what makes 0600 stick.
53
+ await chmod(file, 0o600);
54
+ }
55
+
56
+ /**
57
+ * @param {NodeJS.ProcessEnv} [env]
58
+ * @param {string} [configDir]
59
+ */
60
+ export async function removeConfig(env, configDir) {
61
+ try {
62
+ await rm(configFilePath(env, configDir));
63
+ } catch (err) {
64
+ if (!err || /** @type {NodeJS.ErrnoException} */ (err).code !== "ENOENT") throw err;
65
+ }
66
+ }
67
+
68
+ /**
69
+ * @param {Record<string, unknown>} values
70
+ * @param {NodeJS.ProcessEnv} env
71
+ * @param {Record<string, string>} file
72
+ */
73
+ export function resolveCredentials(values, env, file) {
74
+ const apiKey = first(values["api-key"], env.POSTSHIBA_API_KEY, file.api_key);
75
+ const teamId = first(values.team, env.POSTSHIBA_TEAM_ID, file.team_id);
76
+ const clusterId = first(values.cluster, env.POSTSHIBA_CLUSTER_ID, file.cluster_id);
77
+ const baseUrl = String(
78
+ first(values["base-url"], env.POSTSHIBA_BASE_URL, file.base_url) ?? DEFAULT_BASE_URL,
79
+ ).replace(/\/$/, "");
80
+ return { apiKey, teamId, clusterId, baseUrl };
81
+ }
82
+
83
+ /**
84
+ * @param {...unknown} values
85
+ */
86
+ function first(...values) {
87
+ for (const value of values) {
88
+ if (value !== undefined && value !== null && value !== "") return /** @type {string} */ (value);
89
+ }
90
+ return undefined;
91
+ }
package/src/doctor.js ADDED
@@ -0,0 +1,124 @@
1
+ // @ts-check
2
+
3
+ import { request } from "./client.js";
4
+ import { domainVerified } from "./render.js";
5
+
6
+ /**
7
+ * @param {object} creds
8
+ * @param {string} [creds.apiKey]
9
+ * @param {string} [creds.teamId]
10
+ * @param {string} creds.baseUrl
11
+ * @param {typeof fetch} fetchImpl
12
+ */
13
+ export async function runDoctor(creds, fetchImpl) {
14
+ /** @type {{ id: string, ok: boolean, detail?: string, fix?: string }[]} */
15
+ const checks = [];
16
+
17
+ if (!creds.apiKey) {
18
+ checks.push({ id: "key", ok: false, fix: "postshiba login" });
19
+ } else {
20
+ try {
21
+ const me = /** @type {{ email?: string }} */ (
22
+ await request({
23
+ method: "GET",
24
+ url: `${creds.baseUrl}/api/v1/users/me`,
25
+ apiKey: creds.apiKey,
26
+ fetch: fetchImpl,
27
+ })
28
+ );
29
+ checks.push({ id: "key", ok: true, detail: me.email });
30
+ } catch (err) {
31
+ const message = err instanceof Error ? err.message : String(err);
32
+ checks.push({ id: "key", ok: false, detail: message, fix: "postshiba login" });
33
+ }
34
+ }
35
+
36
+ if (!creds.teamId) {
37
+ checks.push({ id: "team", ok: false, fix: "pass --team or run postshiba login" });
38
+ } else {
39
+ checks.push({ id: "team", ok: true, detail: creds.teamId });
40
+ }
41
+
42
+ if (creds.apiKey && creds.teamId) {
43
+ try {
44
+ const clusters = asList(
45
+ await request({
46
+ method: "GET",
47
+ url: `${creds.baseUrl}/api/v1/teams/${creds.teamId}/clusters`,
48
+ apiKey: creds.apiKey,
49
+ fetch: fetchImpl,
50
+ }),
51
+ );
52
+ const ready = clusters.find((item) => item.sending_ready);
53
+ if (ready) checks.push({ id: "cluster", ok: true, detail: String(ready.name ?? ready.id) });
54
+ else {
55
+ checks.push({
56
+ id: "cluster",
57
+ ok: false,
58
+ fix: `postshiba clusters create --data '{"name":"edge"}'`,
59
+ });
60
+ }
61
+ } catch (err) {
62
+ const message = err instanceof Error ? err.message : String(err);
63
+ checks.push({ id: "cluster", ok: false, detail: message, fix: "postshiba clusters list" });
64
+ }
65
+
66
+ try {
67
+ const domains = asList(
68
+ await request({
69
+ method: "GET",
70
+ url: `${creds.baseUrl}/api/v1/teams/${creds.teamId}/sending_domains`,
71
+ apiKey: creds.apiKey,
72
+ fetch: fetchImpl,
73
+ }),
74
+ );
75
+ const verified = domains.find(domainVerified);
76
+ if (verified) checks.push({ id: "sending_domain", ok: true, detail: String(verified.name) });
77
+ else {
78
+ checks.push({
79
+ id: "sending_domain",
80
+ ok: false,
81
+ fix: "postshiba sending-domains create",
82
+ });
83
+ }
84
+ } catch (err) {
85
+ const message = err instanceof Error ? err.message : String(err);
86
+ checks.push({
87
+ id: "sending_domain",
88
+ ok: false,
89
+ detail: message,
90
+ fix: "postshiba sending-domains create",
91
+ });
92
+ }
93
+ } else {
94
+ if (!checks.some((item) => item.id === "cluster")) {
95
+ checks.push({ id: "cluster", ok: false, fix: "postshiba clusters create --data '{\"name\":\"edge\"}'" });
96
+ }
97
+ if (!checks.some((item) => item.id === "sending_domain")) {
98
+ checks.push({ id: "sending_domain", ok: false, fix: "postshiba sending-domains create" });
99
+ }
100
+ }
101
+
102
+ return { ok: checks.every((item) => item.ok), checks };
103
+ }
104
+
105
+ /**
106
+ * @param {unknown} value
107
+ * @returns {Record<string, any>[]}
108
+ */
109
+ function asList(value) {
110
+ return Array.isArray(value) ? value.filter((item) => item && typeof item === "object") : [];
111
+ }
112
+
113
+ /**
114
+ * @param {{ id: string, ok: boolean, detail?: string, fix?: string }} check
115
+ */
116
+ export function doctorLabel(check) {
117
+ const labels = {
118
+ key: "API key",
119
+ team: "Team id",
120
+ cluster: "Sending-ready cluster",
121
+ sending_domain: "Verified sending domain",
122
+ };
123
+ return labels[/** @type {keyof typeof labels} */ (check.id)] ?? check.id;
124
+ }
package/src/domains.js ADDED
@@ -0,0 +1,67 @@
1
+ // @ts-check
2
+
3
+ import { request } from "./client.js";
4
+ import { interpolatePath } from "./commands.js";
5
+ import { spinning } from "./prompts.js";
6
+ import { colorsFor, domainDnsRows, domainVerified, formatTable } from "./render.js";
7
+
8
+ const VERIFY_MS = 10_000;
9
+ const VERIFY_LIMIT_MS = 5 * 60 * 1000;
10
+
11
+ /**
12
+ * @param {object} ctx
13
+ * @param {boolean} ctx.interactive
14
+ * @param {import("./prompts.js").Prompts} [ctx.prompts]
15
+ * @param {typeof fetch} ctx.fetch
16
+ * @param {{ write: (chunk: string) => unknown }} ctx.stdout
17
+ * @param {NodeJS.ProcessEnv} ctx.env
18
+ * @param {boolean} [ctx.isTTY]
19
+ * @param {(ms: number) => Promise<void>} [ctx.sleep]
20
+ * @param {{ apiKey: string, teamId: string, baseUrl: string }} creds
21
+ */
22
+ export async function createSendingDomainWizard(ctx, creds) {
23
+ if (!ctx.prompts) throw new Error("prompts required");
24
+ const name = await ctx.prompts.text({
25
+ message: "Domain",
26
+ placeholder: "mail.example.com",
27
+ });
28
+ const path = interpolatePath("/api/v1/teams/:teamId/sending_domains", { teamId: creds.teamId });
29
+ const created = /** @type {Record<string, unknown>} */ (
30
+ await spinning(
31
+ ctx.prompts,
32
+ "Creating sending domain",
33
+ () => request({ method: "POST", url: `${creds.baseUrl}${path}`, apiKey: creds.apiKey, body: { name }, fetch: ctx.fetch }),
34
+ (domain) => `Created ${/** @type {Record<string, unknown>} */ (domain).name ?? name}`,
35
+ )
36
+ );
37
+
38
+ const c = colorsFor(ctx);
39
+ const rows = domainDnsRows(created);
40
+ if (rows.length) {
41
+ ctx.stdout.write(`${formatTable(rows, ["type", "name", "value"], c)}\n`);
42
+ }
43
+
44
+ const wait = await ctx.prompts.confirm({ message: "Wait for verification?" });
45
+ if (!wait) return created;
46
+
47
+ const id = String(created.id ?? "");
48
+ const verifyPath = interpolatePath("/api/v1/sending_domains/:id/verify", { id });
49
+ const started = Date.now();
50
+ const sleep = ctx.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
51
+ return spinning(
52
+ ctx.prompts,
53
+ "Waiting for DNS",
54
+ async () => {
55
+ let latest = created;
56
+ while (Date.now() - started < VERIFY_LIMIT_MS) {
57
+ latest = /** @type {Record<string, unknown>} */ (
58
+ await request({ method: "POST", url: `${creds.baseUrl}${verifyPath}`, apiKey: creds.apiKey, fetch: ctx.fetch })
59
+ );
60
+ if (domainVerified(latest)) return latest;
61
+ await sleep(VERIFY_MS);
62
+ }
63
+ return latest;
64
+ },
65
+ (latest) => (domainVerified(latest) ? "Verified" : "Still pending. Run postshiba sending-domains verify later."),
66
+ );
67
+ }
package/src/errors.js ADDED
@@ -0,0 +1,33 @@
1
+ // @ts-check
2
+
3
+ export class UsageError extends Error {
4
+ /**
5
+ * @param {string} message
6
+ * @param {{ helpResource?: string }} [opts]
7
+ */
8
+ constructor(message, opts = {}) {
9
+ super(message);
10
+ this.name = "UsageError";
11
+ this.helpResource = opts.helpResource;
12
+ }
13
+ }
14
+
15
+ export class CancelError extends Error {
16
+ constructor(message = "Cancelled.") {
17
+ super(message);
18
+ this.name = "CancelError";
19
+ }
20
+ }
21
+
22
+ /**
23
+ * @param {{ write: (chunk: string) => unknown }} stderr
24
+ * @param {{ message: string, field?: string | null, status?: number | null, error?: string }} err
25
+ */
26
+ export function writeApiError(stderr, err) {
27
+ let line = `Error: ${err.message}`;
28
+ if (err.field) line += ` (field: ${err.field})`;
29
+ stderr.write(`${line}\n`);
30
+ if (err.status === 429 && err.error === "throttled") {
31
+ stderr.write("The cluster hit its hourly send limit. Wait until the next hour before retrying.\n");
32
+ }
33
+ }
package/src/help.js ADDED
@@ -0,0 +1,84 @@
1
+ // @ts-check
2
+
3
+ import { actionUsage, actionsFor, commands, resources } from "./commands.js";
4
+ import { VERSION } from "./pkg.js";
5
+
6
+ /**
7
+ * @param {string} [topic]
8
+ */
9
+ export function formatHelp(topic) {
10
+ if (!topic) return generalHelp();
11
+ if (topic === "send") return sendHelp();
12
+ if (topic === "login" || topic === "logout" || topic === "whoami") return generalHelp();
13
+ if (topic === "doctor") return "Usage: postshiba doctor [--json]";
14
+ if (topic === "skills") return "Usage: postshiba skills install [--global] [--target cursor|claude|agents]";
15
+ const rows = actionsFor(topic);
16
+ if (rows.length === 0) return "";
17
+ const lines = [`Usage: postshiba ${topic} <action> [ids]`, "", "Actions:"];
18
+ for (const row of rows) {
19
+ lines.push(` ${actionUsage(row)}`);
20
+ }
21
+ lines.push("", "Pass --data JSON, --data @file.json, or --data - for writes.");
22
+ return lines.join("\n");
23
+ }
24
+
25
+ function generalHelp() {
26
+ const width = Math.max(...resources().map((name) => name.length));
27
+ const lines = [
28
+ `postshiba ${VERSION}`,
29
+ "",
30
+ "Usage: postshiba <command>",
31
+ "",
32
+ "Commands:",
33
+ " login Sign in and write the local config file",
34
+ " logout Remove the local config file",
35
+ " whoami Print the signed-in user",
36
+ " send Send an email",
37
+ " doctor Check key, team, cluster, and domain",
38
+ " skills install Copy the agent skill into this project",
39
+ " help [resource] Show this help or help for a resource",
40
+ "",
41
+ "Resources:",
42
+ ];
43
+ for (const name of resources()) {
44
+ const actions = commands.filter((row) => row.resource === name).map((row) => row.action);
45
+ lines.push(` ${name.padEnd(width)} ${actions.join(", ")}`);
46
+ }
47
+ lines.push(
48
+ "",
49
+ "Options:",
50
+ " --json Print API JSON. Never prompt.",
51
+ " --no-input Plain mode. Never prompt.",
52
+ " --yes Skip confirm for delete, suspend, release, unassign",
53
+ " --api-key KEY API key (POSTSHIBA_API_KEY)",
54
+ " --team ID Team id (POSTSHIBA_TEAM_ID)",
55
+ " --base-url URL API base URL (POSTSHIBA_BASE_URL)",
56
+ " -h, --help Show help",
57
+ " --version Print version",
58
+ );
59
+ return lines.join("\n");
60
+ }
61
+
62
+ function sendHelp() {
63
+ return [
64
+ "Usage: postshiba send [options]",
65
+ "",
66
+ " --from ADDR from",
67
+ " --to ADDR to (repeatable)",
68
+ " --cc ADDR --bcc ADDR cc / bcc (repeatable)",
69
+ " --reply-to ADDR reply_to",
70
+ " --subject TEXT subject",
71
+ " --text TEXT text",
72
+ " --html HTML html",
73
+ " --template ID template.id",
74
+ " --var KEY=VALUE template.variables (repeatable)",
75
+ " --header \"Name: value\" headers (repeatable)",
76
+ " --arg KEY=VALUE unique_args (repeatable)",
77
+ " --attach PATH attachments (repeatable)",
78
+ " --tenant NAME tenant",
79
+ " --cluster ID X-Capsule-Cluster-Id on POST /api/v1/emails",
80
+ " --sandbox POST /api/v1/teams/:teamId/clusters/:clusterId/sends (requires --cluster)",
81
+ " --idempotency-key KEY Idempotency-Key on the cluster send path (requires --cluster)",
82
+ " --data JSON base body; flags override keys",
83
+ ].join("\n");
84
+ }
package/src/login.js ADDED
@@ -0,0 +1,107 @@
1
+ // @ts-check
2
+
3
+ import { request } from "./client.js";
4
+ import { readConfig, removeConfig, writeConfig } from "./config.js";
5
+ import { UsageError } from "./errors.js";
6
+ import { spinning } from "./prompts.js";
7
+
8
+ /**
9
+ * @param {Record<string, any>} values
10
+ * @param {object} ctx
11
+ * @param {NodeJS.ProcessEnv} ctx.env
12
+ * @param {string} [ctx.configDir]
13
+ * @param {typeof fetch} ctx.fetch
14
+ * @param {{ write: (chunk: string) => unknown }} ctx.stdout
15
+ * @param {boolean} ctx.interactive
16
+ * @param {import("./prompts.js").Prompts} [ctx.prompts]
17
+ */
18
+ export async function login(values, ctx) {
19
+ let apiKey = values["api-key"] || ctx.env.POSTSHIBA_API_KEY;
20
+ if (!apiKey && ctx.interactive && ctx.prompts) {
21
+ apiKey = await ctx.prompts.password({ message: "API key" });
22
+ }
23
+ if (!apiKey) {
24
+ throw new UsageError("Missing API key. Run postshiba login or set POSTSHIBA_API_KEY.");
25
+ }
26
+
27
+ let teamId = values.team || ctx.env.POSTSHIBA_TEAM_ID;
28
+ const baseUrl = (values["base-url"] || ctx.env.POSTSHIBA_BASE_URL || "https://app.postshiba.com").replace(/\/$/, "");
29
+
30
+ const me = /** @type {{ email?: string }} */ (
31
+ await spinning(
32
+ ctx.interactive ? ctx.prompts : null,
33
+ "Checking key",
34
+ () => request({ method: "GET", url: `${baseUrl}/api/v1/users/me`, apiKey, fetch: ctx.fetch }),
35
+ (user) => `Signed in as ${/** @type {{ email?: string }} */ (user).email ?? "unknown"}`,
36
+ )
37
+ );
38
+
39
+ if (!teamId && ctx.interactive && ctx.prompts) {
40
+ teamId = await ctx.prompts.text({
41
+ message: "Team id",
42
+ placeholder: "on the API keys page",
43
+ });
44
+ }
45
+
46
+ /** @type {Record<string, string>} */
47
+ const saved = { api_key: apiKey };
48
+ if (teamId) saved.team_id = teamId;
49
+ if (values["base-url"] || ctx.env.POSTSHIBA_BASE_URL) saved.base_url = baseUrl;
50
+
51
+ if (teamId && ctx.interactive && ctx.prompts) {
52
+ const clusters = await listClusters(baseUrl, apiKey, teamId, ctx.fetch);
53
+ if (clusters.length === 1) saved.cluster_id = String(clusters[0].id);
54
+ else if (clusters.length > 1) {
55
+ saved.cluster_id = await ctx.prompts.select({
56
+ message: "Default cluster",
57
+ options: clusters.map((item) => ({
58
+ value: String(item.id),
59
+ label: String(item.name ?? item.id),
60
+ })),
61
+ });
62
+ }
63
+ }
64
+
65
+ await writeConfig(ctx.env, ctx.configDir, saved);
66
+ ctx.stdout.write(`Signed in as ${me.email}\n`);
67
+ return 0;
68
+ }
69
+
70
+ /**
71
+ * @param {object} ctx
72
+ * @param {NodeJS.ProcessEnv} ctx.env
73
+ * @param {string} [ctx.configDir]
74
+ * @param {boolean} ctx.interactive
75
+ * @param {import("./prompts.js").Prompts} [ctx.prompts]
76
+ */
77
+ export async function logout(ctx) {
78
+ await removeConfig(ctx.env, ctx.configDir);
79
+ if (ctx.interactive && ctx.prompts) ctx.prompts.outro("Signed out.");
80
+ return 0;
81
+ }
82
+
83
+ /**
84
+ * @param {string} baseUrl
85
+ * @param {string} apiKey
86
+ * @param {string} teamId
87
+ * @param {typeof fetch} fetchImpl
88
+ */
89
+ async function listClusters(baseUrl, apiKey, teamId, fetchImpl) {
90
+ const body = await request({
91
+ method: "GET",
92
+ url: `${baseUrl}/api/v1/teams/${teamId}/clusters`,
93
+ apiKey,
94
+ fetch: fetchImpl,
95
+ });
96
+ return Array.isArray(body) ? body.filter((item) => item && typeof item === "object") : [];
97
+ }
98
+
99
+ /**
100
+ * @param {object} ctx
101
+ * @param {NodeJS.ProcessEnv} ctx.env
102
+ * @param {string} [ctx.configDir]
103
+ */
104
+ export async function hasSavedKey(ctx) {
105
+ const file = await readConfig(ctx.env, ctx.configDir);
106
+ return Boolean(file.api_key);
107
+ }
package/src/menu.js ADDED
@@ -0,0 +1,51 @@
1
+ // @ts-check
2
+
3
+ import { actionsFor, resources } from "./commands.js";
4
+ import { hasSavedKey } from "./login.js";
5
+ import { colorsFor, wordmark } from "./render.js";
6
+
7
+ /**
8
+ * @param {object} ctx
9
+ * @param {import("./prompts.js").Prompts} ctx.prompts
10
+ * @param {boolean} ctx.interactive
11
+ * @param {{ write: (chunk: string) => unknown }} ctx.stdout
12
+ * @param {NodeJS.ProcessEnv} ctx.env
13
+ * @param {string} [ctx.configDir]
14
+ * @param {boolean} [ctx.isTTY]
15
+ * @param {(choice: string, action?: string) => Promise<number>} runChoice
16
+ */
17
+ export async function mainMenu(ctx, runChoice) {
18
+ const c = colorsFor(ctx);
19
+ ctx.prompts.intro(wordmark(c));
20
+ const signedIn = await hasSavedKey(ctx);
21
+ const choice = await ctx.prompts.select({
22
+ message: "What do you want to do?",
23
+ options: [
24
+ { value: "send", label: "Send an email" },
25
+ { value: "sending-domains", label: "Add a sending domain" },
26
+ { value: "clusters", label: "Clusters" },
27
+ { value: "inboxes", label: "Inboxes" },
28
+ { value: "templates", label: "Templates" },
29
+ { value: "events", label: "Events" },
30
+ { value: "webhooks", label: "Webhooks" },
31
+ { value: "doctor", label: "Check my setup" },
32
+ { value: signedIn ? "logout" : "login", label: signedIn ? "Sign out" : "Sign in" },
33
+ { value: "skills", label: "Install the agent skill" },
34
+ { value: "quit", label: "Quit" },
35
+ ],
36
+ });
37
+ if (choice === "quit") {
38
+ ctx.prompts.outro("Later.");
39
+ return 0;
40
+ }
41
+ if (choice === "sending-domains") return runChoice("sending-domains", "create");
42
+ if (resources().includes(choice)) {
43
+ const rows = actionsFor(choice);
44
+ const action = await ctx.prompts.select({
45
+ message: `${choice}`,
46
+ options: rows.map((row) => ({ value: row.action, label: row.action })),
47
+ });
48
+ return runChoice(choice, action);
49
+ }
50
+ return runChoice(choice);
51
+ }
package/src/mode.js ADDED
@@ -0,0 +1,16 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * One decision at the process boundary. Interactive only when both
5
+ * streams are TTYs, --json/--no-input are absent, and CI is unset.
6
+ *
7
+ * @param {{ json?: boolean, "no-input"?: boolean }} flags
8
+ * @param {{ env?: NodeJS.ProcessEnv, isTTY?: boolean, stdin?: { isTTY?: boolean }, stdout?: { isTTY?: boolean } }} io
9
+ */
10
+ export function isInteractive(flags, io) {
11
+ if (flags.json || flags["no-input"]) return false;
12
+ if (io.env && io.env.CI) return false;
13
+ if (io.isTTY === false) return false;
14
+ if (io.isTTY === true) return true;
15
+ return Boolean(io.stdin && io.stdin.isTTY && io.stdout && io.stdout.isTTY);
16
+ }
package/src/pkg.js ADDED
@@ -0,0 +1,9 @@
1
+ // @ts-check
2
+
3
+ import { readFileSync } from "node:fs";
4
+ import { dirname, join } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ export const PACKAGE_ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
8
+ export const VERSION = JSON.parse(readFileSync(join(PACKAGE_ROOT, "package.json"), "utf8")).version;
9
+ export const SKILL_FILE = join(PACKAGE_ROOT, "skills/postshiba-cli/SKILL.md");