nightingale 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.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/ARCHITECTURE.md +56 -0
  3. data/CHANGELOG.md +5 -0
  4. data/CODE_OF_CONDUCT.md +132 -0
  5. data/README.md +98 -0
  6. data/Rakefile +12 -0
  7. data/examples/demo/app.rb +28 -0
  8. data/frontend/.gitignore +24 -0
  9. data/frontend/README.md +16 -0
  10. data/frontend/components.json +17 -0
  11. data/frontend/eslint.config.js +29 -0
  12. data/frontend/index.html +13 -0
  13. data/frontend/package-lock.json +5467 -0
  14. data/frontend/package.json +47 -0
  15. data/frontend/postcss.config.ts +6 -0
  16. data/frontend/public/vite.svg +1 -0
  17. data/frontend/src/App.css +42 -0
  18. data/frontend/src/App.tsx +192 -0
  19. data/frontend/src/assets/react.svg +1 -0
  20. data/frontend/src/components/ui/button.tsx +56 -0
  21. data/frontend/src/components/ui/card.tsx +79 -0
  22. data/frontend/src/components/ui/input.tsx +22 -0
  23. data/frontend/src/components/ui/label.tsx +24 -0
  24. data/frontend/src/components/ui/separator.tsx +31 -0
  25. data/frontend/src/components/ui/slider.tsx +26 -0
  26. data/frontend/src/components/ui/table.tsx +117 -0
  27. data/frontend/src/index.css +76 -0
  28. data/frontend/src/lib/utils.ts +6 -0
  29. data/frontend/src/main.tsx +10 -0
  30. data/frontend/tailwind.config.ts +77 -0
  31. data/frontend/tsconfig.json +30 -0
  32. data/frontend/tsconfig.node.json +10 -0
  33. data/frontend/vite.config.ts +13 -0
  34. data/lib/nightingale/cli.rb +126 -0
  35. data/lib/nightingale/dsl.rb +74 -0
  36. data/lib/nightingale/runner.rb +79 -0
  37. data/lib/nightingale/server.rb +104 -0
  38. data/lib/nightingale/version.rb +5 -0
  39. data/lib/nightingale.rb +11 -0
  40. data/public/nightingale.png +0 -0
  41. metadata +205 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9bfa99712a0dfe0f1eef301b1949287cab8e8e88047743057e50ce1b82baafe3
4
+ data.tar.gz: 65c4761d4a1f9083a4b6d714c7c8f85b0158cdeaa01ae8c0c08ac3c374d04fe2
5
+ SHA512:
6
+ metadata.gz: ae7bb0e38a7ca02de58276762068025a03a58a2723d6c965558525f5b2478c9b2bcef7007628e1a4c189ce3d4cd57f2f1da1159a6fcc6195ac9f5afbe308fef2
7
+ data.tar.gz: f850e8a53018cd28007e59d09279ed9e25ceced95d60ed6872606439f3bcbb05b4602ed3c4bb4126ae198bbde3098c0bfbf8bfc3a5dca4ecdef59b48b31e93de
data/ARCHITECTURE.md ADDED
@@ -0,0 +1,56 @@
1
+ # Nightingale Architecture
2
+
3
+ ## Overview
4
+
5
+ Nightingale consists of three main components:
6
+ 1. **Runner (Ruby)**: Executes the user's script and generates a component tree.
7
+ 2. **Server (Sinatra)**: Serves the frontend and manages WebSocket connections.
8
+ 3. **Frontend (React)**: Renders the component tree and sends events back to the server.
9
+
10
+ ## Communication Protocol
11
+
12
+ Nightingale uses WebSockets for real-time communication.
13
+
14
+ ### Server -> Client (`render`)
15
+
16
+ The server sends the full component tree to the client.
17
+
18
+ ```json
19
+ {
20
+ "type": "render",
21
+ "components": [
22
+ { "type": "title", "props": { "text": "My App" } },
23
+ { "type": "button", "id": "btn1", "props": { "label": "Click Me" } }
24
+ ]
25
+ }
26
+ ```
27
+
28
+ ### Client -> Server (`event`)
29
+
30
+ The client sends user interactions to the server.
31
+
32
+ ```json
33
+ {
34
+ "type": "event",
35
+ "id": "btn1",
36
+ "event": "click",
37
+ "value": true
38
+ }
39
+ ```
40
+
41
+ ## Execution Model
42
+
43
+ When the server receives an event (or on initial load):
44
+ 1. The **Runner** loads the user's script.
45
+ 2. It executes the script from top to bottom.
46
+ 3. DSL methods (like `slider`, `button`) register components in the runner.
47
+ 4. If an event matches a component, the component's return value is updated.
48
+ 5. The resulting component tree is sent back to the client.
49
+
50
+ ## State Management
51
+
52
+ `session_state` is preserved across reruns for a single session (WebSocket connection). It is currently stored in memory.
53
+
54
+ ## Security
55
+
56
+ **Warning**: Nightingale executes arbitrary Ruby code. It is designed for local development. For deployment, ensure the environment is sandboxed (e.g., Docker) and access is restricted.
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-11-24
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ ![](public/nightingale.png)
2
+
3
+ # Nightingale
4
+
5
+ Nightingale is a Ruby framework for building interactive data and AI web applications with a simple, declarative DSL. It brings the "script-as-app" experience (like Streamlit) to the Ruby ecosystem.
6
+
7
+ ## Features
8
+
9
+ - **Ruby DSL**: Write your UI in pure Ruby.
10
+ - **Reactive**: Automatically updates the UI when you save your script.
11
+ - **Interactive**: Built-in widgets like sliders, buttons, and dataframes.
12
+ - **Modern Frontend**: React + Vite powered UI for a smooth experience.
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ gem install nightingale
18
+ # Or add to your Gemfile
19
+ gem 'nightingale'
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ 1. Create a new app:
25
+ ```bash
26
+ nightingale new myapp
27
+ cd myapp
28
+ ```
29
+
30
+ 2. Run the app:
31
+ ```bash
32
+ nightingale run app.rb
33
+ ```
34
+
35
+ 3. Edit `app.rb` and watch the magic happen!
36
+
37
+ ## DSL Reference
38
+
39
+ ### `title(text)`
40
+ Displays a large title.
41
+
42
+ ### `markdown(text)`
43
+ Renders Markdown content.
44
+
45
+ ### `button(label, key: nil)`
46
+ Renders a button. Returns `true` if clicked.
47
+
48
+ ```ruby
49
+ if button "Click me"
50
+ markdown "Clicked!"
51
+ end
52
+ ```
53
+
54
+ ### `slider(label, min:, max:, value: nil, step: 1, key: nil)`
55
+ Renders a slider. Returns the current value.
56
+
57
+ ```ruby
58
+ val = slider "Select value", min: 0, max: 100
59
+ markdown "Value: #{val}"
60
+ ```
61
+
62
+ ### `dataframe(data)`
63
+ Displays a table of data (array of hashes).
64
+
65
+ ```ruby
66
+ data = [{ name: "Alice", age: 30 }, { name: "Bob", age: 25 }]
67
+ dataframe data
68
+ ```
69
+
70
+ ### `session_state`
71
+ A hash-like object to store state across reruns.
72
+
73
+ ```ruby
74
+ session_state[:count] ||= 0
75
+ session_state[:count] += 1 if button "Increment"
76
+ ```
77
+
78
+ ## Architecture
79
+
80
+ See [ARCHITECTURE.md](ARCHITECTURE.md) for details on how Nightingale works.
81
+
82
+ ## Development
83
+
84
+ To set up the project for development (including installing Ruby gems and frontend dependencies):
85
+
86
+ ```bash
87
+ bin/setup
88
+ ```
89
+
90
+ To run the demo app during development:
91
+
92
+ ```bash
93
+ bin/nightingale run examples/demo/app.rb
94
+ ```
95
+
96
+ ## License
97
+
98
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "nightingale"
4
+
5
+ title "Nightingale Demo"
6
+
7
+ sidebar do
8
+ markdown "## Controls"
9
+ n = slider "Number", min: 1, max: 10, value: 3, key: :n
10
+ check = slider "Multiplier", min: 1, max: 5, value: 1, key: :mult
11
+ end
12
+
13
+ markdown "# Hello Nightingale"
14
+ markdown "This is a demo of the Ruby DSL."
15
+
16
+ if button "Compute Random Numbers"
17
+ # compute something
18
+ n = session_state[:n] || 3
19
+ mult = session_state[:mult] || 1
20
+
21
+ result = (1..n).map { |i| { index: i, value: rand(100) * mult } }
22
+
23
+ markdown "### Results"
24
+ dataframe result
25
+ end
26
+
27
+ markdown "---"
28
+ markdown "Current session state: #{session_state.inspect}"
@@ -0,0 +1,24 @@
1
+ # Logs
2
+ logs
3
+ *.log
4
+ npm-debug.log*
5
+ yarn-debug.log*
6
+ yarn-error.log*
7
+ pnpm-debug.log*
8
+ lerna-debug.log*
9
+
10
+ node_modules
11
+ dist
12
+ dist-ssr
13
+ *.local
14
+
15
+ # Editor directories and files
16
+ .vscode/*
17
+ !.vscode/extensions.json
18
+ .idea
19
+ .DS_Store
20
+ *.suo
21
+ *.ntvs*
22
+ *.njsproj
23
+ *.sln
24
+ *.sw?
@@ -0,0 +1,16 @@
1
+ # React + Vite
2
+
3
+ This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
+
5
+ Currently, two official plugins are available:
6
+
7
+ - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
8
+ - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
+
10
+ ## React Compiler
11
+
12
+ The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
13
+
14
+ ## Expanding the ESLint configuration
15
+
16
+ If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema.json",
3
+ "style": "default",
4
+ "rsc": false,
5
+ "tsx": true,
6
+ "tailwind": {
7
+ "config": "tailwind.config.js",
8
+ "css": "src/index.css",
9
+ "baseColor": "slate",
10
+ "cssVariables": true,
11
+ "prefix": ""
12
+ },
13
+ "aliases": {
14
+ "components": "@/components",
15
+ "utils": "@/lib/utils"
16
+ }
17
+ }
@@ -0,0 +1,29 @@
1
+ import js from '@eslint/js'
2
+ import globals from 'globals'
3
+ import reactHooks from 'eslint-plugin-react-hooks'
4
+ import reactRefresh from 'eslint-plugin-react-refresh'
5
+ import { defineConfig, globalIgnores } from 'eslint/config'
6
+
7
+ export default defineConfig([
8
+ globalIgnores(['dist']),
9
+ {
10
+ files: ['**/*.{js,jsx}'],
11
+ extends: [
12
+ js.configs.recommended,
13
+ reactHooks.configs.flat.recommended,
14
+ reactRefresh.configs.vite,
15
+ ],
16
+ languageOptions: {
17
+ ecmaVersion: 2020,
18
+ globals: globals.browser,
19
+ parserOptions: {
20
+ ecmaVersion: 'latest',
21
+ ecmaFeatures: { jsx: true },
22
+ sourceType: 'module',
23
+ },
24
+ },
25
+ rules: {
26
+ 'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
27
+ },
28
+ },
29
+ ])
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>frontend</title>
8
+ </head>
9
+ <body>
10
+ <div id="root"></div>
11
+ <script type="module" src="/src/main.jsx"></script>
12
+ </body>
13
+ </html>