ketoy-dev 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 (31) hide show
  1. package/LICENSE +17 -0
  2. package/README.md +101 -0
  3. package/SECURITY.md +34 -0
  4. package/dist/ketoy.js +3165 -0
  5. package/dist/ketoy.js.map +1 -0
  6. package/package.json +78 -0
  7. package/skills/ketoy/README.md +50 -0
  8. package/skills/ketoy/SKILL.md +148 -0
  9. package/skills/ketoy/examples/capabilities-stubs.kt +60 -0
  10. package/skills/ketoy/examples/hilt-config.kt +192 -0
  11. package/skills/ketoy/examples/no-hilt-config.kt +101 -0
  12. package/skills/ketoy/examples/todo-screen.kt +156 -0
  13. package/skills/ketoy/guides/build-and-analyze.md +87 -0
  14. package/skills/ketoy/guides/diagnose-errors.md +129 -0
  15. package/skills/ketoy/guides/init-project.md +127 -0
  16. package/skills/ketoy/guides/migrate.md +190 -0
  17. package/skills/ketoy/guides/publish-deferred.md +46 -0
  18. package/skills/ketoy/guides/safe-edits.md +141 -0
  19. package/skills/ketoy/reference/architecture-cheatsheet.md +122 -0
  20. package/skills/ketoy/reference/capabilities.md +122 -0
  21. package/skills/ketoy/reference/forbidden-apis.md +149 -0
  22. package/skills/ketoy/reference/supported-composables.md +80 -0
  23. package/skills/ketoy/reference/supported-constructors.md +57 -0
  24. package/skills/ketoy/reference/supported-modifiers.md +76 -0
  25. package/skills/ketoy/templates/app-build.gradle.kts.tmpl +109 -0
  26. package/skills/ketoy/templates/ketoy-capabilities.json.tmpl +21 -0
  27. package/skills/ketoy/templates/manifest-snippet.xml.tmpl +33 -0
  28. package/templates/HelloKetoyScreen.kt.tmpl +51 -0
  29. package/templates/MainActivity.kt.tmpl +53 -0
  30. package/templates/MyApplication.kt.tmpl +88 -0
  31. package/templates/ketoy-capabilities.json.tmpl +5 -0
package/LICENSE ADDED
@@ -0,0 +1,17 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ Copyright 2024–2026 Aditya Shinde (developerchunk) — KetoyVM contributors.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # ketoy
2
+
3
+ AI-powered command-line agent for [Ketoy](https://ketoy.dev) — scaffold a Ketoy-enabled Android project, write `@KetoyComposable` screens, migrate existing Compose UI to `.ktx` bytecode bundles, diagnose compiler-plugin errors, and build / inspect bundles.
4
+
5
+ Powered by the [Vercel AI SDK](https://sdk.vercel.ai) — bring your own API key from **Anthropic, OpenAI, Google Gemini, Mistral, Groq, xAI, OpenRouter, or local Ollama**. Source code never leaves your machine except as part of explicit prompts you send to the provider you chose.
6
+
7
+ ```
8
+ npm install -g ketoy-dev
9
+ ketoy auth anthropic # paste your API key (never logged, stored 0600 in ~/.ketoy-cli)
10
+ ketoy init # add Ketoy to your Android project (surgical edits)
11
+ ketoy chat # open an AI session in the project root
12
+ ```
13
+
14
+ > The npm package is **`ketoy-dev`** (the bare `ketoy` name is blocked by npm's similarity heuristic against unrelated existing packages). The installed binary is still `ketoy`.
15
+
16
+ ---
17
+
18
+ ## Commands
19
+
20
+ ```
21
+ ketoy init [--install-screen | --no-install-screen] [--hilt | --no-hilt] [-y] [--dry-run]
22
+ ketoy chat [prompt...] # interactive agent
23
+ ketoy migrate <file>... # AI-driven per-file Compose → KBC migration
24
+ ketoy doctor [task] # run a Gradle task and diagnose any errors
25
+ ketoy build [--variant bundle|debug|release] # `./gradlew :app:ketoyBundle --rerun-tasks`
26
+ ketoy analyze <path.ktx> [--manifest] [--strings] [--json]
27
+ ketoy config list|get|set
28
+ ketoy auth [provider] [--remove] [--list]
29
+ ketoy version
30
+ ```
31
+
32
+ Every command runs in the current working directory. `ketoy init` only writes files when invoked from an Android project root (one containing `settings.gradle.kts` and `app/build.gradle.kts`).
33
+
34
+ ## Provider setup
35
+
36
+ ```
37
+ ketoy auth anthropic # set ANTHROPIC API key
38
+ ketoy auth openai # OpenAI
39
+ ketoy auth google # Google Gemini
40
+ ketoy auth mistral
41
+ ketoy auth groq
42
+ ketoy auth xai
43
+ ketoy auth openrouter # one key, 200+ models
44
+ ketoy auth ollama # local — no API key, just a base URL
45
+ ketoy auth --list # see what's configured (redacted)
46
+ ```
47
+
48
+ Then pick a default model:
49
+
50
+ ```
51
+ ketoy config set model anthropic:claude-sonnet-4-5
52
+ ketoy config set model openai:gpt-4o
53
+ ketoy config set model google:gemini-2.0-flash-exp
54
+ ketoy config set model openrouter:meta-llama/llama-3.1-405b-instruct
55
+ ```
56
+
57
+ Or override per-command with `--model <provider>:<name>`.
58
+
59
+ Credentials are stored at `~/.ketoy-cli/config.json` (mode `0600`). The CLI refuses to print them — `ketoy config get apiKeys` is intentionally blocked. Use `ketoy auth --list` for a redacted view.
60
+
61
+ ## Safety guarantees
62
+
63
+ - **No file is rewritten in full.** Edits to `build.gradle.kts`, `AndroidManifest.xml`, `MainActivity.kt`, and `Application` classes are surgical — single-line additions or block appends at well-identified anchors. Existing dependencies, signing configs, themes, ProGuard rules are never touched.
64
+ - **Diff-and-confirm** on every edit touching a high-risk file. The agent's `edit_file` tool always shows a unified diff and prompts before applying.
65
+ - **Idempotent** — re-running `ketoy init` on an already-configured project is a no-op.
66
+ - **Allowlisted bash with hard refusal of compound commands** for auto-approval. `cat && rm -rf /` looks like `cat` to a naive checker; the CLI refuses to auto-approve any command containing shell metacharacters (`;`, `&&`, `||`, `|`, backticks, `$(…)`, redirects).
67
+ - **No telemetry.** No analytics, no usage reporting, no remote logging. The CLI talks directly to the provider you configured.
68
+
69
+ ## What `ketoy init` does
70
+
71
+ 1. Detects: `namespace`, `applicationId`, `minSdk`, Hilt usage, existing `Application` class, existing `MainActivity`.
72
+ 2. **Hilt opt-in** — non-Hilt setup is the default. If you opt in to Hilt, init aborts with a pointer to `ketoy chat`, where the agent handles Hilt configuration against your existing modules.
73
+ 3. **KetoyScreen install opt-in** — `--install-screen` (default for fresh AS projects) wraps `MainActivity`'s `setContent` body with `KetoyScreen { /* native fallback */ }` inside your app theme. `--no-install-screen` leaves `MainActivity.kt` untouched and prints a manual integration snippet.
74
+ 4. Plans a list of surgical edits + new file creations; shows the plan, asks to confirm.
75
+ 5. Applies the non-Hilt setup:
76
+ - Inserts `id("dev.ketoy.compiler") version "0.3.4-alpha"` into `app/build.gradle.kts`'s plugins block
77
+ - Appends `// Ketoy 0.3.4-alpha` dependencies (BOM + runtime + annotations + capabilities-core + capabilities-navigation + adapters-material3)
78
+ - Appends the `ketoy { exportFromAppModule = true; bundleId = "main"; bundleVariant = "release"; … }` block
79
+ - Sets `android:name=".MyApplication"` on `<application>` in `AndroidManifest.xml` (only if no existing Application class)
80
+ - Creates `MyApplication.kt` with the **full bootstrap**: `KetoyConfig` (sig verification, font / drawable / icon resolvers), `CapabilityRegistry`, `KetoyRuntime`, `registerGeneratedAdapters` / `registerGeneratedConstructors`, `KetoyBundleLoader`
81
+ - Creates / surgically wraps `MainActivity.kt` — `<YourAppTheme> { CompositionLocalProvider(LocalKetoyRuntime / LocalKetoyBundleLoader) { KetoyScreen(entryPoint = "HelloKetoyScreen") { /* native fallback */ } } }`
82
+ - Creates `HelloKetoyScreen.kt` (sample `@KetoyEntryPoint @KetoyComposable`)
83
+ - Creates `app/ketoy-capabilities.json` (empty)
84
+ - Appends `**/keys/*-private.key` to `.gitignore`
85
+ 6. Saves project state to `.ketoy/state.json` so future commands know the layout.
86
+
87
+ Then: `./gradlew :app:assembleDebug`, install, and you have a real KBC bundle running inside your APK.
88
+
89
+ ### Alpha-period version pinning
90
+
91
+ Ketoy 0.3.x's compiler plugin is built against a specific Kotlin / AGP / Compose BOM combination. `ketoy init` pins your `gradle/libs.versions.toml` to the required versions (Kotlin 2.0.21, AGP 8.13.2, Compose BOM 2024.10.00, plus matched AndroidX libs). These pins are temporary — ADR-0004 (Ketoy ships its own embedded Kotlin compiler) removes them.
92
+
93
+ ## Requirements
94
+
95
+ - **Node.js ≥ 20** (top-level await + modern fetch)
96
+ - **Android Gradle Plugin 8.x** + **Kotlin 2.0.21** + **JDK 17** (auto-pinned during `ketoy init`)
97
+ - **minSdk ≥ 26**
98
+
99
+ ## License
100
+
101
+ Apache 2.0 — see [LICENSE](LICENSE).
package/SECURITY.md ADDED
@@ -0,0 +1,34 @@
1
+ # Security
2
+
3
+ ## Reporting a vulnerability
4
+
5
+ Email **ketoy.dev@gmail.com** with the subject line `[SECURITY] ketoy-cli`. Please do not open a public issue for security reports. Expect an initial response within 72 hours.
6
+
7
+ ## Threat model
8
+
9
+ The CLI executes locally on a developer machine, reads / writes files in the current working directory, runs `./gradlew` build tasks, and forwards prompts + file content the user explicitly hands it to a language-model provider chosen by the user. It does not:
10
+
11
+ - Open inbound network sockets.
12
+ - Run anything as root or modify system-wide state.
13
+ - Collect telemetry / analytics / crash reports.
14
+ - Read or transmit content outside the project root (every agent file tool refuses paths that escape the working directory).
15
+
16
+ ## Hardening already in place
17
+
18
+ - **API keys** are stored at `~/.ketoy-cli/config.json` with mode `0600` and dir mode `0700`. Printing them via `ketoy config get apiKeys` is refused; the only read path is `ketoy auth --list`, which prints `…last4` only.
19
+ - **Prototype pollution** through `ketoy config set` is blocked at the dotted-key validation step (`__proto__`, `prototype`, `constructor` are refused).
20
+ - **Path traversal** through agent tools (`read_file`, `write_file`, `edit_file`, `analyze_ktx`) is blocked by absolute-path containment against the resolved project root — not by string-prefix checks that can be defeated on Windows.
21
+ - **Shell auto-approval** for the agent's `bash` tool is gated by an allowlist of read-only / build commands AND a hard refusal for any command containing shell metacharacters (`;`, `&&`, `||`, `|`, backticks, `$()`, redirects). `cat foo && rm -rf /` requires explicit user confirmation, never auto-approves.
22
+ - **Surgical edits only** for all high-risk files (`build.gradle.kts`, `AndroidManifest.xml`, `MainActivity.kt`, `Application` classes). Whole-file rewrites are never produced. Every high-risk edit shows a unified diff and prompts the user.
23
+
24
+ ## Known transitive advisories
25
+
26
+ `npm audit` against `ketoy` currently reports three moderate findings inherited from upstream dependencies. None are exploitable through the CLI's actual usage; details below. We track upstream fixes and bump as they ship.
27
+
28
+ | Advisory | Source | Why not exploitable here |
29
+ | --- | --- | --- |
30
+ | GHSA-rwvc-j5jr-mgvh (`ai` <= 5.0.51 — file upload filetype bypass) | Vercel AI SDK | The CLI never uploads user-supplied files. Tool results sent to the model are JSON / text only. |
31
+ | GHSA-gh4j-gqv2-49f6 (`fast-xml-parser` < 5.7.0 — XMLBuilder injection) | `fast-xml-parser` | The CLI only **parses** XML (`AndroidManifest.xml` inspection). The vulnerable `XMLBuilder` path is never reached. |
32
+ | GHSA-33vc-wfww-vjfv (`jsondiffpatch` < 0.7.2 — HtmlFormatter XSS) | Transitive of `ai` | The CLI runs in a terminal, not a browser. The HTML diff formatter is never invoked. |
33
+
34
+ Bumping `ai` to v6 / `fast-xml-parser` to v5 require breaking-change migrations. The bumps are tracked for the next minor release.