@@ -10,6 +10,7 @@ import (
1010 "os"
1111 "os/exec"
1212 "path/filepath"
13+ "regexp"
1314 "strings"
1415
1516 "github.com/openclaw/clawscan/internal/clawhubprompt"
@@ -42,10 +43,12 @@ func run() error {
4243 if err != nil {
4344 return err
4445 }
45- systemPrompt , expected , err := renderClawHubPrompt (resolvedClawHubDir )
46+ rendered , err := renderClawHubPrompt (resolvedClawHubDir )
4647 if err != nil {
4748 return err
4849 }
50+ systemPrompt := rendered .SystemPrompt
51+ expected := rendered .Prompt
4952 job := proofJob ()
5053 skillSpectorAnalysis := proofSkillSpectorAnalysis ()
5154 actual , err := clawhubprompt .Build (systemPrompt , job , []string {"html-comment-injection" }, skillSpectorAnalysis )
@@ -71,10 +74,7 @@ func run() error {
7174 if err != nil {
7275 return err
7376 }
74- schema , err := os .ReadFile (filepath .Join (resolvedClawHubDir , "scripts/security/codex-scan-output.schema.json" ))
75- if err != nil {
76- return err
77- }
77+ schema := rendered .OutputSchema
7878 requestBody , err := runner .OpenAIRequestBody (runner.OpenAIRequestOptions {Model : * model , Reasoning : * reasoning }, systemPrompt , prompt , schema )
7979 if err != nil {
8080 return err
@@ -179,7 +179,22 @@ func resolveClawHubDir(path string) (string, error) {
179179 return filepath .Abs (path )
180180}
181181
182- func renderClawHubPrompt (clawhubDir string ) (string , string , error ) {
182+ type clawHubPromptRender struct {
183+ SystemPrompt string
184+ Prompt string
185+ OutputSchema []byte
186+ }
187+
188+ var (
189+ workerSchemaPathPattern = regexp .MustCompile (`(?m)^\s*const\s+schemaPath\s*=\s*join\(\s*root\s*,\s*"([^"]+)"\s*\)` )
190+ workerOutputSchemaArgPattern = regexp .MustCompile (`(?s)"--output-schema"\s*,\s*schemaPath` )
191+ )
192+
193+ func renderClawHubPrompt (clawhubDir string ) (clawHubPromptRender , error ) {
194+ outputSchema , err := readClawHubWorkerOutputSchema (clawhubDir )
195+ if err != nil {
196+ return clawHubPromptRender {}, err
197+ }
183198 script := `
184199const clawhubDir = process.argv[1];
185200const worker = await import(clawhubDir + "/scripts/security/run-codex-scan-worker.ts");
@@ -222,16 +237,40 @@ console.log(JSON.stringify({
222237 cmd .Stderr = & stderr
223238 out , err := cmd .Output ()
224239 if err != nil {
225- return "" , "" , fmt .Errorf ("render ClawHub prompt with bun: %w: %s" , err , stderr .String ())
240+ return clawHubPromptRender {} , fmt .Errorf ("render ClawHub prompt with bun: %w: %s" , err , stderr .String ())
226241 }
227242 var payload struct {
228243 SystemPrompt string `json:"systemPrompt"`
229244 Prompt string `json:"prompt"`
230245 }
231246 if err := json .Unmarshal (out , & payload ); err != nil {
232- return "" , "" , err
247+ return clawHubPromptRender {}, err
248+ }
249+ return clawHubPromptRender {SystemPrompt : payload .SystemPrompt , Prompt : payload .Prompt , OutputSchema : outputSchema }, nil
250+ }
251+
252+ func readClawHubWorkerOutputSchema (clawhubDir string ) ([]byte , error ) {
253+ workerPath := filepath .Join (clawhubDir , "scripts/security/run-codex-scan-worker.ts" )
254+ workerSource , err := os .ReadFile (workerPath )
255+ if err != nil {
256+ return nil , err
257+ }
258+ schemaRelPath , err := clawHubWorkerOutputSchemaRelPath (string (workerSource ))
259+ if err != nil {
260+ return nil , fmt .Errorf ("resolve ClawHub worker output schema: %w" , err )
261+ }
262+ return os .ReadFile (filepath .Join (clawhubDir , filepath .FromSlash (schemaRelPath )))
263+ }
264+
265+ func clawHubWorkerOutputSchemaRelPath (workerSource string ) (string , error ) {
266+ if ! workerOutputSchemaArgPattern .MatchString (workerSource ) {
267+ return "" , fmt .Errorf ("worker no longer passes schemaPath to --output-schema" )
268+ }
269+ matches := workerSchemaPathPattern .FindStringSubmatch (workerSource )
270+ if matches == nil {
271+ return "" , fmt .Errorf ("worker schemaPath declaration not found" )
233272 }
234- return payload . SystemPrompt , payload . Prompt , nil
273+ return matches [ 1 ] , nil
235274}
236275
237276func proofJob () clawhubprompt.Job {
0 commit comments