Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
dist/
.superpowers/
.kiln/tmp/
51 changes: 51 additions & 0 deletions .kiln/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"schema_version": 1,
"artifact_language": "en",
"repo": {
"kind": "single",
"root": null
},
"vcs": {
"provider": "github",
"protected": [
"main"
],
"integration_branch": "main",
"branch_pattern": "${type}/${id}"
},
"tracker": {
"provider": "github"
},
"stack": {
"id": "node",
"cmd": {
"test": "node --test \"tests/*.test.js\"",
"test_fast": ""
},
"steps": [
{
"id": "unit",
"run": "${cmd.test}"
}
]
},
"knowledge": {
"tier": 0
},
"auto": {
"bounded": true,
"full": true
},
"work": {
"committed": true
},
"rules": {
"budget_lines": 200
},
"implement": {
"mode": "inline"
},
"learnings": {
"read_from": []
}
}
85 changes: 85 additions & 0 deletions .kiln/hooks/pre-push.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env node
/**
* Copied into a project as `.kiln/hooks/pre-push.mjs` and run by git, not by kiln.
*
* git has already resolved every ref by the time this runs: stdin carries one line per
* ref as `<local ref> <local sha> <remote ref> <remote sha>`, after `HEAD`, `@`, `+`,
* `push.default`, aliases, `-C` and the working directory have all been worked out. So
* this file parses no command line — that is the entire reason it exists.
*/
import { existsSync, readFileSync } from "node:fs";
import { dirname, join, resolve } from "node:path";

function findRoot(start) {
let dir = resolve(start);
for (;;) {
if (existsSync(join(dir, ".kiln", "config.json"))) return dir;
const parent = dirname(dir);
if (parent === dir) return null;
dir = parent;
}
}

/**
* Found and unreadable is not the same as absent. The first version parsed inside the walk,
* so a config with a byte-order mark or a syntax error was skipped as if it were not there,
* the walk found nothing, and the push went through — the floor failing open on exactly the
* file it exists to obey.
*/
function readConfig(root) {
try {
return JSON.parse(readFileSync(join(root, ".kiln", "config.json"), "utf8").replace(/^\uFEFF/, ""));
} catch {
return null;
}
}

/**
* The same set the PreToolUse guard enforces: what the user declared, plus every branch the
* project ships from. The floor read `vcs.protected` alone, so on a project shipping from
* `v3-master` the layer that cannot be talked out of anything protected less than the one
* that can.
*/
export function protectedBranches(config) {
const declared = config?.vcs?.protected ?? ["main"];
const ships = config?.vcs?.integration_branch;
const shipsFrom = typeof ships === "string" ? [ships] : Object.values(ships ?? {});
return [...new Set([...declared, ...shipsFrom])];
}

export function refusal(line, branches) {
const remoteRef = line.split(/\s+/)[2] ?? "";
const branch = remoteRef.replace(/^refs\/heads\//, "");
return branches.includes(branch) ? { branch, remoteRef } : null;
}

export function message({ branch, remoteRef }) {
return `kiln blocked this push: ${branch} is a protected branch.
git resolved the destination to ${remoteRef}, whatever the command line said.
Work on a branch and open a pull request. To change what is protected, edit vcs.protected in .kiln/config.json.`;
}

function main() {
// No config means kiln is not driving this repository, and kiln does not police
// repositories it is not driving (D33).
const root = findRoot(process.cwd());
if (!root) return 0;
const config = readConfig(root);
if (!config) {
process.stderr.write(`kiln blocked this push: ${join(root, ".kiln", "config.json")} cannot be read, so kiln cannot tell which branches are protected.
Fix the file (\`kiln doctor\` names the problem) and push again.
`);
return 1;
}
const branches = protectedBranches(config);
for (const line of readFileSync(0, "utf8").split("\n").filter(Boolean)) {
const hit = refusal(line, branches);
if (hit) {
process.stderr.write(`${message(hit)}\n`);
return 1;
}
}
return 0;
}

if (process.argv[1]?.endsWith("pre-push.mjs")) process.exit(main());
54 changes: 54 additions & 0 deletions .kiln/rules/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Project rules

Every file in this directory must appear in the table below.
**Unrouted is dead weight: route it, or do not add it.**

| Trigger — a path glob | Rule file |
|---|---|
| _(none yet)_ | — |

A trigger is a path glob and nothing else: `*` stops at a slash, `**` crosses one, `?` is
one character. `src/auth/**`, `**/*.sql`, `package.json`.

There is no "applies when the topic comes up" trigger, deliberately. That kind is matched by
the model reading a description, which is unverifiable — nothing can tell you afterwards
whether the rule was applied — and it is where every report of a rule being silently ignored
comes from.

## Adding one

`kiln rules add <file>.md --trigger "<glob>"` writes the file and the row together, refuses
a name or a glob that would not resolve, and runs the checks below. Editing this table by
hand works too — the table is the contract, not the command.

## What reads this

`kiln rules <id>` matches the globs above against the files the stage names, and prints the
rules that match. It runs twice:

- at **PLAN**, against the change preview, so a rule shapes the plan;
- at **REVIEW**, against the diff that actually happened, so a rule still reaches a file the
plan never predicted.

What it handed over is recorded in the work's `state.json`, so *this rule applied* is a fact
rather than a hope.

## Before adding a rule

Every rule line is a token the agent pays on **every later ticket**, and the longer the rules
get the lower its compliance with each one — so adding a rule to force compliance can
backfire. Three questions before you keep one:

1. Can it merge into a rule that already exists? Prefer editing the old file to adding a new
one.
2. Can an equivalent passage be deleted? Total volume stays flat; it does not grow once per
incident.
3. Is it routed in the table above?

`kiln rules add` answers all three where you write the rule: it names what already covers
the same files, prints the line count before and after, and routes it.

`kiln doctor` mechanizes two of the three: it names every row that does not resolve — a
half-filled row, a rule file that is not here, a glob that matches nothing in this project —
and it compares the total against `rules.budget_lines` in `.kiln/config.json`. Whether a rule
could have merged is judgment, and stays with the reviewer.
31 changes: 31 additions & 0 deletions .kiln/work/20261121-remove-cross-window-merge-so-app/state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"schema_version": 1,
"id": "20261121-remove-cross-window-merge-so-app",
"follows": "20261121-review-each-items-above-one-one",
"status": "closed",
"session_id": "0b73138a-cf32-4ba7-ac23-30a61cd6d8d6",
"path": "bounded",
"type": "fix",
"auto": false,
"stage": "INVESTIGATE",
"step": null,
"gates": {},
"predicted": [],
"base": "85aa9cc7fc0bddefdb247893884b3c315dbf2257",
"last_verified": "85aa9cc7fc0bddefdb247893884b3c315dbf2257",
"dirty_at_open": [
".gitignore"
],
"verify": [],
"pass": 1,
"carry_over": [
{
"from_pass": 1,
"kind": "close",
"text": "Yes, maybe later"
}
],
"displaced": [],
"rules": [],
"knowledge": []
}
28 changes: 28 additions & 0 deletions .kiln/work/20261121-review-each-items-above-one-one/brief.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Brief — triage the six audit findings

## What is asked
- Who: the repository owner, who maintains Notelet alone.
- What: go through the six items of the 2026-11-21 ponytail audit one by one and decide which ones are worth a change.
- Success: each item gets a verdict (handle, fold into another, or drop) with evidence, so follow-up works can be opened for the ones kept.
- Constraint: a spike. Nothing in the source changes in this work.

## The six items
1. Own saves seen as edits from another window (false conflict toast, possible duplicated paragraph).
2. `npm test` fails on Node 22; CI pinned to Node 20.
3. Note positions collapse after about 23 drops into one slot.
4. Importing a backup can leave two Sprints notes.
5. No test for repeated moves (same root as 3).
6. `createFileArea` copies the chrome.storage API shape (same root as 1).

## What I found
- Item 1 is reproduced: a two-save run through the real `createFileArea` and `createStore`, with the app's own-write check copied out, flags the older save as foreign, and `mergeNote` reports a conflict. `mergeHtml` duplicates a paragraph when the two saves are an older and a newer version of the same typing.
- Item 2 is reproduced: `npm test` fails on Node 22.17; the glob form passes 214 of 214.
- Item 3 is reproduced: the 24th drop under the top note lands in the wrong place.
- Item 4 is read from code, not run: the import has no step that joins two board notes.

## Still unknown
- How often two saves of one note overlap on a real Windows install (depends on save latency).
- Whether the owner ever imports a backup into an install that already has a Sprints note.

## Past learnings
- None: this project keeps no learnings store (`.kiln/learnings/` does not exist), so recall was not run.
79 changes: 79 additions & 0 deletions .kiln/work/20261121-review-each-items-above-one-one/findings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Audit triage — which of the six items to handle

## Answer
- Handle items 1, 2 and 3; fold 5 into 3 and 6 into 1; item 4 only if backups are ever imported into an install that already has a Sprints note. (kiln)
- Item 1 is real: when two saves of one note overlap, the app reads its own older save as another window's edit and shows a false conflict message. (confirmed: F1)
- When the overlapping saves are of note text, the same path keeps both versions of the paragraph, so text is duplicated. (confirmed: F2)
- Item 2 is real: the project's test command runs no tests on the current Node release. (confirmed: F4)
- Item 3 is real: dropping notes into the same place about two dozen times makes further drops land in the wrong place. (confirmed: F5)
- Item 4 is a gap, not yet seen by a user: an import from another install's backup adds a second Sprints note instead of joining the existing one. (confirmed: F6)

## Impact
- Item 1 gives the owner a scary "edited in another window" message during fast note moves (holding Alt+Down) and can, rarely, double a paragraph of a note. (confirmed: F1)
- There can be no other window, so the whole merge feature that causes item 1 protects against nothing and can be removed. (confirmed: F3)
- Item 2 means a contributor on a current Node sees a broken test suite, and CI stays on an end-of-life Node. (confirmed: F4)
- Item 3 breaks manual note order for someone who keeps dropping notes into the same place, such as always putting the current note second; drops spread over different places stay fine much longer. (confirmed: F5)
- Recommended order: 2 first (one line), then 1 (a deletion, about 380 lines), then 3 (small fix plus one test), and 4 last or never. (kiln)

## Options
1. Open three follow-up works: 2, then 1 (with 6), then 3 (with 5); leave 4 as a known limit noted in the README. (kiln)
2. The same three, plus 4 as a fourth work that joins an imported Sprints note into the existing one. (kiln)
3. Only 2 and 3; keep the merge code in case a second window ever comes back. (kiln)

## Questions for you
- Do you ever import a backup into an install that already has a Sprints note (a second PC, or after a reinstall where you opened Sprints first)?
- Is a second window, or a return of the browser extension, planned? If yes, item 1 needs a fix rather than a deletion.

## Not checked
- How often two saves of one note overlap on a real Windows install — needs timing of the save in the running app.
- Item 4 was read from the code, not run in the app — needs an import test in the end-to-end suite or by hand.
- Node 20's end of life (April 2026) is from my own knowledge, not checked against the Node release page — check nodejs.org/en/about/previous-releases.

## Scope and method
- Read the save, change-event, merge, import and ordering code; ran three small Node scripts against the real modules; ran the unit suite with both test commands on Node 22.17.

## Findings
### F1. An older own save is treated as a foreign edit
- What: each save fires a change event when it finishes; the app compares it with the last version it wrote, so a slower first save that finishes after a second save started looks foreign, and the merge reports a conflict.
- Where: extension/desktop.js:28, extension/app.js:540, extension/app.js:96
- Basis: ran .kiln/tmp/20261121-review-each-items-above-one-one/race.mjs (real createFileArea, createStore and mergeNote, 50 ms save, second save 30 ms later, the app's written-check copied in); it printed "event for position 90 seen as ANOTHER WINDOW" and "merge conflict: true".
- Reachable: yes — holding Alt+Down on a note in the list saves on every key repeat.
- Action: remove the cross-window path (item 1 with 6).

### F2. The text merge keeps both versions of a paragraph
- What: merging an older and a newer version of one paragraph keeps both.
- Where: extension/merge.js:79
- Basis: ran mergeHtml("<p>a</p>", "<p>abc</p>", "<p>ab</p>") with linkedom; it returned { value: '<p>abc</p><p>ab</p>', conflict: true }.
- Reachable: only when two text saves of one note overlap, for example a save followed at once by hiding the window; rare.
- Action: goes away with F1's removal.

### F3. Only one window can exist
- What: the app registers the single-instance plugin, which only brings the window forward on a second launch, and the config defines one window.
- Where: desktop/src/lib.rs:282, desktop/tauri.conf.json:13
- Basis: read both lines; grep for WebviewWindowBuilder in desktop/src found nothing.
- Reachable: n/a.
- Action: none; this is why F1's code can be deleted.

### F4. The test command runs no tests on Node 22
- What: the script passes a folder to node --test, which Node 22 reads as a file name.
- Where: package.json:7, .github/workflows/ci.yml:18
- Basis: ran npm test on Node 22.17.1: "Cannot find module '<repo>/tests'"; ran node --test "tests/*.test.js": 214 pass, 0 fail.
- Reachable: every test run on Node 22.
- Action: use the glob in package.json and move CI to Node 22.

### F5. Positions collapse after repeated drops into one slot
- What: each drop takes the midpoint of its neighbours, and timestamps have too few bits left after about 23 halvings.
- Where: extension/model.js:81
- Basis: ran .kiln/tmp/20261121-review-each-items-above-one-one/pos.mjs (40 drops right under the top note through placeNote); it printed "drop 24 lands wrong; 2nd is n22 true".
- Reachable: yes — drag and drop, or Alt+Up and Alt+Down, in the notes list.
- Action: renumber the section when the midpoint equals a neighbour; one test that repeats the drop 30 times (item 5).

### F6. Import does not join two Sprints notes
- What: a new Sprints note gets a random id, and import saves backup notes as they are, so a backup's Sprints note with another id sits beside the local one; opening Sprints picks the first.
- Where: extension/board-merge.js:19, extension/model.js:47, extension/app.js:495, extension/app.js:399
- Basis: read those lines; nothing in importNotes or mergeTrackers joins two board notes (mergeTrackers only folds old tracker notes, extension/board-merge.js:14).
- Reachable: only by importing a backup from another install into one that already has a Sprints note.
- Action: decide per the question above.

## Out of scope
- board-merge.js "mergeTrackers" is the one-time migration of old tracker notes, not the cross-window merge; it stays.
Loading
Loading