---
name: seek
description: Search files for a literal string; NDJSON records with tagged errors, bounded memory, and an authority with no write, network or foreign code.
---

# seek 0.1.0

Search files for a literal string; NDJSON records with tagged errors, bounded memory, and an authority with no write, network or foreign code.

```
seek [--root DIR] [--max-count N] [--skip N] [--max-line-bytes N] [--ascii-case-insensitive] [--require-match] [--format ndjson|text] PATTERN FILE...
```

## Output

NDJSON: one JSON object per line, schema `seek.v1`. The last line is a record with `"type":"end"`; **a stream without one was cut short and must be treated as truncated**. `complete` is false when the tool stopped early. Errors are records with `"type":"error"`.

An error is `{code, rule, message, hint, repair, detail}`. Match on `rule`, not on `message`. When `repair` is `{"kind":"retry","argv":[...]}` the argv can be run as it stands; it never widens what the tool may touch.

`--format text` is for a person and is lossy; do not parse it.

## Flags

- `--root <path>`: resolve every FILE relative to this directory and refuse paths outside it
- `--max-count <nat>` (`-m`): stop after this many matches in total, and report truncated with a next cursor
- `--skip <nat>`: skip this many matches before reporting any (the next cursor of a truncated run) Default `0`.
- `--max-line-bytes <nat>`: the longest line held, a longer one is limit.line-too-long (ceiling 16777216) Default `1048576`.
- `--ascii-case-insensitive` (`-i`): fold ASCII letters only when comparing
- `--require-match`: exit 8 (precondition.no-match) when nothing matched
- `--format <choice:ndjson/text>`: ndjson for a program, text (path:line:text) for a person Default `ndjson`.

An unknown flag is refused (`args.unknown-flag`), never ignored. POSIX spellings are not promised.

## Guarantees

- **deterministic**: the same input gives byte-identical output, through a pipe, a file or a terminal (M2)
- **idempotent**: running it twice leaves the same state as once (M7 for the writers, and a reader changes nothing)
- **bounded_memory**: peak memory does not grow with the input's size (M9)
- **concurrency**: read-only; it never writes.

## Exit codes

- `0` SUCCESS: what was asked was done; zero matches is success
- `1` GENERAL_ERROR: the operating system failed mid-operation, or the tool caught a bug in itself
- `2` INVALID_ARGS: the invocation is malformed or names something of the wrong kind; nothing was read
- `3` NOT_FOUND: a named input does not exist
- `4` PERMISSION_DENIED: the operating system refused, or the tool's own confinement did
- `8` PRECONDITION_FAILED: the answer is no, or a limit was reached
- `132`: the tool trapped. A bug in the tool; there is no JSON.
- `141`: the reader closed the pipe.

## Rules

- `args.unknown-flag` (exit 2): a flag that is not in the tool's table
- `args.missing-value` (exit 2): a flag that takes a value was given none
- `args.bad-value` (exit 2): a flag's value is not of the flag's kind
- `args.unexpected-value` (exit 2): a flag that takes no value was given one
- `args.duplicate-flag` (exit 2): the same flag was given twice
- `args.missing-operand` (exit 2): an operand the tool needs was not given
- `path.empty` (exit 2): an empty path
- `path.dotdot` (exit 2): a path with a `..` component
- `path.absolute` (exit 2): an absolute path where one relative to --root is wanted
- `path.outside-root` (exit 4): an absolute path that is not under --root
- `path.too-long` (exit 2): a path longer than 4096 bytes
- `path.symlink` (exit 4): a path that runs through a symbolic link, which the tool does not follow
- `io.not-found` (exit 3): a named input does not exist
- `io.not-a-directory` (exit 3): a path runs through something that is not a directory
- `io.is-a-directory` (exit 2): a directory where a file is wanted
- `io.permission-denied` (exit 4): the operating system refused access
- `io.read-failed` (exit 1): the operating system failed a read
- `limit.line-too-long` (exit 8): a line longer than --max-line-bytes
- `precondition.no-match` (exit 8): --require-match was given and nothing matched

## Authority

What the compiler says this program can reach (`cancho authority`), embedded at build time:

```json
{"bounded":true,"unbounded_by":[],"effects":["args","dir_read","err_write","file_read","fs_read","heap","io_write"],"labels":[{"name":"args","argument":null,"bounded":true},{"name":"dir_read","argument":null,"bounded":true},{"name":"err_write","argument":null,"bounded":true},{"name":"file_read","argument":null,"bounded":true},{"name":"fs_read","argument":"","bounded":true},{"name":"heap","argument":null,"bounded":true},{"name":"io_write","argument":null,"bounded":true}],"never_touches":["the network","signals","other programs","foreign code"],"foreign_symbols":[],"pure":["alphabet","authority","broken","built","bytes","catalogue","ceiling","chunk_size","code_meaning","code_name","compiler","count","count","count","count_byte","counted","decode","default_of","digit_of","distance","emits","emitted","enotdir","entries","entry","entry","entry_at","entry_end","entry_in","equal","err_control","err_depth","err_end","err_escape","err_full","err_number","err_syntax","err_trailing","err_utf8","escape_width","exit_code","exit_in_entry","exit_of_in","expected","field","field_of","field_of","find","find_from","find_in","finish","flag_table","full","get$int","guarantee_keys","guarantees_has","has","has_dotdot","hex4","hex_digit","hex_digit","hex_value","horspool","in_choice","in_range","index_of","index_of_short","io_rule","is_ascii","is_digit","is_digit","is_flag","is_hex","is_loop","is_named","is_tail","is_utf8","is_valid","is_ws","item","kind_of","last_newline","lead_bits","line_end","line_start","longest","lower","max_depth","message_of","more","name_of","nearest","none","nth","ok","operand_count","operand_index","parse_nat","plain_byte","rarest","repairable_in","rule_of","scan_for","schema","searched","second_range","sentences","shell_builtin","shown","size","size$int","slash","start","starts_with","string_end","summary_in","takes_value","tape_len","tool","truncated","under","upper","valid","value_index","value_is_whole","width_of"],"folded_operators":35,"folded_calls":0,"functions":232}
```

The row names *kinds* of access, not *extent*: a path from the command line is checked at run time, so it reads `fs_read("")`. Symlinks are followed.
