|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +This file is the development and contribution contract for AI coding agents working in this repository. |
| 4 | + |
| 5 | +## Project purpose |
| 6 | + |
| 7 | +`tiddlywiki-nmem-importer` imports tiddlers from one Node.js TiddlyWiki into Nowledge Mem. It boots the real Wiki with the npm `tiddlywiki` package, renders WikiText to HTML, converts that HTML to GitHub Flavored Markdown, and upserts each result as a Memory through the installed `nmem` CLI. |
| 8 | + |
| 9 | +`README.md` is the user-facing source of truth for installation and usage. Keep it synchronized whenever CLI behavior changes. |
| 10 | + |
| 11 | +## Non-negotiable behavior |
| 12 | + |
| 13 | +- The current working directory is the only Wiki input. |
| 14 | +- The command must be run from a directory containing a readable `tiddlywiki.info`. |
| 15 | +- Do not restore `--wiki`, hardcoded Wiki names, parent-directory scans, or sibling-directory scans. |
| 16 | +- Default execution is a dry-run. Only `--apply` may write to Nowledge Mem. |
| 17 | +- Never modify, move, or delete source tiddlers. |
| 18 | +- Use the installed current `nmem`; never hardcode a required nmem version. |
| 19 | +- Require the `nmem` CLI and service to report matching versions before writing. |
| 20 | +- Reject remote Nowledge Mem services by default; require `--allow-remote` for an explicit override. |
| 21 | +- Preserve deterministic Memory IDs based on source Wiki name and tiddler title so reruns remain idempotent. |
| 22 | +- Preserve the default sensitive-title filter unless a deliberate behavior change includes tests and README updates. |
| 23 | + |
| 24 | +## Language and runtime |
| 25 | + |
| 26 | +- TypeScript everywhere. |
| 27 | +- Do not add `.js` or `.mjs` source files. |
| 28 | +- Run TypeScript directly with [Nub](https://github.com/nubjs/nub); do not use Bun. |
| 29 | +- Keep `strict` TypeScript enabled. |
| 30 | +- Use ESM imports with explicit `.ts` extensions, matching the existing codebase. |
| 31 | +- Prefer small functions and declarative data transformations over unnecessary classes. |
| 32 | +- Do not add a dependency when the Node.js standard library or an existing dependency is sufficient. |
| 33 | + |
| 34 | +## Repository map |
| 35 | + |
| 36 | +- `src/cli.ts`: CLI orchestration, current-directory validation, reporting, previews, and concurrent imports. |
| 37 | +- `src/core.ts`: tiddler classification, metadata, stable IDs, HTML-to-Markdown conversion, and media warnings. |
| 38 | +- `src/tiddlywiki-worker.ts`: boots TiddlyWiki and sends records over IPC. |
| 39 | +- `src/tiddlywiki.ts`: owns worker lifecycle, IPC validation, and diagnostics. |
| 40 | +- `src/nmem.ts`: validates the active nmem service and invokes `nmem memories add`. |
| 41 | +- `src/options.ts`: parses supported command-line options. |
| 42 | +- `test/`: Node test runner coverage and a minimal TiddlyWiki fixture. |
| 43 | +- `reports/`, `previews/`: generated output; both are ignored and must not be committed. |
| 44 | + |
| 45 | +## Architecture constraints |
| 46 | + |
| 47 | +Keep TiddlyWiki execution in the child worker. TiddlyWiki boot diagnostics must not be mixed with structured tiddler records; records travel through IPC and stderr is collected separately. |
| 48 | + |
| 49 | +Conversion behavior is type-dependent: |
| 50 | + |
| 51 | +- `text/vnd.tiddlywiki` and the empty/default type are rendered by TiddlyWiki before Turndown conversion. |
| 52 | +- `text/markdown` and `text/plain` use their source text directly. |
| 53 | +- Unsupported binary types, system tiddlers, drafts, empty tiddlers, and sensitive-title tiddlers are classified and reported instead of imported. |
| 54 | + |
| 55 | +Memory content includes TiddlyWiki source metadata in front matter. Keep source Wiki, title, tags, created time, and modified time available unless a documented migration replaces them. |
| 56 | + |
| 57 | +The nmem process must receive Memory content through stdin. Do not place note content in command-line arguments or logs. |
| 58 | + |
| 59 | +## Setup |
| 60 | + |
| 61 | +```bash |
| 62 | +mise install |
| 63 | +npm ci |
| 64 | +``` |
| 65 | + |
| 66 | +The repository pins its Node, Nub, npm package, and TypeScript toolchain through `mise.toml`, `package.json`, and `package-lock.json`. The nmem version is intentionally not pinned in source code. |
| 67 | + |
| 68 | +## Required validation |
| 69 | + |
| 70 | +Run both commands after every source or test change: |
| 71 | + |
| 72 | +```bash |
| 73 | +mise exec -- nub run typecheck |
| 74 | +mise exec -- nub run test |
| 75 | +``` |
| 76 | + |
| 77 | +For CLI behavior involving Wiki discovery or rendering, also run a dry-run from `test/fixtures/wiki` or another disposable Wiki root. Never use `--apply` in tests or validation unless the user explicitly authorizes writes to Nowledge Mem. |
| 78 | + |
| 79 | +Tests must cover behavior, not implementation details. Add or update tests when changing: |
| 80 | + |
| 81 | +- CLI options and defaults |
| 82 | +- tiddler classification |
| 83 | +- WikiText/HTML/Markdown conversion |
| 84 | +- deterministic IDs or metadata |
| 85 | +- nmem compatibility and command arguments |
| 86 | +- worker IPC and multiline content |
| 87 | + |
| 88 | +## Contribution workflow |
| 89 | + |
| 90 | +1. Read `README.md`, this file, and the source files relevant to the requested behavior. |
| 91 | +2. Inspect the repository for all references before changing a public option, report field, ID algorithm, label, or conversion rule. |
| 92 | +3. Keep the patch scoped to the request and preserve unrelated user changes. |
| 93 | +4. Update tests and user documentation in the same change when behavior changes. |
| 94 | +5. Run typecheck and the full test suite. |
| 95 | +6. Review the final diff for generated files, note content, credentials, and accidental dependency changes. |
| 96 | +7. Do not commit, push, publish, or create a pull request unless the user explicitly asks. |
| 97 | + |
| 98 | +## Documentation contract |
| 99 | + |
| 100 | +Every project must contain both files: |
| 101 | + |
| 102 | +- `README.md`: written for human users, centered on setup and practical usage. |
| 103 | +- `AGENTS.md`: written for AI coding agents, centered on architecture, development constraints, validation, and contribution. |
| 104 | + |
| 105 | +When project behavior changes, update the relevant sections rather than allowing either document to become historical or aspirational. |
0 commit comments