passport-bridge 0.16.13 → 0.16.14

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 (87) hide show
  1. package/README.md +15 -15
  2. package/dist/bridgeExchange.d.ts +7 -1
  3. package/dist/bridgeExchange.js +11 -2
  4. package/dist/cli.js +3 -1
  5. package/dist/cliActions.js +37 -18
  6. package/dist/cliArgs.js +14 -9
  7. package/dist/cliAutopilot.js +35 -14
  8. package/dist/cliAutopilotPolicy.d.ts +10 -0
  9. package/dist/cliAutopilotPolicy.js +28 -0
  10. package/dist/cliConnect.js +7 -6
  11. package/dist/cliDeadline.js +2 -1
  12. package/dist/cliEnv.js +5 -4
  13. package/dist/cliExec.js +13 -5
  14. package/dist/cliGuardState.d.ts +2 -0
  15. package/dist/cliGuardState.js +5 -1
  16. package/dist/cliHelp.d.ts +5 -4
  17. package/dist/cliHelp.js +2 -27
  18. package/dist/cliHook.js +6 -2
  19. package/dist/cliHookGuard.js +2 -2
  20. package/dist/cliHookInstall.d.ts +3 -0
  21. package/dist/cliHookInstall.js +17 -7
  22. package/dist/cliHookStatus.d.ts +2 -1
  23. package/dist/cliHookStatus.js +26 -17
  24. package/dist/cliInit.js +5 -3
  25. package/dist/cliKeys.d.ts +3 -0
  26. package/dist/cliKeys.js +59 -77
  27. package/dist/cliKeysShim.js +7 -5
  28. package/dist/cliLogin.js +44 -24
  29. package/dist/cliLogout.js +23 -7
  30. package/dist/cliMain.js +48 -20
  31. package/dist/cliOffline.d.ts +2 -2
  32. package/dist/cliOffline.js +31 -8
  33. package/dist/cliOutput.js +72 -42
  34. package/dist/cliReady.d.ts +2 -1
  35. package/dist/cliReady.js +9 -6
  36. package/dist/cliResult.js +1 -1
  37. package/dist/cliScan.js +10 -28
  38. package/dist/cliSessions.d.ts +3 -2
  39. package/dist/cliSessions.js +19 -17
  40. package/dist/cliSetup.js +6 -4
  41. package/dist/cliSetupLock.js +1 -0
  42. package/dist/cliSetupOrg.js +7 -5
  43. package/dist/cliStatus.d.ts +2 -4
  44. package/dist/cliStatus.js +55 -60
  45. package/dist/cliSuggest.d.ts +3 -2
  46. package/dist/cliSuggest.js +19 -6
  47. package/dist/cliSupport.d.ts +1 -1
  48. package/dist/cliSupport.js +3 -7
  49. package/dist/cliSync.js +2 -0
  50. package/dist/cliUndo.d.ts +3 -1
  51. package/dist/cliUndo.js +14 -11
  52. package/dist/cliWait.d.ts +3 -2
  53. package/dist/cliWait.js +10 -18
  54. package/dist/doctor.d.ts +4 -1
  55. package/dist/doctor.js +43 -24
  56. package/dist/execNoKey.d.ts +1 -1
  57. package/dist/execNoKey.js +3 -2
  58. package/dist/execShims.js +2 -2
  59. package/dist/hookFastPath.js +1 -0
  60. package/dist/initAutopilotStep.js +5 -4
  61. package/dist/initInstall.js +4 -3
  62. package/dist/initKeysStep.js +1 -1
  63. package/dist/initLocalSteps.js +4 -2
  64. package/dist/initOutro.d.ts +1 -3
  65. package/dist/initOutro.js +7 -15
  66. package/dist/initPlan.js +6 -6
  67. package/dist/initUi.d.ts +2 -4
  68. package/dist/initUi.js +8 -17
  69. package/dist/keysLocal.js +3 -3
  70. package/dist/keysSecret.d.ts +6 -0
  71. package/dist/keysSecret.js +43 -0
  72. package/dist/launcherFastPath.js +1 -0
  73. package/dist/loginFlow.d.ts +1 -1
  74. package/dist/loginFlow.js +4 -4
  75. package/dist/pathLines.d.ts +1 -0
  76. package/dist/pathLines.js +23 -0
  77. package/dist/pluginPin.d.ts +1 -1
  78. package/dist/pluginPin.js +1 -1
  79. package/dist/plural.d.ts +10 -0
  80. package/dist/plural.js +14 -0
  81. package/dist/term.d.ts +49 -5
  82. package/dist/term.js +200 -26
  83. package/dist/version.d.ts +1 -1
  84. package/dist/version.js +1 -1
  85. package/dist/waitingLine.js +2 -1
  86. package/npm-shrinkwrap.json +2 -2
  87. package/package.json +1 -1
package/dist/initUi.js CHANGED
@@ -15,9 +15,9 @@
15
15
  */
16
16
  import { createInterface } from "node:readline";
17
17
  import { answerOf, ASK_AGAIN, choices, nameConfirmed, typeNamePrompt } from "./cliAsk.js";
18
- import { clip, mark as markOf, paint as paintText, plainText, supportsUnicode, table, termOf, visibleLength, wrap } from "./term.js";
18
+ import { clip, stripAnsi, mark as markOf, paint as paintText, plainText, supportsUnicode, table, termOf, visibleLength, wrap } from "./term.js";
19
19
  export { supportsUnicode, visibleLength };
20
- export const LABEL_WIDTH = 10;
20
+ export const LABEL_WIDTH = 11;
21
21
  const INDENT = " ";
22
22
  export const CONTINUATION = " ".repeat(INDENT.length + LABEL_WIDTH);
23
23
  export class InitPaused extends Error {
@@ -164,10 +164,6 @@ export function processTerminal(runtime, platform, json) {
164
164
  }
165
165
  };
166
166
  }
167
- /** Word-wrap without breaking a URL, path, or `passport` command. */
168
- export function wrapText(text, width) {
169
- return wrap(text, width);
170
- }
171
167
  /**
172
168
  * Rows of cells padded so the columns line up, two spaces apart. Null when the
173
169
  * widest row doesn't fit in `width`: the caller lays those rows out another way.
@@ -250,7 +246,7 @@ export class InitScreen {
250
246
  this.out(`\n${this.paint("1", "Passport setup")}\n\n`);
251
247
  }
252
248
  /** The lead of a step's first row: ` Apps `, or a row of its own for
253
- * a label wider than the column ("Environments"). */
249
+ * a label wider than the column. */
254
250
  leadFor(label) {
255
251
  if (label === undefined)
256
252
  return CONTINUATION;
@@ -262,15 +258,8 @@ export class InitScreen {
262
258
  }
263
259
  emit(label, text) {
264
260
  this.clearLive();
265
- // A link too long for the step's indent starts at the left edge instead,
266
- // so it stays one clickable run (and whole, when it fits the terminal).
267
- if (label === undefined &&
268
- /^https?:\/\/\S+$/.test(text) &&
269
- CONTINUATION.length + text.length > this.terminal.width) {
270
- this.out(`${text}\n`);
271
- this.quiet();
272
- return;
273
- }
261
+ // A link stays at the step's indent, in the content column, and is never
262
+ // broken: one too long for the line runs past the edge, still one link.
274
263
  const lead = this.leadFor(label);
275
264
  for (const line of wrap(this.text(text), this.terminal.width, lead, CONTINUATION)) {
276
265
  this.out(`${line}\n`);
@@ -328,7 +317,8 @@ export class InitScreen {
328
317
  /** One row, clipped to the terminal so `\r` and erase-line replace all of it. */
329
318
  drawLive(lead, text) {
330
319
  const room = Math.max(1, this.liveColumns - lead.length);
331
- const row = clip(this.text(text), room, this.terminal.unicode);
320
+ // One dim span: marks already dimmed inside the text would end it early.
321
+ const row = clip(stripAnsi(this.text(text)), room, this.terminal.unicode);
332
322
  this.out(`\r\u001b[2K${clip(lead, this.liveColumns, this.terminal.unicode)}${this.paint("2", row)}`);
333
323
  this.liveShown = true;
334
324
  }
@@ -477,6 +467,7 @@ export class InitScreen {
477
467
  /** A numbered choice. Returns an index, or undefined when there is no answer. */
478
468
  async choose(question, options, signal, label) {
479
469
  this.line(question, label);
470
+ // copy-style-allow double-space: columns line up
480
471
  options.forEach((option, index) => this.line(` ${index + 1} ${option}`));
481
472
  if (!this.terminal.interactive)
482
473
  return undefined;
package/dist/keysLocal.js CHANGED
@@ -200,7 +200,7 @@ function railwayKeys(home) {
200
200
  kind: "railway-account-token",
201
201
  label: "Railway sign-in",
202
202
  location,
203
- unholdable: `Railway is signed in with a browser session Passport can't hold. Create an account token at ${EXEC_TOKEN_PAGES.railway}, then run passport keys add railway.`,
203
+ unholdable: `Railway is signed in with a browser session Passport can't hold. Create an account token at ${EXEC_TOKEN_PAGES.railway}, then add it.\nRun: passport keys add railway`,
204
204
  removalWords: SIGN_OUT.railway
205
205
  }
206
206
  ];
@@ -242,7 +242,7 @@ function vercelKeys(context, home) {
242
242
  kind: "vercel-token",
243
243
  label: "Vercel sign-in",
244
244
  location: display(path, home),
245
- unholdable: `Vercel is signed in with a browser session Passport can't hold. Create a token at ${EXEC_TOKEN_PAGES.vercel}, then run passport keys add vercel.`,
245
+ unholdable: `Vercel is signed in with a browser session Passport can't hold. Create a token at ${EXEC_TOKEN_PAGES.vercel}, then add it.\nRun: passport keys add vercel`,
246
246
  removalWords: SIGN_OUT.vercel
247
247
  }
248
248
  ];
@@ -295,7 +295,7 @@ function wranglerKeys(context, home) {
295
295
  kind: "cloudflare-cli-token",
296
296
  label: "Wrangler sign-in",
297
297
  location,
298
- unholdable: `Wrangler is signed in with a browser session Passport can't hold. Create an API token at ${EXEC_TOKEN_PAGES.wrangler}, then run passport keys add wrangler.`,
298
+ unholdable: `Wrangler is signed in with a browser session Passport can't hold. Create an API token at ${EXEC_TOKEN_PAGES.wrangler}, then add it.\nRun: passport keys add wrangler`,
299
299
  removalWords: SIGN_OUT.wrangler
300
300
  }
301
301
  ];
@@ -0,0 +1,6 @@
1
+ /**
2
+ * `passport keys add`: the key a person pastes. Hidden input on a terminal
3
+ * (never echoed), the whole of stdin otherwise, at most 16 KB.
4
+ */
5
+ import type { Runtime } from "./cliSupport.js";
6
+ export declare function readSecret(runtime: Runtime, prompt: string): Promise<string>;
@@ -0,0 +1,43 @@
1
+ import { discardTypeAhead } from "./initUi.js";
2
+ export async function readSecret(runtime, prompt) {
3
+ const stdin = runtime.stdin;
4
+ if (!stdin)
5
+ return "";
6
+ if (!stdin.isTTY || !stdin.setRawMode) {
7
+ const chunks = [];
8
+ let bytes = 0;
9
+ for await (const chunk of stdin) {
10
+ const buffer = Buffer.from(chunk);
11
+ bytes += buffer.byteLength;
12
+ if (bytes > 16 * 1024)
13
+ break;
14
+ chunks.push(buffer);
15
+ }
16
+ return Buffer.concat(chunks).toString("utf8").trim();
17
+ }
18
+ // Keys typed before the prompt aren't part of the key.
19
+ if (await discardTypeAhead(stdin))
20
+ throw new Error("Cancelled.");
21
+ runtime.stderr.write(prompt);
22
+ stdin.setRawMode(true);
23
+ let value = "";
24
+ try {
25
+ for await (const chunk of stdin) {
26
+ for (const char of String(chunk)) {
27
+ if (char === "\u0003")
28
+ throw new Error("Cancelled.");
29
+ if (char === "\r" || char === "\n")
30
+ return value.trim();
31
+ if (char === "\u007f")
32
+ value = value.slice(0, -1);
33
+ else
34
+ value += char;
35
+ }
36
+ }
37
+ }
38
+ finally {
39
+ stdin.setRawMode(false);
40
+ runtime.stderr.write("\n");
41
+ }
42
+ return value.trim();
43
+ }
@@ -126,6 +126,7 @@ export function fastPathShell() {
126
126
  ' while [ -n "$pp_w" ]; do',
127
127
  " pp_c=${pp_w%%/*}",
128
128
  " case $pp_w in */*) pp_w=${pp_w#*/} ;; *) pp_w= ;; esac",
129
+ // copy-style-allow three-dots: a shell case pattern, not prose
129
130
  " case $pp_c in '' | .) continue ;; ...) ;; .*) return 1 ;; esac",
130
131
  " pp_p=$pp_p/$pp_c",
131
132
  ' [ -L "$pp_p" ] && return 1',
@@ -21,7 +21,7 @@ export type Approval = {
21
21
  /** The server's window plus a little slack, so its own "expired" wins. */
22
22
  export declare const POLL_SLACK_MS = 15000;
23
23
  export declare const IDENTITY_TIMEOUT_MS = 5000;
24
- export declare const EXPIRED = "This sign-in code expired. Run passport login again.";
24
+ export declare const EXPIRED = "This sign-in code expired.\nRun: passport login";
25
25
  /** What the person must do in the browser, for a caller that draws its own
26
26
  * screen (`passport init`). `opened` is false when no browser was launched. */
27
27
  export type SignInPrompt = {
package/dist/loginFlow.js CHANGED
@@ -37,7 +37,7 @@ const SIGN_IN_WINDOW_MS = 10 * 60 * 1000;
37
37
  export const POLL_SLACK_MS = 15_000;
38
38
  const MAX_TRANSIENT_POLL_FAILURES = 5;
39
39
  export const IDENTITY_TIMEOUT_MS = 5_000;
40
- export const EXPIRED = "This sign-in code expired. Run passport login again.";
40
+ export const EXPIRED = "This sign-in code expired.\nRun: passport login";
41
41
  const DENIED = "Sign-in was denied in the browser. Nothing was saved.";
42
42
  const CANCELLED = "Sign-in cancelled. Nothing was saved.";
43
43
  const OTHER_WORKSPACE = "Passport approved a different workspace than the one requested; no credential was saved.";
@@ -55,7 +55,7 @@ export function signInLines(prompt) {
55
55
  ` Code: ${prompt.userCode}`,
56
56
  ` Link: ${prompt.verifyUrl}${prompt.opened ? " (opened in your browser)" : ""}`,
57
57
  "Check the code matches the one in your browser before you approve.",
58
- "Waiting for the browser... (Ctrl-C to cancel)"
58
+ "Waiting for the browser… (Ctrl-C to stop)"
59
59
  ];
60
60
  }
61
61
  export function printPrompt(runtime, opts, hooks) {
@@ -173,8 +173,8 @@ export async function startSignIn(options, args, runtime) {
173
173
  async function waitForBrowserApproval(cloud, code, intervalMs, deadlineAt, args, runtime) {
174
174
  let transient = 0;
175
175
  const lostContact = (status) => failure(status
176
- ? `Could not check sign-in (${status}). Run passport login again.`
177
- : "Lost contact with Passport while waiting. Check your connection and run passport login again.", 1, "network_or_server");
176
+ ? `Couldn't check the sign-in (${status}). Sign in again.\nRun: passport login`
177
+ : "Lost contact with Passport while waiting. Check your connection, then sign in again.\nRun: passport login", 1, "network_or_server");
178
178
  while (Date.now() < deadlineAt) {
179
179
  await sleep(intervalMs, runtime.signal);
180
180
  let poll;
@@ -0,0 +1 @@
1
+ export declare function pathLines(line: string, width?: number): string[];
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The PATH line on screen (`initInstall.ts` `pathLine` says what it is): what
3
+ * to do, then the command on its own line, never broken. Too narrow for the
4
+ * `echo … >> ~/.zshrc` form, it names the file and the shorter line to add.
5
+ *
6
+ * Add Passport's folder to your PATH, then open a new terminal:
7
+ * echo 'export PATH="$HOME/.passport/cli/bin:$PATH"' >> ~/.zshrc
8
+ */
9
+ import { wrap } from "./term.js";
10
+ export function pathLines(line, width = Number.POSITIVE_INFINITY) {
11
+ const at = line.indexOf(": ");
12
+ if (at < 0)
13
+ return wrap(line, width);
14
+ const command = line.slice(at + 2);
15
+ const appended = command.match(/^echo 'export PATH="\$HOME(\/[^"]+):\$PATH"' >> (\S+)$/);
16
+ if (appended && 2 + command.length > width) {
17
+ return [
18
+ ...wrap(`Add this line to ${appended[2]}, then open a new terminal:`, width),
19
+ ` export PATH=~${appended[1]}:$PATH`
20
+ ];
21
+ }
22
+ return [...wrap(`${line.slice(0, at)}:`, width), ` ${command}`];
23
+ }
@@ -4,4 +4,4 @@
4
4
  * the version, then runs `npm run set-version -- <version>` in the plugin repo
5
5
  * and pushes (docs/RELEASING.md). `pluginPin.test.ts` fails when it drifts.
6
6
  */
7
- export declare const PLUGIN_PIN = "0.16.13";
7
+ export declare const PLUGIN_PIN = "0.16.14";
package/dist/pluginPin.js CHANGED
@@ -4,4 +4,4 @@
4
4
  * the version, then runs `npm run set-version -- <version>` in the plugin repo
5
5
  * and pushes (docs/RELEASING.md). `pluginPin.test.ts` fails when it drifts.
6
6
  */
7
- export const PLUGIN_PIN = "0.16.13";
7
+ export const PLUGIN_PIN = "0.16.14";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Counts with the right noun: "1 key", "3 keys", "1,204 calls".
3
+ *
4
+ * A checked copy of shared/plural.ts (the CLI can't import shared/ in
5
+ * shipped code; termLayout.test.ts compares them word for word).
6
+ */
7
+ /** "1 key" or "3 keys"; `many` for irregular plurals ("1 repository", "2 repositories"). */
8
+ export declare function countOf(n: number, one: string, many?: string): string;
9
+ /** The word that agrees with a count: agree(n, "needs", "need"), agree(n, "it", "them"). */
10
+ export declare function agree(n: number, one: string, many: string): string;
package/dist/plural.js ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Counts with the right noun: "1 key", "3 keys", "1,204 calls".
3
+ *
4
+ * A checked copy of shared/plural.ts (the CLI can't import shared/ in
5
+ * shipped code; termLayout.test.ts compares them word for word).
6
+ */
7
+ /** "1 key" or "3 keys"; `many` for irregular plurals ("1 repository", "2 repositories"). */
8
+ export function countOf(n, one, many = `${one}s`) {
9
+ return `${n.toLocaleString("en-US")} ${n === 1 ? one : many}`;
10
+ }
11
+ /** The word that agrees with a count: agree(n, "needs", "need"), agree(n, "it", "them"). */
12
+ export function agree(n, one, many) {
13
+ return n === 1 ? one : many;
14
+ }
package/dist/term.d.ts CHANGED
@@ -4,11 +4,14 @@
4
4
  * small `Term` value, so a test can lay out any width without a terminal.
5
5
  *
6
6
  * const out = termOf(runtime.stdout, runtime.env);
7
+ * layout(text, out.width) every line fitted, each with its own hang
8
+ * say(stream, env, text) a laid-out message, written
9
+ * promptRows(question, out.width) a question's rows; the last is the prompt
7
10
  * wrap(text, out.width, " ") word-wrapped lines, hanging indent
8
11
  * clip(text, out.columns) one row, cut with "…"
9
12
  * table(rows, out.width) aligned columns, or one block per row
10
13
  * paint(out, "dim", text) 8-color ANSI, only when out.color
11
- * mark(out, "done") ✓ – ! ✗ … (+ - ! x . without Unicode)
14
+ * mark(out, "done") ✓ – ! ✗ … ● (+ - ! x . * without Unicode)
12
15
  * const live = new LiveLine(out, write); live.show(text); live.clear();
13
16
  * countdown(92_000) "1:32"
14
17
  *
@@ -17,7 +20,10 @@
17
20
  * columns. Off a terminal (piped, CI) nothing wraps: `width` and `columns`
18
21
  * are Infinity, color is off, and live lines print nothing.
19
22
  * - NO_COLOR, TERM=dumb, and a non-terminal stream turn color off.
20
- * - A URL, a path, or a `passport <verb>` command never breaks across lines.
23
+ * - Every human line goes through `layout` (or `wrap`): nothing else wraps.
24
+ * - A URL, a path, or a command to paste never breaks across lines. A
25
+ * command goes on its own line, as "Run: <command>" or after a colon.
26
+ * - A short last word never sits alone on its line.
21
27
  * - A live line is clipped to one row of the real terminal, so `\r` and
22
28
  * erase-line replace all of it.
23
29
  * - Marks always sit beside words; they are never the only signal.
@@ -62,16 +68,46 @@ declare const STYLES: {
62
68
  };
63
69
  export type Style = keyof typeof STYLES;
64
70
  export declare function paint(term: Pick<Term, "color">, style: Style, text: string): string;
65
- export type Mark = "done" | "skip" | "warn" | "fail" | "wait";
71
+ export type Mark = "done" | "skip" | "warn" | "fail" | "wait" | "live";
66
72
  export declare function mark(term: Pick<Term, "color" | "unicode">, kind: Mark): string;
67
73
  /** Unicode punctuation a terminal without it can still show. */
68
74
  export declare function plainText(term: Pick<Term, "unicode">, text: string): string;
75
+ /** "Run: <command>": the one way the CLI tells a person to run something. */
76
+ export declare function runLine(command: string): string;
69
77
  /**
70
78
  * Word-wrap `text` to `width` columns. The first line starts with `lead`, the
71
79
  * rest with `rest` (a hanging indent; `lead` by default). A word longer than
72
- * the line (a URL) gets a line of its own and is never cut.
80
+ * the line (a URL, a command) gets a line of its own and is never cut, and a
81
+ * short last word never sits alone. `groups` keeps `[…]`, `<…>`, and `"…"`
82
+ * whole, for usage lines.
73
83
  */
74
- export declare function wrap(text: string, width: number, lead?: string, rest?: string): string[];
84
+ export declare function wrap(text: string, width: number, lead?: string, rest?: string, options?: {
85
+ groups?: boolean;
86
+ usage?: boolean;
87
+ }): string[];
88
+ /**
89
+ * Text laid out to `width`, the one way the CLI fits a terminal. A line that
90
+ * fits stays as it is. A longer line wraps with a hanging indent: under its
91
+ * value column, after its mark, under a usage line's command, or at its own
92
+ * indent. A command to paste is never broken: `Run: <command>` too long for
93
+ * the line puts the command on the next line, under "Run:". Off a terminal
94
+ * (`width` is Infinity) text is unchanged.
95
+ */
96
+ export declare function layout(text: string, width: number, options?: {
97
+ groups?: boolean;
98
+ }): string;
99
+ /** One message written to a stream, laid out to its width on a terminal. */
100
+ export declare function say(stream: Stream & {
101
+ write(text: string): unknown;
102
+ }, env: Env, text: string): void;
103
+ /**
104
+ * A question laid out as a prompt: `rows` print first, and `prompt`, the last
105
+ * row with the choices (`[y/N]`) on it, is what the prompt shows.
106
+ */
107
+ export declare function promptRows(question: string, width: number, lead?: string, rest?: string): {
108
+ rows: string[];
109
+ prompt: string;
110
+ };
75
111
  /** One row of at most `width` columns, cut with an ellipsis. Color is dropped
76
112
  * from a line that has to be cut. */
77
113
  export declare function clip(text: string, width: number, unicode?: boolean): string;
@@ -85,6 +121,14 @@ export declare function table(rows: string[][], width: number, options?: {
85
121
  indent?: string;
86
122
  separator?: string;
87
123
  }): string[];
124
+ /**
125
+ * Parts joined with " · ", wrapped only between parts: "started 12:16 PM ·
126
+ * 3 ran · 4 asked" never breaks inside "Waiting for you (2)". A line ends
127
+ * without its separator; the break separates.
128
+ */
129
+ export declare function joinParts(parts: string[], width: number, lead?: string, rest?: string, separator?: string): string[];
130
+ /** "just now", "4 min ago", "3 h ago", "2 days ago". */
131
+ export declare function ago(ms: number): string;
88
132
  /** "1:32", or "12:05" for longer waits. Never negative. */
89
133
  export declare function countdown(ms: number): string;
90
134
  /**
package/dist/term.js CHANGED
@@ -4,11 +4,14 @@
4
4
  * small `Term` value, so a test can lay out any width without a terminal.
5
5
  *
6
6
  * const out = termOf(runtime.stdout, runtime.env);
7
+ * layout(text, out.width) every line fitted, each with its own hang
8
+ * say(stream, env, text) a laid-out message, written
9
+ * promptRows(question, out.width) a question's rows; the last is the prompt
7
10
  * wrap(text, out.width, " ") word-wrapped lines, hanging indent
8
11
  * clip(text, out.columns) one row, cut with "…"
9
12
  * table(rows, out.width) aligned columns, or one block per row
10
13
  * paint(out, "dim", text) 8-color ANSI, only when out.color
11
- * mark(out, "done") ✓ – ! ✗ … (+ - ! x . without Unicode)
14
+ * mark(out, "done") ✓ – ! ✗ … ● (+ - ! x . * without Unicode)
12
15
  * const live = new LiveLine(out, write); live.show(text); live.clear();
13
16
  * countdown(92_000) "1:32"
14
17
  *
@@ -17,7 +20,10 @@
17
20
  * columns. Off a terminal (piped, CI) nothing wraps: `width` and `columns`
18
21
  * are Infinity, color is off, and live lines print nothing.
19
22
  * - NO_COLOR, TERM=dumb, and a non-terminal stream turn color off.
20
- * - A URL, a path, or a `passport <verb>` command never breaks across lines.
23
+ * - Every human line goes through `layout` (or `wrap`): nothing else wraps.
24
+ * - A URL, a path, or a command to paste never breaks across lines. A
25
+ * command goes on its own line, as "Run: <command>" or after a colon.
26
+ * - A short last word never sits alone on its line.
21
27
  * - A live line is clipped to one row of the real terminal, so `\r` and
22
28
  * erase-line replace all of it.
23
29
  * - Marks always sit beside words; they are never the only signal.
@@ -83,12 +89,15 @@ const STYLES = { bold: "1", dim: "2", red: "31", green: "32", yellow: "33" };
83
89
  export function paint(term, style, text) {
84
90
  return term.color && text ? `\u001b[${STYLES[style]}m${text}\u001b[0m` : text;
85
91
  }
92
+ /** The house symbols. Every command takes its marks from here, so ✓ is
93
+ * always green, ✗ red, ! yellow, – dim, and ● (running) green. */
86
94
  const MARKS = {
87
95
  done: { unicode: "✓", ascii: "+", style: "green" },
88
96
  skip: { unicode: "–", ascii: "-", style: "dim" },
89
97
  warn: { unicode: "!", ascii: "!", style: "yellow" },
90
98
  fail: { unicode: "✗", ascii: "x", style: "red" },
91
- wait: { unicode: "…", ascii: ".", style: "dim" }
99
+ wait: { unicode: "…", ascii: ".", style: "dim" },
100
+ live: { unicode: "●", ascii: "*", style: "green" }
92
101
  };
93
102
  export function mark(term, kind) {
94
103
  const spec = MARKS[kind];
@@ -104,40 +113,172 @@ export function plainText(term, text) {
104
113
  .replace(/[–—]/g, "-")
105
114
  .replace(/·/g, "-")
106
115
  .replace(/[✓]/g, "+")
107
- .replace(/[✗]/g, "x");
116
+ .replace(/[✗]/g, "x")
117
+ .replace(/[●]/g, "*");
108
118
  }
109
- // A command a person may copy stays on one line: `passport keys move`,
110
- // `npx passport-bridge@latest init`, `passport wait apr_123`,
111
- // `passport connect railway --wait 120`.
112
- const COMMAND = /\b(?:npx passport-bridge(?:@latest)?|passport) [a-z][a-z-]*(?: (?:move|add|list|test|install|uninstall|status|set|guard|apr_[A-Za-z0-9_-]+))?(?: (?!to\b|and\b|or\b|then\b)[a-z][a-z0-9_-]*(?= --))?(?: --[a-z][a-z-]*(?: \d+)?)*/g;
119
+ // A command a person may copy stays on one line, with the "Run" or "Use"
120
+ // before it: `passport keys move`, `npx passport-bridge@latest init`,
121
+ // `passport wait apr_123`, `passport connect railway --wait 120`,
122
+ // `passport keys move railway`, `passport exec -- railway`, `passport
123
+ // describe <tool>`.
124
+ const COMMAND = /(?:\b(?:Run|Use) )?\b(?:npx passport-bridge(?:@latest)?|passport) [a-z][a-z-]*(?: (?:move|add|list|test|install|uninstall|status|set|guard|shim|apr_[A-Za-z0-9_-]+))?(?: -- [a-z][a-z0-9-]*)?(?: <[a-z-]+>)?(?: (?!to\b|and\b|or\b|then\b|for\b|in\b|on\b|with\b|yourself\b)[a-z][a-z0-9_-]*(?= --|[.,]?$))?(?: --[a-z][a-z-]*(?: \d+| [a-z][a-z0-9-]*(?= --|[.,]?$))?)*/g;
113
125
  const KEEP = "\u0000";
126
+ /** How far a command sits under its "Run:" when it moves to its own line. */
127
+ const UNDER_RUN = " ";
128
+ /** A line that is a command to paste: never broken, only moved. */
129
+ const SHELL_LINE = /^(?:Run: )?(?:sudo )?(?:passport|npx|echo|codex|claude|fish_add_path|set -Ux|export|gh|railway|cursor-agent) /;
130
+ /** A command to paste, not a usage line (usage has `[options]` and wraps)
131
+ * and not a sentence that starts with a command's name. */
132
+ function shellLine(text) {
133
+ return SHELL_LINE.test(text) && !/ \[|\S {2,}\S|[,;](?:\s|$)|\.(?:\s|$)/.test(text);
134
+ }
135
+ /** "Run: <command>": the one way the CLI tells a person to run something. */
136
+ export function runLine(command) {
137
+ return `Run: ${command}`;
138
+ }
139
+ /** Spaces a wrap never breaks at: inside a command (`passport …`, or all of
140
+ * `Run: <command>`), between a prompt's `[y/N]` and the word before it, and
141
+ * inside `[--flag <value>]` groups when asked. A " · " separator ends a line
142
+ * rather than starting the next one. */
143
+ function protect(paragraph, groups, usage = false) {
144
+ const keep = (part) => part.replace(/ /g, KEEP);
145
+ // A usage line breaks between its options, even one with <placeholders>.
146
+ if (shellLine(paragraph) && !(usage && / </.test(paragraph)))
147
+ return keep(paragraph);
148
+ let text = paragraph.replace(/\bRun: .*$/, keep);
149
+ if (!usage)
150
+ text = text.replace(COMMAND, keep);
151
+ // A flag stays with its value (`--environment production|staging`), and a
152
+ // usage line keeps `[--flag <value>]` groups and quoted words whole.
153
+ text = text.replace(/--[a-z][a-z-]* (?=[a-z<"])/g, keep).replace(/ -- (?=\S)/g, ` --${KEEP}`);
154
+ if (groups)
155
+ text = text.replace(/\[[^\]]*\]|<[^>]*>|"[^"]*"/g, keep);
156
+ return text.replace(/ (\[(?:y\/N|Y\/n)\]|\[[^\]]*default[^\]]*\])/g, `${KEEP}$1`).replace(/ · /g, `${KEEP}· `);
157
+ }
158
+ /** A short word never sits alone on its line (the last line, or one before a
159
+ * word too long to join it): the word before it moves down too, when that
160
+ * leaves a word above. */
161
+ function noWidow(lines, room) {
162
+ for (let index = 1; index < lines.length; index += 1) {
163
+ const line = lines[index];
164
+ const before = lines[index - 1];
165
+ if (line.length !== 1 || before.length < 2)
166
+ continue;
167
+ const word = line[0];
168
+ if (visibleLength(word) > 12 || word.includes(KEEP))
169
+ continue;
170
+ const moved = before.at(-1);
171
+ if (visibleLength(`${moved} ${word}`) > room(index))
172
+ continue;
173
+ before.pop();
174
+ line.unshift(moved);
175
+ }
176
+ }
114
177
  /**
115
178
  * Word-wrap `text` to `width` columns. The first line starts with `lead`, the
116
179
  * rest with `rest` (a hanging indent; `lead` by default). A word longer than
117
- * the line (a URL) gets a line of its own and is never cut.
180
+ * the line (a URL, a command) gets a line of its own and is never cut, and a
181
+ * short last word never sits alone. `groups` keeps `[…]`, `<…>`, and `"…"`
182
+ * whole, for usage lines.
118
183
  */
119
- export function wrap(text, width, lead = "", rest = lead) {
120
- // …and a "·" separator ends a line instead of starting the next one.
121
- const kept = text.replace(COMMAND, (command) => command.replace(/ /g, KEEP)).replace(/ · /g, `${KEEP}· `);
184
+ export function wrap(text, width, lead = "", rest = lead, options = {}) {
122
185
  const out = [];
123
- for (const paragraph of kept.split("\n")) {
124
- let prefix = out.length ? rest : lead;
125
- let current = "";
126
- for (const word of paragraph.split(" ")) {
127
- if (word === "" && current === "")
186
+ for (const paragraph of text.split("\n")) {
187
+ const first = out.length === 0;
188
+ const prefixOf = (index) => (first && index === 0 ? lead : rest);
189
+ const room = (index) => width - visibleLength(prefixOf(index));
190
+ // "Run: <command>" too long for the line: the command goes under "Run:".
191
+ const run = paragraph.match(/^Run: (.+)$/);
192
+ if (run && visibleLength(paragraph) > room(0)) {
193
+ out.push(`${prefixOf(0)}Run:`, `${rest}${UNDER_RUN}${run[1]}`);
194
+ continue;
195
+ }
196
+ const lines = [[]];
197
+ for (const word of protect(paragraph, options.groups ?? false, options.usage).split(" ")) {
198
+ const current = lines.at(-1);
199
+ if (word === "" && !current.length)
128
200
  continue;
129
- const room = width - visibleLength(prefix);
130
- if (current && visibleLength(current) + 1 + visibleLength(word) > room) {
131
- out.push(prefix + current);
132
- prefix = rest;
133
- current = word;
201
+ if (current.length && visibleLength(current.join(" ")) + 1 + visibleLength(word) > room(lines.length - 1)) {
202
+ lines.push([word]);
134
203
  }
135
204
  else
136
- current = current ? `${current} ${word}` : word;
205
+ current.push(word);
137
206
  }
138
- out.push(prefix + current);
207
+ noWidow(lines, room);
208
+ lines.forEach((words, index) => out.push(prefixOf(index) + words.join(" ")));
139
209
  }
140
- return out.map((line) => line.split(KEEP).join(" ").trimEnd());
210
+ // A line ends without its " ·": the break separates.
211
+ return out.map((line) => line.split(KEEP).join(" ").trimEnd().replace(/ ·$/, ""));
212
+ }
213
+ /** " Label value" or " --flag what it does": a long line's value
214
+ * hangs under its column. */
215
+ const COLUMN = /^(\s*\S+(?: \S+)*?\s{2,})\S/;
216
+ /** " ✓ text" or "! text": a marked line hangs under its text. */
217
+ const MARKED = /^(\s*[✓✗!–●…+x*] )\S/;
218
+ /**
219
+ * Text laid out to `width`, the one way the CLI fits a terminal. A line that
220
+ * fits stays as it is. A longer line wraps with a hanging indent: under its
221
+ * value column, after its mark, under a usage line's command, or at its own
222
+ * indent. A command to paste is never broken: `Run: <command>` too long for
223
+ * the line puts the command on the next line, under "Run:". Off a terminal
224
+ * (`width` is Infinity) text is unchanged.
225
+ */
226
+ export function layout(text, width, options = {}) {
227
+ if (!Number.isFinite(width))
228
+ return text;
229
+ return text
230
+ .split("\n")
231
+ .flatMap((line) => layoutLine(line, width, options))
232
+ .join("\n");
233
+ }
234
+ function layoutLine(raw, width, options) {
235
+ if (visibleLength(raw) <= width)
236
+ return [raw];
237
+ const indent = raw.match(/^\s*/)[0];
238
+ const run = raw.slice(indent.length).match(/^Run: (.+)$/);
239
+ if (run)
240
+ return [`${indent}Run:`, `${indent}${UNDER_RUN}${run[1]}`];
241
+ // A command to paste stays whole; an unindented one with <placeholders> is a usage line.
242
+ const body0 = raw.slice(indent.length);
243
+ if (shellLine(body0) && (indent.length > 0 || !/ </.test(body0)))
244
+ return [raw];
245
+ // A JSON shape ({id,name,steps:[…]}) breaks after a comma, never mid-name.
246
+ const line = raw.replace(/[{[][^\s]*[}\]]/g, (shape) => shape.replace(/,(?=\S)/g, ", "));
247
+ const body = line.slice(indent.length);
248
+ const column = line.match(COLUMN);
249
+ const marked = line.match(MARKED);
250
+ const label = body.match(/^(?:JSON|Global): /)?.[0];
251
+ const json = label ? `${indent}${label}` : undefined;
252
+ const hangAt = json ?? marked?.[1] ?? (column && visibleLength(column[1]) < width / 2 ? column[1] : undefined);
253
+ if (hangAt) {
254
+ // A JSON shape breaks after any comma, inside its brackets too.
255
+ const within = json ? { groups: false } : options;
256
+ return wrap(line.slice(hangAt.length), width, hangAt, " ".repeat(visibleLength(hangAt)), within);
257
+ }
258
+ // A first column too wide to hang under (" passport exec -- railway up
259
+ // Run a CLI…" at 40 columns): it gets its own line, the rest under it.
260
+ if (column) {
261
+ const cell = column[1].trimEnd();
262
+ return [cell, ...wrap(line.slice(column[1].length), width, `${indent} `, `${indent} `, options)];
263
+ }
264
+ // A usage line hangs its options under the command, keeping each
265
+ // `[--flag <value>]` whole; an option line hangs under the option.
266
+ const usage = /^(?:Use: )?(?:sudo )?(?:passport|npx) /.test(body);
267
+ const hang = usage ? " " : body.startsWith("-") ? " " : "";
268
+ return wrap(body, width, indent, `${indent}${hang}`, { groups: options.groups || usage, usage });
269
+ }
270
+ /** One message written to a stream, laid out to its width on a terminal. */
271
+ export function say(stream, env, text) {
272
+ stream.write(`${layout(text, termOf(stream, env).width)}\n`);
273
+ }
274
+ /**
275
+ * A question laid out as a prompt: `rows` print first, and `prompt`, the last
276
+ * row with the choices (`[y/N]`) on it, is what the prompt shows.
277
+ */
278
+ export function promptRows(question, width, lead = "", rest = lead) {
279
+ const lines = wrap(question.trimEnd(), width, lead, rest);
280
+ const prompt = lines.pop() ?? lead;
281
+ return { rows: lines, prompt: `${prompt} ` };
141
282
  }
142
283
  /** One row of at most `width` columns, cut with an ellipsis. Color is dropped
143
284
  * from a line that has to be cut. */
@@ -169,9 +310,42 @@ export function table(rows, width, options = {}) {
169
310
  return rows.flatMap((row) => {
170
311
  const [head = "", ...tail] = row;
171
312
  const detail = tail.filter((cell) => stripAnsi(cell).trim()).join(options.separator ?? " · ");
172
- return [...wrap(head, width), ...(detail ? wrap(detail, width, indent) : [])];
313
+ // A head that starts indented (" Railway key") keeps its indent.
314
+ const lead = head.match(/^\s*/)[0];
315
+ return [...wrap(head.slice(lead.length), width, lead), ...(detail ? wrap(detail, width, `${lead}${indent}`) : [])];
173
316
  });
174
317
  }
318
+ /**
319
+ * Parts joined with " · ", wrapped only between parts: "started 12:16 PM ·
320
+ * 3 ran · 4 asked" never breaks inside "Waiting for you (2)". A line ends
321
+ * without its separator; the break separates.
322
+ */
323
+ export function joinParts(parts, width, lead = "", rest = lead, separator = " · ") {
324
+ const lines = [];
325
+ let current = "";
326
+ for (const part of parts.filter(Boolean)) {
327
+ const prefix = lines.length ? rest : lead;
328
+ if (current && visibleLength(prefix + current + separator + part) > width) {
329
+ lines.push(prefix + current);
330
+ current = part;
331
+ }
332
+ else
333
+ current = current ? `${current}${separator}${part}` : part;
334
+ }
335
+ if (current)
336
+ lines.push((lines.length ? rest : lead) + current);
337
+ return lines;
338
+ }
339
+ /** "just now", "4 min ago", "3 h ago", "2 days ago". */
340
+ export function ago(ms) {
341
+ const minutes = Math.round(Math.max(0, ms) / 60_000);
342
+ if (minutes < 1)
343
+ return "just now";
344
+ if (minutes < 60)
345
+ return `${minutes} min ago`;
346
+ const hours = Math.round(minutes / 60);
347
+ return hours < 48 ? `${hours} h ago` : `${Math.round(hours / 24)} days ago`;
348
+ }
175
349
  /** "1:32", or "12:05" for longer waits. Never negative. */
176
350
  export function countdown(ms) {
177
351
  const seconds = Math.max(0, Math.ceil(ms / 1000));
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.16.13";
1
+ export declare const VERSION = "0.16.14";