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
2 changes: 1 addition & 1 deletion .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "name": "editor", "version": "0.1.0", "description": "Tells agents to have the person fill in a secret or a config file in a Hangar tab, instead of asking for it in chat." }
{ "name": "editor", "version": "0.2.0", "description": "Tells agents to have the person fill in a secret or a config file in a Hangar tab, instead of asking for it in chat." }
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* text=auto eol=lf
*.png binary
*.woff2 binary
*.wasm binary
15 changes: 14 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,17 @@ permissions:

jobs:
kit-check:
uses: hangar-ai/.github/.github/workflows/kit-check.yml@v1
uses: hangar-ai/.github/.github/workflows/kit-check.yml@rust-rewrite

# The native tab: its tests, and the committed module checked against the
# source. Rust comes from native/rust-toolchain.toml, which rustup installs
# with the wasm32-unknown-unknown target on the first cargo call there.
native:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Tests
working-directory: native
run: cargo test --locked
- name: The committed module is the one the source makes
run: scripts/build-native.sh --check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.hangar-ui/
node_modules/
native/target/
93 changes: 61 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ check or edit.
so plainly, and adds the line only when you click. A template such as `.env.example`
is meant to be committed and gets no warning.
- **Any other text file opens in a plain editor**: line numbers, the line the agent
pointed at, a diff before saving. JSON is checked by `JSON.parse`. TOML is parsed for
pointed at, a diff before saving. JSON is parsed whole. TOML is parsed for
its syntax and YAML is scanned for what is certainly wrong (a tab in the indentation, a
quote or a bracket left open): both say it is a basic check, not a proof. A broken file
can be saved only after you say you know.
Expand All @@ -30,6 +30,10 @@ check or edit.
English and French, in Hangar's language; light and dark, in Hangar's theme; legible at
the side panel's narrowest.

**A native tab, for Hangar 2.0 or later.** The tab is written in Rust and built to
WebAssembly (`tabs/editor.wasm`): Hangar runs that module and draws the tab with its own
widgets, in your theme, with no browser engine. There is no HTML page.

## What it can touch

Three permissions, shown to you before you enable the kit. It runs nothing by itself: no
Expand All @@ -46,19 +50,28 @@ this is the kit that is for. Nothing under `.git` can be reached, and nothing le
machine.

**What reaches the agent:** the file's path, key names and counts, in sentences fixed in
[`tabs/editor/answer.js`](tabs/editor/answer.js). Never a value. A name that is also a
[`native/src/answer.rs`](native/src/answer.rs). Never a value. A name that is also a
value in the file, or that you typed yourself in the « Add a key » field, is counted and
not named. `test/no-value-reaches-an-agent.test.js` drives the tab over hostile files and
random edits and looks at everything that leaves the page.
not named. `native/tests/no_value_reaches_an_agent.rs` drives the tab over hostile files
and random edits and looks at everything that leaves it, its log included, and checks in the
sources that `panes.send` is called from one place, fed by `answer` alone. The tab logs
nothing, and shows a value only in its own field, dotted until you click Show.

What it cannot do: a tab cannot read `.git/info/exclude` or your global excludes, or tell
whether a file is already tracked, so a tracked file listed in `.gitignore` reads as
ignored and a file excluded elsewhere still gets the warning. `files.read` drops a BOM and
the page cannot know there was one, so saving a file that had one saves it without.
the tab cannot know there was one, so saving a file that had one saves it without.

Details of the native tab: a value over several lines shows as a dotted one-line field until
you click Show, then in a plain text area (Hangar's text areas have no dotted mode). In the
editor, a line longer than the pane is cut at its edge rather than scrolled to, and Ctrl+S
works anywhere in the tab, not only in a field. It is opened with its params, so it does not
ask Hangar for them again.

## Install

You need Hangar 1.9.0 or later.
You need Hangar 2.0.0 or later: the tab is native, and an older Hangar says the kit needs a
newer one.

1. In Hangar, Settings › Kits, add the GitHub link:
`https://github.com/hangar-ai/kit-editor`
Expand Down Expand Up @@ -91,45 +104,61 @@ other.

```
editor/
├── hangar-kit.json the kit: id, hangar >=1.9.0, the tab, its params and permissions
├── hangar-kit.json the kit: schema 2, id, hangar >=2.0.0, the tab (its entry is the module), params, permissions
├── icon.svg
├── .claude-plugin/plugin.json the Claude Code plugin (name = the kit's id)
├── skills/editor/SKILL.md
├── tabs/editor/
│ ├── index.html loads Hangar UI and the SDK, then the scripts below
│ ├── dotenv.js reads a dotenv file, and writes back only what changed
│ ├── answer.js the only sentences an agent ever gets
│ ├── validate.js JSON, YAML, TOML
│ ├── diff.js lines compared, and line endings a textarea drops, restored
│ ├── gitignore.js git's ignore rules
│ ├── logic.js the words in en and fr, params, the picker's order
│ ├── controller.js the behaviour; takes window.hangar as an argument
│ ├── view.js draws a state with Hangar UI's classes, never markup
│ ├── app.js wires them in the page
│ └── style.css the editor's layout, in Hangar UI's tokens
├── test/ node --test, no dependency, a fake window.hangar over made-up files
├── tabs/editor.wasm the native tab, built from native/ and committed: the manifest's `entry`
├── native/ the tab in Rust, on Hangar's kit SDK (hangar-kit-sdk)
│ ├── src/ dotenv.rs (reads a dotenv file, writes back only what changed),
│ │ answer.rs (the only sentences an agent ever gets), validate.rs (JSON,
│ │ YAML, TOML), diff.rs, gitignore.rs (git's ignore rules), logic.rs (the
│ │ words in en and fr, params, the picker's order), editor.rs (the
│ │ behaviour), view.rs (the widgets)
│ ├── tests/ through the SDK's test harness, with a fake Hangar
│ ├── Cargo.toml, Cargo.lock the SDK from Hangar's repository, pinned to a commit
│ └── rust-toolchain.toml the Rust that builds the module
├── scripts/build-native.sh builds native/ into tabs/editor.wasm (--check: fails if it is stale)
├── test/manifest.test.js the manifest, the plugin and the skill, with Node alone
└── package.json, run-tests.js let `node --test kits/editor/` find the tests on any Node
```

### The native tab

```
scripts/build-native.sh # builds native/, writes tabs/editor.wasm
scripts/build-native.sh --check # builds it, and fails if tabs/editor.wasm is not what the source makes
```

builds `native/` for `wasm32-unknown-unknown` and copies the module to `tabs/editor.wasm`.
It needs Rust; `native/rust-toolchain.toml` names the version and the target, which rustup
installs the first time. Hangar never builds a kit: it runs the module the kit ships, so
`tabs/editor.wasm` is committed, rebuilt in the commit that changes `native/`. The build
takes the paths of the machine out of the module, so it is the same byte for byte wherever
it is built, and CI checks that the committed one is what the source makes. To try a change,
link this folder in Hangar's Settings › Kits (it is read live), run the script, and reload the
tab from its bar.

## Tests

```
node --test kits/editor/
cargo test --manifest-path native/Cargo.toml
```

No install step. No test reads a real file of yours: the fake Hangar holds its files in
memory, and the check of the ignore rules against `git check-ignore` runs in a temporary
folder.
The first needs Node alone and checks the manifest, the plugin and the skill. The second runs
the native tab on the host, with no WebAssembly and no Hangar: a fake Hangar answers its calls
from files in memory, under the manifest's three permissions, and the tests press, type and
read its view as a person would. No test reads a real file of yours: the fake Hangar holds its
files in memory, and the check of the ignore rules against `git check-ignore` runs in a
temporary folder.

## This repository

`node --test` runs the tests, with Node alone. Hangar's own files are not in this repository. CI takes Hangar UI and the docs from the Hangar tag the
manifest's `hangar` names, and `node test/hangar-ui.js --get` does the same here. Without them, these tests
skip what needs those files, and say so:

- the permissions and methods used are in the docs, when the docs are around
- Hangar UI's classes, and no colour of its own
`node --test` runs the manifest's and the plugin's tests, with Node alone. Hangar's own files
are not needed.

CI calls [kit-check](https://github.com/hangar-ai/.github/blob/main/.github/workflows/kit-check.yml). A release is
a tag, `v` and the manifest's version, and it reaches Hangar's gallery once
[the catalog](https://github.com/hangar-ai/catalog) is updated and reviewed.
CI calls [kit-check](https://github.com/hangar-ai/.github/blob/main/.github/workflows/kit-check.yml),
runs the native tab's tests, and fails if the committed `tabs/editor.wasm` is not the one the
source makes. A release is a tag, `v` and the manifest's version, and it reaches Hangar's gallery
once [the catalog](https://github.com/hangar-ai/catalog) is updated and reviewed.
8 changes: 4 additions & 4 deletions hangar-kit.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"schema": 1,
"schema": 2,
"id": "editor",
"name": "Editor",
"version": "0.1.0",
"version": "0.2.0",
"description": "Opens a .env or a config file in a tab for you to fill in or check, so that an agent that needs a secret goes on without ever seeing it.",
"author": "Hangar",
"homepage": "https://github.com/hangar-ai/kit-editor",
"icon": "icon.svg",
"hangar": ">=1.9.0",
"hangar": ">=2.0.0",
"gallery": {
"permissionsSummary": "Reads and changes text files of the workspace, .env and other hidden files included, and tells the agent that asked which keys were set, never their values.",
"tags": ["env", "secrets", "config", "tab"]
Expand All @@ -16,7 +16,7 @@
{
"id": "editor",
"title": "Editor",
"entry": "tabs/editor/index.html",
"entry": "tabs/editor.wasm",
"icon": "icon.svg",
"permissions": ["files.read", "files.write", "panes.send"],
"params": {
Expand Down
166 changes: 166 additions & 0 deletions native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions native/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "kit-editor-tab"
description = "The Editor kit's tab, native: Rust built to WebAssembly"
version = "0.1.0"
edition = "2024"
license = "MIT"
publish = false

# The cdylib is the module Hangar loads (tabs/editor.wasm, built by
# scripts/build-native.sh); the rlib is for `cargo test`, which runs the tab on
# the host with hangar_kit_sdk::testing.
[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
# Until a release tag of Hangar holds the SDK, its branch; Cargo.lock pins the commit.
hangar-kit-sdk = { git = "https://github.com/hangar-ai/hangar", branch = "feat/native-rust" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"

[profile.release]
opt-level = "s"
lto = true
strip = true
codegen-units = 1
panic = "abort"

[dev-dependencies]
regex = "1"
Loading
Loading