Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ packages/
doctor.ts Health checks with lifecycle-based warnings
checkpoint.ts Signal host to commit data changes
tools/ System primitives backing CapabilityContext
types.ts ProvisionResult interface
fs.ts File system helpers (ensureLineInFile, ensureDir)
curl.ts Download helpers
shell-profile.ts Login profile management
Expand Down
2 changes: 0 additions & 2 deletions docs/vm-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ packages/vm-cli/
doctor.ts Health checks (mounts, env, PATH, services, openclaw)
checkpoint.ts Signal host to commit data changes
tools/ System primitives backing CapabilityContext
types.ts ProvisionResult interface
fs.ts ensureLineInFile, ensureDir
curl.ts downloadFile, downloadAndRun
shell-profile.ts ensureInBashrc, ensureInProfile, ensurePath
Expand All @@ -107,7 +106,6 @@ indirectly via the context SDK — not by direct import.

| Module | Purpose |
| --------------------- | --------------------------------------------------------- |
| `types.ts` | `ProvisionResult` interface |
| `fs.ts` | `ensureLineInFile`, `ensureDir` |
| `curl.ts` | `downloadFile`, `downloadAndRun` |
| `shell-profile.ts` | `ensureInBashrc`, `ensureInProfile`, `ensurePath` |
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ export function App({ driver, creationTarget }: AppProps) {

{step === "finish" && (
<Finish
driver={driver}
config={config}
onboardSkipped={onboardSkipped}
tailscaleMode={credentialConfig.tailscaleMode}
Expand Down
15 changes: 10 additions & 5 deletions packages/cli/src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ import { openSync } from "node:fs";
import { ReadStream } from "node:tty";
import { join } from "path";
import type { VMDriver } from "@clawctl/host-core";
import { addInstance, getTailscaleHostname, cleanupVM } from "@clawctl/host-core";
import {
addInstance,
getTailscaleHostname,
cleanupVM,
runHeadless,
extractGatewayToken,
loadRegistry,
saveRegistry,
BIN_NAME,
} from "@clawctl/host-core";
import type { RegistryEntry, CleanupTarget } from "@clawctl/host-core";
import { GATEWAY_PORT } from "@clawctl/types";
import { BIN_NAME } from "@clawctl/host-core";

/**
* Run the headless create path: load config, provision, register.
*/
export async function runCreateHeadless(driver: VMDriver, configPath: string): Promise<void> {
const { runHeadless } = await import("@clawctl/host-core");
const result = await runHeadless(driver, configPath);

const entry: RegistryEntry = {
Expand All @@ -36,7 +43,6 @@ export async function runCreateWizard(driver: VMDriver): Promise<void> {
const React = (await import("react")).default;
const { render } = await import("ink");
const { App } = await import("../app.js");
const { extractGatewayToken } = await import("@clawctl/host-core");

type OnboardResult = {
action: "onboard";
Expand Down Expand Up @@ -210,7 +216,6 @@ export async function runCreateWizard(driver: VMDriver): Promise<void> {
console.log(" First tailnet connection requires device approval:");
console.log(` ${BIN_NAME} oc devices list`);
console.log(` ${BIN_NAME} oc devices approve <requestId>`);
const { loadRegistry, saveRegistry } = await import("@clawctl/host-core");
const registry = await loadRegistry();
if (registry.instances[vmName]) {
registry.instances[vmName].tailscaleUrl = tsBaseUrl;
Expand Down
17 changes: 0 additions & 17 deletions packages/cli/src/hooks/use-process-logs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,6 @@ describe("useProcessLogs logic", () => {
expect(lines).toEqual(["first", "second", "third"]);
});

test("clear resets the buffer", () => {
let lines: string[] = [];
const addLine = (line: string) => {
lines.push(line);
};
const clear = () => {
lines = [];
};

addLine("a");
addLine("b");
expect(lines).toHaveLength(2);

clear();
expect(lines).toHaveLength(0);
});

test("addLine is safe to call rapidly", () => {
const lines: string[] = [];
const addLine = (line: string) => {
Expand Down
7 changes: 1 addition & 6 deletions packages/cli/src/hooks/use-process-logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,5 @@ export function useProcessLogs() {
setTick((t) => t + 1);
}, []);

const clear = useCallback(() => {
linesRef.current = [];
setTick((t) => t + 1);
}, []);

return { lines: linesRef.current, addLine, clear };
return { lines: linesRef.current, addLine };
}
2 changes: 1 addition & 1 deletion packages/cli/src/hooks/use-verbose-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export function useVerboseMode() {
}
});

return { verbose, toggle: () => setVerbose((prev) => !prev) };
return { verbose };
}
4 changes: 1 addition & 3 deletions packages/cli/src/steps/credential-setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ export function CredentialSetup({

useEffect(() => {
async function run() {
const updatedCreds = { ...credentialConfig };

// Validate 1Password token in VM
if (hasOp) {
try {
Expand Down Expand Up @@ -81,7 +79,7 @@ export function CredentialSetup({
}

setPhase("done");
setTimeout(() => onComplete(updatedCreds), 500);
setTimeout(() => onComplete(credentialConfig), 500);
}
run();
}, []);
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/src/steps/finish.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Text, Box, useApp } from "ink";
import { StepIndicator } from "../components/step-indicator.js";
import type { VMConfig } from "@clawctl/types";
import { GATEWAY_PORT } from "@clawctl/types";
import type { VMDriver } from "@clawctl/host-core";
import { BIN_NAME } from "@clawctl/host-core";

export interface FinishResult {
Expand All @@ -14,7 +13,6 @@ export interface FinishResult {
}

interface FinishProps {
driver: VMDriver;
config: VMConfig;
onboardSkipped?: boolean;
tailscaleMode?: "off" | "serve" | "funnel";
Expand Down
27 changes: 0 additions & 27 deletions packages/host-core/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { readFile } from "fs/promises";
import { homedir } from "os";
import { resolve } from "path";
import { resolveEnvRefs, validateConfig } from "@clawctl/types";
import type { InstanceConfig, VMConfig } from "@clawctl/types";

Expand Down Expand Up @@ -59,31 +57,6 @@ export function sanitizeConfig(config: InstanceConfig): Record<string, unknown>
return clone;
}

/** Format a zod error into a readable message with field path. */
export function formatZodError(error: import("zod").ZodError): string {
const issue = error.issues[0];
const path = issue.path.join(".");

// Use custom messages (from .min() / .refine()) when they look specific
if (issue.message && !issue.message.startsWith("Invalid input:")) {
return issue.message;
}

// Build a path-based message for generic zod errors
if (path) {
return `'${path}': ${issue.message}`;
}
return issue.message;
}

/** Expand leading ~ to the user's home directory. */
export function expandTilde(path: string): string {
if (path.startsWith("~/") || path === "~") {
return resolve(homedir(), path.slice(2));
}
return path;
}

/** Read and validate a JSON config file. */
export async function loadConfig(path: string): Promise<InstanceConfig> {
let raw: string;
Expand Down
9 changes: 1 addition & 8 deletions packages/host-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@ export type { VMDriver, VMCreateOptions, ExecResult, OnLine } from "./drivers/ty
export { exec, execStream, execWithLogs, commandExists } from "./exec.js";

// Config
export {
loadConfig,
validateConfig,
configToVMConfig,
sanitizeConfig,
formatZodError,
expandTilde,
} from "./config.js";
export { loadConfig, validateConfig, configToVMConfig, sanitizeConfig } from "./config.js";

// Secrets (I/O + re-exports of pure functions from @clawctl/types)
export {
Expand Down
10 changes: 0 additions & 10 deletions packages/vm-cli/src/tools/openclaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ export async function isInstalled(): Promise<boolean> {
return commandExists("openclaw");
}

/** Get the installed openclaw version string. */
export async function version(): Promise<string> {
const npmGlobalBin = `${process.env.HOME}/.npm-global/bin`;
const result = await exec("openclaw", ["--version"], {
quiet: true,
env: { ...process.env, PATH: `${npmGlobalBin}:${process.env.PATH}` },
});
return result.stdout.trim();
}

/** Run openclaw doctor. Returns exit code 0 on success. */
export async function doctor(): Promise<{ exitCode: number; stdout: string; stderr: string }> {
return exec("openclaw", ["doctor"], { quiet: true });
Expand Down
49 changes: 49 additions & 0 deletions tasks/2026-03-16_1833_dead-code-cleanup/TASK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Dead code & misplaced code cleanup

## Status: Resolved

## Scope

Remove dead exports, unused hook return values, unnecessary dynamic imports,
and stale documentation references found during a codebase audit. All items
are minor hygiene — no behavioral changes.

Does NOT cover: any functional changes, new features, or refactoring beyond
the identified dead code.

## Plan

1. Delete `formatZodError` and `expandTilde` from `host-core/src/config.ts` and barrel
2. Delete `openclaw.version()` from `vm-cli/src/tools/openclaw.ts`
3. Remove `clear` from `useProcessLogs` hook and its test
4. Remove `toggle` from `useVerboseMode` hook
5. Remove `driver` prop from `Finish` component and its usage in `app.tsx`
6. Remove unnecessary `updatedCreds` copy in `CredentialSetup`
7. Convert dynamic imports to static imports in `create.ts`
8. Fix stale `tools/types.ts` references in docs
9. Verify: tests pass, lint clean, format clean

## Steps

- [x] Items 1-8 implementation
- [x] `bun test` passes (264 pass, 10 skip, 0 fail)
- [x] `bun run lint` clean
- [x] `bun run format:check` clean
- [x] Grep verification for removed symbols

## Notes

## Outcome

All 8 items delivered as planned:

1. Deleted `formatZodError` + `expandTilde` from host-core (duplicates of types package)
2. Deleted `openclaw.version()` from vm-cli (unused)
3. Removed `clear` from `useProcessLogs` hook + its test
4. Removed `toggle` from `useVerboseMode` hook
5. Removed `driver` prop from `Finish` component
6. Simplified `CredentialSetup` — removed unnecessary `updatedCreds` copy
7. Converted 3 dynamic imports to static imports in `create.ts`
8. Removed stale `tools/types.ts` references from `vm-cli.md` and `architecture.md`

No behavioral changes. All tests pass, lint/format clean.
Loading