feat: add docfill mvp cli
This commit is contained in:
45
docs/superpowers/plans/2026-06-18-docfill-mvp.md
Normal file
45
docs/superpowers/plans/2026-06-18-docfill-mvp.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# Docfill MVP Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** Build a minimal Go CLI that fills `.docx` and `.xlsx` templates from Excel or SQLite rows.
|
||||
|
||||
**Architecture:** A single internal package loads JSON config, reads rows from Excel or SQLite, renders placeholders into docx/xlsx files, and exposes `Run`. A tiny CLI parses `run --config`.
|
||||
|
||||
**Tech Stack:** Go, `excelize` for `.xlsx`, `modernc.org/sqlite` for SQLite, standard `archive/zip` for `.docx`.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Tests First
|
||||
|
||||
**Files:**
|
||||
- Create: `internal/docfill/docfill_test.go`
|
||||
|
||||
- [ ] Write tests for Excel row reading, SQLite row reading, xlsx rendering, docx rendering, and full config execution.
|
||||
- [ ] Run `go test ./...` and confirm it fails because the package implementation does not exist yet.
|
||||
|
||||
### Task 2: Minimal Library
|
||||
|
||||
**Files:**
|
||||
- Create: `internal/docfill/docfill.go`
|
||||
|
||||
- [ ] Implement config parsing.
|
||||
- [ ] Implement Excel and SQLite row readers.
|
||||
- [ ] Implement placeholder replacement.
|
||||
- [ ] Implement xlsx and docx rendering.
|
||||
- [ ] Implement `Run(configPath string) error`.
|
||||
|
||||
### Task 3: CLI
|
||||
|
||||
**Files:**
|
||||
- Create: `cmd/docfill/main.go`
|
||||
|
||||
- [ ] Parse `docfill run --config task.json`.
|
||||
- [ ] Print clear errors to stderr.
|
||||
- [ ] Exit non-zero on failure.
|
||||
|
||||
### Task 4: Verify
|
||||
|
||||
- [ ] Run `go test ./...`.
|
||||
- [ ] Run `go build ./cmd/docfill`.
|
||||
- [ ] Keep README usage minimal.
|
||||
49
docs/superpowers/plans/2026-06-18-docfill-p0.5-delivery.md
Normal file
49
docs/superpowers/plans/2026-06-18-docfill-p0.5-delivery.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# Docfill P0.5 Delivery Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** Make the existing P0 CLI easier to hand to digital employees by adding delivery hygiene, runnable examples, a smoke script, and minimal Word split-placeholder support.
|
||||
|
||||
**Architecture:** Keep one `docfill run` command and the existing internal package. Add only test fixture helpers and examples around the current API; do not add a template engine, web UI, or multi-command workflow.
|
||||
|
||||
**Tech Stack:** Go, `excelize`, `modernc.org/sqlite`, standard shell for smoke testing.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Delivery Hygiene
|
||||
|
||||
**Files:**
|
||||
- Create: `.gitignore`
|
||||
- Modify: `README.md`
|
||||
|
||||
- [ ] Ignore local OS files, compiled binaries, test binaries, and example outputs.
|
||||
- [ ] Keep README focused on run/build/test/smoke usage.
|
||||
|
||||
### Task 2: Word Split Placeholders
|
||||
|
||||
**Files:**
|
||||
- Modify: `internal/docfill/docfill.go`
|
||||
- Modify: `internal/docfill/docfill_test.go`
|
||||
|
||||
- [ ] Add a failing test for a Word placeholder split across adjacent `<w:t>` nodes in one paragraph.
|
||||
- [ ] Implement minimal rendering for split placeholders inside Word text nodes.
|
||||
- [ ] Keep existing contiguous placeholder behavior passing.
|
||||
|
||||
### Task 3: Runnable Examples
|
||||
|
||||
**Files:**
|
||||
- Create: `examples/README.md`
|
||||
- Create: `examples/excel-to-word/task.json`
|
||||
- Create: `examples/sqlite-to-excel/task.json`
|
||||
- Create: `scripts/smoke-fixtures/main.go`
|
||||
- Create: `scripts/smoke.sh`
|
||||
|
||||
- [ ] Add two small configs that mirror real employee daily-report workflows.
|
||||
- [ ] Generate temporary fixture files from Go during smoke tests instead of storing binary Office files in git.
|
||||
- [ ] Smoke test builds the CLI, copies examples to a temp dir, generates fixtures, runs both example configs, and runs `go test -count=1 ./...`.
|
||||
|
||||
### Task 4: Verify
|
||||
|
||||
- [ ] Run `go test -count=1 ./...`.
|
||||
- [ ] Run `bash scripts/smoke.sh`.
|
||||
- [ ] Run `go build -o /tmp/docfill-p05 ./cmd/docfill`.
|
||||
38
docs/superpowers/plans/2026-06-18-docfill-p0.6-freeze.md
Normal file
38
docs/superpowers/plans/2026-06-18-docfill-p0.6-freeze.md
Normal file
@@ -0,0 +1,38 @@
|
||||
# Docfill P0.6 Freeze Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** Freeze the current MVP as a small deliverable that can be built, smoke-tested, and handed to a digital employee.
|
||||
|
||||
**Architecture:** Keep the current single-command CLI and add only delivery wrappers: a local build script, a runbook, and ignore rules for generated artifacts. No new runtime features.
|
||||
|
||||
**Tech Stack:** Go, shell, existing `docfill run` CLI.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Build Output
|
||||
|
||||
**Files:**
|
||||
- Modify: `.gitignore`
|
||||
- Create: `scripts/build.sh`
|
||||
|
||||
- [ ] Ignore `dist/`.
|
||||
- [ ] Build only the current machine target into `dist/docfill-darwin-arm64`.
|
||||
- [ ] Print the output path.
|
||||
|
||||
### Task 2: Digital Employee Runbook
|
||||
|
||||
**Files:**
|
||||
- Create: `docs/digital-employee-runbook.md`
|
||||
- Modify: `README.md`
|
||||
|
||||
- [ ] Document required inputs, command contract, stdout/stderr handling, exit codes, and common errors.
|
||||
- [ ] Link the runbook from README.
|
||||
|
||||
### Task 3: Freeze Verification
|
||||
|
||||
- [ ] Run `go test -count=1 ./...`.
|
||||
- [ ] Run `bash scripts/smoke.sh`.
|
||||
- [ ] Run `bash scripts/build.sh`.
|
||||
- [ ] Stage all project files except local ignored files.
|
||||
- [ ] Commit as `feat: add docfill mvp cli`.
|
||||
50
docs/superpowers/specs/2026-06-18-docfill-mvp-design.md
Normal file
50
docs/superpowers/specs/2026-06-18-docfill-mvp-design.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# Docfill MVP Design
|
||||
|
||||
## Goal
|
||||
|
||||
Build the smallest local Go command-line tool that a digital employee can call to fill Word or Excel templates from Excel or SQLite data.
|
||||
|
||||
## MVP Scope
|
||||
|
||||
- Input data: `.xlsx` table or SQLite query result.
|
||||
- Template files: `.docx` or `.xlsx`.
|
||||
- Placeholder syntax: `{{column_name}}`.
|
||||
- Output: one generated file per input row.
|
||||
- Invocation: `docfill run --config task.json`.
|
||||
|
||||
## Explicit Non-Goals
|
||||
|
||||
- No web UI.
|
||||
- No permission system.
|
||||
- No workflow engine.
|
||||
- No template designer.
|
||||
- No direct business-system integration.
|
||||
- No AI guessing of fields.
|
||||
- No complex Word layout manipulation.
|
||||
|
||||
## Config Shape
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"type": "excel",
|
||||
"path": "./data.xlsx",
|
||||
"sheet": "Sheet1"
|
||||
},
|
||||
"template": {
|
||||
"path": "./template.docx"
|
||||
},
|
||||
"output": {
|
||||
"path": "./out/report_{{name}}_{{_row}}.docx"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
For SQLite, `data` uses `type: "sqlite"` and `query`.
|
||||
|
||||
## Constraints
|
||||
|
||||
- Keep the implementation boring and inspectable.
|
||||
- Infer template behavior from file extension.
|
||||
- Treat Excel first row or SQL column names as placeholder keys.
|
||||
- If a Word placeholder is split across Word XML runs, MVP may not replace it; users should type placeholders as plain contiguous text.
|
||||
65
docs/superpowers/specs/2026-06-18-docfill-p0-cli-design.md
Normal file
65
docs/superpowers/specs/2026-06-18-docfill-p0-cli-design.md
Normal file
@@ -0,0 +1,65 @@
|
||||
# Docfill P0 CLI Design
|
||||
|
||||
## Goal
|
||||
|
||||
Make the MVP safe enough for a digital employee to call repeatedly from scripts.
|
||||
|
||||
## CLI Contract
|
||||
|
||||
```bash
|
||||
docfill run --config task.json --var date=2026-06-18
|
||||
docfill run -c task.json --var date=2026-06-18 --var department=营销部
|
||||
```
|
||||
|
||||
Exit codes:
|
||||
|
||||
- `0`: success.
|
||||
- `1`: task execution or validation failed.
|
||||
- `2`: CLI usage error.
|
||||
|
||||
Output:
|
||||
|
||||
- Success writes a short generated-file summary to stdout.
|
||||
- Errors write one clear line to stderr with the `docfill:` prefix.
|
||||
|
||||
Reserved for later:
|
||||
|
||||
- `docfill validate`.
|
||||
- `--json`.
|
||||
|
||||
## P0 Behavior
|
||||
|
||||
- Resolve relative paths in config from the config file directory.
|
||||
- Support config vars and repeated CLI vars.
|
||||
- CLI vars override config vars.
|
||||
- Per-row data overrides vars during template rendering.
|
||||
- Generated `_row` is always the 1-based row number.
|
||||
- Support SQLite `params` for `?` query placeholders.
|
||||
- Support Excel `header_row`, 1-based, default `1`.
|
||||
- Do not overwrite existing output files unless `output.overwrite` is `true`.
|
||||
- Sanitize placeholder values only when rendering output file paths.
|
||||
- Fail if any template placeholder is missing from the current row context.
|
||||
- Fail if any `{{field}}` remains after rendering.
|
||||
|
||||
## Config Shape
|
||||
|
||||
```json
|
||||
{
|
||||
"vars": {
|
||||
"date": "2026-06-18"
|
||||
},
|
||||
"data": {
|
||||
"type": "sqlite",
|
||||
"path": "./data.db",
|
||||
"query": "select name, done from daily where date = ?",
|
||||
"params": ["{{date}}"]
|
||||
},
|
||||
"template": {
|
||||
"path": "./template.docx"
|
||||
},
|
||||
"output": {
|
||||
"path": "./out/report_{{date}}_{{name}}_{{_row}}.docx",
|
||||
"overwrite": false
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user