jioogen 0.2.12 → 0.2.15
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 +2041 -540
- package/dist/index.js.map +4 -4
- package/package.json +9 -9
- package/skills-pack/ui-quality/impeccable/scripts/impeccable +0 -0
package/dist/index.js
CHANGED
|
@@ -358,14 +358,14 @@ var require_utils = __commonJS({
|
|
|
358
358
|
module.exports = Utils;
|
|
359
359
|
Utils.prototype.makeDir = function(folder) {
|
|
360
360
|
const self = this;
|
|
361
|
-
function
|
|
361
|
+
function mkdirSync2(fpath) {
|
|
362
362
|
let resolvedPath = fpath.split(self.sep)[0];
|
|
363
363
|
fpath.split(self.sep).forEach(function(name) {
|
|
364
364
|
if (!name || name.substr(-1, 1) === ":") return;
|
|
365
365
|
resolvedPath += self.sep + name;
|
|
366
|
-
var
|
|
366
|
+
var stat9;
|
|
367
367
|
try {
|
|
368
|
-
|
|
368
|
+
stat9 = self.fs.statSync(resolvedPath);
|
|
369
369
|
} catch (e) {
|
|
370
370
|
if (e.message && e.message.startsWith("ENOENT")) {
|
|
371
371
|
self.fs.mkdirSync(resolvedPath);
|
|
@@ -373,17 +373,17 @@ var require_utils = __commonJS({
|
|
|
373
373
|
throw e;
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
|
-
if (
|
|
376
|
+
if (stat9 && stat9.isFile()) throw Errors.FILE_IN_THE_WAY(`"${resolvedPath}"`);
|
|
377
377
|
});
|
|
378
378
|
}
|
|
379
|
-
|
|
379
|
+
mkdirSync2(folder);
|
|
380
380
|
};
|
|
381
381
|
Utils.prototype.writeFileTo = function(path, content, overwrite, attr) {
|
|
382
382
|
const self = this;
|
|
383
383
|
if (self.fs.existsSync(path)) {
|
|
384
384
|
if (!overwrite) return false;
|
|
385
|
-
var
|
|
386
|
-
if (
|
|
385
|
+
var stat9 = self.fs.statSync(path);
|
|
386
|
+
if (stat9.isDirectory()) {
|
|
387
387
|
return false;
|
|
388
388
|
}
|
|
389
389
|
}
|
|
@@ -416,8 +416,8 @@ var require_utils = __commonJS({
|
|
|
416
416
|
const self = this;
|
|
417
417
|
self.fs.exists(path, function(exist) {
|
|
418
418
|
if (exist && !overwrite) return callback(false);
|
|
419
|
-
self.fs.stat(path, function(err,
|
|
420
|
-
if (exist &&
|
|
419
|
+
self.fs.stat(path, function(err, stat9) {
|
|
420
|
+
if (exist && stat9 && stat9.isDirectory()) {
|
|
421
421
|
return callback(false);
|
|
422
422
|
}
|
|
423
423
|
var folder = pth.dirname(path);
|
|
@@ -469,13 +469,13 @@ var require_utils = __commonJS({
|
|
|
469
469
|
for (const part of rel.split(pth.sep)) {
|
|
470
470
|
if (!part || part === ".") continue;
|
|
471
471
|
cur = pth.join(cur, part);
|
|
472
|
-
let
|
|
472
|
+
let stat9;
|
|
473
473
|
try {
|
|
474
|
-
|
|
474
|
+
stat9 = self.fs.lstatSync(cur);
|
|
475
475
|
} catch (e) {
|
|
476
476
|
break;
|
|
477
477
|
}
|
|
478
|
-
if (
|
|
478
|
+
if (stat9.isSymbolicLink()) throw Errors.FILE_IN_THE_WAY(`"${cur}"`);
|
|
479
479
|
}
|
|
480
480
|
};
|
|
481
481
|
Utils.prototype.findFiles = function(path) {
|
|
@@ -502,11 +502,11 @@ var require_utils = __commonJS({
|
|
|
502
502
|
self.fs.readdirSync(dir).forEach(function(file) {
|
|
503
503
|
const path2 = pth.join(dir, file);
|
|
504
504
|
if (escapesRoot(path2)) return;
|
|
505
|
-
const
|
|
505
|
+
const stat9 = self.fs.statSync(path2);
|
|
506
506
|
if (!pattern || pattern.test(path2)) {
|
|
507
|
-
files.push(pth.normalize(path2) + (
|
|
507
|
+
files.push(pth.normalize(path2) + (stat9.isDirectory() ? self.sep : ""));
|
|
508
508
|
}
|
|
509
|
-
if (
|
|
509
|
+
if (stat9.isDirectory() && recursive) {
|
|
510
510
|
const realDir = self.fs.realpathSync(path2);
|
|
511
511
|
if (!visited.has(realDir)) {
|
|
512
512
|
visited.add(realDir);
|
|
@@ -553,14 +553,14 @@ var require_utils = __commonJS({
|
|
|
553
553
|
if (!--pending) done();
|
|
554
554
|
return;
|
|
555
555
|
}
|
|
556
|
-
self.fs.stat(file, function(err3,
|
|
556
|
+
self.fs.stat(file, function(err3, stat9) {
|
|
557
557
|
if (err3) return done(err3);
|
|
558
|
-
if (!
|
|
558
|
+
if (!stat9) {
|
|
559
559
|
if (!--pending) done();
|
|
560
560
|
return;
|
|
561
561
|
}
|
|
562
|
-
results.push(pth.normalize(file) + (
|
|
563
|
-
if (!
|
|
562
|
+
results.push(pth.normalize(file) + (stat9.isDirectory() ? self.sep : ""));
|
|
563
|
+
if (!stat9.isDirectory()) {
|
|
564
564
|
if (!--pending) done();
|
|
565
565
|
return;
|
|
566
566
|
}
|
|
@@ -2124,8 +2124,8 @@ var require_adm_zip = __commonJS({
|
|
|
2124
2124
|
return null;
|
|
2125
2125
|
}
|
|
2126
2126
|
function fixPath(zipPath) {
|
|
2127
|
-
const { join:
|
|
2128
|
-
return
|
|
2127
|
+
const { join: join14, normalize: normalize2, sep: sep2 } = pth.posix;
|
|
2128
|
+
return join14(pth.isAbsolute(zipPath) ? "/" : ".", normalize2(sep2 + zipPath.split("\\").join(sep2) + sep2));
|
|
2129
2129
|
}
|
|
2130
2130
|
function filenameFilter(filterfn) {
|
|
2131
2131
|
if (filterfn instanceof RegExp) {
|
|
@@ -8935,11 +8935,18 @@ function normalize(value) {
|
|
|
8935
8935
|
function taskId(task) {
|
|
8936
8936
|
return /TASK-\d{3,}/.exec(task.path)?.[0] ?? "TASK-001";
|
|
8937
8937
|
}
|
|
8938
|
+
var CAP_PLACEHOLDER = /^CAP-X+$/;
|
|
8939
|
+
function isCapPlaceholder(id) {
|
|
8940
|
+
return CAP_PLACEHOLDER.test(id.toUpperCase());
|
|
8941
|
+
}
|
|
8942
|
+
function realCapTokens(text2) {
|
|
8943
|
+
return (text2.match(/\bCAP-[A-Z0-9-]+\b/g) ?? []).filter((token) => !isCapPlaceholder(token));
|
|
8944
|
+
}
|
|
8938
8945
|
function taskOwnedCaps(tasks) {
|
|
8939
8946
|
const owned = /* @__PURE__ */ new Set();
|
|
8940
8947
|
for (const task of tasks) {
|
|
8941
8948
|
const cap = parseTaskContext(task.content, taskId(task)).cap;
|
|
8942
|
-
for (const token of cap
|
|
8949
|
+
for (const token of realCapTokens(cap ?? "")) {
|
|
8943
8950
|
owned.add(token.toUpperCase());
|
|
8944
8951
|
}
|
|
8945
8952
|
}
|
|
@@ -9179,7 +9186,7 @@ ${taskTargets(task)}`
|
|
|
9179
9186
|
);
|
|
9180
9187
|
}
|
|
9181
9188
|
}
|
|
9182
|
-
const capMentioned = input.capabilityRequired === true ||
|
|
9189
|
+
const capMentioned = input.capabilityRequired === true || realCapTokens(specText).length > 0 || taskOwnedCaps(tasks).size > 0;
|
|
9183
9190
|
const specIndex = specs.find((file) => file.path === BUNDLE_PATHS.SPECS_INDEX);
|
|
9184
9191
|
const capModel = specIndex === void 0 ? "" : section2(specIndex.content, "## Capability Model");
|
|
9185
9192
|
if (capMentioned && capModel.trim().length === 0) {
|
|
@@ -9207,6 +9214,7 @@ ${taskTargets(task)}`
|
|
|
9207
9214
|
if (row.every((cell) => cell.length === 0 || /^:?-{2,}:?$/.test(cell))) continue;
|
|
9208
9215
|
const cap = (row[capIndex] ?? "").toUpperCase();
|
|
9209
9216
|
if (!/^CAP-[A-Z0-9-]+$/.test(cap)) continue;
|
|
9217
|
+
if (isCapPlaceholder(cap)) continue;
|
|
9210
9218
|
const required = /^(?:yes|true|required|wajib)$/i.test(row[requiredIndex] ?? "");
|
|
9211
9219
|
if (!required) {
|
|
9212
9220
|
if ((row[signalIndex] ?? "").trim().length === 0) {
|
|
@@ -9949,6 +9957,34 @@ function computeCompletion(tasks, definitions) {
|
|
|
9949
9957
|
return { tasksDone, totalTasks: tasks.length, features, projectComplete };
|
|
9950
9958
|
}
|
|
9951
9959
|
|
|
9960
|
+
// ../contracts/src/layout.ts
|
|
9961
|
+
var LAYOUT_MARKER = ".bundle-layout.json";
|
|
9962
|
+
var CONTRACT_ROOT_REL = "docs/00-contract";
|
|
9963
|
+
function isContractArtifactPath(relative3) {
|
|
9964
|
+
return relative3 === "PRD.md" || relative3 === "traceability.md" || relative3.startsWith("specs/") || relative3.startsWith("tasks/");
|
|
9965
|
+
}
|
|
9966
|
+
function normalizeContractRoot(value) {
|
|
9967
|
+
if (typeof value !== "string") return null;
|
|
9968
|
+
const normalized = value.replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
9969
|
+
if (normalized.length === 0 || normalized === ".") return ".";
|
|
9970
|
+
if (normalized.includes("..") || normalized.startsWith("/")) return null;
|
|
9971
|
+
if (!/^[A-Za-z0-9._/-]+$/.test(normalized)) return null;
|
|
9972
|
+
return normalized;
|
|
9973
|
+
}
|
|
9974
|
+
function parseLayoutMarker(value) {
|
|
9975
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return null;
|
|
9976
|
+
const record = value;
|
|
9977
|
+
if (record.schemaVersion !== 1 || record.layout !== "docs") return null;
|
|
9978
|
+
return normalizeContractRoot(record.contractRoot);
|
|
9979
|
+
}
|
|
9980
|
+
function layoutMarker(contractRoot2 = CONTRACT_ROOT_REL) {
|
|
9981
|
+
return {
|
|
9982
|
+
schemaVersion: 1,
|
|
9983
|
+
layout: "docs",
|
|
9984
|
+
contractRoot: normalizeContractRoot(contractRoot2) ?? CONTRACT_ROOT_REL
|
|
9985
|
+
};
|
|
9986
|
+
}
|
|
9987
|
+
|
|
9952
9988
|
// src/api.ts
|
|
9953
9989
|
var DEFAULT_API_URL = "https://gen.jioo.site";
|
|
9954
9990
|
var SESSION_COOKIE = "jioo_session";
|
|
@@ -10035,6 +10071,24 @@ var ApiClient = class {
|
|
|
10035
10071
|
const response = await this.request(path);
|
|
10036
10072
|
return new Uint8Array(await response.arrayBuffer());
|
|
10037
10073
|
}
|
|
10074
|
+
async getWorkspaceArtifacts(projectId) {
|
|
10075
|
+
return this.getJson(projectPath(projectId, "/artifacts"));
|
|
10076
|
+
}
|
|
10077
|
+
async ensureProjectLayout(projectId) {
|
|
10078
|
+
return this.postJson(
|
|
10079
|
+
projectPath(projectId, "/layout"),
|
|
10080
|
+
{ layout: "docs" }
|
|
10081
|
+
);
|
|
10082
|
+
}
|
|
10083
|
+
async getPrdConfirmation(projectId) {
|
|
10084
|
+
return this.getJson(projectPath(projectId, "/prd-confirmation"));
|
|
10085
|
+
}
|
|
10086
|
+
async revokePrdConfirmation(projectId, reason) {
|
|
10087
|
+
return this.postJson(projectPath(projectId, "/prd-confirmation"), {
|
|
10088
|
+
action: "revoke-confirmation",
|
|
10089
|
+
reason
|
|
10090
|
+
});
|
|
10091
|
+
}
|
|
10038
10092
|
async request(path, options = {}) {
|
|
10039
10093
|
const { json, ...init } = options;
|
|
10040
10094
|
const headers = new Headers(init.headers);
|
|
@@ -10054,9 +10108,15 @@ var ApiClient = class {
|
|
|
10054
10108
|
};
|
|
10055
10109
|
|
|
10056
10110
|
// src/commands.ts
|
|
10111
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
10112
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
10113
|
+
import { mkdir as mkdir10, readdir as readdir8, readFile as readFile12, stat as stat8, writeFile as writeFile10 } from "node:fs/promises";
|
|
10114
|
+
import { join as join13, resolve as resolve6 } from "node:path";
|
|
10115
|
+
|
|
10116
|
+
// src/align.ts
|
|
10057
10117
|
import { spawn } from "node:child_process";
|
|
10058
|
-
import { mkdir as
|
|
10059
|
-
import { join as
|
|
10118
|
+
import { mkdir as mkdir5, readFile as readFile7, rm as rm4, stat as stat4, writeFile as writeFile5 } from "node:fs/promises";
|
|
10119
|
+
import { join as join8 } from "node:path";
|
|
10060
10120
|
|
|
10061
10121
|
// src/authoring.ts
|
|
10062
10122
|
import { existsSync } from "node:fs";
|
|
@@ -10075,6 +10135,9 @@ function cliPackageRoot() {
|
|
|
10075
10135
|
return resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
10076
10136
|
}
|
|
10077
10137
|
var BUNDLED_PACK_DIR = join(cliPackageRoot(), "authoring-pack");
|
|
10138
|
+
function bundledAuthoringPackDir() {
|
|
10139
|
+
return BUNDLED_PACK_DIR;
|
|
10140
|
+
}
|
|
10078
10141
|
async function readBundledManifest() {
|
|
10079
10142
|
const raw = await readFile(join(BUNDLED_PACK_DIR, "manifest.json"), "utf8");
|
|
10080
10143
|
const parsed = JSON.parse(raw);
|
|
@@ -10119,8 +10182,8 @@ async function containsExecutionMarker(dir) {
|
|
|
10119
10182
|
}
|
|
10120
10183
|
return false;
|
|
10121
10184
|
}
|
|
10122
|
-
async function
|
|
10123
|
-
const agentDir = join(
|
|
10185
|
+
async function buildAuthoringOpencodeConfig(packDir) {
|
|
10186
|
+
const agentDir = join(packDir, "agent");
|
|
10124
10187
|
const instructions = [];
|
|
10125
10188
|
try {
|
|
10126
10189
|
const entries = await readdir(agentDir);
|
|
@@ -10129,7 +10192,7 @@ async function buildOpencodeConfig(target) {
|
|
|
10129
10192
|
}
|
|
10130
10193
|
} catch {
|
|
10131
10194
|
}
|
|
10132
|
-
const skillsRoot = join(
|
|
10195
|
+
const skillsRoot = join(packDir, "skills");
|
|
10133
10196
|
const skillPaths = [];
|
|
10134
10197
|
try {
|
|
10135
10198
|
const entries = await readdir(skillsRoot, { withFileTypes: true });
|
|
@@ -10166,7 +10229,7 @@ async function installAuthoringContract(dir) {
|
|
|
10166
10229
|
await mkdir(target, { recursive: true });
|
|
10167
10230
|
await cp(BUNDLED_PACK_DIR, target, { recursive: true, force: true });
|
|
10168
10231
|
const opencodePath = join(target, "opencode.json");
|
|
10169
|
-
const opencodeConfig = await
|
|
10232
|
+
const opencodeConfig = await buildAuthoringOpencodeConfig(target);
|
|
10170
10233
|
await writeFile(opencodePath, `${JSON.stringify(opencodeConfig, null, 2)}
|
|
10171
10234
|
`, "utf8");
|
|
10172
10235
|
const marker = {
|
|
@@ -10223,7 +10286,339 @@ async function removeAuthoringContract(dir) {
|
|
|
10223
10286
|
|
|
10224
10287
|
// src/check.ts
|
|
10225
10288
|
import { readdir as readdir2, readFile as readFile2 } from "node:fs/promises";
|
|
10226
|
-
import { join as
|
|
10289
|
+
import { join as join3, relative } from "node:path";
|
|
10290
|
+
|
|
10291
|
+
// src/layout.ts
|
|
10292
|
+
import {
|
|
10293
|
+
cpSync,
|
|
10294
|
+
existsSync as existsSync2,
|
|
10295
|
+
mkdirSync,
|
|
10296
|
+
readdirSync,
|
|
10297
|
+
readFileSync,
|
|
10298
|
+
renameSync,
|
|
10299
|
+
rmSync,
|
|
10300
|
+
statSync,
|
|
10301
|
+
writeFileSync
|
|
10302
|
+
} from "node:fs";
|
|
10303
|
+
import { join as join2 } from "node:path";
|
|
10304
|
+
var contractRootCache = /* @__PURE__ */ new Map();
|
|
10305
|
+
function resetLayoutCache() {
|
|
10306
|
+
contractRootCache.clear();
|
|
10307
|
+
}
|
|
10308
|
+
function contractRoot(bundleDir) {
|
|
10309
|
+
const cached = contractRootCache.get(bundleDir);
|
|
10310
|
+
if (cached !== void 0) return cached;
|
|
10311
|
+
let resolved = bundleDir;
|
|
10312
|
+
try {
|
|
10313
|
+
const parsed = parseLayoutMarker(
|
|
10314
|
+
JSON.parse(readFileSync(join2(bundleDir, LAYOUT_MARKER), "utf8"))
|
|
10315
|
+
);
|
|
10316
|
+
if (parsed !== null) {
|
|
10317
|
+
resolved = parsed === "." ? bundleDir : join2(bundleDir, parsed);
|
|
10318
|
+
}
|
|
10319
|
+
} catch {
|
|
10320
|
+
if (existsSync2(join2(bundleDir, CONTRACT_ROOT_REL))) {
|
|
10321
|
+
resolved = join2(bundleDir, CONTRACT_ROOT_REL);
|
|
10322
|
+
}
|
|
10323
|
+
}
|
|
10324
|
+
contractRootCache.set(bundleDir, resolved);
|
|
10325
|
+
return resolved;
|
|
10326
|
+
}
|
|
10327
|
+
function resolveProjectPath(bundleDir, relative3) {
|
|
10328
|
+
return isContractArtifactPath(relative3) ? join2(contractRoot(bundleDir), relative3) : join2(bundleDir, relative3);
|
|
10329
|
+
}
|
|
10330
|
+
function ensureDocsLayout(bundleDir, contractRootRel = CONTRACT_ROOT_REL) {
|
|
10331
|
+
const normalized = normalizeContractRoot(contractRootRel) ?? CONTRACT_ROOT_REL;
|
|
10332
|
+
const physical = normalized === "." ? bundleDir : join2(bundleDir, normalized);
|
|
10333
|
+
mkdirSync(physical, { recursive: true });
|
|
10334
|
+
const markerPath = join2(bundleDir, LAYOUT_MARKER);
|
|
10335
|
+
if (!existsSync2(markerPath)) {
|
|
10336
|
+
writeFileSync(markerPath, `${JSON.stringify(layoutMarker(normalized), null, 2)}
|
|
10337
|
+
`, "utf8");
|
|
10338
|
+
}
|
|
10339
|
+
resetLayoutCache();
|
|
10340
|
+
}
|
|
10341
|
+
var CONTRACT_ENTRIES = ["PRD.md", "traceability.md", "specs", "tasks"];
|
|
10342
|
+
function timestamp() {
|
|
10343
|
+
return (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
10344
|
+
}
|
|
10345
|
+
function copyEntry(source, destination) {
|
|
10346
|
+
cpSync(source, destination, { recursive: true, errorOnExist: true, force: false });
|
|
10347
|
+
}
|
|
10348
|
+
function moveEntry(source, destination) {
|
|
10349
|
+
try {
|
|
10350
|
+
renameSync(source, destination);
|
|
10351
|
+
} catch (error) {
|
|
10352
|
+
const code = error.code;
|
|
10353
|
+
if (code !== "EXDEV") throw error;
|
|
10354
|
+
copyEntry(source, destination);
|
|
10355
|
+
rmSync(source, { recursive: true, force: true });
|
|
10356
|
+
}
|
|
10357
|
+
}
|
|
10358
|
+
function collectFiles(root, relative3) {
|
|
10359
|
+
const absolute = join2(root, relative3);
|
|
10360
|
+
if (!existsSync2(absolute)) return [];
|
|
10361
|
+
try {
|
|
10362
|
+
return readdirSync(absolute, { withFileTypes: true }).flatMap(
|
|
10363
|
+
(entry) => entry.isDirectory() ? collectFiles(root, `${relative3}/${entry.name}`) : entry.isFile() ? [`${relative3}/${entry.name}`] : []
|
|
10364
|
+
);
|
|
10365
|
+
} catch {
|
|
10366
|
+
return [];
|
|
10367
|
+
}
|
|
10368
|
+
}
|
|
10369
|
+
function normalizeContractLayout(bundleDir, options = {}) {
|
|
10370
|
+
ensureDocsLayout(bundleDir);
|
|
10371
|
+
const destination = join2(bundleDir, CONTRACT_ROOT_REL);
|
|
10372
|
+
const sources = CONTRACT_ENTRIES.filter((entry) => existsSync2(join2(bundleDir, entry)));
|
|
10373
|
+
if (sources.length === 0) return { moved: [], replaced: [], backup: null };
|
|
10374
|
+
const actions = [];
|
|
10375
|
+
for (const entry of sources) {
|
|
10376
|
+
const target = join2(destination, entry);
|
|
10377
|
+
if (!existsSync2(target)) {
|
|
10378
|
+
actions.push({ from: join2(bundleDir, entry), to: target, replace: false });
|
|
10379
|
+
continue;
|
|
10380
|
+
}
|
|
10381
|
+
const sourceIsDir = statSync(join2(bundleDir, entry)).isDirectory();
|
|
10382
|
+
if (!sourceIsDir) {
|
|
10383
|
+
const source = readFileSync(join2(bundleDir, entry));
|
|
10384
|
+
const dest = readFileSync(target);
|
|
10385
|
+
if (!source.equals(dest))
|
|
10386
|
+
actions.push({ from: join2(bundleDir, entry), to: target, replace: true });
|
|
10387
|
+
else actions.push({ from: join2(bundleDir, entry), to: target, replace: false });
|
|
10388
|
+
continue;
|
|
10389
|
+
}
|
|
10390
|
+
for (const relative3 of collectFiles(bundleDir, entry)) {
|
|
10391
|
+
const targetFile = join2(destination, relative3);
|
|
10392
|
+
const sourceFile = join2(bundleDir, relative3);
|
|
10393
|
+
if (!existsSync2(targetFile)) {
|
|
10394
|
+
actions.push({ from: sourceFile, to: targetFile, replace: false });
|
|
10395
|
+
} else {
|
|
10396
|
+
const source = readFileSync(sourceFile);
|
|
10397
|
+
const dest = readFileSync(targetFile);
|
|
10398
|
+
actions.push({ from: sourceFile, to: targetFile, replace: !source.equals(dest) });
|
|
10399
|
+
}
|
|
10400
|
+
}
|
|
10401
|
+
}
|
|
10402
|
+
if (options.dryRun) {
|
|
10403
|
+
return {
|
|
10404
|
+
moved: actions.filter((action) => !action.replace).map((a) => a.from),
|
|
10405
|
+
replaced: actions.filter((action) => action.replace).map((a) => a.from),
|
|
10406
|
+
backup: null
|
|
10407
|
+
};
|
|
10408
|
+
}
|
|
10409
|
+
const backup = join2(bundleDir, ".jioogen", "backups", `normalize-${timestamp()}`);
|
|
10410
|
+
for (const action of actions) {
|
|
10411
|
+
if (action.replace) {
|
|
10412
|
+
mkdirSync(join2(backup, "replaced"), { recursive: true });
|
|
10413
|
+
cpSync(action.to, join2(backup, "replaced", action.to.replace(/[/\\]/g, "__")), {
|
|
10414
|
+
recursive: true
|
|
10415
|
+
});
|
|
10416
|
+
rmSync(action.to, { recursive: true, force: true });
|
|
10417
|
+
}
|
|
10418
|
+
if (!action.replace && existsSync2(action.to)) {
|
|
10419
|
+
rmSync(action.from, { recursive: true, force: true });
|
|
10420
|
+
continue;
|
|
10421
|
+
}
|
|
10422
|
+
mkdirSync(join2(action.to, ".."), { recursive: true });
|
|
10423
|
+
moveEntry(action.from, action.to);
|
|
10424
|
+
}
|
|
10425
|
+
for (const entry of sources) {
|
|
10426
|
+
const remaining = collectFiles(bundleDir, entry);
|
|
10427
|
+
if (remaining.length === 0) rmSync(join2(bundleDir, entry), { recursive: true, force: true });
|
|
10428
|
+
}
|
|
10429
|
+
resetLayoutCache();
|
|
10430
|
+
return {
|
|
10431
|
+
moved: actions.filter((action) => !action.replace).map((a) => a.from),
|
|
10432
|
+
replaced: actions.filter((action) => action.replace).map((a) => a.from),
|
|
10433
|
+
backup
|
|
10434
|
+
};
|
|
10435
|
+
}
|
|
10436
|
+
function migrateContractLayout(bundleDir, options = {}) {
|
|
10437
|
+
const destination = join2(bundleDir, CONTRACT_ROOT_REL);
|
|
10438
|
+
const existingMarker = existsSync2(join2(bundleDir, LAYOUT_MARKER));
|
|
10439
|
+
const sources = CONTRACT_ENTRIES.filter((entry) => existsSync2(join2(bundleDir, entry)));
|
|
10440
|
+
if (existingMarker && sources.length > 0) {
|
|
10441
|
+
const normalized = normalizeContractLayout(
|
|
10442
|
+
bundleDir,
|
|
10443
|
+
options.dryRun === true ? { dryRun: true } : {}
|
|
10444
|
+
);
|
|
10445
|
+
return {
|
|
10446
|
+
migrated: normalized.moved.length + normalized.replaced.length > 0,
|
|
10447
|
+
moved: [...normalized.moved, ...normalized.replaced].map(
|
|
10448
|
+
(path) => path.replace(bundleDir + "/", "")
|
|
10449
|
+
),
|
|
10450
|
+
backup: normalized.backup
|
|
10451
|
+
};
|
|
10452
|
+
}
|
|
10453
|
+
if (sources.length === 0) {
|
|
10454
|
+
if (!options.dryRun) ensureDocsLayout(bundleDir);
|
|
10455
|
+
return {
|
|
10456
|
+
migrated: !existingMarker,
|
|
10457
|
+
moved: [],
|
|
10458
|
+
backup: null,
|
|
10459
|
+
...existingMarker ? { reason: "sudah memakai layout docs" } : {}
|
|
10460
|
+
};
|
|
10461
|
+
}
|
|
10462
|
+
for (const entry of sources) {
|
|
10463
|
+
if (existsSync2(join2(destination, entry))) {
|
|
10464
|
+
return {
|
|
10465
|
+
migrated: false,
|
|
10466
|
+
moved: [],
|
|
10467
|
+
backup: null,
|
|
10468
|
+
reason: `tujuan sudah berisi ${entry}`
|
|
10469
|
+
};
|
|
10470
|
+
}
|
|
10471
|
+
}
|
|
10472
|
+
if (options.dryRun) {
|
|
10473
|
+
return {
|
|
10474
|
+
migrated: true,
|
|
10475
|
+
moved: sources.map((entry) => `${entry} \u2192 ${CONTRACT_ROOT_REL}/${entry}`),
|
|
10476
|
+
backup: null
|
|
10477
|
+
};
|
|
10478
|
+
}
|
|
10479
|
+
mkdirSync(destination, { recursive: true });
|
|
10480
|
+
const backup = join2(bundleDir, ".jioogen", "backups", `layout-${timestamp()}`);
|
|
10481
|
+
mkdirSync(backup, { recursive: true });
|
|
10482
|
+
for (const entry of sources) copyEntry(join2(bundleDir, entry), join2(backup, entry));
|
|
10483
|
+
for (const entry of sources) {
|
|
10484
|
+
moveEntry(join2(bundleDir, entry), join2(destination, entry));
|
|
10485
|
+
}
|
|
10486
|
+
ensureDocsLayout(bundleDir);
|
|
10487
|
+
return {
|
|
10488
|
+
migrated: true,
|
|
10489
|
+
moved: sources.map((entry) => `${entry} \u2192 ${CONTRACT_ROOT_REL}/${entry}`),
|
|
10490
|
+
backup
|
|
10491
|
+
};
|
|
10492
|
+
}
|
|
10493
|
+
var DOCS_DOMAINS = [
|
|
10494
|
+
"01-product",
|
|
10495
|
+
"02-design",
|
|
10496
|
+
"03-architecture",
|
|
10497
|
+
"04-domain",
|
|
10498
|
+
"05-operations",
|
|
10499
|
+
"06-quality",
|
|
10500
|
+
"99-archive"
|
|
10501
|
+
];
|
|
10502
|
+
function ensureDocsTree(bundleDir) {
|
|
10503
|
+
mkdirSync(join2(bundleDir, "docs"), { recursive: true });
|
|
10504
|
+
for (const domain of DOCS_DOMAINS)
|
|
10505
|
+
mkdirSync(join2(bundleDir, "docs", domain), { recursive: true });
|
|
10506
|
+
}
|
|
10507
|
+
var ROOT_DOC_KEEP = /* @__PURE__ */ new Set([
|
|
10508
|
+
"agents.md",
|
|
10509
|
+
"readme.md",
|
|
10510
|
+
"prd.md",
|
|
10511
|
+
"traceability.md",
|
|
10512
|
+
"license.md",
|
|
10513
|
+
"changelog.md",
|
|
10514
|
+
"contributing.md"
|
|
10515
|
+
]);
|
|
10516
|
+
function classifyRootDoc(name) {
|
|
10517
|
+
const lower = name.toLowerCase();
|
|
10518
|
+
if (lower.includes("design") || lower.includes("style") || lower.includes("ui-ux")) {
|
|
10519
|
+
return "docs/02-design";
|
|
10520
|
+
}
|
|
10521
|
+
if (lower.includes("stack") || lower.includes("architecture") || lower.includes("adr") || lower.includes("decision")) {
|
|
10522
|
+
return "docs/03-architecture";
|
|
10523
|
+
}
|
|
10524
|
+
if (lower.includes("runbook") || lower.includes("deploy") || lower.includes("operation") || lower.includes("ops")) {
|
|
10525
|
+
return "docs/05-operations";
|
|
10526
|
+
}
|
|
10527
|
+
if (lower.includes("test") || lower.includes("qa") || lower.includes("quality")) {
|
|
10528
|
+
return "docs/06-quality";
|
|
10529
|
+
}
|
|
10530
|
+
if (lower.includes("domain") || lower.includes("schema") || lower.includes("model")) {
|
|
10531
|
+
return "docs/04-domain";
|
|
10532
|
+
}
|
|
10533
|
+
if (lower.includes("product") || lower.includes("vision") || lower.includes("persona") || lower.includes("glossary")) {
|
|
10534
|
+
return "docs/01-product";
|
|
10535
|
+
}
|
|
10536
|
+
return "docs/99-archive/unsorted";
|
|
10537
|
+
}
|
|
10538
|
+
var KNOWN_DOC_TARGETS = {
|
|
10539
|
+
"DESIGN.md": "docs/02-design/DESIGN.md",
|
|
10540
|
+
"STACK.md": "docs/03-architecture/STACK.md",
|
|
10541
|
+
"ARCHITECTURE.md": "docs/03-architecture/ARCHITECTURE.md",
|
|
10542
|
+
"RUNBOOK.md": "docs/05-operations/RUNBOOK.md",
|
|
10543
|
+
"TESTING.md": "docs/06-quality/TESTING.md"
|
|
10544
|
+
};
|
|
10545
|
+
function migrateKnownDocs(bundleDir, options = {}) {
|
|
10546
|
+
ensureDocsTree(bundleDir);
|
|
10547
|
+
const moves = [];
|
|
10548
|
+
for (const [name, target] of Object.entries(KNOWN_DOC_TARGETS)) {
|
|
10549
|
+
if (existsSync2(join2(bundleDir, name)) && !existsSync2(join2(bundleDir, target))) {
|
|
10550
|
+
moves.push({ from: name, to: target });
|
|
10551
|
+
}
|
|
10552
|
+
}
|
|
10553
|
+
try {
|
|
10554
|
+
for (const entry of readdirSync(bundleDir, { withFileTypes: true })) {
|
|
10555
|
+
if (!entry.isFile() || !/\.mdx?$/i.test(entry.name)) continue;
|
|
10556
|
+
if (ROOT_DOC_KEEP.has(entry.name.toLowerCase())) continue;
|
|
10557
|
+
if (Object.hasOwn(KNOWN_DOC_TARGETS, entry.name)) continue;
|
|
10558
|
+
const folder = classifyRootDoc(entry.name);
|
|
10559
|
+
const to = `${folder}/${entry.name}`;
|
|
10560
|
+
if (!existsSync2(join2(bundleDir, to))) moves.push({ from: entry.name, to });
|
|
10561
|
+
}
|
|
10562
|
+
} catch {
|
|
10563
|
+
}
|
|
10564
|
+
const stitch = join2(bundleDir, "assets", "stitch");
|
|
10565
|
+
if (existsSync2(stitch)) {
|
|
10566
|
+
for (const entry of readdirSync(stitch, { withFileTypes: true })) {
|
|
10567
|
+
if (!entry.isDirectory()) continue;
|
|
10568
|
+
const from = `assets/stitch/${entry.name}/DESIGN.md`;
|
|
10569
|
+
const to = `docs/99-archive/stitch/${entry.name}/DESIGN.md`;
|
|
10570
|
+
if (existsSync2(join2(bundleDir, from)) && !existsSync2(join2(bundleDir, to))) {
|
|
10571
|
+
moves.push({ from, to });
|
|
10572
|
+
}
|
|
10573
|
+
}
|
|
10574
|
+
}
|
|
10575
|
+
if (options.dryRun) {
|
|
10576
|
+
return { moved: moves.map((move) => `${move.from} \u2192 ${move.to}`), skipped: [], backup: null };
|
|
10577
|
+
}
|
|
10578
|
+
if (moves.length === 0) return { moved: [], skipped: [], backup: null };
|
|
10579
|
+
const backup = join2(bundleDir, ".jioogen", "backups", `docs-${timestamp()}`);
|
|
10580
|
+
mkdirSync(backup, { recursive: true });
|
|
10581
|
+
for (const move of moves) {
|
|
10582
|
+
const target = join2(bundleDir, move.to);
|
|
10583
|
+
mkdirSync(join2(target, ".."), { recursive: true });
|
|
10584
|
+
cpSync(join2(bundleDir, move.from), join2(backup, move.from.replace(/[/\\]/g, "__")), {
|
|
10585
|
+
recursive: true
|
|
10586
|
+
});
|
|
10587
|
+
moveEntry(join2(bundleDir, move.from), target);
|
|
10588
|
+
}
|
|
10589
|
+
return { moved: moves.map((move) => `${move.from} \u2192 ${move.to}`), skipped: [], backup };
|
|
10590
|
+
}
|
|
10591
|
+
function docsReadme() {
|
|
10592
|
+
return `# Dokumentasi Project
|
|
10593
|
+
|
|
10594
|
+
> Peta dokumen. Baca berurutan; jangan menganggap arsip sebagai sumber kebenaran.
|
|
10595
|
+
|
|
10596
|
+
## Urutan baca
|
|
10597
|
+
1. \`docs/00-contract/PRD.md\` \u2014 maksud dan scope produk
|
|
10598
|
+
2. \`docs/01-product/\` \u2014 konteks produk
|
|
10599
|
+
3. \`docs/00-contract/specs/\` \u2014 kontrak teknis
|
|
10600
|
+
4. \`docs/02-design/\` \u2014 desain dan token
|
|
10601
|
+
5. \`docs/03-architecture/\` \u2014 stack dan keputusan
|
|
10602
|
+
6. \`docs/04-domain/\` \u2014 aturan domain
|
|
10603
|
+
7. \`docs/00-contract/tasks/\` \u2014 urutan pekerjaan
|
|
10604
|
+
8. kode \u2014 kenyataan implementasi
|
|
10605
|
+
|
|
10606
|
+
## Lokasi contract
|
|
10607
|
+
- \`PRD.md\`, \`specs/\`, \`tasks/\`, \`traceability.md\` disimpan di \`docs/00-contract/\`.
|
|
10608
|
+
|
|
10609
|
+
## Aturan konflik
|
|
10610
|
+
Dokumen = niat. Kode = kenyataan. Bila berbeda, jangan menebak; tanyakan mana yang benar.
|
|
10611
|
+
`;
|
|
10612
|
+
}
|
|
10613
|
+
function writeDocsReadme(bundleDir, overwrite = false) {
|
|
10614
|
+
const target = join2(bundleDir, "docs", "README.md");
|
|
10615
|
+
if (existsSync2(target) && !overwrite) return false;
|
|
10616
|
+
mkdirSync(join2(bundleDir, "docs"), { recursive: true });
|
|
10617
|
+
writeFileSync(target, docsReadme(), "utf8");
|
|
10618
|
+
return true;
|
|
10619
|
+
}
|
|
10620
|
+
|
|
10621
|
+
// src/check.ts
|
|
10227
10622
|
var EXCLUDED_DIRS = /* @__PURE__ */ new Set([".execution", ".jioogen", ".jioocode", ".git", "node_modules"]);
|
|
10228
10623
|
async function collectMarkdownFiles(root) {
|
|
10229
10624
|
const found = [];
|
|
@@ -10237,13 +10632,16 @@ async function collectMarkdownFiles(root) {
|
|
|
10237
10632
|
for (const entry of entries) {
|
|
10238
10633
|
if (entry.isDirectory()) {
|
|
10239
10634
|
if (EXCLUDED_DIRS.has(entry.name)) continue;
|
|
10240
|
-
await walk2(
|
|
10635
|
+
await walk2(join3(dir, entry.name));
|
|
10241
10636
|
continue;
|
|
10242
10637
|
}
|
|
10243
10638
|
if (!entry.isFile() || !entry.name.toLowerCase().endsWith(".md")) continue;
|
|
10244
|
-
const absolute =
|
|
10639
|
+
const absolute = join3(dir, entry.name);
|
|
10640
|
+
const contract = contractRoot(root);
|
|
10641
|
+
const fromContract = relative(contract, absolute);
|
|
10642
|
+
const insideContract = fromContract.length > 0 && !fromContract.startsWith("..") && !fromContract.startsWith("/");
|
|
10245
10643
|
found.push({
|
|
10246
|
-
path: relative(root, absolute).replace(/\\/g, "/"),
|
|
10644
|
+
path: (insideContract ? fromContract : relative(root, absolute)).replace(/\\/g, "/"),
|
|
10247
10645
|
content: await readFile2(absolute, "utf8")
|
|
10248
10646
|
});
|
|
10249
10647
|
}
|
|
@@ -10370,258 +10768,263 @@ function formatBundleCheck(check) {
|
|
|
10370
10768
|
return lines.join("\n");
|
|
10371
10769
|
}
|
|
10372
10770
|
|
|
10373
|
-
// src/
|
|
10374
|
-
import {
|
|
10375
|
-
import {
|
|
10376
|
-
import { dirname as dirname2, join as
|
|
10377
|
-
|
|
10378
|
-
|
|
10379
|
-
var
|
|
10380
|
-
|
|
10381
|
-
|
|
10382
|
-
|
|
10383
|
-
|
|
10384
|
-
|
|
10385
|
-
|
|
10386
|
-
|
|
10387
|
-
|
|
10388
|
-
|
|
10389
|
-
|
|
10390
|
-
|
|
10391
|
-
|
|
10771
|
+
// src/contract.ts
|
|
10772
|
+
import { createHash } from "node:crypto";
|
|
10773
|
+
import { mkdir as mkdir2, readdir as readdir3, readFile as readFile3, writeFile as writeFile2 } from "node:fs/promises";
|
|
10774
|
+
import { dirname as dirname2, join as join4, relative as relative2 } from "node:path";
|
|
10775
|
+
var CONTRACT_LEDGER_PATH = join4(".jioogen", "contract.json");
|
|
10776
|
+
var APPROVALS_PATH = join4(".jioogen", "approvals.json");
|
|
10777
|
+
var LOCAL_IGNORED_DIRS = /* @__PURE__ */ new Set([".execution", ".jioogen", ".git", "node_modules"]);
|
|
10778
|
+
function sha256(bytes) {
|
|
10779
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
10780
|
+
}
|
|
10781
|
+
async function walkMarkdown(root, directory) {
|
|
10782
|
+
const found = [];
|
|
10783
|
+
async function walk2(current) {
|
|
10784
|
+
let entries;
|
|
10785
|
+
try {
|
|
10786
|
+
entries = await readdir3(current, { withFileTypes: true });
|
|
10787
|
+
} catch {
|
|
10788
|
+
return;
|
|
10789
|
+
}
|
|
10790
|
+
for (const entry of entries) {
|
|
10791
|
+
if (entry.isDirectory()) {
|
|
10792
|
+
if (LOCAL_IGNORED_DIRS.has(entry.name)) continue;
|
|
10793
|
+
await walk2(join4(current, entry.name));
|
|
10794
|
+
continue;
|
|
10795
|
+
}
|
|
10796
|
+
if (!entry.isFile() || !entry.name.toLowerCase().endsWith(".md")) continue;
|
|
10797
|
+
found.push(relative2(root, join4(current, entry.name)).replace(/\\/g, "/"));
|
|
10798
|
+
}
|
|
10799
|
+
}
|
|
10800
|
+
await walk2(join4(root, directory));
|
|
10801
|
+
return found.sort();
|
|
10392
10802
|
}
|
|
10393
|
-
function
|
|
10394
|
-
|
|
10803
|
+
function fingerprint(files, matches) {
|
|
10804
|
+
const entries = Object.entries(files).filter(([path]) => matches(path)).sort(([left], [right]) => left.localeCompare(right));
|
|
10805
|
+
if (entries.length === 0) return null;
|
|
10806
|
+
return sha256(entries.map(([path, hash]) => `${path}:${hash}`).join("\n"));
|
|
10395
10807
|
}
|
|
10396
|
-
function
|
|
10397
|
-
const
|
|
10398
|
-
|
|
10808
|
+
async function snapshotContract(bundleDir) {
|
|
10809
|
+
const root = contractRoot(bundleDir);
|
|
10810
|
+
const paths = /* @__PURE__ */ new Set();
|
|
10811
|
+
for (const name of ["PRD.md", "traceability.md"]) {
|
|
10812
|
+
try {
|
|
10813
|
+
const content = await readFile3(join4(root, name));
|
|
10814
|
+
if (content.byteLength > 0) paths.add(name);
|
|
10815
|
+
} catch {
|
|
10816
|
+
}
|
|
10817
|
+
}
|
|
10818
|
+
for (const directory of ["specs", "tasks"]) {
|
|
10819
|
+
for (const path of await walkMarkdown(root, directory)) paths.add(path);
|
|
10820
|
+
}
|
|
10821
|
+
for (const path of await walkMarkdown(bundleDir, "docs")) {
|
|
10822
|
+
if (!path.startsWith("docs/00-contract/")) paths.add(path);
|
|
10823
|
+
}
|
|
10824
|
+
const files = {};
|
|
10825
|
+
for (const path of [...paths].sort()) {
|
|
10826
|
+
try {
|
|
10827
|
+
files[path] = sha256(await readFile3(join4(root, path)));
|
|
10828
|
+
} catch {
|
|
10829
|
+
}
|
|
10830
|
+
}
|
|
10831
|
+
const tasksMatch = (path) => path.startsWith("tasks/") || path === "traceability.md";
|
|
10832
|
+
return {
|
|
10833
|
+
prd: files["PRD.md"] ?? null,
|
|
10834
|
+
specs: fingerprint(files, (path) => path.startsWith("specs/")),
|
|
10835
|
+
tasks: fingerprint(files, tasksMatch),
|
|
10836
|
+
docs: fingerprint(files, (path) => path.startsWith("docs/")),
|
|
10837
|
+
files
|
|
10838
|
+
};
|
|
10399
10839
|
}
|
|
10400
|
-
function
|
|
10401
|
-
return
|
|
10840
|
+
function hasContractArtifacts(snapshot) {
|
|
10841
|
+
return snapshot.prd !== null || snapshot.specs !== null;
|
|
10402
10842
|
}
|
|
10403
|
-
function
|
|
10404
|
-
|
|
10843
|
+
function freshDerivation(snapshot, now = /* @__PURE__ */ new Date()) {
|
|
10844
|
+
const at = now.toISOString();
|
|
10845
|
+
const prdHash = snapshot.prd;
|
|
10846
|
+
return {
|
|
10847
|
+
specs: prdHash !== null && snapshot.specs !== null ? { prdHash, recordedAt: at } : null,
|
|
10848
|
+
tasks: prdHash !== null && snapshot.tasks !== null ? {
|
|
10849
|
+
prdHash,
|
|
10850
|
+
...snapshot.specs === null ? {} : { specsFingerprint: snapshot.specs },
|
|
10851
|
+
recordedAt: at
|
|
10852
|
+
} : null
|
|
10853
|
+
};
|
|
10405
10854
|
}
|
|
10406
|
-
function
|
|
10407
|
-
|
|
10855
|
+
function computeStaleness(derivation, snapshot) {
|
|
10856
|
+
const specsStale = snapshot.specs !== null && snapshot.prd !== null && derivation.specs !== null && derivation.specs.prdHash !== snapshot.prd;
|
|
10857
|
+
const prdMoved = snapshot.prd !== null && derivation.tasks !== null && derivation.tasks.prdHash !== snapshot.prd;
|
|
10858
|
+
const specsMoved = snapshot.specs !== null && derivation.tasks?.specsFingerprint != null && derivation.tasks.specsFingerprint !== snapshot.specs;
|
|
10859
|
+
const tasksStale = snapshot.tasks !== null && derivation.tasks !== null && (prdMoved || specsMoved);
|
|
10860
|
+
return { specsStale, tasksStale, stale: specsStale || tasksStale };
|
|
10861
|
+
}
|
|
10862
|
+
function changedSince(current, previous) {
|
|
10863
|
+
const prd = previous === null ? current.prd !== null : current.prd !== previous.prd;
|
|
10864
|
+
const specs = previous === null ? current.specs !== null : current.specs !== previous.specs;
|
|
10865
|
+
const tasks = previous === null ? current.tasks !== null : current.tasks !== previous.tasks;
|
|
10866
|
+
const docs = previous === null ? current.docs !== null : current.docs !== previous.docs;
|
|
10867
|
+
return { prd, specs, tasks, docs, any: prd || specs || tasks || docs };
|
|
10868
|
+
}
|
|
10869
|
+
function serverAsSnapshot(server) {
|
|
10870
|
+
return {
|
|
10871
|
+
prd: server.prd,
|
|
10872
|
+
specs: server.specs,
|
|
10873
|
+
tasks: server.tasks,
|
|
10874
|
+
docs: server.docs,
|
|
10875
|
+
files: {}
|
|
10876
|
+
};
|
|
10408
10877
|
}
|
|
10409
|
-
function
|
|
10410
|
-
|
|
10411
|
-
|
|
10412
|
-
|
|
10413
|
-
|
|
10878
|
+
function objectValue(value) {
|
|
10879
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
10880
|
+
}
|
|
10881
|
+
function parseStage(value) {
|
|
10882
|
+
const record = objectValue(value);
|
|
10883
|
+
if (record === null || typeof record.prdHash !== "string" || record.prdHash.length === 0) {
|
|
10884
|
+
return null;
|
|
10885
|
+
}
|
|
10414
10886
|
return {
|
|
10415
|
-
|
|
10416
|
-
|
|
10417
|
-
|
|
10887
|
+
prdHash: record.prdHash,
|
|
10888
|
+
...typeof record.specsFingerprint === "string" ? { specsFingerprint: record.specsFingerprint } : {},
|
|
10889
|
+
recordedAt: typeof record.recordedAt === "string" ? record.recordedAt : ""
|
|
10418
10890
|
};
|
|
10419
10891
|
}
|
|
10420
|
-
|
|
10892
|
+
function parseDerivation(value) {
|
|
10893
|
+
const record = objectValue(value);
|
|
10894
|
+
if (record === null) return null;
|
|
10895
|
+
return { specs: parseStage(record.specs), tasks: parseStage(record.tasks) };
|
|
10896
|
+
}
|
|
10897
|
+
async function readContractLedger(bundleDir) {
|
|
10421
10898
|
let raw;
|
|
10422
10899
|
try {
|
|
10423
|
-
raw = await readFile3(
|
|
10424
|
-
} catch
|
|
10425
|
-
|
|
10426
|
-
throw error;
|
|
10900
|
+
raw = await readFile3(join4(bundleDir, CONTRACT_LEDGER_PATH), "utf8");
|
|
10901
|
+
} catch {
|
|
10902
|
+
return null;
|
|
10427
10903
|
}
|
|
10904
|
+
let parsed;
|
|
10428
10905
|
try {
|
|
10429
|
-
|
|
10906
|
+
parsed = JSON.parse(raw);
|
|
10430
10907
|
} catch {
|
|
10431
10908
|
return null;
|
|
10432
10909
|
}
|
|
10433
|
-
|
|
10434
|
-
|
|
10435
|
-
const
|
|
10436
|
-
if (
|
|
10437
|
-
|
|
10438
|
-
const
|
|
10439
|
-
|
|
10440
|
-
|
|
10441
|
-
|
|
10442
|
-
|
|
10443
|
-
|
|
10444
|
-
|
|
10445
|
-
|
|
10446
|
-
|
|
10447
|
-
|
|
10448
|
-
encoding: "utf8",
|
|
10449
|
-
mode: 384
|
|
10910
|
+
const record = objectValue(parsed);
|
|
10911
|
+
if (record === null || record.schemaVersion !== 1) return null;
|
|
10912
|
+
const local = objectValue(record.local);
|
|
10913
|
+
if (local === null) return null;
|
|
10914
|
+
const files = objectValue(local.files) ?? {};
|
|
10915
|
+
const normalizeSnapshot = (value) => ({
|
|
10916
|
+
prd: typeof value.prd === "string" ? value.prd : null,
|
|
10917
|
+
specs: typeof value.specs === "string" ? value.specs : null,
|
|
10918
|
+
tasks: typeof value.tasks === "string" ? value.tasks : null,
|
|
10919
|
+
docs: typeof value.docs === "string" ? value.docs : null,
|
|
10920
|
+
files: Object.fromEntries(
|
|
10921
|
+
Object.entries(files).filter(
|
|
10922
|
+
(entry) => typeof entry[1] === "string"
|
|
10923
|
+
)
|
|
10924
|
+
)
|
|
10450
10925
|
});
|
|
10451
|
-
|
|
10926
|
+
const serverRecord = objectValue(record.server);
|
|
10927
|
+
const server = serverRecord === null ? null : {
|
|
10928
|
+
prd: typeof serverRecord.prd === "string" ? serverRecord.prd : null,
|
|
10929
|
+
specs: typeof serverRecord.specs === "string" ? serverRecord.specs : null,
|
|
10930
|
+
tasks: typeof serverRecord.tasks === "string" ? serverRecord.tasks : null,
|
|
10931
|
+
docs: typeof serverRecord.docs === "string" ? serverRecord.docs : null,
|
|
10932
|
+
derivation: parseDerivation(serverRecord.derivation)
|
|
10933
|
+
};
|
|
10934
|
+
return {
|
|
10935
|
+
schemaVersion: 1,
|
|
10936
|
+
at: typeof record.at === "string" ? record.at : "",
|
|
10937
|
+
local: normalizeSnapshot(local),
|
|
10938
|
+
server,
|
|
10939
|
+
derivation: parseDerivation(record.derivation) ?? { specs: null, tasks: null }
|
|
10940
|
+
};
|
|
10452
10941
|
}
|
|
10453
|
-
async function
|
|
10454
|
-
const
|
|
10455
|
-
|
|
10456
|
-
|
|
10457
|
-
|
|
10458
|
-
return removed || removedLegacy;
|
|
10942
|
+
async function writeContractLedger(bundleDir, ledger) {
|
|
10943
|
+
const target = join4(bundleDir, CONTRACT_LEDGER_PATH);
|
|
10944
|
+
await mkdir2(dirname2(target), { recursive: true });
|
|
10945
|
+
await writeFile2(target, `${JSON.stringify(ledger, null, 2)}
|
|
10946
|
+
`, "utf8");
|
|
10459
10947
|
}
|
|
10460
|
-
|
|
10948
|
+
function buildContractLedger(local, server, derivation, now = /* @__PURE__ */ new Date()) {
|
|
10949
|
+
return {
|
|
10950
|
+
schemaVersion: 1,
|
|
10951
|
+
at: now.toISOString(),
|
|
10952
|
+
local,
|
|
10953
|
+
server,
|
|
10954
|
+
derivation: derivation ?? server?.derivation ?? freshDerivation(local, now)
|
|
10955
|
+
};
|
|
10956
|
+
}
|
|
10957
|
+
async function readApproval(bundleDir) {
|
|
10958
|
+
let raw;
|
|
10461
10959
|
try {
|
|
10462
|
-
await
|
|
10463
|
-
|
|
10464
|
-
|
|
10465
|
-
if (isMissingFile(error)) return false;
|
|
10466
|
-
throw error;
|
|
10960
|
+
raw = await readFile3(join4(bundleDir, APPROVALS_PATH), "utf8");
|
|
10961
|
+
} catch {
|
|
10962
|
+
return null;
|
|
10467
10963
|
}
|
|
10468
|
-
|
|
10469
|
-
|
|
10470
|
-
|
|
10471
|
-
|
|
10472
|
-
|
|
10473
|
-
|
|
10474
|
-
const
|
|
10964
|
+
let parsed;
|
|
10965
|
+
try {
|
|
10966
|
+
parsed = JSON.parse(raw);
|
|
10967
|
+
} catch {
|
|
10968
|
+
return null;
|
|
10969
|
+
}
|
|
10970
|
+
const record = objectValue(parsed);
|
|
10971
|
+
if (record === null || record.schemaVersion !== 1) return null;
|
|
10972
|
+
const prd = objectValue(record.prd);
|
|
10475
10973
|
return {
|
|
10476
|
-
|
|
10477
|
-
|
|
10478
|
-
|
|
10479
|
-
|
|
10480
|
-
|
|
10481
|
-
|
|
10482
|
-
uiQuality: parseUiQuality(execution.uiQuality ?? value.uiQuality),
|
|
10483
|
-
autoMode: parseAutoMode(execution.autoMode ?? value.autoMode)
|
|
10484
|
-
}
|
|
10974
|
+
schemaVersion: 1,
|
|
10975
|
+
prd: prd !== null && typeof prd.hash === "string" ? {
|
|
10976
|
+
hash: prd.hash,
|
|
10977
|
+
at: typeof prd.at === "string" ? prd.at : "",
|
|
10978
|
+
...typeof prd.note === "string" ? { note: prd.note } : {}
|
|
10979
|
+
} : null
|
|
10485
10980
|
};
|
|
10486
10981
|
}
|
|
10487
|
-
function
|
|
10488
|
-
|
|
10489
|
-
|
|
10490
|
-
|
|
10491
|
-
|
|
10492
|
-
throw new Error(`Project link execution.uiQuality tidak valid: ${String(value)}`);
|
|
10493
|
-
}
|
|
10494
|
-
function parseAutoMode(value) {
|
|
10495
|
-
if (value === void 0 || value === null) return false;
|
|
10496
|
-
if (typeof value === "boolean") return value;
|
|
10497
|
-
if (value === "true" || value === "1" || value === "yes") return true;
|
|
10498
|
-
if (value === "false" || value === "0" || value === "no") return false;
|
|
10499
|
-
throw new Error(`Project link execution.autoMode tidak valid: ${String(value)}`);
|
|
10500
|
-
}
|
|
10501
|
-
async function readAutoMode(bundleDir) {
|
|
10502
|
-
const link = await readProjectLink(resolve2(bundleDir));
|
|
10503
|
-
return link?.execution.autoMode ?? false;
|
|
10504
|
-
}
|
|
10505
|
-
async function writeAutoMode(bundleDir, enabled) {
|
|
10506
|
-
const link = await readProjectLink(resolve2(bundleDir));
|
|
10507
|
-
if (link === null) throw new Error("Belum ada project link. Jalankan `jioogen link` dulu.");
|
|
10508
|
-
await writeProjectLink(resolve2(bundleDir), {
|
|
10509
|
-
projectId: link.projectId,
|
|
10510
|
-
apiUrl: link.apiUrl,
|
|
10511
|
-
taskMode: link.taskMode,
|
|
10512
|
-
execution: { uiQuality: link.execution.uiQuality, autoMode: enabled }
|
|
10513
|
-
});
|
|
10514
|
-
}
|
|
10515
|
-
function parseTaskMode(value) {
|
|
10516
|
-
if (value === void 0) return DEFAULT_TASK_MODE;
|
|
10517
|
-
const parsed = TaskModeSchema.safeParse(value);
|
|
10518
|
-
if (!parsed.success) {
|
|
10519
|
-
throw new Error(`Project link taskMode tidak valid: ${String(value)}`);
|
|
10520
|
-
}
|
|
10521
|
-
return parsed.data;
|
|
10522
|
-
}
|
|
10523
|
-
async function readProjectLink(bundleDir) {
|
|
10524
|
-
for (const directoryName of [PROJECT_DIR, LEGACY_PROJECT_DIR]) {
|
|
10525
|
-
const candidate = join3(bundleDir, directoryName, PROJECT_FILE);
|
|
10526
|
-
let raw = null;
|
|
10527
|
-
try {
|
|
10528
|
-
raw = await readFile3(candidate, "utf8");
|
|
10529
|
-
} catch (error) {
|
|
10530
|
-
if (!isMissingFile(error)) throw error;
|
|
10531
|
-
}
|
|
10532
|
-
if (raw === null) continue;
|
|
10533
|
-
let parsed;
|
|
10534
|
-
try {
|
|
10535
|
-
parsed = JSON.parse(raw);
|
|
10536
|
-
} catch {
|
|
10537
|
-
throw new Error(`Project link is not valid JSON: ${candidate}`);
|
|
10538
|
-
}
|
|
10539
|
-
const link = parseProjectLink(parsed, bundleDir);
|
|
10540
|
-
if (link === null) throw new Error(`Project link is invalid: ${candidate}`);
|
|
10541
|
-
return link;
|
|
10542
|
-
}
|
|
10543
|
-
return null;
|
|
10544
|
-
}
|
|
10545
|
-
async function findProjectLink(startDir) {
|
|
10546
|
-
let directory = resolve2(startDir);
|
|
10547
|
-
for (; ; ) {
|
|
10548
|
-
const link = await readProjectLink(directory);
|
|
10549
|
-
if (link !== null) return link;
|
|
10550
|
-
const parent = dirname2(directory);
|
|
10551
|
-
if (parent === directory) return null;
|
|
10552
|
-
directory = parent;
|
|
10553
|
-
}
|
|
10554
|
-
}
|
|
10555
|
-
async function writeProjectLink(bundleDir, link) {
|
|
10556
|
-
const directory = join3(resolve2(bundleDir), PROJECT_DIR);
|
|
10557
|
-
await mkdir2(directory, { recursive: true });
|
|
10558
|
-
await writeFile2(
|
|
10559
|
-
join3(directory, PROJECT_FILE),
|
|
10560
|
-
`${JSON.stringify(
|
|
10561
|
-
{
|
|
10562
|
-
projectId: link.projectId,
|
|
10563
|
-
apiUrl: link.apiUrl,
|
|
10564
|
-
taskMode: link.taskMode ?? DEFAULT_TASK_MODE,
|
|
10565
|
-
execution: {
|
|
10566
|
-
uiQuality: link.execution?.uiQuality ?? DEFAULT_UI_QUALITY,
|
|
10567
|
-
autoMode: link.execution?.autoMode ?? false
|
|
10568
|
-
}
|
|
10569
|
-
},
|
|
10570
|
-
null,
|
|
10571
|
-
2
|
|
10572
|
-
)}
|
|
10573
|
-
`,
|
|
10574
|
-
"utf8"
|
|
10575
|
-
);
|
|
10982
|
+
async function writeApproval(bundleDir, record) {
|
|
10983
|
+
const target = join4(bundleDir, APPROVALS_PATH);
|
|
10984
|
+
await mkdir2(dirname2(target), { recursive: true });
|
|
10985
|
+
await writeFile2(target, `${JSON.stringify(record, null, 2)}
|
|
10986
|
+
`, "utf8");
|
|
10576
10987
|
}
|
|
10577
|
-
async function
|
|
10578
|
-
|
|
10579
|
-
|
|
10580
|
-
|
|
10581
|
-
|
|
10582
|
-
|
|
10583
|
-
|
|
10584
|
-
|
|
10585
|
-
if (!isMissingFile(error)) throw error;
|
|
10586
|
-
}
|
|
10988
|
+
async function appendApprovalNote(bundleDir, input) {
|
|
10989
|
+
const target = join4(bundleDir, ".jioogen", "custom", "knowledge", "approved-patches.md");
|
|
10990
|
+
await mkdir2(dirname2(target), { recursive: true });
|
|
10991
|
+
let existing = "";
|
|
10992
|
+
try {
|
|
10993
|
+
existing = await readFile3(target, "utf8");
|
|
10994
|
+
} catch {
|
|
10995
|
+
existing = "# Approved local patches\n";
|
|
10587
10996
|
}
|
|
10588
|
-
|
|
10589
|
-
|
|
10590
|
-
|
|
10591
|
-
|
|
10592
|
-
|
|
10593
|
-
}
|
|
10594
|
-
|
|
10595
|
-
|
|
10596
|
-
|
|
10597
|
-
}
|
|
10598
|
-
function isMissingFile(error) {
|
|
10599
|
-
return isRecord(error) && error.code === "ENOENT";
|
|
10997
|
+
const lines = [
|
|
10998
|
+
existing.trimEnd(),
|
|
10999
|
+
"",
|
|
11000
|
+
`## ${input.at} \u2014 PRD lokal disetujui untuk sinkron`,
|
|
11001
|
+
"",
|
|
11002
|
+
`- PRD.md: \`${input.prdHash}\``,
|
|
11003
|
+
...input.note === void 0 || input.note.length === 0 ? [] : [`- Catatan: ${input.note}`],
|
|
11004
|
+
""
|
|
11005
|
+
];
|
|
11006
|
+
await writeFile2(target, `${lines.join("\n")}`, "utf8");
|
|
10600
11007
|
}
|
|
10601
11008
|
|
|
10602
|
-
// src/doctor.ts
|
|
10603
|
-
import { readdir as readdir6, readFile as readFile8, rm as rm6, stat as stat5 } from "node:fs/promises";
|
|
10604
|
-
import { join as join8 } from "node:path";
|
|
10605
|
-
|
|
10606
11009
|
// src/drift.ts
|
|
10607
|
-
import { createHash } from "node:crypto";
|
|
10608
|
-
import { mkdir as mkdir4, readdir as
|
|
10609
|
-
import { dirname as dirname4, isAbsolute as isAbsolute2, join as
|
|
11010
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
11011
|
+
import { mkdir as mkdir4, readdir as readdir5, readFile as readFile6, rm as rm3, stat as stat3, writeFile as writeFile4 } from "node:fs/promises";
|
|
11012
|
+
import { dirname as dirname4, isAbsolute as isAbsolute2, join as join7 } from "node:path";
|
|
10610
11013
|
|
|
10611
11014
|
// src/tasks.ts
|
|
10612
|
-
import { readdirSync, readFileSync } from "node:fs";
|
|
10613
|
-
import { readdir as
|
|
10614
|
-
import { isAbsolute, join as
|
|
11015
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
11016
|
+
import { readdir as readdir4, readFile as readFile5, stat as stat2 } from "node:fs/promises";
|
|
11017
|
+
import { isAbsolute, join as join6 } from "node:path";
|
|
10615
11018
|
|
|
10616
11019
|
// src/sidecar.ts
|
|
10617
11020
|
import { randomUUID } from "node:crypto";
|
|
10618
|
-
import { mkdir as mkdir3, open, readFile as readFile4, rename, rm as
|
|
10619
|
-
import { dirname as dirname3, join as
|
|
11021
|
+
import { mkdir as mkdir3, open, readFile as readFile4, rename, rm as rm2, stat, writeFile as writeFile3 } from "node:fs/promises";
|
|
11022
|
+
import { dirname as dirname3, join as join5 } from "node:path";
|
|
10620
11023
|
var LOCK_RETRY_MS = 25;
|
|
10621
11024
|
var LOCK_TIMEOUT_MS = 3e3;
|
|
10622
11025
|
var LOCK_STALE_MS = 1e4;
|
|
10623
11026
|
function sidecarPath(bundleDir) {
|
|
10624
|
-
return
|
|
11027
|
+
return join5(contractRoot(bundleDir), EXECUTION_SIDECAR_PATH);
|
|
10625
11028
|
}
|
|
10626
11029
|
function lockPath(bundleDir) {
|
|
10627
11030
|
return `${sidecarPath(bundleDir)}.lock`;
|
|
@@ -10656,7 +11059,7 @@ async function withStateLock(bundleDir, fn) {
|
|
|
10656
11059
|
} finally {
|
|
10657
11060
|
await handle.close().catch(() => {
|
|
10658
11061
|
});
|
|
10659
|
-
await
|
|
11062
|
+
await rm2(target, { force: true }).catch(() => {
|
|
10660
11063
|
});
|
|
10661
11064
|
}
|
|
10662
11065
|
}
|
|
@@ -10665,7 +11068,7 @@ async function readState(bundleDir) {
|
|
|
10665
11068
|
try {
|
|
10666
11069
|
raw = await readFile4(sidecarPath(bundleDir), "utf8");
|
|
10667
11070
|
} catch (error) {
|
|
10668
|
-
if (
|
|
11071
|
+
if (isMissingFile(error)) return null;
|
|
10669
11072
|
throw error;
|
|
10670
11073
|
}
|
|
10671
11074
|
let payload;
|
|
@@ -10837,7 +11240,7 @@ async function writeState(bundleDir, state) {
|
|
|
10837
11240
|
`, "utf8");
|
|
10838
11241
|
await rename(temp, target);
|
|
10839
11242
|
} catch (error) {
|
|
10840
|
-
await
|
|
11243
|
+
await rm2(temp, { force: true }).catch(() => {
|
|
10841
11244
|
});
|
|
10842
11245
|
throw error;
|
|
10843
11246
|
}
|
|
@@ -10846,10 +11249,10 @@ async function writeState(bundleDir, state) {
|
|
|
10846
11249
|
async function backupExecutionState(bundleDir) {
|
|
10847
11250
|
const current = await readState(bundleDir);
|
|
10848
11251
|
if (current === null) return null;
|
|
10849
|
-
const backupDir =
|
|
11252
|
+
const backupDir = join5(bundleDir, ".jioogen");
|
|
10850
11253
|
await mkdir3(backupDir, { recursive: true });
|
|
10851
|
-
const
|
|
10852
|
-
const backupFile =
|
|
11254
|
+
const timestamp2 = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
11255
|
+
const backupFile = join5(backupDir, `state.backup-${timestamp2}.json`);
|
|
10853
11256
|
await writeFile3(backupFile, `${JSON.stringify(current, null, 2)}
|
|
10854
11257
|
`, "utf8");
|
|
10855
11258
|
return backupFile;
|
|
@@ -10896,7 +11299,7 @@ function completionDefinitions(definitions) {
|
|
|
10896
11299
|
...definition.layer !== void 0 ? { layer: definition.layer } : {}
|
|
10897
11300
|
}));
|
|
10898
11301
|
}
|
|
10899
|
-
function
|
|
11302
|
+
function isMissingFile(error) {
|
|
10900
11303
|
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
10901
11304
|
}
|
|
10902
11305
|
function isLockBusy(error) {
|
|
@@ -10906,10 +11309,10 @@ async function removeStaleLock(target) {
|
|
|
10906
11309
|
try {
|
|
10907
11310
|
const info = await stat(target);
|
|
10908
11311
|
if (Date.now() - info.mtimeMs < LOCK_STALE_MS) return false;
|
|
10909
|
-
await
|
|
11312
|
+
await rm2(target, { force: true });
|
|
10910
11313
|
return true;
|
|
10911
11314
|
} catch (error) {
|
|
10912
|
-
if (
|
|
11315
|
+
if (isMissingFile(error)) return true;
|
|
10913
11316
|
throw error;
|
|
10914
11317
|
}
|
|
10915
11318
|
}
|
|
@@ -10980,12 +11383,12 @@ var LAYER_CHECKLISTS = {
|
|
|
10980
11383
|
]
|
|
10981
11384
|
};
|
|
10982
11385
|
async function loadTasks(bundleDir) {
|
|
10983
|
-
const tasksDir =
|
|
11386
|
+
const tasksDir = join6(contractRoot(bundleDir), "tasks");
|
|
10984
11387
|
let entries;
|
|
10985
11388
|
try {
|
|
10986
|
-
entries = await
|
|
11389
|
+
entries = await readdir4(tasksDir, { withFileTypes: true });
|
|
10987
11390
|
} catch (error) {
|
|
10988
|
-
if (
|
|
11391
|
+
if (isMissingFile2(error)) throw new Error(`Direktori tasks/ tidak ditemukan di ${bundleDir}`);
|
|
10989
11392
|
throw error;
|
|
10990
11393
|
}
|
|
10991
11394
|
const names = entries.filter(
|
|
@@ -10994,16 +11397,16 @@ async function loadTasks(bundleDir) {
|
|
|
10994
11397
|
const tasks = [];
|
|
10995
11398
|
if (names.length > 0) {
|
|
10996
11399
|
for (const name of names) {
|
|
10997
|
-
const content = await readFile5(
|
|
11400
|
+
const content = await readFile5(join6(tasksDir, name), "utf8");
|
|
10998
11401
|
tasks.push(parseSingleTask(name, content));
|
|
10999
11402
|
}
|
|
11000
11403
|
} else {
|
|
11001
|
-
const singlePath =
|
|
11404
|
+
const singlePath = join6(tasksDir, "TASKS.md");
|
|
11002
11405
|
let content;
|
|
11003
11406
|
try {
|
|
11004
11407
|
content = await readFile5(singlePath, "utf8");
|
|
11005
11408
|
} catch (error) {
|
|
11006
|
-
if (
|
|
11409
|
+
if (isMissingFile2(error)) throw new Error(`Tidak ada berkas task di ${tasksDir}`);
|
|
11007
11410
|
throw error;
|
|
11008
11411
|
}
|
|
11009
11412
|
tasks.push(...parseSingleFile(content));
|
|
@@ -11072,7 +11475,7 @@ function renderActiveTask(task, context) {
|
|
|
11072
11475
|
"- Jangan pindah task, jangan mengerjakan task lain, jangan melebar ke file di luar targetFiles (file/direktori/glob).",
|
|
11073
11476
|
"- Jangan mengarang fitur/endpoint/kolom di luar PRD.md/specs/.",
|
|
11074
11477
|
"- Detail implementasi (pola, struktur file dalam scope, library yang sudah ada) milikmu; ikuti konvensi proyek.",
|
|
11075
|
-
"- Jangan mengubah PRD.md/specs/kontrak. Butuh perubahan
|
|
11478
|
+
"- Jangan mengubah PRD.md/specs/kontrak saat task berjalan. Butuh perubahan? Hentikan task, minta izin sekali, jalankan `npx jioogen approve` + `npx jioogen align`, lalu lanjut.",
|
|
11076
11479
|
"- Selesai: `npx jioogen task complete <ref>`, lalu `npx jioogen sync`."
|
|
11077
11480
|
);
|
|
11078
11481
|
const checklist = renderQualityChecklist(task.layer, context);
|
|
@@ -11089,6 +11492,8 @@ function renderActiveTask(task, context) {
|
|
|
11089
11492
|
if (preferencesBlock.length > 0) lines.push("", preferencesBlock);
|
|
11090
11493
|
const knowledgeBlock = buildCustomKnowledgeBlock(context.bundleDir);
|
|
11091
11494
|
if (knowledgeBlock.length > 0) lines.push("", knowledgeBlock);
|
|
11495
|
+
const docsMap = buildDocsMap(context.bundleDir);
|
|
11496
|
+
if (docsMap.length > 0) lines.push("", docsMap);
|
|
11092
11497
|
}
|
|
11093
11498
|
return lines.join("\n");
|
|
11094
11499
|
}
|
|
@@ -11229,7 +11634,7 @@ async function taskTargetFilesExist(bundleDir, task) {
|
|
|
11229
11634
|
if (cleaned.length === 0) continue;
|
|
11230
11635
|
const staticPart = cleaned.replace(/[*?[][\s\S]*$/, "").replace(/\/+$/, "");
|
|
11231
11636
|
const testPath = staticPart.length > 0 ? staticPart : cleaned;
|
|
11232
|
-
const fullPath = isAbsolute(testPath) ? testPath :
|
|
11637
|
+
const fullPath = isAbsolute(testPath) ? testPath : join6(bundleDir, testPath);
|
|
11233
11638
|
try {
|
|
11234
11639
|
await stat2(fullPath);
|
|
11235
11640
|
return true;
|
|
@@ -11370,24 +11775,30 @@ function isVerificationPlaceholder(value) {
|
|
|
11370
11775
|
var CUSTOM_PREFERENCES_HEADER = "## USER CUSTOM PREFERENCES & STACK (.jioogen/custom/)";
|
|
11371
11776
|
function buildCustomPreferencesBlock(bundleDir) {
|
|
11372
11777
|
const parts = [];
|
|
11373
|
-
const
|
|
11374
|
-
|
|
11375
|
-
|
|
11376
|
-
|
|
11377
|
-
|
|
11378
|
-
|
|
11379
|
-
|
|
11380
|
-
} catch {
|
|
11381
|
-
}
|
|
11382
|
-
const designFile = join5(bundleDir, ".jioogen", "custom", "design", "DESIGN.md");
|
|
11383
|
-
try {
|
|
11384
|
-
const designContent = readFileSync(designFile, "utf8").trim();
|
|
11385
|
-
if (designContent.length > 0) {
|
|
11386
|
-
parts.push(`### User Custom Design (.jioogen/custom/design/DESIGN.md)
|
|
11387
|
-
${designContent}`);
|
|
11778
|
+
const readFirst = (candidates) => {
|
|
11779
|
+
for (const relative3 of candidates) {
|
|
11780
|
+
try {
|
|
11781
|
+
const content = readFileSync2(join6(bundleDir, relative3), "utf8").trim();
|
|
11782
|
+
if (content.length > 0) return { path: relative3, content };
|
|
11783
|
+
} catch {
|
|
11784
|
+
}
|
|
11388
11785
|
}
|
|
11389
|
-
|
|
11390
|
-
}
|
|
11786
|
+
return null;
|
|
11787
|
+
};
|
|
11788
|
+
const stack = readFirst([
|
|
11789
|
+
".jioogen/custom/stack/STACK.md",
|
|
11790
|
+
"docs/03-architecture/STACK.md",
|
|
11791
|
+
"STACK.md"
|
|
11792
|
+
]);
|
|
11793
|
+
if (stack !== null) parts.push(`### User Custom Stack (${stack.path})
|
|
11794
|
+
${stack.content}`);
|
|
11795
|
+
const design = readFirst([
|
|
11796
|
+
".jioogen/custom/design/DESIGN.md",
|
|
11797
|
+
"docs/02-design/DESIGN.md",
|
|
11798
|
+
"DESIGN.md"
|
|
11799
|
+
]);
|
|
11800
|
+
if (design !== null) parts.push(`### User Custom Design (${design.path})
|
|
11801
|
+
${design.content}`);
|
|
11391
11802
|
if (parts.length === 0) return "";
|
|
11392
11803
|
return [
|
|
11393
11804
|
CUSTOM_PREFERENCES_HEADER,
|
|
@@ -11396,10 +11807,10 @@ ${designContent}`);
|
|
|
11396
11807
|
].join("\n\n");
|
|
11397
11808
|
}
|
|
11398
11809
|
function listCustomKnowledgeFiles(bundleDir) {
|
|
11399
|
-
const dir =
|
|
11810
|
+
const dir = join6(bundleDir, ".jioogen", "custom", "knowledge");
|
|
11400
11811
|
let entries;
|
|
11401
11812
|
try {
|
|
11402
|
-
entries =
|
|
11813
|
+
entries = readdirSync2(dir, { withFileTypes: true });
|
|
11403
11814
|
} catch {
|
|
11404
11815
|
return [];
|
|
11405
11816
|
}
|
|
@@ -11407,9 +11818,9 @@ function listCustomKnowledgeFiles(bundleDir) {
|
|
|
11407
11818
|
const result = [];
|
|
11408
11819
|
for (const name of names) {
|
|
11409
11820
|
if (result.length >= MAX_CUSTOM_KNOWLEDGE_FILES) break;
|
|
11410
|
-
const full =
|
|
11821
|
+
const full = join6(dir, name);
|
|
11411
11822
|
try {
|
|
11412
|
-
const content =
|
|
11823
|
+
const content = readFileSync2(full, "utf8");
|
|
11413
11824
|
if (content.trim().length === 0) continue;
|
|
11414
11825
|
} catch {
|
|
11415
11826
|
continue;
|
|
@@ -11418,22 +11829,69 @@ function listCustomKnowledgeFiles(bundleDir) {
|
|
|
11418
11829
|
}
|
|
11419
11830
|
return result.slice(0, MAX_CUSTOM_KNOWLEDGE_FILES);
|
|
11420
11831
|
}
|
|
11832
|
+
function buildDocsMap(bundleDir) {
|
|
11833
|
+
const contract = contractRoot(bundleDir);
|
|
11834
|
+
const entries = [];
|
|
11835
|
+
for (const name of ["PRD.md", "traceability.md"]) {
|
|
11836
|
+
try {
|
|
11837
|
+
if (readFileSync2(join6(contract, name), "utf8").trim().length > 0) entries.push(name);
|
|
11838
|
+
} catch {
|
|
11839
|
+
}
|
|
11840
|
+
}
|
|
11841
|
+
const collect = (root, prefix) => {
|
|
11842
|
+
let names;
|
|
11843
|
+
try {
|
|
11844
|
+
names = readdirSync2(join6(root, prefix));
|
|
11845
|
+
} catch {
|
|
11846
|
+
return;
|
|
11847
|
+
}
|
|
11848
|
+
for (const name of names.sort()) {
|
|
11849
|
+
const relative3 = `${prefix}/${name}`;
|
|
11850
|
+
try {
|
|
11851
|
+
if (readdirSync2(join6(root, relative3)).length >= 0) {
|
|
11852
|
+
if (relative3 === "docs/99-archive") continue;
|
|
11853
|
+
collect(root, relative3);
|
|
11854
|
+
continue;
|
|
11855
|
+
}
|
|
11856
|
+
} catch {
|
|
11857
|
+
}
|
|
11858
|
+
if (name.toLowerCase().endsWith(".md")) entries.push(relative3);
|
|
11859
|
+
}
|
|
11860
|
+
};
|
|
11861
|
+
collect(contract, "specs");
|
|
11862
|
+
collect(contract, "tasks");
|
|
11863
|
+
collect(bundleDir, "docs");
|
|
11864
|
+
const unique2 = [...new Set(entries)].filter((path) => !path.startsWith("docs/00-contract/"));
|
|
11865
|
+
if (unique2.length === 0) return "";
|
|
11866
|
+
const lines = [
|
|
11867
|
+
"## DOC MAP (baca path ini, jangan menebak)",
|
|
11868
|
+
"Kontrak fisik ada di docs/00-contract/; path virtualnya PRD.md, specs/, tasks/.",
|
|
11869
|
+
"Urutan: docs/00-contract/PRD.md \u2192 docs/01-product \u2192 docs/00-contract/specs \u2192 docs/02-design \u2192 docs/03-architecture \u2192 docs/04-domain \u2192 docs/00-contract/tasks \u2192 kode.",
|
|
11870
|
+
"Dokumen = niat; kode = kenyataan. Bila berbeda, tanyakan mana yang benar.",
|
|
11871
|
+
...unique2.slice(0, 40).map((path) => `- ${path}`)
|
|
11872
|
+
];
|
|
11873
|
+
if (unique2.length > 40)
|
|
11874
|
+
lines.push(`- \u2026 (${unique2.length - 40} dokumen lain; lihat docs/README.md)`);
|
|
11875
|
+
return lines.join("\n");
|
|
11876
|
+
}
|
|
11421
11877
|
function buildCustomKnowledgeBlock(bundleDir) {
|
|
11422
11878
|
const files = listCustomKnowledgeFiles(bundleDir);
|
|
11423
11879
|
if (files.length === 0) return "";
|
|
11424
11880
|
const lines = [
|
|
11425
11881
|
CUSTOM_KNOWLEDGE_HEADER,
|
|
11426
11882
|
...files.map((file) => `- ${file}`),
|
|
11427
|
-
"Baca file-file di atas sebagai konteks tambahan user sebelum coding."
|
|
11883
|
+
"Baca file-file di atas sebagai konteks tambahan user sebelum coding.",
|
|
11884
|
+
"Setiap pertanyaan ke user pakai bahasa manusia yang mudah: kalimat pendek, ya/tidak atau pilihan A/B, tanpa jargon teknis.",
|
|
11885
|
+
"Bila user menyetujui patch kontrak, jalankan `jioogen approve --note <alasan>` lalu ubah PRD.md; setelah itu `jioogen align` otomatis menurunkan specs dan tasks, memvalidasi, dan menyelaraskan web. Jangan edit specs/tasks manual dan jangan `jioogen pull --force`."
|
|
11428
11886
|
];
|
|
11429
11887
|
return lines.join("\n");
|
|
11430
11888
|
}
|
|
11431
|
-
function
|
|
11889
|
+
function isMissingFile2(error) {
|
|
11432
11890
|
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
11433
11891
|
}
|
|
11434
11892
|
|
|
11435
11893
|
// src/drift.ts
|
|
11436
|
-
var DRIFT_BASELINE_PATH =
|
|
11894
|
+
var DRIFT_BASELINE_PATH = join7("tasks", ".execution", "baseline.json");
|
|
11437
11895
|
var BASELINE_VERSION = 1;
|
|
11438
11896
|
var MAX_TARGET_FILES = 2e3;
|
|
11439
11897
|
var MAX_BUNDLE_FILE_BYTES = 1048576;
|
|
@@ -11461,7 +11919,10 @@ var IGNORED_TOP_FILES = /* @__PURE__ */ new Set(["AGENTS.md"]);
|
|
|
11461
11919
|
async function readAcknowledged(bundleDir) {
|
|
11462
11920
|
let raw;
|
|
11463
11921
|
try {
|
|
11464
|
-
raw = await readFile6(
|
|
11922
|
+
raw = await readFile6(
|
|
11923
|
+
join7(contractRoot(bundleDir), "tasks", ".execution", "acknowledged.json"),
|
|
11924
|
+
"utf8"
|
|
11925
|
+
);
|
|
11465
11926
|
} catch {
|
|
11466
11927
|
return null;
|
|
11467
11928
|
}
|
|
@@ -11492,14 +11953,14 @@ async function acknowledgeDrift(bundleDir, flags = {}, note, now = /* @__PURE__
|
|
|
11492
11953
|
};
|
|
11493
11954
|
const mergedNote = note ?? existing?.note;
|
|
11494
11955
|
if (mergedNote !== void 0) merged.note = mergedNote;
|
|
11495
|
-
const target =
|
|
11956
|
+
const target = join7(contractRoot(bundleDir), "tasks", ".execution", "acknowledged.json");
|
|
11496
11957
|
await mkdir4(dirname4(target), { recursive: true });
|
|
11497
11958
|
await writeFile4(target, `${JSON.stringify(merged, null, 2)}
|
|
11498
11959
|
`, "utf8");
|
|
11499
11960
|
return merged;
|
|
11500
11961
|
}
|
|
11501
11962
|
function baselinePath(bundleDir) {
|
|
11502
|
-
return
|
|
11963
|
+
return join7(contractRoot(bundleDir), DRIFT_BASELINE_PATH);
|
|
11503
11964
|
}
|
|
11504
11965
|
async function readBaseline(bundleDir) {
|
|
11505
11966
|
let raw;
|
|
@@ -11541,7 +12002,7 @@ async function writeBaseline(bundleDir, baseline) {
|
|
|
11541
12002
|
`, "utf8");
|
|
11542
12003
|
}
|
|
11543
12004
|
async function clearBaseline(bundleDir) {
|
|
11544
|
-
await
|
|
12005
|
+
await rm3(baselinePath(bundleDir), { force: true });
|
|
11545
12006
|
}
|
|
11546
12007
|
async function captureTaskBaseline(bundleDir, definition, now = /* @__PURE__ */ new Date()) {
|
|
11547
12008
|
const baseline = await readBaseline(bundleDir) ?? {
|
|
@@ -11591,7 +12052,7 @@ async function detectDrift(bundleDir, definitions, state, options = {}) {
|
|
|
11591
12052
|
findings.push({
|
|
11592
12053
|
code: "BUNDLE_DRIFT",
|
|
11593
12054
|
severity: bundleDriftAcknowledged ? "info" : "warn",
|
|
11594
|
-
message: "PRD.md/specs/tasks berubah di disk setelah baseline dibuat.
|
|
12055
|
+
message: "PRD.md/specs/tasks berubah di disk setelah baseline dibuat. Kalau disengaja, jalankan `jioogen align` (patch lokal disetujui) atau `jioogen drift --acknowledge`; kalau tidak, kembalikan file itu.",
|
|
11595
12056
|
files: []
|
|
11596
12057
|
});
|
|
11597
12058
|
}
|
|
@@ -11670,8 +12131,8 @@ async function targetHashes(bundleDir, patterns) {
|
|
|
11670
12131
|
}
|
|
11671
12132
|
const hashes = {};
|
|
11672
12133
|
for (const file of [...files].sort()) {
|
|
11673
|
-
const
|
|
11674
|
-
if (
|
|
12134
|
+
const fingerprint2 = await fingerprintRelative(bundleDir, file);
|
|
12135
|
+
if (fingerprint2 !== null) hashes[file] = fingerprint2;
|
|
11675
12136
|
}
|
|
11676
12137
|
return { hashes, truncated };
|
|
11677
12138
|
}
|
|
@@ -11679,7 +12140,7 @@ async function expandPattern(bundleDir, raw) {
|
|
|
11679
12140
|
const pattern = normalizePattern(raw);
|
|
11680
12141
|
if (pattern === null) return [];
|
|
11681
12142
|
if (!/[*?[]/.test(pattern)) {
|
|
11682
|
-
const info = await statMaybe(
|
|
12143
|
+
const info = await statMaybe(join7(bundleDir, pattern));
|
|
11683
12144
|
if (info === null) return [];
|
|
11684
12145
|
if (info.isDirectory()) {
|
|
11685
12146
|
return (await walk(bundleDir, pattern, MAX_TARGET_FILES)).files;
|
|
@@ -11736,11 +12197,11 @@ function globToRegExp(pattern) {
|
|
|
11736
12197
|
async function walk(bundleDir, start, limit) {
|
|
11737
12198
|
const files = [];
|
|
11738
12199
|
let truncated = false;
|
|
11739
|
-
const visit = async (
|
|
12200
|
+
const visit = async (relative3) => {
|
|
11740
12201
|
if (truncated) return;
|
|
11741
12202
|
let entries;
|
|
11742
12203
|
try {
|
|
11743
|
-
entries = await
|
|
12204
|
+
entries = await readdir5(relative3.length === 0 ? bundleDir : join7(bundleDir, relative3), {
|
|
11744
12205
|
withFileTypes: true
|
|
11745
12206
|
});
|
|
11746
12207
|
} catch {
|
|
@@ -11748,7 +12209,7 @@ async function walk(bundleDir, start, limit) {
|
|
|
11748
12209
|
}
|
|
11749
12210
|
entries.sort((left, right) => left.name.localeCompare(right.name));
|
|
11750
12211
|
for (const entry of entries) {
|
|
11751
|
-
const child =
|
|
12212
|
+
const child = relative3.length === 0 ? entry.name : `${relative3}/${entry.name}`;
|
|
11752
12213
|
if (entry.isDirectory()) {
|
|
11753
12214
|
if (IGNORED_DIRS.has(entry.name)) continue;
|
|
11754
12215
|
if (child === "tasks/.execution") continue;
|
|
@@ -11762,70 +12223,743 @@ async function walk(bundleDir, start, limit) {
|
|
|
11762
12223
|
}
|
|
11763
12224
|
}
|
|
11764
12225
|
};
|
|
11765
|
-
await visit(start);
|
|
11766
|
-
return { files, truncated };
|
|
11767
|
-
}
|
|
11768
|
-
async function fingerprintRelative(bundleDir,
|
|
11769
|
-
const info = await statMaybe(
|
|
11770
|
-
if (info === null || !info.isFile()) return null;
|
|
11771
|
-
return `${info.size}:${Math.trunc(info.mtimeMs)}`;
|
|
12226
|
+
await visit(start);
|
|
12227
|
+
return { files, truncated };
|
|
12228
|
+
}
|
|
12229
|
+
async function fingerprintRelative(bundleDir, relative3) {
|
|
12230
|
+
const info = await statMaybe(join7(bundleDir, relative3));
|
|
12231
|
+
if (info === null || !info.isFile()) return null;
|
|
12232
|
+
return `${info.size}:${Math.trunc(info.mtimeMs)}`;
|
|
12233
|
+
}
|
|
12234
|
+
async function hashRelative(bundleDir, relative3) {
|
|
12235
|
+
const info = await statMaybe(join7(bundleDir, relative3));
|
|
12236
|
+
if (info === null || !info.isFile()) return null;
|
|
12237
|
+
if (info.size > MAX_BUNDLE_FILE_BYTES) return `size:${info.size}`;
|
|
12238
|
+
try {
|
|
12239
|
+
const bytes = await readFile6(join7(bundleDir, relative3));
|
|
12240
|
+
return createHash2("sha256").update(bytes).digest("hex");
|
|
12241
|
+
} catch {
|
|
12242
|
+
return null;
|
|
12243
|
+
}
|
|
12244
|
+
}
|
|
12245
|
+
async function statMaybe(path) {
|
|
12246
|
+
try {
|
|
12247
|
+
return await stat3(path);
|
|
12248
|
+
} catch {
|
|
12249
|
+
return null;
|
|
12250
|
+
}
|
|
12251
|
+
}
|
|
12252
|
+
function diffHashes(before, after) {
|
|
12253
|
+
const changed = /* @__PURE__ */ new Set();
|
|
12254
|
+
for (const [path, hash] of Object.entries(before)) {
|
|
12255
|
+
if (after[path] !== hash) changed.add(path);
|
|
12256
|
+
}
|
|
12257
|
+
for (const path of Object.keys(after)) {
|
|
12258
|
+
if (!(path in before)) changed.add(path);
|
|
12259
|
+
}
|
|
12260
|
+
return [...changed].sort();
|
|
12261
|
+
}
|
|
12262
|
+
async function bundleHashOf(bundleDir) {
|
|
12263
|
+
const root = contractRoot(bundleDir);
|
|
12264
|
+
const files = [];
|
|
12265
|
+
for (const name of ["PRD.md", "traceability.md"]) {
|
|
12266
|
+
const info = await statMaybe(join7(root, name));
|
|
12267
|
+
if (info?.isFile()) files.push(name);
|
|
12268
|
+
}
|
|
12269
|
+
for (const directory of ["specs", "tasks"]) {
|
|
12270
|
+
const walked = await walk(root, directory, MAX_TARGET_FILES);
|
|
12271
|
+
for (const file of walked.files) {
|
|
12272
|
+
if (file.startsWith("tasks/.execution/")) continue;
|
|
12273
|
+
if (IGNORED_TOP_FILES.has(file)) continue;
|
|
12274
|
+
if (!file.toLowerCase().endsWith(".md")) continue;
|
|
12275
|
+
files.push(file);
|
|
12276
|
+
}
|
|
12277
|
+
}
|
|
12278
|
+
const lines = [];
|
|
12279
|
+
for (const file of files.sort()) {
|
|
12280
|
+
const hash = await hashRelative(root, file);
|
|
12281
|
+
if (hash !== null) lines.push(`${file}\0${hash}`);
|
|
12282
|
+
}
|
|
12283
|
+
return createHash2("sha256").update(lines.join("\n")).digest("hex");
|
|
12284
|
+
}
|
|
12285
|
+
|
|
12286
|
+
// src/align.ts
|
|
12287
|
+
function serverStateFromWorkspace(state) {
|
|
12288
|
+
const files = {};
|
|
12289
|
+
for (const artifact of state.artifacts) files[artifact.filePath] = artifact.sha256Hash;
|
|
12290
|
+
return {
|
|
12291
|
+
prd: state.derivation.prdHash ?? files["PRD.md"] ?? null,
|
|
12292
|
+
specs: fingerprint(files, (path) => path.startsWith("specs/")),
|
|
12293
|
+
tasks: fingerprint(files, (path) => path.startsWith("tasks/") || path === "traceability.md"),
|
|
12294
|
+
docs: fingerprint(files, (path) => path.startsWith("docs/")),
|
|
12295
|
+
derivation: parseDerivation(state.derivation)
|
|
12296
|
+
};
|
|
12297
|
+
}
|
|
12298
|
+
async function fetchServerState(deps) {
|
|
12299
|
+
if (deps.client === void 0 || deps.projectId === void 0) return null;
|
|
12300
|
+
try {
|
|
12301
|
+
return serverStateFromWorkspace(await deps.client.getWorkspaceArtifacts(deps.projectId));
|
|
12302
|
+
} catch {
|
|
12303
|
+
return null;
|
|
12304
|
+
}
|
|
12305
|
+
}
|
|
12306
|
+
async function mtime(bundleDir, relative3) {
|
|
12307
|
+
try {
|
|
12308
|
+
const target = isContractArtifactPath(relative3) ? resolveProjectPath(bundleDir, relative3) : join8(bundleDir, relative3);
|
|
12309
|
+
return (await stat4(target)).mtimeMs;
|
|
12310
|
+
} catch {
|
|
12311
|
+
return 0;
|
|
12312
|
+
}
|
|
12313
|
+
}
|
|
12314
|
+
async function mtimeDerivation(bundleDir, local) {
|
|
12315
|
+
if (local.prd === null) return freshDerivation(local);
|
|
12316
|
+
const prd = await mtime(bundleDir, "PRD.md");
|
|
12317
|
+
let specs = 0;
|
|
12318
|
+
let tasks = await mtime(bundleDir, "traceability.md");
|
|
12319
|
+
for (const path of Object.keys(local.files)) {
|
|
12320
|
+
const value = await mtime(bundleDir, path);
|
|
12321
|
+
if (path.startsWith("specs/")) specs = Math.max(specs, value);
|
|
12322
|
+
if (path.startsWith("tasks/")) tasks = Math.max(tasks, value);
|
|
12323
|
+
}
|
|
12324
|
+
const at = (/* @__PURE__ */ new Date()).toISOString();
|
|
12325
|
+
const staleMark = `mtime-stale-${at}`;
|
|
12326
|
+
return {
|
|
12327
|
+
specs: local.specs === null ? null : { prdHash: prd > specs ? staleMark : local.prd, recordedAt: at },
|
|
12328
|
+
tasks: local.tasks === null ? null : {
|
|
12329
|
+
prdHash: prd > tasks ? staleMark : local.prd,
|
|
12330
|
+
...local.specs === null ? {} : { specsFingerprint: specs > tasks ? staleMark : local.specs },
|
|
12331
|
+
recordedAt: at
|
|
12332
|
+
}
|
|
12333
|
+
};
|
|
12334
|
+
}
|
|
12335
|
+
async function loadLedger(bundleDir, local, server) {
|
|
12336
|
+
const existing = await readContractLedger(bundleDir);
|
|
12337
|
+
if (existing !== null) {
|
|
12338
|
+
return { ...existing, local };
|
|
12339
|
+
}
|
|
12340
|
+
const derivation = server?.derivation ?? await mtimeDerivation(bundleDir, local);
|
|
12341
|
+
return buildContractLedger(local, server, derivation);
|
|
12342
|
+
}
|
|
12343
|
+
function issuesForStage(check, stage) {
|
|
12344
|
+
return check.issues.filter((issue2) => issue2.owner === stage).map((issue2) => `${issue2.code}: ${issue2.where} \u2014 ${issue2.message}`);
|
|
12345
|
+
}
|
|
12346
|
+
function planAlignment(local, ledger, server, check) {
|
|
12347
|
+
const localChanges = changedSince(local, ledger.local);
|
|
12348
|
+
const previousServer = ledger.server === null ? null : serverAsSnapshot(ledger.server);
|
|
12349
|
+
const serverChanges = server === null || previousServer === null ? { prd: false, specs: false, tasks: false, docs: false, any: false } : changedSince(serverAsSnapshot(server), previousServer);
|
|
12350
|
+
if (localChanges.prd && serverChanges.prd && local.prd !== server?.prd) {
|
|
12351
|
+
return {
|
|
12352
|
+
kind: "conflict",
|
|
12353
|
+
message: "PRD berubah di lokal dan di web sekaligus. Pilih satu versi (lokal atau web) sebelum menyelaraskan."
|
|
12354
|
+
};
|
|
12355
|
+
}
|
|
12356
|
+
if (localChanges.any && serverChanges.any) {
|
|
12357
|
+
return {
|
|
12358
|
+
kind: "conflict",
|
|
12359
|
+
message: "Ada perubahan lokal dan perubahan web pada artefak kontrak. Selesaikan konflik versi dulu agar tidak ada yang tertimpa."
|
|
12360
|
+
};
|
|
12361
|
+
}
|
|
12362
|
+
const staleness = computeStaleness(ledger.derivation, local);
|
|
12363
|
+
if (staleness.specsStale) {
|
|
12364
|
+
return {
|
|
12365
|
+
kind: "author",
|
|
12366
|
+
stage: "specs",
|
|
12367
|
+
reason: "PRD berubah; specs masih dari versi PRD lama."
|
|
12368
|
+
};
|
|
12369
|
+
}
|
|
12370
|
+
if (staleness.tasksStale) {
|
|
12371
|
+
return {
|
|
12372
|
+
kind: "author",
|
|
12373
|
+
stage: "tasks",
|
|
12374
|
+
reason: "Specs/PRD berubah; tasks masih dari versi lama."
|
|
12375
|
+
};
|
|
12376
|
+
}
|
|
12377
|
+
if (serverChanges.any) {
|
|
12378
|
+
return { kind: "pull", reason: "Web punya perubahan kontrak yang belum ada di lokal." };
|
|
12379
|
+
}
|
|
12380
|
+
if (!check.ok) {
|
|
12381
|
+
const owners = new Set(check.issues.map((issue2) => issue2.owner));
|
|
12382
|
+
const repairable = owners.size > 0 && [...owners].every((owner) => owner === "specs" || owner === "tasks");
|
|
12383
|
+
if (repairable) {
|
|
12384
|
+
const stage = owners.has("tasks") ? "tasks" : "specs";
|
|
12385
|
+
if ((stage === "tasks" ? local.tasks : local.specs) !== null) {
|
|
12386
|
+
return {
|
|
12387
|
+
kind: "author",
|
|
12388
|
+
stage,
|
|
12389
|
+
reason: `Gate gagal pada artefak ${stage}; perbaiki turunannya.`
|
|
12390
|
+
};
|
|
12391
|
+
}
|
|
12392
|
+
}
|
|
12393
|
+
return { kind: "gate", check };
|
|
12394
|
+
}
|
|
12395
|
+
const pushChanges = server === null ? localChanges : changedSince(local, serverAsSnapshot(server));
|
|
12396
|
+
if (pushChanges.any) {
|
|
12397
|
+
return {
|
|
12398
|
+
kind: "push",
|
|
12399
|
+
stages: pushChanges,
|
|
12400
|
+
reason: "Kontrak lokal berbeda dari web dan sudah lolos gate; selaraskan ke web."
|
|
12401
|
+
};
|
|
12402
|
+
}
|
|
12403
|
+
return { kind: "clean" };
|
|
12404
|
+
}
|
|
12405
|
+
async function readContractFiles(bundleDir, snapshot, stages) {
|
|
12406
|
+
const files = [];
|
|
12407
|
+
for (const path of Object.keys(snapshot.files).sort()) {
|
|
12408
|
+
const isPrd = path === "PRD.md";
|
|
12409
|
+
const isSpecs = path.startsWith("specs/");
|
|
12410
|
+
const isTasks = path.startsWith("tasks/") || path === "traceability.md";
|
|
12411
|
+
const isDocs = path.startsWith("docs/");
|
|
12412
|
+
if (isPrd && !stages.prd) continue;
|
|
12413
|
+
if (isSpecs && !stages.specs) continue;
|
|
12414
|
+
if (isTasks && !stages.tasks) continue;
|
|
12415
|
+
if (isDocs && !stages.docs) continue;
|
|
12416
|
+
files.push({ path, content: await readFile7(resolveProjectPath(bundleDir, path), "utf8") });
|
|
12417
|
+
}
|
|
12418
|
+
try {
|
|
12419
|
+
const state = await readFile7(resolveProjectPath(bundleDir, EXECUTION_SIDECAR_PATH), "utf8");
|
|
12420
|
+
files.push({ path: EXECUTION_SIDECAR_PATH, content: state });
|
|
12421
|
+
} catch {
|
|
12422
|
+
}
|
|
12423
|
+
return files;
|
|
12424
|
+
}
|
|
12425
|
+
async function pushContract(deps, bundleDir, snapshot, stages, server) {
|
|
12426
|
+
if (deps.client === void 0 || deps.projectId === void 0) {
|
|
12427
|
+
return { ok: false, error: "Project belum terhubung ke API; sinkronisasi web dilewati." };
|
|
12428
|
+
}
|
|
12429
|
+
const approval = await readApproval(bundleDir);
|
|
12430
|
+
if (stages.prd && server !== null && server.prd !== snapshot.prd) {
|
|
12431
|
+
const confirmation = await deps.client.getPrdConfirmation(deps.projectId).catch(() => null);
|
|
12432
|
+
if (confirmation?.confirmation.confirmed === true) {
|
|
12433
|
+
if (approval?.prd?.hash !== snapshot.prd) {
|
|
12434
|
+
return {
|
|
12435
|
+
ok: false,
|
|
12436
|
+
needsApproval: true,
|
|
12437
|
+
error: "PRD lokal berbeda dari PRD yang dikonfirmasi di web."
|
|
12438
|
+
};
|
|
12439
|
+
}
|
|
12440
|
+
await deps.client.revokePrdConfirmation(
|
|
12441
|
+
deps.projectId,
|
|
12442
|
+
"PRD lokal disetujui user untuk diselaraskan."
|
|
12443
|
+
);
|
|
12444
|
+
}
|
|
12445
|
+
}
|
|
12446
|
+
await deps.client.ensureProjectLayout(deps.projectId).catch(() => null);
|
|
12447
|
+
const files = await readContractFiles(bundleDir, snapshot, stages);
|
|
12448
|
+
let result;
|
|
12449
|
+
try {
|
|
12450
|
+
result = await deps.client.postJson(projectPath(deps.projectId, "/artifacts"), {
|
|
12451
|
+
files
|
|
12452
|
+
});
|
|
12453
|
+
} catch (error) {
|
|
12454
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
12455
|
+
}
|
|
12456
|
+
const rejected = result.rejected ?? [];
|
|
12457
|
+
const prdRejected = rejected.find((entry) => entry.path === "PRD.md");
|
|
12458
|
+
if (prdRejected !== void 0) {
|
|
12459
|
+
return {
|
|
12460
|
+
ok: false,
|
|
12461
|
+
needsApproval: prdRejected.code === "PRD_CONFIRMED",
|
|
12462
|
+
error: prdRejected.reason
|
|
12463
|
+
};
|
|
12464
|
+
}
|
|
12465
|
+
const blocked = rejected.filter((entry) => entry.code !== "PRD_CONFIRMED");
|
|
12466
|
+
if (blocked.length > 0) {
|
|
12467
|
+
return {
|
|
12468
|
+
ok: false,
|
|
12469
|
+
error: blocked.map((entry) => `${entry.path}: ${entry.reason}`).join(" | ")
|
|
12470
|
+
};
|
|
12471
|
+
}
|
|
12472
|
+
return { ok: true };
|
|
12473
|
+
}
|
|
12474
|
+
async function pullContract(deps, bundleDir) {
|
|
12475
|
+
if (deps.client === void 0 || deps.projectId === void 0) {
|
|
12476
|
+
return "Project belum terhubung ke API; tidak bisa menarik versi web.";
|
|
12477
|
+
}
|
|
12478
|
+
try {
|
|
12479
|
+
const listing = await deps.client.getWorkspaceArtifacts(deps.projectId);
|
|
12480
|
+
const wanted = listing.files.filter(
|
|
12481
|
+
(path) => path === "PRD.md" || path === "traceability.md" || path.startsWith("specs/") || path.startsWith("tasks/") || path.startsWith("docs/")
|
|
12482
|
+
);
|
|
12483
|
+
const contents = /* @__PURE__ */ new Map();
|
|
12484
|
+
for (const path of wanted) {
|
|
12485
|
+
if (path.includes("..") || path.startsWith("/")) continue;
|
|
12486
|
+
const response = await deps.client.getJson(
|
|
12487
|
+
projectPath(deps.projectId, `/artifacts?path=${encodeURIComponent(path)}`)
|
|
12488
|
+
);
|
|
12489
|
+
contents.set(path, response.artifact.content);
|
|
12490
|
+
}
|
|
12491
|
+
const local = await snapshotContract(bundleDir);
|
|
12492
|
+
for (const path of Object.keys(local.files)) {
|
|
12493
|
+
if (path.startsWith("docs/")) continue;
|
|
12494
|
+
if (!contents.has(path)) await rm4(resolveProjectPath(bundleDir, path), { force: true });
|
|
12495
|
+
}
|
|
12496
|
+
for (const [path, content] of contents) {
|
|
12497
|
+
const target = resolveProjectPath(bundleDir, path);
|
|
12498
|
+
await mkdir5(join8(target, ".."), { recursive: true });
|
|
12499
|
+
await writeFile5(target, content, "utf8");
|
|
12500
|
+
}
|
|
12501
|
+
await clearBaseline(bundleDir).catch(() => {
|
|
12502
|
+
});
|
|
12503
|
+
return null;
|
|
12504
|
+
} catch (error) {
|
|
12505
|
+
return error instanceof Error ? error.message : String(error);
|
|
12506
|
+
}
|
|
12507
|
+
}
|
|
12508
|
+
function authoringPrompt(stage, issues) {
|
|
12509
|
+
const target = stage === "specs" ? "specs/" : "tasks/";
|
|
12510
|
+
const forbidden = stage === "specs" ? "PRD.md dan tasks/" : "PRD.md dan specs/";
|
|
12511
|
+
const lines = [
|
|
12512
|
+
`Stage authoring lokal: ${stage}.`,
|
|
12513
|
+
`Baca PRD.md${stage === "tasks" ? " dan specs/" : ""}, lalu tulis ulang ${target} agar selaras dengan kontrak terbaru.`,
|
|
12514
|
+
`Jangan mengubah ${forbidden}.`,
|
|
12515
|
+
"Gunakan skill authoring yang tersedia, jalankan self-check, dan pastikan hanya file di target yang ditulis."
|
|
12516
|
+
];
|
|
12517
|
+
if (issues.length > 0) {
|
|
12518
|
+
lines.push(
|
|
12519
|
+
"",
|
|
12520
|
+
"Temuan gate yang harus ditutup:",
|
|
12521
|
+
...issues.slice(0, 40).map((issue2) => `- ${issue2}`)
|
|
12522
|
+
);
|
|
12523
|
+
}
|
|
12524
|
+
return lines.join("\n");
|
|
12525
|
+
}
|
|
12526
|
+
function authoringTimeoutMs() {
|
|
12527
|
+
const raw = process.env.JIOOGEN_ALIGN_TIMEOUT_MS;
|
|
12528
|
+
const value = raw === void 0 ? Number.NaN : Number(raw);
|
|
12529
|
+
return Number.isFinite(value) && value > 0 ? value : 30 * 60 * 1e3;
|
|
12530
|
+
}
|
|
12531
|
+
async function runLocalAuthoring(stage, bundleDir, issues) {
|
|
12532
|
+
const configDir2 = join8(bundleDir, ".jioogen", "align");
|
|
12533
|
+
const configPath = join8(configDir2, "opencode.json");
|
|
12534
|
+
await mkdir5(configDir2, { recursive: true });
|
|
12535
|
+
const config = await buildAuthoringOpencodeConfig(bundledAuthoringPackDir());
|
|
12536
|
+
await writeFile5(configPath, `${JSON.stringify(config, null, 2)}
|
|
12537
|
+
`, "utf8");
|
|
12538
|
+
const bin = process.env.OPENCODE_BIN?.trim() || "opencode";
|
|
12539
|
+
const args = [
|
|
12540
|
+
"run",
|
|
12541
|
+
"--agent",
|
|
12542
|
+
"build",
|
|
12543
|
+
"--format",
|
|
12544
|
+
"json",
|
|
12545
|
+
"--dir",
|
|
12546
|
+
bundleDir,
|
|
12547
|
+
authoringPrompt(stage, issues)
|
|
12548
|
+
];
|
|
12549
|
+
return new Promise((resolve7) => {
|
|
12550
|
+
const child = spawn(bin, args, {
|
|
12551
|
+
cwd: bundleDir,
|
|
12552
|
+
env: {
|
|
12553
|
+
...process.env,
|
|
12554
|
+
OPENCODE_CONFIG: configPath,
|
|
12555
|
+
OPENCODE_DISABLE_CLAUDE_CODE: "1"
|
|
12556
|
+
},
|
|
12557
|
+
stdio: ["ignore", "ignore", "pipe"]
|
|
12558
|
+
});
|
|
12559
|
+
let stderr = "";
|
|
12560
|
+
let settled = false;
|
|
12561
|
+
const finish = (result) => {
|
|
12562
|
+
if (settled) return;
|
|
12563
|
+
settled = true;
|
|
12564
|
+
clearTimeout(timer);
|
|
12565
|
+
resolve7(result);
|
|
12566
|
+
};
|
|
12567
|
+
const timer = setTimeout(() => {
|
|
12568
|
+
child.kill("SIGTERM");
|
|
12569
|
+
setTimeout(() => child.kill("SIGKILL"), 5e3).unref();
|
|
12570
|
+
finish({ ok: false, error: `Authoring ${stage} melewati batas waktu.` });
|
|
12571
|
+
}, authoringTimeoutMs());
|
|
12572
|
+
timer.unref();
|
|
12573
|
+
child.stderr.on("data", (chunk) => {
|
|
12574
|
+
stderr = `${stderr}${chunk.toString()}`.slice(-4e3);
|
|
12575
|
+
});
|
|
12576
|
+
child.on("error", (error) => finish({ ok: false, error: error.message }));
|
|
12577
|
+
child.on("close", (code) => {
|
|
12578
|
+
finish(
|
|
12579
|
+
code === 0 ? { ok: true } : {
|
|
12580
|
+
ok: false,
|
|
12581
|
+
error: `Authoring ${stage} gagal (exit ${code ?? "?"}). ${stderr.trim()}`
|
|
12582
|
+
}
|
|
12583
|
+
);
|
|
12584
|
+
});
|
|
12585
|
+
});
|
|
12586
|
+
}
|
|
12587
|
+
async function alignBundle(bundleDir, deps = {}) {
|
|
12588
|
+
if (deps.client !== void 0 && deps.projectId !== void 0) {
|
|
12589
|
+
await deps.client.ensureProjectLayout(deps.projectId).catch(() => null);
|
|
12590
|
+
}
|
|
12591
|
+
const applied = [];
|
|
12592
|
+
let local = await snapshotContract(bundleDir);
|
|
12593
|
+
let server = await fetchServerState(deps);
|
|
12594
|
+
let ledger = await loadLedger(bundleDir, local, server);
|
|
12595
|
+
let check = await inspectBundle(bundleDir);
|
|
12596
|
+
const runAuthoring = deps.runAuthoring ?? runLocalAuthoring;
|
|
12597
|
+
const attempted = /* @__PURE__ */ new Set();
|
|
12598
|
+
for (let step = 0; step < 6; step += 1) {
|
|
12599
|
+
const plan = planAlignment(local, ledger, server, check);
|
|
12600
|
+
if (plan.kind === "clean") {
|
|
12601
|
+
await writeContractLedger(bundleDir, {
|
|
12602
|
+
...ledger,
|
|
12603
|
+
local,
|
|
12604
|
+
server,
|
|
12605
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
12606
|
+
});
|
|
12607
|
+
return { ok: true, applied, check, ledger };
|
|
12608
|
+
}
|
|
12609
|
+
if (plan.kind === "gate") {
|
|
12610
|
+
return { ok: false, applied, blocked: "Bundle belum lolos gate.", check, ledger };
|
|
12611
|
+
}
|
|
12612
|
+
if (plan.kind === "conflict") {
|
|
12613
|
+
return { ok: false, applied, blocked: plan.message, check, ledger };
|
|
12614
|
+
}
|
|
12615
|
+
if (plan.kind === "approve") {
|
|
12616
|
+
return { ok: false, applied, blocked: plan.reason, check, ledger };
|
|
12617
|
+
}
|
|
12618
|
+
if (plan.kind === "author") {
|
|
12619
|
+
if (attempted.has(plan.stage)) {
|
|
12620
|
+
return {
|
|
12621
|
+
ok: false,
|
|
12622
|
+
applied,
|
|
12623
|
+
blocked: `Gate masih gagal setelah authoring ${plan.stage}.`,
|
|
12624
|
+
check,
|
|
12625
|
+
ledger
|
|
12626
|
+
};
|
|
12627
|
+
}
|
|
12628
|
+
attempted.add(plan.stage);
|
|
12629
|
+
const result = await runAuthoring(plan.stage, bundleDir, issuesForStage(check, plan.stage));
|
|
12630
|
+
if (!result.ok) {
|
|
12631
|
+
return {
|
|
12632
|
+
ok: false,
|
|
12633
|
+
applied,
|
|
12634
|
+
blocked: result.error ?? `Authoring ${plan.stage} gagal.`,
|
|
12635
|
+
check,
|
|
12636
|
+
ledger
|
|
12637
|
+
};
|
|
12638
|
+
}
|
|
12639
|
+
applied.push(`author:${plan.stage}`);
|
|
12640
|
+
local = await snapshotContract(bundleDir);
|
|
12641
|
+
const at = (/* @__PURE__ */ new Date()).toISOString();
|
|
12642
|
+
ledger = {
|
|
12643
|
+
...ledger,
|
|
12644
|
+
local,
|
|
12645
|
+
derivation: plan.stage === "specs" ? {
|
|
12646
|
+
...ledger.derivation,
|
|
12647
|
+
specs: local.prd === null ? null : { prdHash: local.prd, recordedAt: at }
|
|
12648
|
+
} : {
|
|
12649
|
+
...ledger.derivation,
|
|
12650
|
+
tasks: local.prd === null || local.tasks === null ? null : {
|
|
12651
|
+
prdHash: local.prd,
|
|
12652
|
+
...local.specs === null ? {} : { specsFingerprint: local.specs },
|
|
12653
|
+
recordedAt: at
|
|
12654
|
+
}
|
|
12655
|
+
}
|
|
12656
|
+
};
|
|
12657
|
+
await writeContractLedger(bundleDir, ledger);
|
|
12658
|
+
check = await inspectBundle(bundleDir);
|
|
12659
|
+
continue;
|
|
12660
|
+
}
|
|
12661
|
+
if (plan.kind === "pull") {
|
|
12662
|
+
const error = await pullContract(deps, bundleDir);
|
|
12663
|
+
if (error !== null) {
|
|
12664
|
+
return { ok: false, applied, blocked: error, check, ledger };
|
|
12665
|
+
}
|
|
12666
|
+
applied.push("pull");
|
|
12667
|
+
local = await snapshotContract(bundleDir);
|
|
12668
|
+
server = await fetchServerState(deps);
|
|
12669
|
+
ledger = await loadLedger(bundleDir, local, server);
|
|
12670
|
+
await writeContractLedger(bundleDir, ledger);
|
|
12671
|
+
check = await inspectBundle(bundleDir);
|
|
12672
|
+
continue;
|
|
12673
|
+
}
|
|
12674
|
+
if (plan.kind === "push") {
|
|
12675
|
+
const approval = await readApproval(bundleDir);
|
|
12676
|
+
if (plan.stages.prd && server !== null && server.prd !== local.prd && approval?.prd?.hash !== local.prd) {
|
|
12677
|
+
return {
|
|
12678
|
+
ok: false,
|
|
12679
|
+
applied,
|
|
12680
|
+
blocked: "PRD lokal berubah. Boleh saya kirim versi lokal ke web? (ya/tidak)",
|
|
12681
|
+
check,
|
|
12682
|
+
ledger
|
|
12683
|
+
};
|
|
12684
|
+
}
|
|
12685
|
+
const result = await pushContract(deps, bundleDir, local, plan.stages, server);
|
|
12686
|
+
if (!result.ok) {
|
|
12687
|
+
return {
|
|
12688
|
+
ok: false,
|
|
12689
|
+
applied,
|
|
12690
|
+
blocked: result.needsApproval === true ? "PRD lokal berubah. Boleh saya kirim versi lokal ke web? (ya/tidak)" : result.error ?? "Sinkronisasi web gagal.",
|
|
12691
|
+
check,
|
|
12692
|
+
ledger
|
|
12693
|
+
};
|
|
12694
|
+
}
|
|
12695
|
+
applied.push("push");
|
|
12696
|
+
server = await fetchServerState(deps);
|
|
12697
|
+
ledger = { ...ledger, local, server, at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
12698
|
+
}
|
|
12699
|
+
}
|
|
12700
|
+
return {
|
|
12701
|
+
ok: false,
|
|
12702
|
+
applied,
|
|
12703
|
+
blocked: "Penyelarasan tidak selesai dalam batas langkah.",
|
|
12704
|
+
check,
|
|
12705
|
+
ledger
|
|
12706
|
+
};
|
|
12707
|
+
}
|
|
12708
|
+
function formatAlign(result) {
|
|
12709
|
+
const lines = [];
|
|
12710
|
+
if (result.ok) {
|
|
12711
|
+
lines.push("\u2714 Kontrak selaras.");
|
|
12712
|
+
} else {
|
|
12713
|
+
lines.push(`\u2716 Kontrak belum selaras: ${result.blocked ?? "tidak diketahui"}`);
|
|
12714
|
+
}
|
|
12715
|
+
if (result.applied.length > 0) lines.push(` Tindakan: ${result.applied.join(", ")}`);
|
|
12716
|
+
if (result.check.issueCount > 0) {
|
|
12717
|
+
lines.push(` Gate: ${result.check.issueCount} isu.`);
|
|
12718
|
+
for (const issue2 of result.check.issues.slice(0, 8)) {
|
|
12719
|
+
lines.push(` - ${issue2.code} ${issue2.where}: ${issue2.message}`);
|
|
12720
|
+
}
|
|
12721
|
+
}
|
|
12722
|
+
return lines.join("\n");
|
|
12723
|
+
}
|
|
12724
|
+
|
|
12725
|
+
// src/config.ts
|
|
12726
|
+
import { chmod, mkdir as mkdir6, readFile as readFile8, rm as rm5, writeFile as writeFile6 } from "node:fs/promises";
|
|
12727
|
+
import { homedir } from "node:os";
|
|
12728
|
+
import { dirname as dirname5, join as join9, resolve as resolve2 } from "node:path";
|
|
12729
|
+
|
|
12730
|
+
// src/types.ts
|
|
12731
|
+
var UI_QUALITY_MODES = ["auto", "on", "off"];
|
|
12732
|
+
|
|
12733
|
+
// src/config.ts
|
|
12734
|
+
var DEFAULT_UI_QUALITY = "auto";
|
|
12735
|
+
var CONFIG_DIR_ENV = "JIOOGEN_CONFIG_DIR";
|
|
12736
|
+
var LEGACY_CONFIG_DIR_ENV = "JIOOCODE_CONFIG_DIR";
|
|
12737
|
+
var CREDENTIALS_FILE = "credentials.json";
|
|
12738
|
+
var PROJECT_DIR = ".jioogen";
|
|
12739
|
+
var LEGACY_PROJECT_DIR = ".jioocode";
|
|
12740
|
+
var PROJECT_FILE = "project.json";
|
|
12741
|
+
function envValue(name) {
|
|
12742
|
+
const value = process.env[name]?.trim();
|
|
12743
|
+
return value !== void 0 && value.length > 0 ? value : void 0;
|
|
12744
|
+
}
|
|
12745
|
+
function configDirOverride() {
|
|
12746
|
+
return envValue(CONFIG_DIR_ENV) ?? envValue(LEGACY_CONFIG_DIR_ENV);
|
|
12747
|
+
}
|
|
12748
|
+
function configDir() {
|
|
12749
|
+
const override = configDirOverride();
|
|
12750
|
+
return override !== void 0 ? resolve2(override) : join9(homedir(), ".config", "jioogen");
|
|
12751
|
+
}
|
|
12752
|
+
function legacyConfigDir() {
|
|
12753
|
+
return join9(homedir(), ".config", "jioocode");
|
|
12754
|
+
}
|
|
12755
|
+
function credentialsPath() {
|
|
12756
|
+
return join9(configDir(), CREDENTIALS_FILE);
|
|
12757
|
+
}
|
|
12758
|
+
function isRecord(value) {
|
|
12759
|
+
return typeof value === "object" && value !== null;
|
|
12760
|
+
}
|
|
12761
|
+
function parseCredentials(value) {
|
|
12762
|
+
if (!isRecord(value)) return null;
|
|
12763
|
+
const { apiUrl, cookie, savedAt } = value;
|
|
12764
|
+
if (typeof apiUrl !== "string" || apiUrl.length === 0) return null;
|
|
12765
|
+
if (typeof cookie !== "string" || cookie.length === 0) return null;
|
|
12766
|
+
return {
|
|
12767
|
+
apiUrl,
|
|
12768
|
+
cookie,
|
|
12769
|
+
savedAt: typeof savedAt === "string" ? savedAt : (/* @__PURE__ */ new Date(0)).toISOString()
|
|
12770
|
+
};
|
|
12771
|
+
}
|
|
12772
|
+
async function readCredentialsFile(path) {
|
|
12773
|
+
let raw;
|
|
12774
|
+
try {
|
|
12775
|
+
raw = await readFile8(path, "utf8");
|
|
12776
|
+
} catch (error) {
|
|
12777
|
+
if (isMissingFile3(error)) return null;
|
|
12778
|
+
throw error;
|
|
12779
|
+
}
|
|
12780
|
+
try {
|
|
12781
|
+
return parseCredentials(JSON.parse(raw));
|
|
12782
|
+
} catch {
|
|
12783
|
+
return null;
|
|
12784
|
+
}
|
|
12785
|
+
}
|
|
12786
|
+
async function readCredentials() {
|
|
12787
|
+
const primary = await readCredentialsFile(credentialsPath());
|
|
12788
|
+
if (primary !== null) return primary;
|
|
12789
|
+
if (configDirOverride() !== void 0) return null;
|
|
12790
|
+
const legacyPath = join9(legacyConfigDir(), CREDENTIALS_FILE);
|
|
12791
|
+
if (legacyPath === credentialsPath()) return null;
|
|
12792
|
+
return readCredentialsFile(legacyPath);
|
|
12793
|
+
}
|
|
12794
|
+
async function writeCredentials(credentials) {
|
|
12795
|
+
const directory = configDir();
|
|
12796
|
+
await mkdir6(directory, { recursive: true, mode: 448 });
|
|
12797
|
+
const target = credentialsPath();
|
|
12798
|
+
await writeFile6(target, `${JSON.stringify(credentials, null, 2)}
|
|
12799
|
+
`, {
|
|
12800
|
+
encoding: "utf8",
|
|
12801
|
+
mode: 384
|
|
12802
|
+
});
|
|
12803
|
+
await chmod(target, 384);
|
|
12804
|
+
}
|
|
12805
|
+
async function clearCredentials() {
|
|
12806
|
+
const removed = await removeCredentialsFile(credentialsPath());
|
|
12807
|
+
const legacyPath = join9(legacyConfigDir(), CREDENTIALS_FILE);
|
|
12808
|
+
if (legacyPath === credentialsPath()) return removed;
|
|
12809
|
+
const removedLegacy = await removeCredentialsFile(legacyPath);
|
|
12810
|
+
return removed || removedLegacy;
|
|
12811
|
+
}
|
|
12812
|
+
async function removeCredentialsFile(path) {
|
|
12813
|
+
try {
|
|
12814
|
+
await rm5(path);
|
|
12815
|
+
return true;
|
|
12816
|
+
} catch (error) {
|
|
12817
|
+
if (isMissingFile3(error)) return false;
|
|
12818
|
+
throw error;
|
|
12819
|
+
}
|
|
12820
|
+
}
|
|
12821
|
+
function parseProjectLink(value, bundleDir) {
|
|
12822
|
+
if (!isRecord(value)) return null;
|
|
12823
|
+
const { projectId, apiUrl } = value;
|
|
12824
|
+
if (typeof projectId !== "string" || projectId.length === 0) return null;
|
|
12825
|
+
if (typeof apiUrl !== "string" || apiUrl.length === 0) return null;
|
|
12826
|
+
const execution = isRecord(value.execution) ? value.execution : {};
|
|
12827
|
+
return {
|
|
12828
|
+
projectId,
|
|
12829
|
+
apiUrl,
|
|
12830
|
+
bundleDir,
|
|
12831
|
+
taskMode: parseTaskMode(value.taskMode),
|
|
12832
|
+
execution: {
|
|
12833
|
+
// Legacy links may store the flag at the top level; prefer the nested form.
|
|
12834
|
+
uiQuality: parseUiQuality(execution.uiQuality ?? value.uiQuality),
|
|
12835
|
+
autoMode: parseAutoMode(execution.autoMode ?? value.autoMode)
|
|
12836
|
+
}
|
|
12837
|
+
};
|
|
11772
12838
|
}
|
|
11773
|
-
|
|
11774
|
-
|
|
11775
|
-
if (
|
|
11776
|
-
|
|
11777
|
-
try {
|
|
11778
|
-
const bytes = await readFile6(join6(bundleDir, relative2));
|
|
11779
|
-
return createHash("sha256").update(bytes).digest("hex");
|
|
11780
|
-
} catch {
|
|
11781
|
-
return null;
|
|
12839
|
+
function parseUiQuality(value) {
|
|
12840
|
+
if (value === void 0) return DEFAULT_UI_QUALITY;
|
|
12841
|
+
if (typeof value === "string" && UI_QUALITY_MODES.includes(value)) {
|
|
12842
|
+
return value;
|
|
11782
12843
|
}
|
|
12844
|
+
throw new Error(`Project link execution.uiQuality tidak valid: ${String(value)}`);
|
|
11783
12845
|
}
|
|
11784
|
-
|
|
11785
|
-
|
|
11786
|
-
|
|
11787
|
-
|
|
11788
|
-
|
|
11789
|
-
}
|
|
12846
|
+
function parseAutoMode(value) {
|
|
12847
|
+
if (value === void 0 || value === null) return false;
|
|
12848
|
+
if (typeof value === "boolean") return value;
|
|
12849
|
+
if (value === "true" || value === "1" || value === "yes") return true;
|
|
12850
|
+
if (value === "false" || value === "0" || value === "no") return false;
|
|
12851
|
+
throw new Error(`Project link execution.autoMode tidak valid: ${String(value)}`);
|
|
11790
12852
|
}
|
|
11791
|
-
function
|
|
11792
|
-
const
|
|
11793
|
-
|
|
11794
|
-
|
|
12853
|
+
async function readAutoMode(bundleDir) {
|
|
12854
|
+
const link = await readProjectLink(resolve2(bundleDir));
|
|
12855
|
+
return link?.execution.autoMode ?? false;
|
|
12856
|
+
}
|
|
12857
|
+
async function writeAutoMode(bundleDir, enabled) {
|
|
12858
|
+
const link = await readProjectLink(resolve2(bundleDir));
|
|
12859
|
+
if (link === null) throw new Error("Belum ada project link. Jalankan `jioogen link` dulu.");
|
|
12860
|
+
await writeProjectLink(resolve2(bundleDir), {
|
|
12861
|
+
projectId: link.projectId,
|
|
12862
|
+
apiUrl: link.apiUrl,
|
|
12863
|
+
taskMode: link.taskMode,
|
|
12864
|
+
execution: { uiQuality: link.execution.uiQuality, autoMode: enabled }
|
|
12865
|
+
});
|
|
12866
|
+
}
|
|
12867
|
+
function parseTaskMode(value) {
|
|
12868
|
+
if (value === void 0) return DEFAULT_TASK_MODE;
|
|
12869
|
+
const parsed = TaskModeSchema.safeParse(value);
|
|
12870
|
+
if (!parsed.success) {
|
|
12871
|
+
throw new Error(`Project link taskMode tidak valid: ${String(value)}`);
|
|
11795
12872
|
}
|
|
11796
|
-
|
|
11797
|
-
|
|
12873
|
+
return parsed.data;
|
|
12874
|
+
}
|
|
12875
|
+
async function readProjectLink(bundleDir) {
|
|
12876
|
+
for (const directoryName of [PROJECT_DIR, LEGACY_PROJECT_DIR]) {
|
|
12877
|
+
const candidate = join9(bundleDir, directoryName, PROJECT_FILE);
|
|
12878
|
+
let raw = null;
|
|
12879
|
+
try {
|
|
12880
|
+
raw = await readFile8(candidate, "utf8");
|
|
12881
|
+
} catch (error) {
|
|
12882
|
+
if (!isMissingFile3(error)) throw error;
|
|
12883
|
+
}
|
|
12884
|
+
if (raw === null) continue;
|
|
12885
|
+
let parsed;
|
|
12886
|
+
try {
|
|
12887
|
+
parsed = JSON.parse(raw);
|
|
12888
|
+
} catch {
|
|
12889
|
+
throw new Error(`Project link is not valid JSON: ${candidate}`);
|
|
12890
|
+
}
|
|
12891
|
+
const link = parseProjectLink(parsed, bundleDir);
|
|
12892
|
+
if (link === null) throw new Error(`Project link is invalid: ${candidate}`);
|
|
12893
|
+
return link;
|
|
11798
12894
|
}
|
|
11799
|
-
return
|
|
12895
|
+
return null;
|
|
11800
12896
|
}
|
|
11801
|
-
async function
|
|
11802
|
-
|
|
11803
|
-
for (
|
|
11804
|
-
const
|
|
11805
|
-
if (
|
|
12897
|
+
async function findProjectLink(startDir) {
|
|
12898
|
+
let directory = resolve2(startDir);
|
|
12899
|
+
for (; ; ) {
|
|
12900
|
+
const link = await readProjectLink(directory);
|
|
12901
|
+
if (link !== null) return link;
|
|
12902
|
+
const parent = dirname5(directory);
|
|
12903
|
+
if (parent === directory) return null;
|
|
12904
|
+
directory = parent;
|
|
11806
12905
|
}
|
|
11807
|
-
|
|
11808
|
-
|
|
11809
|
-
|
|
11810
|
-
|
|
11811
|
-
|
|
11812
|
-
|
|
11813
|
-
|
|
12906
|
+
}
|
|
12907
|
+
async function writeProjectLink(bundleDir, link) {
|
|
12908
|
+
const directory = join9(resolve2(bundleDir), PROJECT_DIR);
|
|
12909
|
+
await mkdir6(directory, { recursive: true });
|
|
12910
|
+
await writeFile6(
|
|
12911
|
+
join9(directory, PROJECT_FILE),
|
|
12912
|
+
`${JSON.stringify(
|
|
12913
|
+
{
|
|
12914
|
+
projectId: link.projectId,
|
|
12915
|
+
apiUrl: link.apiUrl,
|
|
12916
|
+
taskMode: link.taskMode ?? DEFAULT_TASK_MODE,
|
|
12917
|
+
execution: {
|
|
12918
|
+
uiQuality: link.execution?.uiQuality ?? DEFAULT_UI_QUALITY,
|
|
12919
|
+
autoMode: link.execution?.autoMode ?? false
|
|
12920
|
+
}
|
|
12921
|
+
},
|
|
12922
|
+
null,
|
|
12923
|
+
2
|
|
12924
|
+
)}
|
|
12925
|
+
`,
|
|
12926
|
+
"utf8"
|
|
12927
|
+
);
|
|
12928
|
+
}
|
|
12929
|
+
async function removeProjectLink(bundleDir) {
|
|
12930
|
+
let removedKey = false;
|
|
12931
|
+
for (const directoryName of [PROJECT_DIR, LEGACY_PROJECT_DIR]) {
|
|
12932
|
+
const candidate = join9(resolve2(bundleDir), directoryName, PROJECT_FILE);
|
|
12933
|
+
try {
|
|
12934
|
+
await rm5(candidate);
|
|
12935
|
+
removedKey = true;
|
|
12936
|
+
} catch (error) {
|
|
12937
|
+
if (!isMissingFile3(error)) throw error;
|
|
11814
12938
|
}
|
|
11815
12939
|
}
|
|
11816
|
-
|
|
11817
|
-
|
|
11818
|
-
|
|
11819
|
-
|
|
11820
|
-
|
|
11821
|
-
|
|
12940
|
+
return removedKey;
|
|
12941
|
+
}
|
|
12942
|
+
async function readUiQuality(bundleDir) {
|
|
12943
|
+
const link = await readProjectLink(resolve2(bundleDir));
|
|
12944
|
+
return link?.execution.uiQuality ?? DEFAULT_UI_QUALITY;
|
|
12945
|
+
}
|
|
12946
|
+
async function readTaskMode(bundleDir) {
|
|
12947
|
+
const link = await readProjectLink(resolve2(bundleDir));
|
|
12948
|
+
return link?.taskMode ?? DEFAULT_TASK_MODE;
|
|
12949
|
+
}
|
|
12950
|
+
function isMissingFile3(error) {
|
|
12951
|
+
return isRecord(error) && error.code === "ENOENT";
|
|
11822
12952
|
}
|
|
11823
12953
|
|
|
12954
|
+
// src/doctor.ts
|
|
12955
|
+
import { readdir as readdir7, readFile as readFile10, rm as rm7, stat as stat6 } from "node:fs/promises";
|
|
12956
|
+
import { join as join11 } from "node:path";
|
|
12957
|
+
|
|
11824
12958
|
// src/skills.ts
|
|
11825
|
-
import { createHash as
|
|
11826
|
-
import { cp as cp2, mkdir as
|
|
12959
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
12960
|
+
import { cp as cp2, mkdir as mkdir7, readdir as readdir6, readFile as readFile9, rename as rename2, rm as rm6, stat as stat5, writeFile as writeFile7 } from "node:fs/promises";
|
|
11827
12961
|
import { homedir as homedir2 } from "node:os";
|
|
11828
|
-
import { dirname as
|
|
12962
|
+
import { dirname as dirname6, join as join10, resolve as resolve3 } from "node:path";
|
|
11829
12963
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
11830
12964
|
var EXECUTION_SKILL_NAME = "jioogen-execution";
|
|
11831
12965
|
var AGENT_SKILL_DIRS = [
|
|
@@ -11883,7 +13017,7 @@ var JIOOGEN_AGENTS_MD = `${MARKER}
|
|
|
11883
13017
|
- Kamu mengeksekusi task; \`jioogen\` hanya memilih task dan menyinkronkan status.
|
|
11884
13018
|
|
|
11885
13019
|
## 0b. Peran & batas
|
|
11886
|
-
- **JiooGen (read-only):** pemilik konteks & kontrak \u2014 \`PRD.md\`, \`specs/\`, \`tasks/\`,
|
|
13020
|
+
- **JiooGen (read-only):** pemilik konteks & kontrak \u2014 \`docs/00-contract/PRD.md\`, \`specs/\`, \`tasks/\`,
|
|
11887
13021
|
urutan task, monitoring. Ia memilih task dan menyinkronkan status; **tidak**
|
|
11888
13022
|
mendesain, memecah task, mengedit kode, atau menjalankan test.
|
|
11889
13023
|
- **Kamu (Local Harness):** pembangun produk \u2014 desain UI/UX, breakdown naratif \u2192
|
|
@@ -11899,12 +13033,37 @@ var JIOOGEN_AGENTS_MD = `${MARKER}
|
|
|
11899
13033
|
mengizinkanmu menambah task, \`executor\` hanya menjalankan task yang sudah ada \u2014
|
|
11900
13034
|
CLI menolak task baru di disk. Jangan menaikkan mode sendiri.
|
|
11901
13035
|
|
|
13036
|
+
## 0c. Cara bertanya ke user (selalu)
|
|
13037
|
+
- Setiap pertanyaan ke user pakai **bahasa manusia sehari-hari**: pendek, jelas,
|
|
13038
|
+
dan mudah dijawab. Utamakan "ya/tidak" atau pilihan "A / B".
|
|
13039
|
+
- Jangan pakai istilah teknis, path file, kode, nama gate, atau jargon CLI saat
|
|
13040
|
+
bertanya. Cukup satu kalimat tentang dampaknya bagi produk.
|
|
13041
|
+
- Contoh: "Saya mau mengubah PRD, lalu specs, lalu tasks. Boleh? (ya/tidak)".
|
|
13042
|
+
|
|
13043
|
+
## 0d. Otonomi penyelarasan kontrak (wajib)
|
|
13044
|
+
|
|
13045
|
+
- **Jangan menyuruh user mengetik perintah \`jioogen\`.** Kamu yang menjalankan
|
|
13046
|
+
\`jioogen approve\`, \`jioogen align\`, dan \`jioogen docs\`.
|
|
13047
|
+
- Kontrak ada di \`docs/00-contract/\` (\`PRD.md\`, \`specs/\`, \`tasks/\`); dokumen lain
|
|
13048
|
+
ada di \`docs/01-product\`, \`02-design\`, \`03-architecture\`, \`04-domain\`,
|
|
13049
|
+
\`05-operations\`, \`06-quality\`. Baca \`docs/README.md\` lebih dulu.
|
|
13050
|
+
- Bila user bilang PRD berubah, minta ubah produk, atau specs/tasks tampak basi:
|
|
13051
|
+
tanya **sekali** dengan bahasa manusia, mis. "Mau saya rapikan specs, tasks,
|
|
13052
|
+
dan web sekaligus? (ya/tidak)". Setelah "ya", jalankan sendiri \`jioogen approve\`
|
|
13053
|
+
(bila PRD lokal berbeda dari web) lalu \`jioogen align\`.
|
|
13054
|
+
- Bila output CLI menyebut \`ALIGN_NEXT\` atau "kontrak belum selaras": jalankan
|
|
13055
|
+
aksinya sendiri. \`ALIGN_NEXT: approve\` \u2192 tanya sekali, lalu \`approve\` + \`align\`.
|
|
13056
|
+
- **Batch vs Manual:** tanyakan "Batch (sekaligus) atau Manual (satu per satu)?
|
|
13057
|
+
(batch/manual)". Pilihan disimpan; ganti hanya bila user memintanya eksplisit.
|
|
13058
|
+
- Dokumen = niat, kode = kenyataan. Bila berbeda, jangan menebak; tanyakan
|
|
13059
|
+
"Dokumen bilang A, kode melakukan B. Mana yang benar? (dokumen/kode)".
|
|
13060
|
+
|
|
11902
13061
|
## 1. Prioritas mutlak (keras)
|
|
11903
13062
|
- **Task aktif menang** atas ide, refactor, perbaikan, atau fitur lain.
|
|
11904
13063
|
- **Satu task per giliran.** Dilarang mengerjakan lebih dari satu task sekaligus.
|
|
11905
13064
|
- Dilarang pindah task sebelum task aktif \`done\` atau \`failed\`.
|
|
11906
13065
|
- Jangan mengarang fitur/endpoint/kolom yang tidak ada di \`PRD.md\`/\`specs/\`.
|
|
11907
|
-
- Jangan mengubah \`PRD.md
|
|
13066
|
+
- Jangan mengubah \`PRD.md\`/\`specs/\` di luar alur \xA70d; itu kontrak, bukan hasil eksekusi.
|
|
11908
13067
|
- **Warning CLI \u2260 BLOCKER, jangan loop.** Warning seperti ID task duplikat atau
|
|
11909
13068
|
drift bukan alasan menghentikan atau mengulang-ulang eksekusi: baca pesannya,
|
|
11910
13069
|
tandai kondisi di note (\`task start/complete --note "...id duplikat, default pakai
|
|
@@ -11938,9 +13097,20 @@ tangan) sebelum task dijalankan, jangan pura-pura mengerjakannya:
|
|
|
11938
13097
|
- Verifikasi hasilnya lalu \`npx jioogen task adopt <ref> --note "<alat>"\` (task UI:
|
|
11939
13098
|
tambahkan \`--visual "<catatan>"\`). Command itu menjalankan \`verificationCommand\`
|
|
11940
13099
|
dan mencatat \`source: user\` + bukti adopsi di sidecar.
|
|
11941
|
-
-
|
|
11942
|
-
|
|
11943
|
-
|
|
13100
|
+
- Mode authoring lokal: bila user menyetujui patch kontrak di chat lokal, catat
|
|
13101
|
+
persetujuan dengan \`npx jioogen approve --note "<alasan>"\` (menulis
|
|
13102
|
+
\`.jioogen/approvals.json\` + \`.jioogen/custom/knowledge/approved-patches.md\`),
|
|
13103
|
+
lalu ubah \`PRD.md\`. Setelah itu jalankan \`npx jioogen align\`: JiooGen otomatis
|
|
13104
|
+
menurunkan \`specs/\` \u2192 \`tasks/\`, memvalidasi gate, dan menyelaraskan ke web.
|
|
13105
|
+
\`npx jioogen task next\` juga menyelaraskan otomatis sebelum memilih task.
|
|
13106
|
+
Jangan menyuruh user balik ke web dan jangan edit \`specs/\`/\`tasks/\` manual.
|
|
13107
|
+
- Sebelum mode authoring lokal, agent WAJIB bertanya dengan bahasa manusia:
|
|
13108
|
+
"Saya mau mengubah PRD, lalu specs, lalu tasks di lokal. Boleh? (ya/tidak)".
|
|
13109
|
+
Lanjut HANYA bila user menjawab "ya". Tanpa "ya", jangan ubah apa pun.
|
|
13110
|
+
Jangan pakai istilah teknis saat bertanya, dan ingatkan bahwa setelah patch
|
|
13111
|
+
ada, jangan menjalankan \`jioogen pull --force\`.
|
|
13112
|
+
- Di luar mode authoring lokal itu, jangan edit \`PRD.md\`/\`specs/\` lokal;
|
|
13113
|
+
\`BUNDLE_DRIFT\` akan muncul. Jangan mengadopsi penyimpangan diam-diam.
|
|
11944
13114
|
- Port dev server jangan ditebak: JiooGen/app lain bisa sudah memakainya. Pakai port
|
|
11945
13115
|
bebas (mis. \`PORT=3001\`), catat di note; jangan ubah kontrak/spec demi port.
|
|
11946
13116
|
|
|
@@ -11958,8 +13128,8 @@ tangan) sebelum task dijalankan, jangan pura-pura mengerjakannya:
|
|
|
11958
13128
|
- Detail implementasi milikmu: pola komponen/state, struktur file di dalam
|
|
11959
13129
|
\`targetFiles\`, struktur test, dan library yang sudah ada. Ikuti konvensi proyek.
|
|
11960
13130
|
- \`targetFiles\` boleh file exact, direktori, atau glob. File baru hanya di area itu.
|
|
11961
|
-
- Jangan mengubah \`PRD.md\`/\`specs/\`/kontrak. Butuh perubahan
|
|
11962
|
-
|
|
13131
|
+
- Jangan mengubah \`PRD.md\`/\`specs/\`/kontrak di luar alur \xA70d. Butuh perubahan
|
|
13132
|
+
kontrak/data model? Hentikan task, minta izin sekali, lalu jalankan \xA70d.
|
|
11963
13133
|
|
|
11964
13134
|
## 3c. Micro-fix dalam task aktif (tanpa task baru)
|
|
11965
13135
|
Perbaikan kecil yang **wajib** agar Acceptance Criteria task aktif lulus boleh
|
|
@@ -12035,7 +13205,7 @@ atas ide, refactor, perbaikan, atau fitur lain.
|
|
|
12035
13205
|
|
|
12036
13206
|
## 0b. Peran & batas (JiooGen vs Local Harness)
|
|
12037
13207
|
|
|
12038
|
-
- **JiooGen (read-only):** pemilik konteks & kontrak \u2014 \`PRD.md\`, \`specs/\`, \`tasks/\`,
|
|
13208
|
+
- **JiooGen (read-only):** pemilik konteks & kontrak \u2014 \`docs/00-contract/PRD.md\`, \`specs/\`, \`tasks/\`,
|
|
12039
13209
|
urutan task, dan monitoring. Ia memilih task dan menyinkronkan status; **tidak**
|
|
12040
13210
|
mendesain, memecah task, mengedit kode, atau menjalankan test.
|
|
12041
13211
|
- **Kamu (Local Harness):** pembangun produk \u2014 desain UI/UX, breakdown naratif \u2192
|
|
@@ -12054,6 +13224,24 @@ atas ide, refactor, perbaikan, atau fitur lain.
|
|
|
12054
13224
|
- Skill UI (capability \`ui-quality\`, bila terpasang) dipakai untuk desain dan
|
|
12055
13225
|
review; tetap tunduk pada kontrak ini.
|
|
12056
13226
|
|
|
13227
|
+
## 0d. Otonomi penyelarasan kontrak (wajib)
|
|
13228
|
+
|
|
13229
|
+
- **Jangan menyuruh user mengetik perintah \`jioogen\`.** Kamu yang menjalankan
|
|
13230
|
+
\`jioogen approve\`, \`jioogen align\`, dan \`jioogen docs\`.
|
|
13231
|
+
- Kontrak ada di \`docs/00-contract/\` (\`PRD.md\`, \`specs/\`, \`tasks/\`); dokumen lain
|
|
13232
|
+
ada di \`docs/01-product\`, \`02-design\`, \`03-architecture\`, \`04-domain\`,
|
|
13233
|
+
\`05-operations\`, \`06-quality\`. Baca \`docs/README.md\` lebih dulu.
|
|
13234
|
+
- Bila user bilang PRD berubah, minta ubah produk, atau specs/tasks tampak basi:
|
|
13235
|
+
tanya **sekali** dengan bahasa manusia, mis. "Mau saya rapikan specs, tasks,
|
|
13236
|
+
dan web sekaligus? (ya/tidak)". Setelah "ya", jalankan sendiri \`jioogen approve\`
|
|
13237
|
+
(bila PRD lokal berbeda dari web) lalu \`jioogen align\`.
|
|
13238
|
+
- Bila output CLI menyebut \`ALIGN_NEXT\` atau "kontrak belum selaras": jalankan
|
|
13239
|
+
aksinya sendiri. \`ALIGN_NEXT: approve\` \u2192 tanya sekali, lalu \`approve\` + \`align\`.
|
|
13240
|
+
- **Batch vs Manual:** tanyakan "Batch (sekaligus) atau Manual (satu per satu)?
|
|
13241
|
+
(batch/manual)". Pilihan disimpan; ganti hanya bila user memintanya eksplisit.
|
|
13242
|
+
- Dokumen = niat, kode = kenyataan. Bila berbeda, jangan menebak; tanyakan
|
|
13243
|
+
"Dokumen bilang A, kode melakukan B. Mana yang benar? (dokumen/kode)".
|
|
13244
|
+
|
|
12057
13245
|
## 1. Prioritas mutlak (keras)
|
|
12058
13246
|
|
|
12059
13247
|
- **Kerjakan HANYA task aktif.** Task aktif menang atas semua pekerjaan lain.
|
|
@@ -12061,7 +13249,7 @@ atas ide, refactor, perbaikan, atau fitur lain.
|
|
|
12061
13249
|
- Dilarang pindah task sebelum task aktif \`done\` atau \`failed\`.
|
|
12062
13250
|
- Dilarang mengerjakan task yang belum dipilih \`task next\`, walau terlihat mudah.
|
|
12063
13251
|
- Jangan mengarang fitur/endpoint/kolom/state yang tidak ada di \`PRD.md\`/\`specs/\`.
|
|
12064
|
-
- Jangan mengubah \`PRD.md
|
|
13252
|
+
- Jangan mengubah \`PRD.md\`/\`specs/\` di luar alur \xA70d.
|
|
12065
13253
|
|
|
12066
13254
|
## 2. Siklus per giliran
|
|
12067
13255
|
|
|
@@ -12086,9 +13274,20 @@ atau ditulis tangan \u2014 sebelum task dijalankan, jangan pura-pura mengerjakan
|
|
|
12086
13274
|
- Verifikasi hasilnya lalu \`npx jioogen task adopt <ref> --note "<alat>"\` (task UI:
|
|
12087
13275
|
tambahkan \`--visual "<catatan>"\`). Command itu menjalankan \`verificationCommand\`
|
|
12088
13276
|
dan mencatat \`source: user\` + bukti adopsi di sidecar.
|
|
12089
|
-
-
|
|
12090
|
-
|
|
12091
|
-
|
|
13277
|
+
- Mode authoring lokal: bila user menyetujui patch kontrak di chat lokal, catat
|
|
13278
|
+
persetujuan dengan \`npx jioogen approve --note "<alasan>"\` (menulis
|
|
13279
|
+
\`.jioogen/approvals.json\` + \`.jioogen/custom/knowledge/approved-patches.md\`),
|
|
13280
|
+
lalu ubah \`PRD.md\`. Setelah itu jalankan \`npx jioogen align\`: JiooGen otomatis
|
|
13281
|
+
menurunkan \`specs/\` \u2192 \`tasks/\`, memvalidasi gate, dan menyelaraskan ke web.
|
|
13282
|
+
\`npx jioogen task next\` juga menyelaraskan otomatis sebelum memilih task.
|
|
13283
|
+
Jangan menyuruh user balik ke web dan jangan edit \`specs/\`/\`tasks/\` manual.
|
|
13284
|
+
- Sebelum mode authoring lokal, agent WAJIB bertanya dengan bahasa manusia:
|
|
13285
|
+
"Saya mau mengubah PRD, lalu specs, lalu tasks di lokal. Boleh? (ya/tidak)".
|
|
13286
|
+
Lanjut HANYA bila user menjawab "ya". Tanpa "ya", jangan ubah apa pun.
|
|
13287
|
+
Jangan pakai istilah teknis saat bertanya, dan ingatkan bahwa setelah patch
|
|
13288
|
+
ada, jangan menjalankan \`jioogen pull --force\`.
|
|
13289
|
+
- Di luar mode authoring lokal itu, jangan edit \`PRD.md\`/\`specs/\` lokal;
|
|
13290
|
+
\`BUNDLE_DRIFT\` akan muncul. Jangan mengadopsi penyimpangan diam-diam.
|
|
12092
13291
|
- **Port dev server jangan ditebak.** JiooGen/monitor atau app lain bisa sudah
|
|
12093
13292
|
memakai port default; pakai port bebas (mis. \`PORT=3001\`), catat di note, dan
|
|
12094
13293
|
jangan mengubah kontrak/spec demi port.
|
|
@@ -12111,9 +13310,9 @@ atau ditulis tangan \u2014 sebelum task dijalankan, jangan pura-pura mengerjakan
|
|
|
12111
13310
|
- Ikuti konvensi proyek lebih dulu; jangan refactor di luar scope task.
|
|
12112
13311
|
- \`targetFiles\` boleh file exact, direktori, atau glob (mis.
|
|
12113
13312
|
\`src/features/booking/**\`). File baru hanya di dalam area itu.
|
|
12114
|
-
- Jangan mengubah \`PRD.md\`, \`specs/\`, atau kontrak (\`CONTRACT-XXX\`).
|
|
12115
|
-
implementasi menuntut perubahan kontrak/data model/scope:
|
|
12116
|
-
|
|
13313
|
+
- Jangan mengubah \`PRD.md\`, \`specs/\`, atau kontrak (\`CONTRACT-XXX\`) di luar \xA70d.
|
|
13314
|
+
Bila implementasi menuntut perubahan kontrak/data model/scope: hentikan task,
|
|
13315
|
+
minta izin sekali, lalu jalankan \xA70d \u2014 bukan mengarang atau menyimpang diam-diam.
|
|
12117
13316
|
|
|
12118
13317
|
## 3c. Micro-fix dalam task aktif (tanpa task baru)
|
|
12119
13318
|
|
|
@@ -12167,7 +13366,7 @@ Tanya: "Apakah senior engineer bilang ini overcomplicated?" Bila ya, sederhanaka
|
|
|
12167
13366
|
mengeditnya antar-sesi; agent **reuse/extend**, **jangan menimpa** edit user saat
|
|
12168
13367
|
task berjalan. Preferensi tambahan user di \`.jioogen/custom/design/\` (additive).
|
|
12169
13368
|
- Inspeksi token/theme/CSS variables/Tailwind/komponen/design reference yang sudah ada
|
|
12170
|
-
(specs/design.md, custom/design/, docs/DESIGN.md, specs, codebase). Reuse dulu;
|
|
13369
|
+
(specs/design.md, custom/design/, docs/02-design/DESIGN.md, specs, codebase). Reuse dulu;
|
|
12171
13370
|
token baru hanya untuk nilai visual berulang yang nyata; jangan hardcode nilai yang
|
|
12172
13371
|
sudah punya token; jangan membuat design system baru atau mengganti styling di luar
|
|
12173
13372
|
scope. Produk tanpa UI: \`N/A \u2014 tidak ada surface visual\`.
|
|
@@ -12231,18 +13430,18 @@ Gap non-material \u2192 tafsir paling sempit + catat asumsi di note, lanjut. Gap
|
|
|
12231
13430
|
Jangan menebak scope baru.
|
|
12232
13431
|
`;
|
|
12233
13432
|
async function ensureCustomScaffold(root) {
|
|
12234
|
-
const base =
|
|
13433
|
+
const base = join10(root, ".jioogen", "custom");
|
|
12235
13434
|
for (const dir of CUSTOM_SCAFFOLD_DIRS) {
|
|
12236
|
-
await
|
|
13435
|
+
await mkdir7(join10(base, dir), { recursive: true });
|
|
12237
13436
|
}
|
|
12238
|
-
const readme =
|
|
13437
|
+
const readme = join10(root, CUSTOM_SCAFFOLD_README_PATH);
|
|
12239
13438
|
if (await readFileSafe(readme) !== void 0) return [];
|
|
12240
|
-
await
|
|
13439
|
+
await writeFile7(readme, CUSTOM_SCAFFOLD_README, "utf8");
|
|
12241
13440
|
return [CUSTOM_SCAFFOLD_README_PATH];
|
|
12242
13441
|
}
|
|
12243
13442
|
async function readFileSafe(path) {
|
|
12244
13443
|
try {
|
|
12245
|
-
return await
|
|
13444
|
+
return await readFile9(path, "utf8");
|
|
12246
13445
|
} catch {
|
|
12247
13446
|
return void 0;
|
|
12248
13447
|
}
|
|
@@ -12255,7 +13454,7 @@ function isMissingFile4(error) {
|
|
|
12255
13454
|
}
|
|
12256
13455
|
async function isFile(path) {
|
|
12257
13456
|
try {
|
|
12258
|
-
return (await
|
|
13457
|
+
return (await stat5(path)).isFile();
|
|
12259
13458
|
} catch (error) {
|
|
12260
13459
|
if (isMissingFile4(error)) return false;
|
|
12261
13460
|
throw error;
|
|
@@ -12263,7 +13462,7 @@ async function isFile(path) {
|
|
|
12263
13462
|
}
|
|
12264
13463
|
async function isDirectory(path) {
|
|
12265
13464
|
try {
|
|
12266
|
-
return (await
|
|
13465
|
+
return (await stat5(path)).isDirectory();
|
|
12267
13466
|
} catch (error) {
|
|
12268
13467
|
if (isMissingFile4(error)) return false;
|
|
12269
13468
|
throw error;
|
|
@@ -12277,11 +13476,11 @@ function isProductKind(value) {
|
|
|
12277
13476
|
}
|
|
12278
13477
|
function parseSkillEntry(value) {
|
|
12279
13478
|
if (!isRecord2(value)) return null;
|
|
12280
|
-
const { name, source, sha256 } = value;
|
|
13479
|
+
const { name, source, sha256: sha2562 } = value;
|
|
12281
13480
|
if (typeof name !== "string" || name.length === 0) return null;
|
|
12282
13481
|
if (typeof source !== "string" || source.length === 0) return null;
|
|
12283
|
-
if (typeof
|
|
12284
|
-
return { name, source, sha256 };
|
|
13482
|
+
if (typeof sha2562 !== "string" || sha2562.length === 0) return null;
|
|
13483
|
+
return { name, source, sha256: sha2562 };
|
|
12285
13484
|
}
|
|
12286
13485
|
function parsePack(value) {
|
|
12287
13486
|
if (!isRecord2(value)) return null;
|
|
@@ -12331,10 +13530,10 @@ function parseHarnessManifest(value) {
|
|
|
12331
13530
|
};
|
|
12332
13531
|
}
|
|
12333
13532
|
async function readHarnessManifest(bundleDir) {
|
|
12334
|
-
const path =
|
|
13533
|
+
const path = join10(resolve3(bundleDir), HARNESS_MANIFEST_PATH);
|
|
12335
13534
|
let raw;
|
|
12336
13535
|
try {
|
|
12337
|
-
raw = await
|
|
13536
|
+
raw = await readFile9(path, "utf8");
|
|
12338
13537
|
} catch (error) {
|
|
12339
13538
|
if (isMissingFile4(error)) return null;
|
|
12340
13539
|
throw error;
|
|
@@ -12346,24 +13545,24 @@ async function readHarnessManifest(bundleDir) {
|
|
|
12346
13545
|
}
|
|
12347
13546
|
}
|
|
12348
13547
|
async function writeHarnessManifest(bundleDir, manifest) {
|
|
12349
|
-
const path =
|
|
12350
|
-
await
|
|
12351
|
-
await
|
|
13548
|
+
const path = join10(resolve3(bundleDir), HARNESS_MANIFEST_PATH);
|
|
13549
|
+
await mkdir7(dirname6(path), { recursive: true });
|
|
13550
|
+
await writeFile7(path, `${JSON.stringify(manifest, null, 2)}
|
|
12352
13551
|
`, "utf8");
|
|
12353
13552
|
return path;
|
|
12354
13553
|
}
|
|
12355
13554
|
async function detectProductKind(bundleDir) {
|
|
12356
|
-
const tasksDir =
|
|
13555
|
+
const tasksDir = join10(contractRoot(resolve3(bundleDir)), "tasks");
|
|
12357
13556
|
let entries;
|
|
12358
13557
|
try {
|
|
12359
|
-
entries = await
|
|
13558
|
+
entries = await readdir6(tasksDir, { withFileTypes: true });
|
|
12360
13559
|
} catch (error) {
|
|
12361
13560
|
if (isMissingFile4(error)) return "non-ui";
|
|
12362
13561
|
throw error;
|
|
12363
13562
|
}
|
|
12364
13563
|
for (const entry of entries) {
|
|
12365
13564
|
if (!entry.isFile() || !entry.name.toLowerCase().endsWith(".md")) continue;
|
|
12366
|
-
const content = await readFileSafe(
|
|
13565
|
+
const content = await readFileSafe(join10(tasksDir, entry.name));
|
|
12367
13566
|
if (content !== void 0 && FRONTEND_MOCK_LAYER_RE.test(content)) return "ui";
|
|
12368
13567
|
}
|
|
12369
13568
|
return "non-ui";
|
|
@@ -12379,37 +13578,37 @@ function packsForProduct(productKind, uiQuality = "auto") {
|
|
|
12379
13578
|
return packs;
|
|
12380
13579
|
}
|
|
12381
13580
|
function cliPackageRoot2() {
|
|
12382
|
-
return resolve3(
|
|
13581
|
+
return resolve3(dirname6(fileURLToPath2(import.meta.url)), "..");
|
|
12383
13582
|
}
|
|
12384
13583
|
function skillSourceCandidates(pack, name) {
|
|
12385
13584
|
const candidates = [];
|
|
12386
13585
|
const override = process.env.JIOOGEN_SKILLS_DIR?.trim();
|
|
12387
|
-
if (override !== void 0 && override.length > 0) candidates.push(
|
|
12388
|
-
candidates.push(
|
|
12389
|
-
candidates.push(
|
|
13586
|
+
if (override !== void 0 && override.length > 0) candidates.push(join10(override, name));
|
|
13587
|
+
candidates.push(join10(configDir(), "skill-cache", name));
|
|
13588
|
+
candidates.push(join10(cliPackageRoot2(), "skills-pack", pack, name));
|
|
12390
13589
|
const home = homedir2();
|
|
12391
|
-
candidates.push(
|
|
12392
|
-
candidates.push(
|
|
12393
|
-
candidates.push(
|
|
13590
|
+
candidates.push(join10(home, ".agents", "skills", name));
|
|
13591
|
+
candidates.push(join10(home, ".config", "opencode", "skills", name));
|
|
13592
|
+
candidates.push(join10(home, ".claude", "skills", name));
|
|
12394
13593
|
return candidates;
|
|
12395
13594
|
}
|
|
12396
13595
|
async function resolveSkillSource(pack, name) {
|
|
12397
13596
|
for (const candidate of skillSourceCandidates(pack, name)) {
|
|
12398
|
-
if (await isDirectory(candidate) && await isFile(
|
|
13597
|
+
if (await isDirectory(candidate) && await isFile(join10(candidate, "SKILL.md"))) {
|
|
12399
13598
|
return candidate;
|
|
12400
13599
|
}
|
|
12401
13600
|
}
|
|
12402
13601
|
return null;
|
|
12403
13602
|
}
|
|
12404
13603
|
async function collectRelativeFiles(root, prefix) {
|
|
12405
|
-
const entries = await
|
|
13604
|
+
const entries = await readdir6(join10(root, prefix), { withFileTypes: true });
|
|
12406
13605
|
const files = [];
|
|
12407
13606
|
for (const entry of entries) {
|
|
12408
|
-
const
|
|
13607
|
+
const relative3 = prefix.length === 0 ? entry.name : `${prefix}/${entry.name}`;
|
|
12409
13608
|
if (entry.isDirectory()) {
|
|
12410
|
-
files.push(...await collectRelativeFiles(root,
|
|
13609
|
+
files.push(...await collectRelativeFiles(root, relative3));
|
|
12411
13610
|
} else if (entry.isFile()) {
|
|
12412
|
-
files.push(
|
|
13611
|
+
files.push(relative3);
|
|
12413
13612
|
}
|
|
12414
13613
|
}
|
|
12415
13614
|
return files;
|
|
@@ -12417,18 +13616,18 @@ async function collectRelativeFiles(root, prefix) {
|
|
|
12417
13616
|
async function hashSkillDirectory(directory) {
|
|
12418
13617
|
const root = resolve3(directory);
|
|
12419
13618
|
const files = (await collectRelativeFiles(root, "")).sort();
|
|
12420
|
-
const hash =
|
|
12421
|
-
for (const
|
|
12422
|
-
hash.update(
|
|
13619
|
+
const hash = createHash3("sha256");
|
|
13620
|
+
for (const relative3 of files) {
|
|
13621
|
+
hash.update(relative3);
|
|
12423
13622
|
hash.update("\0");
|
|
12424
|
-
hash.update(await
|
|
13623
|
+
hash.update(await readFile9(join10(root, ...relative3.split("/"))));
|
|
12425
13624
|
hash.update("\0");
|
|
12426
13625
|
}
|
|
12427
13626
|
return hash.digest("hex");
|
|
12428
13627
|
}
|
|
12429
13628
|
async function replaceDirectory(source, target) {
|
|
12430
|
-
await
|
|
12431
|
-
await
|
|
13629
|
+
await rm6(target, { recursive: true, force: true });
|
|
13630
|
+
await mkdir7(dirname6(target), { recursive: true });
|
|
12432
13631
|
await cp2(source, target, { recursive: true });
|
|
12433
13632
|
}
|
|
12434
13633
|
function packNamesInCanonicalOrder(names) {
|
|
@@ -12444,19 +13643,19 @@ async function provisionPack(root, pack, prior, written, preserved) {
|
|
|
12444
13643
|
missing.push(name);
|
|
12445
13644
|
continue;
|
|
12446
13645
|
}
|
|
12447
|
-
const
|
|
13646
|
+
const sha2562 = await hashSkillDirectory(source);
|
|
12448
13647
|
const previous = prior?.skills.find((entry) => entry.name === name);
|
|
12449
13648
|
let owned = previous !== void 0;
|
|
12450
13649
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
12451
|
-
const targetDir =
|
|
12452
|
-
const skillMd =
|
|
13650
|
+
const targetDir = join10(root, dir, name);
|
|
13651
|
+
const skillMd = join10(targetDir, "SKILL.md");
|
|
12453
13652
|
if (await isFile(skillMd)) {
|
|
12454
13653
|
const targetHash = await hashSkillDirectory(targetDir);
|
|
12455
13654
|
if (previous === void 0) {
|
|
12456
13655
|
preserved.push(`${dir}/${name}/SKILL.md`);
|
|
12457
13656
|
continue;
|
|
12458
13657
|
}
|
|
12459
|
-
if (targetHash ===
|
|
13658
|
+
if (targetHash === sha2562) {
|
|
12460
13659
|
owned = true;
|
|
12461
13660
|
continue;
|
|
12462
13661
|
}
|
|
@@ -12469,7 +13668,7 @@ async function provisionPack(root, pack, prior, written, preserved) {
|
|
|
12469
13668
|
written.push(`${dir}/${name}/SKILL.md`);
|
|
12470
13669
|
owned = true;
|
|
12471
13670
|
}
|
|
12472
|
-
if (owned) skills.push({ name, source: `${pack}/${name}`, sha256 });
|
|
13671
|
+
if (owned) skills.push({ name, source: `${pack}/${name}`, sha256: sha2562 });
|
|
12473
13672
|
}
|
|
12474
13673
|
return { name: pack, skills, missing };
|
|
12475
13674
|
}
|
|
@@ -12480,36 +13679,36 @@ async function provisionCustomSkills(root, prior) {
|
|
|
12480
13679
|
const conflicts = [];
|
|
12481
13680
|
const removed = [];
|
|
12482
13681
|
const sources = /* @__PURE__ */ new Set();
|
|
12483
|
-
const base =
|
|
13682
|
+
const base = join10(root, CUSTOM_SKILLS_DIR);
|
|
12484
13683
|
const reserved = /* @__PURE__ */ new Set([EXECUTION_SKILL_NAME, ...Object.values(SKILL_PACKS).flat()]);
|
|
12485
13684
|
let entries = [];
|
|
12486
13685
|
try {
|
|
12487
|
-
entries = await
|
|
13686
|
+
entries = await readdir6(base, { withFileTypes: true });
|
|
12488
13687
|
} catch (error) {
|
|
12489
13688
|
if (!isMissingFile4(error)) throw error;
|
|
12490
13689
|
}
|
|
12491
13690
|
const names = entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
|
|
12492
13691
|
for (const name of names) {
|
|
12493
|
-
const source =
|
|
12494
|
-
if (!await isFile(
|
|
13692
|
+
const source = join10(base, name);
|
|
13693
|
+
if (!await isFile(join10(source, "SKILL.md"))) continue;
|
|
12495
13694
|
sources.add(name);
|
|
12496
13695
|
if (reserved.has(name)) {
|
|
12497
13696
|
conflicts.push(name);
|
|
12498
13697
|
continue;
|
|
12499
13698
|
}
|
|
12500
|
-
const
|
|
13699
|
+
const sha2562 = await hashSkillDirectory(source);
|
|
12501
13700
|
const previous = prior.find((entry) => entry.name === name);
|
|
12502
13701
|
let owned = previous !== void 0;
|
|
12503
13702
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
12504
|
-
const targetDir =
|
|
12505
|
-
const skillMd =
|
|
13703
|
+
const targetDir = join10(root, dir, name);
|
|
13704
|
+
const skillMd = join10(targetDir, "SKILL.md");
|
|
12506
13705
|
if (await isFile(skillMd)) {
|
|
12507
13706
|
const targetHash = await hashSkillDirectory(targetDir);
|
|
12508
13707
|
if (previous === void 0) {
|
|
12509
13708
|
preserved.push(`${dir}/${name}/SKILL.md`);
|
|
12510
13709
|
continue;
|
|
12511
13710
|
}
|
|
12512
|
-
if (targetHash ===
|
|
13711
|
+
if (targetHash === sha2562) {
|
|
12513
13712
|
owned = true;
|
|
12514
13713
|
continue;
|
|
12515
13714
|
}
|
|
@@ -12527,7 +13726,7 @@ async function provisionCustomSkills(root, prior) {
|
|
|
12527
13726
|
owned = true;
|
|
12528
13727
|
}
|
|
12529
13728
|
if (owned) {
|
|
12530
|
-
custom2.push({ name, source: `custom/${name}`, sha256 });
|
|
13729
|
+
custom2.push({ name, source: `custom/${name}`, sha256: sha2562 });
|
|
12531
13730
|
} else if (previous !== void 0) {
|
|
12532
13731
|
custom2.push(previous);
|
|
12533
13732
|
}
|
|
@@ -12536,15 +13735,15 @@ async function provisionCustomSkills(root, prior) {
|
|
|
12536
13735
|
if (sources.has(entry.name) && !reserved.has(entry.name)) continue;
|
|
12537
13736
|
if (reserved.has(entry.name)) continue;
|
|
12538
13737
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
12539
|
-
const targetDir =
|
|
12540
|
-
const skillMd =
|
|
13738
|
+
const targetDir = join10(root, dir, entry.name);
|
|
13739
|
+
const skillMd = join10(targetDir, "SKILL.md");
|
|
12541
13740
|
if (!await isFile(skillMd)) continue;
|
|
12542
13741
|
const targetHash = await hashSkillDirectory(targetDir);
|
|
12543
13742
|
if (targetHash !== entry.sha256) {
|
|
12544
13743
|
preserved.push(`${dir}/${entry.name}/SKILL.md`);
|
|
12545
13744
|
continue;
|
|
12546
13745
|
}
|
|
12547
|
-
await
|
|
13746
|
+
await rm6(targetDir, { recursive: true, force: true });
|
|
12548
13747
|
removed.push(`${dir}/${entry.name}/SKILL.md`);
|
|
12549
13748
|
}
|
|
12550
13749
|
}
|
|
@@ -12588,10 +13787,10 @@ async function provisionSkillPacks(bundleDir, packNames, productKind) {
|
|
|
12588
13787
|
};
|
|
12589
13788
|
}
|
|
12590
13789
|
async function ensureBundleGitignore(root) {
|
|
12591
|
-
const path =
|
|
13790
|
+
const path = join10(resolve3(root), ".gitignore");
|
|
12592
13791
|
const existing = await readFileSafe(path);
|
|
12593
13792
|
if (existing === void 0) {
|
|
12594
|
-
await
|
|
13793
|
+
await writeFile7(path, GITIGNORE_BLOCK, "utf8");
|
|
12595
13794
|
return ".gitignore";
|
|
12596
13795
|
}
|
|
12597
13796
|
const start = existing.indexOf(GITIGNORE_START);
|
|
@@ -12599,7 +13798,7 @@ async function ensureBundleGitignore(root) {
|
|
|
12599
13798
|
const next = start >= 0 && end > start ? `${existing.slice(0, start)}${GITIGNORE_BLOCK}${existing.slice(end + GITIGNORE_END.length).replace(/^\n/, "")}` : `${existing.replace(/\n*$/, "\n")}
|
|
12600
13799
|
${GITIGNORE_BLOCK}`;
|
|
12601
13800
|
if (next === existing) return null;
|
|
12602
|
-
await
|
|
13801
|
+
await writeFile7(path, next, "utf8");
|
|
12603
13802
|
return ".gitignore";
|
|
12604
13803
|
}
|
|
12605
13804
|
async function installAgentSkills(bundleDir, options = {}) {
|
|
@@ -12607,21 +13806,21 @@ async function installAgentSkills(bundleDir, options = {}) {
|
|
|
12607
13806
|
const written = [];
|
|
12608
13807
|
const preserved = [];
|
|
12609
13808
|
const productKind = options.productKind ?? await detectProductKind(root);
|
|
12610
|
-
const harnessPath =
|
|
12611
|
-
const agentsPath =
|
|
13809
|
+
const harnessPath = join10(root, HARNESS_MANIFEST_PATH);
|
|
13810
|
+
const agentsPath = join10(root, "AGENTS.md");
|
|
12612
13811
|
const existing = await readFileSafe(agentsPath);
|
|
12613
13812
|
if (existing === void 0 || existing.includes(MARKER_PREFIX)) {
|
|
12614
|
-
await
|
|
13813
|
+
await writeFile7(agentsPath, JIOOGEN_AGENTS_MD, "utf8");
|
|
12615
13814
|
written.push("AGENTS.md");
|
|
12616
13815
|
} else {
|
|
12617
13816
|
preserved.push("AGENTS.md");
|
|
12618
13817
|
}
|
|
12619
13818
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
12620
|
-
const
|
|
12621
|
-
const target =
|
|
12622
|
-
await
|
|
12623
|
-
await
|
|
12624
|
-
written.push(
|
|
13819
|
+
const relative3 = `${dir}/${EXECUTION_SKILL_NAME}/SKILL.md`;
|
|
13820
|
+
const target = join10(root, relative3);
|
|
13821
|
+
await mkdir7(dirname6(target), { recursive: true });
|
|
13822
|
+
await writeFile7(target, JIOOGEN_EXECUTION_SKILL, "utf8");
|
|
13823
|
+
written.push(relative3);
|
|
12625
13824
|
}
|
|
12626
13825
|
const gitignore = await ensureBundleGitignore(root);
|
|
12627
13826
|
if (gitignore !== null) written.push(gitignore);
|
|
@@ -12688,22 +13887,22 @@ async function removeExecutionContract(bundleDir) {
|
|
|
12688
13887
|
const root = resolve3(bundleDir);
|
|
12689
13888
|
const removed = [];
|
|
12690
13889
|
const preserved = [];
|
|
12691
|
-
const agentsPath =
|
|
13890
|
+
const agentsPath = join10(root, "AGENTS.md");
|
|
12692
13891
|
const existingAgents = await readFileSafe(agentsPath);
|
|
12693
13892
|
if (existingAgents !== void 0) {
|
|
12694
13893
|
if (existingAgents.includes(MARKER_PREFIX)) {
|
|
12695
|
-
await
|
|
13894
|
+
await rm6(agentsPath, { force: true });
|
|
12696
13895
|
removed.push("AGENTS.md");
|
|
12697
13896
|
} else {
|
|
12698
13897
|
preserved.push("AGENTS.md");
|
|
12699
13898
|
}
|
|
12700
13899
|
}
|
|
12701
13900
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
12702
|
-
const target =
|
|
13901
|
+
const target = join10(root, dir, EXECUTION_SKILL_NAME);
|
|
12703
13902
|
try {
|
|
12704
|
-
const info = await
|
|
13903
|
+
const info = await stat5(target);
|
|
12705
13904
|
if (info.isDirectory()) {
|
|
12706
|
-
await
|
|
13905
|
+
await rm6(target, { recursive: true, force: true });
|
|
12707
13906
|
removed.push(`${dir}/${EXECUTION_SKILL_NAME}`);
|
|
12708
13907
|
}
|
|
12709
13908
|
} catch (error) {
|
|
@@ -12722,15 +13921,15 @@ async function removeSkillPack(bundleDir, pack) {
|
|
|
12722
13921
|
if (entry !== void 0) {
|
|
12723
13922
|
for (const skill of entry.skills) {
|
|
12724
13923
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
12725
|
-
const targetDir =
|
|
12726
|
-
const skillMd =
|
|
13924
|
+
const targetDir = join10(root, dir, skill.name);
|
|
13925
|
+
const skillMd = join10(targetDir, "SKILL.md");
|
|
12727
13926
|
if (!await isFile(skillMd)) continue;
|
|
12728
13927
|
const targetHash = await hashSkillDirectory(targetDir);
|
|
12729
13928
|
if (targetHash !== skill.sha256) {
|
|
12730
13929
|
preserved.push(`${dir}/${skill.name}/SKILL.md`);
|
|
12731
13930
|
continue;
|
|
12732
13931
|
}
|
|
12733
|
-
await
|
|
13932
|
+
await rm6(targetDir, { recursive: true, force: true });
|
|
12734
13933
|
removed.push(`${dir}/${skill.name}/SKILL.md`);
|
|
12735
13934
|
}
|
|
12736
13935
|
}
|
|
@@ -12764,13 +13963,13 @@ async function restoreSkillPack(bundleDir, packArgument) {
|
|
|
12764
13963
|
missing.push(name);
|
|
12765
13964
|
continue;
|
|
12766
13965
|
}
|
|
12767
|
-
const
|
|
13966
|
+
const sha2562 = await hashSkillDirectory(source);
|
|
12768
13967
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
12769
|
-
const targetDir =
|
|
13968
|
+
const targetDir = join10(root, dir, name);
|
|
12770
13969
|
await replaceDirectory(source, targetDir);
|
|
12771
13970
|
restored.push(`${dir}/${name}`);
|
|
12772
13971
|
}
|
|
12773
|
-
skills.push({ name, source: `${pack}/${name}`, sha256 });
|
|
13972
|
+
skills.push({ name, source: `${pack}/${name}`, sha256: sha2562 });
|
|
12774
13973
|
}
|
|
12775
13974
|
const manifestEntry = { name: pack, skills, missing: packMissing };
|
|
12776
13975
|
const index = updatedPacks.findIndex((candidate) => candidate.name === pack);
|
|
@@ -12792,10 +13991,10 @@ async function disableSkill(bundleDir, name) {
|
|
|
12792
13991
|
const root = resolve3(bundleDir);
|
|
12793
13992
|
const disabled = [];
|
|
12794
13993
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
12795
|
-
const targetDir =
|
|
13994
|
+
const targetDir = join10(root, dir, name);
|
|
12796
13995
|
const disabledDir = `${targetDir}.disabled`;
|
|
12797
13996
|
if (!await isDirectory(targetDir)) continue;
|
|
12798
|
-
if (await isDirectory(disabledDir)) await
|
|
13997
|
+
if (await isDirectory(disabledDir)) await rm6(disabledDir, { recursive: true, force: true });
|
|
12799
13998
|
await rename2(targetDir, disabledDir);
|
|
12800
13999
|
disabled.push(`${dir}/${name}`);
|
|
12801
14000
|
}
|
|
@@ -12805,10 +14004,10 @@ async function enableSkill(bundleDir, name) {
|
|
|
12805
14004
|
const root = resolve3(bundleDir);
|
|
12806
14005
|
const enabled = [];
|
|
12807
14006
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
12808
|
-
const targetDir =
|
|
14007
|
+
const targetDir = join10(root, dir, name);
|
|
12809
14008
|
const disabledDir = `${targetDir}.disabled`;
|
|
12810
14009
|
if (!await isDirectory(disabledDir)) continue;
|
|
12811
|
-
if (await isDirectory(targetDir)) await
|
|
14010
|
+
if (await isDirectory(targetDir)) await rm6(disabledDir, { recursive: true, force: true });
|
|
12812
14011
|
else {
|
|
12813
14012
|
await rename2(disabledDir, targetDir);
|
|
12814
14013
|
enabled.push(`${dir}/${name}`);
|
|
@@ -12972,21 +14171,21 @@ async function checkProject(deps, credentials, projectId) {
|
|
|
12972
14171
|
}
|
|
12973
14172
|
async function isFile2(path) {
|
|
12974
14173
|
try {
|
|
12975
|
-
return (await
|
|
14174
|
+
return (await stat6(path)).isFile();
|
|
12976
14175
|
} catch {
|
|
12977
14176
|
return false;
|
|
12978
14177
|
}
|
|
12979
14178
|
}
|
|
12980
14179
|
async function isDirectory2(path) {
|
|
12981
14180
|
try {
|
|
12982
|
-
return (await
|
|
14181
|
+
return (await stat6(path)).isDirectory();
|
|
12983
14182
|
} catch {
|
|
12984
14183
|
return false;
|
|
12985
14184
|
}
|
|
12986
14185
|
}
|
|
12987
14186
|
async function listMarkdownFiles(directory) {
|
|
12988
14187
|
try {
|
|
12989
|
-
const entries = await
|
|
14188
|
+
const entries = await readdir7(directory, { withFileTypes: true });
|
|
12990
14189
|
return entries.filter((entry) => entry.isFile() && entry.name.toLowerCase().endsWith(".md")).map((entry) => entry.name);
|
|
12991
14190
|
} catch {
|
|
12992
14191
|
return [];
|
|
@@ -12994,17 +14193,18 @@ async function listMarkdownFiles(directory) {
|
|
|
12994
14193
|
}
|
|
12995
14194
|
async function checkBundle(bundleDir) {
|
|
12996
14195
|
const missing = [];
|
|
12997
|
-
|
|
12998
|
-
|
|
14196
|
+
const contract = contractRoot(bundleDir);
|
|
14197
|
+
if (!await isFile2(join11(contract, "PRD.md"))) missing.push("PRD.md");
|
|
14198
|
+
const specsDir = join11(contract, "specs");
|
|
12999
14199
|
if (!await isDirectory2(specsDir)) {
|
|
13000
14200
|
missing.push("specs/");
|
|
13001
14201
|
} else {
|
|
13002
14202
|
const markdown = await listMarkdownFiles(specsDir);
|
|
13003
|
-
const readme = await
|
|
14203
|
+
const readme = await readFile10(join11(specsDir, "SPECS.md"), "utf8").catch(() => "");
|
|
13004
14204
|
const hasContent = markdown.some((name) => name.toLowerCase() !== "specs.md") || specReadmeIsContent(readme);
|
|
13005
14205
|
if (!hasContent) missing.push("specs/*.md (konten)");
|
|
13006
14206
|
}
|
|
13007
|
-
const tasksDir =
|
|
14207
|
+
const tasksDir = join11(contract, "tasks");
|
|
13008
14208
|
if (!await isDirectory2(tasksDir)) {
|
|
13009
14209
|
missing.push("tasks/");
|
|
13010
14210
|
} else {
|
|
@@ -13052,6 +14252,36 @@ async function checkSidecar(bundleDir) {
|
|
|
13052
14252
|
}
|
|
13053
14253
|
async function checkDrift(bundleDir) {
|
|
13054
14254
|
try {
|
|
14255
|
+
const local = await snapshotContract(bundleDir);
|
|
14256
|
+
const hasContract = hasContractArtifacts(local);
|
|
14257
|
+
const ledger = hasContract ? await readContractLedger(bundleDir) : null;
|
|
14258
|
+
if (hasContract && ledger !== null) {
|
|
14259
|
+
const stale = computeStaleness(ledger.derivation, local);
|
|
14260
|
+
if (stale.specsStale) {
|
|
14261
|
+
return makeCheck(
|
|
14262
|
+
"drift",
|
|
14263
|
+
"warn",
|
|
14264
|
+
"PRD berubah: specs masih dari versi PRD lama. Jalankan `jioogen align`."
|
|
14265
|
+
);
|
|
14266
|
+
}
|
|
14267
|
+
if (stale.tasksStale) {
|
|
14268
|
+
return makeCheck(
|
|
14269
|
+
"drift",
|
|
14270
|
+
"warn",
|
|
14271
|
+
"Specs/PRD berubah: tasks masih dari versi lama. Jalankan `jioogen align`."
|
|
14272
|
+
);
|
|
14273
|
+
}
|
|
14274
|
+
}
|
|
14275
|
+
if (hasContract && ledger === null) {
|
|
14276
|
+
const contractCheck = await inspectBundle(bundleDir);
|
|
14277
|
+
if (!contractCheck.ok) {
|
|
14278
|
+
return makeCheck(
|
|
14279
|
+
"drift",
|
|
14280
|
+
"warn",
|
|
14281
|
+
"Baseline kontrak belum ada dan gate bundle gagal; jalankan `jioogen align` agar PRD, specs, dan tasks diselaraskan."
|
|
14282
|
+
);
|
|
14283
|
+
}
|
|
14284
|
+
}
|
|
13055
14285
|
const state = await readState(bundleDir);
|
|
13056
14286
|
if (state === null) {
|
|
13057
14287
|
return makeCheck("drift", "pass", "Belum ada sidecar; drift belum bisa dibandingkan.");
|
|
@@ -13067,10 +14297,10 @@ async function checkDrift(bundleDir) {
|
|
|
13067
14297
|
}
|
|
13068
14298
|
}
|
|
13069
14299
|
async function checkRecovery(bundleDir) {
|
|
13070
|
-
const path =
|
|
14300
|
+
const path = join11(contractRoot(bundleDir), "tasks/.execution/recovery.json");
|
|
13071
14301
|
let raw;
|
|
13072
14302
|
try {
|
|
13073
|
-
raw = await
|
|
14303
|
+
raw = await readFile10(path, "utf8");
|
|
13074
14304
|
} catch (error) {
|
|
13075
14305
|
if (isMissingFile5(error)) {
|
|
13076
14306
|
return makeCheck("recovery", "pass", "Belum ada recovery journal.");
|
|
@@ -13101,7 +14331,7 @@ async function checkLock(bundleDir) {
|
|
|
13101
14331
|
const target = lockPath(bundleDir);
|
|
13102
14332
|
let info;
|
|
13103
14333
|
try {
|
|
13104
|
-
info = await
|
|
14334
|
+
info = await stat6(target);
|
|
13105
14335
|
} catch (error) {
|
|
13106
14336
|
if (isMissingFile5(error)) {
|
|
13107
14337
|
return makeCheck("lock", "pass", "Tidak ada lock; sidecar bebas ditulis.");
|
|
@@ -13127,7 +14357,7 @@ async function checkLock(bundleDir) {
|
|
|
13127
14357
|
async function checkAgents(bundleDir) {
|
|
13128
14358
|
let content;
|
|
13129
14359
|
try {
|
|
13130
|
-
content = await
|
|
14360
|
+
content = await readFile10(join11(bundleDir, "AGENTS.md"), "utf8");
|
|
13131
14361
|
} catch (error) {
|
|
13132
14362
|
if (isMissingFile5(error)) {
|
|
13133
14363
|
return makeCheck(
|
|
@@ -13157,7 +14387,7 @@ async function checkAgents(bundleDir) {
|
|
|
13157
14387
|
async function checkExecutionSkill(bundleDir) {
|
|
13158
14388
|
const missing = [];
|
|
13159
14389
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
13160
|
-
const target =
|
|
14390
|
+
const target = join11(bundleDir, dir, EXECUTION_SKILL_NAME, "SKILL.md");
|
|
13161
14391
|
if (!await isFile2(target)) missing.push(dir);
|
|
13162
14392
|
}
|
|
13163
14393
|
if (missing.length > 0) {
|
|
@@ -13205,8 +14435,8 @@ async function checkSkillPacks(bundleDir) {
|
|
|
13205
14435
|
for (const skill of pack.skills) {
|
|
13206
14436
|
let matched = false;
|
|
13207
14437
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
13208
|
-
const target =
|
|
13209
|
-
if (!await isFile2(
|
|
14438
|
+
const target = join11(bundleDir, dir, skill.name);
|
|
14439
|
+
if (!await isFile2(join11(target, "SKILL.md"))) continue;
|
|
13210
14440
|
try {
|
|
13211
14441
|
if (await hashSkillDirectory(target) === skill.sha256) {
|
|
13212
14442
|
matched = true;
|
|
@@ -13235,44 +14465,66 @@ async function checkSkillPacks(bundleDir) {
|
|
|
13235
14465
|
var CAP_ID_RE = /\bCAP-[A-Z0-9-]+\b/g;
|
|
13236
14466
|
var CAP_PLACEHOLDER_RE = /^CAP-X+$/;
|
|
13237
14467
|
var TASK_CAP_RE = /^\s*cap:\s*(CAP-[A-Z0-9-]+)/im;
|
|
14468
|
+
function capabilityModelNotRequired(content) {
|
|
14469
|
+
const notRequired = /* @__PURE__ */ new Set();
|
|
14470
|
+
const start = content.search(/^##\s+Capability Model\s*$/im);
|
|
14471
|
+
if (start === -1) return notRequired;
|
|
14472
|
+
const section3 = content.slice(start);
|
|
14473
|
+
const next = section3.slice(1).search(/^##\s+/m);
|
|
14474
|
+
const body = next === -1 ? section3 : section3.slice(0, next + 1);
|
|
14475
|
+
for (const line of body.split("\n")) {
|
|
14476
|
+
const trimmed = line.trim();
|
|
14477
|
+
if (!trimmed.startsWith("|")) continue;
|
|
14478
|
+
const cells = trimmed.replace(/^\|/, "").replace(/\|$/, "").split("|").map((cell) => cell.trim());
|
|
14479
|
+
const cap = (cells[0] ?? "").toUpperCase();
|
|
14480
|
+
if (!/^CAP-[A-Z0-9-]+$/.test(cap) || CAP_PLACEHOLDER_RE.test(cap)) continue;
|
|
14481
|
+
if (!/^(?:yes|true|required|wajib)$/i.test(cells[1] ?? "")) notRequired.add(cap);
|
|
14482
|
+
}
|
|
14483
|
+
return notRequired;
|
|
14484
|
+
}
|
|
13238
14485
|
async function collectMarkdownFiles2(root, prefix = "") {
|
|
13239
|
-
const dir =
|
|
14486
|
+
const dir = join11(root, prefix);
|
|
13240
14487
|
let entries;
|
|
13241
14488
|
try {
|
|
13242
|
-
entries = await
|
|
14489
|
+
entries = await readdir7(dir, { withFileTypes: true });
|
|
13243
14490
|
} catch {
|
|
13244
14491
|
return [];
|
|
13245
14492
|
}
|
|
13246
14493
|
const files = [];
|
|
13247
14494
|
for (const entry of entries) {
|
|
13248
|
-
const
|
|
13249
|
-
if (entry.isDirectory()) files.push(...await collectMarkdownFiles2(root,
|
|
13250
|
-
else if (entry.isFile() && entry.name.endsWith(".md")) files.push(
|
|
14495
|
+
const relative3 = prefix.length === 0 ? entry.name : `${prefix}/${entry.name}`;
|
|
14496
|
+
if (entry.isDirectory()) files.push(...await collectMarkdownFiles2(root, relative3));
|
|
14497
|
+
else if (entry.isFile() && entry.name.endsWith(".md")) files.push(relative3);
|
|
13251
14498
|
}
|
|
13252
14499
|
return files;
|
|
13253
14500
|
}
|
|
13254
14501
|
async function checkCapabilityCoverage(bundleDir) {
|
|
14502
|
+
const contract = contractRoot(bundleDir);
|
|
13255
14503
|
const taskCaps = /* @__PURE__ */ new Map();
|
|
13256
|
-
for (const
|
|
13257
|
-
if (
|
|
13258
|
-
const content = await
|
|
14504
|
+
for (const relative3 of await collectMarkdownFiles2(contract, "tasks")) {
|
|
14505
|
+
if (relative3 === BUNDLE_PATHS.TASKS_INDEX) continue;
|
|
14506
|
+
const content = await readFile10(join11(contract, relative3), "utf8");
|
|
13259
14507
|
const cap = TASK_CAP_RE.exec(content)?.[1]?.toUpperCase();
|
|
13260
14508
|
if (cap === void 0) continue;
|
|
13261
|
-
taskCaps.set(cap,
|
|
14509
|
+
taskCaps.set(cap, relative3);
|
|
13262
14510
|
}
|
|
13263
14511
|
const specCaps = /* @__PURE__ */ new Set();
|
|
13264
|
-
|
|
13265
|
-
|
|
14512
|
+
const notRequiredCaps = /* @__PURE__ */ new Set();
|
|
14513
|
+
for (const relative3 of await collectMarkdownFiles2(contract, "specs")) {
|
|
14514
|
+
const content = await readFile10(join11(contract, relative3), "utf8");
|
|
13266
14515
|
for (const match of content.matchAll(CAP_ID_RE)) {
|
|
13267
14516
|
const id = match[0].toUpperCase();
|
|
13268
14517
|
if (CAP_PLACEHOLDER_RE.test(id)) continue;
|
|
13269
14518
|
specCaps.add(id);
|
|
13270
14519
|
}
|
|
14520
|
+
for (const cap of capabilityModelNotRequired(content)) notRequiredCaps.add(cap);
|
|
13271
14521
|
}
|
|
13272
14522
|
if (taskCaps.size === 0 && specCaps.size === 0) {
|
|
13273
14523
|
return makeCheck("capability-coverage", "pass", "Tidak ada CAP-* (bundle legacy).");
|
|
13274
14524
|
}
|
|
13275
|
-
const missingTask = [...specCaps].filter(
|
|
14525
|
+
const missingTask = [...specCaps].filter(
|
|
14526
|
+
(cap) => !taskCaps.has(cap) && !notRequiredCaps.has(cap)
|
|
14527
|
+
);
|
|
13276
14528
|
const missingSpec = [...taskCaps.keys()].filter((cap) => !specCaps.has(cap));
|
|
13277
14529
|
const issues = [];
|
|
13278
14530
|
if (missingTask.length > 0) {
|
|
@@ -13310,18 +14562,18 @@ async function checkDuplicates(bundleDir) {
|
|
|
13310
14562
|
}
|
|
13311
14563
|
const dirsByName = /* @__PURE__ */ new Map();
|
|
13312
14564
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
13313
|
-
const root =
|
|
14565
|
+
const root = join11(bundleDir, dir);
|
|
13314
14566
|
if (!await isDirectory2(root)) continue;
|
|
13315
14567
|
let entries;
|
|
13316
14568
|
try {
|
|
13317
|
-
entries = await
|
|
14569
|
+
entries = await readdir7(root, { withFileTypes: true });
|
|
13318
14570
|
} catch {
|
|
13319
14571
|
continue;
|
|
13320
14572
|
}
|
|
13321
14573
|
for (const entry of entries) {
|
|
13322
14574
|
if (!entry.isDirectory()) continue;
|
|
13323
14575
|
if (managed.has(entry.name)) continue;
|
|
13324
|
-
if (!await isFile2(
|
|
14576
|
+
if (!await isFile2(join11(root, entry.name, "SKILL.md"))) continue;
|
|
13325
14577
|
const owners = dirsByName.get(entry.name) ?? [];
|
|
13326
14578
|
owners.push(dir);
|
|
13327
14579
|
dirsByName.set(entry.name, owners);
|
|
@@ -13341,7 +14593,7 @@ async function checkDuplicates(bundleDir) {
|
|
|
13341
14593
|
async function checkHarness(bundleDir) {
|
|
13342
14594
|
const detected = [];
|
|
13343
14595
|
for (const dir of AGENT_SKILL_DIRS) {
|
|
13344
|
-
if (await isDirectory2(
|
|
14596
|
+
if (await isDirectory2(join11(bundleDir, dir))) detected.push(dir);
|
|
13345
14597
|
}
|
|
13346
14598
|
if (detected.length === 0) {
|
|
13347
14599
|
return makeCheck("harness", "pass", "Tidak ada direktori harness terdeteksi.");
|
|
@@ -13395,7 +14647,7 @@ async function applyFixes(options, deps, checks) {
|
|
|
13395
14647
|
let changed = false;
|
|
13396
14648
|
if (checks.some((check) => check.id === "lock" && check.fixable === true)) {
|
|
13397
14649
|
try {
|
|
13398
|
-
await
|
|
14650
|
+
await rm7(lockPath(options.bundleDir), { force: true });
|
|
13399
14651
|
changed = true;
|
|
13400
14652
|
} catch {
|
|
13401
14653
|
}
|
|
@@ -13438,8 +14690,8 @@ function formatTable(headers, rows) {
|
|
|
13438
14690
|
|
|
13439
14691
|
// src/recovery.ts
|
|
13440
14692
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
13441
|
-
import { mkdir as
|
|
13442
|
-
import { dirname as
|
|
14693
|
+
import { mkdir as mkdir8, readFile as readFile11, rename as rename3, rm as rm8, writeFile as writeFile8 } from "node:fs/promises";
|
|
14694
|
+
import { dirname as dirname7, join as join12 } from "node:path";
|
|
13443
14695
|
var RECOVERY_PATH = "tasks/.execution/recovery.json";
|
|
13444
14696
|
var RECOVERY_BUDGET = { maxAttempts: 3 };
|
|
13445
14697
|
var RECOVERY_BASE_ATTEMPTS = 3;
|
|
@@ -13451,7 +14703,7 @@ function recoveryBudget(input) {
|
|
|
13451
14703
|
return Math.min(budget, RECOVERY_MAX_ATTEMPTS);
|
|
13452
14704
|
}
|
|
13453
14705
|
function recoveryPath(bundleDir) {
|
|
13454
|
-
return
|
|
14706
|
+
return join12(bundleDir, RECOVERY_PATH);
|
|
13455
14707
|
}
|
|
13456
14708
|
function emptyJournal() {
|
|
13457
14709
|
return { schemaVersion: 1, tasks: {} };
|
|
@@ -13466,7 +14718,7 @@ function isJournal(value) {
|
|
|
13466
14718
|
async function readRecovery(bundleDir) {
|
|
13467
14719
|
let raw;
|
|
13468
14720
|
try {
|
|
13469
|
-
raw = await
|
|
14721
|
+
raw = await readFile11(recoveryPath(bundleDir), "utf8");
|
|
13470
14722
|
} catch {
|
|
13471
14723
|
return emptyJournal();
|
|
13472
14724
|
}
|
|
@@ -13491,14 +14743,14 @@ function classifyFailure(input) {
|
|
|
13491
14743
|
}
|
|
13492
14744
|
async function writeRecovery(bundleDir, journal) {
|
|
13493
14745
|
const target = recoveryPath(bundleDir);
|
|
13494
|
-
await
|
|
14746
|
+
await mkdir8(dirname7(target), { recursive: true });
|
|
13495
14747
|
const temp = `${target}.${process.pid}.${randomUUID2()}.tmp`;
|
|
13496
14748
|
try {
|
|
13497
|
-
await
|
|
14749
|
+
await writeFile8(temp, `${JSON.stringify(journal, null, 2)}
|
|
13498
14750
|
`, "utf8");
|
|
13499
14751
|
await rename3(temp, target);
|
|
13500
14752
|
} catch (error) {
|
|
13501
|
-
await
|
|
14753
|
+
await rm8(temp, { force: true }).catch(() => {
|
|
13502
14754
|
});
|
|
13503
14755
|
throw error;
|
|
13504
14756
|
}
|
|
@@ -13581,7 +14833,7 @@ function describeRecovery(entry) {
|
|
|
13581
14833
|
}
|
|
13582
14834
|
|
|
13583
14835
|
// src/session.ts
|
|
13584
|
-
import { rm as
|
|
14836
|
+
import { rm as rm9, stat as stat7 } from "node:fs/promises";
|
|
13585
14837
|
import { resolve as resolve4 } from "node:path";
|
|
13586
14838
|
var LOCK_STALE_MS3 = 1e4;
|
|
13587
14839
|
var CHANGE_REQUEST_PREFIX = "Perubahan diminta:";
|
|
@@ -13734,13 +14986,13 @@ async function removeStaleLock2(bundleDir) {
|
|
|
13734
14986
|
const target = lockPath(bundleDir);
|
|
13735
14987
|
let info;
|
|
13736
14988
|
try {
|
|
13737
|
-
info = await
|
|
14989
|
+
info = await stat7(target);
|
|
13738
14990
|
} catch (error) {
|
|
13739
14991
|
if (isMissingFile6(error)) return;
|
|
13740
14992
|
throw error;
|
|
13741
14993
|
}
|
|
13742
14994
|
if (Date.now() - info.mtimeMs <= LOCK_STALE_MS3) return;
|
|
13743
|
-
await
|
|
14995
|
+
await rm9(target, { force: true });
|
|
13744
14996
|
}
|
|
13745
14997
|
function envFirst(primary, legacy) {
|
|
13746
14998
|
const value = process.env[primary]?.trim();
|
|
@@ -13754,8 +15006,8 @@ function isMissingFile6(error) {
|
|
|
13754
15006
|
|
|
13755
15007
|
// src/zip.ts
|
|
13756
15008
|
var import_adm_zip = __toESM(require_adm_zip(), 1);
|
|
13757
|
-
import { mkdir as
|
|
13758
|
-
import { dirname as
|
|
15009
|
+
import { mkdir as mkdir9, writeFile as writeFile9 } from "node:fs/promises";
|
|
15010
|
+
import { dirname as dirname8, resolve as resolve5, sep } from "node:path";
|
|
13759
15011
|
var IGNORED_PREFIXES = [
|
|
13760
15012
|
".git/",
|
|
13761
15013
|
"node_modules/",
|
|
@@ -13776,9 +15028,9 @@ var TOOL_CALL_LEAK_RE = /\r?\n[A-Za-z0-9_-]+">\s*\/[^\n]*(?=\r?\n|$)/g;
|
|
|
13776
15028
|
function sanitizeMarkdown(content) {
|
|
13777
15029
|
return content.replace(TOOL_CALL_LEAK_RE, "").replace(/\n{3,}/g, "\n\n");
|
|
13778
15030
|
}
|
|
13779
|
-
function isIgnoredBundlePath(
|
|
13780
|
-
if (IGNORED_FILES.has(
|
|
13781
|
-
return IGNORED_PREFIXES.some((prefix) =>
|
|
15031
|
+
function isIgnoredBundlePath(relative3) {
|
|
15032
|
+
if (IGNORED_FILES.has(relative3)) return true;
|
|
15033
|
+
return IGNORED_PREFIXES.some((prefix) => relative3.startsWith(prefix));
|
|
13782
15034
|
}
|
|
13783
15035
|
async function extractBundle(bytes, targetDir) {
|
|
13784
15036
|
const root = resolve5(targetDir);
|
|
@@ -13786,21 +15038,21 @@ async function extractBundle(bytes, targetDir) {
|
|
|
13786
15038
|
const written = [];
|
|
13787
15039
|
for (const entry of zip.getEntries()) {
|
|
13788
15040
|
if (entry.isDirectory) continue;
|
|
13789
|
-
const
|
|
13790
|
-
const segments =
|
|
15041
|
+
const relative3 = entry.entryName.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
15042
|
+
const segments = relative3.split("/");
|
|
13791
15043
|
if (segments.some((segment) => segment.length === 0 || segment === "." || segment === "..")) {
|
|
13792
15044
|
throw new Error(`Path bundle tidak aman: ${entry.entryName}`);
|
|
13793
15045
|
}
|
|
13794
|
-
if (isIgnoredBundlePath(
|
|
13795
|
-
const destination =
|
|
15046
|
+
if (isIgnoredBundlePath(relative3)) continue;
|
|
15047
|
+
const destination = resolveProjectPath(root, relative3);
|
|
13796
15048
|
if (!destination.startsWith(`${root}${sep}`)) {
|
|
13797
15049
|
throw new Error(`Path bundle keluar dari direktori target: ${entry.entryName}`);
|
|
13798
15050
|
}
|
|
13799
|
-
await
|
|
15051
|
+
await mkdir9(dirname8(destination), { recursive: true });
|
|
13800
15052
|
const raw = entry.getData();
|
|
13801
|
-
const data =
|
|
13802
|
-
await
|
|
13803
|
-
written.push(
|
|
15053
|
+
const data = relative3.endsWith(".md") ? Buffer.from(sanitizeMarkdown(raw.toString("utf8")), "utf8") : raw;
|
|
15054
|
+
await writeFile9(destination, data);
|
|
15055
|
+
written.push(relative3);
|
|
13804
15056
|
}
|
|
13805
15057
|
return written;
|
|
13806
15058
|
}
|
|
@@ -13955,9 +15207,23 @@ async function pullCommand(projectId, options) {
|
|
|
13955
15207
|
const target = resolve6(options.dir ?? projectId);
|
|
13956
15208
|
await assertPullTarget(target, projectId, options.force === true);
|
|
13957
15209
|
const bytes = await client.getBytes(projectPath(projectId, "/bundle"));
|
|
15210
|
+
const layout = migrateContractLayout(target);
|
|
15211
|
+
ensureDocsTree(target);
|
|
15212
|
+
writeDocsReadme(target);
|
|
13958
15213
|
const written = await extractBundle(bytes, target);
|
|
13959
15214
|
await clearBaseline(target).catch(() => {
|
|
13960
15215
|
});
|
|
15216
|
+
migrateKnownDocs(target);
|
|
15217
|
+
const localContract = await snapshotContract(target);
|
|
15218
|
+
const serverContract = await client.getWorkspaceArtifacts(projectId).then(serverStateFromWorkspace).catch(() => null);
|
|
15219
|
+
await writeContractLedger(
|
|
15220
|
+
target,
|
|
15221
|
+
buildContractLedger(
|
|
15222
|
+
localContract,
|
|
15223
|
+
serverContract,
|
|
15224
|
+
serverContract?.derivation ?? freshDerivation(localContract)
|
|
15225
|
+
)
|
|
15226
|
+
);
|
|
13961
15227
|
const uiQuality = options.uiQuality ?? await readUiQuality(target);
|
|
13962
15228
|
const skills = await installAgentSkills(target, {
|
|
13963
15229
|
noSkills: skillsDisabled(options),
|
|
@@ -13975,6 +15241,9 @@ async function pullCommand(projectId, options) {
|
|
|
13975
15241
|
console.log(JSON.stringify({ projectId, target, files: written, skills }, null, 2));
|
|
13976
15242
|
return;
|
|
13977
15243
|
}
|
|
15244
|
+
if (layout.migrated && layout.moved.length > 0) {
|
|
15245
|
+
console.log("Struktur dokumen dirapikan: kontrak dipindah ke docs/00-contract.");
|
|
15246
|
+
}
|
|
13978
15247
|
console.log(`Pulled ${written.length} file ke ${target}`);
|
|
13979
15248
|
console.log("Project ter-bind lewat .jioogen/project.json.");
|
|
13980
15249
|
console.log(`Skills eksekusi terpasang: ${skills.written.length} file.`);
|
|
@@ -13985,6 +15254,11 @@ async function linkCommand(projectId, options) {
|
|
|
13985
15254
|
const target = resolve6(options.dir ?? process.cwd());
|
|
13986
15255
|
await assertLinkTarget(target, projectId);
|
|
13987
15256
|
await verifyProjectAccess(client, projectId);
|
|
15257
|
+
const layout = migrateContractLayout(target);
|
|
15258
|
+
ensureDocsTree(target);
|
|
15259
|
+
migrateKnownDocs(target);
|
|
15260
|
+
writeDocsReadme(target);
|
|
15261
|
+
await client.ensureProjectLayout(projectId).catch(() => null);
|
|
13988
15262
|
const taskMode = options.taskMode ?? await readTaskMode(target);
|
|
13989
15263
|
const uiQuality = options.uiQuality ?? await readUiQuality(target);
|
|
13990
15264
|
await writeProjectLink(target, {
|
|
@@ -13999,12 +15273,25 @@ async function linkCommand(projectId, options) {
|
|
|
13999
15273
|
noSkills: skillsDisabled(options),
|
|
14000
15274
|
uiQuality
|
|
14001
15275
|
});
|
|
14002
|
-
const
|
|
15276
|
+
const localContract = await snapshotContract(target);
|
|
15277
|
+
const serverContract = await client.getWorkspaceArtifacts(projectId).then(serverStateFromWorkspace).catch(() => null);
|
|
15278
|
+
await writeContractLedger(
|
|
15279
|
+
target,
|
|
15280
|
+
buildContractLedger(
|
|
15281
|
+
localContract,
|
|
15282
|
+
serverContract,
|
|
15283
|
+
serverContract?.derivation ?? freshDerivation(localContract)
|
|
15284
|
+
)
|
|
15285
|
+
);
|
|
15286
|
+
const linkedFile = join13(target, ".jioogen", "project.json");
|
|
14003
15287
|
if (options.json === true) {
|
|
14004
15288
|
console.log(JSON.stringify({ projectId, target, apiUrl, linkedFile, skills }, null, 2));
|
|
14005
15289
|
return;
|
|
14006
15290
|
}
|
|
14007
15291
|
console.log(`Project ${projectId} ter-bind ke ${target}.`);
|
|
15292
|
+
if (layout.migrated && layout.moved.length > 0) {
|
|
15293
|
+
console.log("Struktur dokumen dirapikan: kontrak dipindah ke docs/00-contract.");
|
|
15294
|
+
}
|
|
14008
15295
|
console.log(`File link: ${linkedFile} (API ${apiUrl}).`);
|
|
14009
15296
|
console.log(`Skills eksekusi terpasang: ${skills.written.length} file.`);
|
|
14010
15297
|
printSkillPacks(skills.packs, skills.missing, skills.custom, skills.conflicts);
|
|
@@ -14173,21 +15460,152 @@ function printSkillPacks(packs, missing, custom2 = [], conflicts = []) {
|
|
|
14173
15460
|
);
|
|
14174
15461
|
}
|
|
14175
15462
|
}
|
|
15463
|
+
async function alignCommand(options) {
|
|
15464
|
+
const local = await resolveLocalBundle(options);
|
|
15465
|
+
migrateContractLayout(local.bundleDir);
|
|
15466
|
+
ensureDocsTree(local.bundleDir);
|
|
15467
|
+
migrateKnownDocs(local.bundleDir);
|
|
15468
|
+
writeDocsReadme(local.bundleDir);
|
|
15469
|
+
let client;
|
|
15470
|
+
const noSync = options.noSync === true || process.env.JIOOGEN_NO_SYNC === "1";
|
|
15471
|
+
if (!noSync) {
|
|
15472
|
+
try {
|
|
15473
|
+
const api = await resolveApi({ api: options.api ?? local.linkedApiUrl });
|
|
15474
|
+
client = api.client;
|
|
15475
|
+
} catch {
|
|
15476
|
+
client = void 0;
|
|
15477
|
+
}
|
|
15478
|
+
}
|
|
15479
|
+
const autoDisabled = process.env.JIOOGEN_AUTO_ALIGN === "0";
|
|
15480
|
+
const result = await alignBundle(local.bundleDir, {
|
|
15481
|
+
...client === void 0 ? {} : { client },
|
|
15482
|
+
projectId: local.projectId,
|
|
15483
|
+
...autoDisabled ? {
|
|
15484
|
+
runAuthoring: async () => ({
|
|
15485
|
+
ok: false,
|
|
15486
|
+
error: "Authoring otomatis dimatikan (JIOOGEN_AUTO_ALIGN=0)."
|
|
15487
|
+
})
|
|
15488
|
+
} : {}
|
|
15489
|
+
});
|
|
15490
|
+
if (options.json === true) {
|
|
15491
|
+
console.log(JSON.stringify(result, null, 2));
|
|
15492
|
+
} else {
|
|
15493
|
+
console.log(formatAlign(result));
|
|
15494
|
+
}
|
|
15495
|
+
if (!result.ok) process.exitCode = 1;
|
|
15496
|
+
}
|
|
15497
|
+
async function docsCommand(options, subcommand) {
|
|
15498
|
+
const link = await findProjectLink(options.dir ?? process.cwd());
|
|
15499
|
+
const bundleDir = resolve6(link?.bundleDir ?? options.dir ?? process.cwd());
|
|
15500
|
+
if (subcommand === "migrate") {
|
|
15501
|
+
const contract = migrateContractLayout(bundleDir, { dryRun: options.dryRun === true });
|
|
15502
|
+
const docs = migrateKnownDocs(bundleDir, { dryRun: options.dryRun === true });
|
|
15503
|
+
if (options.dryRun !== true) {
|
|
15504
|
+
ensureDocsTree(bundleDir);
|
|
15505
|
+
writeDocsReadme(bundleDir);
|
|
15506
|
+
}
|
|
15507
|
+
if (options.json === true) {
|
|
15508
|
+
console.log(JSON.stringify({ contract, docs, dryRun: options.dryRun === true }, null, 2));
|
|
15509
|
+
return;
|
|
15510
|
+
}
|
|
15511
|
+
if (contract.moved.length === 0 && docs.moved.length === 0) {
|
|
15512
|
+
console.log("Dokumen sudah rapi; tidak ada yang dipindah.");
|
|
15513
|
+
return;
|
|
15514
|
+
}
|
|
15515
|
+
for (const move of [...contract.moved, ...docs.moved]) console.log(`- ${move}`);
|
|
15516
|
+
if (options.dryRun === true) console.log("(dry-run: belum ada file yang dipindah)");
|
|
15517
|
+
return;
|
|
15518
|
+
}
|
|
15519
|
+
if (subcommand === "index") {
|
|
15520
|
+
ensureDocsTree(bundleDir);
|
|
15521
|
+
writeDocsReadme(bundleDir, true);
|
|
15522
|
+
console.log("docs/README.md ditulis ulang.");
|
|
15523
|
+
return;
|
|
15524
|
+
}
|
|
15525
|
+
if (subcommand === "scan") {
|
|
15526
|
+
const rootEntries = await readdir8(bundleDir, { withFileTypes: true }).catch(() => []);
|
|
15527
|
+
const misplaced = rootEntries.filter(
|
|
15528
|
+
(entry) => entry.isFile() && entry.name.toLowerCase().endsWith(".md") && entry.name.toLowerCase() !== "agents.md" && entry.name.toLowerCase() !== "prd.md"
|
|
15529
|
+
).map((entry) => entry.name);
|
|
15530
|
+
const result = { misplaced, docsReadme: existsSync3(join13(bundleDir, "docs", "README.md")) };
|
|
15531
|
+
if (options.json === true) console.log(JSON.stringify(result, null, 2));
|
|
15532
|
+
else {
|
|
15533
|
+
console.log(`Dokumen di root yang sebaiknya dipindah: ${misplaced.length}`);
|
|
15534
|
+
for (const name of misplaced) console.log(`- ${name}`);
|
|
15535
|
+
console.log(result.docsReadme ? "docs/README.md ada." : "docs/README.md belum ada.");
|
|
15536
|
+
}
|
|
15537
|
+
return;
|
|
15538
|
+
}
|
|
15539
|
+
if (subcommand === "check") {
|
|
15540
|
+
const issues = [];
|
|
15541
|
+
if (!existsSync3(join13(bundleDir, "docs", "README.md"))) issues.push("docs/README.md belum ada");
|
|
15542
|
+
if (existsSync3(join13(bundleDir, "DESIGN.md"))) issues.push("DESIGN.md masih di root");
|
|
15543
|
+
if (existsSync3(join13(bundleDir, "STACK.md"))) issues.push("STACK.md masih di root");
|
|
15544
|
+
if (issues.length > 0) {
|
|
15545
|
+
for (const issue2 of issues) console.log(`\u26A0 ${issue2}`);
|
|
15546
|
+
process.exitCode = 1;
|
|
15547
|
+
} else {
|
|
15548
|
+
console.log("Struktur dokumen rapi.");
|
|
15549
|
+
}
|
|
15550
|
+
return;
|
|
15551
|
+
}
|
|
15552
|
+
throw new UsageError("Subcommand docs: scan | migrate | index | check");
|
|
15553
|
+
}
|
|
15554
|
+
async function approveCommand(options) {
|
|
15555
|
+
const { bundleDir } = await resolveLocalBundle(options);
|
|
15556
|
+
const local = await snapshotContract(bundleDir);
|
|
15557
|
+
if (local.prd === null) {
|
|
15558
|
+
throw new UsageError("PRD.md belum ada; tidak ada yang bisa disetujui.");
|
|
15559
|
+
}
|
|
15560
|
+
const at = (/* @__PURE__ */ new Date()).toISOString();
|
|
15561
|
+
await writeApproval(bundleDir, {
|
|
15562
|
+
schemaVersion: 1,
|
|
15563
|
+
prd: {
|
|
15564
|
+
hash: local.prd,
|
|
15565
|
+
at,
|
|
15566
|
+
...options.note === void 0 ? {} : { note: options.note }
|
|
15567
|
+
}
|
|
15568
|
+
});
|
|
15569
|
+
await appendApprovalNote(bundleDir, {
|
|
15570
|
+
at,
|
|
15571
|
+
prdHash: local.prd,
|
|
15572
|
+
...options.note === void 0 ? {} : { note: options.note }
|
|
15573
|
+
});
|
|
15574
|
+
if (options.json === true) {
|
|
15575
|
+
console.log(JSON.stringify({ bundleDir, prd: local.prd, at }, null, 2));
|
|
15576
|
+
return;
|
|
15577
|
+
}
|
|
15578
|
+
console.log("PRD lokal disetujui. Versi ini boleh diselaraskan ke web.");
|
|
15579
|
+
console.log("Jalankan `jioogen align` atau `jioogen task next` untuk melanjutkan.");
|
|
15580
|
+
}
|
|
14176
15581
|
async function checkCommand(options) {
|
|
14177
15582
|
const link = await findProjectLink(options.dir ?? process.cwd());
|
|
14178
15583
|
const bundleDir = resolve6(link?.bundleDir ?? options.dir ?? process.cwd());
|
|
14179
15584
|
const result = await inspectBundle(bundleDir);
|
|
15585
|
+
const local = await snapshotContract(bundleDir);
|
|
15586
|
+
const ledger = hasContractArtifacts(local) ? await readContractLedger(bundleDir) : null;
|
|
15587
|
+
const staleness = ledger === null ? { specsStale: false, tasksStale: false, stale: false } : computeStaleness(ledger.derivation, local);
|
|
14180
15588
|
if (options.json === true) {
|
|
14181
|
-
console.log(
|
|
15589
|
+
console.log(
|
|
15590
|
+
JSON.stringify({ ...result, contract: { ledger: ledger !== null, ...staleness } }, null, 2)
|
|
15591
|
+
);
|
|
14182
15592
|
} else {
|
|
14183
15593
|
console.log(formatBundleCheck(result));
|
|
15594
|
+
if (ledger === null && hasContractArtifacts(local)) {
|
|
15595
|
+
console.log("Kontrak: baseline belum ada; jalankan `jioogen align` untuk menyelaraskan.");
|
|
15596
|
+
} else if (staleness.specsStale) {
|
|
15597
|
+
console.log("Kontrak: specs masih dari versi PRD lama. Jalankan `jioogen align`.");
|
|
15598
|
+
} else if (staleness.tasksStale) {
|
|
15599
|
+
console.log("Kontrak: tasks masih dari versi specs/PRD lama. Jalankan `jioogen align`.");
|
|
15600
|
+
}
|
|
14184
15601
|
}
|
|
14185
|
-
if (!result.ok) process.exitCode = 1;
|
|
15602
|
+
if (!result.ok || staleness.stale) process.exitCode = 1;
|
|
14186
15603
|
}
|
|
14187
15604
|
async function doctorCommand(options) {
|
|
14188
15605
|
const link = await findProjectLink(options.dir ?? process.cwd());
|
|
14189
15606
|
const bundleDir = resolve6(link?.bundleDir ?? options.dir ?? process.cwd());
|
|
14190
15607
|
const projectId = options.project ?? link?.projectId;
|
|
15608
|
+
if (options.fix === true) migrateContractLayout(bundleDir);
|
|
14191
15609
|
const report = await runDoctor({
|
|
14192
15610
|
bundleDir,
|
|
14193
15611
|
...projectId === void 0 ? {} : { projectId },
|
|
@@ -14299,7 +15717,52 @@ async function handoffCommand(options) {
|
|
|
14299
15717
|
for (const rule of payload.checkpointRules) console.log(`- ${rule}`);
|
|
14300
15718
|
}
|
|
14301
15719
|
}
|
|
15720
|
+
async function alignBeforeTask(options) {
|
|
15721
|
+
const local = await resolveLocalBundle(options);
|
|
15722
|
+
migrateContractLayout(local.bundleDir);
|
|
15723
|
+
ensureDocsTree(local.bundleDir);
|
|
15724
|
+
migrateKnownDocs(local.bundleDir);
|
|
15725
|
+
writeDocsReadme(local.bundleDir);
|
|
15726
|
+
await installAgentSkills(local.bundleDir, { noSkills: true }).catch(() => null);
|
|
15727
|
+
const contract = await snapshotContract(local.bundleDir);
|
|
15728
|
+
if (!hasContractArtifacts(contract)) return true;
|
|
15729
|
+
const ledger = await readContractLedger(local.bundleDir);
|
|
15730
|
+
const check = await inspectBundle(local.bundleDir);
|
|
15731
|
+
const stale = ledger === null ? true : computeStaleness(ledger.derivation, contract).stale;
|
|
15732
|
+
if (ledger !== null && check.ok && !stale) return true;
|
|
15733
|
+
if (options.json !== true) console.log("Kontrak belum selaras; menyelaraskan otomatis...");
|
|
15734
|
+
let client;
|
|
15735
|
+
const noSync = options.noSync === true || process.env.JIOOGEN_NO_SYNC === "1";
|
|
15736
|
+
if (!noSync) {
|
|
15737
|
+
try {
|
|
15738
|
+
const api = await resolveApi({ api: options.api ?? local.linkedApiUrl });
|
|
15739
|
+
client = api.client;
|
|
15740
|
+
} catch {
|
|
15741
|
+
client = void 0;
|
|
15742
|
+
}
|
|
15743
|
+
}
|
|
15744
|
+
const result = await alignBundle(local.bundleDir, {
|
|
15745
|
+
...client === void 0 ? {} : { client },
|
|
15746
|
+
projectId: local.projectId
|
|
15747
|
+
});
|
|
15748
|
+
if (options.json === true) {
|
|
15749
|
+
console.log(
|
|
15750
|
+
JSON.stringify(
|
|
15751
|
+
{ aligned: result.ok, blocked: result.blocked, applied: result.applied },
|
|
15752
|
+
null,
|
|
15753
|
+
2
|
|
15754
|
+
)
|
|
15755
|
+
);
|
|
15756
|
+
} else {
|
|
15757
|
+
console.log(formatAlign(result));
|
|
15758
|
+
if (!result.ok) console.log("Task tidak dipilih sampai kontrak selaras.");
|
|
15759
|
+
}
|
|
15760
|
+
if (result.ok) return true;
|
|
15761
|
+
process.exitCode = 1;
|
|
15762
|
+
return false;
|
|
15763
|
+
}
|
|
14302
15764
|
async function taskNextCommand(options) {
|
|
15765
|
+
if (!await alignBeforeTask(options)) return;
|
|
14303
15766
|
const { projectId, bundleDir, definitions, written, next } = await withLocalState(
|
|
14304
15767
|
options,
|
|
14305
15768
|
async (local) => {
|
|
@@ -14440,10 +15903,10 @@ ${items.map((item, index) => `- [ ] ${prefix}-${String(index + 1).padStart(2, "0
|
|
|
14440
15903
|
return;
|
|
14441
15904
|
}
|
|
14442
15905
|
if (authored.length > 0) {
|
|
14443
|
-
const path2 =
|
|
14444
|
-
const current = await
|
|
15906
|
+
const path2 = join13(contractRoot(local.bundleDir), "tasks", definition.file);
|
|
15907
|
+
const current = await readFile12(path2, "utf8");
|
|
14445
15908
|
const stripped = current.replace(/\n##\s+Subtasks\b[\s\S]*?(?=\n##\s|$)/i, "").replace(/\n{3,}/g, "\n\n");
|
|
14446
|
-
await
|
|
15909
|
+
await writeFile10(path2, `${stripped.trimEnd()}
|
|
14447
15910
|
|
|
14448
15911
|
${section3}`, "utf8");
|
|
14449
15912
|
console.log(
|
|
@@ -14451,10 +15914,10 @@ ${section3}`, "utf8");
|
|
|
14451
15914
|
);
|
|
14452
15915
|
return;
|
|
14453
15916
|
}
|
|
14454
|
-
const dir =
|
|
14455
|
-
const path =
|
|
14456
|
-
await
|
|
14457
|
-
await
|
|
15917
|
+
const dir = join13(local.bundleDir, ".jioogen", "breakdown");
|
|
15918
|
+
const path = join13(dir, `${definition.id}.md`);
|
|
15919
|
+
await mkdir10(dir, { recursive: true });
|
|
15920
|
+
await writeFile10(
|
|
14458
15921
|
path,
|
|
14459
15922
|
`# Breakdown ${definition.id} \u2014 ${definition.title}
|
|
14460
15923
|
|
|
@@ -14661,7 +16124,7 @@ async function stampVerification(context, definitions, ref, proof, visualSummary
|
|
|
14661
16124
|
async function resolveFallbackVerificationCommand(bundleDir, failedCommand) {
|
|
14662
16125
|
let pkgRaw;
|
|
14663
16126
|
try {
|
|
14664
|
-
pkgRaw = await
|
|
16127
|
+
pkgRaw = await readFile12(join13(bundleDir, "package.json"), "utf8");
|
|
14665
16128
|
} catch {
|
|
14666
16129
|
return null;
|
|
14667
16130
|
}
|
|
@@ -14861,7 +16324,7 @@ function verifyTimeoutMs() {
|
|
|
14861
16324
|
}
|
|
14862
16325
|
function runVerification(command, cwd, timeoutMs) {
|
|
14863
16326
|
return new Promise((resolve7) => {
|
|
14864
|
-
const child =
|
|
16327
|
+
const child = spawn2("sh", ["-c", command], { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
14865
16328
|
let stdout = "";
|
|
14866
16329
|
let stderr = "";
|
|
14867
16330
|
let timedOut = false;
|
|
@@ -14996,6 +16459,11 @@ async function statusCommand(options) {
|
|
|
14996
16459
|
async function contractUpdateBaselineCommand(options) {
|
|
14997
16460
|
const { bundleDir } = await resolveLocalBundle(options);
|
|
14998
16461
|
const newBundleHash = await updateContractBaseline(bundleDir);
|
|
16462
|
+
const localContract = await snapshotContract(bundleDir);
|
|
16463
|
+
await writeContractLedger(
|
|
16464
|
+
bundleDir,
|
|
16465
|
+
buildContractLedger(localContract, null, freshDerivation(localContract))
|
|
16466
|
+
);
|
|
14999
16467
|
console.log(`Baseline kontrak diupdate. Hash baru: ${newBundleHash}`);
|
|
15000
16468
|
console.log(`File terverifikasi: PRD.md, traceability.md, specs/, tasks/`);
|
|
15001
16469
|
console.log(`Perubahan lokal disetujui sebagai baseline baru.`);
|
|
@@ -15023,9 +16491,22 @@ async function driftCommand(options) {
|
|
|
15023
16491
|
}
|
|
15024
16492
|
const definitions = await loadTasks(bundleDir);
|
|
15025
16493
|
const state = await readState(bundleDir);
|
|
16494
|
+
const localContract = await snapshotContract(bundleDir);
|
|
16495
|
+
const hasContract = hasContractArtifacts(localContract);
|
|
16496
|
+
const contractLedger = hasContract ? await readContractLedger(bundleDir) : null;
|
|
16497
|
+
const contractStale = contractLedger === null ? null : computeStaleness(contractLedger.derivation, localContract);
|
|
16498
|
+
const contractIssue = !hasContract ? null : contractLedger === null ? "Baseline kontrak belum ada; jalankan `jioogen align` atau `jioogen pull` untuk membuatnya." : contractStale?.specsStale === true ? "PRD berubah: specs masih dari versi PRD lama. Jalankan `jioogen align`." : contractStale?.tasksStale === true ? "Specs/PRD berubah: tasks masih dari versi lama. Jalankan `jioogen align`." : null;
|
|
15026
16499
|
if (state === null) {
|
|
15027
16500
|
if (options.json === true) {
|
|
15028
|
-
console.log(
|
|
16501
|
+
console.log(
|
|
16502
|
+
JSON.stringify({ bundleDir, findings: [], contract: { issue: contractIssue } }, null, 2)
|
|
16503
|
+
);
|
|
16504
|
+
if (options.strict === true && contractIssue !== null) process.exitCode = 1;
|
|
16505
|
+
return;
|
|
16506
|
+
}
|
|
16507
|
+
if (contractIssue !== null) {
|
|
16508
|
+
console.log(`Drift check ${bundleDir}: ${contractIssue}`);
|
|
16509
|
+
if (options.strict === true) process.exitCode = 1;
|
|
15029
16510
|
return;
|
|
15030
16511
|
}
|
|
15031
16512
|
console.log(`Project bundle ${bundleDir}: belum ada sidecar; drift belum bisa dibandingkan.`);
|
|
@@ -15034,14 +16515,21 @@ async function driftCommand(options) {
|
|
|
15034
16515
|
}
|
|
15035
16516
|
const findings = await detectDrift(bundleDir, definitions, state);
|
|
15036
16517
|
if (options.json === true) {
|
|
15037
|
-
console.log(
|
|
16518
|
+
console.log(
|
|
16519
|
+
JSON.stringify({ bundleDir, findings, contract: { issue: contractIssue } }, null, 2)
|
|
16520
|
+
);
|
|
16521
|
+
if (options.strict === true && (contractIssue !== null || findings.some((finding) => finding.severity === "warn"))) {
|
|
16522
|
+
process.exitCode = 1;
|
|
16523
|
+
}
|
|
15038
16524
|
if (options.strict === true && findings.some((finding) => finding.severity === "warn")) {
|
|
15039
16525
|
process.exitCode = 1;
|
|
15040
16526
|
}
|
|
15041
16527
|
return;
|
|
15042
16528
|
}
|
|
16529
|
+
if (contractIssue !== null) console.log(`\u26A0 ${contractIssue}`);
|
|
15043
16530
|
if (findings.length === 0) {
|
|
15044
16531
|
console.log(`Drift check ${bundleDir}: tidak ada perubahan di luar harness.`);
|
|
16532
|
+
if (options.strict === true && contractIssue !== null) process.exitCode = 1;
|
|
15045
16533
|
return;
|
|
15046
16534
|
}
|
|
15047
16535
|
for (const finding of findings) {
|
|
@@ -15055,21 +16543,21 @@ async function driftCommand(options) {
|
|
|
15055
16543
|
"- Perubahan tidak disengaja pada PRD.md/specs/tasks: `git checkout -- PRD.md specs tasks`"
|
|
15056
16544
|
);
|
|
15057
16545
|
console.log(
|
|
15058
|
-
"- Perubahan kontrak disengaja: revisi via
|
|
16546
|
+
"- Perubahan kontrak disengaja: `jioogen align` (patch lokal disetujui) atau revisi via web lalu `jioogen pull`."
|
|
15059
16547
|
);
|
|
15060
16548
|
console.log(
|
|
15061
16549
|
"- Perubahan di scope task: `jioogen task adopt <ref>` (setelah verifikasi) atau `jioogen task reset <ref>`."
|
|
15062
16550
|
);
|
|
15063
16551
|
}
|
|
15064
|
-
if (options.strict === true && hasWarn) process.exitCode = 1;
|
|
16552
|
+
if (options.strict === true && (hasWarn || contractIssue !== null)) process.exitCode = 1;
|
|
15065
16553
|
}
|
|
15066
16554
|
async function baselineListCommand(options) {
|
|
15067
16555
|
const bundleDir = await resolveSkillsBundleDir(options);
|
|
15068
16556
|
const manifest = await readHarnessManifest(bundleDir);
|
|
15069
|
-
const knowledgeDir =
|
|
16557
|
+
const knowledgeDir = join13(bundleDir, ".jioogen", "custom", "knowledge");
|
|
15070
16558
|
let knowledgeFiles = [];
|
|
15071
16559
|
try {
|
|
15072
|
-
const entries = await
|
|
16560
|
+
const entries = await readdir8(knowledgeDir, { withFileTypes: true });
|
|
15073
16561
|
knowledgeFiles = entries.filter((entry) => entry.isFile()).map((entry) => entry.name).sort();
|
|
15074
16562
|
} catch {
|
|
15075
16563
|
knowledgeFiles = [];
|
|
@@ -15077,24 +16565,24 @@ async function baselineListCommand(options) {
|
|
|
15077
16565
|
const nonEmptyKnowledge = [];
|
|
15078
16566
|
for (const name of knowledgeFiles) {
|
|
15079
16567
|
try {
|
|
15080
|
-
const content = await
|
|
16568
|
+
const content = await readFile12(join13(knowledgeDir, name), "utf8");
|
|
15081
16569
|
if (content.trim().length > 0) nonEmptyKnowledge.push(name);
|
|
15082
16570
|
} catch {
|
|
15083
16571
|
}
|
|
15084
16572
|
}
|
|
15085
|
-
const customSkillsDir =
|
|
16573
|
+
const customSkillsDir = join13(bundleDir, ".jioogen", "custom", "skills");
|
|
15086
16574
|
let customSkillNames = [];
|
|
15087
16575
|
try {
|
|
15088
|
-
const entries = await
|
|
16576
|
+
const entries = await readdir8(customSkillsDir, { withFileTypes: true });
|
|
15089
16577
|
customSkillNames = entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
|
|
15090
16578
|
} catch {
|
|
15091
16579
|
customSkillNames = [];
|
|
15092
16580
|
}
|
|
15093
|
-
const agentsPath =
|
|
16581
|
+
const agentsPath = join13(bundleDir, "AGENTS.md");
|
|
15094
16582
|
let agentsExists = false;
|
|
15095
16583
|
let agentsBaseline = false;
|
|
15096
16584
|
try {
|
|
15097
|
-
const content = await
|
|
16585
|
+
const content = await readFile12(agentsPath, "utf8");
|
|
15098
16586
|
agentsExists = true;
|
|
15099
16587
|
agentsBaseline = content.includes("jioogen-execution-skill");
|
|
15100
16588
|
} catch {
|
|
@@ -15178,15 +16666,16 @@ async function syncCommand(options) {
|
|
|
15178
16666
|
];
|
|
15179
16667
|
if (options.files !== void 0) {
|
|
15180
16668
|
for (const raw of options.files.split(",")) {
|
|
15181
|
-
const
|
|
15182
|
-
if (
|
|
15183
|
-
assertBundleRelative(
|
|
16669
|
+
const relative3 = raw.trim();
|
|
16670
|
+
if (relative3.length === 0) continue;
|
|
16671
|
+
assertBundleRelative(relative3);
|
|
15184
16672
|
files.push({
|
|
15185
|
-
path:
|
|
15186
|
-
content: await
|
|
16673
|
+
path: relative3,
|
|
16674
|
+
content: await readFile12(resolveProjectPath(bundleDir, relative3), "utf8")
|
|
15187
16675
|
});
|
|
15188
16676
|
}
|
|
15189
16677
|
}
|
|
16678
|
+
await client.ensureProjectLayout(projectId).catch(() => null);
|
|
15190
16679
|
let result;
|
|
15191
16680
|
try {
|
|
15192
16681
|
result = await client.postJson(projectPath(projectId, "/artifacts"), {
|
|
@@ -15438,7 +16927,7 @@ async function assertPullDefaultDir(cwd, dirOption) {
|
|
|
15438
16927
|
async function assertPullTarget(target, projectId, force = false) {
|
|
15439
16928
|
let entries;
|
|
15440
16929
|
try {
|
|
15441
|
-
entries = await
|
|
16930
|
+
entries = await readdir8(target);
|
|
15442
16931
|
} catch (error) {
|
|
15443
16932
|
if (isMissingFile7(error)) return;
|
|
15444
16933
|
throw error;
|
|
@@ -15472,17 +16961,17 @@ async function assertLinkTarget(target, projectId) {
|
|
|
15472
16961
|
}
|
|
15473
16962
|
async function hasBundleMarkers(target) {
|
|
15474
16963
|
try {
|
|
15475
|
-
await
|
|
16964
|
+
await readFile12(join13(contractRoot(target), "PRD.md"));
|
|
15476
16965
|
return true;
|
|
15477
16966
|
} catch (error) {
|
|
15478
16967
|
if (!isMissingFile7(error)) throw error;
|
|
15479
16968
|
}
|
|
15480
|
-
return hasTaskMarkdown(
|
|
16969
|
+
return hasTaskMarkdown(join13(contractRoot(target), "tasks"));
|
|
15481
16970
|
}
|
|
15482
16971
|
async function hasTaskMarkdown(directory) {
|
|
15483
16972
|
let names;
|
|
15484
16973
|
try {
|
|
15485
|
-
names = await
|
|
16974
|
+
names = await readdir8(directory);
|
|
15486
16975
|
} catch (error) {
|
|
15487
16976
|
if (isMissingFile7(error)) return false;
|
|
15488
16977
|
throw error;
|
|
@@ -15490,15 +16979,15 @@ async function hasTaskMarkdown(directory) {
|
|
|
15490
16979
|
return names.some((name) => name.toLowerCase().endsWith(".md"));
|
|
15491
16980
|
}
|
|
15492
16981
|
async function scaffoldCustomLayer(bundleDir) {
|
|
15493
|
-
const stackDir =
|
|
15494
|
-
const knowledgeDir =
|
|
15495
|
-
const designDir =
|
|
15496
|
-
await
|
|
15497
|
-
await
|
|
15498
|
-
await
|
|
15499
|
-
const exampleFile =
|
|
16982
|
+
const stackDir = join13(bundleDir, ".jioogen", "custom", "stack");
|
|
16983
|
+
const knowledgeDir = join13(bundleDir, ".jioogen", "custom", "knowledge");
|
|
16984
|
+
const designDir = join13(bundleDir, ".jioogen", "custom", "design");
|
|
16985
|
+
await mkdir10(stackDir, { recursive: true });
|
|
16986
|
+
await mkdir10(knowledgeDir, { recursive: true });
|
|
16987
|
+
await mkdir10(designDir, { recursive: true });
|
|
16988
|
+
const exampleFile = join13(stackDir, "STACK.md.example");
|
|
15500
16989
|
try {
|
|
15501
|
-
await
|
|
16990
|
+
await stat8(exampleFile);
|
|
15502
16991
|
} catch {
|
|
15503
16992
|
const template = [
|
|
15504
16993
|
"# Custom Stack & Architecture Preferences",
|
|
@@ -15512,7 +17001,7 @@ async function scaffoldCustomLayer(bundleDir) {
|
|
|
15512
17001
|
"- Testing Runner: Vitest (bukan Jest)",
|
|
15513
17002
|
""
|
|
15514
17003
|
].join("\n");
|
|
15515
|
-
await
|
|
17004
|
+
await writeFile10(exampleFile, template, "utf8").catch(() => {
|
|
15516
17005
|
});
|
|
15517
17006
|
}
|
|
15518
17007
|
}
|
|
@@ -15714,7 +17203,7 @@ async function readLine() {
|
|
|
15714
17203
|
}
|
|
15715
17204
|
|
|
15716
17205
|
// src/index.ts
|
|
15717
|
-
var VERSION = "0.2.
|
|
17206
|
+
var VERSION = "0.2.15";
|
|
15718
17207
|
function parseTaskModeOption(value) {
|
|
15719
17208
|
if (value === void 0) return void 0;
|
|
15720
17209
|
const parsed = TaskModeSchema.safeParse(value);
|
|
@@ -15752,6 +17241,9 @@ Usage:
|
|
|
15752
17241
|
jioogen authoring install [--dir <dir>]
|
|
15753
17242
|
jioogen authoring status [--dir <dir>] [--json]
|
|
15754
17243
|
jioogen authoring remove [--dir <dir>]
|
|
17244
|
+
jioogen align [--dir <dir>] [--json]
|
|
17245
|
+
jioogen approve [--dir <dir>] [--note <text>] [--json]
|
|
17246
|
+
jioogen docs (scan|migrate|index|check) [--dir <dir>] [--dry-run] [--json]
|
|
15755
17247
|
jioogen check [--dir <dir>] [--json]
|
|
15756
17248
|
jioogen doctor [--fix] [--dir <dir>] [--json]
|
|
15757
17249
|
jioogen drift [--dir <dir>] [--json] [--strict] [--acknowledge] [--prd] [--specs] [--tasks] [--note <text>]
|
|
@@ -15960,6 +17452,15 @@ async function dispatch(command, rest, options) {
|
|
|
15960
17452
|
case "authoring":
|
|
15961
17453
|
await dispatchAuthoring(rest, options);
|
|
15962
17454
|
return;
|
|
17455
|
+
case "align":
|
|
17456
|
+
await alignCommand(options);
|
|
17457
|
+
return;
|
|
17458
|
+
case "docs":
|
|
17459
|
+
await docsCommand(options, rest[0] ?? "scan");
|
|
17460
|
+
return;
|
|
17461
|
+
case "approve":
|
|
17462
|
+
await approveCommand(options);
|
|
17463
|
+
return;
|
|
15963
17464
|
case "check":
|
|
15964
17465
|
await checkCommand(options);
|
|
15965
17466
|
return;
|