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
2 changes: 1 addition & 1 deletion .docs/wiki/Development.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ How the repository is laid out, how to run both halves while changing them, and
| `web/src/styles/`, `web/src/site/`, `web/src/sandbox/` | Component styles; published-site script; the sandboxed Mermaid renderer |
| `web/src/i18n/` | UI catalogs, one folder per language; the Vite i18n plugin bundles each language's files into one chunk loaded on demand |
| `web/public/` | Served as is: `sw.js` (service worker), `maps/` |
| `tools/` | `boot_backend`, `oc_install` (Go side), `notices/` (generates `NOTICES.md`), `wikicheck/` (checks this wiki against the code), `skillcheck/` (checks the skill's `policy.json`), `bundlecheck/` (fails `make build` when the JavaScript the first page loads, the entry plus its modulepreloads gzipped, passes 260 KB; `-budget` changes the limit) |
| `tools/` | `boot_backend`, `oc_install` (Go side), `notices/` (generates `NOTICES.md`, and `src-tauri/NOTICES.md` with `desktop`; `--check` fails when either does not list, with its licence text, every Go module, npm production package and Rust crate that ships, and runs in CI), `wikicheck/` (checks this wiki against the code), `skillcheck/` (checks the skill's `policy.json`), `bundlecheck/` (fails `make build` when the JavaScript the first page loads, the entry plus its modulepreloads gzipped, passes 260 KB; `-budget` changes the limit) |
| `deploy/`, `install.sh`, `Dockerfile` | Systemd unit, installer, container image |
| `.github/workflows/` | `ci.yml` (every push to `main` or a `compile_v*` branch and every pull request); releases are built by formcompiler |

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ jobs:
go-version-file: go.mod
- name: go tests
run: go test -count=1 ./...
- name: third-party notices cover what ships
run: go run ./tools/notices --check
window:
runs-on: ubuntu-latest
steps:
Expand Down
2,807 changes: 2,755 additions & 52 deletions NOTICES.md

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions internal/HASHOUT_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2718,3 +2718,33 @@ Limits, all against a zip bomb: an entry is read at most `files.max_upload_mb` p
`POST /api/files/unzip` has a summary in `internal/apidoc/apidoc.go`; the generated name for `unzip` would have read badly. `go run ./tools/wikicheck` does not list routes and passes either way.

Ran: `gofmt -l internal cmd` (nothing), `go vet ./internal/files/ ./internal/apidoc/`, `GOOS=windows go build -o /dev/null ./cmd/form-md`, `CGO_ENABLED=0 go build` of `cmd/form-md`, `go run ./tools/wikicheck` (23 pages agree). Against a server on a throwaway data folder: a zip of two PNGs (one in a folder, one named .PNG), a GIF, a .txt, a text file named .png, a `__MACOSX/` entry, a dot file, a nested .zip and a folder answered 201 with 3 files and 5 skipped; a plain text file answered 400 `not_a_zip`; a zip of two text files answered 400 `no_images` with both in `data.skipped`; purpose cover answered 400 `bad_purpose`; no session answered 401; the files folder held no `.unzip-*` afterwards. Not run: an encrypted instance, a zip over a cap, a zip over the upload limit, Windows itself.

---

## Shared finder 1.1.0 and complete notices {#finder-1-1-notices}

### internal/agentlookup · the Windows starter of the shared finder 1.1.0
- refers-to: internal/agentlookup/agentlookup.go :: `Version`, `SpecSHA256`, `CommandLineRefused`, `ErrUnsafeArg`, `PlainName`, `BatchFile`, `ShimTarget`, `shimRunner`, `CmdSafe`, `StartArgv`; internal/agentlookup/windows_shims_test.go; internal/agentlookup/windows_start_test.go :: `TestTheRefusalPointsAtStandardInputOrAFile`
- kind: fix

The specification moved to FormVis `backend/app/services/agent_lookup.py` 1.1.0 (SHA-256 `313fcd40541199c920314516026a0b225aeb4915e9a5dc26bf51d1ba05f1da8e`, recorded as `SpecSHA256` beside `Version`). Only its Windows start changed from 1.0.1, so only that part changed here; macOS, Linux and every other function are as before. form.md is Go, so the file is not copied: its behaviour is written in Go, as for 1.0.1.

- The program name is read the way Windows opens it (`PlainName`, `BatchFile`): any letter case, trailing dots or spaces, a `::$DATA` stream name. `foo.cmd.` or `foo.CMD` no longer skips the shim reading and the cmd.exe check.
- `ShimTarget` follows npm, pnpm and bun shims: one script or one `.exe` before `%*`, one runner (node or bun, from the script lines and the values of `_prog`) across the lines, and no variable set other than `dp0`, `_prog`, `PATHEXT` and pnpm's `NODE_PATH`, which is not carried over. A launcher that sets anything else (Antigravity's `ELECTRON_RUN_AS_NODE`) is not followed. The runner is the `node.exe` or `bun.exe` beside the shim, else the one on PATH. Before this, the last `"%~dp0..." %*` match was taken whatever else the file did, and bun shims were not followed.
- Through cmd.exe, `CmdSafe` refuses a word or program path holding `& | < > ^ ( ) ! % "` or a control character, as before, and also a program path with a space that holds `@` or is followed by a word with a space or an empty word, since cmd /c would remove its quotes. The refusal is `*CommandLineRefused`; `errors.Is(err, ErrUnsafeArg)` still matches it, and its message suggests standard input or a file. `Check` reports it as broken, as before.

Ran: `go test ./internal/agentlookup ./internal/claudecode` with the FormVis 1.1.0 cases ported (shim names in any case, pnpm, bun beside and on PATH, mixed runners, missing target or runner, a launcher with its own variables, the program path rule, the quoted-path rule, plain words, non-batch programs, the name reading, a refusal in `Check`); `GOOS=windows go vet ./internal/agentlookup`. Not run: Windows itself.

### tools/notices · every licence file, and a check in CI
- refers-to: tools/notices/texts.go :: `noticeFiles`, `joinFiles`, `extras`, `hasBody`, `unix`; tools/notices/desktop.go :: `shippedCrates`, `crateLicense`, `standardText`; tools/notices/main.go :: `goModuleList`, `webLock`, `readLicense`, `webLicense`; tools/notices/check.go :: `checkAll`, `compare`; tools/notices/check_test.go; .github/workflows/ci.yml (test job)
- kind: fix

NOTICES.md (embedded in the binary, served at `/notices`, linked from Settings as Open-source licences, and bundled in the desktop app as `NOTICES-server.md`) and src-tauri/NOTICES.md (bundled as `NOTICES.md`) already listed every Go module, npm production package and shipped crate with a licence text. Three gaps in the texts are fixed:

- Only the first licence file of a package was taken. Now every licence-like file at its top is (licence, COPYING, COPYRIGHT, NOTICE, PATENTS, AUTHORS, third-party licences), so Go's PATENTS, modernc's LICENSE-3RD-PARTY and SQLite files, es-toolkit's NOTICE and the like are in. A crate under an OR choice keeps one licence (MIT first, as before) with its copyright, NOTICE and third-party files; under AND every licence file is kept (brotli, dpi, encoding_rs's WHATWG text, unicode-ident's Unicode licence were missing).
- A crate that ships no licence text gets the standard text of each licence its Cargo.toml declares (each part of an AND), with a line naming that SPDX expression and its repository.
- Texts with Windows line ends are written with Unix ones, so a regenerated file matches what git stores.

`go run ./tools/notices --check` fails when either file does not list a component that ships, lists one that no longer does, has a row without a licence text, or has Windows line ends. It reads `go list`, `web/package-lock.json` and `cargo metadata`, so it needs no `node_modules`; `--server` checks NOTICES.md alone. CI runs it in the test job. No binary is downloaded by the app, and no Python ships, so neither has a section.

Ran: the generator for both files, then `--check` (passes; it also passes on the files before this change, whose gaps were in the texts, not the lists), `go test ./tools/notices`.
270 changes: 212 additions & 58 deletions internal/agentlookup/agentlookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package agentlookup
import (
"context"
"errors"
"io"
"os"
"os/exec"
"path/filepath"
Expand All @@ -17,7 +18,11 @@ import (
"github.com/nodemode-ai/form.md/internal/nowindow"
)

const Version = "1.0.1"
// Version and SpecSHA256 name the shared finder this package follows: FormVis
// backend/app/services/agent_lookup.py at that version and hash.
const Version = "1.1.0"

const SpecSHA256 = "313fcd40541199c920314516026a0b225aeb4915e9a5dc26bf51d1ba05f1da8e"

type Program struct {
Title string
Expand Down Expand Up @@ -659,92 +664,241 @@ func quote(word string, fish bool) string {
return "'" + strings.ReplaceAll(word, "'", `'"'"'`) + "'"
}

// CommandLineRefused is a word the Windows command interpreter would not pass
// through to the program as it is. errors.Is matches it to ErrUnsafeArg.
type CommandLineRefused struct{ Message string }

func (e *CommandLineRefused) Error() string { return e.Message }

func (e *CommandLineRefused) Is(target error) bool { return target == ErrUnsafeArg }

var ErrUnsafeArg = errors.New("this text cannot be passed to the program on Windows through cmd.exe")

var batchEndings = []string{".cmd", ".bat"}

const refusal = "Windows starts this program through the command interpreter (cmd.exe), which would change or act on the text, so it " +
"was not started. Pass long or special text through standard input or a file if the program supports it, or point " +
"the setting at the program's .exe or node script so it starts without the command interpreter."

const (
dp0Script = `"%(?:~dp0|dp0%)\\?([^"%\r\n]+?\.(?:js|cjs|mjs))"`
dp0Exe = `"%(?:~dp0|dp0%)\\?([^"%\r\n]+?\.exe)"`
runnerRe = `(?:"%_prog%"|(node|bun)(?:\.exe)?|"%(?:~dp0|dp0%)\\?(node|bun)\.exe")`
)

var (
ErrUnsafeArg = errors.New("this text cannot be passed to the program on Windows through cmd.exe: leave out control characters and & | < > ^ ( ) ! % \" or pass long text through stdin or a file if the program supports it")
shimTarget = regexp.MustCompile(`"(?:%~dp0%?|%dp0%)\\?([^"%]+)"\s+%\*`)
controlChars = regexp.MustCompile(`[\x00-\x1f\x7f]`)
streamName = regexp.MustCompile(`(?i)(?:::\$data)?[ .]*$`)
shimScript = regexp.MustCompile(`(?im)(?:^|&)[ \t]*@?` + runnerRe + `[ \t]+` + dp0Script + `[ \t]+%\*[ \t\r]*$`)
shimExe = regexp.MustCompile(`(?im)(?:^|&)[ \t]*@?` + dp0Exe + `[ \t]+%\*[ \t\r]*$`)
shimSets = regexp.MustCompile(`(?i)\bset[ \t]+"?([A-Za-z_]\w*)=`)
shimProg = regexp.MustCompile(`(?i)\bset[ \t]+"?_prog=([^"\r\n]*)`)
progValue = regexp.MustCompile(`(?i)^(?:%(?:~dp0|dp0%)\\?)?(node|bun)(?:\.exe)?$`)
shimOwnVars = map[string]bool{"dp0": true, "_prog": true, "pathext": true, "node_path": true}
cmdRefused = regexp.MustCompile(`[&|<>^()!%"\x00-\x1f\x7f]`)
)

const cmdSpecial = `&|<>^()!%"`
// PlainName is the file name as Windows opens it: lower case, without
// trailing dots or spaces or a ::$DATA stream name.
func PlainName(path string) string {
name := path
if i := strings.LastIndexAny(path, `\/`); i >= 0 {
name = path[i+1:]
}
return strings.ToLower(streamName.ReplaceAllString(name, ""))
}

func StartArgv(cmd []string, env []string, platform string) ([]string, error) {
env = environ(env)
if Windows(platform) {
first := strings.ToLower(cmd[0])
if strings.HasSuffix(first, ".cmd") || strings.HasSuffix(first, ".bat") {
if direct := resolveShim(cmd[0], env); direct != nil {
return append(direct, cmd[1:]...), nil
}
for _, w := range cmd {
if !cmdSafe(w) {
return nil, ErrUnsafeArg
}
// BatchFile reports whether Windows would start this file through the
// command interpreter (.cmd or .bat in any letter case).
func BatchFile(path string) bool {
name := PlainName(path)
for _, end := range batchEndings {
if strings.HasSuffix(name, end) {
return true
}
}
return false
}

func winDir(path string) string {
if i := strings.LastIndexAny(path, `\/`); i >= 0 {
return path[:i]
}
return "."
}

func beside(dir, rel string) string {
parts := []string{dir}
for _, part := range strings.Split(strings.ReplaceAll(rel, `\`, "/"), "/") {
if part != "" {
parts = append(parts, part)
}
}
return filepath.Join(parts...)
}

func isFile(path string) bool {
st, err := os.Stat(path)
return err == nil && !st.IsDir()
}

func allSame(paths []string) bool {
for _, p := range paths {
if p != paths[0] {
return false
}
}
return true
}

// shimRunner is the one runner (node or bun) every script line of a shim
// uses, or "" when they disagree or one is unknown.
func shimRunner(text string, named []string) string {
stems := map[string]bool{}
viaProg := false
for _, word := range named {
if word == "" {
viaProg = true
} else {
stems[strings.ToLower(word)] = true
}
}
if viaProg {
for _, m := range shimProg.FindAllStringSubmatch(text, -1) {
hit := progValue.FindStringSubmatch(strings.TrimSpace(m[1]))
if hit == nil {
return ""
}
return append([]string{or(get(env, "COMSPEC"), "cmd.exe"), "/c"}, cmd...), nil
stems[strings.ToLower(hit[1])] = true
}
return append([]string{}, cmd...), nil
}
sh := LoginShell(env, platform)
fish := filepath.Base(sh) == "fish"
words := make([]string, len(cmd))
for i, w := range cmd {
words[i] = quote(w, fish)
if len(stems) != 1 {
return ""
}
return []string{sh, "-l", "-c", "exec " + strings.Join(words, " ")}, nil
for stem := range stems {
return stem
}
return ""
}

// cmdSafe reports whether a word can go through cmd.exe and a script shim
// unchanged. cmd.exe reads its special characters even inside double quotes
// once a shim expands %*, so quoting is not treated as protection.
func cmdSafe(word string) bool {
return !controlChars.MatchString(word) && !strings.ContainsAny(word, cmdSpecial)
func runnerOnPath(runner string, env []string) string {
for _, d := range strings.Split(get(env, "PATH"), ";") {
if d = strings.Trim(d, `" `); d != "" {
if c := filepath.Join(d, runner+".exe"); isFile(c) {
return c
}
}
}
return ""
}

func resolveShim(shim string, env []string) []string {
body, err := os.ReadFile(shim)
// ShimTarget is the program an npm, pnpm or bun .cmd shim runs (its script
// with node or bun, or its .exe), so it can be started without the command
// interpreter; nil when the file is not such a shim (it sets anything of its
// own other than NODE_PATH, or hands %* to anything else) or its target is
// missing. pnpm's NODE_PATH is not carried over.
func ShimTarget(shim string, env []string) []string {
f, err := os.Open(shim)
if err != nil {
return nil
}
found := shimTarget.FindAllStringSubmatch(string(body), -1)
if len(found) == 0 {
return nil
buf := make([]byte, 65536)
n, _ := io.ReadFull(f, buf)
_ = f.Close()
text := strings.ToValidUTF8(string(buf[:n]), "�")
for _, m := range shimSets.FindAllStringSubmatch(text, -1) {
if !shimOwnVars[strings.ToLower(m[1])] {
return nil
}
}
dir := winDir(shim)
target := filepath.Join(append([]string{dir}, strings.Split(strings.Trim(found[len(found)-1][1], `\`), `\`)...)...)
if st, err := os.Stat(target); err != nil || st.IsDir() {
return nil
lines := shimScript.FindAllStringSubmatch(text, -1)
scripts, named := []string{}, []string{}
for _, m := range lines {
scripts = append(scripts, beside(dir, m[3]))
named = append(named, or(m[1], m[2]))
}
exes := []string{}
for _, m := range shimExe.FindAllStringSubmatch(text, -1) {
exes = append(exes, beside(dir, m[1]))
}
if len(scripts) > 0 && len(exes) == 0 && allSame(scripts) && isFile(scripts[0]) {
runner := shimRunner(text, named)
if runner == "" {
return nil
}
found := filepath.Join(dir, runner+".exe")
if !isFile(found) {
found = runnerOnPath(runner, env)
}
if found == "" {
return nil
}
return []string{found, scripts[0]}
}
switch strings.ToLower(filepath.Ext(target)) {
case ".exe":
return []string{target}
case ".js", ".cjs", ".mjs":
if node := nodeFor(dir, env); node != "" {
return []string{node, target}
if len(exes) > 0 && len(scripts) == 0 && allSame(exes) && isFile(exes[0]) {
if name := PlainName(exes[0]); name != "node.exe" && name != "bun.exe" {
return []string{exes[0]}
}
}
return nil
}

func winDir(path string) string {
if i := strings.LastIndexAny(path, `\/`); i >= 0 {
return path[:i]
// CmdSafe returns a *CommandLineRefused unless cmd.exe /c would pass every
// word, the program's path included, unchanged. No word may hold
// & | < > ^ ( ) ! % " or a control character, quoted or not. A program path
// with a space or tab keeps its quotes only when it is the line's one quoted
// word and holds no @.
func CmdSafe(words []string) error {
for i, word := range words {
if cmdRefused.MatchString(word) {
what := "A word for this program"
if i == 0 {
what = "The path of this program"
}
return &CommandLineRefused{what + " has one of & | < > ^ ( ) ! % \" or a control character. " + refusal}
}
}
return "."
if len(words) == 0 || !strings.ContainsAny(words[0], " \t") {
return nil
}
bad := strings.Contains(words[0], "@")
for _, word := range words[1:] {
bad = bad || word == "" || strings.ContainsAny(word, " \t")
}
if bad {
return &CommandLineRefused{"The path of this program has a space, and the command interpreter would drop its quotes when an " +
"@ is in it or another word has a space or is empty. " + refusal}
}
return nil
}

func nodeFor(dir string, env []string) string {
candidates := []string{filepath.Join(dir, "node.exe")}
for _, d := range strings.Split(get(env, "PATH"), ";") {
if d = strings.Trim(d, `" `); d != "" {
candidates = append(candidates, filepath.Join(d, "node.exe"))
// StartArgv is how a program is started, the same for a tab, Chat and a
// check: through the person's login shell on macOS and Linux (exec, so the
// process is the program), directly on Windows. An npm, pnpm or bun .cmd shim
// is started as the script or program it names, with the words as an argv
// list; any other .cmd or .bat goes through cmd.exe, only with words it
// passes through unchanged.
func StartArgv(cmd []string, env []string, platform string) ([]string, error) {
env = environ(env)
if Windows(platform) {
if !BatchFile(cmd[0]) {
return append([]string{}, cmd...), nil
}
}
for _, c := range candidates {
if st, err := os.Stat(c); err == nil && !st.IsDir() {
return c
if direct := ShimTarget(cmd[0], env); direct != nil && !BatchFile(direct[0]) {
return append(direct, cmd[1:]...), nil
}
if err := CmdSafe(cmd); err != nil {
return nil, err
}
return append([]string{or(get(env, "COMSPEC"), "cmd.exe"), "/c"}, cmd...), nil
}
return ""
sh := LoginShell(env, platform)
fish := filepath.Base(sh) == "fish"
words := make([]string, len(cmd))
for i, w := range cmd {
words[i] = quote(w, fish)
}
return []string{sh, "-l", "-c", "exec " + strings.Join(words, " ")}, nil
}

type Result struct {
Expand Down
Loading
Loading