rempug 0.0.0-stage → 0.1.1
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/.claude-plugin/marketplace.json +14 -0
- package/.claude-plugin/plugin.json +6 -0
- package/.mcp.json +8 -0
- package/LICENSE +21 -0
- package/README.md +105 -2
- package/dist/src/cli.js +55 -0
- package/dist/src/commands.js +476 -0
- package/dist/src/core/agents.js +42 -0
- package/dist/src/core/bangun.js +21 -0
- package/dist/src/core/brief.js +91 -0
- package/dist/src/core/centang.js +34 -0
- package/dist/src/core/doctor.js +58 -0
- package/dist/src/core/errors.js +16 -0
- package/dist/src/core/git.js +35 -0
- package/dist/src/core/ledger.js +349 -0
- package/dist/src/core/paham.js +149 -0
- package/dist/src/core/probe.js +204 -0
- package/dist/src/core/profile.js +31 -0
- package/dist/src/core/registry.js +78 -0
- package/dist/src/core/reply.js +38 -0
- package/dist/src/core/report.js +206 -0
- package/dist/src/core/scan.js +58 -0
- package/dist/src/core/scope.js +103 -0
- package/dist/src/core/screen.js +74 -0
- package/dist/src/core/sections.js +25 -0
- package/dist/src/core/send.js +166 -0
- package/dist/src/core/tick.js +119 -0
- package/dist/src/core/tmux.js +33 -0
- package/dist/src/core/transport.js +48 -0
- package/dist/src/core/verify.js +308 -0
- package/dist/src/core/watch.js +51 -0
- package/dist/src/mcp.js +119 -0
- package/dist/src/runtime.js +31 -0
- package/hooks/hooks.json +15 -0
- package/package.json +63 -5
- package/skills/rempug/SKILL.md +107 -0
|
@@ -0,0 +1,476 @@
|
|
|
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, formatLaporanManusia, 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, {
|
|
278
|
+
md: { type: "string" },
|
|
279
|
+
manusia: { type: "boolean" },
|
|
280
|
+
});
|
|
281
|
+
const tasks = h.ledger.listTasks(h.repo);
|
|
282
|
+
if (values.md) {
|
|
283
|
+
writeFileSync(values.md, formatLaporanMd(h.repo, tasks));
|
|
284
|
+
return void h.io.stdout(`laporan ditulis ke ${values.md}`);
|
|
285
|
+
}
|
|
286
|
+
h.io.stdout(values.manusia
|
|
287
|
+
? formatLaporanManusia(tasks)
|
|
288
|
+
: formatLaporan(h.repo, tasks));
|
|
289
|
+
},
|
|
290
|
+
layar(args, h) {
|
|
291
|
+
const { values, positionals } = argumen(args, {
|
|
292
|
+
baris: { type: "string" },
|
|
293
|
+
});
|
|
294
|
+
const nama = positionals[0];
|
|
295
|
+
const agent = readAgents(h.registryFile).find((a) => a.name === nama);
|
|
296
|
+
if (!agent)
|
|
297
|
+
throw new RempugError(`agent "${nama ?? ""}" tidak terdaftar`);
|
|
298
|
+
h.io.stdout(h.transport.layar(agent.tmux, Number(values.baris ?? 30) || 30));
|
|
299
|
+
},
|
|
300
|
+
async watch(args, h) {
|
|
301
|
+
const { values } = argumen(args, {
|
|
302
|
+
konsumen: { type: "string" },
|
|
303
|
+
bangun: { type: "boolean" },
|
|
304
|
+
});
|
|
305
|
+
const kontrol = new AbortController();
|
|
306
|
+
h.ctx.sinyal?.addEventListener("abort", () => kontrol.abort(), {
|
|
307
|
+
once: true,
|
|
308
|
+
});
|
|
309
|
+
if (h.ctx.sinyal?.aborted)
|
|
310
|
+
kontrol.abort();
|
|
311
|
+
const pane = values.bangun
|
|
312
|
+
? listPanes(h.ctx.tmux).find((p) => p.paneId === h.ctx.env.TMUX_PANE)
|
|
313
|
+
: undefined;
|
|
314
|
+
let putaran = 0;
|
|
315
|
+
await watch({
|
|
316
|
+
ledger: h.ledger,
|
|
317
|
+
repo: h.repo,
|
|
318
|
+
konsumen: values.konsumen,
|
|
319
|
+
sinyal: kontrol.signal,
|
|
320
|
+
intervalMs: h.ctx.watchMs ?? 1000,
|
|
321
|
+
tulis: (baris) => {
|
|
322
|
+
h.io.stdout(baris);
|
|
323
|
+
if (pane)
|
|
324
|
+
void bangunkan({
|
|
325
|
+
transport: h.transport,
|
|
326
|
+
target: pane.target,
|
|
327
|
+
baris,
|
|
328
|
+
});
|
|
329
|
+
},
|
|
330
|
+
tiapSiklus: async () => {
|
|
331
|
+
if (++putaran % (h.ctx.tickSetiap ?? 3) !== 0)
|
|
332
|
+
return;
|
|
333
|
+
await tick({
|
|
334
|
+
ledger: h.ledger,
|
|
335
|
+
repo: h.repo,
|
|
336
|
+
registryFile: h.registryFile,
|
|
337
|
+
transport: h.transport,
|
|
338
|
+
tmux: h.ctx.tmux,
|
|
339
|
+
opsi: h.ctx.tickOpsi,
|
|
340
|
+
}).catch(() => []);
|
|
341
|
+
await pump(sendDeps(h)).catch(() => []);
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
},
|
|
345
|
+
skill(args, h) {
|
|
346
|
+
if (args[0] !== "install")
|
|
347
|
+
throw new UsageError("pemakaian: rempug skill install");
|
|
348
|
+
const sumber = readFileSync(new URL("../../skills/rempug/SKILL.md", import.meta.url), "utf8");
|
|
349
|
+
const konfig = h.ctx.env.CLAUDE_CONFIG_DIR ||
|
|
350
|
+
join(h.ctx.env.HOME || homedir(), ".claude");
|
|
351
|
+
const tujuan = join(konfig, "skills", "rempug", "SKILL.md");
|
|
352
|
+
let lama;
|
|
353
|
+
try {
|
|
354
|
+
lama = readFileSync(tujuan, "utf8");
|
|
355
|
+
}
|
|
356
|
+
catch {
|
|
357
|
+
lama = undefined;
|
|
358
|
+
}
|
|
359
|
+
if (lama === sumber)
|
|
360
|
+
return void h.io.stdout(`skill sudah terbaru: ${tujuan}`);
|
|
361
|
+
mkdirSync(dirname(tujuan), { recursive: true });
|
|
362
|
+
writeFileSync(tujuan, sumber);
|
|
363
|
+
h.io.stdout(lama === undefined
|
|
364
|
+
? `skill terpasang: ${tujuan}`
|
|
365
|
+
: `skill diperbarui: ${tujuan}`);
|
|
366
|
+
},
|
|
367
|
+
async mcp(_args, h) {
|
|
368
|
+
const { jalankanMcp } = await import("./mcp.js");
|
|
369
|
+
const { io: _io, ...dasar } = h.ctx;
|
|
370
|
+
await jalankanMcp(dasar, versiPaket());
|
|
371
|
+
},
|
|
372
|
+
terima(_args, h) {
|
|
373
|
+
for (const baris of terima(h.ledger, h.repo))
|
|
374
|
+
h.io.stdout(baris);
|
|
375
|
+
},
|
|
376
|
+
async status(_args, h) {
|
|
377
|
+
h.ledger.purgeOlderThan(retentionDays(h.ctx.env));
|
|
378
|
+
const bagian = [];
|
|
379
|
+
const panes = listPanes(h.ctx.tmux);
|
|
380
|
+
const dibersihkan = [];
|
|
381
|
+
for (const a of readAgents(h.registryFile))
|
|
382
|
+
if (!panes.some((p) => p.target === a.tmux)) {
|
|
383
|
+
removeAgent(h.registryFile, a.name);
|
|
384
|
+
dibersihkan.push(a.name);
|
|
385
|
+
}
|
|
386
|
+
const rows = agentRows(h.registryFile, h.ledger, h.ctx.tmux);
|
|
387
|
+
if (rows.length)
|
|
388
|
+
bagian.push(rows
|
|
389
|
+
.map((r) => `${r.name} ${r.tidakAndal ? "tidak-andal" : r.status}${r.tugas === undefined ? "" : ` (T${r.tugas})`}`)
|
|
390
|
+
.join(", "));
|
|
391
|
+
const baru = scan(h.repo, { tmux: h.ctx.tmux }).kandidat.filter((c) => c.keyakinan === "tinggi" && !rows.some((r) => r.tmux === c.target));
|
|
392
|
+
if (baru.length)
|
|
393
|
+
bagian.push(`baru: ${baru.map((c) => `${c.jenis} (${c.target})`).join(", ")}`);
|
|
394
|
+
if (dibersihkan.length)
|
|
395
|
+
bagian.push(`dibersihkan: ${dibersihkan.join(", ")}`);
|
|
396
|
+
const versi = h.ctx.versi ?? versiAgent;
|
|
397
|
+
const usang = rows
|
|
398
|
+
.filter((r) => isStale(r, versi(r.kind)))
|
|
399
|
+
.map((r) => r.name);
|
|
400
|
+
if (usang.length)
|
|
401
|
+
bagian.push(`usang: ${usang.join(", ")} (jalankan probe)`);
|
|
402
|
+
const kons = h.ledger.getConsumer(KONSUMEN);
|
|
403
|
+
const hidup = kons?.lastSeen !== undefined && h.ledger.now() - kons.lastSeen <= 10;
|
|
404
|
+
if (rows.length)
|
|
405
|
+
bagian.push(hidup ? "pantau aktif" : "pantau mati");
|
|
406
|
+
h.io.stdout(bagian.length
|
|
407
|
+
? `rempug: ${bagian.join(" | ")}`
|
|
408
|
+
: "rempug: belum ada agent; jalankan /rempug");
|
|
409
|
+
},
|
|
410
|
+
};
|
|
411
|
+
/** Perintah yang menempel penanda kejadian tertunda di awal keluarannya (hanya yang dipakai orkestrator). */
|
|
412
|
+
const BERPENANDA = new Set([
|
|
413
|
+
"ls",
|
|
414
|
+
"send",
|
|
415
|
+
"jawab",
|
|
416
|
+
"log",
|
|
417
|
+
"show",
|
|
418
|
+
"diff",
|
|
419
|
+
"report",
|
|
420
|
+
"layar",
|
|
421
|
+
"status",
|
|
422
|
+
"probe",
|
|
423
|
+
"register",
|
|
424
|
+
]);
|
|
425
|
+
function versiPaket() {
|
|
426
|
+
const pkg = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
|
|
427
|
+
return pkg.version;
|
|
428
|
+
}
|
|
429
|
+
/** Menjalankan satu perintah rempug dan mengembalikan kode keluar. Tidak pernah melempar. */
|
|
430
|
+
export async function run(argv, ctx) {
|
|
431
|
+
const [cmd, ...args] = argv;
|
|
432
|
+
const { io } = ctx;
|
|
433
|
+
if (!cmd || cmd === "--help" || cmd === "-h" || cmd === "help") {
|
|
434
|
+
io.stdout(USAGE);
|
|
435
|
+
return 0;
|
|
436
|
+
}
|
|
437
|
+
if (cmd === "--version") {
|
|
438
|
+
io.stdout(versiPaket());
|
|
439
|
+
return 0;
|
|
440
|
+
}
|
|
441
|
+
let ledger;
|
|
442
|
+
try {
|
|
443
|
+
const handler = HANDLERS[cmd];
|
|
444
|
+
if (!handler)
|
|
445
|
+
throw new UsageError(`perintah "${cmd}" tidak dikenal; lihat --help`);
|
|
446
|
+
const h = {
|
|
447
|
+
get ledger() {
|
|
448
|
+
ledger ??= Ledger.open(ledgerPath(ctx.env));
|
|
449
|
+
return ledger;
|
|
450
|
+
},
|
|
451
|
+
repo: repoRoot(ctx.cwd),
|
|
452
|
+
registryFile: registryPath(ctx.env),
|
|
453
|
+
transport: ctx.transport ?? tmuxTransport(ctx.tmux),
|
|
454
|
+
ctx,
|
|
455
|
+
io,
|
|
456
|
+
};
|
|
457
|
+
if (BERPENANDA.has(cmd)) {
|
|
458
|
+
const penanda = penandaTertunda(h.ledger, h.repo);
|
|
459
|
+
if (penanda)
|
|
460
|
+
io.stdout(penanda);
|
|
461
|
+
}
|
|
462
|
+
const hasil = await handler(args, h);
|
|
463
|
+
return typeof hasil === "number" ? hasil : 0;
|
|
464
|
+
}
|
|
465
|
+
catch (error) {
|
|
466
|
+
if (error instanceof RempugError) {
|
|
467
|
+
io.stderr(`rempug: ${error.message}`);
|
|
468
|
+
return error.kode;
|
|
469
|
+
}
|
|
470
|
+
io.stderr(`rempug: galat tak terduga: ${error.stack ?? error}`);
|
|
471
|
+
return 1;
|
|
472
|
+
}
|
|
473
|
+
finally {
|
|
474
|
+
ledger?.close();
|
|
475
|
+
}
|
|
476
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readAgents, registerAgent } from "./registry.js";
|
|
2
|
+
import { listPanes } from "./tmux.js";
|
|
3
|
+
/** Mendaftarkan agent setelah memastikan pane-nya ada di tmux. */
|
|
4
|
+
export function register(file, agent, tmux) {
|
|
5
|
+
if (!listPanes(tmux).some((p) => p.target === agent.tmux))
|
|
6
|
+
throw new Error(`pane "${agent.tmux}" tidak ada di tmux`);
|
|
7
|
+
registerAgent(file, agent);
|
|
8
|
+
return agent;
|
|
9
|
+
}
|
|
10
|
+
/** Satu baris per agent terdaftar, dengan status dari tmux dan ledger. */
|
|
11
|
+
export function agentRows(file, ledger, tmux) {
|
|
12
|
+
const targets = new Set(listPanes(tmux).map((p) => p.target));
|
|
13
|
+
return readAgents(file).map((agent) => {
|
|
14
|
+
if (!targets.has(agent.tmux))
|
|
15
|
+
return { ...agent, status: "hilang", tugas: undefined };
|
|
16
|
+
const aktif = ledger.activeTaskOf(agent.name);
|
|
17
|
+
return aktif
|
|
18
|
+
? { ...agent, status: "sibuk", tugas: aktif.id }
|
|
19
|
+
: { ...agent, status: "siap", tugas: undefined };
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/** Agent yang boleh menerima tugas; menolak yang tidak terdaftar atau sesinya hilang. */
|
|
23
|
+
export function requireAvailable(rows, name) {
|
|
24
|
+
const row = rows.find((r) => r.name === name);
|
|
25
|
+
if (!row)
|
|
26
|
+
throw new Error(`agent "${name}" tidak terdaftar`);
|
|
27
|
+
if (row.tidakAndal)
|
|
28
|
+
throw new Error(`agent "${name}" tidak andal (gagal probe); jalankan /rempug untuk mengujinya lagi`);
|
|
29
|
+
if (row.status === "hilang")
|
|
30
|
+
throw new Error(`agent "${name}" hilang: pane ${row.tmux} tidak ada lagi di tmux`);
|
|
31
|
+
return row;
|
|
32
|
+
}
|
|
33
|
+
export function formatAgentRow(row) {
|
|
34
|
+
const status = row.tidakAndal ? "tidak-andal" : row.status;
|
|
35
|
+
const kemampuan = row.capabilities.length ? row.capabilities.join(",") : "-";
|
|
36
|
+
const tugas = row.tugas === undefined ? "" : ` T${row.tugas}`;
|
|
37
|
+
const ack = row.ukur?.ackMs === undefined
|
|
38
|
+
? ""
|
|
39
|
+
: ` ack ${(row.ukur.ackMs / 1000).toFixed(1)}s`;
|
|
40
|
+
const catatan = row.tidakAndal && row.catatan ? ` — ${row.catatan}` : "";
|
|
41
|
+
return `${row.name.padEnd(10)}${status} ${kemampuan}${tugas}${ack}${catatan}`;
|
|
42
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
2
|
+
/**
|
|
3
|
+
* Cadangan bila tool Monitor tidak ada: mengetik satu baris ke pane orkestrator, hanya saat pane itu idle
|
|
4
|
+
* (layar tidak berubah), supaya tidak bercampur dengan ketikan atau keluaran yang sedang berjalan.
|
|
5
|
+
*/
|
|
6
|
+
export async function bangunkan(opsi) {
|
|
7
|
+
const { transport, target } = opsi;
|
|
8
|
+
try {
|
|
9
|
+
// Perbandingan mentah, bukan hashLayar: untuk menyuntik teks, timer yang berjalan pun berarti pane sibuk.
|
|
10
|
+
const awal = transport.tampak(target).baris.join("\n");
|
|
11
|
+
await sleep(opsi.jedaMs ?? 400);
|
|
12
|
+
const akhir = transport.tampak(target).baris.join("\n");
|
|
13
|
+
if (awal !== akhir)
|
|
14
|
+
return false;
|
|
15
|
+
await transport.kirim(target, `[rempug] ${opsi.baris}`);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { parseSections } from "./sections.js";
|
|
2
|
+
export const SECTIONS = [
|
|
3
|
+
"TUJUAN",
|
|
4
|
+
"CAKUPAN",
|
|
5
|
+
"LANGKAH",
|
|
6
|
+
"CEK",
|
|
7
|
+
"BALASAN",
|
|
8
|
+
];
|
|
9
|
+
const LANGKAH_BARIS = /^\s*\d+[.)]\s+(.*)$/;
|
|
10
|
+
function parsePath(raw) {
|
|
11
|
+
const path = raw.replace(/^(\.\/)+/, "");
|
|
12
|
+
if (!path || path.startsWith("/") || path.startsWith("-"))
|
|
13
|
+
return undefined;
|
|
14
|
+
return path.split("/").includes("..") ? undefined : path;
|
|
15
|
+
}
|
|
16
|
+
function parseCakupan(text, errors) {
|
|
17
|
+
const [mode, ...rest] = text.split(/[\s,]+/).filter(Boolean);
|
|
18
|
+
if ((mode === "baca" || mode === "browser") && rest.length === 0)
|
|
19
|
+
return { mode };
|
|
20
|
+
if (mode === "edit") {
|
|
21
|
+
if (rest.length === 0) {
|
|
22
|
+
errors.push("CAKUPAN: mode edit wajib menyebut minimal satu path");
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
const paths = rest.map(parsePath);
|
|
26
|
+
const buruk = rest.filter((_, i) => paths[i] === undefined);
|
|
27
|
+
if (buruk.length > 0) {
|
|
28
|
+
errors.push(`CAKUPAN: path tidak valid (harus relatif terhadap repo, tanpa "..", tidak diawali "-"): ${buruk.join(", ")}`);
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
return { mode, paths: paths };
|
|
32
|
+
}
|
|
33
|
+
errors.push('CAKUPAN harus "edit <path...>", "baca", atau "browser"');
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
function parseLangkah(text, errors) {
|
|
37
|
+
const langkah = [];
|
|
38
|
+
for (const line of text.split("\n")) {
|
|
39
|
+
if (!line.trim())
|
|
40
|
+
continue;
|
|
41
|
+
const nomor = LANGKAH_BARIS.exec(line);
|
|
42
|
+
if (nomor)
|
|
43
|
+
langkah.push((nomor[1] ?? "").trim());
|
|
44
|
+
else if (langkah.length > 0)
|
|
45
|
+
langkah[langkah.length - 1] += ` ${line.trim()}`;
|
|
46
|
+
else {
|
|
47
|
+
errors.push('LANGKAH harus bernomor, mis. "1. buka halaman"');
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return langkah;
|
|
52
|
+
}
|
|
53
|
+
/** Mengurai dan memvalidasi brief; semua kekurangan dilaporkan sekaligus. */
|
|
54
|
+
export function parseBrief(text) {
|
|
55
|
+
const { body: found, errors } = parseSections(text, SECTIONS);
|
|
56
|
+
const body = new Map();
|
|
57
|
+
for (const section of SECTIONS) {
|
|
58
|
+
const content = found.get(section);
|
|
59
|
+
if (content)
|
|
60
|
+
body.set(section, content);
|
|
61
|
+
else
|
|
62
|
+
errors.push(`bagian ${section} hilang atau kosong`);
|
|
63
|
+
}
|
|
64
|
+
const cakupan = body.has("CAKUPAN")
|
|
65
|
+
? parseCakupan(body.get("CAKUPAN"), errors)
|
|
66
|
+
: undefined;
|
|
67
|
+
const langkah = body.has("LANGKAH")
|
|
68
|
+
? parseLangkah(body.get("LANGKAH"), errors)
|
|
69
|
+
: [];
|
|
70
|
+
const cekText = body.get("CEK");
|
|
71
|
+
const cek = cekText === undefined || /^(-|tidak ada)$/i.test(cekText)
|
|
72
|
+
? []
|
|
73
|
+
: cekText
|
|
74
|
+
.split("\n")
|
|
75
|
+
.map((l) => l.trim())
|
|
76
|
+
.filter(Boolean);
|
|
77
|
+
if (cekText !== undefined && cakupan?.mode === "edit" && cek.length === 0)
|
|
78
|
+
errors.push("CEK wajib berisi minimal satu perintah untuk tugas edit");
|
|
79
|
+
if (errors.length > 0 || !cakupan)
|
|
80
|
+
return { ok: false, errors };
|
|
81
|
+
return {
|
|
82
|
+
ok: true,
|
|
83
|
+
brief: {
|
|
84
|
+
tujuan: body.get("TUJUAN"),
|
|
85
|
+
cakupan,
|
|
86
|
+
langkah,
|
|
87
|
+
cek,
|
|
88
|
+
balasan: body.get("BALASAN"),
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, relative, resolve } from "node:path";
|
|
3
|
+
import { RempugError, UsageError } from "./errors.js";
|
|
4
|
+
const escapeRegex = (teks) => teks.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
5
|
+
/**
|
|
6
|
+
* Mencentang satu item `tasks.md` (`berkas#nomor`, mis. `spec/tasks.md#2.1`): hanya baris itu yang berubah
|
|
7
|
+
* dari `- [ ]` menjadi `- [x]`. Mengembalikan `false` bila item sudah tercentang.
|
|
8
|
+
*/
|
|
9
|
+
export function centangItem(spesifikasi, repo) {
|
|
10
|
+
const [berkas, nomor, ...lebih] = spesifikasi.split("#");
|
|
11
|
+
if (!berkas || !nomor || lebih.length > 0)
|
|
12
|
+
throw new UsageError(`--centang harus berbentuk berkas#nomor, mis. spec/tasks.md#2.1 (diterima: ${spesifikasi})`);
|
|
13
|
+
const path = resolve(repo, berkas);
|
|
14
|
+
const rel = relative(repo, path);
|
|
15
|
+
if (isAbsolute(berkas) || rel.startsWith("..") || isAbsolute(rel))
|
|
16
|
+
throw new UsageError(`${berkas} di luar repo; --centang hanya untuk berkas di dalam repo`);
|
|
17
|
+
let isi;
|
|
18
|
+
try {
|
|
19
|
+
isi = readFileSync(path, "utf8");
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
throw new RempugError(`berkas ${berkas} tidak ada`);
|
|
23
|
+
}
|
|
24
|
+
// Nomor tingkat atas ditulis "2." sedangkan sub-item "2.1"; "2" tidak boleh cocok dengan "2.1".
|
|
25
|
+
const belum = new RegExp(`^(\\s*- )\\[ \\] (${escapeRegex(nomor)}(?:\\.(?=\\s)|(?=\\s)))`, "m");
|
|
26
|
+
const sudah = new RegExp(`^\\s*- \\[x\\] ${escapeRegex(nomor)}(?:\\.(?=\\s)|(?=\\s))`, "m");
|
|
27
|
+
if (!belum.test(isi)) {
|
|
28
|
+
if (sudah.test(isi))
|
|
29
|
+
return false;
|
|
30
|
+
throw new RempugError(`item ${nomor} tidak ditemukan di ${berkas}`);
|
|
31
|
+
}
|
|
32
|
+
writeFileSync(path, isi.replace(belum, "$1[x] $2"));
|
|
33
|
+
return true;
|
|
34
|
+
}
|