Skip to content
Open
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
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Convenience targets. The authoritative build commands live in cmd/*/
# (for the Go CLI) and extension/package.json (for the browser extension).

.PHONY: all cli wasm extension extension-dev extension-clean test clean help

help:
@echo "scry — available targets:"
@echo " make cli Build the Go CLI → ./scry"
@echo " make wasm Build the Go WASM bundle into extension/public/"
@echo " make extension Full production build of the Chrome extension"
@echo " make extension-dev Start the CRXJS dev server"
@echo " make test Run Go tests"
@echo " make clean Remove build artefacts"

cli:
go build -o scry .

wasm:
cd extension && bun run build:wasm

extension: wasm
cd extension && bun run build:vite

extension-dev:
cd extension && bun run dev

extension-clean:
rm -rf extension/dist extension/public/scry.wasm extension/public/wasm_exec.js

test:
go test ./core/... ./internal/...

clean: extension-clean
rm -f scry
8 changes: 4 additions & 4 deletions cmd/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (

"github.com/urfave/cli/v3"

"github.com/meysam81/scry/internal/audit"
"github.com/meysam81/scry/core/checks"
"github.com/meysam81/scry/core/model"
"github.com/meysam81/scry/core/rules"
"github.com/meysam81/scry/internal/cmdutil"
"github.com/meysam81/scry/internal/config"
"github.com/meysam81/scry/internal/crawler"
"github.com/meysam81/scry/internal/logger"
"github.com/meysam81/scry/internal/model"
"github.com/meysam81/scry/internal/rules"
)

var (
Expand Down Expand Up @@ -198,7 +198,7 @@ func runSingleCheck(ctx context.Context, cfg *config.Config, fetcher crawler.Fet

// Run audit checks.
l.Info().Msg("running audit checks")
registry := audit.DefaultRegistry(l, cfg.SchemaPath)
registry := checks.DefaultRegistry(l, cfg.SchemaPath)

// Load and register custom CEL rules if configured.
if cfg.RulesFile != "" {
Expand Down
6 changes: 3 additions & 3 deletions cmd/crawl/crawl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (

"github.com/urfave/cli/v3"

"github.com/meysam81/scry/internal/audit"
"github.com/meysam81/scry/core/checks"
"github.com/meysam81/scry/core/rules"
"github.com/meysam81/scry/internal/baseline"
"github.com/meysam81/scry/internal/cmdutil"
"github.com/meysam81/scry/internal/config"
"github.com/meysam81/scry/internal/crawler"
"github.com/meysam81/scry/internal/logger"
"github.com/meysam81/scry/internal/metrics"
"github.com/meysam81/scry/internal/rules"
)

var (
Expand Down Expand Up @@ -256,7 +256,7 @@ func runCrawl(ctx context.Context, cmd *cli.Command) error {

// Run audit checks.
l.Info().Msg("running audit checks")
registry := audit.DefaultRegistry(l, cfg.SchemaPath)
registry := checks.DefaultRegistry(l, cfg.SchemaPath)

// Load and register custom CEL rules if configured.
if cfg.RulesFile != "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/lighthouse/lighthouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (

"github.com/urfave/cli/v3"

"github.com/meysam81/scry/core/model"
"github.com/meysam81/scry/internal/cmdutil"
"github.com/meysam81/scry/internal/config"
lh "github.com/meysam81/scry/internal/lighthouse"
"github.com/meysam81/scry/internal/logger"
"github.com/meysam81/scry/internal/model"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion cmd/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/urfave/cli/v3"

"github.com/meysam81/scry/core/schema"
"github.com/meysam81/scry/internal/logger"
"github.com/meysam81/scry/internal/schema"
)

var flagURL string
Expand Down
91 changes: 91 additions & 0 deletions cmd/wasm/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//go:build js && wasm

// WASM entry point for the scry browser extension. Exposes a narrow,
// JSON-over-string surface that mirrors core/engine so the extension
// calls into the same audit pipeline the CLI uses.
package main

import (
"context"
"encoding/json"
"syscall/js"

"github.com/meysam81/scry/core/engine"
"github.com/meysam81/scry/core/model"
)

var defaultEngine *engine.Engine

func init() {
e, err := engine.New(engine.Options{IncludeDeepStructuredData: true})
if err != nil {
// Fall back to a schema-less engine if the embedded registry is
// somehow corrupt. A degraded audit beats a dead extension.
e, _ = engine.New(engine.Options{IncludeDeepStructuredData: false})
}
defaultEngine = e
}

// resp is the canonical envelope every exported function returns.
// The extension validates { ok, data?, error? } with Zod.
type resp struct {
OK bool `json:"ok"`
Data any `json:"data,omitempty"`
Error any `json:"error,omitempty"`
}

func ok(data any) string {
b, _ := json.Marshal(resp{OK: true, Data: data})
return string(b)
}

func fail(msg string) string {
b, _ := json.Marshal(resp{OK: false, Error: msg})
return string(b)
}

// auditPageInput is the JSON contract with the extension. Body is sent
// separately because model.Page excludes Body from JSON marshaling.
type auditPageInput struct {
Page model.Page `json:"page"`
Body string `json:"body"`
}

func auditPage(_ js.Value, args []js.Value) any {
if len(args) < 1 || args[0].Type() != js.TypeString {
return fail("scryAuditPage expects one string argument (JSON)")
}
var in auditPageInput
if err := json.Unmarshal([]byte(args[0].String()), &in); err != nil {
return fail("invalid input JSON: " + err.Error())
}
if in.Body != "" {
in.Page.Body = []byte(in.Body)
}
issues := defaultEngine.AuditPage(context.Background(), &in.Page)
if issues == nil {
issues = []model.Issue{}
}
return ok(map[string]any{
"issues": issues,
"url": in.Page.URL,
})
}

func listChecks(_ js.Value, _ []js.Value) any {
return ok(map[string]any{"checks": engine.ListAllCheckNames()})
}

func version(_ js.Value, _ []js.Value) any {
return ok(map[string]any{
"engine": "scry-wasm",
"api": 1,
})
}

func main() {
js.Global().Set("scryAuditPage", js.FuncOf(auditPage))
js.Global().Set("scryListChecks", js.FuncOf(listChecks))
js.Global().Set("scryVersion", js.FuncOf(version))
select {}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package audit
package checks

import (
"context"
"fmt"
"strconv"
"strings"

"github.com/meysam81/scry/internal/model"
"github.com/meysam81/scry/core/model"
"golang.org/x/net/html"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package audit
package checks

import (
"context"
"strings"
"testing"

"github.com/meysam81/scry/internal/model"
"github.com/meysam81/scry/core/model"
)

func TestAccessibilityChecker_Name(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package audit
package checks

import (
"context"
Expand All @@ -9,7 +9,7 @@ import (
"sync"
"time"

"github.com/meysam81/scry/internal/model"
"github.com/meysam81/scry/core/model"
"github.com/meysam81/scry/internal/safenet"
"golang.org/x/time/rate"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package audit
package checks

import (
"context"
Expand All @@ -7,7 +7,7 @@ import (
"strings"
"testing"

"github.com/meysam81/scry/internal/model"
"github.com/meysam81/scry/core/model"
)

func TestExternalLinkChecker_Check_ReturnsNil(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions internal/audit/health.go → core/checks/health.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package audit
package checks

import (
"context"
Expand All @@ -8,7 +8,7 @@ import (
"strings"
"time"

"github.com/meysam81/scry/internal/model"
"github.com/meysam81/scry/core/model"
)

var versionRe = regexp.MustCompile(`\d+\.\d+`)
Expand Down
4 changes: 2 additions & 2 deletions internal/audit/health_test.go → core/checks/health_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package audit
package checks

import (
"context"
Expand All @@ -7,7 +7,7 @@ import (
"testing"
"time"

"github.com/meysam81/scry/internal/model"
"github.com/meysam81/scry/core/model"
)

func TestHealthChecker_Check(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions internal/audit/helpers.go → core/checks/helpers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package audit
package checks

import (
"bytes"
Expand All @@ -8,8 +8,8 @@ import (
"sync"
"sync/atomic"

"github.com/meysam81/scry/core/model"
"github.com/meysam81/scry/internal/logger"
"github.com/meysam81/scry/internal/model"
"golang.org/x/net/html"
)

Expand Down
4 changes: 2 additions & 2 deletions internal/audit/hreflang.go → core/checks/hreflang.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package audit
package checks

import (
"context"
"fmt"
"regexp"
"strings"

"github.com/meysam81/scry/internal/model"
"github.com/meysam81/scry/core/model"
"golang.org/x/net/html"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package audit
package checks

import (
"context"
"strings"
"testing"

"github.com/meysam81/scry/internal/model"
"github.com/meysam81/scry/core/model"
)

func hreflangPage(url, body string) *model.Page {
Expand Down
4 changes: 2 additions & 2 deletions internal/audit/images.go → core/checks/images.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package audit
package checks

import (
"context"
Expand All @@ -7,7 +7,7 @@ import (
"strings"
"time"

"github.com/meysam81/scry/internal/model"
"github.com/meysam81/scry/core/model"
"github.com/meysam81/scry/internal/safenet"
"golang.org/x/net/html"
)
Expand Down
4 changes: 2 additions & 2 deletions internal/audit/images_test.go → core/checks/images_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package audit
package checks

import (
"context"
Expand All @@ -8,7 +8,7 @@ import (
"strings"
"testing"

"github.com/meysam81/scry/internal/model"
"github.com/meysam81/scry/core/model"
)

func TestImageChecker_Check(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions internal/audit/links.go → core/checks/links.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package audit
package checks

import (
"context"
"fmt"
"strings"

"github.com/meysam81/scry/internal/model"
"github.com/meysam81/scry/core/model"
"golang.org/x/net/html"
)

Expand Down
4 changes: 2 additions & 2 deletions internal/audit/links_test.go → core/checks/links_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package audit
package checks

import (
"context"
"strings"
"testing"

"github.com/meysam81/scry/internal/model"
"github.com/meysam81/scry/core/model"
)

func TestLinkChecker_Check_NonHTML_ReturnsNil(t *testing.T) {
Expand Down
Loading
Loading