rempug 0.0.0-stage → 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.
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "rempug",
3
+ "description": "Delegasi kerja dari agent orkestrator ke agent CLI lain lewat tmux, hemat token dan terverifikasi mesin.",
4
+ "license": "MIT",
5
+ "keywords": ["agent", "orchestrator", "tmux", "mcp"]
6
+ }
package/.mcp.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "mcpServers": {
3
+ "rempug": {
4
+ "command": "npx",
5
+ "args": ["-y", "rempug", "mcp"]
6
+ }
7
+ }
8
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 rempug contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,106 @@
1
- # Temporary Holding Version
1
+ # rempug
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
+ Delegasi kerja dari satu agent **orkestrator** (mis. Claude Code) ke agent CLI lain (Codex, Antigravity, opencode, Claude) yang berjalan di sesi **tmux**. Hemat token, terverifikasi mesin, dan tanpa file sampah di proyek.
4
+
5
+ Anda hanya mengetik `/rempug` sekali. Sesudah itu orkestrator mendelegasikan, menunggu, memverifikasi, mengulang, dan mengalihkan pekerjaan sendiri; Anda hanya menilai apakah hasil yang Anda minta sudah benar.
6
+
7
+ ## Kenapa
8
+
9
+ - Membaca layar tmux mentah boros token dan rawan salah baca. Hasil kerja kembali lewat **perintah**, bukan lewat scrape layar.
10
+ - Agent berupa model murah, jadi klaim mereka tidak dipercaya. **rempug menghitung sendiri** file yang berubah, menjalankan cek penerimaan, dan mendeteksi commit diam-diam.
11
+ - Orkestrator tidak perlu diingatkan: `rempug watch` mendorong satu baris per kejadian, dengan kursor yang tersimpan sehingga tidak ada kejadian yang hilang.
12
+ - Semua status disimpan di satu berkas SQLite di luar repo. Tidak ada `tasks/`, `state/`, atau `evidence/` di proyek Anda.
13
+
14
+ ## Kebutuhan
15
+
16
+ - Linux atau macOS (butuh `tmux`)
17
+ - Node.js 22.13 atau lebih baru (memakai `node:sqlite` bawaan, tanpa dependensi native)
18
+
19
+ ## Pemasangan
20
+
21
+ ```bash
22
+ npm i -g rempug
23
+ ```
24
+
25
+ Lalu pasang skill dan server MCP untuk Claude Code, salah satunya:
26
+
27
+ ```bash
28
+ # Plugin: skill /rempug + server MCP + hook awal sesi sekaligus
29
+ claude plugin marketplace add dianramdhani/rempug
30
+ claude plugin install rempug
31
+
32
+ # Atau manual
33
+ rempug skill install
34
+ claude mcp add --scope user rempug -- rempug mcp
35
+ ```
36
+
37
+ Agent yang Anda delegasikan harus bisa menjalankan `rempug` dari shell-nya (`rempug doctor` memeriksanya).
38
+
39
+ ## Pemakaian
40
+
41
+ Siapkan sesi tmux dan jalankan agent di dalamnya (beserta apa pun yang perlu disiapkan, mis. sesi Playwright), lalu di orkestrator:
42
+
43
+ ```
44
+ /rempug
45
+ ```
46
+
47
+ Orkestrator memindai tmux, menebak mana yang agent, bertanya **satu kali** untuk penamaan, lalu **mengukur** tiap agent (probe) dan menampilkan tabel kesiapan:
48
+
49
+ ```
50
+ agy ✓ siap ack 1.8 dtk
51
+ codex ✓ siap ack 2.4 dtk
52
+ opencode ✗ tidak-andal teks tertahan di kotak input; 7 kombinasi dicoba
53
+ ```
54
+
55
+ Sesudahnya Anda cukup meminta hasil. Orkestrator memutuskan sendiri apa yang dibagi ke agent dan hanya melaporkan hasilnya: tujuan tercapai atau belum, bukti yang menentukan, dan keputusan yang butuh Anda. Hook awal sesi memulihkan status di sesi berikutnya, jadi `/rempug` tidak perlu diulang.
56
+
57
+ ## Cara kerja
58
+
59
+ 1. `send` memvalidasi **brief** (TUJUAN, CAKUPAN, LANGKAH, CEK, BALASAN), menolak cakupan yang beririsan dengan tugas edit lain, mengambil snapshot berkas, lalu mengetik **satu baris pointer** ke pane agent.
60
+ 2. Agent menjalankan `rempug brief` (ini bukti pengiriman), mengonfirmasi pemahaman lewat `rempug paham`, bekerja, lalu `rempug reply`. Konfirmasi yang cocok dengan brief disetujui otomatis tanpa token orkestrator.
61
+ 3. Verifikasi berjalan di proses terlepas: berkas yang berubah (+/−), perubahan di luar cakupan (hanya nama), cek penerimaan yang dijalankan rempug sendiri, dan commit atau pindah branch.
62
+ 4. `watch` mencetak satu baris, mis. `T12 codex ✓ 3 file +41/−7 | scope OK | tsc ✓ vitest ✗(2)`.
63
+
64
+ Pemantau layar berjalan di dalam `watch`: mengulang pengiriman yang tertahan, melaporkan pertanyaan, prompt izin, dan limit, mengirim satu pengingat, lalu menyatakan agent macet. **Prompt izin tidak pernah dijawab otomatis.**
65
+
66
+ ## Perintah
67
+
68
+ Untuk orkestrator: `scan`, `register`, `probe`, `ls`, `status`, `doctor`, `send`, `jawab`, `log`, `show`, `diff`, `report`, `layar`, `watch`, `terima`.
69
+ Untuk agent: `brief`, `paham`, `tunggu`, `reply`.
70
+ Semuanya juga tersedia sebagai tool MCP (`rempug mcp`), kecuali `watch`. Jalankan `rempug --help` untuk pemakaian lengkap.
71
+
72
+ ## Konfigurasi
73
+
74
+ | Variabel | Fungsi | Bawaan |
75
+ |---|---|---|
76
+ | `XDG_STATE_HOME` | Lokasi ledger (`rempug/ledger.db`) | `~/.local/state` |
77
+ | `XDG_CONFIG_HOME` | Lokasi registry agent | `~/.config` |
78
+ | `REMPUG_RETENTION_DAYS` | Masa simpan tugas | 30 |
79
+ | `REMPUG_ACK_DETIK` | Batas menunggu agent membaca brief | 45 |
80
+ | `REMPUG_DIAM_DETIK` | Layar tidak berubah selama ini dianggap diam | 10 |
81
+ | `REMPUG_MACET_DETIK` | Diam selama ini tanpa balasan berarti macet | 120 |
82
+ | `REMPUG_WATCH_MS` | Selang `watch` | 1000 |
83
+ | `REMPUG_TMUX_SOCKET` | Memakai server tmux lain (`tmux -L`) | server bawaan |
84
+ | `CLAUDE_CONFIG_DIR` | Lokasi pemasangan skill | `~/.claude` |
85
+
86
+ ## Batasan yang perlu diketahui
87
+
88
+ - **Deteksi keadaan layar bersifat heuristik** (teks tertahan, pertanyaan, prompt izin, limit). Ia teruji terhadap TUI palsu yang meniru perilaku berbeda, tetapi belum divalidasi terhadap setiap TUI sungguhan. Agent yang gagal probe ditandai `tidak-andal` dan tidak dipakai.
89
+ - Konfirmasi pemahaman menangkap salah paham pada **cakupan, cek, dan tindakan terlarang**, bukan salah paham makna pada TUJUAN. Untuk tugas berisiko gunakan `--teliti`; verifikasi sesudah kerja tetap menjadi jaring terakhir.
90
+ - Pengecekan cakupan sengaja **konservatif**: path tanpa wildcard dianggap sebagai dirinya sendiri beserta isinya.
91
+ - Windows tidak didukung (tmux).
92
+
93
+ ## Pengembangan
94
+
95
+ ```bash
96
+ npm ci
97
+ npm run check # Biome
98
+ npm run typecheck
99
+ npm test # butuh tmux; termasuk uji ujung ke ujung
100
+ ```
101
+
102
+ Commit mengikuti [Conventional Commits](https://www.conventionalcommits.org/); versi, `CHANGELOG.md`, GitHub Release, dan publish npm dihasilkan otomatis oleh semantic-release dari cabang `main`.
103
+
104
+ ## Lisensi
105
+
106
+ MIT
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env node
2
+ import { checkNodeVersion } from "./runtime.js";
3
+ const node = checkNodeVersion(process.versions.node);
4
+ if (!node.ok) {
5
+ console.error(node.message);
6
+ process.exit(1);
7
+ }
8
+ // `node:sqlite` masih eksperimental di Node 22 dan mencetak peringatan ke stderr, yang akan
9
+ // mengotori keluaran yang dibaca agent. Hanya peringatan itu yang dibuang.
10
+ const emitAsli = process.emitWarning;
11
+ process.emitWarning = ((peringatan, ...sisa) => {
12
+ const tipe = typeof sisa[0] === "string"
13
+ ? sisa[0]
14
+ : sisa[0]?.type;
15
+ if (tipe === "ExperimentalWarning" && String(peringatan).includes("SQLite"))
16
+ return;
17
+ return emitAsli.call(process, peringatan, ...sisa);
18
+ });
19
+ const { run } = await import("./commands.js");
20
+ async function bacaStdin() {
21
+ if (process.stdin.isTTY)
22
+ throw new (await import("./core/errors.js")).UsageError("isi dibaca dari stdin; pipe teks ke perintah ini (mis. rempug reply T1 <<'EOF' ... EOF)");
23
+ const potongan = [];
24
+ for await (const p of process.stdin)
25
+ potongan.push(p);
26
+ return Buffer.concat(potongan).toString("utf8");
27
+ }
28
+ const kontrol = new AbortController();
29
+ for (const sinyal of ["SIGINT", "SIGTERM"])
30
+ process.on(sinyal, () => kontrol.abort());
31
+ /** Bilangan positif dari variabel lingkungan; nilai lain diabaikan sehingga bawaan tetap berlaku. */
32
+ function angka(nilai) {
33
+ const n = Number(nilai);
34
+ return Number.isFinite(n) && n > 0 ? n : undefined;
35
+ }
36
+ const ambang = Object.fromEntries(Object.entries({
37
+ ackDetik: angka(process.env.REMPUG_ACK_DETIK),
38
+ diamDetik: angka(process.env.REMPUG_DIAM_DETIK),
39
+ macetDetik: angka(process.env.REMPUG_MACET_DETIK),
40
+ }).filter(([, v]) => v !== undefined));
41
+ process.exitCode = await run(process.argv.slice(2), {
42
+ env: process.env,
43
+ cwd: process.cwd(),
44
+ tmux: process.env.REMPUG_TMUX_SOCKET
45
+ ? { socket: process.env.REMPUG_TMUX_SOCKET }
46
+ : undefined,
47
+ sinyal: kontrol.signal,
48
+ tickOpsi: ambang,
49
+ watchMs: angka(process.env.REMPUG_WATCH_MS),
50
+ io: {
51
+ stdout: (teks) => void process.stdout.write(`${teks}\n`),
52
+ stderr: (teks) => void process.stderr.write(`${teks}\n`),
53
+ stdin: bacaStdin,
54
+ },
55
+ });
@@ -0,0 +1,471 @@
1
+ import { spawn } from "node:child_process";
2
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { homedir } from "node:os";
4
+ import { dirname, join } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { parseArgs } from "node:util";
7
+ import { agentRows, formatAgentRow, register } from "./core/agents.js";
8
+ import { bangunkan } from "./core/bangun.js";
9
+ import { centangItem } from "./core/centang.js";
10
+ import { defaultDoctorDeps, formatDoctor, runDoctor } from "./core/doctor.js";
11
+ import { RempugError, UsageError } from "./core/errors.js";
12
+ import { repoRoot } from "./core/git.js";
13
+ import { Ledger, ledgerPath, retentionDays } from "./core/ledger.js";
14
+ import { jawab, paham, tunggu } from "./core/paham.js";
15
+ import { formatProbe, isStale, probeAgent, versiAgent, } from "./core/probe.js";
16
+ import { readAgents, registryPath, removeAgent, updateAgent, } from "./core/registry.js";
17
+ import { reply } from "./core/reply.js";
18
+ import { barisLog, formatLaporan, formatLaporanMd, formatShow, } from "./core/report.js";
19
+ import { scan } from "./core/scan.js";
20
+ import { KONSUMEN, pump, readBrief, sendTask, } from "./core/send.js";
21
+ import { tick } from "./core/tick.js";
22
+ import { listPanes } from "./core/tmux.js";
23
+ import { tmuxTransport } from "./core/transport.js";
24
+ import { computeChanges, takeSnapshot, unifiedDiff, verifyTask, } from "./core/verify.js";
25
+ import { penandaTertunda, terima, watch } from "./core/watch.js";
26
+ const USAGE = `rempug: distribusi kerja dari agent orkestrator ke agent CLI lain lewat tmux.
27
+
28
+ Untuk orkestrator:
29
+ scan | register <nama> --target T [--jenis J] [--kemampuan a,b] [--tanpa-probe]
30
+ probe <nama> [--profil JSON] | ls | doctor | status
31
+ send <agent> [--queue] [--after N] [--teliti] [--centang berkas#nomor] (brief dari stdin)
32
+ log [--n 20] | show <id> [--penuh] | diff <id> [berkas] | report [--md berkas]
33
+ jawab <id> [teks] | layar <agent> [--baris N] | watch [--konsumen N] | terima
34
+ Untuk agent:
35
+ brief <id> | paham <id> | tunggu <id> | reply <id> [--gagal]
36
+ Lainnya: --version`;
37
+ function argumen(args, options) {
38
+ try {
39
+ return parseArgs({ args, options, allowPositionals: true });
40
+ }
41
+ catch (error) {
42
+ throw new UsageError(error.message);
43
+ }
44
+ }
45
+ function idDari(teks) {
46
+ const n = Number(String(teks ?? "").replace(/^T/i, ""));
47
+ if (!Number.isInteger(n) || n <= 0)
48
+ throw new UsageError(`ID tugas tidak valid: "${teks ?? ""}" (contoh: 12 atau T12)`);
49
+ return n;
50
+ }
51
+ function sendDeps(h) {
52
+ return {
53
+ ledger: h.ledger,
54
+ registryFile: h.registryFile,
55
+ repo: h.repo,
56
+ transport: h.transport,
57
+ tmux: h.ctx.tmux,
58
+ siapkan: (task) => {
59
+ if (task.mode === "edit")
60
+ takeSnapshot(h.ledger, task, task.repo);
61
+ },
62
+ };
63
+ }
64
+ function probeDeps(h) {
65
+ return {
66
+ ledger: h.ledger,
67
+ registryFile: h.registryFile,
68
+ transport: h.transport,
69
+ tmux: h.ctx.tmux,
70
+ repo: h.repo,
71
+ versi: h.ctx.versi,
72
+ ...h.ctx.probe,
73
+ };
74
+ }
75
+ function spawnVerifyBawaan(ctx, id) {
76
+ const cli = fileURLToPath(new URL("./cli.js", import.meta.url));
77
+ spawn(process.execPath, [cli, "_verify", String(id)], {
78
+ detached: true,
79
+ stdio: "ignore",
80
+ cwd: ctx.cwd,
81
+ env: ctx.env,
82
+ }).unref();
83
+ }
84
+ const kerjakan = (h, id) => {
85
+ const task = h.ledger.getTask(id);
86
+ if (!task)
87
+ throw new RempugError(`tugas T${id} tidak ada`);
88
+ return task;
89
+ };
90
+ const HANDLERS = {
91
+ scan(_args, h) {
92
+ h.io.stdout(JSON.stringify(scan(h.repo, { tmux: h.ctx.tmux })));
93
+ },
94
+ async register(args, h) {
95
+ const { values, positionals } = argumen(args, {
96
+ target: { type: "string" },
97
+ jenis: { type: "string" },
98
+ kemampuan: { type: "string" },
99
+ "tanpa-probe": { type: "boolean" },
100
+ });
101
+ const [nama] = positionals;
102
+ if (!nama || !values.target)
103
+ throw new UsageError("pemakaian: rempug register <nama> --target <sesi:window.pane> [--jenis J] [--kemampuan a,b] [--tanpa-probe]");
104
+ register(h.registryFile, {
105
+ name: nama,
106
+ kind: values.jenis ?? nama,
107
+ tmux: values.target,
108
+ capabilities: (values.kemampuan ?? "")
109
+ .split(",")
110
+ .map((k) => k.trim())
111
+ .filter(Boolean),
112
+ }, h.ctx.tmux);
113
+ if (values["tanpa-probe"])
114
+ return void h.io.stdout(`${nama} terdaftar (belum diprobe)`);
115
+ h.io.stdout(formatProbe(await probeAgent(probeDeps(h), nama)));
116
+ },
117
+ async probe(args, h) {
118
+ const { values, positionals } = argumen(args, {
119
+ profil: { type: "string" },
120
+ });
121
+ const [nama] = positionals;
122
+ if (!nama)
123
+ throw new UsageError("pemakaian: rempug probe <nama> [--profil JSON]");
124
+ let kandidat;
125
+ if (values.profil) {
126
+ try {
127
+ kandidat = [JSON.parse(values.profil)];
128
+ }
129
+ catch {
130
+ throw new UsageError("--profil harus berupa JSON profil pengiriman");
131
+ }
132
+ }
133
+ h.io.stdout(formatProbe(await probeAgent({ ...probeDeps(h), ...(kandidat ? { kandidat } : {}) }, nama)));
134
+ },
135
+ async ls(_args, h) {
136
+ const kons = h.ledger.getConsumer(KONSUMEN);
137
+ const hidup = kons?.lastSeen !== undefined && h.ledger.now() - kons.lastSeen <= 10;
138
+ // Tanpa watch yang berjalan, pemeriksaan layar dilakukan di sini agar agent macet tetap terdeteksi.
139
+ if (!hidup)
140
+ await tick({
141
+ ledger: h.ledger,
142
+ repo: h.repo,
143
+ registryFile: h.registryFile,
144
+ transport: h.transport,
145
+ tmux: h.ctx.tmux,
146
+ opsi: h.ctx.tickOpsi,
147
+ }).catch(() => []);
148
+ const rows = agentRows(h.registryFile, h.ledger, h.ctx.tmux);
149
+ h.io.stdout(rows.length
150
+ ? rows.map(formatAgentRow).join("\n")
151
+ : "belum ada agent terdaftar; jalankan /rempug");
152
+ },
153
+ doctor(_args, h) {
154
+ const hasil = runDoctor(defaultDoctorDeps());
155
+ h.io.stdout(formatDoctor(hasil));
156
+ return hasil.ok ? 0 : 1;
157
+ },
158
+ async send(args, h) {
159
+ const { values, positionals } = argumen(args, {
160
+ queue: { type: "boolean" },
161
+ after: { type: "string" },
162
+ teliti: { type: "boolean" },
163
+ centang: { type: "string" },
164
+ brief: { type: "string" },
165
+ });
166
+ const [agent] = positionals;
167
+ if (!agent)
168
+ throw new UsageError("pemakaian: rempug send <agent> [--queue] [--after N] [--teliti] [--centang berkas#nomor] (brief dari stdin)");
169
+ h.ledger.purgeOlderThan(retentionDays(h.ctx.env));
170
+ const brief = values.brief ?? (await h.io.stdin());
171
+ const terdaftar = readAgents(h.registryFile).find((a) => a.name === agent);
172
+ if (terdaftar && isStale(terdaftar, undefined)) {
173
+ const hasil = await probeAgent(probeDeps(h), agent);
174
+ h.io.stdout(`profil ${agent} usang (pengiriman gagal berulang); diprobe ulang: ${hasil.status}`);
175
+ }
176
+ const hasil = await sendTask(sendDeps(h), {
177
+ agent,
178
+ brief,
179
+ queue: values.queue,
180
+ afterId: values.after === undefined ? undefined : idDari(values.after),
181
+ teliti: values.teliti,
182
+ centang: values.centang,
183
+ });
184
+ h.io.stdout(`T${hasil.id} ${hasil.status}`);
185
+ if (hasil.peringatan)
186
+ h.io.stdout(hasil.peringatan);
187
+ },
188
+ brief(args, h) {
189
+ const id = idDari(args[0]);
190
+ h.io.stdout(readBrief(h.ledger, id));
191
+ // Agent yang membaca brief terbukti dapat dijangkau, jadi hitungan kegagalannya diulang dari nol.
192
+ const agent = readAgents(h.registryFile).find((a) => a.name === h.ledger.getTask(id)?.agent);
193
+ if (agent?.gagalBeruntun)
194
+ updateAgent(h.registryFile, agent.name, { gagalBeruntun: 0 });
195
+ },
196
+ async paham(args, h) {
197
+ const id = idDari(args[0]);
198
+ const hasil = paham(h.ledger, id, await h.io.stdin());
199
+ if (hasil.hasil === "LANJUT")
200
+ return void h.io.stdout("LANJUT");
201
+ if (hasil.hasil === "GAGAL-PAHAM")
202
+ return void h.io.stdout(`GAGAL-PAHAM: terlalu banyak klarifikasi; berhenti dan jalankan \`rempug reply T${id} --gagal\`.`);
203
+ h.io.stdout(`MENUNGGU: ${hasil.alasan}\nJalankan \`rempug tunggu T${id}\` dan ulangi sampai LANJUT.`);
204
+ },
205
+ async tunggu(args, h) {
206
+ h.io.stdout(await tunggu(h.ledger, idDari(args[0])));
207
+ },
208
+ async jawab(args, h) {
209
+ const id = idDari(args[0]);
210
+ const teks = args.slice(1).join(" ").trim() || (await h.io.stdin()).trim();
211
+ if (!teks)
212
+ throw new UsageError("pemakaian: rempug jawab <id> <teks> (atau teks dari stdin)");
213
+ const hasil = await jawab({
214
+ ledger: h.ledger,
215
+ registryFile: h.registryFile,
216
+ transport: h.transport,
217
+ tmux: h.ctx.tmux,
218
+ }, id, teks);
219
+ h.io.stdout(hasil === "disimpan"
220
+ ? `T${id}: jawaban disimpan; agent menerimanya lewat rempug tunggu`
221
+ : `T${id}: jawaban dikirim ke agent`);
222
+ },
223
+ async reply(args, h) {
224
+ const { values, positionals } = argumen(args, {
225
+ gagal: { type: "boolean" },
226
+ });
227
+ const id = idDari(positionals[0]);
228
+ const { status } = reply(h.ledger, id, await h.io.stdin(), {
229
+ gagal: values.gagal,
230
+ spawnVerify: h.ctx.spawnVerify ?? ((n) => spawnVerifyBawaan(h.ctx, n)),
231
+ });
232
+ h.io.stdout(status === "gagal"
233
+ ? `OK T${id} ditandai gagal.`
234
+ : `OK T${id} diterima; verifikasi berjalan.`);
235
+ if (status === "gagal")
236
+ await pump(sendDeps(h)).catch(() => []);
237
+ },
238
+ async _verify(args, h) {
239
+ const id = idDari(args[0]);
240
+ const hasil = verifyTask(h.ledger, id);
241
+ const task = kerjakan(h, id);
242
+ if (hasil.ok && task.centang) {
243
+ try {
244
+ centangItem(task.centang, task.repo);
245
+ }
246
+ catch (error) {
247
+ h.ledger.addEvent(id, "peringatan", `T${id} ${task.agent} ⚠ centang gagal: ${error.message}`);
248
+ }
249
+ }
250
+ await pump({ ...sendDeps(h), repo: task.repo }).catch(() => []);
251
+ },
252
+ log(args, h) {
253
+ const { values } = argumen(args, { n: { type: "string" } });
254
+ const n = Number(values.n ?? 20) || 20;
255
+ const tasks = h.ledger.listTasks(h.repo).slice(-n);
256
+ h.io.stdout(tasks.length ? tasks.map(barisLog).join("\n") : "belum ada tugas");
257
+ },
258
+ show(args, h) {
259
+ const { values, positionals } = argumen(args, {
260
+ penuh: { type: "boolean" },
261
+ });
262
+ h.io.stdout(formatShow(kerjakan(h, idDari(positionals[0])), values.penuh === true));
263
+ },
264
+ diff(args, h) {
265
+ const id = idDari(args[0]);
266
+ const task = kerjakan(h, id);
267
+ if (args[1])
268
+ return void h.io.stdout(unifiedDiff(h.ledger, task, task.repo, args[1]));
269
+ const perubahan = computeChanges(h.ledger, task, task.repo);
270
+ h.io.stdout(perubahan.length
271
+ ? perubahan
272
+ .map((f) => `${f.status} ${f.path} +${f.plus}/−${f.minus}${f.biner ? " (biner)" : ""}`)
273
+ .join("\n")
274
+ : "tidak ada perubahan");
275
+ },
276
+ report(args, h) {
277
+ const { values } = argumen(args, { md: { type: "string" } });
278
+ const tasks = h.ledger.listTasks(h.repo);
279
+ if (values.md) {
280
+ writeFileSync(values.md, formatLaporanMd(h.repo, tasks));
281
+ return void h.io.stdout(`laporan ditulis ke ${values.md}`);
282
+ }
283
+ h.io.stdout(formatLaporan(h.repo, tasks));
284
+ },
285
+ layar(args, h) {
286
+ const { values, positionals } = argumen(args, {
287
+ baris: { type: "string" },
288
+ });
289
+ const nama = positionals[0];
290
+ const agent = readAgents(h.registryFile).find((a) => a.name === nama);
291
+ if (!agent)
292
+ throw new RempugError(`agent "${nama ?? ""}" tidak terdaftar`);
293
+ h.io.stdout(h.transport.layar(agent.tmux, Number(values.baris ?? 30) || 30));
294
+ },
295
+ async watch(args, h) {
296
+ const { values } = argumen(args, {
297
+ konsumen: { type: "string" },
298
+ bangun: { type: "boolean" },
299
+ });
300
+ const kontrol = new AbortController();
301
+ h.ctx.sinyal?.addEventListener("abort", () => kontrol.abort(), {
302
+ once: true,
303
+ });
304
+ if (h.ctx.sinyal?.aborted)
305
+ kontrol.abort();
306
+ const pane = values.bangun
307
+ ? listPanes(h.ctx.tmux).find((p) => p.paneId === h.ctx.env.TMUX_PANE)
308
+ : undefined;
309
+ let putaran = 0;
310
+ await watch({
311
+ ledger: h.ledger,
312
+ repo: h.repo,
313
+ konsumen: values.konsumen,
314
+ sinyal: kontrol.signal,
315
+ intervalMs: h.ctx.watchMs ?? 1000,
316
+ tulis: (baris) => {
317
+ h.io.stdout(baris);
318
+ if (pane)
319
+ void bangunkan({
320
+ transport: h.transport,
321
+ target: pane.target,
322
+ baris,
323
+ });
324
+ },
325
+ tiapSiklus: async () => {
326
+ if (++putaran % (h.ctx.tickSetiap ?? 3) !== 0)
327
+ return;
328
+ await tick({
329
+ ledger: h.ledger,
330
+ repo: h.repo,
331
+ registryFile: h.registryFile,
332
+ transport: h.transport,
333
+ tmux: h.ctx.tmux,
334
+ opsi: h.ctx.tickOpsi,
335
+ }).catch(() => []);
336
+ await pump(sendDeps(h)).catch(() => []);
337
+ },
338
+ });
339
+ },
340
+ skill(args, h) {
341
+ if (args[0] !== "install")
342
+ throw new UsageError("pemakaian: rempug skill install");
343
+ const sumber = readFileSync(new URL("../../skills/rempug/SKILL.md", import.meta.url), "utf8");
344
+ const konfig = h.ctx.env.CLAUDE_CONFIG_DIR ||
345
+ join(h.ctx.env.HOME || homedir(), ".claude");
346
+ const tujuan = join(konfig, "skills", "rempug", "SKILL.md");
347
+ let lama;
348
+ try {
349
+ lama = readFileSync(tujuan, "utf8");
350
+ }
351
+ catch {
352
+ lama = undefined;
353
+ }
354
+ if (lama === sumber)
355
+ return void h.io.stdout(`skill sudah terbaru: ${tujuan}`);
356
+ mkdirSync(dirname(tujuan), { recursive: true });
357
+ writeFileSync(tujuan, sumber);
358
+ h.io.stdout(lama === undefined
359
+ ? `skill terpasang: ${tujuan}`
360
+ : `skill diperbarui: ${tujuan}`);
361
+ },
362
+ async mcp(_args, h) {
363
+ const { jalankanMcp } = await import("./mcp.js");
364
+ const { io: _io, ...dasar } = h.ctx;
365
+ await jalankanMcp(dasar, versiPaket());
366
+ },
367
+ terima(_args, h) {
368
+ for (const baris of terima(h.ledger, h.repo))
369
+ h.io.stdout(baris);
370
+ },
371
+ async status(_args, h) {
372
+ h.ledger.purgeOlderThan(retentionDays(h.ctx.env));
373
+ const bagian = [];
374
+ const panes = listPanes(h.ctx.tmux);
375
+ const dibersihkan = [];
376
+ for (const a of readAgents(h.registryFile))
377
+ if (!panes.some((p) => p.target === a.tmux)) {
378
+ removeAgent(h.registryFile, a.name);
379
+ dibersihkan.push(a.name);
380
+ }
381
+ const rows = agentRows(h.registryFile, h.ledger, h.ctx.tmux);
382
+ if (rows.length)
383
+ bagian.push(rows
384
+ .map((r) => `${r.name} ${r.tidakAndal ? "tidak-andal" : r.status}${r.tugas === undefined ? "" : ` (T${r.tugas})`}`)
385
+ .join(", "));
386
+ const baru = scan(h.repo, { tmux: h.ctx.tmux }).kandidat.filter((c) => c.keyakinan === "tinggi" && !rows.some((r) => r.tmux === c.target));
387
+ if (baru.length)
388
+ bagian.push(`baru: ${baru.map((c) => `${c.jenis} (${c.target})`).join(", ")}`);
389
+ if (dibersihkan.length)
390
+ bagian.push(`dibersihkan: ${dibersihkan.join(", ")}`);
391
+ const versi = h.ctx.versi ?? versiAgent;
392
+ const usang = rows
393
+ .filter((r) => isStale(r, versi(r.kind)))
394
+ .map((r) => r.name);
395
+ if (usang.length)
396
+ bagian.push(`usang: ${usang.join(", ")} (jalankan probe)`);
397
+ const kons = h.ledger.getConsumer(KONSUMEN);
398
+ const hidup = kons?.lastSeen !== undefined && h.ledger.now() - kons.lastSeen <= 10;
399
+ if (rows.length)
400
+ bagian.push(hidup ? "pantau aktif" : "pantau mati");
401
+ h.io.stdout(bagian.length
402
+ ? `rempug: ${bagian.join(" | ")}`
403
+ : "rempug: belum ada agent; jalankan /rempug");
404
+ },
405
+ };
406
+ /** Perintah yang menempel penanda kejadian tertunda di awal keluarannya (hanya yang dipakai orkestrator). */
407
+ const BERPENANDA = new Set([
408
+ "ls",
409
+ "send",
410
+ "jawab",
411
+ "log",
412
+ "show",
413
+ "diff",
414
+ "report",
415
+ "layar",
416
+ "status",
417
+ "probe",
418
+ "register",
419
+ ]);
420
+ function versiPaket() {
421
+ const pkg = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
422
+ return pkg.version;
423
+ }
424
+ /** Menjalankan satu perintah rempug dan mengembalikan kode keluar. Tidak pernah melempar. */
425
+ export async function run(argv, ctx) {
426
+ const [cmd, ...args] = argv;
427
+ const { io } = ctx;
428
+ if (!cmd || cmd === "--help" || cmd === "-h" || cmd === "help") {
429
+ io.stdout(USAGE);
430
+ return 0;
431
+ }
432
+ if (cmd === "--version") {
433
+ io.stdout(versiPaket());
434
+ return 0;
435
+ }
436
+ let ledger;
437
+ try {
438
+ const handler = HANDLERS[cmd];
439
+ if (!handler)
440
+ throw new UsageError(`perintah "${cmd}" tidak dikenal; lihat --help`);
441
+ const h = {
442
+ get ledger() {
443
+ ledger ??= Ledger.open(ledgerPath(ctx.env));
444
+ return ledger;
445
+ },
446
+ repo: repoRoot(ctx.cwd),
447
+ registryFile: registryPath(ctx.env),
448
+ transport: ctx.transport ?? tmuxTransport(ctx.tmux),
449
+ ctx,
450
+ io,
451
+ };
452
+ if (BERPENANDA.has(cmd)) {
453
+ const penanda = penandaTertunda(h.ledger, h.repo);
454
+ if (penanda)
455
+ io.stdout(penanda);
456
+ }
457
+ const hasil = await handler(args, h);
458
+ return typeof hasil === "number" ? hasil : 0;
459
+ }
460
+ catch (error) {
461
+ if (error instanceof RempugError) {
462
+ io.stderr(`rempug: ${error.message}`);
463
+ return error.kode;
464
+ }
465
+ io.stderr(`rempug: galat tak terduga: ${error.stack ?? error}`);
466
+ return 1;
467
+ }
468
+ finally {
469
+ ledger?.close();
470
+ }
471
+ }