@gratux/sdk 0.0.0-stage → 1.0.1
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.
- package/README.md +193 -2
- package/dist/api-types.d.ts +644 -0
- package/dist/api-types.js +2 -0
- package/dist/host-entry.d.ts +16 -0
- package/dist/host-entry.js +43 -0
- package/dist/host.d.ts +108 -0
- package/dist/host.js +172 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +81 -0
- package/dist/language-types.d.ts +135 -0
- package/dist/language-types.js +38 -0
- package/dist/manifest.d.ts +142 -0
- package/dist/manifest.js +45 -0
- package/dist/runtime.d.ts +29 -0
- package/dist/runtime.js +1136 -0
- package/dist/types.d.ts +147 -0
- package/dist/types.js +206 -0
- package/package.json +55 -4
- package/templates/basic/README.md +17 -0
- package/templates/basic/gratux.json +19 -0
- package/templates/basic/src/extension.ts +7 -0
- package/templates/basic/tsconfig.json +15 -0
- package/templates/webview/README.md +17 -0
- package/templates/webview/gratux.json +19 -0
- package/templates/webview/src/extension.ts +43 -0
- package/templates/webview/tsconfig.json +15 -0
package/README.md
CHANGED
|
@@ -1,3 +1,194 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Gratux Native SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript SDK for building **real** extensions for the Gratux Android IDE: commands,
|
|
4
|
+
status bar items, WebView views, editor edits, terminals, language features, files,
|
|
5
|
+
network, storage, Android APIs and AI — all backed by the Android runtime, with no
|
|
6
|
+
simulated behaviour.
|
|
7
|
+
|
|
8
|
+
> The SDK is published on npm as [`@gratux/sdk`](https://www.npmjs.com/package/@gratux/sdk).
|
|
9
|
+
> Add it as a development dependency for types and tooling. Extension bundles must keep
|
|
10
|
+
> `@gratux/sdk` **external**; the app injects the API at runtime via
|
|
11
|
+
> `require("@gratux/sdk")`.
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install
|
|
17
|
+
npm run build # compile the SDK (dist/)
|
|
18
|
+
npm test # node:test suite
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Create `gratux.json` and `src/extension.ts`:
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"schemaVersion": 1,
|
|
26
|
+
"id": "acme.hello",
|
|
27
|
+
"name": "Hello",
|
|
28
|
+
"version": "0.1.0",
|
|
29
|
+
"publisher": "acme",
|
|
30
|
+
"type": "typescript",
|
|
31
|
+
"main": "dist/extension.js",
|
|
32
|
+
"engines": { "gratux": "^1.0.0" },
|
|
33
|
+
"permissions": ["commands.register", "ui.notifications"],
|
|
34
|
+
"activationEvents": ["onCommand:hello.run"],
|
|
35
|
+
"contributes": {
|
|
36
|
+
"commands": [{ "id": "hello.run", "title": "Hello: Greet" }]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { commands, window } from "@gratux/sdk";
|
|
43
|
+
|
|
44
|
+
export function activate(): void {
|
|
45
|
+
commands.registerCommand("hello.run", () =>
|
|
46
|
+
window.showInformationMessage("Hello from Gratux!"),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Bundle and validate:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx esbuild src/extension.ts --bundle --format=cjs --platform=neutral \
|
|
55
|
+
--target=es2020 --external:@gratux/sdk --outfile=dist/extension.js
|
|
56
|
+
node /path/to/gratux-sdk/scripts/validate-extension.mjs .
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Install the SDK in an extension project for TypeScript declarations and editor
|
|
60
|
+
autocomplete:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npm install --save-dev @gratux/sdk esbuild
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Pack a `.gxpkg` (zip with `gratux.json` and `dist/extension.js` at the root) and
|
|
67
|
+
install it from **Extensions → Install from file**, or drop it into
|
|
68
|
+
`gratux/app/src/main/assets/extensions/` and add a registry entry.
|
|
69
|
+
|
|
70
|
+
Templates: [`templates/basic`](templates/basic), [`templates/webview`](templates/webview).
|
|
71
|
+
Working samples: [`samples/`](samples) — Word Count, TODO Tree, JSON Tools, Quick Runner,
|
|
72
|
+
Project Dashboard.
|
|
73
|
+
|
|
74
|
+
## Manifest
|
|
75
|
+
|
|
76
|
+
| Field | Required | Notes |
|
|
77
|
+
| --- | --- | --- |
|
|
78
|
+
| `schemaVersion` | no | `1` (current) |
|
|
79
|
+
| `id` | yes | `publisher.name`, lowercase, digits, `-`, `.` |
|
|
80
|
+
| `name`, `version`, `publisher` | yes | `version` is semver |
|
|
81
|
+
| `description`, `license`, `repository`, `icon` | no | registry/UI metadata |
|
|
82
|
+
| `type` | no | `typescript` (default), `javascript`, `declarative` |
|
|
83
|
+
| `main` | code | defaults to `dist/extension.js`, must stay inside the package |
|
|
84
|
+
| `engines.gratux` | recommended | range checked against `1.0.0` (`*`, `^`, `~`, `>=`, `<=`, `>`, `<`) |
|
|
85
|
+
| `permissions` | no | see the table in `src/manifest.ts`; every call is checked |
|
|
86
|
+
| `activationEvents` | no | `onStartupFinished`, `onCommand:…`, `onLanguage:…`, `onView:…`, `*` |
|
|
87
|
+
| `contributes` | no | commands, keybindings, menus, views, languages, languageServers, configuration, snippets, themes |
|
|
88
|
+
| `platform.arch` | no | restrict to `aarch64`, `arm`, `x86_64`, `i686` |
|
|
89
|
+
|
|
90
|
+
The authoritative validation lives in the Android app
|
|
91
|
+
(`ExtensionManifest.kt`); the SDK types mirror it for editor autocomplete.
|
|
92
|
+
|
|
93
|
+
## API surface
|
|
94
|
+
|
|
95
|
+
| Module | What works |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| `commands` | register/unregister, execute contributed and built-in commands, list, onDidExecuteCommand |
|
|
98
|
+
| `window` | status bar items, messages, quick picks, input boxes, custom dialogs, progress, output/log channels, WebView views with package assets and `showView` |
|
|
99
|
+
| `workspace` | root/folders, `findFiles`, `relativePath`, `openFile`, `saveAll`, watchers (creation/change/deletion events), configuration |
|
|
100
|
+
| `fs` | text and binary reads, write/exists/stat/list/create/delete/rename/copy — sandboxed to the workspace |
|
|
101
|
+
| `editor` | active document snapshot, selection, insert/replace/applyEdits, setSelection, reveal, save, find, replaceAll, line decorations, document/selection/save events |
|
|
102
|
+
| `languages` | register languages and completion/hover/definition/reference/formatting/code-action/symbol providers, diagnostics |
|
|
103
|
+
| `lsp` | register/start/stop language servers installed in the prefix, status |
|
|
104
|
+
| `terminal` | real PTY sessions: create, show, sendText, execute, read, resize, close, list, profiles, events |
|
|
105
|
+
| `network` | `fetch` (native HTTP), `cancelAll`, `createWebSocket` |
|
|
106
|
+
| `storage` | per-extension key/value, secrets encrypted with an Android Keystore key |
|
|
107
|
+
| `config` | global/workspace settings, update, change events |
|
|
108
|
+
| `android` | notifications, clipboard, share, open URL, device info, document picker, text/binary document reads, lifecycle events |
|
|
109
|
+
| `ai` | providers, models, one-shot requests, real streaming with cancellation |
|
|
110
|
+
| `env` | app/SDK version, arch, prefix, home, workspace |
|
|
111
|
+
| `permissions` | check/granted/declared |
|
|
112
|
+
|
|
113
|
+
## Packaging and registry
|
|
114
|
+
|
|
115
|
+
- Package format: ZIP renamed `.gxpkg`, manifest at the root (or one wrapper folder).
|
|
116
|
+
- The installer verifies SHA-256, blocks zip-slip, validates the manifest, checks
|
|
117
|
+
`platform.arch`, installs atomically and rolls back on failure.
|
|
118
|
+
- Bundled catalogue: `app/src/main/assets/extensions/registry.json` with
|
|
119
|
+
`asset:extensions/<id>.gxpkg` locations. The listing is read through
|
|
120
|
+
`ExtensionRegistryProvider`, so a remote marketplace can replace it without
|
|
121
|
+
touching the installer or UI.
|
|
122
|
+
- `npm run build:assets` rebuilds the host bundle + all samples + `registry.json`.
|
|
123
|
+
|
|
124
|
+
## Limits and unsupported features (v1)
|
|
125
|
+
|
|
126
|
+
- Single-document editor: no tabs/groups/splits, so no multi-document editing APIs.
|
|
127
|
+
- Decorations are line-level CSS classes (error/warning/info/highlight), not
|
|
128
|
+
inline widgets/hover cards; multi-cursor writes are not exposed.
|
|
129
|
+
- `editor.find` is programmatic; there is no interactive find/replace UI.
|
|
130
|
+
- Language provider registration is stored and used for diagnostics; completion,
|
|
131
|
+
hover, definition, reference, formatting, code action and symbol dispatch to the
|
|
132
|
+
editor UI is **not wired yet** (planned with the LSP bridge in the next milestone).
|
|
133
|
+
- LSP servers must be executables installed in the Gratux prefix; extensions cannot
|
|
134
|
+
host their own LSP transport or semantic-token provider.
|
|
135
|
+
- WebSocket support is real but the host shares one JS sandbox: extensions are
|
|
136
|
+
isolated by token + permission checks, not by V8 isolates.
|
|
137
|
+
- WebView views render in an expandable panel. Package-local JS/CSS/images load through
|
|
138
|
+
`webview.asWebviewUri`; remote page/resource loads require the `network.request`
|
|
139
|
+
permission. HTML video supports native fullscreen playback. Browser and PDF-reader
|
|
140
|
+
extensions can be built as WebView apps (PDF.js can be bundled as an extension asset).
|
|
141
|
+
`fs.readFileBytes` and `android.readDocumentBytes` return `Uint8Array` data for binary
|
|
142
|
+
formats; one native binary read is limited to 16 MB to bound memory use.
|
|
143
|
+
- No VS Code / VSIX / Open VSX compatibility; the manifest and API are Gratux-native.
|
|
144
|
+
|
|
145
|
+
## Security model
|
|
146
|
+
|
|
147
|
+
- Each extension gets a random per-session token; Kotlin resolves the token to the
|
|
148
|
+
extension id, so a page cannot impersonate another extension.
|
|
149
|
+
- Every bridge call goes through `PERMISSIONS` (`method → permission`); both
|
|
150
|
+
declared and user-granted permissions are required. Dangerous permissions are
|
|
151
|
+
revocable per extension.
|
|
152
|
+
- Packages are never executed during install; the hash is computed on the actual
|
|
153
|
+
received bytes.
|
|
154
|
+
- Secrets are encrypted with an AES/GCM key stored in the Android Keystore.
|
|
155
|
+
- This is still in-process JavaScript: a hostile extension with `filesystem.unrestricted`,
|
|
156
|
+
`terminal.execute` or `network.request` can do what those permissions allow. Install
|
|
157
|
+
extensions you trust; permissions are the security boundary.
|
|
158
|
+
|
|
159
|
+
See [`../docs/EXTENSION_PLATFORM.md`](../docs/EXTENSION_PLATFORM.md) for the full
|
|
160
|
+
architecture, lifecycle and roadmap.
|
|
161
|
+
|
|
162
|
+
## Publishing to npm
|
|
163
|
+
|
|
164
|
+
The `publish.yml` GitHub Actions workflow tests and builds the SDK on pushes to
|
|
165
|
+
`main` that change SDK source, build scripts, templates, or package metadata. It
|
|
166
|
+
publishes a version only when that version is not already on npm; bump
|
|
167
|
+
`package.json` and `package-lock.json` for each release. The workflow uses npm
|
|
168
|
+
Trusted Publishing with GitHub Actions OIDC and does not need an npm token.
|
|
169
|
+
|
|
170
|
+
Configure the package's **Trusted Publisher** settings on npmjs.com:
|
|
171
|
+
|
|
172
|
+
| Field | Value |
|
|
173
|
+
| --- | --- |
|
|
174
|
+
| Publisher | GitHub Actions |
|
|
175
|
+
| Organization or user | `PanditSiddharth` |
|
|
176
|
+
| Repository | `gratux-sdk` |
|
|
177
|
+
| Workflow filename | `publish.yml` |
|
|
178
|
+
| Environment name | Leave blank |
|
|
179
|
+
| Allowed action | Enable direct `npm publish` |
|
|
180
|
+
|
|
181
|
+
The workflow also supports manual runs from the GitHub Actions tab. Re-running
|
|
182
|
+
without a version bump safely skips a version that has already been published.
|
|
183
|
+
|
|
184
|
+
## Scripts
|
|
185
|
+
|
|
186
|
+
| Script | Purpose |
|
|
187
|
+
| --- | --- |
|
|
188
|
+
| `npm run build` | compile TypeScript to `dist/` |
|
|
189
|
+
| `npm run build:host` | compile + build `extension-sdk.js` for the app |
|
|
190
|
+
| `npm run build:samples` | bundle and pack the five samples into app assets |
|
|
191
|
+
| `npm run build:assets` | build SDK, host bundle and samples |
|
|
192
|
+
| `npm test` | node:test suite |
|
|
193
|
+
| `npm run typecheck:samples` | type-check sample sources |
|
|
194
|
+
| `npm run validate -- <dir>` | validate an unpacked extension |
|