Skip to content

feat: support local-script targets in opfor hunt#192

Merged
jithin23-kv merged 3 commits into
KeyValueSoftwareSystems:masterfrom
jithin23-kv:feat/hunt-local-script-target
Jul 14, 2026
Merged

feat: support local-script targets in opfor hunt#192
jithin23-kv merged 3 commits into
KeyValueSoftwareSystems:masterfrom
jithin23-kv:feat/hunt-local-script-target

Conversation

@jithin23-kv

@jithin23-kv jithin23-kv commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Problem

opfor hunt (the autonomous commander/operator/scout red-teaming mode) only supported HTTP targets. If a target's chat API couldn't be modeled as a simple request/response HTTP call — e.g. async/polling APIs, session ids embedded in a URL path segment rather than a body/header field (which session.send has no way to express), or auth flows needing custom logic — there was no way to point opfor hunt at it. opfor run already supported type: "local-script" targets for exactly this case; opfor hunt explicitly threw "local-script targets are not supported by opfor hunt (HTTP only).".

Separately, --ui had a bug: it fell back to launching the setup wizard whenever --endpoint was omitted, even when a valid target was already supplied via --target-config (which is how local-script targets are configured, since they have no endpoint).

Solution

  • Added a TargetKind ("http" | "local-script") to the autonomous runner's TargetConfig, plus a scriptPath field.
  • Added createLocalScriptTargetClient(), a TargetClient implementation that shells out to a user script per turn (via the same invokeLocalTargetScript stdin/stdout contract opfor run already uses) instead of making an HTTP request. Hunt's per-thread threadId is passed through as the script's sessionId, so thread forks each get isolated sessions automatically — no extra wiring needed.
  • createTargetClient() now branches on config.type to pick the HTTP or local-script client.
  • Removed the hard throw in mapAgentTargetToAutonomous() and added proper mapping, validation (checks scriptPath instead of endpoint), and name-fallback (script basename instead of URL host) for local-script targets.
  • Fixed --ui's fallback condition to also check !opts.targetConfig, so it only launches the setup wizard when no target was specified at all.
  • Bumped the local-script kill timeout from 30s to 240s (slow/polling-based target scripts were getting killed mid-turn).
  • Fixed local-script error responses not being prefixed with "ERROR:", which meant isTargetError() never actually flagged them as errors (it checks response.startsWith("ERROR:")) — errors from a script were silently treated as normal target replies.

Changes

  • core/src/autonomous/lib/types.tsTargetKind type, type/scriptPath fields on TargetConfig
  • core/src/autonomous/target/http.ts — branch to createLocalScriptTargetClient() in createTargetClient()
  • core/src/autonomous/target/localScript.ts (new) — local-script TargetClient implementation
  • core/src/lib/localScriptTarget.ts — timeout 30s → 240s; error responses now prefixed ERROR:
  • runners/cli/src/commands/hunt.ts — local-script mapping/validation/naming in mapAgentTargetToAutonomous(); --ui fallback condition fix

Issue

N/A

Summary by CodeRabbit

  • New Features

    • Added support for local-script targets in opfor hunt.
    • Local scripts now receive prompts and per-thread session IDs.
    • Configured targets can launch directly into the live dashboard with --ui.
    • Local target scripts support responses up to four minutes.
  • Bug Fixes

    • Improved local-script validation, naming, error reporting, and rate-limit handling.
  • Documentation

    • Added configuration examples and usage guidance for local-script targets.

Extends `opfor hunt` to accept `type: "local-script"` targets (previously
HTTP-only), matching the local-script support already in `opfor run`. Adds
a TargetClient that shells out to a user script per turn instead of making
an HTTP request, threading hunt's per-thread threadId through as the
script's sessionId so thread forks get proper session isolation for free.

Also fixes two related bugs:
- local-script error responses weren't prefixed with "ERROR:", so
  isTargetError() never flagged them as target errors
- --ui fell back to the setup wizard whenever --endpoint was absent,
  even when --target-config supplied a valid local-script target
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 361b266d-197f-466c-9c18-0818af3b07a0

📥 Commits

Reviewing files that changed from the base of the PR and between ad791ef and 403746e.

📒 Files selected for processing (1)
  • core/src/autonomous/target/localScript.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • core/src/autonomous/target/localScript.ts

Walkthrough

The PR adds local-script target configuration and execution, routes these targets through a dedicated client, updates hunt CLI validation and UI behavior, extends local-script timeout and error handling, and documents target configuration and session propagation.

Changes

Local-script target support

Layer / File(s) Summary
Target configuration and client routing
core/src/autonomous/lib/types.ts, core/src/autonomous/target/http.ts
Adds HTTP/local-script target types and routes local-script configurations to a dedicated client.
Local-script invocation and result mapping
core/src/autonomous/target/localScript.ts, core/src/lib/localScriptTarget.ts
Invokes configured scripts with prompts and thread sessions, maps responses and errors, and increases the execution timeout to 240 seconds.
Hunt CLI integration and documentation
runners/cli/src/commands/hunt.ts, docs/hunt.md
Accepts local-script target configuration, validates script paths, adjusts UI setup behavior, derives target names, and documents usage and session handling.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant HuntCLI
  participant createTargetClient
  participant LocalScriptTargetClient
  participant invokeLocalTargetScript
  HuntCLI->>createTargetClient: create client from local-script TargetConfig
  createTargetClient->>LocalScriptTargetClient: construct local-script client
  LocalScriptTargetClient->>invokeLocalTargetScript: send prompt and thread session
  invokeLocalTargetScript-->>LocalScriptTargetClient: return response or error
  LocalScriptTargetClient-->>HuntCLI: return mapped target result
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding local-script target support to opfor hunt.
Description check ✅ Passed The PR description covers Problem, Solution, Changes, and Issue, with only optional How to test and Screenshots sections omitted.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
core/src/autonomous/target/localScript.ts (1)

12-15: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make the error message actionable.

Per coding guidelines, error messages should tell the user how to fix the problem, not just that something failed. The current message says what's missing but not how to set it.

As per coding guidelines: "Write actionable error messages that tell the user how to fix the problem, not just that something failed."

♻️ Proposed fix
-    throw new Error("local-script target is missing `scriptPath`.");
+    throw new Error(
+      "local-script target is missing `scriptPath`. Set `scriptPath` on the target in --target-config (e.g., { \"type\": \"local-script\", \"scriptPath\": \"./adapter.js\" })."
+    );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/src/autonomous/target/localScript.ts` around lines 12 - 15, Update the
missing-scriptPath error in createLocalScriptTargetClient to include actionable
guidance explaining that the caller must set config.scriptPath to the local
script path, while preserving the existing validation behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@core/src/autonomous/target/localScript.ts`:
- Around line 12-15: Update the missing-scriptPath error in
createLocalScriptTargetClient to include actionable guidance explaining that the
caller must set config.scriptPath to the local script path, while preserving the
existing validation behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5fd84311-d2a9-4246-ac9d-1fef8639d89c

📥 Commits

Reviewing files that changed from the base of the PR and between 2ff5624 and 25adc17.

📒 Files selected for processing (5)
  • core/src/autonomous/lib/types.ts
  • core/src/autonomous/target/http.ts
  • core/src/autonomous/target/localScript.ts
  • core/src/lib/localScriptTarget.ts
  • runners/cli/src/commands/hunt.ts

Add hunt.md coverage for the local-script target support added in
this PR — --target-config usage, session/threadId wiring, and the
240s per-turn timeout.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/hunt.md`:
- Around line 29-40: Update the `--endpoint` option description in the options
table to state that the flag is required only when no endpoint is provided by
`--target-config`, while preserving the exception for local-script targets
configured there.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 55966ce6-a433-40dd-b25a-2fc9533ea37f

📥 Commits

Reviewing files that changed from the base of the PR and between 25adc17 and 2ba1ae1.

📒 Files selected for processing (1)
  • docs/hunt.md

Comment thread docs/hunt.md
@jithin23-kv jithin23-kv force-pushed the feat/hunt-local-script-target branch from ad791ef to 403746e Compare July 14, 2026 05:27
@jithin23-kv jithin23-kv merged commit fd2a10f into KeyValueSoftwareSystems:master Jul 14, 2026
8 checks passed
@jithin23-kv jithin23-kv deleted the feat/hunt-local-script-target branch July 14, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants