@tiny-fish/cli 0.21.1-next.195 → 0.21.1-next.196

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/README.md CHANGED
@@ -80,6 +80,9 @@ Brings both halves of an install current: the global `@tiny-fish/cli` package an
80
80
  `use-tinyfish` skill. Use this rather than remembering `npm i -g @tiny-fish/cli@latest` and
81
81
  `skills update -g` separately.
82
82
 
83
+ Successful steps are summarised in one line each. Add `--verbose` to see the full npm and skills
84
+ output; a failing step prints its output either way.
85
+
83
86
  The skill step refreshes only the TinyFish skill, and only for the agents you ran
84
87
  `tinyfish connect` against. Other global skills, and agents you never connected, are left alone.
85
88
  The refresh overwrites your copy of the skill, including any local edits to it. Restart your
@@ -144,7 +144,8 @@ function connectedLine(client, signInDeferred) {
144
144
  function runPostInstallSteps(client, options, state, telemetry, signInDeferred) {
145
145
  try {
146
146
  state.stage = "cli_install";
147
- installTinyFishCli();
147
+ // Verbose on purpose: first-run setup must not go silent.
148
+ installTinyFishCli({ verbose: true });
148
149
  telemetry.track("checkpoint", { phase: "cli_installed" });
149
150
  state.stage = "skill_install";
150
151
  installWebSkill(client);
@@ -207,7 +208,7 @@ export async function connectOpenClaw(options) {
207
208
  telemetry.track("checkpoint", { phase: "prerequisite_ok" });
208
209
  if (options.installCli !== false) {
209
210
  state.stage = "cli_install";
210
- installTinyFishCli();
211
+ installTinyFishCli({ verbose: true });
211
212
  telemetry.track("checkpoint", { phase: "cli_installed" });
212
213
  }
213
214
  state.stage = "skill_install";
@@ -1,6 +1,6 @@
1
1
  import { Command } from "commander";
2
2
  /** Returns the version now installed, so the caller reports exactly what the user was told. */
3
- export declare function runUpgrade(): string | null;
3
+ export declare function runUpgrade(verbose?: boolean): string | null;
4
4
  /** `runUpgrade` plus its outcome telemetry, which must never change what the upgrade does. */
5
- export declare function runUpgradeCommand(): Promise<void>;
5
+ export declare function runUpgradeCommand(verbose?: boolean): Promise<void>;
6
6
  export declare function registerUpgrade(program: Command): void;
@@ -26,13 +26,16 @@ function attempt(label, run) {
26
26
  }
27
27
  }
28
28
  /** Returns the version now installed, so the caller reports exactly what the user was told. */
29
- export function runUpgrade() {
29
+ export function runUpgrade(verbose = false) {
30
30
  errLine("Upgrading TinyFish...");
31
+ let refreshed = false;
31
32
  try {
32
33
  // Both steps always run: neither artifact should stay stale because the other failed.
33
34
  const failures = [
34
- attempt("update the TinyFish CLI", installTinyFishCli),
35
- attempt("refresh the TinyFish web skill", updateWebSkill),
35
+ attempt("update the TinyFish CLI", () => installTinyFishCli({ verbose })),
36
+ attempt("refresh the TinyFish web skill", () => {
37
+ refreshed = updateWebSkill({ verbose });
38
+ }),
36
39
  ].filter((failure) => failure !== undefined);
37
40
  if (failures.length > 0)
38
41
  throw new Error(`tinyfish upgrade failed: ${failures.join("; ")}`);
@@ -45,9 +48,9 @@ export function runUpgrade() {
45
48
  return null;
46
49
  }
47
50
  const version = installedCliVersion();
48
- errLine(version
49
- ? `TinyFish CLI ${version} is up to date. Restart your agent to pick up the refreshed skill.`
50
- : "TinyFish is up to date. Restart your agent to pick up the refreshed skill.");
51
+ const upToDate = version ? `TinyFish CLI ${version} is up to date.` : "TinyFish is up to date.";
52
+ // Only a rewritten skill needs an agent restart.
53
+ errLine(refreshed ? `${upToDate} Restart your agent to pick up the refreshed skill.` : upToDate);
51
54
  return version;
52
55
  }
53
56
  /** The version now on disk. Only the upgrade's own npm call knows what "latest" resolved to. */
@@ -67,7 +70,7 @@ function globalCliVersion() {
67
70
  }
68
71
  }
69
72
  /** `runUpgrade` plus its outcome telemetry, which must never change what the upgrade does. */
70
- export async function runUpgradeCommand() {
73
+ export async function runUpgradeCommand(verbose = false) {
71
74
  // This command is the upgrade, so a trailing "an update is available" would be noise.
72
75
  suppressNotice();
73
76
  let reported = false;
@@ -90,7 +93,7 @@ export async function runUpgradeCommand() {
90
93
  });
91
94
  let outcome = "updated";
92
95
  try {
93
- printedVersion = runUpgrade();
96
+ printedVersion = runUpgrade(verbose);
94
97
  if (process.exitCode === SIGNAL_EXIT_CODES.SIGINT)
95
98
  outcome = "interrupted";
96
99
  }
@@ -108,7 +111,8 @@ export function registerUpgrade(program) {
108
111
  program
109
112
  .command("upgrade")
110
113
  .description("Update the TinyFish CLI and the use-tinyfish skill to the latest versions")
111
- .action(async () => {
112
- await runUpgradeCommand();
114
+ .option("--verbose", "Print the full npm and skills output instead of only on failure")
115
+ .action(async (options) => {
116
+ await runUpgradeCommand(Boolean(options.verbose));
113
117
  });
114
118
  }
@@ -3,7 +3,11 @@ import { type AgentClient } from "./connect-runtime.js";
3
3
  export declare const SKILL_INSTALL_TIMEOUT_MS = 120000;
4
4
  export declare const TINYFISH_CLI_NOT_FOUND_MESSAGE = "TinyFish CLI installed but is not available on PATH. Open a new terminal and retry.";
5
5
  export declare const UPGRADE_HINT = "Run `tinyfish upgrade` any time to update the CLI and skill.";
6
- export declare function installTinyFishCli(): void;
6
+ /** Quiet captures subprocess output and replays it only on failure. */
7
+ export type InstallOptions = {
8
+ verbose: boolean;
9
+ };
10
+ export declare function installTinyFishCli({ verbose }: InstallOptions): void;
7
11
  export declare function installWebSkill(client: NativeMcpClient): void;
8
12
  /**
9
13
  * Refresh the skill we installed, for the harnesses we installed it in.
@@ -12,6 +16,8 @@ export declare function installWebSkill(client: NativeMcpClient): void;
12
16
  * only in prose, it repairs a copy whose lock entry lost its hash, and it cannot spread the
13
17
  * skill to agents the user never connected (`update` re-adds with no --agent, which targets
14
18
  * every agent on the machine).
19
+ *
20
+ * Returns whether a skill was actually rewritten.
15
21
  */
16
- export declare function updateWebSkill(): void;
22
+ export declare function updateWebSkill({ verbose }: InstallOptions): boolean;
17
23
  export declare function ensureCliAuthenticated(source: AgentClient, apiKey?: string): void;
@@ -14,17 +14,37 @@ export const UPGRADE_HINT = "Run `tinyfish upgrade` any time to update the CLI a
14
14
  const SKILLS_CLI_PACKAGE = "skills@1.5.15";
15
15
  const TINYFISH_WEB_SKILL_SOURCE = "tinyfish-io/tinyfish-cookbook";
16
16
  const TINYFISH_WEB_SKILL = "use-tinyfish";
17
- export function installTinyFishCli() {
18
- errLine("Installing the TinyFish CLI...");
17
+ // spawnSync caps piped output at 1 MiB by default.
18
+ const STEP_MAX_BUFFER = 10 * 1024 * 1024;
19
+ function captureStdio(verbose) {
20
+ return verbose
21
+ ? { stdio: "inherit", timeout: SKILL_INSTALL_TIMEOUT_MS }
22
+ : { encoding: "utf8", maxBuffer: STEP_MAX_BUFFER, timeout: SKILL_INSTALL_TIMEOUT_MS };
23
+ }
24
+ /** Inherited stdio leaves these null; only piped runs yield text. */
25
+ function capturedOutput(result) {
26
+ return `${asText(result.stdout)}${asText(result.stderr)}`;
27
+ }
28
+ function asText(stream) {
29
+ return typeof stream === "string" ? stream : "";
30
+ }
31
+ /** A verbose run captured nothing, so this is a no-op. */
32
+ function replay(output) {
33
+ if (output.trim())
34
+ errLine(output.trimEnd());
35
+ }
36
+ export function installTinyFishCli({ verbose }) {
37
+ if (verbose)
38
+ errLine("Installing the TinyFish CLI...");
19
39
  // Without the prefix, a curl install upgrades npm's global tree and never the PATH binary.
20
40
  const root = installRoot();
21
41
  const prefixArgs = root ? ["--prefix", root.prefix] : [];
22
- const result = spawn.sync("npm", ["install", "--global", ...prefixArgs, TINYFISH_CLI_INSTALL_SPEC], {
23
- stdio: "inherit",
24
- timeout: SKILL_INSTALL_TIMEOUT_MS,
25
- });
42
+ const result = spawn.sync("npm", ["install", "--global", ...prefixArgs, TINYFISH_CLI_INSTALL_SPEC], captureStdio(verbose));
26
43
  if (result.error || result.status !== 0) {
27
- throw spawnStepError("Could not install the TinyFish CLI", result);
44
+ // Built first: it runs the interrupt check, and abandonment must not replay.
45
+ const error = spawnStepError("Could not install the TinyFish CLI", result);
46
+ replay(capturedOutput(result));
47
+ throw error;
28
48
  }
29
49
  }
30
50
  /** `skills add` is an unconditional overwrite, so it doubles as the refresh path. */
@@ -53,6 +73,8 @@ function skillSpawnEnv() {
53
73
  // Safe to match on because SKILLS_CLI_PACKAGE is pinned.
54
74
  const SKILL_UPDATE_FAILURE_PATTERN = /Failed to (?:update|check|fetch)/;
55
75
  const SKILL_NOT_INSTALLED_PATTERN = /No installed skills found matching/;
76
+ // Nothing was rewritten, so nothing needs an agent restart.
77
+ const SKILL_ALREADY_CURRENT_PATTERN = /All global skills are up to date/;
56
78
  // A lock entry with no recorded hash is untrackable, so `skills` reports it as skipped rather
57
79
  // than failed. Left undetected that reads as "up to date" while nothing was refreshed.
58
80
  const SKILL_UNCHECKABLE_PATTERN = /cannot be checked automatically/;
@@ -65,6 +87,7 @@ export function installWebSkill(client) {
65
87
  const result = spawn.sync("npx", skillAddArgs([client.skillAgent]), {
66
88
  encoding: "utf8",
67
89
  env: skillSpawnEnv(),
90
+ maxBuffer: STEP_MAX_BUFFER,
68
91
  timeout: SKILL_INSTALL_TIMEOUT_MS,
69
92
  });
70
93
  const output = `${result.stdout ?? ""}${result.stderr ?? ""}`;
@@ -81,8 +104,10 @@ export function installWebSkill(client) {
81
104
  * only in prose, it repairs a copy whose lock entry lost its hash, and it cannot spread the
82
105
  * skill to agents the user never connected (`update` re-adds with no --agent, which targets
83
106
  * every agent on the machine).
107
+ *
108
+ * Returns whether a skill was actually rewritten.
84
109
  */
85
- export function updateWebSkill() {
110
+ export function updateWebSkill({ verbose }) {
86
111
  // One entry per `tinyfish connect <client>`, persisted by PF-3169.
87
112
  const connected = loadConfig().connect ?? {};
88
113
  const skillAgents = NATIVE_MCP_CLIENTS
@@ -90,71 +115,82 @@ export function updateWebSkill() {
90
115
  .map((client) => client.skillAgent);
91
116
  const hasOpenClaw = Boolean(connected["openclaw"]);
92
117
  // Installs predating PF-3169 recorded nothing; ask `skills` to refresh what it tracks.
93
- if (skillAgents.length === 0 && !hasOpenClaw) {
94
- refreshWebSkillByHash();
95
- return;
118
+ if (skillAgents.length === 0 && !hasOpenClaw)
119
+ return refreshWebSkillByHash(verbose);
120
+ let refreshed = false;
121
+ if (skillAgents.length > 0) {
122
+ reinstallWebSkill(skillAgents, verbose);
123
+ refreshed = true;
96
124
  }
97
- if (skillAgents.length > 0)
98
- reinstallWebSkill(skillAgents);
99
125
  // OpenClaw keeps its skill under its own CLI, so it needs its own refresh.
100
126
  if (hasOpenClaw)
101
- reinstallOpenClawSkill();
127
+ refreshed = reinstallOpenClawSkill(verbose) || refreshed;
128
+ return refreshed;
102
129
  }
103
- function reinstallOpenClawSkill() {
104
- errLine("Refreshing the TinyFish skill in OpenClaw...");
105
- const result = spawn.sync("openclaw", OPENCLAW_SKILL_INSTALL_ARGS, {
106
- stdio: "inherit",
107
- timeout: SKILL_INSTALL_TIMEOUT_MS,
108
- });
130
+ function reinstallOpenClawSkill(verbose) {
131
+ if (verbose)
132
+ errLine("Refreshing the TinyFish skill in OpenClaw...");
133
+ const result = spawn.sync("openclaw", OPENCLAW_SKILL_INSTALL_ARGS, captureStdio(verbose));
109
134
  // OpenClaw may have been removed since connect; a stale context entry must not fail an
110
135
  // upgrade that otherwise succeeded.
111
136
  if (commandNotFound(result.error)) {
112
137
  errLine("OpenClaw is not on PATH, so its TinyFish skill was left unchanged.");
113
- return;
138
+ return false;
114
139
  }
115
140
  if (result.error || result.status !== 0) {
116
141
  throwIfInterrupted(result);
142
+ replay(capturedOutput(result));
117
143
  throw new Error("Could not refresh the TinyFish skill in OpenClaw", { cause: result.error });
118
144
  }
145
+ return true;
119
146
  }
120
- function reinstallWebSkill(skillAgents) {
121
- errLine(`Refreshing the TinyFish web skill for ${skillAgents.join(", ")}...`);
147
+ function reinstallWebSkill(skillAgents, verbose) {
148
+ if (verbose)
149
+ errLine(`Refreshing the TinyFish web skill for ${skillAgents.join(", ")}...`);
122
150
  const result = spawn.sync("npx", skillAddArgs(skillAgents), {
123
151
  encoding: "utf8",
124
152
  env: skillSpawnEnv(),
153
+ maxBuffer: STEP_MAX_BUFFER,
125
154
  timeout: SKILL_INSTALL_TIMEOUT_MS,
126
155
  });
127
- const output = `${result.stdout ?? ""}${result.stderr ?? ""}`;
128
- if (output.trim())
129
- errLine(output.trimEnd());
130
- if (result.error || result.status !== 0 || SKILL_INSTALL_FAILURE_PATTERN.test(output)) {
156
+ const output = capturedOutput(result);
157
+ const failed = Boolean(result.error) || result.status !== 0 || SKILL_INSTALL_FAILURE_PATTERN.test(output);
158
+ if (failed)
131
159
  throwIfInterrupted(result);
160
+ if (verbose || failed)
161
+ replay(output);
162
+ if (failed)
132
163
  throw new Error("Could not refresh the TinyFish web skill", { cause: result.error });
133
- }
134
164
  }
135
165
  /** Fallback when no harness is recorded: ask `skills` to refresh whatever it tracks. */
136
- function refreshWebSkillByHash() {
137
- errLine("Refreshing the TinyFish web skill...");
166
+ function refreshWebSkillByHash(verbose) {
167
+ if (verbose)
168
+ errLine("Refreshing the TinyFish web skill...");
138
169
  const result = spawn.sync("npx", ["-y", SKILLS_CLI_PACKAGE, "update", TINYFISH_WEB_SKILL, "--global", "--yes"], {
139
170
  encoding: "utf8",
140
171
  env: skillSpawnEnv(),
172
+ maxBuffer: STEP_MAX_BUFFER,
141
173
  timeout: SKILL_INSTALL_TIMEOUT_MS,
142
174
  });
143
- // Piped rather than inherited so the output can be inspected; echoed back for the user.
144
- const output = `${result.stdout ?? ""}${result.stderr ?? ""}`;
145
- if (output.trim())
146
- errLine(output.trimEnd());
147
- if (result.error || result.status !== 0 || SKILL_UPDATE_FAILURE_PATTERN.test(output)) {
175
+ // Piped so prose-only failures can be matched; skills exits 0 anyway.
176
+ const output = capturedOutput(result);
177
+ const unchecked = SKILL_UNCHECKABLE_PATTERN.test(output);
178
+ const failed = Boolean(result.error) || result.status !== 0 || SKILL_UPDATE_FAILURE_PATTERN.test(output);
179
+ if (failed)
148
180
  throwIfInterrupted(result);
181
+ if (verbose || failed || unchecked)
182
+ replay(output);
183
+ if (failed)
149
184
  throw new Error("Could not refresh the TinyFish web skill", { cause: result.error });
150
- }
151
- if (SKILL_UNCHECKABLE_PATTERN.test(output)) {
185
+ if (unchecked) {
152
186
  errLine("Run `tinyfish connect <client>` to reinstall the skill and restore update tracking.");
153
187
  throw new Error("The TinyFish web skill cannot be checked for updates");
154
188
  }
155
189
  if (SKILL_NOT_INSTALLED_PATTERN.test(output)) {
156
190
  errLine("No use-tinyfish skill installed. Run `tinyfish connect <client>` to add it.");
191
+ return false;
157
192
  }
193
+ return !SKILL_ALREADY_CURRENT_PATTERN.test(output);
158
194
  }
159
195
  export function ensureCliAuthenticated(source, apiKey) {
160
196
  const envKey = apiKey ?? process.env["TINYFISH_API_KEY"];
@@ -33,10 +33,13 @@ export class ConnectStepError extends Error {
33
33
  }
34
34
  class PrerequisiteError extends ConnectStepError {
35
35
  }
36
+ // A maxBuffer overflow is also killed with SIGTERM, and is a failure too.
37
+ const NOT_INTERRUPTIONS = new Set(["ETIMEDOUT", "ENOBUFS"]);
36
38
  export function throwIfInterrupted(result) {
37
39
  // spawn.sync kills a timed-out child with SIGTERM, so signal alone would misread a slow
38
40
  // network as the user walking away. A timeout is a failure and must report as one.
39
- if (result.error?.code === "ETIMEDOUT")
41
+ const code = result.error?.code;
42
+ if (code && NOT_INTERRUPTIONS.has(code))
40
43
  return;
41
44
  if (result.signal === "SIGINT" || result.signal === "SIGTERM") {
42
45
  throw new ConnectInterruptedError("Setup interrupted");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiny-fish/cli",
3
- "version": "0.21.1-next.195",
3
+ "version": "0.21.1-next.196",
4
4
  "description": "TinyFish CLI — run web automations from your terminal",
5
5
  "type": "module",
6
6
  "bin": {