mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-22 15:21:17 +00:00
* feat(onboarding): recommend plugins and skills from installed apps Scan installed macOS apps during classic onboarding (TCC-free), gather candidates from official catalogs + ClawHub search, let the configured model pick genuine matches, and offer an opt-in multiselect install step. Adds a device.apps node-host command (default-off sharing, Android-parity envelope) so remote gateways can request a paired Mac's inventory, and a wizard.appRecommendations kill switch. Custom setup-inference completions no longer inherit the 32-token verification-probe output cap. * feat(onboarding): recommend apps in guided flow * fix(onboarding): harden app recommendations against ClawHub self-promotion Third-party ClawHub skills are never pre-selected regardless of model tier (publisher-controlled listing text reaches the matcher prompt and could promote itself); their labels now say they install third-party code. Installed-app scans follow symlinked .app bundles. Matcher output stays bounded by the resolved model's own maxTokens budget (documented invariant). * fix(onboarding): key official catalog candidates by resolved plugin id Real catalog entries are package manifests without a top-level id; keying the candidate map and channel/provider classification by entry.id collapsed the whole official catalog into one undefined-keyed entry, so no official plugin or channel was ever recommended. Regression test runs against the bundled catalogs. * fix(onboarding): satisfy lint, types, deadcode, and migration gates Split the guided-onboarding test into a self-contained custodian suite to stay under max-lines. Narrow app-recommendation exports (drop dead node-payload normalizer, unexport internal types/helpers, route candidate tests through the public API), replace map-spread with a helper, unexport device.apps result types, add installedAppsSharing to node-host migration expectations, cast the wizard multiselect mock, and regenerate the docs map. * test(onboarding): register new live test in the shard classifier
196 lines
6.7 KiB
TypeScript
196 lines
6.7 KiB
TypeScript
import { createExecApprovalPolicySnapshot } from "../infra/exec-approvals.js";
|
|
import type { scanInstalledApps } from "../infra/installed-apps.js";
|
|
import type { OpenClawPluginNodeHostCommandIo } from "../plugins/types.js";
|
|
import type { OpenClawPluginNodeHostCommandContext } from "../plugins/types.node-host.js";
|
|
import type { NodeHostClient } from "./client.js";
|
|
import {
|
|
decodeClaudeCliNodeRunParams,
|
|
type ClaudeCliNodeRunParams,
|
|
type ClaudeCliNodeRunResult,
|
|
} from "./invoke-agent-cli-claude-params.js";
|
|
import { runClaudeCliNodeCommand } from "./invoke-agent-cli-claude.js";
|
|
import {
|
|
buildSystemRunApprovalPlan,
|
|
handleSystemRunInvoke,
|
|
resolveEffectiveSystemRunExecPolicy,
|
|
} from "./invoke-system-run.js";
|
|
import type { NodeInvokeRequestPayload, RunResult, SkillBinsProvider } from "./invoke-types.js";
|
|
|
|
export type NodeHostInvokeRuntime = {
|
|
claudePath?: string;
|
|
handleSystemRun?: typeof handleSystemRunInvoke;
|
|
signal?: AbortSignal;
|
|
pluginCommandIo?: OpenClawPluginNodeHostCommandIo;
|
|
pluginCommandContext?: OpenClawPluginNodeHostCommandContext;
|
|
installedAppsSharingEnabled?: boolean;
|
|
installedAppsPlatform?: NodeJS.Platform;
|
|
scanInstalledApps?: typeof scanInstalledApps;
|
|
};
|
|
|
|
type ClaudeCliNodeInvokeDeps = Pick<
|
|
Parameters<typeof handleSystemRunInvoke>[0],
|
|
| "resolveExecSecurity"
|
|
| "resolveExecAsk"
|
|
| "isCmdExeInvocation"
|
|
| "sanitizeEnv"
|
|
| "runViaMacAppExecHost"
|
|
| "buildExecEventPayload"
|
|
> & {
|
|
sendErrorResult: (
|
|
client: NodeHostClient,
|
|
frame: NodeInvokeRequestPayload,
|
|
code: string,
|
|
message: string,
|
|
) => Promise<void>;
|
|
sendInvalidRequestResult: (
|
|
client: NodeHostClient,
|
|
frame: NodeInvokeRequestPayload,
|
|
error: unknown,
|
|
) => Promise<void>;
|
|
sendInvokeResult: (
|
|
client: NodeHostClient,
|
|
frame: NodeInvokeRequestPayload,
|
|
result: {
|
|
ok: boolean;
|
|
payload?: unknown;
|
|
payloadJSON?: string | null;
|
|
error?: { code?: string; message?: string } | null;
|
|
},
|
|
) => Promise<void>;
|
|
};
|
|
|
|
export async function handleClaudeCliNodeInvoke(params: {
|
|
frame: NodeInvokeRequestPayload;
|
|
client: NodeHostClient;
|
|
skillBins: SkillBinsProvider;
|
|
runtime: NodeHostInvokeRuntime;
|
|
deps: ClaudeCliNodeInvokeDeps;
|
|
}): Promise<void> {
|
|
if (!params.runtime.claudePath) {
|
|
await params.deps.sendErrorResult(
|
|
params.client,
|
|
params.frame,
|
|
"UNAVAILABLE",
|
|
"Claude CLI agent runs are unavailable",
|
|
);
|
|
return;
|
|
}
|
|
const claudePath = params.runtime.claudePath;
|
|
let request: ClaudeCliNodeRunParams;
|
|
try {
|
|
request = await decodeClaudeCliNodeRunParams(params.frame.paramsJSON);
|
|
} catch (error) {
|
|
await params.deps.sendInvalidRequestResult(params.client, params.frame, error);
|
|
return;
|
|
}
|
|
const approvalCommand = [claudePath, ...request.argv];
|
|
const preparedApproval = buildSystemRunApprovalPlan({
|
|
command: approvalCommand,
|
|
...(request.cwd ? { cwd: request.cwd } : {}),
|
|
...(request.agentId ? { agentId: request.agentId } : {}),
|
|
...(request.sessionKey ? { sessionKey: request.sessionKey } : {}),
|
|
});
|
|
if (!preparedApproval.ok) {
|
|
await params.deps.sendErrorResult(
|
|
params.client,
|
|
params.frame,
|
|
"INVALID_REQUEST",
|
|
preparedApproval.message,
|
|
);
|
|
return;
|
|
}
|
|
const { getRuntimeConfig: getNodeRuntimeConfig } = await import("../config/config.js");
|
|
const execPolicy = await resolveEffectiveSystemRunExecPolicy({
|
|
cfg: getNodeRuntimeConfig(),
|
|
agentId: request.agentId,
|
|
defaultSecurity: params.deps.resolveExecSecurity(undefined),
|
|
defaultAsk: params.deps.resolveExecAsk(undefined),
|
|
requireSocket: false,
|
|
});
|
|
const approvalPlan = {
|
|
...preparedApproval.plan,
|
|
policySnapshot: createExecApprovalPolicySnapshot({
|
|
file: execPolicy.approvals.file,
|
|
agentId: request.agentId,
|
|
}),
|
|
};
|
|
let runResult: RunResult | undefined;
|
|
await (params.runtime.handleSystemRun ?? handleSystemRunInvoke)({
|
|
client: params.client,
|
|
// The command-specific validator is the execution boundary. Approval sees
|
|
// every executable argument; prompt/stdin content remains request input.
|
|
params: {
|
|
command: approvalCommand,
|
|
...(request.cwd ? { cwd: request.cwd } : {}),
|
|
...(request.env ? { env: request.env } : {}),
|
|
...(request.agentId ? { agentId: request.agentId } : {}),
|
|
...(request.sessionKey ? { sessionKey: request.sessionKey } : {}),
|
|
...(request.systemRunPlan ? { systemRunPlan: request.systemRunPlan } : {}),
|
|
...(request.approvalDecision ? { approvalDecision: request.approvalDecision } : {}),
|
|
timeoutMs: request.timeoutMs,
|
|
},
|
|
skillBins: params.skillBins,
|
|
execHostEnforced: false,
|
|
execHostFallbackAllowed: true,
|
|
resolveExecSecurity: params.deps.resolveExecSecurity,
|
|
resolveExecAsk: params.deps.resolveExecAsk,
|
|
isCmdExeInvocation: params.deps.isCmdExeInvocation,
|
|
sanitizeEnv: params.deps.sanitizeEnv,
|
|
runCommand: async (approvalArgv, cwd, env, timeoutMs) => {
|
|
runResult = await runClaudeCliNodeCommand({
|
|
client: params.client,
|
|
frame: params.frame,
|
|
request,
|
|
argv: approvalArgv,
|
|
cwd,
|
|
env,
|
|
timeoutMs,
|
|
signal: params.runtime.signal,
|
|
});
|
|
return runResult;
|
|
},
|
|
runViaMacAppExecHost: params.deps.runViaMacAppExecHost,
|
|
// Agent runs already report through the agent-run stream. Suppress the
|
|
// system.run lifecycle side-channel, whose Gateway provenance is scoped
|
|
// exclusively to system.run invokes.
|
|
sendNodeEvent: async () => {},
|
|
buildExecEventPayload: params.deps.buildExecEventPayload,
|
|
sendInvokeResult: async (result) => {
|
|
if (
|
|
!result.ok &&
|
|
!request.approvalDecision &&
|
|
result.error?.message?.includes("approval required")
|
|
) {
|
|
await params.deps.sendInvokeResult(params.client, params.frame, {
|
|
ok: true,
|
|
payloadJSON: JSON.stringify({
|
|
approvalRequired: true,
|
|
systemRunPlan: approvalPlan,
|
|
security: execPolicy.security,
|
|
ask: execPolicy.ask,
|
|
}),
|
|
});
|
|
return;
|
|
}
|
|
if (!result.ok || !runResult) {
|
|
await params.deps.sendInvokeResult(params.client, params.frame, result);
|
|
return;
|
|
}
|
|
const payload: ClaudeCliNodeRunResult = {
|
|
exitCode: runResult.exitCode ?? 1,
|
|
stderrTail: runResult.stderr,
|
|
truncated: runResult.truncated,
|
|
...(runResult.timedOut
|
|
? { timeoutKind: runResult.noOutputTimedOut ? ("idle" as const) : ("hard" as const) }
|
|
: {}),
|
|
};
|
|
await params.deps.sendInvokeResult(params.client, params.frame, {
|
|
ok: true,
|
|
payloadJSON: JSON.stringify(payload),
|
|
});
|
|
},
|
|
sendExecFinishedEvent: async () => {},
|
|
preferMacAppExecHost: false,
|
|
});
|
|
}
|