@aryasaatvik/scratchpad 0.5.1 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,43 @@
1
+ ## @aryasaatvik/scratchpad@0.6.1
2
+
3
+ ### Index notes with more than 1024 chunks
4
+
5
+ `scratchpad search` and `scratchpad index` failed with "Too many docs: N exceeds max write batch
6
+ size of 1024" when one note, or one cleanup pass, touched more than 1024 vector chunks. Vector
7
+ writes and deletes now go to zvec in batches of at most 1024.
8
+
9
+ ## @aryasaatvik/scratchpad@0.6.0
10
+
11
+ ### Note lifecycle: sweep, review, and hybrid search
12
+
13
+ `scratchpad sweep` lists expired artifacts (non-note files older than their window, 14 days by
14
+ default, set per path under `lifecycle` in `scratchpad.config.ts`) and, with `--apply`, moves them
15
+ to the system Trash with a receipt in `maintenance/trash-log.md`. It is a dry run by default, skips
16
+ anything a note links to or a `protect` glob matches, and reports refused paths without failing.
17
+ `--json` gives a stable report.
18
+
19
+ `scratchpad archive` now moves paths to the Trash with a receipt instead of writing under
20
+ `archive/`. Existing `archive/` contents become ordinary sweep candidates.
21
+
22
+ `scratchpad review` classifies notes with an OpenRouter decision model (default
23
+ `typesafe/jev-1.14`) using repository evidence: referenced commits, branches, worktrees, PR and
24
+ issue state, file paths, and note links. It reports each note's kind, lifecycle verdict
25
+ (fresh, stale, superseded, expired) and confidence, plus calls, cache hits, and the cost OpenRouter
26
+ reports. Verdicts are cached, so reruns pay only for changed notes. `--apply` writes the verdict to
27
+ front matter. `sweep --apply` trashes notes with a cached stale or superseded verdict at or above
28
+ `lifecycle.notes.autoTrashConfidence` (0.9), except index files, backlog and feedback, notes updated
29
+ within 7 days, notes linked from a live note, and protected paths.
30
+
31
+ `scratchpad search` and `scratchpad index` add hybrid search over the notes root: SQLite full-text
32
+ search fused with `qwen/qwen3-embedding-8b` embeddings in an embedded zvec index. Without a key,
33
+ search runs full-text only.
34
+
35
+ `doctor` reports top-level folders and files outside the project layout, and `path --real` prints
36
+ the resolved storage path.
37
+
38
+ The classifier and search now read one OpenRouter key from `SCRATCHPAD_OPENROUTER_API_KEY` or
39
+ `~/.config/scratchpad/secrets/openrouter-api-key`. `TYPESAFE_API_KEY` is no longer read.
40
+
1
41
  ## @aryasaatvik/scratchpad@0.5.1
2
42
 
3
43
  ### Archive directories and run from inside `.scratchpad`
package/README.md CHANGED
@@ -133,8 +133,8 @@ checkout's `.scratchpad`, else the primary checkout's, else
133
133
  remote, e.g. `github.com/owner/repo`).
134
134
 
135
135
  ```
136
- scratchpad path [--global] # print the notes root in use
137
- scratchpad doctor # project id, notes root, store, token
136
+ scratchpad path [--global] [--real] # print the notes root; --real resolves symlinks
137
+ scratchpad doctor # project id, layout drift, store, token
138
138
  scratchpad skills list | path # skills embedded in this CLI
139
139
  scratchpad skills get <name> [--full | --ref <reference>]
140
140
  scratchpad backlog new <issue|milestone> "<title>" [--milestone <slug>] [--depends-on <path>]
@@ -145,7 +145,9 @@ scratchpad feedback review [--global] [--classify] [--json]
145
145
  scratchpad feedback list [--global] [--status <s>] [--disposition <d>]... [--all]
146
146
  scratchpad feedback resolve <id|file|path> --disposition <d> --review <name|path> [--evidence <e>]...
147
147
  scratchpad route "<correction>" [--write] [--json]
148
- scratchpad archive <paths...> --reason "<why>" # move files or directories into archive/<date>-<reason>/
148
+ scratchpad archive <paths...> --reason "<why>" # move notes or directories to the OS Trash
149
+ scratchpad review [paths...] [--apply] [--json] [--limit 100] # classify notes; --apply writes review metadata
150
+ scratchpad sweep [--apply] [--json] # preview expired artifacts; --apply moves them to Trash
149
151
  ```
150
152
 
151
153
  `scratchpad skills get scratchpad` prints the agent skill that drives these commands; its source is
@@ -153,19 +155,128 @@ scratchpad archive <paths...> --reason "<why>" # move files or directories in
153
155
  repository the project id is local to the directory. `--global` feedback lives in `~/.scratchpad`
154
156
  (override with `SCRATCHPAD_GLOBAL_HOME`).
155
157
 
156
- The classifier is opt-in: store a key in
157
- `$XDG_CONFIG_HOME/scratchpad/secrets/typesafe-api-key` (default
158
- `~/.config/scratchpad/secrets/typesafe-api-key`), or set `TYPESAFE_API_KEY` to override it.
158
+ `path` keeps the selected notes path by default, including a worktree's `.scratchpad` symlink.
159
+ Use `path --real` when an agent needs the physical storage path for writes. It preserves the same
160
+ plain-text or JSON output shape, works with `--global`, and fails if the selected root is missing
161
+ or inaccessible; it never creates the directory.
162
+
163
+ `doctor` checks the notes root's top-level entries against `layout` in `scratchpad.config.ts`.
164
+ It reports unlisted folders and loose files, without moving them or inspecting nested layout.
165
+ The JSON report adds `layout` with `folders`, `files`, `rootExists`, `outOfLayoutFolders`, and
166
+ `looseFiles`. A missing notes root is reported without creating it. Omitted lists use the defaults:
167
+
168
+ - Folders: `backlog`, `research`, `reference`, `feedback`, `handoffs`, `decisions`, `delivery`,
169
+ `maintenance`, `artifacts`.
170
+ - Files: `README.md`, `STATE.md`.
171
+
172
+ `archive` retires local notes to the operating system's Trash and appends receipts to
173
+ `maintenance/trash-log.md`. It no longer creates dated directories under `archive/`.
174
+ `sweep` previews expired artifacts with byte totals; `--apply` moves eligible entries to Trash
175
+ and records receipts. Trash uses `/usr/bin/trash` on macOS and `gio trash` on Linux; other platforms report an unsupported-platform error. Each move first writes and flushes a `pending` receipt, then appends `trashed`, `failed`, or `skipped-changed` with the same id. An unmatched pending receipt means the operation needs reconciliation against the source and OS Trash; do not automatically retry it. A later failure does not undo earlier moves. Markdown and HTML files are notes, so artifact expiry does not remove them.
176
+ Existing `archive/` contents may contain expired artifacts. Unwritable entries are reported as
177
+ refused, allowing other eligible entries to proceed. This local-note lifecycle is separate from
178
+ the optional read-only GitHub archive mount described below.
179
+
180
+ `sweep --json` emits version 1 of the report: `version: 1`, `apply`, `groups`, `totalBytes`,
181
+ `refused`, `warningCount`, and `trashed`. Each group contains `source`, `entries`, and `bytes`;
182
+ entries contain `path`, `bytes`, `reason`, and `source`. Refused entries contain `path` and
183
+ `reason`; `trashed` contains the entries successfully moved by an apply run. Paths are relative to
184
+ the real notes root, bytes are file sizes, and `totalBytes` sums eligible entries (excluding refusals).
185
+ Groups are ordered by source and entries by path. Dry runs have an empty `trashed` array.
186
+ Refusals produce warnings and exit 0. Artifact windows use mtime (strictly older than the window);
187
+ the last matching override wins. Relative Markdown/HTML links (including linked directories) and
188
+ `lifecycle.protect` globs protect artifacts. Symlinks are not traversed or swept.
189
+
190
+ Note lifecycle review uses the same OpenRouter decision model as routing. Paths are relative to
191
+ the resolved notes root. The dry run reports kind, verdict (`fresh`, `stale`, `superseded`,
192
+ `expired`), confidence, repository evidence, cache hits, calls, and provider token usage.
193
+ `review --apply` updates only lifecycle front matter, preserving unknown YAML and body bytes.
194
+ Existing front matter remains reviewable: unrecognized lifecycle values are preserved verbatim,
195
+ treated as absent in the normalized view, and supplied as field-local lifecycle evidence.
196
+ Only lifecycle keys enter that fallback; unrelated front matter is never copied into it.
197
+ Sensitive key values, including block scalars, are masked structurally before model serialization.
198
+ Local reference checks use the complete original bytes, including YAML comments and non-mapping
199
+ headers. The model receives a separate redacted lifecycle projection; local inbound links still
200
+ protect targets on cached reviews.
201
+ Non-finite and cyclic legacy values use JSON-safe representations; their original YAML is preserved.
202
+ `metadataWarnings` identifies each field and redacted value; only unparseable YAML is skipped.
203
+ Recognized lifecycle dates use ISO dates or timestamps.
204
+ Only regular Markdown/HTML files inside the notes root can be reviewed. HTML is dry-run only;
205
+ `--apply` accepts Markdown and uses a locked, checked atomic replacement. Configured issue,
206
+ milestone and archive-projection mounts are excluded by physical path, wherever they live.
207
+ Review-only metadata writes preserve mtime, so reviewing an old note does not make it newly fresh.
208
+ Declared kind corrections invalidate the cache; generated review metadata does not.
209
+ Confidence is exactly the Decisions API probability of the chosen lifecycle label, independent
210
+ of kind probability and the provider's separate confidence metric. Full per-label probabilities
211
+ are returned in `notes[].reviewed.probabilities` and cached with the review. Question revisions
212
+ invalidate old verdicts. The default auto-trash threshold remains 0.9.
213
+ Backlog and feedback retain their own schemas.
214
+
215
+ ```ts
216
+ lifecycle: {
217
+ notes: { autoTrashConfidence: 0.9, minFreshDays: 7, estimatedCostPerCall: 0.001 },
218
+ protect: ["decisions/**"],
219
+ }
220
+ ```
221
+
222
+ OpenRouter-reported cost is used when available, including zero-cost responses. Missing costs
223
+ fall back to calls × `estimatedCostPerCall` in USD and are labeled estimates; the default is a
224
+ configurable budget placeholder, not a provider quote. Mixed runs report the measured subtotal
225
+ and number of estimated calls separately. Cache hits incur no new model cost. Verdicts are cached in the
226
+ project state database by content, evidence and model. Age changes or repository changes
227
+ invalidate the cache. `sweep` consumes only current cached stale/superseded verdicts and never
228
+ calls the model. It protects README/STATE indexes, backlog/feedback, recently updated notes,
229
+ notes linked from a non-stale note, and configured protect globs. Expired model verdicts alone
230
+ do not auto-trash notes. With the classifier disabled, review exits successfully with a clear
231
+ message and sweep handles artifacts only.
232
+
233
+ The classifier uses OpenRouter's Decisions API with pinned default model `typesafe/jev-1.14`.
234
+ Users may select the moving `~typesafe/jev-latest` alias through `classifier.model`. Decision
235
+ models are listed by `GET https://openrouter.ai/api/v1/models?output_modalities=decisions`;
236
+ chat-completion model IDs are a separate catalog.
237
+ Classification and search embeddings share one OpenRouter key. Store it in
238
+ `$XDG_CONFIG_HOME/scratchpad/secrets/openrouter-api-key` (default
239
+ `~/.config/scratchpad/secrets/openrouter-api-key`), or set `SCRATCHPAD_OPENROUTER_API_KEY` to override it.
159
240
  Keep the secrets directory private (`0700`) and the key file readable only by its owner (`0600`).
160
241
  Relative `XDG_CONFIG_HOME` values are ignored. Optionally choose a model
161
242
  with `SCRATCHPAD_CLASSIFIER` or `classifier.model` in `scratchpad.config.ts`
162
- (`SCRATCHPAD_CLASSIFIER=none` disables it). Feedback is redacted before it is
243
+ (`SCRATCHPAD_CLASSIFIER=none` or `classifier.model: "none"` disables it). Model overrides name
244
+ OpenRouter model IDs. Feedback is redacted before it is
163
245
  sent for classification. Feedback files are written first, and classifier
164
246
  failures never block or undo those writes.
165
247
 
166
248
  Every checkout of a project whose mounts resolve to the same files (for example
167
249
  `wt` worktrees linking `.scratchpad` to the primary) shares one local store.
168
250
 
251
+ ### Search notes
252
+
253
+ ```sh
254
+ scratchpad index --rebuild --json
255
+ scratchpad search "deployment decision" --limit 10 --kind decision --json
256
+ scratchpad search "instruction feedback" --global
257
+ ```
258
+
259
+ Search scans the resolved project's Markdown notes before every query, including edits and
260
+ removals. `--kind` matches front matter `kind` exactly; notes without a kind are excluded when
261
+ filtering. Results include the physical path, heading, snippet and reciprocal rank fusion score.
262
+ `--global` also includes `feedback/` under `SCRATCHPAD_GLOBAL_HOME` (default `~/.scratchpad`).
263
+
264
+ Without credentials, commands use SQLite FTS5 and print a notice on stderr (also included in
265
+ JSON). Hybrid search shares the classifier's OpenRouter key: set `SCRATCHPAD_OPENROUTER_API_KEY` or put it in
266
+ `$XDG_CONFIG_HOME/scratchpad/secrets/openrouter-api-key` (default `~/.config/...`), with mode
267
+ `0600`. Hybrid indexing sends note title, heading and chunk text to OpenRouter's
268
+ `qwen/qwen3-embedding-8b` model at 1024 dimensions; queries are sent there too. To opt out even
269
+ when a key is present, set `search: { embeddings: false }` in `scratchpad.config.ts`.
270
+ Config discovery walks upward, so ancestor opt-outs apply too.
271
+
272
+ The rebuildable index lives in `$XDG_STATE_HOME/scratchpad/<project hash>/search/`, beside the
273
+ project sync database. Private (`0700`) caches are separated by the selected physical notes roots,
274
+ so toggling `--global` or switching worktrees retains each scope’s index. `index --rebuild`
275
+ recreates that scope’s text and vector stores, including corrupt stores. A concurrent refresh or
276
+ native writer returns a busy error; retry after the other operation exits. Linux x64 vector
277
+ search requires an AVX2-capable CPU. Ordinary FTS-only search does not load native bindings.
278
+ Rebuilding a scope with existing vector state briefly loads zvec to check that no native reader or writer has it open, even without a key.
279
+
169
280
  ### Artifacts
170
281
 
171
282
  Hosted immutable Markdown/HTML revisions with review, share, Trash, and
@@ -263,6 +374,18 @@ Most commands accept `--json` for machine-readable output.
263
374
  ```ts
264
375
  export default {
265
376
  repo: "owner/name",
377
+ // Optional: each list replaces the corresponding built-in layout list.
378
+ layout: {
379
+ folders: ["backlog", "research", "maintenance", "artifacts"],
380
+ files: ["README.md", "STATE.md"],
381
+ },
382
+ lifecycle: {
383
+ artifacts: {
384
+ maxAgeDays: 14,
385
+ overrides: [{ path: "artifacts/sre/**", maxAgeDays: 30 }],
386
+ },
387
+ protect: ["artifacts/keep/**"],
388
+ },
266
389
  mounts: [
267
390
  {
268
391
  provider: "github",