Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ jobs:
- name: Test runtime publication contracts with offline command stubs
run: python3 -m unittest discover -s scripts/runtime-image -p 'test_*.py' -v

- name: Test the Decisions judge against an offline API stub
run: python3 -m unittest discover -s docker/clawscan-runtime/tests -p 'test_decisions_judge.py' -v

test:
name: ${{ matrix.check_name }}
runs-on: ${{ matrix.os }}
Expand Down
15 changes: 13 additions & 2 deletions .github/workflows/judge-inspection-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ jobs:
with:
node-version: 24.22.1

- name: Build ClawScan and install pinned judge harness
- name: Build ClawScan and install the judge and pinned overview harness
run: |
go build -o ./dist/clawscan ./cmd/clawscan
ln -sf "$PWD/docker/clawscan-runtime/judges/clawscan_decisions_judge.py" ./dist/clawscan-decisions-judge
echo "$PWD/dist" >> "$GITHUB_PATH"
npm install -g @openai/codex@0.164.0
codex --version

Expand Down Expand Up @@ -79,9 +81,18 @@ jobs:
], cwd=root, env=env, check=True, timeout=240)
artifact = json.loads(report.read_text())
judge = artifact.get("judge", {})
print(json.dumps({"status": judge.get("status"), "error": judge.get("error")}))
overview = artifact.get("overview") or {}
decision = (judge.get("result") or {}).get("decision") or {}
print(json.dumps({
"judge": judge.get("status"), "error": judge.get("error"),
"verdict": (judge.get("result") or {}).get("verdict"),
"model": decision.get("model"), "latencyMs": decision.get("latencyMs"),
"overview": overview.get("status"), "overviewError": overview.get("error"),
}))
assert judge.get("status") == "completed", "Judge did not complete"
assert judge["result"]["verdict"] in ("benign", "suspicious", "malicious")
assert overview.get("status") == "completed", "Overview did not complete"
assert overview["result"]["summary"], "Overview has no summary"

- name: Retain redacted CLI report
if: always()
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/runtime-image-production-contract.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ permissions:

jobs:
native:
name: Qualify locked production SDKs (e9bfb7e)
name: Qualify locked production SDKs (3583a66)
if: github.event_name == 'pull_request'
runs-on: ubuntu-22.04
timeout-minutes: 25
Expand All @@ -24,7 +24,7 @@ jobs:
- name: Checkout exact reviewed candidate
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: e9bfb7e7409cb2b7a422a8064780289c7d94c07a
ref: 3583a66933fb198cf231a78b1853cf0f3ee22019
fetch-depth: 2
path: candidate
persist-credentials: false
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: production-scanner-contract-e9bfb7e
name: production-scanner-contract-3583a66
path: |
${{ runner.temp }}/clawscan-production-contract/inputs.json
${{ runner.temp }}/clawscan-production-contract/result.json
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules/
*.tgz
.DS_Store
.artifacts/
__pycache__/
3 changes: 3 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ separate commands, but do not add ClawHub-specific flags to `cmd/clawscan`.
in the judge command; a failed judge command keeps its own error.
- Judge placeholders and prompt interpolation must fail clearly when they
reference a scanner that was not requested.
- The optional overview step is advisory prose about a completed verdict. Its
failure, timeout, or output never changes the verdict, gate, run status,
completeness, or exit status.
- When a judge is configured, usable partial SkillSpector reports may reach the
independent judge with `status: partial` and `reportPolicy: judge-gaps`.
Preserve raw partial status, findings, gaps, and provenance. The judge
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- **Breaking:** the `clawhub` and `clawhub-aig` profiles take their verdict from the OpenAI Decisions API (`gpt-6-luna`) through the new `clawscan-decisions-judge` command in the runtime image, and add a Codex `gpt-6-luna` low-effort overview step for readable prose. `judge.result` now holds typed fields only: `verdict`, `confidence`, `dimensions.<name>.status`/`.confidence`, `scan_findings_in_context[]` (`ruleId`, `scanner`, `expected_for_purpose`, `probability`), and a new `decision` object with the model, usage, latency, verdict probabilities, and risk-signal probabilities. `summary`, dimension `detail`, finding `note`, and `user_guidance` move to the new top-level `overview.result`. Refusals, HTTP errors, and oversized input fail the judge with the real error.
- Add an optional, pluggable profile `overview.command` (`--overview <cmd>`, `--no-overview`). It runs after a completed verdict with the judge workspace plus `judge.json` and the `{{ judge.result }}` prompt placeholder, records `overview` in the run artifact, and never changes the verdict, gate, status, completeness, or exit status. Benchmark runs skip the profile overview.
- Run full CodeQL scans daily instead of on every main push, preserve PR and manual analysis, and start scans when draft PRs become ready for review.
- Summarize per-file SkillSpector accounting lists in the ClawHub judge prompt as counts plus a bounded sample. The full report stays in the judge workspace.
- **Breaking:** make the runner judge-agnostic. Remove the artifact-inspection receipt (challenge file, receipt validation, the `{{ artifact_inspection.required_file }}` placeholder, the `artifact_inspection` field in the bundled clawhub prompt and output schema, and the `challenge`, `requiredFile`, and `requiredFileSha256` fields on `judge.attempts`), the runner-level judge prompt budget (`judge prompt too large`), and every profile-name special case. A judge with an input limit enforces it itself; a failed judge command keeps its own error and is never retried. A judge command that exits successfully without a JSON object, including one that never writes `{{ output }}`, is retried once. `judge.attempts` is now recorded for every judge command run, not only for ClawHub profiles.
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,20 @@ clawscan profiles -v

| Profile | Scanners | Judge |
| --- | --- | --- |
| `clawhub` | `skillspector`, `aig` | Codex `gpt-6.1-sol`, high reasoning, Standard service, bundled ClawHub prompt/schema |
| `clawhub-aig` | `skillspector`, `aig` | Codex `gpt-6.1-sol`, high reasoning, Standard service, bundled ClawHub prompt/schema |
| `clawhub` | `skillspector`, `aig` | OpenAI Decisions API `gpt-6-luna` verdict (`clawscan-decisions-judge`), then a Codex `gpt-6-luna` low-effort overview |
| `clawhub-aig` | `skillspector`, `aig` | Same judge and overview as `clawhub` |
| `openclaw-install-policy` | `skillspector` | none |

The two ClawHub profiles explicitly configure the OpenAI scanner lanes with
`scannerEnvDefaults`: SkillSpector uses `SKILLSPECTOR_PROVIDER=openai`,
`SKILLSPECTOR_MODEL=gpt-6.1-sol`, and `SKILLSPECTOR_REASONING_EFFORT=medium`;
A.I.G uses `DEFAULT_MODEL=gpt-6.1-sol` and `REASONING_EFFORT=medium` with OpenAI
credentials. The final Codex judge uses `gpt-6.1-sol`, high reasoning, and default
Standard service (no fast/priority override). Credentials stay in the environment.
credentials. The verdict comes from the OpenAI Decisions API (`gpt-6-luna`)
through `clawscan-decisions-judge`, which returns typed answers only; a separate
Codex overview step (`gpt-6-luna`, low reasoning, Standard service) writes the
readable summary and never changes the verdict. Credentials stay in the
environment. See [judge harness](docs/judge.md#clawhub-decisions-judge) for the
request shape, verdict mapping, and environment variables.

Explicit model/provider/effort environment overrides win. A different
SkillSpector provider retains its own model defaults. A.I.G with a dedicated
Expand Down Expand Up @@ -285,7 +289,9 @@ Supported `--judge` placeholders:
The judge is any command that reads the prompt and writes a JSON object matching
the output schema. ClawScan is judge-agnostic: judge-specific checks, such as an
input-size limit, belong inside the judge command, and a failed judge command
keeps its own error. See [judge harness](docs/judge.md).
keeps its own error. A profile can add an `overview.command` that writes a
readable summary after the verdict; it never changes the verdict or gate. See
[judge harness](docs/judge.md).

## Sandbox

Expand Down
158 changes: 158 additions & 0 deletions cmd/clawscan/compat_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package main

import (
"bytes"
"encoding/json"
"os"
"path/filepath"
"reflect"
"runtime"
"strings"
"testing"

"github.com/openclaw/clawscan/internal/runner"
)

// Data-model compatibility for the Decisions judge and optional overview.
//
// The fixtures under testdata/ were produced by the real binaries at the
// ClawHub production pin (c3cfaf1, legacy artifact-inspection receipt and the
// retired clawscan-static scanner) and at pre-#148 main (fa01a95), each running
// `--profile clawhub --sandbox off` with scanner fixtures and a stub judge that
// writes the legacy prose result. Host paths were scrubbed.
var legacyArtifactFixtures = []string{
"legacy-clawhub-artifact-c3cfaf1.json",
"legacy-clawhub-artifact-fa01a95.json",
}

func TestLegacyStoredArtifactsRemainReadable(t *testing.T) {
for _, name := range legacyArtifactFixtures {
t.Run(name, func(t *testing.T) {
raw, err := os.ReadFile(filepath.Join("testdata", name))
if err != nil {
t.Fatal(err)
}
var original map[string]any
if err := json.Unmarshal(raw, &original); err != nil {
t.Fatal(err)
}
if _, ok := original["overview"]; ok {
t.Fatal("legacy fixture unexpectedly has an overview")
}
var artifact runner.Artifact
if err := json.Unmarshal(raw, &artifact); err != nil {
t.Fatalf("legacy artifact no longer decodes: %v", err)
}
if artifact.Overview != nil {
t.Fatalf("absent overview decoded as %#v", artifact.Overview)
}
if artifact.SchemaVersion != "clawscan-run-v1" || !artifact.Complete || artifact.Gate != "pass" {
t.Fatalf("schema=%q complete=%v gate=%q", artifact.SchemaVersion, artifact.Complete, artifact.Gate)
}
result := judgeResultMap(t, artifact)
for _, field := range []string{"verdict", "summary", "user_guidance", "dimensions"} {
if _, ok := result[field]; !ok {
t.Fatalf("legacy judge.result lost %q: %#v", field, result)
}
}

// The CLI summary still reads the legacy verdict and prints no
// overview lines for an artifact without one.
var summary bytes.Buffer
printRunSummary(&summary, runner.RunTargetsResult{Single: &artifact}, "")
for _, want := range []string{"judge_completed: 1", "clean: 1", "gate: pass"} {
if !strings.Contains(summary.String(), want) {
t.Fatalf("summary missing %q:\n%s", want, summary.String())
}
}
if strings.Contains(summary.String(), "overview") {
t.Fatalf("summary invented an overview:\n%s", summary.String())
}

// Re-encoding keeps the absent overview absent and the stored
// judge result unchanged.
encoded, err := json.Marshal(artifact)
if err != nil {
t.Fatal(err)
}
var roundTrip map[string]any
if err := json.Unmarshal(encoded, &roundTrip); err != nil {
t.Fatal(err)
}
if _, ok := roundTrip["overview"]; ok {
t.Fatal("re-encoded legacy artifact gained an overview key")
}
originalJudge := original["judge"].(map[string]any)
roundJudge := roundTrip["judge"].(map[string]any)
if !reflect.DeepEqual(originalJudge["result"], roundJudge["result"]) {
t.Fatalf("legacy judge.result changed on re-encode:\n%v\n%v", originalJudge["result"], roundJudge["result"])
}
if originalJudge["status"] != roundJudge["status"] {
t.Fatalf("judge status changed: %v -> %v", originalJudge["status"], roundJudge["status"])
}
})
}
}

// A project config written before the overview step, here the exact
// pre-#148 clawhub profile with its Codex judge, prompt, and output schema,
// still resolves and runs unchanged: no overview runs or appears in the
// artifact, and the judge's prose result is recorded as before.
func TestPreOverviewProfileConfigRunsUnchanged(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("the stub codex judge is a POSIX shell script")
}
dir := t.TempDir()
configDir := filepath.Join(dir, "security")
if err := os.MkdirAll(configDir, 0o755); err != nil {
t.Fatal(err)
}
for source, dest := range map[string]string{
filepath.Join("..", "..", "schemas", "testdata", "clawhub-profile-fa01a95.yml"): "clawscan.yml",
filepath.Join("testdata", "legacy-clawhub-prompt-fa01a95.md"): "prompt.md",
filepath.Join("testdata", "legacy-clawhub-output-fa01a95.schema.json"): "output.schema.json",
} {
data, err := os.ReadFile(source)
if err != nil {
t.Fatal(err)
}
writeFile(t, filepath.Join(configDir, dest), string(data))
}
target := filepath.Join(dir, "skill")
writeSkill(t, target, "# Notes\nAppend notes to ./notes.md.\n")
aigFixture := filepath.Join(dir, "aig.json")
writeFile(t, aigFixture, `{"version":"2.1.0","runs":[{"results":[]}]}`)
const legacyResult = `{"verdict":"benign","confidence":"high","summary":"Legacy prose summary.","dimensions":{"purpose_capability":{"status":"ok","detail":"d"},"instruction_scope":{"status":"ok","detail":"d"},"install_mechanism":{"status":"ok","detail":"d"},"environment_proportionality":{"status":"ok","detail":"d"},"persistence_privilege":{"status":"ok","detail":"d"}},"scan_findings_in_context":[],"user_guidance":"Legacy guidance."}`

var runErr error
stdout := captureStdout(t, func() {
runErr = run([]string{
target, "--config", filepath.Join(configDir, "clawscan.yml"), "--profile", "clawhub",
"--scanner-result", "aig=" + aigFixture, "--sandbox", "off", "--json",
}, append(os.Environ(), "CLAWSCAN_TEST_OVERVIEW_JSON="+legacyResult, "OPENAI_API_KEY=legacy-fixture-key"))
})
if runErr != nil {
t.Fatalf("pre-overview profile config failed: %v\n%s", runErr, stdout)
}
var generic map[string]any
if err := json.Unmarshal([]byte(stdout), &generic); err != nil {
t.Fatal(err)
}
if _, ok := generic["overview"]; ok {
t.Fatal("a profile without overview.command produced an overview")
}
var artifact runner.Artifact
if err := json.Unmarshal([]byte(stdout), &artifact); err != nil {
t.Fatal(err)
}
if !artifact.Complete || artifact.Status != "completed" || artifact.ConfigSource == nil || *artifact.ConfigSource == "built-in" {
t.Fatalf("status=%q complete=%v config=%v", artifact.Status, artifact.Complete, artifact.ConfigSource)
}
result := judgeResultMap(t, artifact)
if result["summary"] != "Legacy prose summary." || result["user_guidance"] != "Legacy guidance." {
t.Fatalf("legacy Codex judge result changed: %#v", result)
}
if artifact.Judge.ConfiguredModel != "gpt-6.1-sol" {
t.Fatalf("legacy Codex judge provenance = %q", artifact.Judge.ConfiguredModel)
}
}
Loading
Loading