jioogen 0.2.18 → 0.2.19
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 +455 -245
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9898,11 +9898,58 @@ function summarizeExecutionCounts(tasks) {
|
|
|
9898
9898
|
}
|
|
9899
9899
|
return base;
|
|
9900
9900
|
}
|
|
9901
|
+
var SUPERSESSION_SUMMARY_PREFIX = "stale adoption superseded";
|
|
9902
|
+
function isSupersessionEvidence(entry) {
|
|
9903
|
+
return entry.type === "text" && (entry.summary ?? "").startsWith(SUPERSESSION_SUMMARY_PREFIX);
|
|
9904
|
+
}
|
|
9905
|
+
var ADOPTION_MARKER_PREFIX = "adopted outside harness";
|
|
9906
|
+
function isAdoptionMarker(entry) {
|
|
9907
|
+
return entry.type === "text" && entry.summary !== void 0 && entry.summary.startsWith(ADOPTION_MARKER_PREFIX);
|
|
9908
|
+
}
|
|
9909
|
+
function validAt(entry) {
|
|
9910
|
+
if (entry.at === void 0) return void 0;
|
|
9911
|
+
const parsed = Date.parse(entry.at);
|
|
9912
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
9913
|
+
}
|
|
9914
|
+
function adoptionMarkers(task) {
|
|
9915
|
+
return (task.evidence ?? []).filter(isAdoptionMarker);
|
|
9916
|
+
}
|
|
9917
|
+
function maxAdoptionAt(task) {
|
|
9918
|
+
const values = adoptionMarkers(task).map(validAt).filter((value) => value !== void 0);
|
|
9919
|
+
if (values.length === 0) return void 0;
|
|
9920
|
+
return Math.max(...values);
|
|
9921
|
+
}
|
|
9922
|
+
function maxSupersededAt(task) {
|
|
9923
|
+
const values = (task.evidence ?? []).filter(isSupersessionEvidence).map(validAt).filter((value) => value !== void 0);
|
|
9924
|
+
if (values.length === 0) return void 0;
|
|
9925
|
+
return Math.max(...values);
|
|
9926
|
+
}
|
|
9901
9927
|
function isAdoptedTask(task) {
|
|
9902
|
-
|
|
9903
|
-
|
|
9904
|
-
|
|
9928
|
+
const baseAdopted = task.source === "user" || (task.evidence ?? []).some(
|
|
9929
|
+
(entry) => entry.type === "text" && entry.summary !== void 0 && entry.summary.startsWith(ADOPTION_MARKER_PREFIX)
|
|
9930
|
+
);
|
|
9931
|
+
if (!baseAdopted) return false;
|
|
9932
|
+
const adoptionAt = maxAdoptionAt(task);
|
|
9933
|
+
if (adoptionAt === void 0) return true;
|
|
9934
|
+
const supersededAt = maxSupersededAt(task);
|
|
9935
|
+
if (supersededAt !== void 0 && supersededAt > adoptionAt) return false;
|
|
9936
|
+
return true;
|
|
9937
|
+
}
|
|
9938
|
+
function isStaleAdoption(task) {
|
|
9939
|
+
if (task.status !== "done") return false;
|
|
9940
|
+
if (!isAdoptedTask(task)) return false;
|
|
9941
|
+
const adoptionAt = maxAdoptionAt(task);
|
|
9942
|
+
if (adoptionAt === void 0) return false;
|
|
9943
|
+
const verificationEntries = (task.evidence ?? []).filter(
|
|
9944
|
+
(entry) => entry.type === "verification" && typeof entry.exitCode === "number"
|
|
9905
9945
|
);
|
|
9946
|
+
const withAt = verificationEntries.map((entry) => ({ entry, at: validAt(entry) })).filter((item) => item.at !== void 0);
|
|
9947
|
+
if (withAt.length === 0) return false;
|
|
9948
|
+
const maxAt = Math.max(...withAt.map((item) => item.at));
|
|
9949
|
+
if (withAt.some((item) => item.at === maxAt && item.entry.exitCode !== 0)) return false;
|
|
9950
|
+
const latest = withAt.find((item) => item.at === maxAt && item.entry.exitCode === 0);
|
|
9951
|
+
if (latest === void 0) return false;
|
|
9952
|
+
return latest.at > adoptionAt;
|
|
9906
9953
|
}
|
|
9907
9954
|
function computeCompletion(tasks, definitions) {
|
|
9908
9955
|
const defById = new Map(
|
|
@@ -11250,6 +11297,34 @@ function appendTaskEvidence(state, ref, evidence) {
|
|
|
11250
11297
|
const tasks = state.tasks.map((entry, i) => i === index ? task : entry);
|
|
11251
11298
|
return rebuild(state, tasks, state.current);
|
|
11252
11299
|
}
|
|
11300
|
+
function supersedeStaleAdoption(state, ref, now = /* @__PURE__ */ new Date()) {
|
|
11301
|
+
const index = state.tasks.findIndex((task) => task.ref.toUpperCase() === ref.toUpperCase());
|
|
11302
|
+
if (index === -1) return state;
|
|
11303
|
+
const previous = state.tasks[index];
|
|
11304
|
+
if (previous === void 0) return state;
|
|
11305
|
+
const adoptionMarkers2 = (previous.evidence ?? []).filter(
|
|
11306
|
+
(entry) => entry.type === "text" && entry.summary !== void 0 && entry.summary.startsWith("adopted outside harness")
|
|
11307
|
+
);
|
|
11308
|
+
if (adoptionMarkers2.length === 0) return state;
|
|
11309
|
+
if (!isAdoptedTask(previous)) return state;
|
|
11310
|
+
const adoptionAtValues = adoptionMarkers2.map((entry) => entry.at === void 0 ? NaN : Date.parse(entry.at)).filter((value) => !Number.isNaN(value));
|
|
11311
|
+
if (adoptionAtValues.length === 0) return state;
|
|
11312
|
+
const latestAdoptionAt = Math.max(...adoptionAtValues);
|
|
11313
|
+
const effectiveMs = Math.max(now.getTime(), latestAdoptionAt + 1);
|
|
11314
|
+
const effective = new Date(effectiveMs).toISOString();
|
|
11315
|
+
const summary = `${SUPERSESSION_SUMMARY_PREFIX}: ${adoptionMarkers2.length} marker(s), verified exit 0`;
|
|
11316
|
+
const updated = {
|
|
11317
|
+
...previous,
|
|
11318
|
+
updatedAt: effective,
|
|
11319
|
+
evidence: [...previous.evidence ?? [], { type: "text", summary, at: effective }],
|
|
11320
|
+
history: [
|
|
11321
|
+
...previous.history ?? [],
|
|
11322
|
+
{ status: previous.status, at: effective, note: SUPERSESSION_SUMMARY_PREFIX }
|
|
11323
|
+
]
|
|
11324
|
+
};
|
|
11325
|
+
const tasks = state.tasks.map((entry, i) => i === index ? updated : entry);
|
|
11326
|
+
return rebuild(state, tasks, state.current, new Date(effectiveMs));
|
|
11327
|
+
}
|
|
11253
11328
|
function setTaskSource(state, ref, source) {
|
|
11254
11329
|
const index = state.tasks.findIndex((task2) => task2.ref.toUpperCase() === ref.toUpperCase());
|
|
11255
11330
|
if (index === -1) return state;
|
|
@@ -13195,14 +13270,166 @@ function isMissingFile3(error) {
|
|
|
13195
13270
|
}
|
|
13196
13271
|
|
|
13197
13272
|
// src/doctor.ts
|
|
13198
|
-
import { readdir as readdir7, readFile as
|
|
13199
|
-
import { join as
|
|
13273
|
+
import { readdir as readdir7, readFile as readFile11, rm as rm8, stat as stat6 } from "node:fs/promises";
|
|
13274
|
+
import { join as join12 } from "node:path";
|
|
13275
|
+
|
|
13276
|
+
// src/recovery.ts
|
|
13277
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
13278
|
+
import { mkdir as mkdir7, readFile as readFile9, rename as rename2, rm as rm6, writeFile as writeFile7 } from "node:fs/promises";
|
|
13279
|
+
import { dirname as dirname6, join as join10 } from "node:path";
|
|
13280
|
+
var RECOVERY_PATH = "tasks/.execution/recovery.json";
|
|
13281
|
+
var RECOVERY_BUDGET = { maxAttempts: 3 };
|
|
13282
|
+
var RECOVERY_BASE_ATTEMPTS = 3;
|
|
13283
|
+
var RECOVERY_MAX_ATTEMPTS = 6;
|
|
13284
|
+
function recoveryBudget(input) {
|
|
13285
|
+
let budget = RECOVERY_BASE_ATTEMPTS;
|
|
13286
|
+
if (input.failureClass === "transient") budget += 1;
|
|
13287
|
+
if (input.failureClass === "semantic") budget += 1;
|
|
13288
|
+
return Math.min(budget, RECOVERY_MAX_ATTEMPTS);
|
|
13289
|
+
}
|
|
13290
|
+
function recoveryPath(bundleDir) {
|
|
13291
|
+
return join10(bundleDir, RECOVERY_PATH);
|
|
13292
|
+
}
|
|
13293
|
+
function isMissingFile4(error) {
|
|
13294
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
13295
|
+
}
|
|
13296
|
+
function emptyJournal() {
|
|
13297
|
+
return { schemaVersion: 1, tasks: {} };
|
|
13298
|
+
}
|
|
13299
|
+
function isJournal(value) {
|
|
13300
|
+
if (typeof value !== "object" || value === null) return false;
|
|
13301
|
+
const obj = value;
|
|
13302
|
+
if (obj.schemaVersion !== 1) return false;
|
|
13303
|
+
if (typeof obj.tasks !== "object" || obj.tasks === null) return false;
|
|
13304
|
+
return true;
|
|
13305
|
+
}
|
|
13306
|
+
async function readRecoveryStrict(bundleDir) {
|
|
13307
|
+
let raw;
|
|
13308
|
+
try {
|
|
13309
|
+
raw = await readFile9(recoveryPath(bundleDir), "utf8");
|
|
13310
|
+
} catch (error) {
|
|
13311
|
+
if (isMissingFile4(error)) return emptyJournal();
|
|
13312
|
+
return null;
|
|
13313
|
+
}
|
|
13314
|
+
let payload;
|
|
13315
|
+
try {
|
|
13316
|
+
payload = JSON.parse(raw);
|
|
13317
|
+
} catch {
|
|
13318
|
+
return null;
|
|
13319
|
+
}
|
|
13320
|
+
if (!isJournal(payload)) return null;
|
|
13321
|
+
return payload;
|
|
13322
|
+
}
|
|
13323
|
+
async function readRecovery(bundleDir) {
|
|
13324
|
+
const strict = await readRecoveryStrict(bundleDir);
|
|
13325
|
+
return strict ?? emptyJournal();
|
|
13326
|
+
}
|
|
13327
|
+
function classifyFailure(input) {
|
|
13328
|
+
if (input.stalled === true || input.timedOut === true) return "transient";
|
|
13329
|
+
if (input.verificationFailed === true) return "semantic";
|
|
13330
|
+
const note = input.note ?? "";
|
|
13331
|
+
if (/^AUTHORIZATION:/i.test(note.trim())) return "authorization";
|
|
13332
|
+
if (/timeout|stall|econn|rate limit|\b429\b|\b5\d\d\b/i.test(note)) return "transient";
|
|
13333
|
+
const prior = input.prior ?? null;
|
|
13334
|
+
if (prior !== null && prior.attempts >= 1 && note === prior.lastNote) return "no_progress";
|
|
13335
|
+
return "semantic";
|
|
13336
|
+
}
|
|
13337
|
+
async function writeRecovery(bundleDir, journal) {
|
|
13338
|
+
const target = recoveryPath(bundleDir);
|
|
13339
|
+
await mkdir7(dirname6(target), { recursive: true });
|
|
13340
|
+
const temp = `${target}.${process.pid}.${randomUUID2()}.tmp`;
|
|
13341
|
+
try {
|
|
13342
|
+
await writeFile7(temp, `${JSON.stringify(journal, null, 2)}
|
|
13343
|
+
`, "utf8");
|
|
13344
|
+
await rename2(temp, target);
|
|
13345
|
+
} catch (error) {
|
|
13346
|
+
await rm6(temp, { force: true }).catch(() => {
|
|
13347
|
+
});
|
|
13348
|
+
throw error;
|
|
13349
|
+
}
|
|
13350
|
+
}
|
|
13351
|
+
async function recordFailure(bundleDir, ref, args) {
|
|
13352
|
+
return withStateLock(bundleDir, async () => {
|
|
13353
|
+
const journal = await readRecovery(bundleDir);
|
|
13354
|
+
const prior = journal.tasks[ref] ?? null;
|
|
13355
|
+
const klass = classifyFailure({ ...args, prior });
|
|
13356
|
+
const attempt = (prior?.attempts ?? 0) + 1;
|
|
13357
|
+
const budget = recoveryBudget({
|
|
13358
|
+
failureClass: klass,
|
|
13359
|
+
priorAttempts: prior?.attempts ?? 0,
|
|
13360
|
+
priorClass: prior?.lastClass ?? null
|
|
13361
|
+
});
|
|
13362
|
+
const exhausted = attempt >= budget;
|
|
13363
|
+
const resumable = exhausted;
|
|
13364
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
13365
|
+
const note = args.note ?? "";
|
|
13366
|
+
const history = [...prior?.history ?? []];
|
|
13367
|
+
history.push({ attempt, class: klass, note, at: now });
|
|
13368
|
+
const capped = history.length > 20 ? history.slice(history.length - 20) : history;
|
|
13369
|
+
const entry = {
|
|
13370
|
+
ref,
|
|
13371
|
+
attempts: attempt,
|
|
13372
|
+
exhausted,
|
|
13373
|
+
resumable,
|
|
13374
|
+
lastClass: klass,
|
|
13375
|
+
lastNote: note === "" ? prior?.lastNote ?? "" : note,
|
|
13376
|
+
history: capped,
|
|
13377
|
+
updatedAt: now
|
|
13378
|
+
};
|
|
13379
|
+
journal.tasks[ref] = entry;
|
|
13380
|
+
await writeRecovery(bundleDir, journal);
|
|
13381
|
+
return { entry, exhausted, class: klass, attempt };
|
|
13382
|
+
});
|
|
13383
|
+
}
|
|
13384
|
+
async function recordSuccess(bundleDir, ref) {
|
|
13385
|
+
await withStateLock(bundleDir, async () => {
|
|
13386
|
+
const journal = await readRecovery(bundleDir);
|
|
13387
|
+
if (journal.tasks[ref] !== void 0) {
|
|
13388
|
+
delete journal.tasks[ref];
|
|
13389
|
+
await writeRecovery(bundleDir, journal);
|
|
13390
|
+
}
|
|
13391
|
+
});
|
|
13392
|
+
}
|
|
13393
|
+
async function rearmTask(bundleDir, ref) {
|
|
13394
|
+
await withStateLock(bundleDir, async () => {
|
|
13395
|
+
const journal = await readRecovery(bundleDir);
|
|
13396
|
+
const prior = journal.tasks[ref];
|
|
13397
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
13398
|
+
const entry = {
|
|
13399
|
+
ref,
|
|
13400
|
+
attempts: 0,
|
|
13401
|
+
exhausted: false,
|
|
13402
|
+
resumable: true,
|
|
13403
|
+
lastClass: prior?.lastClass ?? null,
|
|
13404
|
+
lastNote: prior?.lastNote ?? "",
|
|
13405
|
+
history: prior?.history ?? [],
|
|
13406
|
+
updatedAt: now
|
|
13407
|
+
};
|
|
13408
|
+
journal.tasks[ref] = entry;
|
|
13409
|
+
await writeRecovery(bundleDir, journal);
|
|
13410
|
+
});
|
|
13411
|
+
}
|
|
13412
|
+
function isExhausted(journal, ref) {
|
|
13413
|
+
return journal.tasks[ref]?.exhausted === true;
|
|
13414
|
+
}
|
|
13415
|
+
function describeRecovery(entry) {
|
|
13416
|
+
if (entry === void 0) {
|
|
13417
|
+
return "No recovery record. Run `jioogen resume`, then retry with a different approach.";
|
|
13418
|
+
}
|
|
13419
|
+
const lines = [];
|
|
13420
|
+
lines.push(
|
|
13421
|
+
`Task ${entry.ref}: ${entry.attempts}/${RECOVERY_BUDGET.maxAttempts} attempts, last=${entry.lastClass ?? "none"}.`
|
|
13422
|
+
);
|
|
13423
|
+
if (entry.lastNote.length > 0) lines.push(`Last note: ${entry.lastNote}`);
|
|
13424
|
+
lines.push("Run `jioogen resume`, then retry with a different approach.");
|
|
13425
|
+
return lines.join("\n");
|
|
13426
|
+
}
|
|
13200
13427
|
|
|
13201
13428
|
// src/skills.ts
|
|
13202
13429
|
import { createHash as createHash3 } from "node:crypto";
|
|
13203
|
-
import { cp as cp2, mkdir as
|
|
13430
|
+
import { cp as cp2, mkdir as mkdir8, readdir as readdir6, readFile as readFile10, rename as rename3, rm as rm7, stat as stat5, writeFile as writeFile8 } from "node:fs/promises";
|
|
13204
13431
|
import { homedir as homedir2 } from "node:os";
|
|
13205
|
-
import { dirname as
|
|
13432
|
+
import { dirname as dirname7, join as join11, resolve as resolve3 } from "node:path";
|
|
13206
13433
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
13207
13434
|
var EXECUTION_SKILL_NAME = "jioogen-execution";
|
|
13208
13435
|
var AGENT_SKILL_DIRS = [
|
|
@@ -13685,18 +13912,18 @@ Gap non-material \u2192 tafsir paling sempit + catat asumsi di note, lanjut. Gap
|
|
|
13685
13912
|
Jangan menebak scope baru.
|
|
13686
13913
|
`;
|
|
13687
13914
|
async function ensureCustomScaffold(root) {
|
|
13688
|
-
const base =
|
|
13915
|
+
const base = join11(root, ".jioogen", "custom");
|
|
13689
13916
|
for (const dir of CUSTOM_SCAFFOLD_DIRS) {
|
|
13690
|
-
await
|
|
13917
|
+
await mkdir8(join11(base, dir), { recursive: true });
|
|
13691
13918
|
}
|
|
13692
|
-
const readme =
|
|
13919
|
+
const readme = join11(root, CUSTOM_SCAFFOLD_README_PATH);
|
|
13693
13920
|
if (await readFileSafe(readme) !== void 0) return [];
|
|
13694
|
-
await
|
|
13921
|
+
await writeFile8(readme, CUSTOM_SCAFFOLD_README, "utf8");
|
|
13695
13922
|
return [CUSTOM_SCAFFOLD_README_PATH];
|
|
13696
13923
|
}
|
|
13697
13924
|
async function readFileSafe(path) {
|
|
13698
13925
|
try {
|
|
13699
|
-
return await
|
|
13926
|
+
return await readFile10(path, "utf8");
|
|
13700
13927
|
} catch {
|
|
13701
13928
|
return void 0;
|
|
13702
13929
|
}
|
|
@@ -13704,14 +13931,14 @@ async function readFileSafe(path) {
|
|
|
13704
13931
|
function isRecord2(value) {
|
|
13705
13932
|
return typeof value === "object" && value !== null;
|
|
13706
13933
|
}
|
|
13707
|
-
function
|
|
13934
|
+
function isMissingFile5(error) {
|
|
13708
13935
|
return isRecord2(error) && error.code === "ENOENT";
|
|
13709
13936
|
}
|
|
13710
13937
|
async function isFile(path) {
|
|
13711
13938
|
try {
|
|
13712
13939
|
return (await stat5(path)).isFile();
|
|
13713
13940
|
} catch (error) {
|
|
13714
|
-
if (
|
|
13941
|
+
if (isMissingFile5(error)) return false;
|
|
13715
13942
|
throw error;
|
|
13716
13943
|
}
|
|
13717
13944
|
}
|
|
@@ -13719,7 +13946,7 @@ async function isDirectory(path) {
|
|
|
13719
13946
|
try {
|
|
13720
13947
|
return (await stat5(path)).isDirectory();
|
|
13721
13948
|
} catch (error) {
|
|
13722
|
-
if (
|
|
13949
|
+
if (isMissingFile5(error)) return false;
|
|
13723
13950
|
throw error;
|
|
13724
13951
|
}
|
|
13725
13952
|
}
|
|
@@ -13785,12 +14012,12 @@ function parseHarnessManifest(value) {
|
|
|
13785
14012
|
};
|
|
13786
14013
|
}
|
|
13787
14014
|
async function readHarnessManifest(bundleDir) {
|
|
13788
|
-
const path =
|
|
14015
|
+
const path = join11(resolve3(bundleDir), HARNESS_MANIFEST_PATH);
|
|
13789
14016
|
let raw;
|
|
13790
14017
|
try {
|
|
13791
|
-
raw = await
|
|
14018
|
+
raw = await readFile10(path, "utf8");
|
|
13792
14019
|
} catch (error) {
|
|
13793
|
-
if (
|
|
14020
|
+
if (isMissingFile5(error)) return null;
|
|
13794
14021
|
throw error;
|
|
13795
14022
|
}
|
|
13796
14023
|
try {
|
|
@@ -13800,24 +14027,24 @@ async function readHarnessManifest(bundleDir) {
|
|
|
13800
14027
|
}
|
|
13801
14028
|
}
|
|
13802
14029
|
async function writeHarnessManifest(bundleDir, manifest) {
|
|
13803
|
-
const path =
|
|
13804
|
-
await
|
|
13805
|
-
await
|
|
14030
|
+
const path = join11(resolve3(bundleDir), HARNESS_MANIFEST_PATH);
|
|
14031
|
+
await mkdir8(dirname7(path), { recursive: true });
|
|
14032
|
+
await writeFile8(path, `${JSON.stringify(manifest, null, 2)}
|
|
13806
14033
|
`, "utf8");
|
|
13807
14034
|
return path;
|
|
13808
14035
|
}
|
|
13809
14036
|
async function detectProductKind(bundleDir) {
|
|
13810
|
-
const tasksDir =
|
|
14037
|
+
const tasksDir = join11(contractRoot(resolve3(bundleDir)), "tasks");
|
|
13811
14038
|
let entries;
|
|
13812
14039
|
try {
|
|
13813
14040
|
entries = await readdir6(tasksDir, { withFileTypes: true });
|
|
13814
14041
|
} catch (error) {
|
|
13815
|
-
if (
|
|
14042
|
+
if (isMissingFile5(error)) return "non-ui";
|
|
13816
14043
|
throw error;
|
|
13817
14044
|
}
|
|
13818
14045
|
for (const entry of entries) {
|
|
13819
14046
|
if (!entry.isFile() || !entry.name.toLowerCase().endsWith(".md")) continue;
|
|
13820
|
-
const content = await readFileSafe(
|
|
14047
|
+
const content = await readFileSafe(join11(tasksDir, entry.name));
|
|
13821
14048
|
if (content !== void 0 && FRONTEND_MOCK_LAYER_RE.test(content)) return "ui";
|
|
13822
14049
|
}
|
|
13823
14050
|
return "non-ui";
|
|
@@ -13833,30 +14060,30 @@ function packsForProduct(productKind, uiQuality = "auto") {
|
|
|
13833
14060
|
return packs;
|
|
13834
14061
|
}
|
|
13835
14062
|
function cliPackageRoot2() {
|
|
13836
|
-
return resolve3(
|
|
14063
|
+
return resolve3(dirname7(fileURLToPath2(import.meta.url)), "..");
|
|
13837
14064
|
}
|
|
13838
14065
|
function skillSourceCandidates(pack, name) {
|
|
13839
14066
|
const candidates = [];
|
|
13840
14067
|
const override = process.env.JIOOGEN_SKILLS_DIR?.trim();
|
|
13841
|
-
if (override !== void 0 && override.length > 0) candidates.push(
|
|
13842
|
-
candidates.push(
|
|
13843
|
-
candidates.push(
|
|
14068
|
+
if (override !== void 0 && override.length > 0) candidates.push(join11(override, name));
|
|
14069
|
+
candidates.push(join11(configDir(), "skill-cache", name));
|
|
14070
|
+
candidates.push(join11(cliPackageRoot2(), "skills-pack", pack, name));
|
|
13844
14071
|
const home = homedir2();
|
|
13845
|
-
candidates.push(
|
|
13846
|
-
candidates.push(
|
|
13847
|
-
candidates.push(
|
|
14072
|
+
candidates.push(join11(home, ".agents", "skills", name));
|
|
14073
|
+
candidates.push(join11(home, ".config", "opencode", "skills", name));
|
|
14074
|
+
candidates.push(join11(home, ".claude", "skills", name));
|
|
13848
14075
|
return candidates;
|
|
13849
14076
|
}
|
|
13850
14077
|
async function resolveSkillSource(pack, name) {
|
|
13851
14078
|
for (const candidate of skillSourceCandidates(pack, name)) {
|
|
13852
|
-
if (await isDirectory(candidate) && await isFile(
|
|
14079
|
+
if (await isDirectory(candidate) && await isFile(join11(candidate, "SKILL.md"))) {
|
|
13853
14080
|
return candidate;
|
|
13854
14081
|
}
|
|
13855
14082
|
}
|
|
13856
14083
|
return null;
|
|
13857
14084
|
}
|
|
13858
14085
|
async function collectRelativeFiles(root, prefix) {
|
|
13859
|
-
const entries = await readdir6(
|
|
14086
|
+
const entries = await readdir6(join11(root, prefix), { withFileTypes: true });
|
|
13860
14087
|
const files = [];
|
|
13861
14088
|
for (const entry of entries) {
|
|
13862
14089
|
const relative3 = prefix.length === 0 ? entry.name : `${prefix}/${entry.name}`;
|
|
@@ -13875,14 +14102,14 @@ async function hashSkillDirectory(directory) {
|
|
|
13875
14102
|
for (const relative3 of files) {
|
|
13876
14103
|
hash.update(relative3);
|
|
13877
14104
|
hash.update("\0");
|
|
13878
|
-
hash.update(await
|
|
14105
|
+
hash.update(await readFile10(join11(root, ...relative3.split("/"))));
|
|
13879
14106
|
hash.update("\0");
|
|
13880
14107
|
}
|
|
13881
14108
|
return hash.digest("hex");
|
|
13882
14109
|
}
|
|
13883
14110
|
async function replaceDirectory(source, target) {
|
|
13884
|
-
await
|
|
13885
|
-
await
|
|
14111
|
+
await rm7(target, { recursive: true, force: true });
|
|
14112
|
+
await mkdir8(dirname7(target), { recursive: true });
|
|
13886
14113
|
await cp2(source, target, { recursive: true });
|
|
13887
14114
|
}
|
|
13888
14115
|
function packNamesInCanonicalOrder(names) {
|
|
@@ -13902,8 +14129,8 @@ async function provisionPack(root, pack, prior, written, preserved) {
|
|
|
13902
14129
|
const previous = prior?.skills.find((entry) => entry.name === name);
|
|
13903
14130
|
let owned = previous !== void 0;
|
|
13904
14131
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
13905
|
-
const targetDir =
|
|
13906
|
-
const skillMd =
|
|
14132
|
+
const targetDir = join11(root, dir, name);
|
|
14133
|
+
const skillMd = join11(targetDir, "SKILL.md");
|
|
13907
14134
|
if (await isFile(skillMd)) {
|
|
13908
14135
|
const targetHash = await hashSkillDirectory(targetDir);
|
|
13909
14136
|
if (previous === void 0) {
|
|
@@ -13934,18 +14161,18 @@ async function provisionCustomSkills(root, prior) {
|
|
|
13934
14161
|
const conflicts = [];
|
|
13935
14162
|
const removed = [];
|
|
13936
14163
|
const sources = /* @__PURE__ */ new Set();
|
|
13937
|
-
const base =
|
|
14164
|
+
const base = join11(root, CUSTOM_SKILLS_DIR);
|
|
13938
14165
|
const reserved = /* @__PURE__ */ new Set([EXECUTION_SKILL_NAME, ...Object.values(SKILL_PACKS).flat()]);
|
|
13939
14166
|
let entries = [];
|
|
13940
14167
|
try {
|
|
13941
14168
|
entries = await readdir6(base, { withFileTypes: true });
|
|
13942
14169
|
} catch (error) {
|
|
13943
|
-
if (!
|
|
14170
|
+
if (!isMissingFile5(error)) throw error;
|
|
13944
14171
|
}
|
|
13945
14172
|
const names = entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
|
|
13946
14173
|
for (const name of names) {
|
|
13947
|
-
const source =
|
|
13948
|
-
if (!await isFile(
|
|
14174
|
+
const source = join11(base, name);
|
|
14175
|
+
if (!await isFile(join11(source, "SKILL.md"))) continue;
|
|
13949
14176
|
sources.add(name);
|
|
13950
14177
|
if (reserved.has(name)) {
|
|
13951
14178
|
conflicts.push(name);
|
|
@@ -13955,8 +14182,8 @@ async function provisionCustomSkills(root, prior) {
|
|
|
13955
14182
|
const previous = prior.find((entry) => entry.name === name);
|
|
13956
14183
|
let owned = previous !== void 0;
|
|
13957
14184
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
13958
|
-
const targetDir =
|
|
13959
|
-
const skillMd =
|
|
14185
|
+
const targetDir = join11(root, dir, name);
|
|
14186
|
+
const skillMd = join11(targetDir, "SKILL.md");
|
|
13960
14187
|
if (await isFile(skillMd)) {
|
|
13961
14188
|
const targetHash = await hashSkillDirectory(targetDir);
|
|
13962
14189
|
if (previous === void 0) {
|
|
@@ -13990,15 +14217,15 @@ async function provisionCustomSkills(root, prior) {
|
|
|
13990
14217
|
if (sources.has(entry.name) && !reserved.has(entry.name)) continue;
|
|
13991
14218
|
if (reserved.has(entry.name)) continue;
|
|
13992
14219
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
13993
|
-
const targetDir =
|
|
13994
|
-
const skillMd =
|
|
14220
|
+
const targetDir = join11(root, dir, entry.name);
|
|
14221
|
+
const skillMd = join11(targetDir, "SKILL.md");
|
|
13995
14222
|
if (!await isFile(skillMd)) continue;
|
|
13996
14223
|
const targetHash = await hashSkillDirectory(targetDir);
|
|
13997
14224
|
if (targetHash !== entry.sha256) {
|
|
13998
14225
|
preserved.push(`${dir}/${entry.name}/SKILL.md`);
|
|
13999
14226
|
continue;
|
|
14000
14227
|
}
|
|
14001
|
-
await
|
|
14228
|
+
await rm7(targetDir, { recursive: true, force: true });
|
|
14002
14229
|
removed.push(`${dir}/${entry.name}/SKILL.md`);
|
|
14003
14230
|
}
|
|
14004
14231
|
}
|
|
@@ -14042,10 +14269,10 @@ async function provisionSkillPacks(bundleDir, packNames, productKind) {
|
|
|
14042
14269
|
};
|
|
14043
14270
|
}
|
|
14044
14271
|
async function ensureBundleGitignore(root) {
|
|
14045
|
-
const path =
|
|
14272
|
+
const path = join11(resolve3(root), ".gitignore");
|
|
14046
14273
|
const existing = await readFileSafe(path);
|
|
14047
14274
|
if (existing === void 0) {
|
|
14048
|
-
await
|
|
14275
|
+
await writeFile8(path, GITIGNORE_BLOCK, "utf8");
|
|
14049
14276
|
return ".gitignore";
|
|
14050
14277
|
}
|
|
14051
14278
|
const start = existing.indexOf(GITIGNORE_START);
|
|
@@ -14053,7 +14280,7 @@ async function ensureBundleGitignore(root) {
|
|
|
14053
14280
|
const next = start >= 0 && end > start ? `${existing.slice(0, start)}${GITIGNORE_BLOCK}${existing.slice(end + GITIGNORE_END.length).replace(/^\n/, "")}` : `${existing.replace(/\n*$/, "\n")}
|
|
14054
14281
|
${GITIGNORE_BLOCK}`;
|
|
14055
14282
|
if (next === existing) return null;
|
|
14056
|
-
await
|
|
14283
|
+
await writeFile8(path, next, "utf8");
|
|
14057
14284
|
return ".gitignore";
|
|
14058
14285
|
}
|
|
14059
14286
|
async function installAgentSkills(bundleDir, options = {}) {
|
|
@@ -14061,20 +14288,20 @@ async function installAgentSkills(bundleDir, options = {}) {
|
|
|
14061
14288
|
const written = [];
|
|
14062
14289
|
const preserved = [];
|
|
14063
14290
|
const productKind = options.productKind ?? await detectProductKind(root);
|
|
14064
|
-
const harnessPath =
|
|
14065
|
-
const agentsPath =
|
|
14291
|
+
const harnessPath = join11(root, HARNESS_MANIFEST_PATH);
|
|
14292
|
+
const agentsPath = join11(root, "AGENTS.md");
|
|
14066
14293
|
const existing = await readFileSafe(agentsPath);
|
|
14067
14294
|
if (existing === void 0 || existing.includes(MARKER_PREFIX)) {
|
|
14068
|
-
await
|
|
14295
|
+
await writeFile8(agentsPath, JIOOGEN_AGENTS_MD, "utf8");
|
|
14069
14296
|
written.push("AGENTS.md");
|
|
14070
14297
|
} else {
|
|
14071
14298
|
preserved.push("AGENTS.md");
|
|
14072
14299
|
}
|
|
14073
14300
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
14074
14301
|
const relative3 = `${dir}/${EXECUTION_SKILL_NAME}/SKILL.md`;
|
|
14075
|
-
const target =
|
|
14076
|
-
await
|
|
14077
|
-
await
|
|
14302
|
+
const target = join11(root, relative3);
|
|
14303
|
+
await mkdir8(dirname7(target), { recursive: true });
|
|
14304
|
+
await writeFile8(target, JIOOGEN_EXECUTION_SKILL, "utf8");
|
|
14078
14305
|
written.push(relative3);
|
|
14079
14306
|
}
|
|
14080
14307
|
const gitignore = await ensureBundleGitignore(root);
|
|
@@ -14142,26 +14369,26 @@ async function removeExecutionContract(bundleDir) {
|
|
|
14142
14369
|
const root = resolve3(bundleDir);
|
|
14143
14370
|
const removed = [];
|
|
14144
14371
|
const preserved = [];
|
|
14145
|
-
const agentsPath =
|
|
14372
|
+
const agentsPath = join11(root, "AGENTS.md");
|
|
14146
14373
|
const existingAgents = await readFileSafe(agentsPath);
|
|
14147
14374
|
if (existingAgents !== void 0) {
|
|
14148
14375
|
if (existingAgents.includes(MARKER_PREFIX)) {
|
|
14149
|
-
await
|
|
14376
|
+
await rm7(agentsPath, { force: true });
|
|
14150
14377
|
removed.push("AGENTS.md");
|
|
14151
14378
|
} else {
|
|
14152
14379
|
preserved.push("AGENTS.md");
|
|
14153
14380
|
}
|
|
14154
14381
|
}
|
|
14155
14382
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
14156
|
-
const target =
|
|
14383
|
+
const target = join11(root, dir, EXECUTION_SKILL_NAME);
|
|
14157
14384
|
try {
|
|
14158
14385
|
const info = await stat5(target);
|
|
14159
14386
|
if (info.isDirectory()) {
|
|
14160
|
-
await
|
|
14387
|
+
await rm7(target, { recursive: true, force: true });
|
|
14161
14388
|
removed.push(`${dir}/${EXECUTION_SKILL_NAME}`);
|
|
14162
14389
|
}
|
|
14163
14390
|
} catch (error) {
|
|
14164
|
-
if (!
|
|
14391
|
+
if (!isMissingFile5(error)) throw error;
|
|
14165
14392
|
}
|
|
14166
14393
|
}
|
|
14167
14394
|
return { removed, preserved };
|
|
@@ -14176,15 +14403,15 @@ async function removeSkillPack(bundleDir, pack) {
|
|
|
14176
14403
|
if (entry !== void 0) {
|
|
14177
14404
|
for (const skill of entry.skills) {
|
|
14178
14405
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
14179
|
-
const targetDir =
|
|
14180
|
-
const skillMd =
|
|
14406
|
+
const targetDir = join11(root, dir, skill.name);
|
|
14407
|
+
const skillMd = join11(targetDir, "SKILL.md");
|
|
14181
14408
|
if (!await isFile(skillMd)) continue;
|
|
14182
14409
|
const targetHash = await hashSkillDirectory(targetDir);
|
|
14183
14410
|
if (targetHash !== skill.sha256) {
|
|
14184
14411
|
preserved.push(`${dir}/${skill.name}/SKILL.md`);
|
|
14185
14412
|
continue;
|
|
14186
14413
|
}
|
|
14187
|
-
await
|
|
14414
|
+
await rm7(targetDir, { recursive: true, force: true });
|
|
14188
14415
|
removed.push(`${dir}/${skill.name}/SKILL.md`);
|
|
14189
14416
|
}
|
|
14190
14417
|
}
|
|
@@ -14220,7 +14447,7 @@ async function restoreSkillPack(bundleDir, packArgument) {
|
|
|
14220
14447
|
}
|
|
14221
14448
|
const sha2562 = await hashSkillDirectory(source);
|
|
14222
14449
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
14223
|
-
const targetDir =
|
|
14450
|
+
const targetDir = join11(root, dir, name);
|
|
14224
14451
|
await replaceDirectory(source, targetDir);
|
|
14225
14452
|
restored.push(`${dir}/${name}`);
|
|
14226
14453
|
}
|
|
@@ -14246,11 +14473,11 @@ async function disableSkill(bundleDir, name) {
|
|
|
14246
14473
|
const root = resolve3(bundleDir);
|
|
14247
14474
|
const disabled = [];
|
|
14248
14475
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
14249
|
-
const targetDir =
|
|
14476
|
+
const targetDir = join11(root, dir, name);
|
|
14250
14477
|
const disabledDir = `${targetDir}.disabled`;
|
|
14251
14478
|
if (!await isDirectory(targetDir)) continue;
|
|
14252
|
-
if (await isDirectory(disabledDir)) await
|
|
14253
|
-
await
|
|
14479
|
+
if (await isDirectory(disabledDir)) await rm7(disabledDir, { recursive: true, force: true });
|
|
14480
|
+
await rename3(targetDir, disabledDir);
|
|
14254
14481
|
disabled.push(`${dir}/${name}`);
|
|
14255
14482
|
}
|
|
14256
14483
|
return { disabled };
|
|
@@ -14259,12 +14486,12 @@ async function enableSkill(bundleDir, name) {
|
|
|
14259
14486
|
const root = resolve3(bundleDir);
|
|
14260
14487
|
const enabled = [];
|
|
14261
14488
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
14262
|
-
const targetDir =
|
|
14489
|
+
const targetDir = join11(root, dir, name);
|
|
14263
14490
|
const disabledDir = `${targetDir}.disabled`;
|
|
14264
14491
|
if (!await isDirectory(disabledDir)) continue;
|
|
14265
|
-
if (await isDirectory(targetDir)) await
|
|
14492
|
+
if (await isDirectory(targetDir)) await rm7(disabledDir, { recursive: true, force: true });
|
|
14266
14493
|
else {
|
|
14267
|
-
await
|
|
14494
|
+
await rename3(disabledDir, targetDir);
|
|
14268
14495
|
enabled.push(`${dir}/${name}`);
|
|
14269
14496
|
}
|
|
14270
14497
|
}
|
|
@@ -14287,7 +14514,7 @@ function makeCheck(id, status, detail, fixable) {
|
|
|
14287
14514
|
function errorMessage(error) {
|
|
14288
14515
|
return error instanceof Error ? error.message : String(error);
|
|
14289
14516
|
}
|
|
14290
|
-
function
|
|
14517
|
+
function isMissingFile6(error) {
|
|
14291
14518
|
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
14292
14519
|
}
|
|
14293
14520
|
function resolveDeps(deps) {
|
|
@@ -14301,7 +14528,8 @@ function resolveDeps(deps) {
|
|
|
14301
14528
|
const client = new ApiClient(apiUrl, cookie);
|
|
14302
14529
|
return client.getJson(projectPath(projectId, "/execution"));
|
|
14303
14530
|
}),
|
|
14304
|
-
installSkills: deps?.installSkills ?? ((bundleDir) => installAgentSkills(bundleDir))
|
|
14531
|
+
installSkills: deps?.installSkills ?? ((bundleDir) => installAgentSkills(bundleDir)),
|
|
14532
|
+
publishSidecar: deps?.publishSidecar
|
|
14305
14533
|
};
|
|
14306
14534
|
}
|
|
14307
14535
|
function checkNode() {
|
|
@@ -14449,17 +14677,17 @@ async function listMarkdownFiles(directory) {
|
|
|
14449
14677
|
async function checkBundle(bundleDir) {
|
|
14450
14678
|
const missing = [];
|
|
14451
14679
|
const contract = contractRoot(bundleDir);
|
|
14452
|
-
if (!await isFile2(
|
|
14453
|
-
const specsDir =
|
|
14680
|
+
if (!await isFile2(join12(contract, "PRD.md"))) missing.push("PRD.md");
|
|
14681
|
+
const specsDir = join12(contract, "specs");
|
|
14454
14682
|
if (!await isDirectory2(specsDir)) {
|
|
14455
14683
|
missing.push("specs/");
|
|
14456
14684
|
} else {
|
|
14457
14685
|
const markdown = await listMarkdownFiles(specsDir);
|
|
14458
|
-
const readme = await
|
|
14686
|
+
const readme = await readFile11(join12(specsDir, "SPECS.md"), "utf8").catch(() => "");
|
|
14459
14687
|
const hasContent = markdown.some((name) => name.toLowerCase() !== "specs.md") || specReadmeIsContent(readme);
|
|
14460
14688
|
if (!hasContent) missing.push("specs/*.md (konten)");
|
|
14461
14689
|
}
|
|
14462
|
-
const tasksDir =
|
|
14690
|
+
const tasksDir = join12(contract, "tasks");
|
|
14463
14691
|
if (!await isDirectory2(tasksDir)) {
|
|
14464
14692
|
missing.push("tasks/");
|
|
14465
14693
|
} else {
|
|
@@ -14505,6 +14733,82 @@ async function checkSidecar(bundleDir) {
|
|
|
14505
14733
|
);
|
|
14506
14734
|
}
|
|
14507
14735
|
}
|
|
14736
|
+
async function checkStaleAdoption(bundleDir) {
|
|
14737
|
+
let state;
|
|
14738
|
+
try {
|
|
14739
|
+
state = await readState(bundleDir);
|
|
14740
|
+
} catch (error) {
|
|
14741
|
+
return makeCheck(
|
|
14742
|
+
"stale-adoption",
|
|
14743
|
+
"warn",
|
|
14744
|
+
`Tidak bisa memeriksa stale adoption: ${errorMessage(error)}.`
|
|
14745
|
+
);
|
|
14746
|
+
}
|
|
14747
|
+
if (state === null) {
|
|
14748
|
+
return makeCheck("stale-adoption", "pass", "Belum ada sidecar; stale adoption tidak berlaku.");
|
|
14749
|
+
}
|
|
14750
|
+
const strictJournal = await readRecoveryStrict(bundleDir);
|
|
14751
|
+
if (strictJournal === null) {
|
|
14752
|
+
return makeCheck(
|
|
14753
|
+
"stale-adoption",
|
|
14754
|
+
"warn",
|
|
14755
|
+
"Recovery journal rusak; stale adoption tidak diperbaiki otomatis."
|
|
14756
|
+
);
|
|
14757
|
+
}
|
|
14758
|
+
const journal = strictJournal;
|
|
14759
|
+
const unusableAdopted = [];
|
|
14760
|
+
for (const task of state.tasks) {
|
|
14761
|
+
const markers = (task.evidence ?? []).filter(
|
|
14762
|
+
(entry) => entry.type === "text" && entry.summary !== void 0 && entry.summary.startsWith("adopted outside harness")
|
|
14763
|
+
);
|
|
14764
|
+
if (markers.length === 0) continue;
|
|
14765
|
+
const hasValidAt = markers.some((entry) => {
|
|
14766
|
+
if (entry.at === void 0) return false;
|
|
14767
|
+
return !Number.isNaN(Date.parse(entry.at));
|
|
14768
|
+
});
|
|
14769
|
+
const baseAdopted = task.source === "user" || (task.evidence ?? []).some(
|
|
14770
|
+
(entry) => entry.type === "text" && entry.summary !== void 0 && entry.summary.startsWith("adopted outside harness")
|
|
14771
|
+
);
|
|
14772
|
+
if (baseAdopted && !hasValidAt) {
|
|
14773
|
+
unusableAdopted.push(task.ref);
|
|
14774
|
+
}
|
|
14775
|
+
}
|
|
14776
|
+
const candidates = [];
|
|
14777
|
+
const deferred = [];
|
|
14778
|
+
for (const task of state.tasks) {
|
|
14779
|
+
if (!isStaleAdoption(task)) continue;
|
|
14780
|
+
const checkpointPending = state.current?.ref === task.ref && state.current.awaitingCheckpoint === true;
|
|
14781
|
+
const exhausted = isExhausted(journal, task.ref);
|
|
14782
|
+
if (checkpointPending || exhausted) {
|
|
14783
|
+
deferred.push(task.ref);
|
|
14784
|
+
continue;
|
|
14785
|
+
}
|
|
14786
|
+
candidates.push(task.ref);
|
|
14787
|
+
}
|
|
14788
|
+
if (candidates.length > 0) {
|
|
14789
|
+
const detailParts = [
|
|
14790
|
+
`Task stale adoption (verified exit 0 lebih baru): ${candidates.join(", ")}`
|
|
14791
|
+
];
|
|
14792
|
+
if (deferred.length > 0) detailParts.push(`ditunda: ${deferred.join(", ")}`);
|
|
14793
|
+
if (unusableAdopted.length > 0)
|
|
14794
|
+
detailParts.push(`tanpa timestamp: ${unusableAdopted.join(", ")}`);
|
|
14795
|
+
return makeCheck(
|
|
14796
|
+
"stale-adoption",
|
|
14797
|
+
"warn",
|
|
14798
|
+
`${detailParts.join("; ")}. Jalankan \`jioogen doctor --fix\`.`,
|
|
14799
|
+
true
|
|
14800
|
+
);
|
|
14801
|
+
}
|
|
14802
|
+
if (deferred.length > 0 || unusableAdopted.length > 0) {
|
|
14803
|
+
const refs = [...deferred, ...unusableAdopted];
|
|
14804
|
+
return makeCheck(
|
|
14805
|
+
"stale-adoption",
|
|
14806
|
+
"warn",
|
|
14807
|
+
`Stale adoption tertunda/tidak dapat diperbaiki: ${refs.join(", ")}.`
|
|
14808
|
+
);
|
|
14809
|
+
}
|
|
14810
|
+
return makeCheck("stale-adoption", "pass", "Tidak ada stale adoption.");
|
|
14811
|
+
}
|
|
14508
14812
|
async function checkDrift(bundleDir) {
|
|
14509
14813
|
try {
|
|
14510
14814
|
const local = await snapshotContract(bundleDir);
|
|
@@ -14552,12 +14856,12 @@ async function checkDrift(bundleDir) {
|
|
|
14552
14856
|
}
|
|
14553
14857
|
}
|
|
14554
14858
|
async function checkRecovery(bundleDir) {
|
|
14555
|
-
const path =
|
|
14859
|
+
const path = join12(contractRoot(bundleDir), "tasks/.execution/recovery.json");
|
|
14556
14860
|
let raw;
|
|
14557
14861
|
try {
|
|
14558
|
-
raw = await
|
|
14862
|
+
raw = await readFile11(path, "utf8");
|
|
14559
14863
|
} catch (error) {
|
|
14560
|
-
if (
|
|
14864
|
+
if (isMissingFile6(error)) {
|
|
14561
14865
|
return makeCheck("recovery", "pass", "Belum ada recovery journal.");
|
|
14562
14866
|
}
|
|
14563
14867
|
return makeCheck("recovery", "warn", "Recovery journal tidak bisa dibaca.");
|
|
@@ -14588,7 +14892,7 @@ async function checkLock(bundleDir) {
|
|
|
14588
14892
|
try {
|
|
14589
14893
|
info = await stat6(target);
|
|
14590
14894
|
} catch (error) {
|
|
14591
|
-
if (
|
|
14895
|
+
if (isMissingFile6(error)) {
|
|
14592
14896
|
return makeCheck("lock", "pass", "Tidak ada lock; sidecar bebas ditulis.");
|
|
14593
14897
|
}
|
|
14594
14898
|
return makeCheck("lock", "warn", `Tidak bisa memeriksa lock: ${errorMessage(error)}.`);
|
|
@@ -14612,9 +14916,9 @@ async function checkLock(bundleDir) {
|
|
|
14612
14916
|
async function checkAgents(bundleDir) {
|
|
14613
14917
|
let content;
|
|
14614
14918
|
try {
|
|
14615
|
-
content = await
|
|
14919
|
+
content = await readFile11(join12(bundleDir, "AGENTS.md"), "utf8");
|
|
14616
14920
|
} catch (error) {
|
|
14617
|
-
if (
|
|
14921
|
+
if (isMissingFile6(error)) {
|
|
14618
14922
|
return makeCheck(
|
|
14619
14923
|
"agents",
|
|
14620
14924
|
"fail",
|
|
@@ -14642,7 +14946,7 @@ async function checkAgents(bundleDir) {
|
|
|
14642
14946
|
async function checkExecutionSkill(bundleDir) {
|
|
14643
14947
|
const missing = [];
|
|
14644
14948
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
14645
|
-
const target =
|
|
14949
|
+
const target = join12(bundleDir, dir, EXECUTION_SKILL_NAME, "SKILL.md");
|
|
14646
14950
|
if (!await isFile2(target)) missing.push(dir);
|
|
14647
14951
|
}
|
|
14648
14952
|
if (missing.length > 0) {
|
|
@@ -14690,8 +14994,8 @@ async function checkSkillPacks(bundleDir) {
|
|
|
14690
14994
|
for (const skill of pack.skills) {
|
|
14691
14995
|
let matched = false;
|
|
14692
14996
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
14693
|
-
const target =
|
|
14694
|
-
if (!await isFile2(
|
|
14997
|
+
const target = join12(bundleDir, dir, skill.name);
|
|
14998
|
+
if (!await isFile2(join12(target, "SKILL.md"))) continue;
|
|
14695
14999
|
try {
|
|
14696
15000
|
if (await hashSkillDirectory(target) === skill.sha256) {
|
|
14697
15001
|
matched = true;
|
|
@@ -14738,7 +15042,7 @@ function capabilityModelNotRequired(content) {
|
|
|
14738
15042
|
return notRequired;
|
|
14739
15043
|
}
|
|
14740
15044
|
async function collectMarkdownFiles2(root, prefix = "") {
|
|
14741
|
-
const dir =
|
|
15045
|
+
const dir = join12(root, prefix);
|
|
14742
15046
|
let entries;
|
|
14743
15047
|
try {
|
|
14744
15048
|
entries = await readdir7(dir, { withFileTypes: true });
|
|
@@ -14758,7 +15062,7 @@ async function checkCapabilityCoverage(bundleDir) {
|
|
|
14758
15062
|
const taskCaps = /* @__PURE__ */ new Map();
|
|
14759
15063
|
for (const relative3 of await collectMarkdownFiles2(contract, "tasks")) {
|
|
14760
15064
|
if (relative3 === BUNDLE_PATHS.TASKS_INDEX) continue;
|
|
14761
|
-
const content = await
|
|
15065
|
+
const content = await readFile11(join12(contract, relative3), "utf8");
|
|
14762
15066
|
const cap = TASK_CAP_RE.exec(content)?.[1]?.toUpperCase();
|
|
14763
15067
|
if (cap === void 0) continue;
|
|
14764
15068
|
taskCaps.set(cap, relative3);
|
|
@@ -14766,7 +15070,7 @@ async function checkCapabilityCoverage(bundleDir) {
|
|
|
14766
15070
|
const specCaps = /* @__PURE__ */ new Set();
|
|
14767
15071
|
const notRequiredCaps = /* @__PURE__ */ new Set();
|
|
14768
15072
|
for (const relative3 of await collectMarkdownFiles2(contract, "specs")) {
|
|
14769
|
-
const content = await
|
|
15073
|
+
const content = await readFile11(join12(contract, relative3), "utf8");
|
|
14770
15074
|
for (const match of content.matchAll(CAP_ID_RE)) {
|
|
14771
15075
|
const id = match[0].toUpperCase();
|
|
14772
15076
|
if (CAP_PLACEHOLDER_RE.test(id)) continue;
|
|
@@ -14817,7 +15121,7 @@ async function checkDuplicates(bundleDir) {
|
|
|
14817
15121
|
}
|
|
14818
15122
|
const dirsByName = /* @__PURE__ */ new Map();
|
|
14819
15123
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
14820
|
-
const root =
|
|
15124
|
+
const root = join12(bundleDir, dir);
|
|
14821
15125
|
if (!await isDirectory2(root)) continue;
|
|
14822
15126
|
let entries;
|
|
14823
15127
|
try {
|
|
@@ -14828,7 +15132,7 @@ async function checkDuplicates(bundleDir) {
|
|
|
14828
15132
|
for (const entry of entries) {
|
|
14829
15133
|
if (!entry.isDirectory()) continue;
|
|
14830
15134
|
if (managed.has(entry.name)) continue;
|
|
14831
|
-
if (!await isFile2(
|
|
15135
|
+
if (!await isFile2(join12(root, entry.name, "SKILL.md"))) continue;
|
|
14832
15136
|
const owners = dirsByName.get(entry.name) ?? [];
|
|
14833
15137
|
owners.push(dir);
|
|
14834
15138
|
dirsByName.set(entry.name, owners);
|
|
@@ -14848,7 +15152,7 @@ async function checkDuplicates(bundleDir) {
|
|
|
14848
15152
|
async function checkHarness(bundleDir) {
|
|
14849
15153
|
const detected = [];
|
|
14850
15154
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
14851
|
-
if (await isDirectory2(
|
|
15155
|
+
if (await isDirectory2(join12(bundleDir, dir))) detected.push(dir);
|
|
14852
15156
|
}
|
|
14853
15157
|
if (detected.length === 0) {
|
|
14854
15158
|
return makeCheck("harness", "pass", "Tidak ada direktori harness terdeteksi.");
|
|
@@ -14887,6 +15191,7 @@ async function runChecks(options, deps) {
|
|
|
14887
15191
|
checks.push(await checkProject(deps, credentials, effectiveProjectId));
|
|
14888
15192
|
checks.push(await checkBundle(options.bundleDir));
|
|
14889
15193
|
checks.push(await checkSidecar(options.bundleDir));
|
|
15194
|
+
checks.push(await checkStaleAdoption(options.bundleDir));
|
|
14890
15195
|
checks.push(await checkDrift(options.bundleDir));
|
|
14891
15196
|
checks.push(await checkLock(options.bundleDir));
|
|
14892
15197
|
checks.push(await checkRecovery(options.bundleDir));
|
|
@@ -14902,7 +15207,7 @@ async function applyFixes(options, deps, checks) {
|
|
|
14902
15207
|
let changed = false;
|
|
14903
15208
|
if (checks.some((check) => check.id === "lock" && check.fixable === true)) {
|
|
14904
15209
|
try {
|
|
14905
|
-
await
|
|
15210
|
+
await rm8(lockPath(options.bundleDir), { force: true });
|
|
14906
15211
|
changed = true;
|
|
14907
15212
|
} catch {
|
|
14908
15213
|
}
|
|
@@ -14917,6 +15222,44 @@ async function applyFixes(options, deps, checks) {
|
|
|
14917
15222
|
} catch {
|
|
14918
15223
|
}
|
|
14919
15224
|
}
|
|
15225
|
+
if (checks.some((check) => check.id === "stale-adoption" && check.fixable === true)) {
|
|
15226
|
+
try {
|
|
15227
|
+
let sidecarRepaired = false;
|
|
15228
|
+
await withStateLock(options.bundleDir, async () => {
|
|
15229
|
+
const state = await readState(options.bundleDir);
|
|
15230
|
+
if (state === null) return;
|
|
15231
|
+
const strictJournal = await readRecoveryStrict(options.bundleDir);
|
|
15232
|
+
if (strictJournal === null) return;
|
|
15233
|
+
const journal = strictJournal;
|
|
15234
|
+
let working = state;
|
|
15235
|
+
let localChanged = false;
|
|
15236
|
+
for (const task of state.tasks) {
|
|
15237
|
+
const checkpointPending = state.current?.ref === task.ref && state.current.awaitingCheckpoint === true;
|
|
15238
|
+
if (!isStaleAdoption(task)) continue;
|
|
15239
|
+
if (checkpointPending) continue;
|
|
15240
|
+
if (isExhausted(journal, task.ref)) continue;
|
|
15241
|
+
const next = supersedeStaleAdoption(working, task.ref, /* @__PURE__ */ new Date());
|
|
15242
|
+
if (next !== working) {
|
|
15243
|
+
working = next;
|
|
15244
|
+
localChanged = true;
|
|
15245
|
+
}
|
|
15246
|
+
}
|
|
15247
|
+
if (localChanged) {
|
|
15248
|
+
await writeState(options.bundleDir, working);
|
|
15249
|
+
changed = true;
|
|
15250
|
+
sidecarRepaired = true;
|
|
15251
|
+
}
|
|
15252
|
+
});
|
|
15253
|
+
if (sidecarRepaired) {
|
|
15254
|
+
try {
|
|
15255
|
+
await deps.publishSidecar?.(options.bundleDir);
|
|
15256
|
+
} catch {
|
|
15257
|
+
console.warn("Status tersimpan lokal; jalankan `jioogen sync`");
|
|
15258
|
+
}
|
|
15259
|
+
}
|
|
15260
|
+
} catch {
|
|
15261
|
+
}
|
|
15262
|
+
}
|
|
14920
15263
|
return changed;
|
|
14921
15264
|
}
|
|
14922
15265
|
async function runDoctor(options) {
|
|
@@ -14943,150 +15286,6 @@ function formatTable(headers, rows) {
|
|
|
14943
15286
|
return [render(headers), divider, ...rows.map(render)].join("\n");
|
|
14944
15287
|
}
|
|
14945
15288
|
|
|
14946
|
-
// src/recovery.ts
|
|
14947
|
-
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
14948
|
-
import { mkdir as mkdir8, readFile as readFile11, rename as rename3, rm as rm8, writeFile as writeFile8 } from "node:fs/promises";
|
|
14949
|
-
import { dirname as dirname7, join as join12 } from "node:path";
|
|
14950
|
-
var RECOVERY_PATH = "tasks/.execution/recovery.json";
|
|
14951
|
-
var RECOVERY_BUDGET = { maxAttempts: 3 };
|
|
14952
|
-
var RECOVERY_BASE_ATTEMPTS = 3;
|
|
14953
|
-
var RECOVERY_MAX_ATTEMPTS = 6;
|
|
14954
|
-
function recoveryBudget(input) {
|
|
14955
|
-
let budget = RECOVERY_BASE_ATTEMPTS;
|
|
14956
|
-
if (input.failureClass === "transient") budget += 1;
|
|
14957
|
-
if (input.failureClass === "semantic") budget += 1;
|
|
14958
|
-
return Math.min(budget, RECOVERY_MAX_ATTEMPTS);
|
|
14959
|
-
}
|
|
14960
|
-
function recoveryPath(bundleDir) {
|
|
14961
|
-
return join12(bundleDir, RECOVERY_PATH);
|
|
14962
|
-
}
|
|
14963
|
-
function emptyJournal() {
|
|
14964
|
-
return { schemaVersion: 1, tasks: {} };
|
|
14965
|
-
}
|
|
14966
|
-
function isJournal(value) {
|
|
14967
|
-
if (typeof value !== "object" || value === null) return false;
|
|
14968
|
-
const obj = value;
|
|
14969
|
-
if (obj.schemaVersion !== 1) return false;
|
|
14970
|
-
if (typeof obj.tasks !== "object" || obj.tasks === null) return false;
|
|
14971
|
-
return true;
|
|
14972
|
-
}
|
|
14973
|
-
async function readRecovery(bundleDir) {
|
|
14974
|
-
let raw;
|
|
14975
|
-
try {
|
|
14976
|
-
raw = await readFile11(recoveryPath(bundleDir), "utf8");
|
|
14977
|
-
} catch {
|
|
14978
|
-
return emptyJournal();
|
|
14979
|
-
}
|
|
14980
|
-
let payload;
|
|
14981
|
-
try {
|
|
14982
|
-
payload = JSON.parse(raw);
|
|
14983
|
-
} catch {
|
|
14984
|
-
return emptyJournal();
|
|
14985
|
-
}
|
|
14986
|
-
if (!isJournal(payload)) return emptyJournal();
|
|
14987
|
-
return payload;
|
|
14988
|
-
}
|
|
14989
|
-
function classifyFailure(input) {
|
|
14990
|
-
if (input.stalled === true || input.timedOut === true) return "transient";
|
|
14991
|
-
if (input.verificationFailed === true) return "semantic";
|
|
14992
|
-
const note = input.note ?? "";
|
|
14993
|
-
if (/^AUTHORIZATION:/i.test(note.trim())) return "authorization";
|
|
14994
|
-
if (/timeout|stall|econn|rate limit|\b429\b|\b5\d\d\b/i.test(note)) return "transient";
|
|
14995
|
-
const prior = input.prior ?? null;
|
|
14996
|
-
if (prior !== null && prior.attempts >= 1 && note === prior.lastNote) return "no_progress";
|
|
14997
|
-
return "semantic";
|
|
14998
|
-
}
|
|
14999
|
-
async function writeRecovery(bundleDir, journal) {
|
|
15000
|
-
const target = recoveryPath(bundleDir);
|
|
15001
|
-
await mkdir8(dirname7(target), { recursive: true });
|
|
15002
|
-
const temp = `${target}.${process.pid}.${randomUUID2()}.tmp`;
|
|
15003
|
-
try {
|
|
15004
|
-
await writeFile8(temp, `${JSON.stringify(journal, null, 2)}
|
|
15005
|
-
`, "utf8");
|
|
15006
|
-
await rename3(temp, target);
|
|
15007
|
-
} catch (error) {
|
|
15008
|
-
await rm8(temp, { force: true }).catch(() => {
|
|
15009
|
-
});
|
|
15010
|
-
throw error;
|
|
15011
|
-
}
|
|
15012
|
-
}
|
|
15013
|
-
async function recordFailure(bundleDir, ref, args) {
|
|
15014
|
-
return withStateLock(bundleDir, async () => {
|
|
15015
|
-
const journal = await readRecovery(bundleDir);
|
|
15016
|
-
const prior = journal.tasks[ref] ?? null;
|
|
15017
|
-
const klass = classifyFailure({ ...args, prior });
|
|
15018
|
-
const attempt = (prior?.attempts ?? 0) + 1;
|
|
15019
|
-
const budget = recoveryBudget({
|
|
15020
|
-
failureClass: klass,
|
|
15021
|
-
priorAttempts: prior?.attempts ?? 0,
|
|
15022
|
-
priorClass: prior?.lastClass ?? null
|
|
15023
|
-
});
|
|
15024
|
-
const exhausted = attempt >= budget;
|
|
15025
|
-
const resumable = exhausted;
|
|
15026
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
15027
|
-
const note = args.note ?? "";
|
|
15028
|
-
const history = [...prior?.history ?? []];
|
|
15029
|
-
history.push({ attempt, class: klass, note, at: now });
|
|
15030
|
-
const capped = history.length > 20 ? history.slice(history.length - 20) : history;
|
|
15031
|
-
const entry = {
|
|
15032
|
-
ref,
|
|
15033
|
-
attempts: attempt,
|
|
15034
|
-
exhausted,
|
|
15035
|
-
resumable,
|
|
15036
|
-
lastClass: klass,
|
|
15037
|
-
lastNote: note === "" ? prior?.lastNote ?? "" : note,
|
|
15038
|
-
history: capped,
|
|
15039
|
-
updatedAt: now
|
|
15040
|
-
};
|
|
15041
|
-
journal.tasks[ref] = entry;
|
|
15042
|
-
await writeRecovery(bundleDir, journal);
|
|
15043
|
-
return { entry, exhausted, class: klass, attempt };
|
|
15044
|
-
});
|
|
15045
|
-
}
|
|
15046
|
-
async function recordSuccess(bundleDir, ref) {
|
|
15047
|
-
await withStateLock(bundleDir, async () => {
|
|
15048
|
-
const journal = await readRecovery(bundleDir);
|
|
15049
|
-
if (journal.tasks[ref] !== void 0) {
|
|
15050
|
-
delete journal.tasks[ref];
|
|
15051
|
-
await writeRecovery(bundleDir, journal);
|
|
15052
|
-
}
|
|
15053
|
-
});
|
|
15054
|
-
}
|
|
15055
|
-
async function rearmTask(bundleDir, ref) {
|
|
15056
|
-
await withStateLock(bundleDir, async () => {
|
|
15057
|
-
const journal = await readRecovery(bundleDir);
|
|
15058
|
-
const prior = journal.tasks[ref];
|
|
15059
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
15060
|
-
const entry = {
|
|
15061
|
-
ref,
|
|
15062
|
-
attempts: 0,
|
|
15063
|
-
exhausted: false,
|
|
15064
|
-
resumable: true,
|
|
15065
|
-
lastClass: prior?.lastClass ?? null,
|
|
15066
|
-
lastNote: prior?.lastNote ?? "",
|
|
15067
|
-
history: prior?.history ?? [],
|
|
15068
|
-
updatedAt: now
|
|
15069
|
-
};
|
|
15070
|
-
journal.tasks[ref] = entry;
|
|
15071
|
-
await writeRecovery(bundleDir, journal);
|
|
15072
|
-
});
|
|
15073
|
-
}
|
|
15074
|
-
function isExhausted(journal, ref) {
|
|
15075
|
-
return journal.tasks[ref]?.exhausted === true;
|
|
15076
|
-
}
|
|
15077
|
-
function describeRecovery(entry) {
|
|
15078
|
-
if (entry === void 0) {
|
|
15079
|
-
return "No recovery record. Run `jioogen resume`, then retry with a different approach.";
|
|
15080
|
-
}
|
|
15081
|
-
const lines = [];
|
|
15082
|
-
lines.push(
|
|
15083
|
-
`Task ${entry.ref}: ${entry.attempts}/${RECOVERY_BUDGET.maxAttempts} attempts, last=${entry.lastClass ?? "none"}.`
|
|
15084
|
-
);
|
|
15085
|
-
if (entry.lastNote.length > 0) lines.push(`Last note: ${entry.lastNote}`);
|
|
15086
|
-
lines.push("Run `jioogen resume`, then retry with a different approach.");
|
|
15087
|
-
return lines.join("\n");
|
|
15088
|
-
}
|
|
15089
|
-
|
|
15090
15289
|
// src/session.ts
|
|
15091
15290
|
import { rm as rm9, stat as stat7 } from "node:fs/promises";
|
|
15092
15291
|
import { resolve as resolve4 } from "node:path";
|
|
@@ -15243,7 +15442,7 @@ async function removeStaleLock2(bundleDir) {
|
|
|
15243
15442
|
try {
|
|
15244
15443
|
info = await stat7(target);
|
|
15245
15444
|
} catch (error) {
|
|
15246
|
-
if (
|
|
15445
|
+
if (isMissingFile7(error)) return;
|
|
15247
15446
|
throw error;
|
|
15248
15447
|
}
|
|
15249
15448
|
if (Date.now() - info.mtimeMs <= LOCK_STALE_MS3) return;
|
|
@@ -15255,7 +15454,7 @@ function envFirst(primary, legacy) {
|
|
|
15255
15454
|
const fallback = process.env[legacy]?.trim();
|
|
15256
15455
|
return fallback !== void 0 && fallback.length > 0 ? fallback : void 0;
|
|
15257
15456
|
}
|
|
15258
|
-
function
|
|
15457
|
+
function isMissingFile7(error) {
|
|
15259
15458
|
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
15260
15459
|
}
|
|
15261
15460
|
|
|
@@ -15923,7 +16122,18 @@ async function doctorCommand(options) {
|
|
|
15923
16122
|
const report = await runDoctor({
|
|
15924
16123
|
bundleDir,
|
|
15925
16124
|
...projectId === void 0 ? {} : { projectId },
|
|
15926
|
-
fix: options.fix === true
|
|
16125
|
+
fix: options.fix === true,
|
|
16126
|
+
deps: {
|
|
16127
|
+
publishSidecar: async (bd) => {
|
|
16128
|
+
const pid = projectId ?? link?.projectId;
|
|
16129
|
+
if (pid === void 0) return;
|
|
16130
|
+
await pushSidecarBestEffort(options, {
|
|
16131
|
+
projectId: pid,
|
|
16132
|
+
bundleDir: bd,
|
|
16133
|
+
linkedApiUrl: link?.apiUrl
|
|
16134
|
+
});
|
|
16135
|
+
}
|
|
16136
|
+
}
|
|
15927
16137
|
});
|
|
15928
16138
|
if (options.json === true) {
|
|
15929
16139
|
console.log(JSON.stringify(report, null, 2));
|
|
@@ -17253,7 +17463,7 @@ async function assertPullTarget(target, projectId, force = false) {
|
|
|
17253
17463
|
try {
|
|
17254
17464
|
entries = await readdir8(target);
|
|
17255
17465
|
} catch (error) {
|
|
17256
|
-
if (
|
|
17466
|
+
if (isMissingFile8(error)) return;
|
|
17257
17467
|
throw error;
|
|
17258
17468
|
}
|
|
17259
17469
|
if (entries.length === 0) return;
|
|
@@ -17288,7 +17498,7 @@ async function hasBundleMarkers(target) {
|
|
|
17288
17498
|
await readFile12(join13(contractRoot(target), "PRD.md"));
|
|
17289
17499
|
return true;
|
|
17290
17500
|
} catch (error) {
|
|
17291
|
-
if (!
|
|
17501
|
+
if (!isMissingFile8(error)) throw error;
|
|
17292
17502
|
}
|
|
17293
17503
|
return hasTaskMarkdown(join13(contractRoot(target), "tasks"));
|
|
17294
17504
|
}
|
|
@@ -17297,7 +17507,7 @@ async function hasTaskMarkdown(directory) {
|
|
|
17297
17507
|
try {
|
|
17298
17508
|
names = await readdir8(directory);
|
|
17299
17509
|
} catch (error) {
|
|
17300
|
-
if (
|
|
17510
|
+
if (isMissingFile8(error)) return false;
|
|
17301
17511
|
throw error;
|
|
17302
17512
|
}
|
|
17303
17513
|
return names.some((name) => name.toLowerCase().endsWith(".md"));
|
|
@@ -17431,7 +17641,7 @@ function envFirst2(primary, legacy) {
|
|
|
17431
17641
|
const fallback = process.env[legacy]?.trim();
|
|
17432
17642
|
return fallback !== void 0 && fallback.length > 0 ? fallback : void 0;
|
|
17433
17643
|
}
|
|
17434
|
-
function
|
|
17644
|
+
function isMissingFile8(error) {
|
|
17435
17645
|
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
17436
17646
|
}
|
|
17437
17647
|
async function authoringInstallCommand(options) {
|
|
@@ -17547,7 +17757,7 @@ async function readLine() {
|
|
|
17547
17757
|
}
|
|
17548
17758
|
|
|
17549
17759
|
// src/index.ts
|
|
17550
|
-
var VERSION = "0.2.
|
|
17760
|
+
var VERSION = "0.2.19";
|
|
17551
17761
|
function parseTaskModeOption(value) {
|
|
17552
17762
|
if (value === void 0) return void 0;
|
|
17553
17763
|
const parsed = TaskModeSchema.safeParse(value);
|