@ywldan/karsa 0.1.0 → 0.1.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 (4) hide show
  1. package/README.md +30 -2
  2. package/bin/karsa.js +77 -25
  3. package/package.json +9 -4
  4. package/karsa +0 -0
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  **"Ember in the terminal"** — agentic coding CLI berbasis Rust yang ringan,
6
6
  dengan TUI fullscreen, daemon multi-sesi, dan keamanan berlapis.
7
7
 
8
- `v0.1.0` · Rust 2024 · workspace 17 crate · semua teks UI Bahasa Indonesia
8
+ `v0.1.2` · Rust 2024 · workspace 17 crate · semua teks UI Bahasa Indonesia
9
9
 
10
10
  </div>
11
11
 
@@ -18,7 +18,7 @@ binary `target/release/karsa`):
18
18
 
19
19
  ```text
20
20
  karsa default · mock ctx 0% · · - t/s · 0s ·
21
- ℹ ▚▞ karsa v0.1.0 — ketik prompt; `/` palette; Ctrl+C 2× keluar TODO FILES PLAN MCP TAB
21
+ ℹ ▚▞ karsa v0.1.2 — ketik prompt; `/` palette; Ctrl+C 2× keluar TODO FILES PLAN MCP TAB
22
22
  ────────────────────────────
23
23
  ℹ mcp: 1 server aktif — 1 terhubung, 0 gagal (rincian `/mcp`)
24
24
  ╭ /cmd · ⏎ kirim · ⇧⏎ antri · ↑ riwayat ───────────────────────────────────────────────────────────╮
@@ -57,6 +57,34 @@ Silahkan lihat dokumen lengkap spesifikasi di [`KARSA-BUILD.md`](KARSA-BUILD.md)
57
57
  | **karsa-sdk** | protokol NDJSON versi 1 (`hello/ping/turn/stop/message/broadcast/sessions/swarm/bye`) + client async + `karsa sdk schema` |
58
58
  | **Slash commands** | **68 perintah tepat terdaftar** (≥ 58 syarat §15.3) dengan metadata (alias, argumen, summary, help, scope); yang belum tersedia tampil `not-implemented` — tidak pernah senyap |
59
59
 
60
+ ## Pasang
61
+
62
+ ```bash
63
+ # npm (Linux x64 & Windows x64)
64
+ npm install -g @ywldan/karsa
65
+ karsa --version
66
+
67
+ # dari sumber
68
+ cargo build --release -p karsa-cli # biner: target/release/karsa
69
+ ```
70
+
71
+ Paket npm utama hanya berisi wrapper Node (`bin/karsa.js`); biner aslinya datang
72
+ lewat `optionalDependencies` per platform — `@ywldan/karsa-linux-x64`,
73
+ `@ywldan/karsa-win32-x64` — jadi yang terunduh hanya biner untuk OS/arsitektur
74
+ kamu. Kalau paket platform tidak tersedia (mis. arm64 atau macOS), wrapper
75
+ berhenti dengan pesan jelas, bukan gagal senyap. Bisa ditimpa dengan env
76
+ `KARSA_BIN=/jalur/ke/karsa`.
77
+
78
+ Mengemas + menerbitkan rilis npm: `./scripts/npm-pack.sh` (stage + `npm pack` ke
79
+ `dist/`) lalu `./scripts/npm-pack.sh --publish`. Biner Windows di-cross-compile
80
+ dari Linux (`x86_64-pc-windows-gnu`) dan hanya bergantung pada DLL bawaan
81
+ Windows — tanpa libgcc/winpthread.
82
+
83
+ > **Windows:** TUI, `run`, `config`, `provider`, `sessions`, `mcp`, `skills`
84
+ jalan normal. `karsa daemon` / `karsa daemon-server` **tidak** tersedia di
85
+ Windows karena transport-nya unix socket — arm-nya di-cfg-out dan CLI memberi
86
+ pesan eksplisit; pakai WSL kalau butuh daemon multi-sesi.
87
+
60
88
  ## Mulai cepat
61
89
 
62
90
  ```bash
package/bin/karsa.js CHANGED
@@ -1,34 +1,86 @@
1
1
  #!/usr/bin/env node
2
- const { execSync } = require('child_process');
3
- const path = require('path');
4
- const os = require('os');
5
- const fs = require('fs');
2
+ // Wrapper npm untuk biner `karsa`.
3
+ //
4
+ // Kenapa file ini ada: npm tidak bisa memasang biner Rust langsung, jadi paket
5
+ // utama hanya membawa biner untuk platform yang terpasang lewat
6
+ // `optionalDependencies` (@ywldan/karsa-<platform>-<arch>). Wrapper ini memilih
7
+ // biner yang cocok lalu meneruskan seluruh argv + exit code.
8
+ //
9
+ // Catatan penting: JANGAN pernah menimpa `__dirname`/`require` di file ini.
10
+ // Node >= 22.7 mendeteksi ulang modul saat kompilasi CommonJS gagal dan
11
+ // menjatuhkannya ke mode ESM, yang membuat `require` hilang:
12
+ // "ReferenceError: require is not defined in ES module scope"
13
+ 'use strict';
6
14
 
7
- const platform = os.platform();
8
- const arch = os.arch();
15
+ const { spawnSync } = require('node:child_process');
16
+ const fs = require('node:fs');
17
+ const path = require('node:path');
9
18
 
10
- let binaryName = 'karsa';
11
- if (platform === 'win32') {
12
- binaryName += '.exe';
13
- }
14
-
15
- // Determine the directory where this script resides
16
- const __dirname = path.dirname(process.mainModule.filename);
17
- const binaryPath = path.join(__dirname, '..', binaryName);
19
+ const EXE = process.platform === 'win32' ? 'karsa.exe' : 'karsa';
20
+ const PLATFORM = `${process.platform}-${process.arch}`;
21
+ const PKG_ROOT = path.resolve(__dirname, '..');
22
+ const SUB_PKG = `@ywldan/karsa-${PLATFORM}`;
18
23
 
19
- // If the binary exists next to the script (in the package root), run it
20
- if (fs.existsSync(binaryPath)) {
24
+ function isFile(p) {
21
25
  try {
22
- execSync(`"${binaryPath}" ${process.argv.slice(2).join(' ')}`, { stdio: 'inherit' });
23
- } catch (e) {
24
- process.exit(e.code);
26
+ return Boolean(p) && fs.statSync(p).isFile();
27
+ } catch {
28
+ return false;
29
+ }
30
+ }
31
+
32
+ // Kandidat lokasi biner, dari yang paling spesifik ke paling umum.
33
+ function candidates() {
34
+ const list = [];
35
+ if (process.env.KARSA_BIN) {
36
+ list.push(process.env.KARSA_BIN);
25
37
  }
26
- } else {
27
- // Fallback: try to run from PATH (in case user installed globally via other means)
38
+ // 1. Dependensi platform (jalur normal).
28
39
  try {
29
- execSync(`${binaryName} ${process.argv.slice(2).join(' ')}`, { stdio: 'inherit' });
30
- } catch (e) {
31
- console.error(`Karsa binary not found. Please install it via cargo install karsa-cli or download a release from GitHub.`);
32
- process.exit(1);
40
+ const dir = path.dirname(require.resolve(`${SUB_PKG}/package.json`));
41
+ list.push(path.join(dir, EXE));
42
+ } catch {
43
+ // optionalDependency tidak terpasang; lanjut ke fallback.
44
+ }
45
+ // 2. Layout npm/yarn/pnpm yang di-hoist.
46
+ list.push(path.join(PKG_ROOT, '..', SUB_PKG.split('/')[1], EXE));
47
+ // 3. Biner yang dibundel di paket utama (layout lama, <= 0.1.1).
48
+ list.push(path.join(PKG_ROOT, EXE));
49
+ return list;
50
+ }
51
+
52
+ function resolveBinary() {
53
+ for (const c of candidates()) {
54
+ if (isFile(c)) return c;
33
55
  }
56
+ return null;
57
+ }
58
+
59
+ const binary = resolveBinary();
60
+
61
+ if (!binary) {
62
+ process.stderr.write(
63
+ [
64
+ `karsa: biner untuk ${PLATFORM} tidak ditemukan.`,
65
+ ` Coba pasang ulang: npm install -g @ywldan/karsa`,
66
+ ` Rilis praterkompilasi: https://github.com/ywildan/karsa-cli-landing/releases`,
67
+ ` Bangun dari sumber: cargo install --path crates/karsa-cli (atau cargo build --release -p karsa-cli)`,
68
+ '',
69
+ ].join('\n'),
70
+ );
71
+ process.exit(1);
72
+ }
73
+
74
+ // spawnSync dengan array argumen: tanpa shell, jadi argumen ber-spasi/kutip
75
+ // diteruskan utuh (execSync + interpolasi string akan merusaknya).
76
+ const result = spawnSync(binary, process.argv.slice(2), { stdio: 'inherit' });
77
+
78
+ if (result.error) {
79
+ process.stderr.write(`karsa: gagal menjalankan ${binary}: ${result.error.message}\n`);
80
+ process.exit(1);
81
+ }
82
+ if (result.signal) {
83
+ // Biner dihentikan sinyal: tiru perilaku terminal.
84
+ process.kill(process.pid, result.signal);
34
85
  }
86
+ process.exit(result.status === null ? 1 : result.status);
package/package.json CHANGED
@@ -1,15 +1,20 @@
1
1
  {
2
2
  "name": "@ywldan/karsa",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Karsa - Rust agentic coding CLI",
5
5
  "bin": {
6
6
  "karsa": "./bin/karsa.js"
7
7
  },
8
8
  "files": [
9
- "bin/",
10
- "README.md",
11
- "karsa"
9
+ "bin/"
12
10
  ],
11
+ "optionalDependencies": {
12
+ "@ywldan/karsa-linux-x64": "0.1.2",
13
+ "@ywldan/karsa-win32-x64": "0.1.2"
14
+ },
15
+ "engines": {
16
+ "node": ">=18"
17
+ },
13
18
  "scripts": {
14
19
  "test": "echo \"Error: no test specified\" && exit 1"
15
20
  },
package/karsa DELETED
Binary file