@leemour/cli-messaging 0.119.0 → 0.120.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.
@@ -5,6 +5,8 @@ export interface SecretInput {
5
5
  output?: NodeJS.WritableStream;
6
6
  /** For a phone number or an SMS code, which a person needs to see while typing. */
7
7
  echo?: boolean;
8
+ /** Cancels pending input without closing the caller's stream. */
9
+ signal?: AbortSignal;
8
10
  }
9
11
  /**
10
12
  * One line of secret, taken without a file and without argv.
@@ -16,5 +18,5 @@ export interface SecretInput {
16
18
  * The prompt goes to **stderr**, not stdout, so that `session start --json` still writes one JSON
17
19
  * value and nothing else.
18
20
  */
19
- export declare const readSecret: (prompt: string, { input, output, echo }?: SecretInput) => Promise<string>;
21
+ export declare const readSecret: (prompt: string, { input, output, echo, signal }?: SecretInput) => Promise<string>;
20
22
  //# sourceMappingURL=prompt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/terminal/prompt.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC,cAAc,GAAG;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAA;IAC9B,mFAAmF;IACnF,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,WACb,MAAM,4BACoD,WAAW,KAC5E,OAAO,CAAC,MAAM,CA+BhB,CAAA"}
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/terminal/prompt.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC,cAAc,GAAG;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAA;IAC9B,mFAAmF;IACnF,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,iEAAiE;IACjE,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,WACb,MAAM,oCAC4D,WAAW,KACpF,OAAO,CAAC,MAAM,CA6DhB,CAAA"}
@@ -11,8 +11,36 @@ import { CliError } from "@leemour/cli-core";
11
11
  * The prompt goes to **stderr**, not stdout, so that `session start --json` still writes one JSON
12
12
  * value and nothing else.
13
13
  */
14
- export const readSecret = async (prompt, { input = process.stdin, output = process.stderr, echo = false } = {}) => {
14
+ export const readSecret = async (prompt, { input = process.stdin, output = process.stderr, echo = false, signal } = {}) => {
15
+ const cancelled = () => new CliError("cancelled", "cancelled — nothing was stored");
16
+ if (signal?.aborted)
17
+ throw cancelled();
15
18
  if (!input.isTTY) {
19
+ if (signal) {
20
+ return new Promise((resolve, reject) => {
21
+ const chunks = [];
22
+ const cleanup = () => {
23
+ input.off("data", data).off("end", end).off("error", error).off("close", abort);
24
+ signal.removeEventListener("abort", abort);
25
+ };
26
+ const data = (chunk) => chunks.push(Buffer.from(chunk));
27
+ const end = () => {
28
+ cleanup();
29
+ resolve(Buffer.concat(chunks).toString("utf8").trim());
30
+ };
31
+ const error = (cause) => {
32
+ cleanup();
33
+ reject(cause);
34
+ };
35
+ const abort = () => {
36
+ cleanup();
37
+ input.pause();
38
+ reject(cancelled());
39
+ };
40
+ input.on("data", data).once("end", end).once("error", error).once("close", abort);
41
+ signal.addEventListener("abort", abort, { once: true });
42
+ });
43
+ }
16
44
  const chunks = [];
17
45
  for await (const chunk of input)
18
46
  chunks.push(Buffer.from(chunk));
@@ -27,19 +55,22 @@ export const readSecret = async (prompt, { input = process.stdin, output = proce
27
55
  },
28
56
  });
29
57
  const reader = createInterface({ input, output: shim, terminal: true });
58
+ const abort = () => reader.close();
30
59
  try {
31
60
  // Ctrl-C and a closed terminal would otherwise leave this waiting for ever, and Node exits
32
61
  // on the unsettled promise with a warning and a code nobody documents.
33
62
  const answer = await new Promise((resolve, reject) => {
34
- const cancel = () => reject(new CliError("cancelled", "cancelled — nothing was stored"));
63
+ const cancel = () => reject(cancelled());
35
64
  reader.once("SIGINT", cancel);
36
65
  reader.once("close", cancel);
66
+ signal?.addEventListener("abort", abort, { once: true });
37
67
  reader.question(prompt, resolve);
38
68
  muted = !echo;
39
69
  });
40
70
  return answer.trim();
41
71
  }
42
72
  finally {
73
+ signal?.removeEventListener("abort", abort);
43
74
  reader.close();
44
75
  output.write("\n");
45
76
  }
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/terminal/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAS5C;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAC7B,MAAc,EACd,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,IAAI,GAAG,KAAK,EAAE,GAAgB,EAAE,EACjE,EAAE;IACnB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,MAAM,GAAa,EAAE,CAAA;QAC3B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,KAAK;YAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;QAChE,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAA;IACtD,CAAC;IAED,IAAI,KAAK,GAAG,KAAK,CAAA;IACjB,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC;QACxB,KAAK,CAAC,KAAK,EAA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2FAA2F;QAC3F,uEAAuE;QACvE,MAAM,MAAM,GAAG,MAAM,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3D,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAA;YACxC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;YAC7B,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;YAC5B,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;YACxD,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;YAChC,KAAK,GAAG,CAAC,IAAI,CAAA;QACf,CAAC,CAAC,CAAA;QACF,OAAO,MAAM,CAAC,IAAI,EAAE,CAAA;IACtB,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QAC3C,MAAM,CAAC,KAAK,EAAE,CAAA;QACd,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACpB,CAAC;AACH,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leemour/cli-messaging",
3
- "version": "0.119.0",
3
+ "version": "0.120.0",
4
4
  "description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
5
5
  "license": "MIT",
6
6
  "author": "Viacheslav Ptsarev",
package/parity.json CHANGED
@@ -20,6 +20,10 @@
20
20
  "value": "<time>",
21
21
  "meaning": "read what came after this ISO 8601 time, or 2h / 1d ago; not with --after-id or the --before pair"
22
22
  },
23
+ "--agent": {
24
+ "value": "<agent>",
25
+ "meaning": "install the skill for this agent; asks at a terminal, otherwise none"
26
+ },
23
27
  "--all": {
24
28
  "meaning": "every row, no paging"
25
29
  },
@@ -257,6 +261,10 @@
257
261
  "value": "<on|off>",
258
262
  "meaning": "members may see the invite link"
259
263
  },
264
+ "--method": {
265
+ "value": "<method>",
266
+ "meaning": "how to log in when there is no session"
267
+ },
260
268
  "--model": {
261
269
  "value": "<id>",
262
270
  "meaning": "which downloaded speech model hears them; `models audio list` shows them",
@@ -1941,6 +1949,43 @@
1941
1949
  }
1942
1950
  }
1943
1951
  },
1952
+ "setup": {
1953
+ "in": [],
1954
+ "planned": {
1955
+ "tg": "guided first-run onboarding",
1956
+ "max": "guided first-run onboarding"
1957
+ },
1958
+ "options": {
1959
+ "--agent": {
1960
+ "in": [],
1961
+ "planned": {
1962
+ "tg": "guided first-run onboarding",
1963
+ "max": "guided first-run onboarding"
1964
+ }
1965
+ },
1966
+ "--app": {
1967
+ "in": [],
1968
+ "planned": {
1969
+ "tg": "guided first-run onboarding"
1970
+ },
1971
+ "reason": "Telegram requires an application from my.telegram.org; MAX has no application registration step"
1972
+ },
1973
+ "--method": {
1974
+ "in": [],
1975
+ "planned": {
1976
+ "tg": "guided first-run onboarding",
1977
+ "max": "guided first-run onboarding"
1978
+ }
1979
+ },
1980
+ "--qr-file": {
1981
+ "in": [],
1982
+ "planned": {
1983
+ "tg": "guided first-run onboarding"
1984
+ },
1985
+ "reason": "Telegram can expose its temporary QR login token as a PNG"
1986
+ }
1987
+ }
1988
+ },
1944
1989
  "skill": {
1945
1990
  "in": "all"
1946
1991
  },