返回 DeepSeek-Reasonix
backend.go
根目录 / internal / skill / skillwatch / backend.go
1 package skillwatch
2
3 import (
4 "errors"
5 "io"
6 )
7
8 // errHelperStopped reports a helper backend that cannot serve registrations:
9 // process dead and out of restart budget, or never started.
10 var errHelperStopped = errors.New("watch helper stopped")
11
12 // helperProcess is the minimal process handle the helper client needs; it
13 // exists so tests can inject a re-exec without depending on os/exec here.
14 type helperProcess interface {
15 Stdin() io.Writer
16 Stdout() io.Reader
17 Wait() error
18 Kill() error
19 }
20
21 // backend abstracts the physical watch mechanism. register may block (the
22 // helper path waits for the pipe round trip), so the service always calls it
23 // from its own goroutine; cancel is fire-and-forget and close is terminal.
24 type backend interface {
25 register(id, rootGen uint64, root string, dirs []string) error
26 cancel(id uint64)
27 close() error
28 physicalWatches() uint64
29 }
30
31 // errScanOnly reports a service that was asked for no physical watches.
32 var errScanOnly = errors.New("scan-only service has no physical watches")
33
34 // scanOnlyBackend refuses every registration, which is how the service already
35 // handles a backend it cannot use: the root degrades to backoff scanning and
36 // the store keeps working from its scans. Options.ScanOnly selects it so a
37 // caller can hold a real, closable service without a helper process.
38 type scanOnlyBackend struct{}
39
40 func (scanOnlyBackend) register(uint64, uint64, string, []string) error { return errScanOnly }
41 func (scanOnlyBackend) cancel(uint64) {}
42 func (scanOnlyBackend) close() error { return nil }
43 func (scanOnlyBackend) physicalWatches() uint64 { return 0 }
44
44 lines GO