Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
chore(semgrep): justify the #5195/#5184/#5311 child-process and path findings
garrytan5ddfb12f004a
diff --git a/scripts/module-size-limits.tsv b/scripts/module-size-limits.tsvindex b18fac1907..2ea539adb5 100644--- a/scripts/module-size-limits.tsv+++ b/scripts/module-size-limits.tsv@@ -4,7 +4,7 @@# the same commit as any peel (the guard fails on >50 lines of stale slack).# Columns: path max_lines policy notesrc/cli.ts 3162 ratchet +2 fix wave 5 (#5401): projections drain help line and thin-client hint; +2 (#5137) key-shadow warning seam, logic in ai/key-warnings.ts; +2 System One v1: decide help line + thin-client refusal hint; refactor wave 1 split target (W4 cli); ceiling rationale: docs/architecture/key-files/entrypoints-and-docs.md entry for src/cli.ts; evidence delivery: thin-client return_unit version-skew warning (+3; logic in search/evidence-delivery.ts); put stdin recovery (#5700): stdin hint in the --content requires-a-value error and stdin usage/required text in printOpHelp (+7); logic in persistence/deactivation.ts)-src/commands/autopilot.ts 1633 ratchet refactor wave 1 split target (W4 autopilot, cut line); ceiling rationale: docs/architecture/key-files/commands-1.md entry for src/commands/autopilot.ts+src/commands/autopilot.ts 1635 ratchet refactor wave 1 split target (W4 autopilot, cut line); ceiling rationale: docs/architecture/key-files/commands-1.md entry for src/commands/autopilot.ts; +2 fix wave 5: nosemgrep justifications on the per-brain job launchctl/systemctl calls (#5195)src/commands/doctor.ts 653 ratchet refactor wave 1 split target (W4 doctor); ceiling rationale: docs/architecture/key-files/commands-2.md entry for src/commands/doctor.tssrc/commands/embed.ts 2187 ratchet lowered v0.46.26.0: embedBatchWithBackoff + retry cluster peeled to core/embed-retry.ts (core/commands layering fix); grown wave-g (#4530): per-model input-limit wiring; wave-k #3622 reimpl: --stale zero-progress failure quarantine; +29 #4668 (#4530): oversize-heal call sites in both --stale drains — kept low by peeling the healed-row remap to core/embed-oversize-heal.ts (shared with embed-stale.ts); +35 #4647 (refs #4599): per-tick timeout+abort on the single-flight lock heartbeat refresh (interval deliberately NOT unref'd); +122 refs #4599: stall-watchdog race around the drain + shared idempotent flushAndRelease + CLI stall exit mapping (watchdog machinery itself lives in core/embed-stall.ts); +12: adversarial-review hardening (healed_splits progress key + heal-tick comment); #5105: guarded derived projection preparation and read seals; #5105: conditional embedding installer wiring; archived eligibility: active-only dispatch with honest stranded-work reporting; explicit archived admission: live-source snapshots and honest refused-installation failures; +2 fw3: embed --stale --images dispatch (sweep lives in core/embed-stale-images.ts); +5 #5289: dry run reports restamp-only chunks apart from chunks to embed (count lives in core/embedding-invalidation.ts); +6 #4616: keep a partially refused batch in embedPageTexts and name the recovery command in failure samples (guard lives in core/ai/embedding-guard.ts); +5 #5226: embed summary counts distinct pagessrc/commands/extract-conversation-facts.ts 2146 ratchet grown v0.46.x per-provider gateway-unavailable copy; grown wave-g (#4482): expected budget/deadline caps classified apart from error halts; wave-k: save-time resolution caller (#4052/#3729 — supersedes wave-g's per-row resolveEntitySlug mapper); +1: key-aware llm-fallback default (#3813); +1: pricingOverrides wiring into the owned BudgetTracker (#4633 adoption); +3: #4869 snapshot-mismatch counts as pages_failed; merged reliability/shared-skills source integration; +19: additive skip reasons and model-free dry-run (#5364); +21 #5757: managed extraction buffers a page's rows and replaces the prior batch in one coordinator transaction (replacement helper lives in core/persistence/derived-facts.ts)diff --git a/src/commands/autopilot.ts b/src/commands/autopilot.tsindex b7c7e29f26..8db039b649 100644--- a/src/commands/autopilot.ts+++ b/src/commands/autopilot.ts@@ -1048,7 +1048,9 @@ function installLaunchd(wrapperPath: string, home: string, repoPath: string, job// running daemon must be relaunched anyway to pick up a regenerated// wrapper / env file (#2608: the boot warning tells users to re-run// --install to reload; this line is what makes that true on macOS).+ // nosemgrep: javascript.lang.security.detect-child-process.detect-child-process -- launchdLabel comes from autopilotLaunchdLabel(), which rejects anything outside [A-Za-z0-9._-] and '..'; trusted local CLI onlyexecSync(`launchctl unload "${plistPath(job.launchdLabel)}" 2>/dev/null || true`, { stdio: 'pipe' });+ // nosemgrep: javascript.lang.security.detect-child-process.detect-child-process -- same grammar-checked labelexecSync(`launchctl load "${plistPath(job.launchdLabel)}"`, { stdio: 'pipe' });console.log(`Installed launchd service: ${job.launchdLabel}`);console.log(` Repo: ${repoPath}`);@@ -1167,6 +1169,7 @@ function installSystemd(wrapperPath: string, repoPath: string, job: AutopilotJob// world-writable units); mode only applies on create, so normalize.chmodSync(unitPath, 0o644);execSync('systemctl --user daemon-reload', { stdio: 'pipe', timeout: 10_000 });+ // nosemgrep: javascript.lang.security.detect-child-process.detect-child-process -- systemdUnit is a constant or gbrain-autopilot-<8 hex chars>.service from the install id; trusted local CLI onlyexecSync(`systemctl --user enable --now ${job.systemdUnit}`, { stdio: 'pipe', timeout: 15_000 });// enable --now does NOT restart an already-active unit, so a reinstall// over a running daemon would keep the old process (and its stale env)@@ -1174,6 +1177,7 @@ function installSystemd(wrapperPath: string, repoPath: string, job: AutopilotJob// --install to reload; this line is what makes that true on systemd).// try-restart only bounces a running unit — a fresh install just started// above is restarted at worst, never left stopped.+ // nosemgrep: javascript.lang.security.detect-child-process.detect-child-process -- same derived unit nameexecSync(`systemctl --user try-restart ${job.systemdUnit}`, { stdio: 'pipe', timeout: 15_000 });console.log(`Installed systemd user service: ${job.systemdUnit}`);console.log(` Repo: ${repoPath}`);@@ -1194,6 +1198,7 @@ function installEphemeralContainer(job: AutopilotJob,) {// Write a start script the agent's bootstrap can source on every container start.+ // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal -- homeDir is configDir() of the local operator's own brainconst pidPath = join(job.homeDir, 'autopilot.pid');const script = `#!/bin/bash# Auto-generated by gbrain autopilot --install (ephemeral-container target)@@ -1291,6 +1296,7 @@ function installCrontab(wrapperPath: string, home: string, job: AutopilotJob) {return;}// Use a temp file instead of echo pipe to avoid shell escaping issues (#1)+ // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal -- homeDir is configDir() of the local operator's own brainconst tmpFile = join(job.homeDir, 'crontab.tmp');mkdirSync(job.homeDir, { recursive: true });writeFileSync(tmpFile, existing.trimEnd() + '\n' + cronLine + '\n');diff --git a/src/commands/autopilot/jobs.ts b/src/commands/autopilot/jobs.tsindex 7c1500043f..35a9aa18ec 100644--- a/src/commands/autopilot/jobs.ts+++ b/src/commands/autopilot/jobs.ts@@ -18,10 +18,12 @@ import { errorFor } from '../../core/errors.ts';import type { InstallTarget } from '../autopilot.ts';export function plistPath(label: string): string {+ // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal -- label is grammar-checked by autopilotLaunchdLabel(); HOME is the operator's ownreturn join(process.env.HOME || '', 'Library', 'LaunchAgents', `${label}.plist`);}export function systemdUnitPath(unit: string = DEFAULT_AUTOPILOT_SYSTEMD_UNIT): string {+ // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal -- unit is a constant or derived from the hex install idreturn join(process.env.HOME || '', '.config', 'systemd', 'user', unit);}@@ -71,6 +73,7 @@ export function cronLineBelongsToBrain(line: string, job: AutopilotJob): booleanexport function brainCommand(brainHome: string, verb: string): string {const parent = dirname(brainHome);const defaultHome = join(process.env.HOME || '', '.gbrain');+ // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal -- path comparison only, no fs accessreturn resolvePath(brainHome) === resolvePath(defaultHome)? `gbrain autopilot ${verb}`: `GBRAIN_HOME=${shellQuote(parent)} gbrain autopilot ${verb}`;diff --git a/src/commands/migrations/in-process.ts b/src/commands/migrations/in-process.tsindex 6cc64d48e3..50a13e3c47 100644--- a/src/commands/migrations/in-process.ts+++ b/src/commands/migrations/in-process.ts@@ -128,6 +128,7 @@ export function gbrainChildCommand(*/export function runGbrainSubprocess(cmd: string, opts?: { timeoutMs?: number }): string {try {+ // nosemgrep: javascript.lang.security.detect-child-process.detect-child-process -- cmd is a fixed migration subcommand string from the orchestrators; gbrainChildCommand prefixes the running CLI (#5184)const out = execSync(gbrainChildCommand(cmd), {stdio: ['inherit', 'pipe', 'pipe'],timeout: opts?.timeoutMs ?? MIGRATE_ONLY_TIMEOUT_MS,diff --git a/src/commands/upgrade.ts b/src/commands/upgrade.tsindex 0f50adba00..805505d87f 100644--- a/src/commands/upgrade.ts+++ b/src/commands/upgrade.ts@@ -320,6 +320,7 @@ export function resolveBunGlobalRoot(): string {*/export function bunGlobalExactTagPin(globalRoot: string): string | null {try {+ // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal -- globalRoot is resolveBunGlobalRoot(): Bun's own global install dir from BUN_INSTALL or HOMEconst pkg = JSON.parse(readFileSync(join(globalRoot, 'package.json'), 'utf-8')) as { dependencies?: Record<string, string> };const spec = pkg.dependencies?.gbrain;if (typeof spec !== 'string') return null;diff --git a/src/core/autopilot-paths.ts b/src/core/autopilot-paths.tsindex 4932b4b52d..9e8890f1eb 100644--- a/src/core/autopilot-paths.ts+++ b/src/core/autopilot-paths.ts@@ -76,6 +76,7 @@ export function autopilotLaunchdLabel(suffix: string | null = null): string {/** realpath, or `resolve` for a directory that does not exist yet (ENG-O11). */export function canonicalDir(path: string): string {+ // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal -- canonicalizes the operator's own brain home for the install-id record; no fs writetry { return realpathSync(path); } catch { return resolve(path); }}