@ghostystudio/cli 0.12.0 → 0.13.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.
Files changed (3) hide show
  1. package/README.md +7 -0
  2. package/dist/index.js +96 -11
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -35,6 +35,9 @@ ghosty dbs ls|tables|query|import|grant|revoke <id> [db] [--write] [--arg V]
35
35
  ghosty turns ls <id> [--errors | --status running|done|stopped|error] [--since 1h] [--limit N]
36
36
  ghosty turns show <id> [turn-id|last] # where a turn's time went: each tool with its seconds, output tokens
37
37
  ghosty channels whatsapp ls|enable|disable <id> [number] [--dry-run]
38
+ ghosty channels whatsapp link|unlink <id> --integration ID --answer on|off [--forward] [--dry-run] # bring a WABA number from Formmy
39
+ ghosty channels wa import <id> --from-file F --own-number yes|no [--dry-run] # personal WhatsApp session, no QR
40
+ ghosty channels wa pair|status|pause <id> [--phone N]
38
41
  ghosty channels wa groups ls|set|create <id> [group] [--role equipo|cliente] [--on|--off] [--dry-run] # personal WhatsApp groups
39
42
  ghosty board archive <id> --integration X | --column X | --before 30d [--dry-run]
40
43
  ghosty mcp get|set <id> [--file servers.json]
@@ -76,6 +79,10 @@ Exit codes: `0` ok · `1` API error · `2` usage error · `3` not signed in.
76
79
  - `try --replay FILE --out DIR`: replays real conversations from your machine. The report is written after every step, survives Ghosty deploys (it honors `Retry-After`), and `--resume` continues a partial run.
77
80
  - `agents doctor` speaks English like the rest of the CLI; `channels whatsapp ls` returns a full URL.
78
81
 
82
+ ### Changes in 0.13.0
83
+
84
+ - Migrate WhatsApp numbers without signing up again: `channels whatsapp link|unlink` (a WhatsApp Business number that lives in Formmy; `--answer on|off` is required, `--dry-run` shows what changes in gs and in Formmy) and `channels wa import` (a personal WhatsApp session exported from EasyBits, no QR). Also `channels wa pair --phone` (pairing code), `wa status` and `wa pause`.
85
+
79
86
  ### Changes in 0.12.0
80
87
 
81
88
  - New: `channels wa groups ls|set|create`: which groups of the agent's personal WhatsApp it answers, and as `equipo` or `cliente`. Turning a group on asks first (`--yes` without a terminal); `--dry-run` shows the plan.
package/dist/index.js CHANGED
@@ -282,7 +282,7 @@ async function postLong(path, body, timeoutMs = 9e5) {
282
282
  const req = httpsRequest(`${base}${path}`, {
283
283
  method: "POST",
284
284
  timeout: timeoutMs,
285
- headers: { authorization: `Bearer ${token}`, "user-agent": `ghosty-cli/${"0.12.0"}`, "content-type": "application/json", "content-length": Buffer.byteLength(data) }
285
+ headers: { authorization: `Bearer ${token}`, "user-agent": `ghosty-cli/${"0.13.0"}`, "content-type": "application/json", "content-length": Buffer.byteLength(data) }
286
286
  }, (res) => {
287
287
  let buf = "";
288
288
  res.on("data", (c) => buf += c);
@@ -324,7 +324,7 @@ async function request(path, opts = {}, retried = false) {
324
324
  method: opts.method ?? (opts.body !== void 0 || opts.raw !== void 0 ? "POST" : "GET"),
325
325
  headers: {
326
326
  authorization: `Bearer ${token}`,
327
- "user-agent": `ghosty-cli/${"0.12.0"}`,
327
+ "user-agent": `ghosty-cli/${"0.13.0"}`,
328
328
  ...opts.body !== void 0 ? { "content-type": "application/json" } : {},
329
329
  ...opts.headers
330
330
  },
@@ -1136,7 +1136,7 @@ async function call(path, v, init = {}) {
1136
1136
  "x-ghosty-ts": ts,
1137
1137
  "x-ghosty-sig": sig,
1138
1138
  "content-type": "application/json",
1139
- "user-agent": `ghosty-cli/${"0.12.0"}`
1139
+ "user-agent": `ghosty-cli/${"0.13.0"}`
1140
1140
  },
1141
1141
  body: method === "GET" ? void 0 : raw
1142
1142
  });
@@ -1574,6 +1574,7 @@ async function credentialsCmd2(sub, provider, v) {
1574
1574
  }
1575
1575
 
1576
1576
  // src/commands/channels.ts
1577
+ import { readFile as readFile6 } from "node:fs/promises";
1577
1578
  var enc7 = encodeURIComponent;
1578
1579
  var digits = (s) => s.replace(/\D/g, "");
1579
1580
  function find(nums, ref) {
@@ -1585,6 +1586,8 @@ function find(nums, ref) {
1585
1586
  async function channelsCmd(kind, sub, id, ref, v) {
1586
1587
  if (kind !== "whatsapp" && kind !== "wa") throw usage(`Unknown channel: ${kind ?? "(none)"}.`, "Try: ghosty channels whatsapp ls <agent-id>");
1587
1588
  if (!id) throw usage("Missing agent id.", "Example: ghosty channels whatsapp ls <agent-id>");
1589
+ if (sub === "link" || sub === "unlink") return linkCmd(sub, id, v);
1590
+ if (sub === "import" || sub === "status" || sub === "pause" || sub === "pair") return waCmd(sub, id, v);
1588
1591
  if (sub === "enable" && !v["dry-run"]) requireYesIfHeadless(v.yes, `ghosty channels whatsapp enable ${id} ${ref ?? "<number>"}`);
1589
1592
  const path = `/api/v2/agents/${enc7(id)}/whatsapp`;
1590
1593
  const cur = await api(path);
@@ -1592,7 +1595,7 @@ async function channelsCmd(kind, sub, id, ref, v) {
1592
1595
  const rows = cur.numbers.map((n2) => ({ number: n2.label, answers: n2.mine ? lavender("this agent") : n2.takenByOther ? "another agent" : dim("nobody (silent)"), id: n2.id }));
1593
1596
  return out(cur, () => rows.length ? table(rows, ["number", "answers", "id"]) : dim(`No WhatsApp Business numbers yet. Pair one at ${cur.salesUrl}`));
1594
1597
  }
1595
- if (sub !== "enable" && sub !== "disable") throw usage(`Unknown subcommand: ${sub}.`, "Try: ghosty channels whatsapp ls | enable | disable <agent-id> <number>");
1598
+ if (sub !== "enable" && sub !== "disable") throw usage(`Unknown subcommand: ${sub}.`, "Try: ghosty channels whatsapp ls | enable | disable | link | unlink \xB7 ghosty channels wa import | status | pause | groups");
1596
1599
  if (!ref) throw usage("Missing number.", `Example: ghosty channels whatsapp ${sub} ${id} +52 55 1234 5678`);
1597
1600
  const n = find(cur.numbers, ref);
1598
1601
  const on = sub === "enable";
@@ -1651,6 +1654,61 @@ The agent will start answering in this group as ${role}.`, { yes: v.yes, retry:
1651
1654
  const now = r.groups.find((x) => x.jid === g.jid);
1652
1655
  return out({ group: now ?? null, plan: [plan] }, () => `${lavender("\u2713")} ${g.name}: ${now?.enabled ? "on" : "off"} as ${now?.role ?? role}`);
1653
1656
  }
1657
+ async function waCmd(sub, id, v) {
1658
+ if (!id) throw usage("Missing agent id.", `Example: ghosty channels wa ${sub} <agent-id>`);
1659
+ const base = `/api/v2/agents/${enc7(id)}/wa`;
1660
+ if (sub === "status") {
1661
+ const s = await api(base);
1662
+ return out(s, () => `${s.status === "connected" ? lavender("\u25CF connected") : dim(`\u25CB ${s.status}`)} ${s.phone ? `+${s.phone}` : dim("(no number)")}${s.live ? "" : dim(" \xB7 no socket in gs")}${s.hasCreds ? "" : dim(" \xB7 no saved session")}${s.reason ? `
1663
+ ${dim(s.reason)}` : ""}`);
1664
+ }
1665
+ if (sub === "pair") {
1666
+ const phone = (v.phone ?? "").replace(/\D/g, "");
1667
+ if (phone.length < 10) throw usage("Missing --phone (10-15 digits, with country code).", `Example: ghosty channels wa pair ${id} --phone 5215512345678`);
1668
+ await api(base, { method: "POST", body: { phone } });
1669
+ let s = { status: "connecting", phone: null, live: false, hasCreds: false };
1670
+ for (let i = 0; i < 15 && !s.pairingCode && s.status !== "connected"; i++) {
1671
+ await new Promise((r2) => setTimeout(r2, 1e3));
1672
+ s = await api(base);
1673
+ }
1674
+ return out(s, () => s.status === "connected" ? `${lavender("\u2713")} Already connected (+${s.phone}).` : s.pairingCode ? `Code: ${bold(s.pairingCode)}
1675
+ ${dim("On the phone: WhatsApp \u2192 Linked devices \u2192 Link with phone number \u2192 type it. Then: ghosty channels wa status " + id)}` : dim(`No code yet (status: ${s.status}${s.reason ? `, ${s.reason}` : ""}). Try again in a minute.`));
1676
+ }
1677
+ if (sub === "pause") {
1678
+ await api(base, { method: "DELETE" });
1679
+ return out({ paused: true }, () => `${lavender("\u2713")} Paused. The session is kept: ${dim(`ghosty channels wa import \u2026 or the Channels page reconnects it`)}`);
1680
+ }
1681
+ const file = v["from-file"];
1682
+ if (!file) throw usage("Missing --from-file.", `Example: ghosty channels wa import ${id} --from-file creds.json --own-number no --dry-run`);
1683
+ const own = v["own-number"];
1684
+ if (own !== "yes" && own !== "no") throw usage("Missing --own-number yes|no.", "yes = the number belongs to the agent \xB7 no = it is a person's number (only their chat with themselves is the owner's)");
1685
+ const data = JSON.parse(await readFile6(file, "utf8"));
1686
+ const body = { authCreds: data.authCreds, authKeys: data.authKeys, phone: data.phone, groups: data.groups, ownNumber: own === "yes", replace: !!v.replace };
1687
+ const plan = await api(`${base}/import`, { method: "POST", body: { ...body, dryRun: true } });
1688
+ if (v["dry-run"]) return out(plan, () => `${plan.plan.join("\n")}
1689
+ ${dim("Dry run: nothing changed.")}`);
1690
+ await confirm(`${bold(plan.plan.join("\n"))}
1691
+ This number starts living in gs. Turn off its EasyBits socket first, WITHOUT logout (two sockets knock each other off).`, { yes: v.yes, expect: plan.phone.slice(-4), retry: `ghosty channels wa import ${id} --from-file ${file} --own-number ${own}${v.replace ? " --replace" : ""}` });
1692
+ const r = await api(`${base}/import`, { method: "POST", body: { ...body, connect: !v["no-connect"] } });
1693
+ return out(r, () => `${lavender("\u2713")} +${r.phone} imported \xB7 status: ${r.status === "connected" ? lavender("connected") : r.status}${r.reason ? dim(` (${r.reason})`) : ""}
1694
+ ${dim(`Next: ghosty channels wa groups ls ${id} \xB7 delete ${file}: it holds the account's keys`)}`);
1695
+ }
1696
+ async function linkCmd(sub, id, v) {
1697
+ if (!id || !v.integration) throw usage("Missing agent id or --integration.", `Example: ghosty channels whatsapp ${sub} <agent-id> --integration <formmy-integration-id> --answer off --dry-run`);
1698
+ if (sub === "link" && v.answer !== "on" && v.answer !== "off") throw usage("Missing --answer on|off.", "on = this agent answers real customers \xB7 off = it only records (add --forward so gs still sees the conversations)");
1699
+ const path = `/api/v2/agents/${enc7(id)}/whatsapp/link`;
1700
+ const body = { integrationId: v.integration, ...sub === "unlink" ? { unlink: true } : { answer: v.answer === "on", ...v.forward ? { forward: true } : {} } };
1701
+ const plan = await api(path, { method: "POST", body: { ...body, dryRun: true } });
1702
+ const text = `${plan.plan.join("\n")}
1703
+ ${dim(`Formmy: ${plan.formmy.before.url ?? "null"} \u2192 ${plan.formmy.after.url ?? "null"} (as ${plan.formmy.by})`)}`;
1704
+ if (v["dry-run"]) return out(plan, () => `${text}
1705
+ ${dim("Dry run: nothing changed.")}`);
1706
+ const digits4 = (plan.number.phoneNumberId ?? v.integration).slice(-4);
1707
+ await confirm(`${bold(text)}
1708
+ ${sub === "link" ? "From now on this number's messages reach this agent in gs." : "This number goes back to where it was before."}`, { yes: v.yes, expect: digits4, retry: `ghosty channels whatsapp ${sub} ${id} --integration ${v.integration}${sub === "link" ? ` --answer ${v.answer}${v.forward ? " --forward" : ""}` : ""}` });
1709
+ const r = await api(path, { method: "POST", body });
1710
+ return out(r, () => `${lavender("\u2713")} ${sub === "link" ? `Linked (link ${r.linkId}). Check: ghosty channels whatsapp ls ${id} \xB7 ghosty turns ls ${id} --since 10m` : "Unlinked: Formmy points where it did before."}`);
1711
+ }
1654
1712
 
1655
1713
  // src/commands/board.ts
1656
1714
  async function boardCmd(sub, id, v) {
@@ -1881,6 +1939,11 @@ HELPS.channels = {
1881
1939
  "ghosty channels whatsapp ls <agent-id>",
1882
1940
  "ghosty channels whatsapp enable <agent-id> <number> [--dry-run] [--yes]",
1883
1941
  "ghosty channels whatsapp disable <agent-id> <number> [--dry-run]",
1942
+ "ghosty channels whatsapp link <agent-id> --integration <formmy-id> --answer on|off [--forward] [--dry-run] [--yes]",
1943
+ "ghosty channels whatsapp unlink <agent-id> --integration <formmy-id> [--dry-run] [--yes]",
1944
+ "ghosty channels wa import <agent-id> --from-file creds.json --own-number yes|no [--replace] [--no-connect] [--dry-run] [--yes]",
1945
+ "ghosty channels wa pair <agent-id> --phone 5215512345678",
1946
+ "ghosty channels wa status|pause <agent-id>",
1884
1947
  "ghosty channels wa groups ls <agent-id> [--cached]",
1885
1948
  "ghosty channels wa groups set <agent-id> <group> [--role equipo|cliente] [--on | --off] [--dry-run] [--yes]",
1886
1949
  'ghosty channels wa groups create <agent-id> "Name" [--role equipo|cliente]'
@@ -1890,19 +1953,30 @@ HELPS.channels = {
1890
1953
  ["--yes", "enable / groups set --on: skip the confirmation (required without a terminal)"],
1891
1954
  ["--role R", "groups: equipo (the team: writes to databases, admin tools) or cliente (like any customer)"],
1892
1955
  ["--on | --off", "groups set: the agent answers in that group, or stops"],
1893
- ["--cached", "groups ls: don't ask WhatsApp for the live list (faster; may miss new groups)"]
1956
+ ["--cached", "groups ls: don't ask WhatsApp for the live list (faster; may miss new groups)"],
1957
+ ["--integration ID", "link/unlink: the WhatsApp Business number's Integration id in Formmy"],
1958
+ ["--answer on|off", "link (required, no default): on = this agent answers real customers; off = it only records"],
1959
+ ["--forward", "link --answer off: still make Formmy forward, so gs sees the conversations"],
1960
+ ["--from-file F", "import: {authCreds, authKeys, phone, groups} exported from EasyBits"],
1961
+ ["--own-number yes|no", "import (required): the number is the agent's, or a person's (only their self-chat is the owner's)"],
1962
+ ["--replace", "import: replace a session already saved in gs"],
1963
+ ["--no-connect", "import: save it but don't connect yet"]
1894
1964
  ],
1895
1965
  examples: [
1896
1966
  "ghosty channels whatsapp ls <id>",
1897
1967
  "ghosty channels whatsapp enable <id> 5512345678 --dry-run",
1898
1968
  "ghosty channels whatsapp disable <id> 5512345678",
1899
1969
  "ghosty channels wa groups ls <id>",
1900
- 'ghosty channels wa groups set <id> "Pia-cotizadora" --role equipo --on --dry-run'
1970
+ 'ghosty channels wa groups set <id> "Pia-cotizadora" --role equipo --on --dry-run',
1971
+ "ghosty channels whatsapp link <id> --integration 6a3af395\u2026 --answer off --dry-run",
1972
+ "ghosty channels wa import <id> --from-file pia-wa.json --own-number no --dry-run"
1901
1973
  ],
1902
1974
  notes: [
1903
1975
  "<number> is its id, its label or its last digits. One number, one agent: enabling it takes it from the other agent.",
1904
1976
  "Disabling keeps logging messages; nobody answers them.",
1905
- "Groups belong to the PERSONAL WhatsApp paired to the agent (not WhatsApp Business). <group> is its name or its jid."
1977
+ "Groups belong to the PERSONAL WhatsApp paired to the agent (not WhatsApp Business). <group> is its name or its jid.",
1978
+ "link moves a number that already lives in Formmy (EasyBits, a droplet) without redoing Meta's signup; unlink sends it back. Only the owner, an admin of the agent or Ghosty staff.",
1979
+ "import: turn off the EasyBits socket first WITHOUT logout (two sockets knock each other off; a logout invalidates the keys). Delete the file afterwards."
1906
1980
  ],
1907
1981
  learn: `${REF}#canales-de-whatsapp`
1908
1982
  };
@@ -1941,7 +2015,7 @@ function helpText(cmd) {
1941
2015
  }
1942
2016
 
1943
2017
  // src/update.ts
1944
- import { mkdir as mkdir4, readFile as readFile6, writeFile as writeFile4 } from "node:fs/promises";
2018
+ import { mkdir as mkdir4, readFile as readFile7, writeFile as writeFile4 } from "node:fs/promises";
1945
2019
  import { homedir as homedir3 } from "node:os";
1946
2020
  import { dirname as dirname3, join as join4 } from "node:path";
1947
2021
  var FILE = join4(process.env.XDG_CONFIG_HOME || join4(homedir3(), ".config"), "ghosty", "update.json");
@@ -1957,7 +2031,7 @@ async function latestVersion() {
1957
2031
  if (process.env.GHOSTY_NO_UPDATE_CHECK || process.env.CI) return null;
1958
2032
  let cache = {};
1959
2033
  try {
1960
- cache = JSON.parse(await readFile6(FILE, "utf8"));
2034
+ cache = JSON.parse(await readFile7(FILE, "utf8"));
1961
2035
  } catch {
1962
2036
  }
1963
2037
  if (!cache.checkedAt || Date.now() - cache.checkedAt > DAY) {
@@ -2009,6 +2083,10 @@ ${bold("Configure an agent")}
2009
2083
  dbs ls|tables|query|import|grant|revoke <id> [db] Databases it uses [--write] [--external-write t1,t2] [--external-rows t:col] [--from easybits:ID --dry-run]
2010
2084
  mcp get|set <id> MCP servers [--file servers.json]
2011
2085
  channels whatsapp ls|enable|disable <id> [number] Which WhatsApp Business numbers it answers [--dry-run]
2086
+ channels whatsapp link|unlink <id> --integration ID --answer on|off Bring a WhatsApp Business number from Formmy/EasyBits to this agent, or send it back [--forward] [--dry-run]
2087
+ channels wa import <id> --from-file F --own-number yes|no Move a personal WhatsApp session here, no QR [--dry-run] [--replace] [--no-connect]
2088
+ channels wa pair <id> --phone N Pair a personal WhatsApp by code (no QR)
2089
+ channels wa status|pause <id> Personal WhatsApp: how it is / pause it (keeps the session)
2012
2090
  channels wa groups ls|set|create <id> [group] Personal WhatsApp groups it answers, and as whom [--role equipo|cliente] [--on|--off] [--dry-run]
2013
2091
  board archive <id> Archive cards in bulk (reversible) --integration X | --column X | --before 30d [--dry-run]
2014
2092
 
@@ -2138,6 +2216,13 @@ async function main() {
2138
2216
  before: { type: "string" },
2139
2217
  recycle: { type: "boolean" },
2140
2218
  role: { type: "string" },
2219
+ "from-file": { type: "string" },
2220
+ "own-number": { type: "string" },
2221
+ answer: { type: "string" },
2222
+ phone: { type: "string" },
2223
+ forward: { type: "boolean" },
2224
+ replace: { type: "boolean" },
2225
+ "no-connect": { type: "boolean" },
2141
2226
  cached: { type: "boolean" },
2142
2227
  check: { type: "string", multiple: true },
2143
2228
  contains: { type: "string", multiple: true }
@@ -2147,7 +2232,7 @@ async function main() {
2147
2232
  const tokens = splitTokens(pos, v);
2148
2233
  globals.token = tokens.session;
2149
2234
  globals.profile = v.profile;
2150
- if (v.version) return out({ version: "0.12.0" }, () => "0.12.0");
2235
+ if (v.version) return out({ version: "0.13.0" }, () => "0.13.0");
2151
2236
  const [cmd, sub, a1, a2] = pos;
2152
2237
  if (cmd === "partner" && (v.help || !sub || sub === "help")) return out({ help: PARTNER_HELP }, () => PARTNER_HELP);
2153
2238
  const topic = cmd === "help" ? sub : v.help ? cmd : void 0;
@@ -2232,7 +2317,7 @@ async function main() {
2232
2317
  throw unknown(cmd, cmd, COMMANDS, "ghosty --help");
2233
2318
  }
2234
2319
  }
2235
- var notice = updateNotice("0.12.0").catch(() => null);
2320
+ var notice = updateNotice("0.13.0").catch(() => null);
2236
2321
  main().then(
2237
2322
  async () => {
2238
2323
  const n = await notice;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ghostystudio/cli",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Official Ghosty Studio CLI — configure, test and chat with your agents from the terminal. Built for humans and coding agents.",
5
5
  "type": "module",
6
6
  "bin": {