tensaku 0.0.1 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19a05003b74ad6d7a4e18d0bf6c838974e619cbb4e5319172b574b363b0cd16b
4
- data.tar.gz: 90fc49efb273155c0a2a6da66586ebce56a0fa0bdf9ca2fbd441f6133d151d70
3
+ metadata.gz: 7840bdd39302cb0d136b8c8741e03c5252c7bdb872c45945f7b05dea6718ed61
4
+ data.tar.gz: 5150d45d8880f37081dc8fc2026319ad542e379dfccf178db1ecaec414a09e46
5
5
  SHA512:
6
- metadata.gz: 0c51109fc72f7c5c0b50fb90082780a5eb9c4afd30caab6af6c09a6ba7824cb41ea5ca56707b2d4d8e9b5d0dd83fdbd6f10b33e662bf0cd894e600eb07d9a70f
7
- data.tar.gz: 80aa78b84cf8a88415886c6d2ef245aa900446a36dc5effe824905938bd081772b1eeacd3d1f762fd08b5092e51d44ea8f5cd0a0fdc1f7fd8600cc219a24f204
6
+ metadata.gz: 4b838531e2b6154e96c5c493782f047364e3ba05255e436f7b9c1df40b683a77030a7c0b2f209045fd3a7a9b3d4aa466dde30da1740033e1c5c0bd310e54f584
7
+ data.tar.gz: eeab9c2146c35d03e2165e11d115929439128ea6eaefc1ca833f7792aca256173c806a30458e8878a398e6c54f7ba822818fef2960e928d9e4f190d4ad4b43c3
data/CHANGELOG.md CHANGED
@@ -1,15 +1,80 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## 0.1.0 (2026-11-08)
4
+
5
+ ### Editing
6
+
7
+ - Herb stamps every ERB element with its source position in development, through ReActionView's ERB
8
+ interception and Herb's `SourceAttributionVisitor`. Production keeps Erubi.
9
+ - In-place editing of template text and attributes, translations (with other locales) and Markdown
10
+ blocks from producers. Writes are byte splices with a stale-file check and one-step undo.
11
+ - Whole Markdown lists can be edited as source.
12
+ - Markdown blocks are read from `data-md-source="path:line:col-line:col"`, the attribute Kiln 0.1.3
13
+ writes. Paragraphs, headings, list items, quotes and whole lists are editable; code blocks, tables and
14
+ rules only get notes. Kiln's content directory isn't writable automatically: add it to
15
+ `writable_paths`.
16
+ - Edit mode outlines only elements with text written in the template, asked once from `POST /editable`.
17
+ Text that comes entirely from Ruby (`<%= %>`) isn't outlined.
18
+ - The editor takes the page's background, text colour and type and sits over the element. Its status
19
+ bar floats below it.
20
+ - After a save, the page updates every node with the same source right away, then fetches the page
21
+ again and morphs it in with idiomorph.
22
+ - Edit history lists the saves made since the page loaded.
23
+ - Open in editor (`GET /editor`), through Rails' `ActiveSupport::Editor` and `RAILS_EDITOR`.
24
+
25
+ ### Notes
4
26
 
5
- - Herb source stamps on every ERB element in development, through ReActionView's ERB interception and
6
- Herb's `SourceAttributionVisitor`. Production keeps Erubi.
7
- - Overlay with a corner button and Alt+Shift+T: hover to see sources, copy references with the
8
- partial chain, Stimulus controller and Turbo Frame.
9
27
  - Notes on elements, text selections and areas, stored in `tmp/tensaku/notes/`, with pins and a notes
10
28
  panel. Agents read them as files, through the MCP endpoint, from the clipboard or with the Claude
11
29
  Code skill.
12
- - In-place editing of template text and attributes, translations (with other locales) and Markdown
13
- blocks from producers, written back as byte splices with a stale-file check and one-step undo.
14
- - Page update after a save: same-source nodes right away, then refetch and idiomorph.
15
- - `bin/rails generate tensaku:install`.
30
+ - Notes can be edited from their card. An edited note goes back to `open` and loses the old reply.
31
+ - A `working` status and the `start_note` MCP tool show when an agent picks a note up. `GET /notes`
32
+ returns `agent.connected`, true for 20 seconds after any MCP call, and the toolbar shows it as a
33
+ green light. The overlay polls the notes every four seconds while the tab is visible.
34
+ - Notes keep a thread (`thread`, with `from` and the agent's name). `reply_to_note` adds an agent
35
+ message, and answering a question from the page adds yours.
36
+ - Notes can move to another element (`PATCH /notes/:id` with `targets`). The card says when a note's
37
+ element is gone.
38
+ - MCP `initialize` returns an `Mcp-Session-Id`. The page names connected agents from `clientInfo`.
39
+ - The notes panel shows every page's notes. `GET /notes.md?format=short` gives one line per note.
40
+ - A note on selected text keeps the phrase marked on the page.
41
+ - Toasts, and optional browser notifications, when an agent starts, answers or resolves a note.
42
+
43
+ ### Overlay
44
+
45
+ - A corner button and Alt+Shift+T open select mode. Hover to see sources, and copy references with
46
+ the partial chain, the Stimulus controller and the Turbo Frame.
47
+ - Arrow keys move the select-mode highlight through stamped elements. Enter opens the menu, and
48
+ Cmd/Ctrl+C copies the highlighted element's reference.
49
+ - Shift-click in select mode picks several elements for one note.
50
+ - Toolbar buttons hide the pins and delete the page's notes after a second click.
51
+ - Settings for the copy format, notifications and a compact corner button.
52
+ - One look on light and dark pages: a dark toolbar of drawn tools (highlighter to select, red pen to
53
+ edit, sticky-note pad for notes) with tooltips, a dark element menu, notes on Post-it paper, and round
54
+ pins that turn green with a drawn check when resolved. The page cursor shows the selected tool.
55
+ Motion is off with `prefers-reduced-motion`.
56
+
57
+ ### Safety and fixes
58
+
59
+ - `writable_paths` takes single files as well as directories. A file allows only that file, such as
60
+ `../CONTRIBUTING.md` outside the app.
61
+ - The endpoints check the `Host` and `Origin` headers and refuse requests a proxy forwarded from
62
+ another machine, so DNS rebinding or a tunnel can't reach them.
63
+ - The token goes only into successful pages and 422 form errors requested with a local `Host`, never
64
+ into error pages or HTML fragments that scripts fetch. It's kept in `tmp/tensaku/token`, shared by
65
+ Puma workers and across restarts.
66
+ - The script carries the page's CSP nonce and respects `SCRIPT_NAME`.
67
+ - Saves and note changes take a shared lock, so concurrent saves don't lose each other's changes.
68
+ - Apps that use `I18n::Backend::Chain` no longer fail on every `t()` call in development.
69
+ - An untouched `&nbsp;` stays `&nbsp;` after a nearby edit. CRLF files keep CRLF line endings. YAML
70
+ anchors and tags survive an edit, and a value in a flow mapping is quoted when it needs to be.
71
+ - `watch_notes` no longer misses notes saved in the same second as its `since`. Malformed note files
72
+ are skipped. Bad request bodies get a 422 instead of a server error.
73
+ - The toast's Undo reverts the save it belongs to. Enter while composing with an IME doesn't save.
74
+ Values typed into the page's forms survive the refresh after a save. Translations stay editable after
75
+ Back and Forward. A second copy of the script adds nothing.
76
+ - Select mode leaves keys in the page's own inputs alone. Every changed piece of an attribute is saved.
77
+ Pins and outlines follow scrolling containers. A note on a repeated element pins to the matching copy.
78
+ - Herb, ReActionView and Rails are pinned to the versions Tensaku is tested with.
79
+ - The generator (`bin/rails generate tensaku:install`) reads the Gemfile through Bundler, reports an
80
+ invalid `.mcp.json` instead of crashing, honors `--pretend` and uses the configured mount path.
data/README.md CHANGED
@@ -1,17 +1,26 @@
1
- # Tensaku
1
+ <h1 align="center">Tensaku</h1>
2
2
 
3
- Tensaku (添削, correcting a draft) lets you fix a running Rails app from the page itself, in
4
- development. Click a piece of text and edit it in place, and Tensaku writes the change back to the ERB
5
- template, the locale YAML or the Markdown source. Or leave a note on an element or an area of the page,
6
- and your coding agent reads it with the exact file and line attached.
3
+ <p align="center">
4
+ <img src="https://img.shields.io/badge/status-experimental-e8b44f" alt="Status: experimental">
5
+ <a href="https://rubyonrails.org"><img src="https://img.shields.io/badge/Rails-8.1-b45d3c?logo=rubyonrails&amp;logoColor=white" alt="Rails 8.1"></a>
6
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-57966f" alt="License: MIT"></a>
7
+ </p>
7
8
 
8
- Tensaku is built on [Herb](https://github.com/marcoroth/herb) through
9
- [ReActionView](https://github.com/marcoroth/reactionview), and only runs in development. Production
10
- doesn't change: it keeps rendering with Erubi and never loads Tensaku, ReActionView or Herb.
9
+ <p align="center">
10
+ Fix your Rails app on the page, in development.
11
+ </p>
11
12
 
12
- Status: 0.0.1, unreleased. Requires Ruby 4.0+ and Rails 8.1+.
13
+ <p align="center">
14
+ <a href="https://tensaku.lostcoords.com">Documentation</a> ·
15
+ <a href="https://tensaku.lostcoords.com/installation">Installation</a> ·
16
+ <a href="https://tensaku.lostcoords.com/safety">Safety and limits</a>
17
+ </p>
13
18
 
14
- ## Install
19
+ Tensaku (添削, correcting a draft) lets you click text on a running Rails page and edit it. It writes the change back to the ERB template, the locale YAML or the Markdown file. For anything that isn't a text edit, leave a note on the page, and your coding agent reads it with the file and line of each element.
20
+
21
+ Tensaku is experimental. It needs Ruby 4.0 or later and Rails 8.1. It runs only in development, on [Herb](https://github.com/marcoroth/herb) through [ReActionView](https://github.com/marcoroth/reactionview). Test and production keep rendering with Erubi and never load Tensaku, ReActionView or Herb.
22
+
23
+ ## Install it in a Rails app
15
24
 
16
25
  ```ruby
17
26
  # Gemfile
@@ -25,172 +34,33 @@ bundle install
25
34
  bin/rails generate tensaku:install
26
35
  ```
27
36
 
28
- The generator checks the Gemfile group, writes `config/initializers/reactionview.rb`, installs the
29
- Claude Code skill in `.claude/skills/tensaku/`, adds the MCP endpoint to `.mcp.json`, and makes sure
30
- `tmp/` is ignored. It prints what it changed. No JavaScript setup is needed: the middleware injects one
31
- prebuilt script, which works with importmap, jsbundling or no JavaScript at all.
32
-
33
- ## Use
34
-
35
- Start the server and open a page. A small round button sits in the bottom right corner (drag it
36
- anywhere). Click it for the toolbar, or press **Alt+Shift+T** to go straight to select mode.
37
-
38
- - **Select**: hover to see where an element comes from (`h1 app/views/pages/about.html.erb:1`), click
39
- it for a menu:
40
- - **Copy reference**: `GET /about → app/views/pages/_hero.html.erb:4:3`, the text, the partial
41
- chain, the Stimulus controller, the Turbo Frame and the translation key.
42
- - **Add note**: write what should change. Select some text first to note just that text.
43
- - **Edit text** / **Edit attributes**.
44
- - **Drag** in select mode to note an area. The note collects every stamped element inside it.
45
- - **Alt/Option-click** any text to edit it right away, in any mode.
46
- - **Edit**: outlines every editable text on the page. A normal click edits.
47
- - **Notes**: the notes on this page, copy them as Markdown, resolve, delete or answer questions.
48
-
49
- The editor shows the source, never the rendered text. In `Hello <%= user.name %>!` you edit `Hello ` and
50
- `!`; the Ruby shows as a locked chip. Translations show `%{name}` interpolations as chips, and
51
- "Other locales" lets you update the same key in every locale at once. Enter or leaving the editor
52
- saves, Shift+Enter adds a line break in Markdown, Escape cancels. After a save, a toast offers Undo.
53
-
54
- ## What can be edited
55
-
56
- | Source | How Tensaku finds it | Written to |
57
- |---|---|---|
58
- | Static text in ERB views, partials, layouts, ViewComponent sidecar templates, mailer templates | `data-herb-source="path:line:col"`, stamped by Herb's `SourceAttributionVisitor` | The template, only the bytes of that text |
59
- | `alt`, `title`, `placeholder`, `aria-label`, button `value` | The same stamp | The attribute value, keeping its quotes |
60
- | `t()` translations, in text and attributes | An invisible marker the I18n backend adds in development | The locale YAML, only the value's bytes |
61
- | Markdown blocks (`p`, headings, `li`, `blockquote`) | `data-tensaku-md="path:line:col-line:col"` from a producer such as Kiln's content layer | The Markdown file, inside the block's range |
62
-
63
- Everything else on the page (text from Ruby data like `@post.title`, output of `form_with` or custom
64
- helpers, DOM built by JavaScript) can still get notes, placed through the nearest stamped element.
65
-
66
- Every write is a splice: Tensaku re-reads the file, checks that the bytes it's about to replace are
67
- still what the page was rendered from, and replaces exactly those bytes through a temp file and a
68
- rename. YAML is never loaded and dumped, so comments, ordering and quoting stay. If the file changed
69
- since the page rendered, the edit is refused and nothing is merged or guessed.
70
-
71
- After a save, Tensaku clears Action View's template cache (and ViewComponent's, and reloads I18n),
72
- updates every copy of the text on the page right away, then fetches the page again and morphs it in
73
- with [idiomorph](https://github.com/bigskysoftware/idiomorph). Stimulus controllers stay connected,
74
- no Turbo visit fires, and elements marked `data-turbo-permanent` or `data-tensaku-permanent` are left
75
- alone. On a page reached by a POST (a form that rendered errors) Tensaku updates the text it knows and
76
- asks you to reload.
77
-
78
- Elements rendered in a loop share one stamp: the editor says "this edits all 3 copies".
79
-
80
- ## Notes for agents
81
-
82
- Notes are JSON files in `tmp/tensaku/notes/`, one per note: local, ignored by git, cleared by
83
- `bin/rails tmp:clear`. Resolved notes are deleted after three days.
84
-
85
- ```json
86
- {
87
- "id": "a7f3",
88
- "url": "/about",
89
- "comment": "tighten this, and the heading is wrong",
90
- "targets": [
91
- { "kind": "element", "file": "app/views/pages/_hero.html.erb", "range": "4:3-4:40", "tag": "h1", "text": "About me" }
92
- ],
93
- "status": "open",
94
- "reply": null
95
- }
96
- ```
97
-
98
- An agent gets them four ways:
99
-
100
- - **Files**: read `tmp/tensaku/notes/*.json`.
101
- - **MCP**: `http://localhost:3000/__tensaku/mcp` (Streamable HTTP). Tools: `list_notes`, `get_note`,
102
- `resolve_note`, `ask_question`, `watch_notes` (waits for new notes) and `current_selection`. The
103
- generator adds it to `.mcp.json`.
104
- - **Clipboard**: copy one note or all open notes as Markdown from the page, for any chat.
105
- - **Claude Code skill**: `.claude/skills/tensaku/SKILL.md` explains how to find, act on and resolve notes.
106
-
107
- A note is `open`, `question` (the agent asked something back; the question shows on the page) or
108
- `resolved` (with a reply; the pin turns green so you can check the change, then dismiss it).
37
+ The generator writes `config/initializers/reactionview.rb`, installs a Claude Code skill in `.claude/skills/tensaku/` and adds the MCP endpoint to `.mcp.json`. It prints every file it changes. You don't set up any JavaScript. The middleware injects one prebuilt script into HTML pages.
109
38
 
110
- ## Producers and attributes
39
+ Start the server and open a page. A round 添 button sits in the bottom right corner. Press **Alt+Shift+T** to select an element and see the file and line it came from.
111
40
 
112
- The overlay only reads attributes, so it doesn't care what rendered the page.
41
+ ## Edit text where you see it
113
42
 
114
- | Attribute | Set by | Meaning |
115
- |---|---|---|
116
- | `data-herb-source="path:line:col"` | Herb | Element's open tag position (1-based) |
117
- | Marker inside translated strings | Tensaku's I18n backend | Locale and key. Stripped by the overlay. |
118
- | `data-tensaku-group` | The app | Widen the highlight and the edit target to this element |
119
- | `data-tensaku-md="path:line:col-line:col"` | A Markdown producer, development only | Block's Markdown source range (byte columns, end inclusive) |
120
- | `data-tensaku-permanent` | The app | The morph after a save leaves this element alone (client-rendered islands) |
121
- | `<meta name="tensaku" data-tensaku-request="GET">` | Tensaku | Request method, so the overlay knows whether it can fetch the page again |
122
-
123
- [Kiln](https://github.com/davafons/kiln)'s content layer emits `data-tensaku-md` in development when
124
- Tensaku is loaded, and Kiln's content directory is writable automatically. Kiln builds fail if any
125
- `data-herb-*` or `data-tensaku-*` attribute reaches the output.
126
-
127
- ## Configuration
128
-
129
- ```ruby
130
- # config/initializers/tensaku.rb
131
- if defined?(Tensaku)
132
- Tensaku.configure do |config|
133
- config.writable_paths << "content" # default: app/views app/components config/locales
134
- config.shortcut = "alt+shift+KeyT" # modifiers and a KeyboardEvent#code
135
- config.prune_after = 7 * 24 * 60 * 60 # seconds before resolved notes are deleted
136
- end
137
- end
138
- ```
43
+ Alt-click (Option-click) any text. The editor shows the source, so in `Hello <%= user.name %>!` you edit `Hello ` and `!` and the Ruby stays a locked chip. Enter saves, Escape cancels, and a toast offers Undo.
139
44
 
140
- Other gems can call `Tensaku.register_writable_path("their/dir")`.
45
+ Tensaku edits static template text, attributes such as `alt` and `placeholder`, `t()` translations in every locale, and Markdown blocks. Each save replaces only the bytes of the edited text, and refuses if the file changed since the page rendered. The page then updates in place, with no reload.
141
46
 
142
- ## Safety
47
+ ## Leave notes for your agent
143
48
 
144
- - Development only. The railtie, middleware and I18n markers check `Rails.env.development?`, so nothing
145
- loads in test or production even if the gem is in the wrong Gemfile group.
146
- - Every endpoint answers loopback addresses only. Everything the overlay calls needs a per-boot token
147
- embedded in the page. The MCP endpoint can't receive that token from an MCP client, so it also
148
- refuses requests with a foreign `Origin` or a non-local `Host` (browsers can't reach it from another
149
- site). It reads and updates notes; it never writes source files.
150
- - Writes are limited to the writable paths, checked after resolving symlinks.
49
+ In select mode, click an element, select some text, or drag over an area, and choose **Add note**. Notes are JSON files in `tmp/tensaku/notes/`, ignored by git. Your agent reads them from the files, from the MCP endpoint at `/__tensaku/mcp`, through the Claude Code skill, or from Markdown you copy from the page.
151
50
 
152
- ## Limits
153
-
154
- - Text from Ruby data, rich text (bold, links, splitting paragraphs), Phlex views and inline
155
- ViewComponent templates (`erb_template`) are out of scope. They get notes.
156
- - Pluralized translations (`count:`) aren't marked, so they aren't edited in the page.
157
- - Translation markers are part of the string while Ruby handles it, in development. A comparison like
158
- `t(".title") == "Welcome"` inside a controller action or view is false in development.
159
- - Fragment caching in development (`bin/rails dev:cache`) keeps showing the old text from cached
160
- fragments. Tensaku warns when it's on.
161
- - One person editing at a time. No undo history beyond one step: version control is the history.
162
- - Herb's dev server patches template changes itself when it runs (ReActionView's `slots` option), and
163
- Tensaku then skips its own refetch for template edits.
164
-
165
- ## Development
166
-
167
- ```sh
168
- bundle install
169
- bun install # only to change the overlay
170
- bin/test # unit and browser tests (Cuprite, needs Chrome)
171
- bin/lint # RuboCop, house rules, TypeScript, compiled overlay up to date
172
- bun run build # app/javascript/tensaku/*.ts -> app/assets/tensaku.js (committed)
173
- ```
174
-
175
- The documentation site is a Rails app in `docs/`, rendered to static files by Kiln and styled with
176
- lostcoords-ui. Tensaku runs on it in development, so it's also where Tensaku is tried on a real site:
177
-
178
- ```sh
179
- cd docs
180
- bundle install
181
- bin/rails tailwindcss:build
182
- bin/rails server # edit the docs from the page
183
- RAILS_ENV=production bin/rails kiln:build # static site in docs/dist
184
- ```
51
+ The agent marks a note `working`, asks a question back, or resolves it with a reply. Each change shows on the note's pin. A green pin means the change is ready for you to check.
185
52
 
186
- With [Parcela](https://parcela.run), `parcela up --detach` runs the docs server and the Tailwind watcher at
187
- https://tensaku.localhost.
53
+ ## Documentation
188
54
 
189
- CI builds the docs with `kiln:build` on every push.
55
+ The documentation site is [tensaku.lostcoords.com](https://tensaku.lostcoords.com). Its pages are Markdown files in `docs/app/views/pages/`.
190
56
 
191
- The test suite runs `test/dummy` in the development environment, since that's the only place Tensaku
192
- switches on. Browser tests write to the dummy app's files and restore them afterwards.
57
+ - [Install Tensaku](docs/app/views/pages/installation.html.md) and see [what the generator does](docs/app/views/pages/installation.html.md#what-the-generator-does).
58
+ - Read [what can be edited](docs/app/views/pages/editing.html.md) and [how a save works](docs/app/views/pages/editing.html.md#how-a-save-works).
59
+ - Leave [notes](docs/app/views/pages/notes.html.md), and give agents the [note format and MCP tools](docs/app/views/pages/agents.html.md).
60
+ - Look up the [configuration options](docs/app/views/pages/configuration.html.md) and the [attributes the overlay reads](docs/app/views/pages/producers.html.md).
61
+ - Read [safety and limits](docs/app/views/pages/safety.html.md) before you use it on a real app.
62
+ - [Contribute](CONTRIBUTING.md) or read the [changelog](CHANGELOG.md).
193
63
 
194
64
  ## License
195
65
 
196
- MIT
66
+ Tensaku is licensed under the [MIT License](LICENSE).