@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.
@@ -29719,7 +29719,8 @@ var DEFAULT_LAYOUT = {
29719
29719
  "decisions",
29720
29720
  "delivery",
29721
29721
  "maintenance",
29722
- "artifacts"
29722
+ "artifacts",
29723
+ "codemaps"
29723
29724
  ],
29724
29725
  files: ["README.md", "STATE.md"]
29725
29726
  };
@@ -51973,8 +51974,8 @@ var bundleHtml = async (options) => {
51973
51974
  // package.json
51974
51975
  var package_default = {
51975
51976
  name: "@aryasaatvik/scratchpad",
51976
- version: "0.6.1",
51977
- description: "Local-first GitHub issue and milestone tracking, hosted artifacts and uploads, and local architecture codemaps.",
51977
+ version: "0.6.3",
51978
+ description: "Working memory for coding agents: project notes shared across worktrees, instruction feedback, note search and lifecycle cleanup, plus GitHub backlog sync, hosted artifacts and codemaps.",
51978
51979
  keywords: [
51979
51980
  "bun",
51980
51981
  "cli",
@@ -52013,8 +52014,7 @@ var package_default = {
52013
52014
  "LICENSE",
52014
52015
  "CHANGELOG.md",
52015
52016
  "SECURITY.md",
52016
- "docs/adr",
52017
- "docs/release.md"
52017
+ "docs"
52018
52018
  ],
52019
52019
  type: "module",
52020
52020
  publishConfig: {
@@ -55458,6 +55458,26 @@ var searchError = (cause) => cause instanceof SearchError || cause instanceof Se
55458
55458
  // packages/cli/src/search/embeddings.ts
55459
55459
  var DIMENSIONS = 1024;
55460
55460
  var MODEL = "qwen/qwen3-embedding-8b";
55461
+ var EMBED_REQUEST_SIZE = 64;
55462
+ var EMBED_CONCURRENCY = 8;
55463
+ var mapConcurrent = async (items, limit, f) => {
55464
+ const results = new Array(items.length);
55465
+ let next = 0;
55466
+ let failed = false;
55467
+ const worker = async () => {
55468
+ while (!failed && next < items.length) {
55469
+ const i = next++;
55470
+ try {
55471
+ results[i] = await f(items[i]);
55472
+ } catch (cause) {
55473
+ failed = true;
55474
+ throw cause;
55475
+ }
55476
+ }
55477
+ };
55478
+ await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
55479
+ return results;
55480
+ };
55461
55481
  var Response2 = Struct({
55462
55482
  data: ArraySchema(Struct({
55463
55483
  index: Number6,
@@ -55467,9 +55487,10 @@ var Response2 = Struct({
55467
55487
  var openRouter = (key) => ({
55468
55488
  identity: `${MODEL}:${DIMENSIONS}:v1`,
55469
55489
  async embed(texts) {
55470
- const vectors = [];
55471
- for (let offset = 0;offset < texts.length; offset += 64) {
55472
- const input = texts.slice(offset, offset + 64);
55490
+ const batches = [];
55491
+ for (let offset = 0;offset < texts.length; offset += EMBED_REQUEST_SIZE)
55492
+ batches.push(texts.slice(offset, offset + EMBED_REQUEST_SIZE));
55493
+ const results = await mapConcurrent(batches, EMBED_CONCURRENCY, async (input) => {
55473
55494
  const response = await fetch("https://openrouter.ai/api/v1/embeddings", {
55474
55495
  method: "POST",
55475
55496
  signal: AbortSignal.timeout(60000),
@@ -55487,9 +55508,9 @@ var openRouter = (key) => ({
55487
55508
  throw new SearchError({
55488
55509
  message: "Embedding response has invalid indexes, count or dimensions"
55489
55510
  });
55490
- vectors.push(...data.map((d) => [...d.embedding]));
55491
- }
55492
- return vectors;
55511
+ return data.map((d) => [...d.embedding]);
55512
+ });
55513
+ return results.flat();
55493
55514
  }
55494
55515
  });
55495
55516
  var embed = (embedder, texts) => tryPromise2({ try: () => embedder.embed(texts), catch: searchError });
@@ -55729,6 +55750,24 @@ var inBatches = (items, write) => {
55729
55750
  results.push(...write(items.slice(i, i + VECTOR_WRITE_BATCH)));
55730
55751
  return results;
55731
55752
  };
55753
+ var EMBED_GROUP_CHUNKS = 512;
55754
+ var groupByChunks = (notes, size) => {
55755
+ const groups = [];
55756
+ let group = [];
55757
+ let count = 0;
55758
+ for (const note of notes) {
55759
+ group.push(note);
55760
+ count += note.pending.length;
55761
+ if (count >= size) {
55762
+ groups.push(group);
55763
+ group = [];
55764
+ count = 0;
55765
+ }
55766
+ }
55767
+ if (group.length)
55768
+ groups.push(group);
55769
+ return groups;
55770
+ };
55732
55771
  var Metadata = Struct({
55733
55772
  title: optional2(String5),
55734
55773
  kind: optional2(String5)
@@ -55819,9 +55858,10 @@ var run6 = fn2("Search.run")(function* (options, query) {
55819
55858
  const vectorWriter = options.embedder ? yield* acquireRelease2(tryPromise2({ try: () => writer(vectorPath), catch: searchError }), (c) => sync2(() => c.closeSync())) : undefined;
55820
55859
  const vectorEmpty = vectorWriter?.stats.docCount === 0;
55821
55860
  let changed = 0;
55861
+ const embeddingIdentity = options.embedder?.identity;
55862
+ const prepared = [];
55822
55863
  for (const [path, text] of sources) {
55823
55864
  const fileHash = hash3(text);
55824
- const embeddingIdentity = options.embedder?.identity;
55825
55865
  const needsVectors = embeddingIdentity !== undefined && (vectorEmpty || (oldByPath.get(path) ?? []).some((c) => c.notePath === path && c.vectorHash !== hash3(`${embeddingIdentity}:${c.contentHash}`)));
55826
55866
  if (!options.rebuild && files.get(path) === fileHash && !needsVectors)
55827
55867
  continue;
@@ -55836,8 +55876,12 @@ var run6 = fn2("Search.run")(function* (options, query) {
55836
55876
  vectorHash: oldChunks.get(c.id)?.contentHash === c.contentHash ? oldChunks.get(c.id)?.vectorHash ?? null : null
55837
55877
  }));
55838
55878
  const pending = chunks.filter((c) => options.rebuild || vectorEmpty || oldChunks.get(c.id)?.vectorHash !== hash3(`${embeddingIdentity}:${c.contentHash}`));
55839
- if (options.embedder && vectorWriter) {
55840
- const vectors = yield* embed(options.embedder, pending.map(embeddingInput));
55879
+ prepared.push({ path, fileHash, chunks, pending });
55880
+ }
55881
+ for (const group of groupByChunks(prepared, EMBED_GROUP_CHUNKS)) {
55882
+ const pending = group.flatMap((note) => note.pending);
55883
+ if (options.embedder && vectorWriter && embeddingIdentity !== undefined) {
55884
+ const vectors = pending.length ? yield* embed(options.embedder, pending.map(embeddingInput)) : [];
55841
55885
  yield* try_3({
55842
55886
  try: () => {
55843
55887
  const docs = pending.map((c, i) => {
@@ -55853,17 +55897,19 @@ var run6 = fn2("Search.run")(function* (options, query) {
55853
55897
  if (failed)
55854
55898
  throw new SearchError({ message: `Vector upsert failed: ${failed.message}` });
55855
55899
  }
55856
- for (const c of chunks)
55857
- c.vectorHash = hash3(`${embeddingIdentity}:${c.contentHash}`);
55900
+ for (const note of group)
55901
+ for (const c of note.chunks)
55902
+ c.vectorHash = hash3(`${embeddingIdentity}:${c.contentHash}`);
55858
55903
  },
55859
55904
  catch: searchError
55860
55905
  });
55861
55906
  }
55862
- yield* try_3({
55863
- try: () => store.replace(path, fileHash, chunks),
55864
- catch: searchError
55865
- });
55866
- changed++;
55907
+ for (const note of group)
55908
+ yield* try_3({
55909
+ try: () => store.replace(note.path, note.fileHash, note.chunks),
55910
+ catch: searchError
55911
+ });
55912
+ changed += group.length;
55867
55913
  }
55868
55914
  const deleted = [...files.keys()].filter((path) => !sources.has(path));
55869
55915
  yield* try_3({
@@ -56121,8 +56167,9 @@ nested files the same way.
56121
56167
  - Treat GitHub as authoritative for PR state and Scratchpad as the planning-to-delivery map.
56122
56168
  - In a project with a \`scratchpad.config.ts\`, \`scratchpad sync\` also mirrors these files to GitHub
56123
56169
  issues and milestones. A status whose first word is in the config's \`backlog.closedStatuses\`
56124
- (default: done, complete(d), closed, merged, landed, delivered, cancel(l)ed, superseded,
56125
- implemented, historical, moved) syncs as closed. Preview with \`scratchpad sync --dry-run\` first.
56170
+ (default: done, complete, completed, closed, merged, landed, delivered, cancelled, canceled,
56171
+ superseded, implemented, historical, moved) syncs as closed. Preview with
56172
+ \`scratchpad sync --dry-run\` first.
56126
56173
  - Keep completed material active while it is useful for delivery; retire it through this skill's
56127
56174
  \`archive\` mode (a Trash move with a receipt) when it no longer supports current work.
56128
56175
 
@@ -56166,10 +56213,10 @@ For multi-worktree or multi-harness work:
56166
56213
  releasing the worker lease or removing its worktree.
56167
56214
 
56168
56215
  For durable user-visible tasks, the coordinator owns one Markdown-table registry at
56169
- \`.scratchpad/backlog/handoffs/task-registry.md\`; it records the stable task ID/title, stream,
56170
- current delivery, worktree/branch/PR, last verified base, next-ready work, exclusions, and write
56171
- allowlist. Treat the registry as a recovery aid: task runtime, Git, GitHub, tests, and providers
56172
- remain authoritative.
56216
+ \`.scratchpad/handoffs/task-registry.md\`; it records the stable task ID/title, stream, current
56217
+ delivery, worktree/branch/PR, last verified base, next-ready work, exclusions, and write allowlist.
56218
+ Treat the registry as a recovery aid: task runtime, Git, GitHub, tests, and providers remain
56219
+ authoritative.
56173
56220
 
56174
56221
  Treat coordination notes as advisory. Recheck actual worker, Git, and runtime state before assigning
56175
56222
  or closing work.
@@ -56293,12 +56340,14 @@ reported by the harness; do not infer a model from writing style or a product na
56293
56340
 
56294
56341
  ### Classification
56295
56342
 
56296
- When a classifier is configured (\`scratchpad doctor\` reports it), \`feedback new\` classifies the
56297
- redacted text after writing the file and adds a \`classification\` block (\`scope\`: project, global, or
56298
- tool; \`kind\`; \`actionable\`; \`confidence\`; \`model\`) to the front matter. \`status\` becomes
56299
- \`classified\`, or \`review\` when confidence is below 0.7. Without a classifier, or when classification
56300
- fails, the file stays \`status: new\` and the command still succeeds. Classification is triage
56301
- metadata; it never edits the body and does not replace a review disposition.
56343
+ When a classifier is configured (\`scratchpad doctor\` reports it; \`SCRATCHPAD_CLASSIFIER=none\` or
56344
+ \`classifier.model: "none"\` turns it off, and \`SCRATCHPAD_CLASSIFIER\` otherwise overrides the model),
56345
+ \`feedback new\` classifies the redacted text after writing the file and adds a \`classification\` block
56346
+ (\`scope\`: project, global, or tool; \`kind\`; \`actionable\`; \`confidence\`; \`model\`) to the front
56347
+ matter. \`status\` becomes \`classified\`, or \`review\` when confidence is below 0.7. Without a
56348
+ classifier, or when classification fails, the file stays \`status: new\` and the command still
56349
+ succeeds. Classification is triage metadata; it never edits the body and does not replace a review
56350
+ disposition.
56302
56351
 
56303
56352
  \`scratchpad route "<correction>"\` asks the classifier which folder owns a correction (project, or
56304
56353
  global for global and tool scope) and writes nothing; it fails when no classifier is configured.
@@ -56490,11 +56539,13 @@ scratchpad search "instruction feedback" --global
56490
56539
  Without an embedding key, search falls back to FTS-only keyword matching and prints a notice on
56491
56540
  stderr; it still works, so use distinctive terms. Hybrid search needs
56492
56541
  \`SCRATCHPAD_OPENROUTER_API_KEY\` or the key in \`~/.config/scratchpad/secrets/openrouter-api-key\`
56493
- (mode \`0600\`). Never print or record the key. With a key, the note title, heading, and chunk text of
56494
- every indexed note, and each query, are sent to OpenRouter (\`qwen/qwen3-embedding-8b\`). Before
56495
- searching notes that hold secrets, customer data, or anything the user would not share with that
56496
- provider, set \`search: { embeddings: false }\` in \`scratchpad.config.ts\` (discovered upward,
56497
- including ancestor configs), which stays FTS-only even when a key is present.
56542
+ (keep it \`0600\` and its directory \`0700\`; the CLI does not check). The path honors an absolute
56543
+ \`$XDG_CONFIG_HOME\` (default \`~/.config\`). Never print or record the key. With a key, the note title,
56544
+ heading, and chunk text of every indexed note, and each query, are sent to OpenRouter
56545
+ (\`qwen/qwen3-embedding-8b\`). Before searching notes that hold secrets, customer data, or anything
56546
+ the user would not share with that provider, set \`search: { embeddings: false }\` in
56547
+ \`scratchpad.config.ts\` (discovered upward, including ancestor configs), which stays FTS-only even
56548
+ when a key is present.
56498
56549
 
56499
56550
  ## Initialize
56500
56551
 
@@ -56507,6 +56558,9 @@ first use. The root index should explain:
56507
56558
  - where the latest handoff lives;
56508
56559
  - which checkout or worktree owns shared coordination state.
56509
56560
 
56561
+ This mode organizes notes; the CLI \`scratchpad init\` only scaffolds \`scratchpad.config.ts\` and
56562
+ backlog mounts for GitHub sync.
56563
+
56510
56564
  Do not create placeholder files or elaborate taxonomy without an immediate use. Read the
56511
56565
  \`organization\` reference when choosing a layout or retention policy.
56512
56566
 
@@ -56718,8 +56772,10 @@ scratchpad review [paths...] [--apply] [--json] [--limit 100]
56718
56772
  placeholder. Set \`lifecycle.notes.estimatedCostPerCall\` for that fallback.
56719
56773
  - Classification uses OpenRouter Decisions with pinned default model \`typesafe/jev-1.14\`. Set
56720
56774
  \`classifier.model\` to \`~typesafe/jev-latest\` only when a moving alias is wanted. It shares
56721
- \`SCRATCHPAD_OPENROUTER_API_KEY\` or \`~/.config/scratchpad/secrets/openrouter-api-key\` (0600) with
56722
- search embeddings. \`classifier.model\` names an OpenRouter model ID.
56775
+ \`SCRATCHPAD_OPENROUTER_API_KEY\` or \`~/.config/scratchpad/secrets/openrouter-api-key\` (keep
56776
+ it 0600) with search embeddings. \`classifier.model\` names an OpenRouter model ID;
56777
+ \`SCRATCHPAD_CLASSIFIER\` overrides it. Set \`SCRATCHPAD_CLASSIFIER=none\` or
56778
+ \`classifier.model: "none"\` to turn classification off even when a key is present.
56723
56779
  - Without a classifier key, \`review\` says \`classifier disabled\` and exits 0, and \`sweep\` handles
56724
56780
  artifacts only. \`scratchpad doctor\` shows whether a classifier is configured; enable it with
56725
56781
  \`SCRATCHPAD_OPENROUTER_API_KEY\` or the XDG secret the README describes.
@@ -56773,30 +56829,38 @@ reorganize other repositories merely to match this example.
56773
56829
  \`\`\`text
56774
56830
  .scratchpad/
56775
56831
  \u251C\u2500\u2500 README.md
56776
- \u251C\u2500\u2500 feedback/
56777
- \u251C\u2500\u2500 research/
56832
+ \u251C\u2500\u2500 STATE.md
56778
56833
  \u251C\u2500\u2500 backlog/
56779
56834
  \u2502 \u251C\u2500\u2500 issues/
56780
56835
  \u2502 \u251C\u2500\u2500 milestones/
56781
- \u2502 \u251C\u2500\u2500 handoffs/
56782
56836
  \u2502 \u2514\u2500\u2500 parking-lot.md
56837
+ \u251C\u2500\u2500 research/
56783
56838
  \u251C\u2500\u2500 reference/
56784
- \u2514\u2500\u2500 maintenance/
56839
+ \u251C\u2500\u2500 feedback/
56840
+ \u251C\u2500\u2500 handoffs/
56841
+ \u251C\u2500\u2500 decisions/
56842
+ \u251C\u2500\u2500 delivery/
56843
+ \u251C\u2500\u2500 maintenance/
56844
+ \u251C\u2500\u2500 artifacts/
56845
+ \u2514\u2500\u2500 codemaps/
56785
56846
  \`\`\`
56786
56847
 
56848
+ Create only what the work needs: \`STATE.md\` and the folders are made on first use, not up front.
56849
+
56787
56850
  - Keep \`README.md\` as a small index of active work and important continuity pointers.
56788
56851
  - Put instruction-friction occurrences in \`feedback/\` (the \`instruction-feedback\` reference covers
56789
56852
  global and project routing). The home-level \`~/.scratchpad/feedback/\` holds shared feedback.
56790
56853
  - Put investigations, comparisons, and temporary findings in \`research/\`.
56791
56854
  - Put executable work and delivery groupings in \`backlog/\`; the CLI reads issues and milestones only
56792
56855
  from \`backlog/issues/\` and \`backlog/milestones/\`, at any depth beneath them.
56793
- - Put session-continuity artifacts in \`backlog/handoffs/\`.
56856
+ - Put session-continuity artifacts, including \`task-registry.md\`, in the top-level \`handoffs/\`.
56794
56857
  - Put unsettled working contracts in \`reference/\`.
56795
56858
  - Retire inactive working memory with \`scratchpad archive\`, which moves it to the OS Trash and
56796
56859
  records a receipt in \`maintenance/trash-log.md\`. There is no \`archive/\` folder.
56797
56860
  - Keep only declared top-level folders; \`scratchpad doctor\` reports the rest against \`layout\` in
56798
56861
  \`scratchpad.config.ts\`. Built-in folders: \`backlog\`, \`research\`, \`reference\`, \`feedback\`,
56799
- \`handoffs\`, \`decisions\`, \`delivery\`, \`maintenance\`, \`artifacts\`; files: \`README.md\`, \`STATE.md\`.
56862
+ \`handoffs\`, \`decisions\`, \`delivery\`, \`maintenance\`, \`artifacts\`, \`codemaps\`; files: \`README.md\`,
56863
+ \`STATE.md\`.
56800
56864
 
56801
56865
  This is a convention, not a required schema. Follow an existing repository layout instead of
56802
56866
  rewriting it to match this example.
@@ -56808,7 +56872,7 @@ responsibilities, not a universal schema:
56808
56872
 
56809
56873
  | Category | Use when the project needs it |
56810
56874
  | -------------- | ------------------------------------------------------------- |
56811
- | \`backlog/\` | Issues, milestones, deferred decisions, and handoffs |
56875
+ | \`backlog/\` | Issues, milestones, and deferred work |
56812
56876
  | \`delivery/\` | Delivery plans and current execution evidence |
56813
56877
  | \`research/\` | Investigations and comparisons |
56814
56878
  | \`reference/\` | Working reference material not yet suitable for tracked docs |
@@ -56820,6 +56884,11 @@ responsibilities, not a universal schema:
56820
56884
  | \`maintenance/\` | Trash receipts (\`trash-log.md\`) written by the CLI |
56821
56885
  | \`tmp/\` | Explicitly disposable experiments, not authoritative evidence |
56822
56886
 
56887
+ Folders outside the default layout (\`marketing/\`, \`incidents/\`, \`validation/\`, \`web-audits/\`,
56888
+ \`tmp/\`) must be declared in \`layout.folders\` in \`scratchpad.config.ts\`, or \`scratchpad doctor\` flags
56889
+ them. Prefer the defaults: validation reports to \`maintenance/\`, incidents to \`decisions/\` or
56890
+ \`delivery/\`, temporary output to \`artifacts/\` (which \`sweep\` expires).
56891
+
56823
56892
  Keep the root index short and link to owning records. A record's status and evidence matter more
56824
56893
  than its folder name. Shared storage does not require one giant state file: assign task-specific
56825
56894
  files and one writer per file.
@@ -56855,7 +56924,8 @@ description:
56855
56924
  evidence authoritative. Owns .scratchpad only \u2014 not README, docs/, AGENTS.md, project-local
56856
56925
  skills, or Claude Code / Codex auto-memory."
56857
56926
  argument-hint:
56858
- "[status | explore | search | init | backlog | feedback | sync | reconcile | archive | extract]"
56927
+ "[status | explore | search | init | backlog | feedback | review | sync | reconcile | archive |
56928
+ extract]"
56859
56929
  metadata:
56860
56930
  opencode/slash: "true"
56861
56931
  ---
@@ -56987,6 +57057,10 @@ it. Keep analysis local. Treat static analyzer output as evidence, never as the
56987
57057
  \`.scratchpad/codemaps/<name>/\`; let the CLI own timestamped bundles.
56988
57058
  - Never inspect, copy, upload to, or invoke Foglamp. This workflow implements the independent
56989
57059
  Scratchpad product contract.
57060
+ - \`codemaps/\` is part of the default Scratchpad layout. Age-based artifact expiry in
57061
+ \`scratchpad sweep\` skips \`codemap.json\` beside \`codemap.html\` but expires leftover draft files;
57062
+ delete or regenerate drafts instead of relying on them. The HTML is still a note, so a \`stale\` or
57063
+ \`superseded\` review verdict can sweep it; add \`codemaps/**\` to \`lifecycle.protect\` to keep bundles.
56990
57064
  - Do not install a skill globally, publish a codemap, or modify tracked repository files.
56991
57065
  - Keep the overview at no more than 40 nodes and 80 meaningful edges. Aim below the caps so the map
56992
57066
  remains legible.
@@ -57724,7 +57798,7 @@ var withConsoleBuffer = (program) => acquireUseRelease2(sync2(() => {
57724
57798
  }
57725
57799
  state.buffer.length = 0;
57726
57800
  }));
57727
- var app = make39("scratchpad").pipe(withDescription4("Local-first GitHub issue and milestone tracking, hosted artifacts and uploads, and local architecture codemaps"), withSubcommands([
57801
+ var app = make39("scratchpad").pipe(withDescription4("Working memory for coding agents: project notes shared across worktrees, instruction feedback, note search and lifecycle cleanup, plus GitHub backlog sync, hosted artifacts and codemaps."), withSubcommands([
57728
57802
  init,
57729
57803
  path,
57730
57804
  doctor,
@@ -33,6 +33,13 @@ domain documents; GitHub DTOs do not cross the `GithubClientShape` or
33
33
  documents into GitHub requests, resolves milestone slug-to-number linking, and
34
34
  maps GitHub failures to `ProviderError`.
35
35
 
36
+ Translation from wire DTOs to domain documents lives in pure mapping functions in
37
+ `github/client.ts`, beside the DTO schemas, called from the client's decode helpers. Schema handles only
38
+ wire encoding (dates, numbers); the mapping stays a function rather than a
39
+ `Schema` transformation, because it renames fields, derives values such as slugs,
40
+ and builds nested objects (`providerRef`, `sync`) that do not exist on the wire.
41
+ A transformation would also need an `encode` direction nothing uses.
42
+
36
43
  Repo identity comes from `scratchpad.config.ts` (`owner/name`), not from git
37
44
  remotes. Auth resolves `GITHUB_TOKEN` / `GH_TOKEN`, then `gh auth token`.
38
45
  Transport details are documented in
@@ -1,6 +1,7 @@
1
1
  # 0008 — The CLI classifies notes with an optional decision model
2
2
 
3
- Status: Accepted
3
+ Status: Accepted. Superseded in part by [0010](0010-openrouter-decisions-and-note-lifecycle.md),
4
+ which replaces the transport and default model.
4
5
 
5
6
  ## Context
6
7
 
@@ -0,0 +1,71 @@
1
+ # 0010 — OpenRouter Decisions and note lifecycle
2
+
3
+ Status: Accepted
4
+
5
+ ## Context
6
+
7
+ [ADR 0008](0008-cli-decision-model.md) gave the CLI an optional `Classifier` over Effect's
8
+ `DecisionModel`, served by TypeSafe's Jev model over its direct API. Two things changed. Notes
9
+ need lifecycle judgment as well as feedback routing: is a note still fresh, stale, or superseded
10
+ by newer work? And search embeddings arrived ([ADR 0012](0012-local-hybrid-search.md)), which
11
+ made a second provider key a cost for the user. OpenRouter serves both decision models and
12
+ embeddings under one key.
13
+
14
+ ## Decision
15
+
16
+ **Transport.** The classifier calls OpenRouter's Decisions API through `@effect/ai-openrouter`.
17
+ Decision models are listed by `GET https://openrouter.ai/api/v1/models?output_modalities=decisions`.
18
+ The model still comes from `SCRATCHPAD_CLASSIFIER`, then `classifier.model`, then the default;
19
+ `none` disables it. One OpenRouter key serves classification, lifecycle review, and search
20
+ embeddings.
21
+
22
+ **Pinned default.** The default is `typesafe/jev-1.14`, an exact version, so cached verdicts stay
23
+ valid until the model is deliberately changed. The moving `~typesafe/jev-latest` alias is opt-in
24
+ through `classifier.model`. `typesafe/jev-router` is a chat model, not a decision model, and is
25
+ not valid.
26
+
27
+ **Confidence.** Confidence is the probability of the chosen label, taken from the Decisions API,
28
+ independent of kind probability and the provider's separate confidence metric. Per-label
29
+ probabilities are returned and cached with each review.
30
+
31
+ **Review.** `scratchpad review` asks one four-label question per note (`fresh`, `stale`,
32
+ `superseded`, `expired`) with repository evidence. Verdicts are cached in the project state
33
+ database, keyed by content, evidence, model, and question revision. A question revision therefore
34
+ invalidates old verdicts. `review --apply` writes only lifecycle front matter.
35
+
36
+ **Sweep consumes the cache.** `sweep` never calls the model. It trashes only cached
37
+ stale/superseded verdicts at or above `lifecycle.notes.autoTrashConfidence` (default 0.9), and
38
+ protects:
39
+
40
+ - README and STATE indexes,
41
+ - backlog and feedback,
42
+ - notes updated within `minFreshDays` (default 7),
43
+ - notes linked from a live (non-stale) note,
44
+ - paths matching `lifecycle.protect` globs.
45
+
46
+ An expired model verdict alone never auto-trashes a note.
47
+
48
+ ## Calibration evidence
49
+
50
+ The original four-label question was compared with three sharper prompts on 31 sample notes. The
51
+ original matched 5 of 5 evidence anchors; the three sharper prompts misjudged live or durable
52
+ notes. The whole experiment cost about $0.023. The sharper prompts were not adopted.
53
+
54
+ ## Consequences
55
+
56
+ - Classification, lifecycle review, and embeddings depend on one provider account and one key
57
+ location (`~/.config/scratchpad/secrets/openrouter-api-key`, or
58
+ `SCRATCHPAD_OPENROUTER_API_KEY`). Without it, every command still works; review reports that
59
+ the classifier is disabled and sweep handles artifacts only.
60
+ - Moving to a new default model invalidates cached verdicts and is a visible change.
61
+ - The 0008 rules about redaction, writes-first behavior, and deterministic tests are unchanged.
62
+ `TYPESAFE_API_KEY` is no longer used.
63
+
64
+ ## Alternatives
65
+
66
+ - **Keep the direct TypeSafe API.** Rejected: a second key beside OpenRouter embeddings, and no
67
+ shared model catalog.
68
+ - **A moving alias as the default.** Rejected: silent model changes would shift verdicts that
69
+ sweep acts on.
70
+ - **A chat model with a free-text verdict.** Rejected: untyped output, no per-label
71
+ probabilities, no calibrated confidence.
@@ -0,0 +1,46 @@
1
+ # 0011 — Trash instead of archive folders
2
+
3
+ Status: Accepted
4
+
5
+ ## Context
6
+
7
+ Retiring a note used to mean moving it into a dated directory under `archive/`. Those folders
8
+ grew without bound and nothing cleaned them, so retired notes and expired artifacts kept
9
+ occupying disk and showing up in the notes root.
10
+
11
+ ## Decision
12
+
13
+ `archive` and `sweep --apply` move files to the operating system's Trash: `/usr/bin/trash` on
14
+ macOS and `gio trash` on Linux. Other platforms report an unsupported-platform error. Trash is
15
+ recoverable and the OS reclaims its space.
16
+
17
+ Each move is receipted in `maintenance/trash-log.md`. The CLI writes and flushes a `pending`
18
+ receipt first, then appends `trashed`, `failed`, or `skipped-changed` with the same id. An
19
+ unmatched `pending` means a crash or interruption between the two and needs a human to reconcile
20
+ the source path against the Trash; the CLI never retries it automatically. A later failure does
21
+ not undo earlier moves.
22
+
23
+ `archive` acts on the paths it is given immediately; it has no preview. `sweep` previews by
24
+ default and moves nothing without `--apply`, and `sweep --json` reports exactly what an apply run
25
+ would do (see [lifecycle.md](../lifecycle.md)).
26
+
27
+ `.md` and `.html` files are notes, never artifacts: artifact expiry does not remove them. Notes
28
+ leave only through `archive` or the cached-verdict rules of
29
+ [ADR 0010](0010-openrouter-decisions-and-note-lifecycle.md).
30
+ The GitHub archive mount of [ADR 0005](0005-closed-object-archive.md) is a separate, read-only
31
+ projection and is unaffected.
32
+
33
+ ## Consequences
34
+
35
+ - Retirement is reversible from the OS Trash for as long as the user keeps it.
36
+ - The pending-then-final receipt protocol makes crashes visible instead of silent.
37
+ - Existing `archive/` contents are left alone and may contain expired artifacts, which `sweep`
38
+ can still pick up.
39
+ - Trash behavior differs per platform and is unavailable on others.
40
+
41
+ ## Alternatives
42
+
43
+ - **Keep dated archive directories.** Rejected: unbounded growth and no cleanup.
44
+ - **Delete permanently.** Rejected: not recoverable.
45
+ - **A Scratchpad-owned trash directory.** Rejected: it would repeat the unbounded-folder problem
46
+ and skip the OS's own recovery and space reclamation.
@@ -0,0 +1,46 @@
1
+ # 0012 — Local hybrid note search
2
+
3
+ Status: Accepted
4
+
5
+ ## Context
6
+
7
+ Agents need to find earlier decisions, handoffs, and feedback in a notes root that grows with
8
+ every session. Grep misses paraphrases. A hosted index would store every note on another service
9
+ and make search depend on it. Embedding calls send chunk text to OpenRouter, while the index itself
10
+ stays on the machine; what the provider retains is governed by its policy, not by this design.
11
+
12
+ ## Decision
13
+
14
+ `scratchpad search` runs a local hybrid index:
15
+
16
+ - **Text:** SQLite FTS5.
17
+ - **Vectors:** zvec with a FLAT index and cosine distance.
18
+ - **Fusion:** reciprocal rank fusion of the two result lists; the score is reported with each
19
+ result.
20
+ - **Embeddings:** OpenRouter's `qwen/qwen3-embedding-8b` at 1024 dimensions, using the same key as
21
+ the classifier ([ADR 0010](0010-openrouter-decisions-and-note-lifecycle.md)). Note title,
22
+ heading, and chunk text, and queries, are sent there.
23
+
24
+ The index is derived and rebuildable. It lives under the XDG state directory, per project and per
25
+ selected notes root, and is refreshed by content hash before each query, so edits and removals are
26
+ visible without a daemon. `index --rebuild` recreates a scope's stores, including corrupt ones.
27
+
28
+ Without a key, or with `search.embeddings: false`, ordinary searches are FTS-only and say so on
29
+ stderr without loading native bindings. `index --rebuild` still loads zvec when the scope has
30
+ existing vector state, even without a key. The compiled binary embeds the zvec bindings. zvec
31
+ write batches are capped at 1024 documents.
32
+
33
+ ## Consequences
34
+
35
+ - Search sends note text only when embeddings are enabled; `search.embeddings: false` opts out,
36
+ including through ancestor config. Lifecycle review sends note text separately; disable it with
37
+ `classifier.model: "none"` or `SCRATCHPAD_CLASSIFIER=none`.
38
+ - Concurrent writers return a busy error rather than corrupting the index.
39
+ - Linux x64 vector search needs an AVX2-capable CPU.
40
+ - Changing the embedding model or dimensions means rebuilding the index.
41
+
42
+ ## Alternatives
43
+
44
+ - **FTS only.** Rejected as the only mode: it misses paraphrased queries. It remains the fallback.
45
+ - **A hosted vector store.** Rejected: keeps every note off the machine and adds a service to run.
46
+ - **Vector search only.** Rejected: exact identifiers and rare terms retrieve better with FTS.
@@ -10,5 +10,8 @@ Durable record of the decisions behind Scratchpad. Active planning lives in
10
10
  - [0005 — Closed-object archive projection](0005-closed-object-archive.md)
11
11
  - [0006 — GitHub transport: Octokit, GraphQL for issues, REST for milestones](0006-octokit-graphql-and-rest.md)
12
12
  - [0007 — Explicit remote delete](0007-explicit-remote-delete.md)
13
- - [0008 — The CLI classifies notes with an optional decision model](0008-cli-decision-model.md)
13
+ - [0008 — The CLI classifies notes with an optional decision model (superseded in part by 0010)](0008-cli-decision-model.md)
14
14
  - [0009 — Worker-proxied multipart uploads](0009-worker-multipart-uploads.md)
15
+ - [0010 — OpenRouter Decisions and note lifecycle](0010-openrouter-decisions-and-note-lifecycle.md)
16
+ - [0011 — Trash instead of archive folders](0011-trash-instead-of-archive-folders.md)
17
+ - [0012 — Local hybrid note search](0012-local-hybrid-search.md)
@@ -0,0 +1,79 @@
1
+ # Artifacts and uploads
2
+
3
+ The hosted Worker (for example `scratchpad.arya.sh`) serves immutable Markdown/HTML artifact
4
+ revisions with review, share, Trash, and export/import, plus unlisted file uploads. Both require a
5
+ deployment profile (or `--url` on each command). Hosted artifacts are immutable presentation and
6
+ review surfaces over the delivery graph.
7
+
8
+ ## Artifact commands
9
+
10
+ ```
11
+ scratchpad artifact profile set <name> --url <https://…> [--default]
12
+ scratchpad artifact push <path> --slug <slug> [--kind delivery] [--review] [--wait]
13
+ scratchpad artifact list | show <slug>
14
+ scratchpad artifact open <slug>
15
+ scratchpad artifact wait <slug> --json
16
+ scratchpad artifact share | unshare <slug>
17
+ scratchpad artifact delete | restore <slug>
18
+ scratchpad artifact prune --slug <slug> # or --sweep-orphans for abandoned uploads
19
+ scratchpad artifact pull <slug> [--revision <n>]
20
+ scratchpad artifact export | import <zip>
21
+ scratchpad artifact annotations <slug>
22
+ scratchpad artifact resolve <slug> <ordinal> [--dismiss|--reopen] [--reply <text>]
23
+ ```
24
+
25
+ Soft-deleted artifacts go to Trash via `artifact delete`.
26
+
27
+ ## Profiles
28
+
29
+ Profiles live at `$XDG_CONFIG_HOME/scratchpad/deployments.json` and may include Cloudflare Access
30
+ service-token fields for non-interactive CLI auth. See [deploy.md](deploy.md) for the Worker and
31
+ Access bypass rules, and [production-smoke.md](production-smoke.md) for an end-to-end checklist.
32
+
33
+ ## Uploads
34
+
35
+ Unlisted public file URLs (for example PR screenshots) on the same Worker as artifacts. Also
36
+ require a profile or `--url`.
37
+
38
+ ```
39
+ scratchpad upload <file...> [--name <name>] [--ttl-days <n>] [--profile <name>]
40
+ scratchpad upload <file> --resume <session-id> # repeat the original name/type/TTL options
41
+ scratchpad uploads list [--json]
42
+ scratchpad uploads delete <id>
43
+ ```
44
+
45
+ Most commands accept `--json` for machine-readable output.
46
+
47
+ ### Size limits and multipart
48
+
49
+ Files up to 1 GiB can be uploaded from the CLI or Files view. The existing single-request path
50
+ handles files up to 100 MiB; larger files stream through the Worker in 32 MiB parts. A public link
51
+ appears only after R2 verifies the whole file's SHA-256. Browser hashing reads bounded slices, and
52
+ text previews keep their separate 100 MiB ceiling.
53
+
54
+ Multipart sessions expire after 24 hours, or earlier if their `--ttl-days` deadline passes.
55
+ Requests retry transient failures without duplicating the link. If a part's storage result is
56
+ ambiguous, cancellation and a fresh upload are safer than replacing a possibly in-flight part.
57
+ Completion receipts let API callers retry completion with the same session ID after a lost
58
+ response. The CLI's `--resume` flag resumes one unchanged file with its original options and
59
+ authenticated identity. Browser uploads retry in-process; they do not persist a resumable session
60
+ across page reloads. `artifact prune --sweep-orphans` retries staging cleanup and removes old,
61
+ cleaned session records. See [the multipart upload design](adr/0009-worker-multipart-uploads.md).
62
+
63
+ ### Serving, TTL, and expiry
64
+
65
+ Uploaded bodies are served under `/f/*`. With `--ttl-days`, a link expires that many days after
66
+ registration, stops serving, and disappears from upload listings. Expiring links use
67
+ `Cache-Control: no-store` so subsequent requests recheck the expiration; links without a TTL
68
+ retain their one-year immutable caching policy. Expiration cannot revoke copies already downloaded
69
+ or responses cached under an older cache policy.
70
+
71
+ Expiration is logical, not immediate storage deletion. Run `artifact prune --sweep-orphans` to
72
+ remove expired upload records and reclaim unreferenced blobs after the orphan grace period. Blobs
73
+ shared by another upload or artifact remain available to that reference.
74
+
75
+ ## Deployment
76
+
77
+ Worker deploy steps are in [deploy.md](deploy.md); the production checklist is
78
+ [production-smoke.md](production-smoke.md). The Worker's web UI follows the
79
+ [design system](../DESIGN.md).