Merge pull request 'fix: setup UX improvements (#114)' (#115) from fix/114-setup-ux into main
CI / check (push) Successful in 2m43s
CI / check (push) Successful in 2m43s
This commit was merged in pull request #115.
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
"@united-workforce/cli": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: setup UX improvements (#114)
|
||||||
|
|
||||||
|
- Setup validates adapter availability and prints install command if missing
|
||||||
|
- Setup prints "Config saved to <path> ✓" on success
|
||||||
|
- Spawn ENOENT gives actionable error ("not found in PATH" + which command)
|
||||||
|
- SQLite ExperimentalWarning suppressed via NODE_OPTIONS in spawned processes
|
||||||
|
- Bootstrap VERSION reads cli package version (was reading util version)
|
||||||
|
- Bootstrap PATH guidance is shell-agnostic (no hardcoded .bashrc/.profile)
|
||||||
@@ -1,10 +1,35 @@
|
|||||||
|
import { readFileSync } from "node:fs";
|
||||||
|
import { dirname, join } from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
import {
|
import {
|
||||||
generateAdapterDevelopingReference,
|
generateAdapterDevelopingReference,
|
||||||
generateUsageReference,
|
generateUsageReference,
|
||||||
generateWorkflowAuthoringReference,
|
generateWorkflowAuthoringReference,
|
||||||
VERSION,
|
|
||||||
} from "@united-workforce/util";
|
} from "@united-workforce/util";
|
||||||
|
|
||||||
|
// CLI package version (for bootstrap prompt — uwf --version prints this)
|
||||||
|
// Walk up from __dirname to find the nearest package.json (works from both src/ and dist/)
|
||||||
|
function _findCliVersion(): string {
|
||||||
|
let dir = dirname(fileURLToPath(import.meta.url));
|
||||||
|
for (let i = 0; i < 5; i++) {
|
||||||
|
const candidate = join(dir, "package.json");
|
||||||
|
try {
|
||||||
|
const pkg = JSON.parse(readFileSync(candidate, "utf-8")) as {
|
||||||
|
name?: string;
|
||||||
|
version?: string;
|
||||||
|
};
|
||||||
|
if (pkg.name === "@united-workforce/cli") {
|
||||||
|
return pkg.version ?? "0.0.0";
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// not found, keep walking
|
||||||
|
}
|
||||||
|
dir = dirname(dir);
|
||||||
|
}
|
||||||
|
return "0.0.0";
|
||||||
|
}
|
||||||
|
const CLI_VERSION = _findCliVersion();
|
||||||
|
|
||||||
export {
|
export {
|
||||||
generateAdapterDevelopingReference as cmdPromptAdapterDeveloping,
|
generateAdapterDevelopingReference as cmdPromptAdapterDeveloping,
|
||||||
generateUsageReference as cmdPromptUsage,
|
generateUsageReference as cmdPromptUsage,
|
||||||
@@ -45,14 +70,14 @@ pnpm --version || npm --version
|
|||||||
|
|
||||||
# 3. Global bin directory is in PATH
|
# 3. Global bin directory is in PATH
|
||||||
# For pnpm:
|
# For pnpm:
|
||||||
pnpm root -g 2>/dev/null && pnpm bin -g
|
pnpm bin -g # prints the global bin directory
|
||||||
# For npm:
|
# For npm:
|
||||||
npm prefix -g
|
npm prefix -g # global prefix; bin is <prefix>/bin
|
||||||
# The "bin" directory printed above MUST be in your PATH.
|
# The directory printed above MUST be in your PATH.
|
||||||
# Test: echo $PATH | tr ':' '\\n' | grep -E "(pnpm|npm|node)"
|
# Test: echo \\$PATH | tr ':' '\\\\n'
|
||||||
# FIX: add the bin directory to ~/.profile or ~/.bashrc:
|
# FIX: add the missing directory to your shell's startup file
|
||||||
# export PATH="$(pnpm bin -g):$PATH" # pnpm
|
# (e.g. ~/.bashrc, ~/.zshrc, ~/.profile, or fish config):
|
||||||
# export PATH="$(npm prefix -g)/bin:$PATH" # npm
|
# export PATH="<global-bin-dir>:$PATH"
|
||||||
|
|
||||||
# 4. (uwf-hermes only) hermes CLI
|
# 4. (uwf-hermes only) hermes CLI
|
||||||
which hermes
|
which hermes
|
||||||
@@ -61,13 +86,13 @@ which hermes
|
|||||||
# or create a symlink: ln -s ~/.hermes/hermes-agent/.venv/bin/hermes ~/.local/bin/hermes
|
# or create a symlink: ln -s ~/.hermes/hermes-agent/.venv/bin/hermes ~/.local/bin/hermes
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
**All checks must pass before continuing.** If you had to modify PATH, verify the change persists by opening a new shell or sourcing your profile.
|
**All checks must pass before continuing.** If you had to modify PATH, verify the change persists by opening a new shell or sourcing your shell config.
|
||||||
|
|
||||||
### Step 1 — Install CLI and agent adapter
|
### Step 1 — Install CLI and agent adapter
|
||||||
|
|
||||||
\`\`\`bash
|
\`\`\`bash
|
||||||
pnpm add -g @united-workforce/cli # or: npm install -g @united-workforce/cli
|
pnpm add -g @united-workforce/cli # or: npm install -g @united-workforce/cli
|
||||||
uwf --version # should print ${VERSION}
|
uwf --version # should print ${CLI_VERSION}
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
Install an agent adapter (at least one is required):
|
Install an agent adapter (at least one is required):
|
||||||
@@ -165,7 +190,7 @@ If the thread reaches \`$END\` with status \`completed\`, the setup is working.
|
|||||||
|
|
||||||
\`\`\`bash
|
\`\`\`bash
|
||||||
pnpm add -g @united-workforce/cli@latest # or: npm install -g @united-workforce/cli@latest
|
pnpm add -g @united-workforce/cli@latest # or: npm install -g @united-workforce/cli@latest
|
||||||
uwf --version # should print ${VERSION}
|
uwf --version # should print ${CLI_VERSION}
|
||||||
|
|
||||||
# Also update your adapter(s)
|
# Also update your adapter(s)
|
||||||
pnpm add -g @united-workforce/agent-hermes@latest
|
pnpm add -g @united-workforce/agent-hermes@latest
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { execFileSync } from "node:child_process";
|
||||||
import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { stdin as input, stdout as output } from "node:process";
|
import { stdin as input, stdout as output } from "node:process";
|
||||||
@@ -181,7 +182,6 @@ export async function _discoverAgents(): Promise<string[]> {
|
|||||||
|
|
||||||
async function _tryWhichDiscovery(): Promise<string[] | null> {
|
async function _tryWhichDiscovery(): Promise<string[] | null> {
|
||||||
try {
|
try {
|
||||||
const { execFileSync } = await import("node:child_process");
|
|
||||||
const text = execFileSync("which", ["-a", "uwf-hermes", "uwf-claude-code", "uwf-cursor"], {
|
const text = execFileSync("which", ["-a", "uwf-hermes", "uwf-claude-code", "uwf-cursor"], {
|
||||||
encoding: "utf-8",
|
encoding: "utf-8",
|
||||||
stdio: ["pipe", "pipe", "pipe"],
|
stdio: ["pipe", "pipe", "pipe"],
|
||||||
@@ -397,6 +397,37 @@ function mergeConfig(existing: Record<string, unknown>, args: SetupArgs): Record
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the configured adapter binary (and its dependencies) are in PATH.
|
||||||
|
* Returns warnings array — empty means all good.
|
||||||
|
*/
|
||||||
|
export function _checkAdapterAvailability(agentName: string): string[] {
|
||||||
|
const warnings: string[] = [];
|
||||||
|
const binary = `uwf-${agentName}`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
execFileSync("which", [binary], { encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
|
||||||
|
} catch {
|
||||||
|
warnings.push(
|
||||||
|
`${binary} not found in PATH. Install it: pnpm add -g @united-workforce/agent-${agentName}`,
|
||||||
|
);
|
||||||
|
return warnings; // skip dependency check if adapter itself is missing
|
||||||
|
}
|
||||||
|
|
||||||
|
// uwf-hermes depends on hermes CLI
|
||||||
|
if (agentName === "hermes") {
|
||||||
|
try {
|
||||||
|
execFileSync("which", ["hermes"], { encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
|
||||||
|
} catch {
|
||||||
|
warnings.push(
|
||||||
|
'hermes CLI not found in PATH (required by uwf-hermes). Fix: export PATH="$HOME/.hermes/hermes-agent/.venv/bin:$PATH"',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return warnings;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-interactive setup. All required args provided via CLI flags.
|
* Non-interactive setup. All required args provided via CLI flags.
|
||||||
*/
|
*/
|
||||||
@@ -411,15 +442,26 @@ export async function cmdSetup(args: SetupArgs): Promise<Record<string, unknown>
|
|||||||
|
|
||||||
writeFileSync(configPath, stringify(merged, { indent: 2 }), "utf8");
|
writeFileSync(configPath, stringify(merged, { indent: 2 }), "utf8");
|
||||||
|
|
||||||
|
// Print config path to stderr (stdout is reserved for JSON output)
|
||||||
|
console.error(`Config saved to ${configPath} ✓`);
|
||||||
|
|
||||||
// Validate model connectivity
|
// Validate model connectivity
|
||||||
const validation = await validateModel(args.baseUrl, args.apiKey, args.model);
|
const validation = await validateModel(args.baseUrl, args.apiKey, args.model);
|
||||||
|
|
||||||
|
// Check adapter availability
|
||||||
|
const agentName = _agentNameFromBinary(args.agent ?? "hermes");
|
||||||
|
const adapterWarnings = _checkAdapterAvailability(agentName);
|
||||||
|
for (const w of adapterWarnings) {
|
||||||
|
console.error(`⚠ ${w}`);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
configPath,
|
configPath,
|
||||||
provider: args.provider,
|
provider: args.provider,
|
||||||
model: args.model,
|
model: args.model,
|
||||||
defaultAgent: merged.defaultAgent,
|
defaultAgent: merged.defaultAgent,
|
||||||
validation,
|
validation,
|
||||||
|
adapterWarnings,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1001,9 +1001,21 @@ function spawnAgent(
|
|||||||
stdio: ["ignore", "pipe", "pipe"],
|
stdio: ["ignore", "pipe", "pipe"],
|
||||||
maxBuffer: 50 * 1024 * 1024, // 50 MB — stream-json output can be large
|
maxBuffer: 50 * 1024 * 1024, // 50 MB — stream-json output can be large
|
||||||
cwd,
|
cwd,
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
NODE_OPTIONS: [process.env.NODE_OPTIONS, "--disable-warning=ExperimentalWarning"]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(" "),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const err = e as NodeJS.ErrnoException & { stderr?: Buffer | string | null };
|
const err = e as NodeJS.ErrnoException & { stderr?: Buffer | string | null };
|
||||||
|
if (err.code === "ENOENT") {
|
||||||
|
failStep(
|
||||||
|
plog,
|
||||||
|
`"${agent.command}" not found in PATH. Install it or check your PATH config. Run: which ${agent.command}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
const stderr =
|
const stderr =
|
||||||
err.stderr == null
|
err.stderr == null
|
||||||
? ""
|
? ""
|
||||||
@@ -1242,6 +1254,12 @@ async function cmdThreadStepBackground(
|
|||||||
const child = spawn(scriptPath, args, {
|
const child = spawn(scriptPath, args, {
|
||||||
detached: true,
|
detached: true,
|
||||||
stdio: "ignore",
|
stdio: "ignore",
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
NODE_OPTIONS: [process.env.NODE_OPTIONS, "--disable-warning=ExperimentalWarning"]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(" "),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
child.unref();
|
child.unref();
|
||||||
|
|||||||
Reference in New Issue
Block a user