2.4 KiB
2.4 KiB
P5c task 02: sift extract <file.pdf>
Branch: p5c (git switch p5c; git status --short must be empty, otherwise stop)
Commit subject: cli: sift extract uploads a local PDF; README and skill
Goal
sift extract thesis.pdf [--pages 41-60] [--grep RE] [--question Q] [--json] uploads the file
to /v1/extract and prints the answer exactly as sift fetch does.
Files
- Copy:
cmd/sift/extract_test.go - Create:
cmd/sift/extractcmd.go - Modify:
cmd/sift/main.go(acase "extract":and one help line),README.md,skill/SKILL.md,docs/implementer-log.md
Interfaces
package main
type extractOpts struct {
File, Pages, Grep, Question, Mode string
JSON bool
}
const extractUsage = "usage: sift extract <file.pdf> [--pages a-b] [--grep RE] [--question Q] [--mode clean|digest] [--json]"
func parseExtractOpts(args []string) (extractOpts, error) // flags before or after the file, as fetch
func extractURL(base string, o extractOpts) string // base + "/v1/extract?" + only the options that are set; mode=digest when Question is set and Mode is empty
Rules
- The command:
- Resolve the base URL and key exactly as
sift fetchdoes (reuse its client-config helpers; do not copy them). statthe file: over 100 MiB → exit with a message before uploading.POSTthe bytes withContent-Type: application/pdfand the bearer key.- Print
content(or the whole envelope with--json), with the same errors and exit codes as fetch (exitFor). - Do not read the whole file into memory twice: stream it with
os.Openas the request body and setContentLength.
- Resolve the base URL and key exactly as
README.md: asift extractsubsection next tosift fetch.skill/SKILL.md: "A PDF on disk (an attachment, a download):sift extract <file>, with the same--pages/--grep/--question. Never runpdftotextyourself."
Steps
- 1.
git switch p5c; copy the given test. 2. See it fail. - 3.
extractcmd.go,main.go, README, skill. - 4.
gofmt -w;go test -race -count=3 ./cmd/sift/→ok. 5.make gate. - 6.
make build && bin/sift extract 2>&1 | head -1prints the usage line. - 7. Row
p5c/02-extract-cli; commit.
git add cmd/sift README.md skill/SKILL.md docs/implementer-log.md
git commit -F .state/commit-msg.txt
Done when
- All tests pass;
make gateok; given file byte-identical.