jioogen 0.2.5 → 0.2.7

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/dist/index.js CHANGED
@@ -2124,8 +2124,8 @@ var require_adm_zip = __commonJS({
2124
2124
  return null;
2125
2125
  }
2126
2126
  function fixPath(zipPath) {
2127
- const { join: join8, normalize, sep: sep2 } = pth.posix;
2128
- return join8(pth.isAbsolute(zipPath) ? "/" : ".", normalize(sep2 + zipPath.split("\\").join(sep2) + sep2));
2127
+ const { join: join9, normalize, sep: sep2 } = pth.posix;
2128
+ return join9(pth.isAbsolute(zipPath) ? "/" : ".", normalize(sep2 + zipPath.split("\\").join(sep2) + sep2));
2129
2129
  }
2130
2130
  function filenameFilter(filterfn) {
2131
2131
  if (filterfn instanceof RegExp) {
@@ -2978,8 +2978,9 @@ var ApiClient = class {
2978
2978
  };
2979
2979
 
2980
2980
  // src/commands.ts
2981
- import { readdir as readdir5, readFile as readFile7 } from "node:fs/promises";
2982
- import { join as join7, resolve as resolve5 } from "node:path";
2981
+ import { spawn } from "node:child_process";
2982
+ import { readdir as readdir5, readFile as readFile8 } from "node:fs/promises";
2983
+ import { join as join8, resolve as resolve5 } from "node:path";
2983
2984
 
2984
2985
  // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
2985
2986
  var external_exports = {};
@@ -7363,6 +7364,65 @@ function lintRequirementAcceptance(markdown) {
7363
7364
  }
7364
7365
  return { ok: issues.length === 0, issues, sectionsAccounted: 0 };
7365
7366
  }
7367
+ var VERIFICATION_LABEL_RE = /^\s*(?:[-*]\s*)?\*{0,2}verificationCommand\*{0,2}\s*:\s*(.+)$/im;
7368
+ var VERIFICATION_HEADING_RE = /^#{1,6}\s*verification command\s*$/im;
7369
+ var TARGET_FILES_LABEL_RE = /^\s*(?:[-*]\s*)?\*{0,2}targetFiles\*{0,2}\s*:\s*(.*)$/im;
7370
+ var TARGET_FILES_HEADING_RE = /^#{1,6}\s*target files\s*$/im;
7371
+ var ACCEPTANCE_HEADING_RE = /^#{1,6}\s*acceptance criteria\s*$/im;
7372
+ function cleanCommand(value) {
7373
+ return value.replace(/^[-*]\s+/, "").replace(/[`"']/g, "").trim();
7374
+ }
7375
+ function followingBlock(content, headingRe) {
7376
+ const lines = content.split(/\r?\n/);
7377
+ const index = lines.findIndex((line) => headingRe.test(line));
7378
+ if (index === -1) return "";
7379
+ const rest = [];
7380
+ for (let i = index + 1; i < lines.length; i += 1) {
7381
+ const line = lines[i] ?? "";
7382
+ if (/^#{1,6}\s+/.test(line)) break;
7383
+ rest.push(line);
7384
+ }
7385
+ return rest.join("\n").trim();
7386
+ }
7387
+ function taskVerificationCommand(content) {
7388
+ const inline = content.match(VERIFICATION_LABEL_RE)?.[1];
7389
+ if (inline !== void 0) {
7390
+ const cleaned2 = cleanCommand(inline);
7391
+ return cleaned2.length === 0 ? null : cleaned2;
7392
+ }
7393
+ const block = followingBlock(content, VERIFICATION_HEADING_RE);
7394
+ if (block.length === 0) return null;
7395
+ const first = block.split(/\r?\n/).find((line) => line.trim().length > 0);
7396
+ if (first === void 0) return null;
7397
+ const cleaned = cleanCommand(first);
7398
+ return cleaned.length === 0 || /^n\/?a$|^—+$|^-+$/i.test(cleaned) ? null : cleaned;
7399
+ }
7400
+ function taskTargetFiles(content) {
7401
+ const lines = content.split(/\r?\n/);
7402
+ const labelIndex = lines.findIndex((line) => TARGET_FILES_LABEL_RE.test(line));
7403
+ let source = [];
7404
+ if (labelIndex !== -1) {
7405
+ const inline = (lines[labelIndex]?.match(TARGET_FILES_LABEL_RE)?.[1] ?? "").trim();
7406
+ if (inline.length > 0 && inline !== "[]") {
7407
+ source = inline.split(",");
7408
+ } else {
7409
+ for (let i = labelIndex + 1; i < lines.length; i += 1) {
7410
+ const line = lines[i] ?? "";
7411
+ if (line.trim().length === 0) continue;
7412
+ const item = /^\s*-\s+(.+?)\s*$/.exec(line);
7413
+ if (item === null) break;
7414
+ source.push(item[1] ?? "");
7415
+ }
7416
+ }
7417
+ }
7418
+ if (source.length === 0) {
7419
+ source = followingBlock(content, TARGET_FILES_HEADING_RE).split(/\r?\n/);
7420
+ }
7421
+ return source.map((item) => cleanCommand(item).replace(/^[-*]\s+/, "")).map((item) => item.replace(/[[\]]/g, "").trim()).filter((item) => item.length > 0);
7422
+ }
7423
+ function taskAcceptance(content) {
7424
+ return followingBlock(content, ACCEPTANCE_HEADING_RE);
7425
+ }
7366
7426
  function lintTaskBundle(files) {
7367
7427
  const issues = [];
7368
7428
  for (const file of files) {
@@ -7385,6 +7445,41 @@ function lintTaskBundle(files) {
7385
7445
  message: `Task "${file.path}" tidak merujuk requirement mana pun (FR/NFR/BR/REQ) dan bukan foundation`
7386
7446
  });
7387
7447
  }
7448
+ const command = taskVerificationCommand(file.content);
7449
+ if (command !== null && /--passWithNoTests|--pass-with-no-tests/i.test(command)) {
7450
+ issues.push({
7451
+ code: "VERIFICATION_FAKE_FLAG",
7452
+ where: file.path,
7453
+ message: `Task "${file.path}" memakai --passWithNoTests pada verificationCommand (verifikasi palsu)`
7454
+ });
7455
+ }
7456
+ const acceptance = taskAcceptance(file.content);
7457
+ const mentionsTests = /\b(test|tests|testing)\b/i.test(acceptance);
7458
+ const mentionsVerification = /\b(test|tests|verifikasi|typecheck|lint)\b/i.test(acceptance);
7459
+ const coversAllCommands = /\b(semua|all)\s+verificationCommand/i.test(acceptance);
7460
+ if (mentionsVerification && !coversAllCommands && command !== null) {
7461
+ const runsVerification = /test|vitest|jest|pytest|go test|cargo test|typecheck|\btsc\b|biome|eslint|lint/i.test(
7462
+ command
7463
+ );
7464
+ if (!runsVerification) {
7465
+ issues.push({
7466
+ code: "VERIFICATION_MISSING_AC_COMMAND",
7467
+ where: file.path,
7468
+ message: `Task "${file.path}" AC menyebut test/verifikasi tetapi verificationCommand tidak menjalankannya`
7469
+ });
7470
+ }
7471
+ }
7472
+ if (mentionsTests) {
7473
+ const targets = taskTargetFiles(file.content);
7474
+ const hasTestTarget = targets.some((target) => /test|spec|__tests__/i.test(target));
7475
+ if (targets.length > 0 && !hasTestTarget) {
7476
+ issues.push({
7477
+ code: "TARGET_FILES_MISSING_TEST",
7478
+ where: file.path,
7479
+ message: `Task "${file.path}" AC menyebut test tetapi targetFiles tidak memuat file test`
7480
+ });
7481
+ }
7482
+ }
7388
7483
  }
7389
7484
  return { ok: issues.length === 0, issues, sectionsAccounted: 0 };
7390
7485
  }
@@ -8804,8 +8899,8 @@ var JIOOGEN_AGENTS_MD = `${MARKER}
8804
8899
  1. \`npx jioogen task next\` \u2014 baca blok **TASK AKTIF** + isi file task.
8805
8900
  2. \`npx jioogen task start <ref>\`.
8806
8901
  3. Implementasikan **hanya** task itu sampai semua Acceptance Criteria terpenuhi.
8807
- 4. Jalankan \`verificationCommand\` task itu sampai **exit 0** (jangan dipalsukan).
8808
- 5. \`npx jioogen task complete <ref>\`, lalu buat satu commit git kecil.
8902
+ 4. Jalankan \`npx jioogen task verify <ref>\` \u2014 CLI menjalankan \`verificationCommand\` dan mencatat bukti exit code.
8903
+ 5. \`npx jioogen task complete <ref>\` (ditolak bila belum ada bukti exit 0), lalu buat satu commit git kecil.
8809
8904
  6. \`npx jioogen sync\`, lalu kembali ke langkah 1.
8810
8905
 
8811
8906
  ## 3. Batas scope
@@ -8824,6 +8919,7 @@ var JIOOGEN_AGENTS_MD = `${MARKER}
8824
8919
  - Pakai test runner yang dideklarasikan di \`specs/\` atau dibuat task scaffold.
8825
8920
  - Dilarang \`--passWithNoTests\` atau flag yang membuat command exit 0 tanpa test nyata.
8826
8921
  - Kalau test belum ada, task belum selesai.
8922
+ - Bukti verifikasi dicatat CLI lewat \`npx jioogen task verify <ref>\`; \`task complete\` menolak tanpa bukti exit 0.
8827
8923
 
8828
8924
  ## 5. Checkpoint
8829
8925
  Berhenti dan minta konfirmasi user bila task berikutnya berpindah layer, nomor
@@ -8871,8 +8967,8 @@ atas ide, refactor, perbaikan, atau fitur lain.
8871
8967
  1. \`npx jioogen task next\` \u2014 baca TASK AKTIF + isi file task.
8872
8968
  2. \`npx jioogen task start <ref>\`.
8873
8969
  3. Implementasikan **hanya** task itu sampai semua Acceptance Criteria terpenuhi.
8874
- 4. Jalankan \`verificationCommand\` task itu sampai **exit 0**.
8875
- 5. \`npx jioogen task complete <ref>\`, lalu buat **satu commit git kecil** untuk
8970
+ 4. Jalankan \`npx jioogen task verify <ref>\` sampai exit 0; CLI mencatat buktinya.
8971
+ 5. \`npx jioogen task complete <ref>\` (wajib bukti), lalu buat **satu commit git kecil** untuk
8876
8972
  task itu (lewati bila folder bukan repo git).
8877
8973
  6. \`npx jioogen sync\`, lalu kembali ke langkah 1.
8878
8974
 
@@ -8901,6 +8997,7 @@ atas ide, refactor, perbaikan, atau fitur lain.
8901
8997
  - **Dilarang** \`--passWithNoTests\` atau flag sejenis yang membuat command exit 0
8902
8998
  tanpa menjalankan test nyata.
8903
8999
  - Kalau test belum ada, task belum selesai.
9000
+ - Bukti verifikasi dicatat CLI lewat \`npx jioogen task verify <ref>\`; \`task complete\` menolak tanpa bukti exit 0.
8904
9001
  - Task \`layer: verification\` menjalankan semua \`verificationCommand\`, smoke test
8905
9002
  route/navigasi, cek UI states + responsive, dan verifikasi AC.
8906
9003
 
@@ -9502,6 +9599,37 @@ async function checkSidecar(bundleDir) {
9502
9599
  );
9503
9600
  }
9504
9601
  }
9602
+ async function checkRecovery(bundleDir) {
9603
+ const path = join5(bundleDir, "tasks/.execution/recovery.json");
9604
+ let raw;
9605
+ try {
9606
+ raw = await readFile5(path, "utf8");
9607
+ } catch (error) {
9608
+ if (isMissingFile4(error)) {
9609
+ return makeCheck("recovery", "pass", "Belum ada recovery journal.");
9610
+ }
9611
+ return makeCheck("recovery", "warn", "Recovery journal tidak bisa dibaca.");
9612
+ }
9613
+ let payload;
9614
+ try {
9615
+ payload = JSON.parse(raw);
9616
+ } catch {
9617
+ return makeCheck("recovery", "warn", "Recovery journal bukan JSON valid.");
9618
+ }
9619
+ const tasks = typeof payload === "object" && payload !== null ? payload.tasks : void 0;
9620
+ if (tasks === void 0 || typeof tasks !== "object" || tasks === null) {
9621
+ return makeCheck("recovery", "warn", "Recovery journal tidak memuat tasks.");
9622
+ }
9623
+ const exhausted = Object.entries(tasks).filter(([, entry]) => entry?.exhausted === true).map(([ref]) => ref);
9624
+ if (exhausted.length > 0) {
9625
+ return makeCheck(
9626
+ "recovery",
9627
+ "warn",
9628
+ `Task RECOVERY_EXHAUSTED: ${exhausted.join(", ")}. Jalankan \`jioogen resume\`.`
9629
+ );
9630
+ }
9631
+ return makeCheck("recovery", "pass", "Recovery journal valid; tidak ada task exhausted.");
9632
+ }
9505
9633
  async function checkLock(bundleDir) {
9506
9634
  const target = lockPath(bundleDir);
9507
9635
  let info;
@@ -9720,6 +9848,7 @@ async function runChecks(options, deps) {
9720
9848
  checks.push(await checkBundle(options.bundleDir));
9721
9849
  checks.push(await checkSidecar(options.bundleDir));
9722
9850
  checks.push(await checkLock(options.bundleDir));
9851
+ checks.push(await checkRecovery(options.bundleDir));
9723
9852
  checks.push(await checkAgents(options.bundleDir));
9724
9853
  checks.push(await checkExecutionSkill(options.bundleDir));
9725
9854
  checks.push(await checkSkillPacks(options.bundleDir));
@@ -9772,13 +9901,144 @@ function formatTable(headers, rows) {
9772
9901
  return [render(headers), divider, ...rows.map(render)].join("\n");
9773
9902
  }
9774
9903
 
9904
+ // src/recovery.ts
9905
+ import { randomUUID as randomUUID2 } from "node:crypto";
9906
+ import { mkdir as mkdir4, readFile as readFile6, rename as rename2, rm as rm5, writeFile as writeFile4 } from "node:fs/promises";
9907
+ import { dirname as dirname4, join as join6 } from "node:path";
9908
+ var RECOVERY_PATH = "tasks/.execution/recovery.json";
9909
+ var RECOVERY_BUDGET = { maxAttempts: 3 };
9910
+ function recoveryPath(bundleDir) {
9911
+ return join6(bundleDir, RECOVERY_PATH);
9912
+ }
9913
+ function emptyJournal() {
9914
+ return { schemaVersion: 1, tasks: {} };
9915
+ }
9916
+ function isJournal(value) {
9917
+ if (typeof value !== "object" || value === null) return false;
9918
+ const obj = value;
9919
+ if (obj.schemaVersion !== 1) return false;
9920
+ if (typeof obj.tasks !== "object" || obj.tasks === null) return false;
9921
+ return true;
9922
+ }
9923
+ async function readRecovery(bundleDir) {
9924
+ let raw;
9925
+ try {
9926
+ raw = await readFile6(recoveryPath(bundleDir), "utf8");
9927
+ } catch {
9928
+ return emptyJournal();
9929
+ }
9930
+ let payload;
9931
+ try {
9932
+ payload = JSON.parse(raw);
9933
+ } catch {
9934
+ return emptyJournal();
9935
+ }
9936
+ if (!isJournal(payload)) return emptyJournal();
9937
+ return payload;
9938
+ }
9939
+ function classifyFailure(input) {
9940
+ if (input.stalled === true || input.timedOut === true) return "transient";
9941
+ if (input.verificationFailed === true) return "semantic";
9942
+ const note = input.note ?? "";
9943
+ if (/^AUTHORIZATION:/i.test(note.trim())) return "authorization";
9944
+ if (/timeout|stall|econn|rate limit|\b429\b|\b5\d\d\b/i.test(note)) return "transient";
9945
+ const prior = input.prior ?? null;
9946
+ if (prior !== null && prior.attempts >= 1 && note === prior.lastNote) return "no_progress";
9947
+ return "semantic";
9948
+ }
9949
+ async function writeRecovery(bundleDir, journal) {
9950
+ const target = recoveryPath(bundleDir);
9951
+ await mkdir4(dirname4(target), { recursive: true });
9952
+ const temp = `${target}.${process.pid}.${randomUUID2()}.tmp`;
9953
+ try {
9954
+ await writeFile4(temp, `${JSON.stringify(journal, null, 2)}
9955
+ `, "utf8");
9956
+ await rename2(temp, target);
9957
+ } catch (error) {
9958
+ await rm5(temp, { force: true }).catch(() => {
9959
+ });
9960
+ throw error;
9961
+ }
9962
+ }
9963
+ async function recordFailure(bundleDir, ref, args) {
9964
+ return withStateLock(bundleDir, async () => {
9965
+ const journal = await readRecovery(bundleDir);
9966
+ const prior = journal.tasks[ref] ?? null;
9967
+ const klass = classifyFailure({ ...args, prior });
9968
+ const attempt = (prior?.attempts ?? 0) + 1;
9969
+ const exhausted = attempt >= RECOVERY_BUDGET.maxAttempts;
9970
+ const resumable = exhausted;
9971
+ const now = (/* @__PURE__ */ new Date()).toISOString();
9972
+ const note = args.note ?? "";
9973
+ const history = [...prior?.history ?? []];
9974
+ history.push({ attempt, class: klass, note, at: now });
9975
+ const capped = history.length > 20 ? history.slice(history.length - 20) : history;
9976
+ const entry = {
9977
+ ref,
9978
+ attempts: attempt,
9979
+ exhausted,
9980
+ resumable,
9981
+ lastClass: klass,
9982
+ lastNote: note === "" ? prior?.lastNote ?? "" : note,
9983
+ history: capped,
9984
+ updatedAt: now
9985
+ };
9986
+ journal.tasks[ref] = entry;
9987
+ await writeRecovery(bundleDir, journal);
9988
+ return { entry, exhausted, class: klass, attempt };
9989
+ });
9990
+ }
9991
+ async function recordSuccess(bundleDir, ref) {
9992
+ await withStateLock(bundleDir, async () => {
9993
+ const journal = await readRecovery(bundleDir);
9994
+ if (journal.tasks[ref] !== void 0) {
9995
+ delete journal.tasks[ref];
9996
+ await writeRecovery(bundleDir, journal);
9997
+ }
9998
+ });
9999
+ }
10000
+ async function rearmTask(bundleDir, ref) {
10001
+ await withStateLock(bundleDir, async () => {
10002
+ const journal = await readRecovery(bundleDir);
10003
+ const prior = journal.tasks[ref];
10004
+ const now = (/* @__PURE__ */ new Date()).toISOString();
10005
+ const entry = {
10006
+ ref,
10007
+ attempts: 0,
10008
+ exhausted: false,
10009
+ resumable: true,
10010
+ lastClass: prior?.lastClass ?? null,
10011
+ lastNote: prior?.lastNote ?? "",
10012
+ history: prior?.history ?? [],
10013
+ updatedAt: now
10014
+ };
10015
+ journal.tasks[ref] = entry;
10016
+ await writeRecovery(bundleDir, journal);
10017
+ });
10018
+ }
10019
+ function isExhausted(journal, ref) {
10020
+ return journal.tasks[ref]?.exhausted === true;
10021
+ }
10022
+ function describeRecovery(entry) {
10023
+ if (entry === void 0) {
10024
+ return "No recovery record. Run `jioogen resume`, then retry with a different approach.";
10025
+ }
10026
+ const lines = [];
10027
+ lines.push(
10028
+ `Task ${entry.ref}: ${entry.attempts}/${RECOVERY_BUDGET.maxAttempts} attempts, last=${entry.lastClass ?? "none"}.`
10029
+ );
10030
+ if (entry.lastNote.length > 0) lines.push(`Last note: ${entry.lastNote}`);
10031
+ lines.push("Run `jioogen resume`, then retry with a different approach.");
10032
+ return lines.join("\n");
10033
+ }
10034
+
9775
10035
  // src/session.ts
9776
- import { rm as rm5, stat as stat4 } from "node:fs/promises";
10036
+ import { rm as rm6, stat as stat4 } from "node:fs/promises";
9777
10037
  import { resolve as resolve3 } from "node:path";
9778
10038
 
9779
10039
  // src/tasks.ts
9780
- import { readdir as readdir4, readFile as readFile6 } from "node:fs/promises";
9781
- import { join as join6 } from "node:path";
10040
+ import { readdir as readdir4, readFile as readFile7 } from "node:fs/promises";
10041
+ import { join as join7 } from "node:path";
9782
10042
  var TASK_ID_RE2 = /\b(?:TASK|T)-\d{3,}\b/i;
9783
10043
  var HEADING_RE = /^#{1,4}\s+(.+)$/m;
9784
10044
  var LAYER_RANK = {
@@ -9828,7 +10088,7 @@ var LAYER_CHECKLISTS = {
9828
10088
  ]
9829
10089
  };
9830
10090
  async function loadTasks(bundleDir) {
9831
- const tasksDir = join6(bundleDir, "tasks");
10091
+ const tasksDir = join7(bundleDir, "tasks");
9832
10092
  let entries;
9833
10093
  try {
9834
10094
  entries = await readdir4(tasksDir, { withFileTypes: true });
@@ -9842,14 +10102,14 @@ async function loadTasks(bundleDir) {
9842
10102
  const tasks = [];
9843
10103
  if (names.length > 0) {
9844
10104
  for (const name of names) {
9845
- const content = await readFile6(join6(tasksDir, name), "utf8");
10105
+ const content = await readFile7(join7(tasksDir, name), "utf8");
9846
10106
  tasks.push(parseSingleTask(name, content));
9847
10107
  }
9848
10108
  } else {
9849
- const singlePath = join6(tasksDir, "TASKS.md");
10109
+ const singlePath = join7(tasksDir, "TASKS.md");
9850
10110
  let content;
9851
10111
  try {
9852
- content = await readFile6(singlePath, "utf8");
10112
+ content = await readFile7(singlePath, "utf8");
9853
10113
  } catch (error) {
9854
10114
  if (isMissingFile5(error)) throw new Error(`Tidak ada berkas task di ${tasksDir}`);
9855
10115
  throw error;
@@ -10022,16 +10282,16 @@ function isBoundary(previous, next) {
10022
10282
  return previous.phase !== void 0 && next.phase !== previous.phase;
10023
10283
  }
10024
10284
  var RISKY_TASK_RE = /\b(migrat(?:e|ion|ions)?|migrasi|prisma|schema|rls|auth|permission|payment|checkout|webhook|secret|deploy|drop)\b/i;
10025
- var TARGET_FILES_LABEL_RE = /^\s*(?:[-*]\s*)?\*{0,2}targetFiles\*{0,2}\s*:\s*(.*)$/i;
10285
+ var TARGET_FILES_LABEL_RE2 = /^\s*(?:[-*]\s*)?\*{0,2}targetFiles\*{0,2}\s*:\s*(.*)$/i;
10026
10286
  function isRiskyTask(task) {
10027
10287
  const targetFiles = task.targetFiles ?? targetFilesFromContent(task.content);
10028
10288
  return RISKY_TASK_RE.test([task.id, task.title, ...targetFiles].join("\n"));
10029
10289
  }
10030
10290
  function targetFilesFromContent(content) {
10031
10291
  const lines = content.split(/\r?\n/);
10032
- const index = lines.findIndex((line) => TARGET_FILES_LABEL_RE.test(line));
10292
+ const index = lines.findIndex((line) => TARGET_FILES_LABEL_RE2.test(line));
10033
10293
  if (index === -1) return [];
10034
- const inline = (lines[index]?.match(TARGET_FILES_LABEL_RE)?.[1] ?? "").trim();
10294
+ const inline = (lines[index]?.match(TARGET_FILES_LABEL_RE2)?.[1] ?? "").trim();
10035
10295
  if (inline.length > 0) return splitTargetFiles(inline);
10036
10296
  const items = [];
10037
10297
  for (let cursor = index + 1; cursor < lines.length; cursor += 1) {
@@ -10050,6 +10310,36 @@ function splitTargetFiles(value) {
10050
10310
  function cleanTargetFile(value) {
10051
10311
  return value.replace(/^[-*\s]+/, "").trim();
10052
10312
  }
10313
+ function verificationCommandFromContent(content) {
10314
+ const inline = content.match(
10315
+ /^\s*(?:[-*]\s*)?\*{0,2}verificationCommand\*{0,2}\s*:\s*(.+?)\s*$/im
10316
+ );
10317
+ if (inline?.[1] !== void 0) {
10318
+ const value = stripVerificationBackticks(inline[1].trim());
10319
+ if (isVerificationPlaceholder(value)) return null;
10320
+ if (value.length > 0) return value;
10321
+ }
10322
+ const lines = content.split(/\r?\n/);
10323
+ for (let i = 0; i < lines.length; i += 1) {
10324
+ const heading = lines[i]?.trim() ?? "";
10325
+ if (!/^#{1,6}\s+Verification(?:\s+Command)?\s*$/i.test(heading)) continue;
10326
+ for (let j = i + 1; j < lines.length; j += 1) {
10327
+ const next = (lines[j] ?? "").trim();
10328
+ if (next.length === 0) continue;
10329
+ if (/^#{1,6}\s/.test(next)) break;
10330
+ const value = stripVerificationBackticks(next);
10331
+ if (isVerificationPlaceholder(value)) return null;
10332
+ return value.length > 0 ? value : null;
10333
+ }
10334
+ }
10335
+ return null;
10336
+ }
10337
+ function stripVerificationBackticks(value) {
10338
+ return value.replace(/^`+/, "").replace(/`+$/, "").trim();
10339
+ }
10340
+ function isVerificationPlaceholder(value) {
10341
+ return /^(?:n\/a|—+|-+|none)$/i.test(value.trim());
10342
+ }
10053
10343
  function isMissingFile5(error) {
10054
10344
  return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
10055
10345
  }
@@ -10071,22 +10361,38 @@ async function resumeSession(options) {
10071
10361
  awaitingCheckpoint: false
10072
10362
  };
10073
10363
  }
10074
- return withStateLock(context.bundleDir, async () => {
10364
+ const definitions = await loadTasks(context.bundleDir);
10365
+ const written = await withStateLock(context.bundleDir, async () => {
10075
10366
  const state = await readState(context.bundleDir) ?? initial;
10076
- const definitions = await loadTasks(context.bundleDir);
10077
10367
  const merged = mergeTasks(state, definitions);
10078
- const written = await writeState(context.bundleDir, merged);
10079
- const current = written.current ?? null;
10080
- const next = selectNext(definitions, written.tasks);
10081
- return {
10082
- projectId: written.projectId ?? context.projectId ?? "",
10083
- bundleDir: context.bundleDir,
10084
- hasState: true,
10085
- current,
10086
- nextRef: next?.task.id ?? null,
10087
- awaitingCheckpoint: current?.awaitingCheckpoint === true
10088
- };
10368
+ return writeState(context.bundleDir, merged);
10089
10369
  });
10370
+ const journal = await readRecovery(context.bundleDir);
10371
+ const exhausted = written.tasks.filter(
10372
+ (task) => isExhausted(journal, task.ref.toUpperCase()) || isExhausted(journal, task.ref)
10373
+ );
10374
+ if (exhausted.length > 0) {
10375
+ await withStateLock(context.bundleDir, async () => {
10376
+ const state = await readState(context.bundleDir) ?? written;
10377
+ let next2 = state;
10378
+ for (const task of exhausted) {
10379
+ next2 = withStatus(next2, task.ref, "todo", { awaitingCheckpoint: false });
10380
+ }
10381
+ await writeState(context.bundleDir, next2);
10382
+ });
10383
+ for (const task of exhausted) await rearmTask(context.bundleDir, task.ref.toUpperCase());
10384
+ }
10385
+ const finalState = await readState(context.bundleDir) ?? written;
10386
+ const current = finalState.current ?? null;
10387
+ const next = selectNext(definitions, finalState.tasks);
10388
+ return {
10389
+ projectId: finalState.projectId ?? context.projectId ?? "",
10390
+ bundleDir: context.bundleDir,
10391
+ hasState: true,
10392
+ current,
10393
+ nextRef: next?.task.id ?? null,
10394
+ awaitingCheckpoint: current?.awaitingCheckpoint === true
10395
+ };
10090
10396
  }
10091
10397
  async function reviewSession(options, review) {
10092
10398
  const context = await resolveBundleContext(options);
@@ -10122,7 +10428,10 @@ async function reviewSession(options, review) {
10122
10428
  );
10123
10429
  }
10124
10430
  const note = `${CHANGE_REQUEST_PREFIX} ${review.note ?? ""}`.trim();
10125
- const reopened = withStatus(state, target.ref, "in_progress", { note, awaitingCheckpoint: false });
10431
+ const reopened = withStatus(state, target.ref, "in_progress", {
10432
+ note,
10433
+ awaitingCheckpoint: false
10434
+ });
10126
10435
  const reopenedTarget = findTask(reopened, target.ref);
10127
10436
  const nextCurrent = {
10128
10437
  ref: reopenedTarget?.ref ?? target.ref,
@@ -10191,7 +10500,7 @@ async function removeStaleLock2(bundleDir) {
10191
10500
  throw error;
10192
10501
  }
10193
10502
  if (Date.now() - info.mtimeMs <= LOCK_STALE_MS3) return;
10194
- await rm5(target, { force: true });
10503
+ await rm6(target, { force: true });
10195
10504
  }
10196
10505
  function envFirst(primary, legacy) {
10197
10506
  const value = process.env[primary]?.trim();
@@ -10205,8 +10514,8 @@ function isMissingFile6(error) {
10205
10514
 
10206
10515
  // src/zip.ts
10207
10516
  var import_adm_zip = __toESM(require_adm_zip(), 1);
10208
- import { mkdir as mkdir4, writeFile as writeFile4 } from "node:fs/promises";
10209
- import { dirname as dirname4, resolve as resolve4, sep } from "node:path";
10517
+ import { mkdir as mkdir5, writeFile as writeFile5 } from "node:fs/promises";
10518
+ import { dirname as dirname5, resolve as resolve4, sep } from "node:path";
10210
10519
  async function extractBundle(bytes, targetDir) {
10211
10520
  const root = resolve4(targetDir);
10212
10521
  const zip = new import_adm_zip.default(Buffer.from(bytes));
@@ -10222,8 +10531,8 @@ async function extractBundle(bytes, targetDir) {
10222
10531
  if (!destination.startsWith(`${root}${sep}`)) {
10223
10532
  throw new Error(`Path bundle keluar dari direktori target: ${entry.entryName}`);
10224
10533
  }
10225
- await mkdir4(dirname4(destination), { recursive: true });
10226
- await writeFile4(destination, entry.getData());
10534
+ await mkdir5(dirname5(destination), { recursive: true });
10535
+ await writeFile5(destination, entry.getData());
10227
10536
  written.push(relative2);
10228
10537
  }
10229
10538
  return written;
@@ -10343,7 +10652,7 @@ async function linkCommand(projectId, options) {
10343
10652
  await verifyProjectAccess(client, projectId);
10344
10653
  await writeProjectLink(target, { projectId, apiUrl });
10345
10654
  const skills = await installAgentSkills(target, { noSkills: skillsDisabled(options) });
10346
- const linkedFile = join7(target, ".jioogen", "project.json");
10655
+ const linkedFile = join8(target, ".jioogen", "project.json");
10347
10656
  if (options.json === true) {
10348
10657
  console.log(JSON.stringify({ projectId, target, apiUrl, linkedFile, skills }, null, 2));
10349
10658
  return;
@@ -10478,7 +10787,7 @@ async function doctorCommand(options) {
10478
10787
  const warns = report.checks.filter((check) => check.status === "warn").length;
10479
10788
  console.log(
10480
10789
  `
10481
- ${report.ok ? "Doctor OK" : "Doctor GAGAL"} (${fails} fail, ${warns} warn).` + (options.fix === true ? "" : " Jalankan `jioogen doctor --fix` untuk perbaikan wiring.")
10790
+ ${report.ok ? "Doctor OK" : "Doctor GAGAL"} (${fails} fail, ${warns} warn).` + (report.ok || options.fix === true ? "" : " Jalankan `jioogen doctor --fix` untuk perbaikan wiring.")
10482
10791
  );
10483
10792
  }
10484
10793
  if (!report.ok) process.exitCode = 1;
@@ -10588,6 +10897,21 @@ async function taskNextCommand(options) {
10588
10897
  return;
10589
10898
  }
10590
10899
  const awaitingCheckpoint = written.current?.awaitingCheckpoint === true;
10900
+ const journal = await readRecovery(bundleDir);
10901
+ if (isExhausted(journal, next.task.id)) {
10902
+ const entry = journal.tasks[next.task.id];
10903
+ const diagnosis = describeRecovery(entry);
10904
+ if (options.json === true) {
10905
+ console.log(
10906
+ JSON.stringify({ done: false, projectId, recoveryExhausted: true, diagnosis }, null, 2)
10907
+ );
10908
+ return;
10909
+ }
10910
+ console.log("## RECOVERY_EXHAUSTED \u2014 task ini butuh keputusan");
10911
+ console.log(diagnosis);
10912
+ console.log("\nLanjutkan dengan `npx jioogen resume`, lalu ulangi dengan pendekatan berbeda.");
10913
+ return;
10914
+ }
10591
10915
  const manifest = await readHarnessManifest(bundleDir);
10592
10916
  const context = manifest === null ? void 0 : {
10593
10917
  productKind: manifest.productKind,
@@ -10625,7 +10949,14 @@ Status: ${next.state.status} \u2014 silakan ulangi.`);
10625
10949
  Progress: ${written.counts?.done ?? 0}/${definitions.length} task selesai.`);
10626
10950
  }
10627
10951
  async function taskStartCommand(ref, options) {
10952
+ const key = ref.trim().toUpperCase();
10628
10953
  const task = await withLocalState(options, async (local) => {
10954
+ const journal = await readRecovery(local.bundleDir);
10955
+ if (isExhausted(journal, key) || isExhausted(journal, ref)) {
10956
+ throw new Error(
10957
+ `Task ${ref} berstatus RECOVERY_EXHAUSTED. Jalankan \`jioogen resume\` lalu ulangi dengan pendekatan berbeda.`
10958
+ );
10959
+ }
10629
10960
  assertStartDependencies(ref, local.definitions, local.state.tasks);
10630
10961
  const updated = withStatus(local.state, ref, "in_progress", {
10631
10962
  awaitingCheckpoint: false,
@@ -10637,35 +10968,65 @@ async function taskStartCommand(ref, options) {
10637
10968
  console.log(`Started ${task?.ref ?? ref} (attempt ${task?.attempt ?? 1}).`);
10638
10969
  }
10639
10970
  async function taskCompleteCommand(ref, options) {
10640
- const { completedTask, next, checkpoint } = await withLocalState(options, async (local) => {
10641
- assertCompleteDependencies(ref, local.definitions, local.state.tasks, options.force === true);
10642
- const completed = withStatus(local.state, ref, "done", {
10643
- note: options.note ?? "",
10644
- awaitingCheckpoint: false
10645
- });
10646
- const completedTask2 = completed.tasks.find(
10647
- (entry) => entry.ref.toUpperCase() === ref.toUpperCase()
10648
- );
10649
- const next2 = selectNext(local.definitions, completed.tasks);
10650
- const definition = local.definitions.find(
10651
- (entry) => entry.id.toUpperCase() === ref.toUpperCase()
10652
- );
10653
- const risky = definition !== void 0 && isRiskyTask(definition);
10654
- const boundary = completedTask2 !== void 0 && (next2 !== null && isBoundary(completedTask2, next2.task) || risky);
10655
- if (boundary && completedTask2 !== void 0) {
10656
- const target = next2?.task;
10657
- const withCheckpoint = setCurrent(completed, {
10658
- ref: target?.id ?? completedTask2.ref,
10659
- layer: target?.layer ?? completedTask2.layer,
10660
- phase: target?.phase ?? completedTask2.phase ?? 1,
10661
- awaitingCheckpoint: true
10971
+ const { completedTask, next, checkpoint, bundleDir } = await withLocalState(
10972
+ options,
10973
+ async (local) => {
10974
+ assertCompleteDependencies(ref, local.definitions, local.state.tasks, options.force === true);
10975
+ const definition = local.definitions.find(
10976
+ (entry) => entry.id.toUpperCase() === ref.trim().toUpperCase()
10977
+ );
10978
+ const verificationCommand = definition === void 0 ? null : verificationCommandFromContent(definition.content);
10979
+ const stateTask = local.state.tasks.find(
10980
+ (entry) => entry.ref.toUpperCase() === ref.trim().toUpperCase()
10981
+ );
10982
+ if (options.force !== true) {
10983
+ if (verificationCommand === null) {
10984
+ throw new Error(
10985
+ `Task ${ref} tidak punya verificationCommand. Gunakan --force untuk jalur legacy.`
10986
+ );
10987
+ }
10988
+ const proof = stateTask?.verification;
10989
+ if (proof === void 0 || proof.exitCode !== 0 || proof.command !== verificationCommand) {
10990
+ throw new Error(
10991
+ `Task ${ref} belum diverifikasi. Jalankan \`jioogen task verify ${ref}\`.`
10992
+ );
10993
+ }
10994
+ } else {
10995
+ if (verificationCommand !== null) {
10996
+ const proof = stateTask?.verification;
10997
+ if (proof === void 0 || proof.exitCode !== 0 || proof.command !== verificationCommand) {
10998
+ console.warn(`Warning: bypass verification requirement for ${ref}.`);
10999
+ }
11000
+ } else {
11001
+ console.warn(`Warning: task ${ref} has no verificationCommand (legacy bypass).`);
11002
+ }
11003
+ }
11004
+ const completed = withStatus(local.state, ref, "done", {
11005
+ note: options.note ?? "",
11006
+ awaitingCheckpoint: false
10662
11007
  });
10663
- await writeState(local.bundleDir, withCheckpoint);
10664
- return { completedTask: completedTask2, next: next2, checkpoint: true };
11008
+ const completedTask2 = completed.tasks.find(
11009
+ (entry) => entry.ref.toUpperCase() === ref.toUpperCase()
11010
+ );
11011
+ const next2 = selectNext(local.definitions, completed.tasks);
11012
+ const risky = definition !== void 0 && isRiskyTask(definition);
11013
+ const boundary = completedTask2 !== void 0 && (next2 !== null && isBoundary(completedTask2, next2.task) || risky);
11014
+ if (boundary && completedTask2 !== void 0) {
11015
+ const target = next2?.task;
11016
+ const withCheckpoint = setCurrent(completed, {
11017
+ ref: target?.id ?? completedTask2.ref,
11018
+ layer: target?.layer ?? completedTask2.layer,
11019
+ phase: target?.phase ?? completedTask2.phase ?? 1,
11020
+ awaitingCheckpoint: true
11021
+ });
11022
+ await writeState(local.bundleDir, withCheckpoint);
11023
+ return { completedTask: completedTask2, next: next2, checkpoint: true, bundleDir: local.bundleDir };
11024
+ }
11025
+ await writeState(local.bundleDir, completed);
11026
+ return { completedTask: completedTask2, next: next2, checkpoint: false, bundleDir: local.bundleDir };
10665
11027
  }
10666
- await writeState(local.bundleDir, completed);
10667
- return { completedTask: completedTask2, next: next2, checkpoint: false };
10668
- });
11028
+ );
11029
+ await recordSuccess(bundleDir, ref.trim().toUpperCase());
10669
11030
  console.log(`Done ${completedTask?.ref ?? ref}.`);
10670
11031
  if (checkpoint) {
10671
11032
  if (next === null) {
@@ -10682,16 +11043,150 @@ async function taskCompleteCommand(ref, options) {
10682
11043
  }
10683
11044
  if (next !== null) console.log(`Berikutnya: ${next.task.id} \u2014 ${next.task.title}`);
10684
11045
  }
11046
+ async function taskVerifyCommand(ref, options) {
11047
+ const context = await resolveLocalBundle(options);
11048
+ const definitions = await loadTasks(context.bundleDir);
11049
+ const definition = definitions.find((task) => task.id.toUpperCase() === ref.trim().toUpperCase());
11050
+ if (definition === void 0) {
11051
+ throw new Error(`Task ${ref} tidak ditemukan.`);
11052
+ }
11053
+ const command = verificationCommandFromContent(definition.content);
11054
+ if (command === null) {
11055
+ throw new Error(
11056
+ `Task ${ref} tidak punya verificationCommand. Jalankan \`jioogen task verify\` tidak dapat dilanjutkan.`
11057
+ );
11058
+ }
11059
+ const timeoutMs = verifyTimeoutMs();
11060
+ const startedAt = Date.now();
11061
+ const result = await runVerification(command, context.bundleDir, timeoutMs);
11062
+ const durationMs = Date.now() - startedAt;
11063
+ const at = (/* @__PURE__ */ new Date()).toISOString();
11064
+ await withStateLock(context.bundleDir, async () => {
11065
+ const existing = await readState(context.bundleDir);
11066
+ const state = existing === null ? createState(context.projectId, definitions) : mergeTasks(existing, definitions);
11067
+ const index = state.tasks.findIndex(
11068
+ (task) => task.ref.toUpperCase() === ref.trim().toUpperCase()
11069
+ );
11070
+ if (index === -1) {
11071
+ throw new Error(`Task ${ref} tidak ada di sidecar.`);
11072
+ }
11073
+ const updatedTask = {
11074
+ ...state.tasks[index],
11075
+ verification: { command, exitCode: result.exitCode, at, durationMs }
11076
+ };
11077
+ const tasks = state.tasks.map(
11078
+ (task, i) => i === index ? updatedTask : task
11079
+ );
11080
+ await writeState(context.bundleDir, { ...state, tasks });
11081
+ });
11082
+ const payload = {
11083
+ ref: definition.id,
11084
+ command,
11085
+ exitCode: result.exitCode,
11086
+ durationMs,
11087
+ at,
11088
+ timedOut: result.timedOut,
11089
+ stdout: result.stdout,
11090
+ stderr: result.stderr
11091
+ };
11092
+ if (options.json === true) {
11093
+ console.log(JSON.stringify(payload, null, 2));
11094
+ } else {
11095
+ console.log(`Verify ${definition.id}: exit ${result.exitCode} (${durationMs}ms)`);
11096
+ if (result.stdout.trim().length > 0) {
11097
+ console.log(result.stdout.trimEnd());
11098
+ }
11099
+ if (result.stderr.trim().length > 0) {
11100
+ console.error(result.stderr.trimEnd());
11101
+ }
11102
+ }
11103
+ if (result.exitCode !== 0) {
11104
+ throw new Error(`Verification gagal (exit ${result.exitCode}).`);
11105
+ }
11106
+ }
11107
+ function verifyTimeoutMs() {
11108
+ const raw = process.env.JIOOGEN_VERIFY_TIMEOUT_MS;
11109
+ if (raw === void 0 || raw.trim().length === 0) return 9e5;
11110
+ const value = Number(raw);
11111
+ if (!Number.isFinite(value) || value < 0) return 9e5;
11112
+ return value;
11113
+ }
11114
+ function runVerification(command, cwd, timeoutMs) {
11115
+ return new Promise((resolve6) => {
11116
+ const child = spawn("sh", ["-c", command], { cwd, stdio: ["ignore", "pipe", "pipe"] });
11117
+ let stdout = "";
11118
+ let stderr = "";
11119
+ let timedOut = false;
11120
+ let settled = false;
11121
+ let timer;
11122
+ const finish = (exitCode) => {
11123
+ if (settled) return;
11124
+ settled = true;
11125
+ if (timer !== void 0) clearTimeout(timer);
11126
+ resolve6({
11127
+ exitCode,
11128
+ stdout: tailText(stdout),
11129
+ stderr: tailText(stderr),
11130
+ timedOut
11131
+ });
11132
+ };
11133
+ child.stdout.on("data", (chunk) => {
11134
+ stdout += chunk.toString();
11135
+ });
11136
+ child.stderr.on("data", (chunk) => {
11137
+ stderr += chunk.toString();
11138
+ });
11139
+ child.on("error", () => finish(1));
11140
+ child.on("close", (code, signal) => {
11141
+ if (timedOut) {
11142
+ finish(124);
11143
+ return;
11144
+ }
11145
+ finish(code ?? (signal !== null ? 1 : 0));
11146
+ });
11147
+ if (timeoutMs > 0) {
11148
+ timer = setTimeout(() => {
11149
+ timedOut = true;
11150
+ try {
11151
+ child.kill("SIGKILL");
11152
+ } catch {
11153
+ }
11154
+ }, timeoutMs);
11155
+ }
11156
+ });
11157
+ }
11158
+ function tailText(value) {
11159
+ return value.length <= 2e3 ? value : value.slice(-2e3);
11160
+ }
10685
11161
  async function taskFailCommand(ref, reasonParts, options) {
10686
11162
  const reason = reasonParts.join(" ").trim() || options.note || "";
10687
- await withLocalState(options, async (local) => {
11163
+ const key = ref.trim().toUpperCase();
11164
+ const bundleDir = await withLocalState(options, async (local) => {
10688
11165
  const updated = withStatus(local.state, ref, "failed", {
10689
11166
  note: reason,
10690
11167
  awaitingCheckpoint: false
10691
11168
  });
10692
11169
  await writeState(local.bundleDir, updated);
11170
+ return local.bundleDir;
10693
11171
  });
11172
+ const recovery = await recordFailure(bundleDir, key, { note: reason });
11173
+ if (recovery.exhausted) {
11174
+ await withLocalState(options, async (local) => {
11175
+ const blocked = withStatus(local.state, ref, "blocked", {
11176
+ note: `RECOVERY_EXHAUSTED: ${describeRecovery(recovery.entry)}`,
11177
+ awaitingCheckpoint: false
11178
+ });
11179
+ await writeState(local.bundleDir, blocked);
11180
+ });
11181
+ }
10694
11182
  console.log(`Failed ${ref}${reason.length > 0 ? `: ${reason}` : "."}`);
11183
+ console.log(
11184
+ `Recovery: attempt ${recovery.attempt}/${RECOVERY_BUDGET.maxAttempts}, kelas ${recovery.class}.`
11185
+ );
11186
+ if (recovery.exhausted) {
11187
+ console.log("Status: RECOVERY_EXHAUSTED (blocked). State tersimpan dan bisa dilanjutkan.");
11188
+ console.log(describeRecovery(recovery.entry));
11189
+ }
10695
11190
  }
10696
11191
  async function taskResetCommand(ref, reasonParts, options) {
10697
11192
  const reason = reasonParts.join(" ").trim() || options.note || "";
@@ -10779,7 +11274,7 @@ async function syncCommand(options) {
10779
11274
  assertBundleRelative(relative2);
10780
11275
  files.push({
10781
11276
  path: relative2,
10782
- content: await readFile7(join7(bundleDir, relative2), "utf8")
11277
+ content: await readFile8(join8(bundleDir, relative2), "utf8")
10783
11278
  });
10784
11279
  }
10785
11280
  }
@@ -10913,12 +11408,12 @@ async function assertLinkTarget(target, projectId) {
10913
11408
  }
10914
11409
  async function hasBundleMarkers(target) {
10915
11410
  try {
10916
- await readFile7(join7(target, "PRD.md"));
11411
+ await readFile8(join8(target, "PRD.md"));
10917
11412
  return true;
10918
11413
  } catch (error) {
10919
11414
  if (!isMissingFile7(error)) throw error;
10920
11415
  }
10921
- return hasTaskMarkdown(join7(target, "tasks"));
11416
+ return hasTaskMarkdown(join8(target, "tasks"));
10922
11417
  }
10923
11418
  async function hasTaskMarkdown(directory) {
10924
11419
  let names;
@@ -10992,7 +11487,7 @@ function isMissingFile7(error) {
10992
11487
  }
10993
11488
 
10994
11489
  // src/index.ts
10995
- var VERSION = "0.2.5";
11490
+ var VERSION = "0.2.7";
10996
11491
  var USAGE = `jioogen \u2014 CLI JiooGen (task selection lokal, server read-only)
10997
11492
 
10998
11493
  Usage:
@@ -11016,6 +11511,7 @@ Usage:
11016
11511
  jioogen task next [--json]
11017
11512
  jioogen task start <ref>
11018
11513
  jioogen task complete <ref> [--note <text>] [--force]
11514
+ jioogen task verify <ref> [--dir <dir>] [--json]
11019
11515
  jioogen task fail <ref> [reason...] [--note <text>]
11020
11516
  jioogen task reset <ref> [reason...] [--note <text>]
11021
11517
  jioogen status [--remote] [--json]
@@ -11222,6 +11718,9 @@ async function dispatchTask(rest, options) {
11222
11718
  case "start":
11223
11719
  await taskStartCommand(requireRef(ref, "start"), options);
11224
11720
  return;
11721
+ case "verify":
11722
+ await taskVerifyCommand(requireRef(ref, "verify"), options);
11723
+ return;
11225
11724
  case "complete":
11226
11725
  await taskCompleteCommand(requireRef(ref, "complete"), options);
11227
11726
  return;