@aryasaatvik/scratchpad 0.6.1 → 0.6.3
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 +15 -0
- package/README.md +71 -378
- package/dist/scratchpad.js +123 -49
- package/docs/adr/0003-github-provider-seam.md +7 -0
- package/docs/adr/0008-cli-decision-model.md +2 -1
- package/docs/adr/0010-openrouter-decisions-and-note-lifecycle.md +71 -0
- package/docs/adr/0011-trash-instead-of-archive-folders.md +46 -0
- package/docs/adr/0012-local-hybrid-search.md +46 -0
- package/docs/adr/README.md +4 -1
- package/docs/artifacts.md +79 -0
- package/docs/backlog-sync.md +97 -0
- package/docs/codemaps.md +28 -0
- package/docs/configuration.md +127 -0
- package/docs/deploy.md +75 -0
- package/docs/feedback.md +71 -0
- package/docs/lifecycle.md +126 -0
- package/docs/notes.md +83 -0
- package/docs/production-smoke.md +75 -0
- package/docs/release.md +3 -3
- package/docs/search.md +48 -0
- package/package.json +3 -4
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Backlog sync with GitHub
|
|
2
|
+
|
|
3
|
+
Scratchpad can project a repository's GitHub issues and milestones to Markdown files with typed
|
|
4
|
+
YAML front matter, and push local edits back. This is optional: it needs `scratchpad init` and a
|
|
5
|
+
`scratchpad.config.ts` with `repo` set. The notes commands in [notes.md](notes.md) work without it.
|
|
6
|
+
|
|
7
|
+
## Commands
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
scratchpad init # scaffold scratchpad.config.ts + mount dirs + local store
|
|
11
|
+
scratchpad status # repo, mounts, pending pushes, open conflicts
|
|
12
|
+
scratchpad pull # GitHub -> Markdown files (incremental, by cursor)
|
|
13
|
+
scratchpad push # queued local changes -> GitHub
|
|
14
|
+
scratchpad sync # pull then push
|
|
15
|
+
scratchpad watch # daemon: turn local file edits into queued changes
|
|
16
|
+
scratchpad repair # resolve conflicts (interactive, or --take-local/--take-remote)
|
|
17
|
+
scratchpad delete # explicitly delete a mapped remote issue/milestone (--remote)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Workflow
|
|
21
|
+
|
|
22
|
+
In a project directory run `scratchpad init`, edit `scratchpad.config.ts` and set `repo` to
|
|
23
|
+
`owner/name`, then pull:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
bunx @aryasaatvik/scratchpad init
|
|
27
|
+
bunx @aryasaatvik/scratchpad pull
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Make local edits under the configured `.scratchpad/backlog` mount, then preview and apply the
|
|
31
|
+
provider updates:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
bunx @aryasaatvik/scratchpad push --dry-run
|
|
35
|
+
bunx @aryasaatvik/scratchpad push
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The repository includes a basic example, `examples/basic`:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
cd examples/basic
|
|
42
|
+
bun run status
|
|
43
|
+
bun run plan
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`plan` runs `scratchpad push --dry-run`, so it shows the GitHub create operations Scratchpad would
|
|
47
|
+
perform without calling the provider.
|
|
48
|
+
|
|
49
|
+
## Dry runs
|
|
50
|
+
|
|
51
|
+
`pull` / `push` / `sync` accept `--dry-run`, which prints the planned actions without mutating
|
|
52
|
+
files, the queue, or the provider.
|
|
53
|
+
|
|
54
|
+
## Delete semantics
|
|
55
|
+
|
|
56
|
+
Deleting a tracked backlog file is non-destructive remotely: `push` closes the issue or archives
|
|
57
|
+
the milestone. Hard provider deletion is deliberately separate: `scratchpad delete --file <path>
|
|
58
|
+
--remote` deletes the mapped remote object, removes the local file, and removes the projection
|
|
59
|
+
mapping. Live remote deletes require `--yes` or an interactive TTY confirmation; `--dry-run`
|
|
60
|
+
reports the planned delete without mutating anything. Remote deletion is available only through
|
|
61
|
+
this explicit command, not through filesystem removal. See
|
|
62
|
+
[ADR 0007](adr/0007-explicit-remote-delete.md).
|
|
63
|
+
|
|
64
|
+
## Backlog file contract
|
|
65
|
+
|
|
66
|
+
Backlog files follow the Scratchpad skill's contract: `status` is free text in the repository's
|
|
67
|
+
own vocabulary, the title is the first `# ` heading, and `milestone` / `depends_on` are paths
|
|
68
|
+
relative to the file that contains them, so issues and milestones may be nested in subfolders of
|
|
69
|
+
`backlog/issues/` and `backlog/milestones/`.
|
|
70
|
+
|
|
71
|
+
A status whose first word is in `backlog.closedStatuses` (default `done`, `complete(d)`,
|
|
72
|
+
`closed`, `merged`, `landed`, `delivered`, `cancel(l)ed`, `superseded`, `implemented`,
|
|
73
|
+
`historical`, `moved`) syncs as closed; anything else is open. Files in the older shape (`title`,
|
|
74
|
+
`state: open|closed` in front matter) still read, and are rewritten in the new shape on the next
|
|
75
|
+
sync.
|
|
76
|
+
|
|
77
|
+
`scratchpad backlog new` and `backlog validate | graph` create and check these files; see
|
|
78
|
+
[notes.md](notes.md#backlog-notes).
|
|
79
|
+
|
|
80
|
+
## Archive mount
|
|
81
|
+
|
|
82
|
+
The backlog mount holds open work only. With an optional `archive` block, objects closed within
|
|
83
|
+
`closedWithinDays` project to a separate read-only mount (older closures project nowhere, and
|
|
84
|
+
aged-out files are pruned on the next `pull`). Editing or deleting an archived file does nothing;
|
|
85
|
+
only the backlog mount is writable. See [ADR 0005](adr/0005-closed-object-archive.md). Config
|
|
86
|
+
keys: [configuration.md](configuration.md#mounts).
|
|
87
|
+
|
|
88
|
+
## Auth
|
|
89
|
+
|
|
90
|
+
Auth resolves `GITHUB_TOKEN` / `GH_TOKEN`, then `gh auth token`.
|
|
91
|
+
|
|
92
|
+
## Local store
|
|
93
|
+
|
|
94
|
+
The SQLite store lives under `$XDG_STATE_HOME/scratchpad/<project-hash>/store.db`, never in the
|
|
95
|
+
repo. It is local durability (mappings, cursors, outbox, conflicts), not product truth: the
|
|
96
|
+
Markdown files and the provider are the system of record for backlog sync. Every checkout of a
|
|
97
|
+
project whose mounts resolve to the same files shares one store.
|
package/docs/codemaps.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Codemaps
|
|
2
|
+
|
|
3
|
+
Local, evidence-backed architecture maps. Canonical JSON plus a self-contained HTML viewer live
|
|
4
|
+
under ignored `.scratchpad/codemaps/<name>/<timestamp>/`. No Worker profile is required.
|
|
5
|
+
|
|
6
|
+
```
|
|
7
|
+
scratchpad skills get codemap # print the bundled producer skill
|
|
8
|
+
scratchpad codemap create --name <name> --input <draft.json>
|
|
9
|
+
scratchpad codemap validate --name <name> [--snapshot <ts>]
|
|
10
|
+
scratchpad codemap render --name <name> [--snapshot <ts>]
|
|
11
|
+
scratchpad codemap list [--name <name>] [--json]
|
|
12
|
+
scratchpad codemap open --name <name> [--snapshot <ts>] [--editor auto|code|cursor|zed]
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Flow
|
|
16
|
+
|
|
17
|
+
1. Emit the producer skill with `scratchpad skills get codemap`.
|
|
18
|
+
2. Have an agent write a `CodemapDraft`.
|
|
19
|
+
3. Create the bundle with `codemap create`.
|
|
20
|
+
4. Open the newest snapshot with `codemap open` on a secured loopback session. Source clicks use a
|
|
21
|
+
per-session token to open paths inside the scanned repository only.
|
|
22
|
+
|
|
23
|
+
Validation reports `fresh` / `stale` / `unverifiable` against the current HEAD and dirty
|
|
24
|
+
fingerprint; stale snapshots still open with a warning.
|
|
25
|
+
|
|
26
|
+
Local codemaps are ignored working memory until an explicit later publish path exists. Hosted
|
|
27
|
+
artifacts, by contrast, are immutable presentation and review surfaces; see
|
|
28
|
+
[artifacts.md](artifacts.md).
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Configuration
|
|
2
|
+
|
|
3
|
+
Most agent commands need no configuration. `scratchpad.config.ts` at the project root configures
|
|
4
|
+
layout, lifecycle, search, the classifier, and, for backlog sync, the repository and mounts.
|
|
5
|
+
`scratchpad init` scaffolds it. Keys are defined in
|
|
6
|
+
[`packages/core/src/config.ts`](../packages/core/src/config.ts).
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
export default {
|
|
10
|
+
repo: "owner/name",
|
|
11
|
+
// Optional: each list replaces the corresponding built-in layout list.
|
|
12
|
+
layout: {
|
|
13
|
+
folders: ["backlog", "research", "maintenance", "artifacts"],
|
|
14
|
+
files: ["README.md", "STATE.md"],
|
|
15
|
+
},
|
|
16
|
+
lifecycle: {
|
|
17
|
+
artifacts: {
|
|
18
|
+
maxAgeDays: 14,
|
|
19
|
+
overrides: [{ path: "artifacts/sre/**", maxAgeDays: 30 }],
|
|
20
|
+
},
|
|
21
|
+
notes: { autoTrashConfidence: 0.9, minFreshDays: 7, estimatedCostPerCall: 0.001 },
|
|
22
|
+
protect: ["artifacts/keep/**"],
|
|
23
|
+
},
|
|
24
|
+
search: { embeddings: true },
|
|
25
|
+
classifier: { model: "typesafe/jev-1.14" },
|
|
26
|
+
backlog: { closedStatuses: ["done", "merged"] },
|
|
27
|
+
mounts: [
|
|
28
|
+
{
|
|
29
|
+
provider: "github",
|
|
30
|
+
issues: ".scratchpad/backlog/issues",
|
|
31
|
+
milestones: ".scratchpad/backlog/milestones",
|
|
32
|
+
// Optional: project recently-closed objects to a read-only archive.
|
|
33
|
+
archive: {
|
|
34
|
+
issues: ".scratchpad/archive/issues",
|
|
35
|
+
milestones: ".scratchpad/archive/milestones",
|
|
36
|
+
closedWithinDays: 7,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Keys
|
|
44
|
+
|
|
45
|
+
### `repo`
|
|
46
|
+
|
|
47
|
+
Target repository as `owner/name`. Required by the schema; used by backlog sync.
|
|
48
|
+
|
|
49
|
+
### `mounts`
|
|
50
|
+
|
|
51
|
+
Each mount has `provider: "github"`, `issues`, and `milestones` directories. The backlog mount
|
|
52
|
+
holds open work only. The optional `archive` block (`issues`, `milestones`, `closedWithinDays`)
|
|
53
|
+
projects objects closed within `closedWithinDays` to a separate read-only mount; the value must be
|
|
54
|
+
positive and is checked when the config loads. See [backlog-sync.md](backlog-sync.md#archive-mount)
|
|
55
|
+
and [ADR 0005](adr/0005-closed-object-archive.md).
|
|
56
|
+
|
|
57
|
+
### `backlog`
|
|
58
|
+
|
|
59
|
+
`closedStatuses`: status tokens that sync as closed. See
|
|
60
|
+
[backlog-sync.md](backlog-sync.md#backlog-file-contract) for the defaults.
|
|
61
|
+
|
|
62
|
+
### `layout`
|
|
63
|
+
|
|
64
|
+
`folders` and `files` list the allowed top-level entries of the notes root. An omitted list uses
|
|
65
|
+
the default: folders `backlog`, `research`, `reference`, `feedback`, `handoffs`, `decisions`,
|
|
66
|
+
`delivery`, `maintenance`, `artifacts`, `codemaps`; files `README.md`, `STATE.md`. A list given here replaces
|
|
67
|
+
the default list. `scratchpad doctor` reports drift; see [notes.md](notes.md#doctor).
|
|
68
|
+
|
|
69
|
+
### `lifecycle`
|
|
70
|
+
|
|
71
|
+
- `artifacts.maxAgeDays`: artifact expiry window in days (greater than 0; default 14).
|
|
72
|
+
`artifacts.overrides` is a list of `{ path, maxAgeDays }` glob overrides; the last matching
|
|
73
|
+
override wins.
|
|
74
|
+
- `notes.autoTrashConfidence`: 0 to 1, default 0.9. Cached stale/superseded verdicts at or above
|
|
75
|
+
it are auto-trashed by `sweep --apply`.
|
|
76
|
+
- `notes.minFreshDays`: at least 0, default 7. Recently updated notes are protected.
|
|
77
|
+
- `notes.estimatedCostPerCall`: at least 0, USD, default 0.001. Fallback when OpenRouter reports
|
|
78
|
+
no cost; labeled an estimate.
|
|
79
|
+
- `protect`: globs of notes and artifacts that `sweep` never removes. Manual `archive` does not
|
|
80
|
+
check these globs.
|
|
81
|
+
|
|
82
|
+
Behavior: [lifecycle.md](lifecycle.md).
|
|
83
|
+
|
|
84
|
+
### `search`
|
|
85
|
+
|
|
86
|
+
`embeddings: false` opts out of hybrid search even when an OpenRouter key is present. Config
|
|
87
|
+
discovery walks upward, so ancestor opt-outs apply too. See [search.md](search.md).
|
|
88
|
+
|
|
89
|
+
### `classifier`
|
|
90
|
+
|
|
91
|
+
`model` names an OpenRouter Decisions model; `"none"` disables classification. See
|
|
92
|
+
[feedback.md](feedback.md#classifier).
|
|
93
|
+
|
|
94
|
+
## Environment variables
|
|
95
|
+
|
|
96
|
+
| Variable | Purpose |
|
|
97
|
+
| ------------------------------- | ---------------------------------------------------------- |
|
|
98
|
+
| `GITHUB_TOKEN`, `GH_TOKEN` | GitHub auth, checked in that order before `gh auth token`. |
|
|
99
|
+
| `SCRATCHPAD_OPENROUTER_API_KEY` | OpenRouter key; overrides the secrets file. |
|
|
100
|
+
| `SCRATCHPAD_CLASSIFIER` | Classifier model override; `none` disables it. |
|
|
101
|
+
| `SCRATCHPAD_GLOBAL_HOME` | Host-wide notes home; default `~/.scratchpad`. |
|
|
102
|
+
| `XDG_DATA_HOME` | Fallback notes root `scratchpad/projects/<project-id>`. |
|
|
103
|
+
| `XDG_STATE_HOME` | State store and search index; default `~/.local/state`. |
|
|
104
|
+
| `XDG_CONFIG_HOME` | Secrets and deployment profiles; default `~/.config`. |
|
|
105
|
+
|
|
106
|
+
An empty `XDG_STATE_HOME` or `XDG_DATA_HOME` is treated as unset. `XDG_CONFIG_HOME` must be an
|
|
107
|
+
absolute path; a relative value is ignored.
|
|
108
|
+
|
|
109
|
+
## Secrets
|
|
110
|
+
|
|
111
|
+
The OpenRouter key is shared by classification, note lifecycle review, and search embeddings.
|
|
112
|
+
Store it in `$XDG_CONFIG_HOME/scratchpad/secrets/openrouter-api-key` (default
|
|
113
|
+
`~/.config/scratchpad/secrets/openrouter-api-key`), or set `SCRATCHPAD_OPENROUTER_API_KEY` to
|
|
114
|
+
override it. Keep the secrets directory private (`0700`) and the key file readable only by its
|
|
115
|
+
owner (`0600`). An unreadable or empty key file is an error.
|
|
116
|
+
|
|
117
|
+
Deployment profiles for hosted artifacts live at `$XDG_CONFIG_HOME/scratchpad/deployments.json`;
|
|
118
|
+
see [artifacts.md](artifacts.md).
|
|
119
|
+
|
|
120
|
+
## Where state lives
|
|
121
|
+
|
|
122
|
+
- Notes root: the checkout's `.scratchpad`, else the primary checkout's, else
|
|
123
|
+
`$XDG_DATA_HOME/scratchpad/projects/<project-id>`. See [notes.md](notes.md).
|
|
124
|
+
- Sync store: `$XDG_STATE_HOME/scratchpad/<project-hash>/store.db`, never in the repo. It holds
|
|
125
|
+
mappings, cursors, outbox, conflicts, and cached review verdicts.
|
|
126
|
+
- Search index: `$XDG_STATE_HOME/scratchpad/<project-hash>/search/`, derived and rebuildable.
|
|
127
|
+
- Global feedback: `~/.scratchpad` or `SCRATCHPAD_GLOBAL_HOME`.
|
package/docs/deploy.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Deploy
|
|
2
|
+
|
|
3
|
+
Scratchpad ships from a local machine. There is no CI/CD: checks, the worker
|
|
4
|
+
deploy, and the CLI release all run from `bun` scripts you invoke yourself.
|
|
5
|
+
|
|
6
|
+
## Worker (`scratchpad.arya.sh`)
|
|
7
|
+
|
|
8
|
+
The `apps/worker` Cloudflare Worker hosts the artifact surfaces. Deploy it with
|
|
9
|
+
Wrangler from your own authenticated session:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
bun run check # gate locally — nothing else does
|
|
13
|
+
bun run deploy:dry-run # build + resolve bindings without uploading
|
|
14
|
+
bun run deploy # vite build + wrangler deploy
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`wrangler` authenticates through your `CLOUDFLARE_API_TOKEN` or an interactive
|
|
18
|
+
`wrangler login`; the deploy targets the account that owns the
|
|
19
|
+
`scratchpad` Worker, `scratchpad-artifacts` R2 bucket, and `ARTIFACT_AGENT`
|
|
20
|
+
Durable Object.
|
|
21
|
+
|
|
22
|
+
### Secrets
|
|
23
|
+
|
|
24
|
+
Sequence fences read GitHub as the `scratchpad-app` GitHub App. Set its two
|
|
25
|
+
secrets once per environment; they are not in `wrangler.jsonc` and never leave
|
|
26
|
+
your machine:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
cd apps/worker
|
|
30
|
+
wrangler secret put GITHUB_APP_ID # 4298378
|
|
31
|
+
wrangler secret put GITHUB_APP_PRIVATE_KEY # the PKCS#8 PEM
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Dev reads the same values from `apps/worker/.env` (git-ignored). Do not create
|
|
35
|
+
`apps/worker/.dev.vars`: when it exists, Wrangler ignores every `.env` file and
|
|
36
|
+
GitHub-backed dev loses its credentials. Writing an env file while the Vite dev
|
|
37
|
+
server runs restarts workerd and can leave every route returning 500; change env
|
|
38
|
+
files together with a deliberate dev-server restart.
|
|
39
|
+
|
|
40
|
+
For local renderer work, `.env` also sets
|
|
41
|
+
`RENDERER_ORIGIN=http://html.renderer.localhost:5173` and
|
|
42
|
+
`RENDERER_HOST_SUFFIX=renderer.localhost`, so the same dev server serves the
|
|
43
|
+
isolated renderer. Without them, dev falls back to the production renderer from
|
|
44
|
+
`wrangler.jsonc`, and renderer changes are visible only after a renderer deploy.
|
|
45
|
+
`curl http://html.renderer.localhost:5173/` should return the bootstrap.
|
|
46
|
+
|
|
47
|
+
Grant the app
|
|
48
|
+
access to a repository's owner by installing github.com/apps/scratchpad-app on
|
|
49
|
+
that account — no secret changes when the set of charted repositories grows.
|
|
50
|
+
|
|
51
|
+
### Cloudflare Access bypass for public routes
|
|
52
|
+
|
|
53
|
+
The Worker enforces its own auth in code, but the Cloudflare Access application
|
|
54
|
+
in front of `scratchpad.arya.sh` must let the public route families through or
|
|
55
|
+
anonymous fetches (including GitHub's camo image proxy) hit the Access login
|
|
56
|
+
wall. The Access app needs bypass rules covering:
|
|
57
|
+
|
|
58
|
+
- `/s/*` — shared artifact pages and their assets
|
|
59
|
+
- `/f/*` — unlisted public file uploads
|
|
60
|
+
|
|
61
|
+
This is dashboard (or API) state, not code: adding a new public route family
|
|
62
|
+
means adding a matching bypass rule before it works for anonymous callers.
|
|
63
|
+
|
|
64
|
+
## CLI (`@aryasaatvik/scratchpad`)
|
|
65
|
+
|
|
66
|
+
Tegami owns the changelog, version PR, npm publish, `v<version>` tag, GitHub
|
|
67
|
+
Release, and the compiled release artifacts. Run it locally:
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
bun run tegami pr preview # preview the version-package PR
|
|
71
|
+
bun run tegami pr # open/update it
|
|
72
|
+
bun run release # after the version PR merges: publish + tag + release
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
See [release.md](release.md) for the npm auth and compiled-binary details.
|
package/docs/feedback.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Instruction feedback and routing
|
|
2
|
+
|
|
3
|
+
Agents record corrections and friction as feedback notes. The CLI writes them deterministically and
|
|
4
|
+
may classify them with an optional decision model.
|
|
5
|
+
|
|
6
|
+
## Commands
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
scratchpad feedback new "<text>" [--global] [--harness <h>] [--model <m>] [--session <id>]
|
|
10
|
+
scratchpad feedback normalize [--global] [--dry-run] [--json]
|
|
11
|
+
scratchpad feedback review [--global] [--classify] [--json]
|
|
12
|
+
scratchpad feedback list [--global] [--status <s>] [--disposition <d>]... [--all]
|
|
13
|
+
scratchpad feedback resolve <id|file|path> --disposition <d> --review <name|path> [--evidence <e>]...
|
|
14
|
+
scratchpad route "<correction>" [--write] [--json]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
- `feedback new` writes a feedback file under the notes root's `feedback/`; `--slug` overrides the
|
|
18
|
+
file-name slug derived from the text.
|
|
19
|
+
- `feedback normalize` adopts legacy feedback without changing bodies; preview with
|
|
20
|
+
`feedback normalize --global --dry-run --json`.
|
|
21
|
+
- `feedback review` lists feedback with no disposition or an open disposition; `--classify`
|
|
22
|
+
classifies unclassified entries first and needs a classifier.
|
|
23
|
+
- `feedback list` filters by status (`new`, `review`, `classified`) and disposition (repeatable);
|
|
24
|
+
`--all` includes dismissed, installed, and verified occurrences.
|
|
25
|
+
- `feedback resolve` records a review disposition (`open`, `deferred`, `dismissed`, `source-fixed`,
|
|
26
|
+
`installed`, `verified`) on one occurrence. The occurrence is the id after the last `-` in the
|
|
27
|
+
file name, the file name with or without `.md`, or a path. `--review` names the review record in
|
|
28
|
+
`feedback/reviews/` (this scope's, then the global one) or a path; `--evidence` takes a commit,
|
|
29
|
+
PR URL, or path and is repeatable.
|
|
30
|
+
- `route` suggests which instruction layer a correction belongs to; `--write` also records it as a
|
|
31
|
+
feedback file.
|
|
32
|
+
|
|
33
|
+
## Global feedback home
|
|
34
|
+
|
|
35
|
+
`--global` feedback lives in `~/.scratchpad` (override with `SCRATCHPAD_GLOBAL_HOME`). Use it for
|
|
36
|
+
corrections that apply across projects. `scratchpad search --global` includes its `feedback/`
|
|
37
|
+
folder; see [search.md](search.md).
|
|
38
|
+
|
|
39
|
+
## Classifier
|
|
40
|
+
|
|
41
|
+
The classifier uses OpenRouter's Decisions API through `@effect/ai-openrouter`, with the pinned
|
|
42
|
+
default model `typesafe/jev-1.14`. Users may select the moving `~typesafe/jev-latest` alias through
|
|
43
|
+
`classifier.model`. Decision models are listed by
|
|
44
|
+
`GET https://openrouter.ai/api/v1/models?output_modalities=decisions`; chat-completion model IDs
|
|
45
|
+
are a separate catalog and are not valid here.
|
|
46
|
+
|
|
47
|
+
Model selection, in order: `SCRATCHPAD_CLASSIFIER`, then `classifier.model` in
|
|
48
|
+
`scratchpad.config.ts`, then the pinned default. `SCRATCHPAD_CLASSIFIER=none` or
|
|
49
|
+
`classifier.model: "none"` disables it. Model overrides name OpenRouter model IDs.
|
|
50
|
+
|
|
51
|
+
Classification and search embeddings share one OpenRouter key. Store it in
|
|
52
|
+
`$XDG_CONFIG_HOME/scratchpad/secrets/openrouter-api-key` (default
|
|
53
|
+
`~/.config/scratchpad/secrets/openrouter-api-key`), or set `SCRATCHPAD_OPENROUTER_API_KEY` to
|
|
54
|
+
override it. Keep the secrets directory private (`0700`) and the key file readable only by its
|
|
55
|
+
owner (`0600`). Relative `XDG_CONFIG_HOME` values are ignored. See
|
|
56
|
+
[configuration.md](configuration.md#secrets).
|
|
57
|
+
|
|
58
|
+
The same decision model also reviews note lifecycle; see [lifecycle.md](lifecycle.md) and
|
|
59
|
+
[ADR 0010](adr/0010-openrouter-decisions-and-note-lifecycle.md).
|
|
60
|
+
|
|
61
|
+
## Redaction
|
|
62
|
+
|
|
63
|
+
Feedback is redacted before it is sent for classification: tokens, keys, private keys, and email
|
|
64
|
+
addresses never leave the process. Redaction is best-effort pattern matching biased toward
|
|
65
|
+
over-redacting, so feedback text should not contain customer data.
|
|
66
|
+
|
|
67
|
+
## Writes first
|
|
68
|
+
|
|
69
|
+
Feedback files are written first, and classifier failures never block or undo those writes. A
|
|
70
|
+
timeout, provider error, or low confidence yields a warning or the review bucket, never a failed
|
|
71
|
+
command. Without a key, or with the classifier disabled, every command still works.
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# Note lifecycle: review, sweep, archive
|
|
2
|
+
|
|
3
|
+
Notes accumulate. The lifecycle commands classify them against repository evidence and retire the
|
|
4
|
+
stale ones to the operating system's Trash, where they stay recoverable.
|
|
5
|
+
|
|
6
|
+
```
|
|
7
|
+
scratchpad archive <paths...> --reason "<why>" # move notes or directories to the OS Trash
|
|
8
|
+
scratchpad review [paths...] [--apply] [--json] [--limit 100] # classify notes; --apply writes metadata
|
|
9
|
+
scratchpad sweep [--apply] [--json] # preview expired artifacts; --apply moves to Trash
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
`archive` moves the given paths to Trash immediately; it has no preview. `sweep --apply` moves
|
|
13
|
+
files to Trash and `review --apply` writes lifecycle front matter; without `--apply` both only
|
|
14
|
+
report. Run `review` and `sweep` without `--apply` first.
|
|
15
|
+
|
|
16
|
+
## Archive
|
|
17
|
+
|
|
18
|
+
`archive` retires local notes to the operating system's Trash and appends receipts to
|
|
19
|
+
`maintenance/trash-log.md`. It no longer creates dated directories under `archive/`. Paths are
|
|
20
|
+
relative to the notes root (omit the `.scratchpad/` prefix) and may be files or directories.
|
|
21
|
+
`--reason` is recorded in the receipt.
|
|
22
|
+
|
|
23
|
+
This local-note lifecycle is separate from the optional read-only GitHub archive mount described in
|
|
24
|
+
[backlog-sync.md](backlog-sync.md#archive-mount).
|
|
25
|
+
|
|
26
|
+
## Trash and receipts
|
|
27
|
+
|
|
28
|
+
Trash uses `/usr/bin/trash` on macOS and `gio trash` on Linux; other platforms report an
|
|
29
|
+
unsupported-platform error. Each move first writes and flushes a `pending` receipt, then appends
|
|
30
|
+
`trashed`, `failed`, or `skipped-changed` with the same id. An unmatched pending receipt means the
|
|
31
|
+
operation needs reconciliation against the source and OS Trash; do not automatically retry it. A
|
|
32
|
+
later failure does not undo earlier moves.
|
|
33
|
+
|
|
34
|
+
## Sweep
|
|
35
|
+
|
|
36
|
+
`sweep` previews expired artifacts with byte totals; `--apply` moves eligible entries to Trash and
|
|
37
|
+
records receipts. Markdown and HTML files are notes, so artifact expiry does not remove them.
|
|
38
|
+
Existing `archive/` contents may contain expired artifacts. Unwritable entries are reported as
|
|
39
|
+
refused, allowing other eligible entries to proceed.
|
|
40
|
+
|
|
41
|
+
Artifact windows use mtime (strictly older than the window); the last matching override wins.
|
|
42
|
+
Relative Markdown/HTML links (including linked directories) and `lifecycle.protect` globs protect
|
|
43
|
+
artifacts. Symlinks are not traversed or swept. Windows come from `lifecycle.artifacts`; see
|
|
44
|
+
[configuration.md](configuration.md#lifecycle).
|
|
45
|
+
|
|
46
|
+
`sweep` also consumes cached note verdicts, as described under [Review](#review). It never calls
|
|
47
|
+
the model.
|
|
48
|
+
|
|
49
|
+
### Sweep JSON, version 1
|
|
50
|
+
|
|
51
|
+
`sweep --json` emits version 1 of the report: `version: 1`, `apply`, `groups`, `totalBytes`,
|
|
52
|
+
`refused`, `warningCount`, and `trashed`. Each group contains `source`, `entries`, and `bytes`;
|
|
53
|
+
entries contain `path`, `bytes`, `reason`, and `source`. Refused entries contain `path` and
|
|
54
|
+
`reason`; `trashed` contains the entries successfully moved by an apply run. Paths are relative to
|
|
55
|
+
the real notes root, bytes are file sizes, and `totalBytes` sums eligible entries (excluding
|
|
56
|
+
refusals). Groups are ordered by source and entries by path. Dry runs have an empty `trashed`
|
|
57
|
+
array. Refusals produce warnings and exit 0.
|
|
58
|
+
|
|
59
|
+
## Review
|
|
60
|
+
|
|
61
|
+
Note lifecycle review uses the same OpenRouter decision model as routing; see
|
|
62
|
+
[feedback.md](feedback.md#classifier). Paths are relative to the resolved notes root. The dry run
|
|
63
|
+
reports kind, verdict (`fresh`, `stale`, `superseded`, `expired`), confidence, repository evidence,
|
|
64
|
+
cache hits, calls, and provider token usage. `review --apply` updates only lifecycle front matter,
|
|
65
|
+
preserving unknown YAML and body bytes. Backlog and feedback retain their own schemas.
|
|
66
|
+
|
|
67
|
+
### Scope
|
|
68
|
+
|
|
69
|
+
Only regular Markdown/HTML files inside the notes root can be reviewed. HTML is dry-run only;
|
|
70
|
+
`--apply` accepts Markdown and uses a locked, checked atomic replacement. Configured issue,
|
|
71
|
+
milestone and archive-projection mounts are excluded by physical path, wherever they live.
|
|
72
|
+
Review-only metadata writes preserve mtime, so reviewing an old note does not make it newly fresh.
|
|
73
|
+
|
|
74
|
+
### Confidence and probabilities
|
|
75
|
+
|
|
76
|
+
Confidence is exactly the Decisions API probability of the chosen lifecycle label, independent of
|
|
77
|
+
kind probability and the provider's separate confidence metric. Full per-label probabilities are
|
|
78
|
+
returned in `notes[].reviewed.probabilities` and cached with the review. Question revisions
|
|
79
|
+
invalidate old verdicts. See [ADR 0010](adr/0010-openrouter-decisions-and-note-lifecycle.md).
|
|
80
|
+
|
|
81
|
+
### Cache
|
|
82
|
+
|
|
83
|
+
Verdicts are cached in the project state database by content, evidence and model. Age changes or
|
|
84
|
+
repository changes invalidate the cache. Declared kind corrections invalidate the cache; generated
|
|
85
|
+
review metadata does not. Cache hits incur no new model cost.
|
|
86
|
+
|
|
87
|
+
### Legacy metadata and redaction
|
|
88
|
+
|
|
89
|
+
Existing front matter remains reviewable: unrecognized lifecycle values are preserved verbatim,
|
|
90
|
+
treated as absent in the normalized view, and supplied as field-local lifecycle evidence. Only
|
|
91
|
+
lifecycle keys enter that fallback; unrelated front matter is never copied into it. Recognized
|
|
92
|
+
lifecycle dates use ISO dates or timestamps.
|
|
93
|
+
|
|
94
|
+
Sensitive key values, including block scalars, are masked structurally before model serialization.
|
|
95
|
+
Local reference checks use the complete original bytes, including YAML comments and non-mapping
|
|
96
|
+
headers. The model receives a separate redacted lifecycle projection; local inbound links still
|
|
97
|
+
protect targets on cached reviews. Non-finite and cyclic legacy values use JSON-safe
|
|
98
|
+
representations; their original YAML is preserved. `metadataWarnings` identifies each field and
|
|
99
|
+
redacted value; only unparseable YAML is skipped.
|
|
100
|
+
|
|
101
|
+
### Cost accounting
|
|
102
|
+
|
|
103
|
+
OpenRouter-reported cost is used when available, including zero-cost responses. Missing costs fall
|
|
104
|
+
back to calls x `estimatedCostPerCall` in USD and are labeled estimates; the default is a
|
|
105
|
+
configurable budget placeholder, not a provider quote. Mixed runs report the measured subtotal and
|
|
106
|
+
number of estimated calls separately.
|
|
107
|
+
|
|
108
|
+
### What sweep auto-trashes
|
|
109
|
+
|
|
110
|
+
`sweep` consumes only current cached stale/superseded verdicts at or above `autoTrashConfidence`
|
|
111
|
+
(default 0.9). It protects README/STATE indexes, backlog/feedback, recently updated notes
|
|
112
|
+
(`minFreshDays`, default 7), notes linked from a non-stale note, and configured protect globs.
|
|
113
|
+
Expired model verdicts alone do not auto-trash notes. With the classifier disabled, review exits
|
|
114
|
+
successfully with a clear message and sweep handles artifacts only.
|
|
115
|
+
|
|
116
|
+
## Lifecycle config
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
lifecycle: {
|
|
120
|
+
notes: { autoTrashConfidence: 0.9, minFreshDays: 7, estimatedCostPerCall: 0.001 },
|
|
121
|
+
protect: ["decisions/**"],
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
The full key reference is in [configuration.md](configuration.md#lifecycle). The decision record
|
|
126
|
+
is [ADR 0011](adr/0011-trash-instead-of-archive-folders.md).
|
package/docs/notes.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Notes root and layout
|
|
2
|
+
|
|
3
|
+
Scratchpad keeps a project's working memory as Markdown files in one directory, the notes root.
|
|
4
|
+
These commands need no `scratchpad.config.ts`.
|
|
5
|
+
|
|
6
|
+
## Notes root resolution
|
|
7
|
+
|
|
8
|
+
The notes root of a project is, in order:
|
|
9
|
+
|
|
10
|
+
1. the checkout's `.scratchpad`,
|
|
11
|
+
2. else the primary checkout's `.scratchpad`,
|
|
12
|
+
3. else `$XDG_DATA_HOME/scratchpad/projects/<project-id>`.
|
|
13
|
+
|
|
14
|
+
The project id is the origin remote, for example `github.com/owner/repo`. Outside a Git repository
|
|
15
|
+
the project id is local to the directory.
|
|
16
|
+
|
|
17
|
+
Every checkout of a project whose mounts resolve to the same files (for example `wt` worktrees
|
|
18
|
+
linking `.scratchpad` to the primary checkout) shares one notes root and one local store. Agents
|
|
19
|
+
running in different worktrees therefore read and write the same notes.
|
|
20
|
+
|
|
21
|
+
## Commands
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
scratchpad path [--global] [--real] # print the notes root; --real resolves symlinks
|
|
25
|
+
scratchpad doctor # project id, layout drift, store, token
|
|
26
|
+
scratchpad skills list | path # skills embedded in this CLI
|
|
27
|
+
scratchpad skills get <name> [--full | --ref <reference>]
|
|
28
|
+
scratchpad backlog new <issue|milestone> "<title>" [--milestone <slug>] [--depends-on <path>]
|
|
29
|
+
scratchpad backlog validate | graph # decode, check fields, links and cycles; show the tree
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### `path`
|
|
33
|
+
|
|
34
|
+
`path` keeps the selected notes path by default, including a worktree's `.scratchpad` symlink.
|
|
35
|
+
Use `path --real` when an agent needs the physical storage path for writes. It preserves the same
|
|
36
|
+
plain-text or JSON output shape, works with `--global`, and fails if the selected root is missing
|
|
37
|
+
or inaccessible; it never creates the directory.
|
|
38
|
+
|
|
39
|
+
`--global` selects the host-wide notes home instead: `~/.scratchpad`, overridable with
|
|
40
|
+
`SCRATCHPAD_GLOBAL_HOME`. Global instruction feedback lives there; see [feedback.md](feedback.md).
|
|
41
|
+
|
|
42
|
+
### `doctor`
|
|
43
|
+
|
|
44
|
+
`doctor` checks the notes root's top-level entries against `layout` in `scratchpad.config.ts`.
|
|
45
|
+
It reports unlisted folders and loose files, without moving them or inspecting nested layout.
|
|
46
|
+
The JSON report adds `layout` with `folders`, `files`, `rootExists`, `outOfLayoutFolders`, and
|
|
47
|
+
`looseFiles`. A missing notes root is reported without creating it. Omitted lists use the defaults:
|
|
48
|
+
|
|
49
|
+
- Folders: `backlog`, `research`, `reference`, `feedback`, `handoffs`, `decisions`, `delivery`,
|
|
50
|
+
`maintenance`, `artifacts`, `codemaps`.
|
|
51
|
+
- Files: `README.md`, `STATE.md`.
|
|
52
|
+
|
|
53
|
+
A list given in config replaces the corresponding default list; see
|
|
54
|
+
[configuration.md](configuration.md#layout).
|
|
55
|
+
|
|
56
|
+
`doctor` also reports the project id, notes root and its source, whether a config was found, the
|
|
57
|
+
state store, the selected classifier model and whether it is enabled, and GitHub auth availability.
|
|
58
|
+
|
|
59
|
+
### Skills
|
|
60
|
+
|
|
61
|
+
`scratchpad skills get scratchpad` prints the agent skill that drives these commands. Its source is
|
|
62
|
+
[`packages/cli/skill-data/scratchpad/`](../packages/cli/skill-data/scratchpad/). Skills are embedded
|
|
63
|
+
in the CLI, so the instructions an agent reads match the CLI version it runs. The `codemap` skill
|
|
64
|
+
is printed with `scratchpad skills get codemap`; see [codemaps.md](codemaps.md).
|
|
65
|
+
|
|
66
|
+
### Backlog notes
|
|
67
|
+
|
|
68
|
+
`backlog new` creates an issue or milestone file under the notes root's `backlog/`. `backlog
|
|
69
|
+
validate` decodes the files and checks fields, links, and cycles; `backlog graph` shows the tree.
|
|
70
|
+
Their file contract and the GitHub sync built on it are described in
|
|
71
|
+
[backlog-sync.md](backlog-sync.md).
|
|
72
|
+
|
|
73
|
+
## Store sharing
|
|
74
|
+
|
|
75
|
+
The local SQLite store is derived state, kept under `$XDG_STATE_HOME/scratchpad/<project-hash>/`
|
|
76
|
+
and never in the repository; see [configuration.md](configuration.md#where-state-lives).
|
|
77
|
+
Checkouts that resolve to the same files share it.
|
|
78
|
+
|
|
79
|
+
## Related
|
|
80
|
+
|
|
81
|
+
- Local note retirement: [lifecycle.md](lifecycle.md)
|
|
82
|
+
- Note search: [search.md](search.md)
|
|
83
|
+
- Instruction feedback: [feedback.md](feedback.md)
|