@gratux/sdk 0.0.0-stage → 1.0.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.
package/README.md CHANGED
@@ -1,3 +1,160 @@
1
- # Temporary Holding Version
1
+ # Gratux Native SDK
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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 not published to npm. Extensions bundle their code with
9
+ > `@gratux/sdk` kept **external**; the app injects the API at runtime via
10
+ > `require("@gratux/sdk")`.
11
+
12
+ ## Quick start
13
+
14
+ ```bash
15
+ cd sdk
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 ../sdk/scripts/validate-extension.mjs .
57
+ ```
58
+
59
+ Pack a `.gxpkg` (zip with `gratux.json` and `dist/extension.js` at the root) and
60
+ install it from **Extensions → Install from file**, or drop it into
61
+ `app/src/main/assets/extensions/` and add a registry entry.
62
+
63
+ Templates: [`templates/basic`](templates/basic), [`templates/webview`](templates/webview).
64
+ Working samples: [`samples/`](samples) — Word Count, TODO Tree, JSON Tools, Quick Runner,
65
+ Project Dashboard.
66
+
67
+ ## Manifest
68
+
69
+ | Field | Required | Notes |
70
+ | --- | --- | --- |
71
+ | `schemaVersion` | no | `1` (current) |
72
+ | `id` | yes | `publisher.name`, lowercase, digits, `-`, `.` |
73
+ | `name`, `version`, `publisher` | yes | `version` is semver |
74
+ | `description`, `license`, `repository`, `icon` | no | registry/UI metadata |
75
+ | `type` | no | `typescript` (default), `javascript`, `declarative` |
76
+ | `main` | code | defaults to `dist/extension.js`, must stay inside the package |
77
+ | `engines.gratux` | recommended | range checked against `1.0.0` (`*`, `^`, `~`, `>=`, `<=`, `>`, `<`) |
78
+ | `permissions` | no | see the table in `src/manifest.ts`; every call is checked |
79
+ | `activationEvents` | no | `onStartupFinished`, `onCommand:…`, `onLanguage:…`, `onView:…`, `*` |
80
+ | `contributes` | no | commands, keybindings, menus, views, languages, languageServers, configuration, snippets, themes |
81
+ | `platform.arch` | no | restrict to `aarch64`, `arm`, `x86_64`, `i686` |
82
+
83
+ The authoritative validation lives in the Android app
84
+ (`ExtensionManifest.kt`); the SDK types mirror it for editor autocomplete.
85
+
86
+ ## API surface
87
+
88
+ | Module | What works |
89
+ | --- | --- |
90
+ | `commands` | register/unregister, execute contributed and built-in commands, list, onDidExecuteCommand |
91
+ | `window` | status bar items, messages, quick picks, input boxes, custom dialogs, progress, output/log channels, WebView views, `showView` |
92
+ | `workspace` | root/folders, `findFiles`, `relativePath`, `openFile`, `saveAll`, watchers (creation/change/deletion events), configuration |
93
+ | `fs` | read/write/exists/stat/list/create/delete/rename/copy — sandboxed to the workspace |
94
+ | `editor` | active document snapshot, selection, insert/replace/applyEdits, setSelection, reveal, save, find, replaceAll, line decorations, document/selection/save events |
95
+ | `languages` | register languages and completion/hover/definition/reference/formatting/code-action/symbol providers, diagnostics |
96
+ | `lsp` | register/start/stop language servers installed in the prefix, status |
97
+ | `terminal` | real PTY sessions: create, show, sendText, execute, read, resize, close, list, profiles, events |
98
+ | `network` | `fetch` (native HTTP), `cancelAll`, `createWebSocket` |
99
+ | `storage` | per-extension key/value, secrets encrypted with an Android Keystore key |
100
+ | `config` | global/workspace settings, update, change events |
101
+ | `android` | notifications, clipboard, share, open URL, device info, document picker, lifecycle events |
102
+ | `ai` | providers, models, one-shot requests, real streaming with cancellation |
103
+ | `env` | app/SDK version, arch, prefix, home, workspace |
104
+ | `permissions` | check/granted/declared |
105
+
106
+ ## Packaging and registry
107
+
108
+ - Package format: ZIP renamed `.gxpkg`, manifest at the root (or one wrapper folder).
109
+ - The installer verifies SHA-256, blocks zip-slip, validates the manifest, checks
110
+ `platform.arch`, installs atomically and rolls back on failure.
111
+ - Bundled catalogue: `app/src/main/assets/extensions/registry.json` with
112
+ `asset:extensions/<id>.gxpkg` locations. The listing is read through
113
+ `ExtensionRegistryProvider`, so a remote marketplace can replace it without
114
+ touching the installer or UI.
115
+ - `npm run build:assets` rebuilds the host bundle + all samples + `registry.json`.
116
+
117
+ ## Limits and unsupported features (v1)
118
+
119
+ - Single-document editor: no tabs/groups/splits, so no multi-document editing APIs.
120
+ - Decorations are line-level CSS classes (error/warning/info/highlight), not
121
+ inline widgets/hover cards; multi-cursor writes are not exposed.
122
+ - `editor.find` is programmatic; there is no interactive find/replace UI.
123
+ - Language provider registration is stored and used for diagnostics; completion,
124
+ hover, definition, reference, formatting, code action and symbol dispatch to the
125
+ editor UI is **not wired yet** (planned with the LSP bridge in the next milestone).
126
+ - LSP servers must be executables installed in the Gratux prefix; extensions cannot
127
+ host their own LSP transport or semantic-token provider.
128
+ - WebSocket support is real but the host shares one JS sandbox: extensions are
129
+ isolated by token + permission checks, not by V8 isolates.
130
+ - WebView views render as an overlay panel (not docked into a native sidebar).
131
+ - No VS Code / VSIX / Open VSX compatibility; the manifest and API are Gratux-native.
132
+
133
+ ## Security model
134
+
135
+ - Each extension gets a random per-session token; Kotlin resolves the token to the
136
+ extension id, so a page cannot impersonate another extension.
137
+ - Every bridge call goes through `PERMISSIONS` (`method → permission`); both
138
+ declared and user-granted permissions are required. Dangerous permissions are
139
+ revocable per extension.
140
+ - Packages are never executed during install; the hash is computed on the actual
141
+ received bytes.
142
+ - Secrets are encrypted with an AES/GCM key stored in the Android Keystore.
143
+ - This is still in-process JavaScript: a hostile extension with `filesystem.unrestricted`,
144
+ `terminal.execute` or `network.request` can do what those permissions allow. Install
145
+ extensions you trust; permissions are the security boundary.
146
+
147
+ See [`../docs/EXTENSION_PLATFORM.md`](../docs/EXTENSION_PLATFORM.md) for the full
148
+ architecture, lifecycle and roadmap.
149
+
150
+ ## Scripts
151
+
152
+ | Script | Purpose |
153
+ | --- | --- |
154
+ | `npm run build` | compile TypeScript to `dist/` |
155
+ | `npm run build:host` | compile + build `extension-sdk.js` for the app |
156
+ | `npm run build:samples` | bundle and pack the five samples into app assets |
157
+ | `npm run build:assets` | build SDK, host bundle and samples |
158
+ | `npm test` | node:test suite |
159
+ | `npm run typecheck:samples` | type-check sample sources |
160
+ | `npm run validate -- <dir>` | validate an unpacked extension |