mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-17 05:22:17 +00:00
fix(opencode): address round-2 review findings on the hooks surface
- R2-1: the V2 execute.after adapter passed { result: ... } as the tool
output; skill-run-tracker derives outcomes from error fields on the
response itself, so failed skills recorded as successes. The adapter
now forwards the raw event.result ?? event.output. Covered by a T05
assertion that an is_error skill event records outcome failure and a
clean event still records success.
- R2-2: cmd.exe expands %VAR% and honors embedded quotes even inside
double quotes, so escaping " was unsafe. spawnCommand now refuses
arguments carrying ", %, CR or LF (nothing spawns; the rejection
surfaces through the formatter's catch) and emits the canonical /s
form with one outer quote pair around the whole command. T01 asserts
the outer pair, strips it before inspecting the inner quoting, and
covers two refusal payloads.
- R2-3: repo review rules ban console.log; the client-less log fallback
and the startup line now use console.info (identical stdout behavior).
- R2-4: declined installs recorded before the barrel split retained the
old module/factory stub in plugins/index.ts, and a later selective
install (e.g. commands-core) has no operation rewriting it, so the
strict deactivation gate failed the install after all writes landed.
The strict branch now migrates such retained files in place only when
ownership is proven twice (managed-recorded contentSha256 matches disk
AND disk equals an exact historical disabled-stub payload), written
through writeFileNoFollow with that digest as expectedContent;
anything else keeps failing closed. The preflight branch accepts an
already-inactive recorded config under the same digest-verified
condition, since selective installs legitimately plan no .opencode
writes. New lifecycle test covers both the migration (install ok,
doctor clean, ownership retained) and the refusal path (mis-recorded
digest never grants a rewrite).
This commit is contained in:
1 parent
6286b7c2f1
commit
76f8ea4bd3
5 files changed
+234
-10
No files matched your search
@@ -183,11 +183,27 @@ function spawnCommand(
|
||||
process.platform === "win32" &&
|
||||
/^(npx|npm|pnpm|yarn|bun)(\.cmd)?$/i.test(command)
|
||||
) {
|
||||
// R2-2: cmd.exe expands %VAR% and honours embedded quotes even inside
|
||||
// "double quotes", so backslash-escaping a quote here is not safe. Reject
|
||||
// any argument carrying a quote, percent sign, or line break outright
|
||||
// (line breaks would also terminate the /c command string). Legitimate
|
||||
// package-manager invocations never need these characters; callers already
|
||||
// surface the rejection through run()'s rejection path.
|
||||
const unsafe = args.find((value) => /["%\r\n]/.test(value))
|
||||
if (unsafe !== undefined) {
|
||||
throw new Error(
|
||||
`Refusing to launch package-manager shim with unsafe argument: ${JSON.stringify(unsafe)}`,
|
||||
)
|
||||
}
|
||||
const shim = `${command.replace(/\.cmd$/i, "")}.cmd`
|
||||
const quote = (value: string) => `"${value.replace(/"/g, '\\"')}"`
|
||||
const quote = (value: string) => `"${value}"`
|
||||
// Canonical `/s` form: wrap the whole command string in one outer pair of
|
||||
// quotes. cmd strips exactly that outer pair and executes the remainder
|
||||
// verbatim, so the quoted shim path resolves instead of being re-split.
|
||||
const inner = [shim, ...args].map(quote).join(" ")
|
||||
return {
|
||||
file: process.env.ComSpec || "cmd.exe",
|
||||
spawnArgs: ["/d", "/s", "/c", [shim, ...args].map(quote).join(" ")],
|
||||
spawnArgs: ["/d", "/s", "/c", `"${inner}"`],
|
||||
verbatim: true,
|
||||
}
|
||||
}
|
||||
@@ -366,7 +382,7 @@ async function createEccRuntime(input: {
|
||||
if (level === "error") console.error(line)
|
||||
else if (level === "warn") console.warn(line)
|
||||
else if (level === "debug") console.debug(line)
|
||||
else console.log(line)
|
||||
else console.info(line)
|
||||
} catch {
|
||||
// Logging must never break a hook.
|
||||
}
|
||||
@@ -1025,7 +1041,11 @@ export const ECCHooksPluginDefinition = {
|
||||
registrations.push(await ctx.tool.hook("execute.before", safe("execute.before", (event: LooseRecord) => hooks["tool.execute.before"](toToolInput(event), {}))))
|
||||
registrations.push(
|
||||
await ctx.tool.hook("execute.after", safe("execute.after", (event: LooseRecord) =>
|
||||
hooks["tool.execute.after"](toToolInput(event), { result: event.result ?? event.output }),
|
||||
// R2-1: hand the shared handler the tool output object directly. The
|
||||
// skill tracker reads error fields (isError/is_error/status/error) off
|
||||
// `tool_response` itself; a `{ result: … }` wrapper made failed skill
|
||||
// runs look like successes.
|
||||
hooks["tool.execute.after"](toToolInput(event), event.result ?? event.output),
|
||||
)),
|
||||
)
|
||||
}
|
||||
@@ -1208,7 +1228,7 @@ async function disposeRegistrations(
|
||||
|
||||
function logStartup(directory: string) {
|
||||
// Mirrors the V1 startup line used in server-log triage (TROUBLESHOOTING.md).
|
||||
console.log(`[ecc] hooks plugin v${getECCVersion(findEccRootDir(PLUGIN_DIR, ECC_ROOT_PROBES.root))} loaded (directory=${directory})`)
|
||||
console.info(`[ecc] hooks plugin v${getECCVersion(findEccRootDir(PLUGIN_DIR, ECC_ROOT_PROBES.root))} loaded (directory=${directory})`)
|
||||
}
|
||||
|
||||
export default ECCHooksPluginDefinition
|
||||
Reference in new issue
Block a user