@skathi-native/cli 0.0.0 → 0.1.0-beta.2

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 (81) hide show
  1. package/aot-inputs.ts +294 -0
  2. package/ascii.ts +397 -0
  3. package/build.ts +1236 -0
  4. package/check/builtins.json +1219 -0
  5. package/check/builtins.ts +112 -0
  6. package/check/codes.ts +178 -0
  7. package/check/command.ts +105 -0
  8. package/check/config.ts +76 -0
  9. package/check/finding.ts +30 -0
  10. package/check/graph.ts +69 -0
  11. package/check/highlight.ts +40 -0
  12. package/check/index.ts +308 -0
  13. package/check/packages.ts +54 -0
  14. package/check/program.ts +209 -0
  15. package/check/report.ts +219 -0
  16. package/check/rules.ts +307 -0
  17. package/check/schema.ts +69 -0
  18. package/check/typing.ts +703 -0
  19. package/cli/assets.ts +114 -0
  20. package/cli/build-app.ts +587 -0
  21. package/cli/config.ts +646 -0
  22. package/cli/create.ts +327 -0
  23. package/cli/dev.ts +92 -0
  24. package/cli/elf.ts +142 -0
  25. package/cli/help.ts +160 -0
  26. package/cli/host-fetch.ts +178 -0
  27. package/cli/host.ts +378 -0
  28. package/cli/icon.ts +303 -0
  29. package/cli/macos-bundle.ts +451 -0
  30. package/cli/pe.ts +429 -0
  31. package/cli/platform.ts +74 -0
  32. package/cli/sk.ts +290 -0
  33. package/cli/skpk.ts +268 -0
  34. package/cli/stamp.ts +254 -0
  35. package/cli/term.ts +176 -0
  36. package/cli/versioninfo.ts +123 -0
  37. package/css-prefixes.ts +118 -0
  38. package/devtools/apps.ts +68 -0
  39. package/devtools/commands.ts +860 -0
  40. package/devtools/ctl.ts +166 -0
  41. package/package.json +52 -3
  42. package/prod.ts +701 -0
  43. package/runtime-path.ts +24 -0
  44. package/tailwind.ts +76 -0
  45. package/templates/minimal/assets/hello.txt +1 -0
  46. package/templates/minimal/src/App.vue +142 -0
  47. package/templates/minimal/src/main.ts +4 -0
  48. package/templates/showcase/assets/hello.txt +1 -0
  49. package/templates/showcase/assets/media/aurora.png +0 -0
  50. package/templates/showcase/assets/media/clip.mp4 +0 -0
  51. package/templates/showcase/assets/media/sticker.tgs +0 -0
  52. package/templates/showcase/src/App.vue +128 -0
  53. package/templates/showcase/src/components/Card.vue +41 -0
  54. package/templates/showcase/src/components/Icon.vue +29 -0
  55. package/templates/showcase/src/components/Missing.vue +26 -0
  56. package/templates/showcase/src/components/Page.vue +41 -0
  57. package/templates/showcase/src/components/Titlebar.vue +128 -0
  58. package/templates/showcase/src/engine.ts +33 -0
  59. package/templates/showcase/src/icons.ts +22 -0
  60. package/templates/showcase/src/main.ts +7 -0
  61. package/templates/showcase/src/pages/AudioPage.vue +124 -0
  62. package/templates/showcase/src/pages/FilesPage.vue +91 -0
  63. package/templates/showcase/src/pages/FormsPage.vue +139 -0
  64. package/templates/showcase/src/pages/GraphicsPage.vue +156 -0
  65. package/templates/showcase/src/pages/HomePage.vue +141 -0
  66. package/templates/showcase/src/pages/LocalePage.vue +71 -0
  67. package/templates/showcase/src/pages/MediaPage.vue +85 -0
  68. package/templates/showcase/src/pages/MotionPage.vue +199 -0
  69. package/templates/showcase/src/pages/NetworkPage.vue +103 -0
  70. package/templates/showcase/src/pages/PermissionsPage.vue +80 -0
  71. package/templates/showcase/src/pages/StoragePage.vue +117 -0
  72. package/templates/showcase/src/pages/StylesPage.vue +199 -0
  73. package/templates/showcase/src/pages/SystemPage.vue +89 -0
  74. package/templates/showcase/src/pages/TrayPage.vue +66 -0
  75. package/templates/showcase/src/pages/WindowPage.vue +128 -0
  76. package/templates/showcase/src/product.ts +2 -0
  77. package/templates/showcase/src/router.ts +149 -0
  78. package/templates/showcase/src/stores/counter.ts +9 -0
  79. package/templates/showcase/src/stores/desktop.ts +115 -0
  80. package/templates/showcase/src/styles.css +140 -0
  81. package/vitecompat.ts +1151 -0
@@ -0,0 +1,166 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * sk-devtools CLI: the zero-setup way to drive a running dev host.
4
+ *
5
+ * bun devtools/ctl.ts [--dist <slot> | --app <name>] <cmd> [args...]
6
+ *
7
+ * Reads `<dist>/devtools.json`, sends one newline-delimited JSON request over TCP to 127.0.0.1 and
8
+ * prints the reply. Exit code 0 on `{ok:true}`, 1 otherwise. No npm dependencies on purpose: an
9
+ * agent driving the app through Bash should not need `bun install`.
10
+ */
11
+
12
+ import { connect } from "node:net";
13
+ import { readFileSync } from "node:fs";
14
+ import { resolve, dirname, join } from "node:path";
15
+ import { fileURLToPath } from "node:url";
16
+
17
+ import { buildRequest, usageBlock, UsageError, splitArgs } from "./commands";
18
+ import { appSlot } from "./apps";
19
+
20
+ const HERE = dirname(fileURLToPath(import.meta.url));
21
+ const DEFAULT_DIST = resolve(HERE, "..", "dist");
22
+ /** A wedged pump must never hang the caller. Overridable with --timeout <ms>. */
23
+ const DEFAULT_TIMEOUT_MS = 10_000;
24
+
25
+ const USAGE = `sk-devtools — drive a running Skathi dev host
26
+
27
+ bun devtools/ctl.ts [--dist <slot>] [--timeout <ms>] <command> [args]
28
+
29
+ commands
30
+ ${usageBlock()}
31
+
32
+ options
33
+ --dist <slot> the dist directory the target host was launched with
34
+ (default: ${DEFAULT_DIST})
35
+ --app <name> a PACKAGED app instead (sk build): its newest live instance
36
+ under %TEMP%\\skathi\\apps\\<name>
37
+ --window <id> which of the target's OS windows the command is about
38
+ (\`windows\` lists them; default: the primary one)
39
+ --timeout <ms> client-side reply timeout (default ${DEFAULT_TIMEOUT_MS})
40
+ --json print the raw wire response instead of just \`data\`
41
+ `;
42
+
43
+ function die(message: string, code = 1): never {
44
+ console.error(message);
45
+ process.exit(code);
46
+ }
47
+
48
+ const { positional, flags } = splitArgs(process.argv.slice(2));
49
+ if (flags.help || positional.length === 0) {
50
+ console.log(USAGE);
51
+ process.exit(positional.length === 0 && !flags.help ? 1 : 0);
52
+ }
53
+
54
+ const distDir = (() => {
55
+ if (typeof flags.app === "string" && flags.app) {
56
+ const found = appSlot(flags.app);
57
+ if ("error" in found) die(found.error);
58
+ return found.dir;
59
+ }
60
+ return typeof flags.dist === "string" && flags.dist ? resolve(flags.dist) : DEFAULT_DIST;
61
+ })();
62
+ const timeoutMs = Number(flags.timeout ?? DEFAULT_TIMEOUT_MS) || DEFAULT_TIMEOUT_MS;
63
+
64
+ type Handshake = { port: number; pid: number; token: string };
65
+
66
+ function readHandshake(dir: string): Handshake {
67
+ const path = join(dir, "devtools.json");
68
+ let raw: string;
69
+ try {
70
+ raw = readFileSync(path, "utf8");
71
+ } catch {
72
+ die(
73
+ `no devtools.json at ${path} — is a dev host running with this dist?\n` +
74
+ ` start one: SK_DIST=${dir} target/x86_64-pc-windows-msvc/debug/sk-app.exe\n` +
75
+ ` or point at another slot: --dist <dir>`,
76
+ );
77
+ }
78
+ try {
79
+ const h = JSON.parse(raw) as Handshake;
80
+ if (!h.port || !h.token) throw new Error("missing port/token");
81
+ return h;
82
+ } catch (e) {
83
+ die(`${path} is not a valid devtools handshake: ${(e as Error).message}`);
84
+ }
85
+ }
86
+
87
+ function send(port: number, payload: string, ms: number): Promise<string> {
88
+ return new Promise((resolveReply, reject) => {
89
+ const socket = connect({ host: "127.0.0.1", port });
90
+ let buffer = "";
91
+ const timer = setTimeout(() => {
92
+ socket.destroy();
93
+ reject(
94
+ new Error(
95
+ `no reply within ${ms}ms — the host's frame pump may be wedged, or the window is ` +
96
+ `mid-drag (gpui runs a modal loop there). Retry, or raise --timeout.`,
97
+ ),
98
+ );
99
+ }, ms);
100
+ const finish = (fn: () => void) => {
101
+ clearTimeout(timer);
102
+ socket.destroy();
103
+ fn();
104
+ };
105
+ socket.on("connect", () => socket.write(payload + "\n"));
106
+ socket.on("data", (chunk) => {
107
+ buffer += chunk.toString("utf8");
108
+ const nl = buffer.indexOf("\n");
109
+ if (nl >= 0) finish(() => resolveReply(buffer.slice(0, nl)));
110
+ });
111
+ socket.on("error", (e) =>
112
+ finish(() =>
113
+ reject(
114
+ new Error(
115
+ `cannot reach 127.0.0.1:${port}: ${e.message} — devtools.json is stale ` +
116
+ `(the host that wrote it exited). Relaunch the host, or --dist another slot.`,
117
+ ),
118
+ ),
119
+ ),
120
+ );
121
+ socket.on("close", () => finish(() => reject(new Error("connection closed before a reply"))));
122
+ });
123
+ }
124
+
125
+ const handshake = readHandshake(distDir);
126
+ const windowArg = Number(flags.window);
127
+ // `--window` rides on every request; a client that never passes it addresses the primary window.
128
+ let request: Record<string, unknown>;
129
+ try {
130
+ request = {
131
+ token: handshake.token,
132
+ ...(Number.isFinite(windowArg) ? { window: windowArg } : {}),
133
+ ...buildRequest(positional, flags),
134
+ };
135
+ } catch (e) {
136
+ // `commands.ts` throws rather than exiting: the MCP server imports it too.
137
+ if (!(e instanceof UsageError)) throw e;
138
+ die(`${e.message}\n\n${USAGE}`);
139
+ }
140
+
141
+ let line: string;
142
+ try {
143
+ line = await send(handshake.port, JSON.stringify(request), timeoutMs);
144
+ } catch (e) {
145
+ die(String((e as Error).message));
146
+ }
147
+
148
+ let reply: { ok?: boolean; data?: unknown; error?: string };
149
+ try {
150
+ reply = JSON.parse(line);
151
+ } catch {
152
+ die(`the host sent something that is not JSON: ${line.slice(0, 400)}`);
153
+ }
154
+
155
+ // A thrown `eval` is a successful ROUND TRIP carrying `{ok:true, data:{exception}}`; the exit
156
+ // code is the shell's error channel, so surface it there too.
157
+ const threw = reply.ok === true && !!(reply.data as { exception?: string } | undefined)?.exception;
158
+
159
+ if (flags.json) {
160
+ console.log(JSON.stringify(reply, null, 2));
161
+ } else if (reply.ok) {
162
+ console.log(JSON.stringify(reply.data, null, 2));
163
+ } else {
164
+ console.error(reply.error ?? "unknown error");
165
+ }
166
+ process.exit(reply.ok && !threw ? 0 : 1);
package/package.json CHANGED
@@ -1,12 +1,61 @@
1
1
  {
2
2
  "name": "@skathi-native/cli",
3
- "version": "0.0.0",
4
- "description": "Skathi CLI (sk). Placeholder; the first release follows.",
5
3
  "license": "MIT OR Apache-2.0",
6
4
  "repository": {
7
5
  "type": "git",
8
6
  "url": "git+https://github.com/argon-chat/skathi.git",
9
7
  "directory": "packages/cli"
10
8
  },
11
- "files": []
9
+ "version": "0.1.0-beta.2",
10
+ "type": "module",
11
+ "files": [
12
+ "cli",
13
+ "check",
14
+ "templates",
15
+ "devtools/apps.ts",
16
+ "devtools/commands.ts",
17
+ "devtools/ctl.ts",
18
+ "aot-inputs.ts",
19
+ "ascii.ts",
20
+ "build.ts",
21
+ "css-prefixes.ts",
22
+ "prod.ts",
23
+ "runtime-path.ts",
24
+ "tailwind.ts",
25
+ "vitecompat.ts"
26
+ ],
27
+ "description": "The sk CLI: SFC compiler, dev and production builders, packaging and devtools for Skathi apps.",
28
+ "bin": {
29
+ "sk": "./cli/sk.ts"
30
+ },
31
+ "dependencies": {
32
+ "@clack/prompts": "^1.9.0",
33
+ "@skathi-native/runtime": "0.1.0-beta.2",
34
+ "@vue/compiler-sfc": "^3.5.41",
35
+ "postcss": "^8.4.31",
36
+ "tailwindcss": "3.4",
37
+ "typescript": "5"
38
+ },
39
+ "devDependencies": {
40
+ "@modelcontextprotocol/sdk": "^1.30.0"
41
+ },
42
+ "engines": {
43
+ "bun": ">=1.4"
44
+ },
45
+ "scripts": {
46
+ "test": "bun test",
47
+ "build": "bun build.ts",
48
+ "watch": "bun build.ts --watch",
49
+ "build:prod": "bun prod.ts",
50
+ "devtools:ui": "bun devtools/ui.ts",
51
+ "sk": "bun cli/sk.ts"
52
+ },
53
+ "comments": {
54
+ "tailwindcss": "Pinned to 3.4.x: v3 emits literal declarations that crates/sk-css maps onto gpui; v4 uses var(--tw-*) + calc() + @property, which the engine does not fully resolve yet (see tailwind.ts).",
55
+ "@modelcontextprotocol/sdk": "devDependency: used only by devtools/mcp.ts. devtools/ctl.ts is dependency-free so an agent can drive the app through Bash without bun install.",
56
+ "typescript": "sk check and the AOT input inventory (sk build --aot-inputs). Builds do not invoke tsc: bun transpiles .ts directly."
57
+ },
58
+ "publishConfig": {
59
+ "access": "public"
60
+ }
12
61
  }