Skip to content

hassan-mohiddin/freeflow / .deprecated/skill-tooling-pre-rewrite/skills/evaluate-skill

evaluate-skill

Verified

Use when evaluating, comparing, or making readiness claims about agent-skill behavior.

scripts/lib/process.mjs

View on GitHub
import { spawn } from "node:child_process";
import { StringDecoder } from "node:string_decoder";
import { DEFAULT_OUTPUT_LIMIT_BYTES } from "./constants.mjs";

export function runProcess(
  command,
  args,
  {
    cwd,
    env,
    timeoutMs = 180000,
    outputLimitBytes = DEFAULT_OUTPUT_LIMIT_BYTES,
    transportLimitBytes = outputLimitBytes,
    stdoutLineTransform,
    signal,
  } = {},
) {
  return new Promise((resolve, reject) => {
    const startedAt = new Date();
    const child = spawn(command, args, {
      cwd,
      env,
      stdio: ["ignore", "pipe", "pipe"],
      detached: process.platform !== "win32",
    });
    const stdout = [];
    const stderr = [];
    const decoder = stdoutLineTransform ? new StringDecoder("utf8") : null;
    let pendingLine = "";
    let transportBytes = 0;
    let retainedOutputBytes = 0;
    let timedOut = false;
    let outputLimitExceeded = false;
    let transportLimitExceeded = false;
    let transformError = null;

    function terminate() {
      if (!child.pid) return;
      try {
        if (process.platform !== "win32") process.kill(-child.pid, "SIGKILL");
        else child.kill("SIGKILL");
      } catch {
        child.kill("SIGKILL");
      }
    }

    function retain(target, value) {
      const buffer = Buffer.isBuffer(value) ? value : Buffer.from(value);
      if (retainedOutputBytes + buffer.length > outputLimitBytes) {
        outputLimitExceeded = true;
        terminate();
        return false;
      }
      target.push(buffer);
      retainedOutputBytes += buffer.length;
      return true;
    }

    function observeTransport(chunk) {
      transportBytes += Buffer.byteLength(chunk);
      if (transportBytes > transportLimitBytes) {
        transportLimitExceeded = true;
        terminate();
        return false;
      }
      return true;
    }

    function transformLine(line, terminated = true) {
      if (transformError || outputLimitExceeded || transportLimitExceeded) return;
      try {
        const transformed = stdoutLineTransform(line, { terminated });
        if (transformed === null || transformed === undefined) return;
        retain(stdout, `${transformed}${terminated ? "\n" : ""}`);
      } catch (error) {
        transformError = error;
        terminate();
      }
    }

    child.stdout.on("data", (chunk) => {
      if (!observeTransport(chunk)) return;
      if (!stdoutLineTransform) {
        retain(stdout, chunk);
        return;
      }
      pendingLine += decoder.write(chunk);
      for (;;) {
        const newline = pendingLine.indexOf("\n");
        if (newline < 0) break;
        const line = pendingLine.slice(0, newline).replace(/\r$/, "");
        pendingLine = pendingLine.slice(newline + 1);
        transformLine(line);
      }
    });
    child.stderr.on("data", (chunk) => {
      if (!observeTransport(chunk)) return;
      retain(stderr, chunk);
    });
    child.on("error", reject);

    const timer = setTimeout(() => {
      timedOut = true;
      terminate();
    }, timeoutMs);
    timer.unref?.();

    const onAbort = () => terminate();
    signal?.addEventListener("abort", onAbort, { once: true });

    child.on("close", (code, exitSignal) => {
      clearTimeout(timer);
      signal?.removeEventListener("abort", onAbort);
      if (stdoutLineTransform && !outputLimitExceeded) {
        pendingLine += decoder.end();
        if (pendingLine.length > 0) transformLine(pendingLine, false);
      }
      if (transformError) {
        reject(transformError);
        return;
      }
      const endedAt = new Date();
      resolve({
        command,
        args,
        code,
        signal: exitSignal,
        timed_out: timedOut,
        output_limit_exceeded: outputLimitExceeded,
        transport_limit_exceeded: transportLimitExceeded,
        transport_bytes: transportBytes,
        retained_output_bytes: retainedOutputBytes,
        aborted: Boolean(signal?.aborted),
        stdout: Buffer.concat(stdout).toString("utf8"),
        stderr: Buffer.concat(stderr).toString("utf8"),
        started_at: startedAt.toISOString(),
        ended_at: endedAt.toISOString(),
        duration_ms: endedAt.getTime() - startedAt.getTime(),
      });
    });
  });
}
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall