arkaik 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +348 -48
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -17058,6 +17058,41 @@ function promotionPatch(node, promotion) {
|
|
|
17058
17058
|
};
|
|
17059
17059
|
}
|
|
17060
17060
|
|
|
17061
|
+
// ../schema/src/mentions.ts
|
|
17062
|
+
function isPlatformId(value) {
|
|
17063
|
+
return PLATFORM_IDS.includes(value);
|
|
17064
|
+
}
|
|
17065
|
+
var ACCEPTANCE_MENTION = /\b(AC-[a-z0-9][a-z0-9-]*)(?:\\?@((?:(?!\bAC-[a-z0-9])\S)+))?/gi;
|
|
17066
|
+
var TRAILING_PROSE = /* @__PURE__ */ new Set([".", ",", ";", ":", "!", "?", ")", "]", "}", ">", "'", '"', "`", "*", "_", "~"]);
|
|
17067
|
+
function trimTrailingProse(token) {
|
|
17068
|
+
let end = token.length;
|
|
17069
|
+
while (end > 0 && TRAILING_PROSE.has(token[end - 1])) end -= 1;
|
|
17070
|
+
return token.slice(0, end);
|
|
17071
|
+
}
|
|
17072
|
+
function mentionedAcceptances(event) {
|
|
17073
|
+
const mentions = /* @__PURE__ */ new Map();
|
|
17074
|
+
const unknown2 = /* @__PURE__ */ new Map();
|
|
17075
|
+
for (const text of [event.title, event.body]) {
|
|
17076
|
+
if (!text) continue;
|
|
17077
|
+
for (const match of text.matchAll(ACCEPTANCE_MENTION)) {
|
|
17078
|
+
const id = `AC-${match[1].slice(3)}`;
|
|
17079
|
+
const written = match[2];
|
|
17080
|
+
if (written === void 0) {
|
|
17081
|
+
mentions.set(`${id}@`, { id, platform: null });
|
|
17082
|
+
continue;
|
|
17083
|
+
}
|
|
17084
|
+
const token = trimTrailingProse(written);
|
|
17085
|
+
const suffix = token.toLowerCase();
|
|
17086
|
+
if (!isPlatformId(suffix)) {
|
|
17087
|
+
unknown2.set(`${id}@${suffix}`, { id, platform: token || written });
|
|
17088
|
+
continue;
|
|
17089
|
+
}
|
|
17090
|
+
mentions.set(`${id}@${suffix}`, { id, platform: suffix });
|
|
17091
|
+
}
|
|
17092
|
+
}
|
|
17093
|
+
return { mentions: [...mentions.values()], unknown: [...unknown2.values()] };
|
|
17094
|
+
}
|
|
17095
|
+
|
|
17061
17096
|
// ../schema/src/quality-ops.ts
|
|
17062
17097
|
var DEFAULT_TARGET_LEVEL = 3;
|
|
17063
17098
|
function upsertAssessment(assessments, next) {
|
|
@@ -20306,13 +20341,273 @@ function runLinkCli(argv) {
|
|
|
20306
20341
|
});
|
|
20307
20342
|
}
|
|
20308
20343
|
|
|
20309
|
-
// src/commands/
|
|
20310
|
-
import {
|
|
20344
|
+
// src/commands/live.ts
|
|
20345
|
+
import { readFileSync as readFileSync9 } from "node:fs";
|
|
20311
20346
|
import { join as join8, resolve as resolve9 } from "node:path";
|
|
20312
20347
|
var LINK_FILE2 = "docs/arkaik/arkaik.json";
|
|
20348
|
+
var DEFAULT_BASE_URL2 = "https://arkaik.app";
|
|
20349
|
+
var MAX_ENTRIES_PER_REQUEST = 50;
|
|
20350
|
+
var KNOWN_FLAGS = /* @__PURE__ */ new Set(["--platform", "--detail", "--mentions", "--paths", "--remote", "--dry-run", "--help"]);
|
|
20351
|
+
var VALUED_FLAGS = /* @__PURE__ */ new Set(["--platform", "--detail", "--mentions", "--paths", "--remote"]);
|
|
20352
|
+
var DROPPABLE_REASONS = /* @__PURE__ */ new Set(["platform_not_applicable", "unknown_node"]);
|
|
20353
|
+
var ACCEPTANCE_ID = /^AC-[A-Za-z0-9._-]+$/;
|
|
20354
|
+
var USAGE11 = `arkaik live \u2014 mark the acceptances a deploy carried live on one platform
|
|
20355
|
+
|
|
20356
|
+
Usage:
|
|
20357
|
+
arkaik live --platform <web|ios|android> [options] [AC-id ...]
|
|
20358
|
+
|
|
20359
|
+
Options:
|
|
20360
|
+
--platform <id> Required. The platform that went live.
|
|
20361
|
+
--detail <text> Evidence to record on the status change: a deploy URL, a build number.
|
|
20362
|
+
--mentions <file> JSON array of merged pull requests: [{ number, title, body, files }].
|
|
20363
|
+
Acceptances mentioned as AC-id@<platform> count; bare AC-id mentions
|
|
20364
|
+
count only when the PR touched one of --paths (or --paths is absent).
|
|
20365
|
+
--paths <prefixes> Comma-separated path prefixes that make a bare mention count (apps/web).
|
|
20366
|
+
--dry-run Print the entries and send nothing.
|
|
20367
|
+
--remote <url> Instance origin. Default: $ARKAIK_URL, else the link file's remote, else ${DEFAULT_BASE_URL2}
|
|
20368
|
+
-h, --help Show this help.
|
|
20369
|
+
|
|
20370
|
+
Environment:
|
|
20371
|
+
ARKAIK_TOKEN Required. A release:append token from <origin>/settings/tokens.
|
|
20372
|
+
|
|
20373
|
+
Reads ${LINK_FILE2} for the project id. Exit 0 when nothing needs marking; exit 1 on a refusal or any failed request.`;
|
|
20374
|
+
function flagValue2(argv, flag) {
|
|
20375
|
+
const index = argv.indexOf(flag);
|
|
20376
|
+
return index !== -1 ? argv[index + 1] : void 0;
|
|
20377
|
+
}
|
|
20378
|
+
function normalisePrefix(prefix) {
|
|
20379
|
+
const trimmed = prefix.trim().replace(/^(\.\/)+/, "").replace(/^\/+/, "").replace(/\/+$/, "");
|
|
20380
|
+
return trimmed === "" ? null : `${trimmed}/`;
|
|
20381
|
+
}
|
|
20382
|
+
function touchesAny(files, prefixes) {
|
|
20383
|
+
return files.some((file2) => prefixes.some((prefix) => file2.startsWith(prefix)));
|
|
20384
|
+
}
|
|
20385
|
+
function deriveLiveIds(prs, platform, paths) {
|
|
20386
|
+
const prefixes = paths.map(normalisePrefix).filter((p) => p !== null);
|
|
20387
|
+
const ids = [];
|
|
20388
|
+
const warnings = [];
|
|
20389
|
+
const seen = /* @__PURE__ */ new Set();
|
|
20390
|
+
const explicit = /* @__PURE__ */ new Set();
|
|
20391
|
+
for (const pr of prs) {
|
|
20392
|
+
const scan = mentionedAcceptances({ title: pr.title ?? "", body: pr.body ?? "" });
|
|
20393
|
+
for (const unknown2 of scan.unknown) {
|
|
20394
|
+
warnings.push(`#${pr.number || "?"}: ${unknown2.id}@${unknown2.platform} names no platform arkaik knows \u2014 ignored`);
|
|
20395
|
+
}
|
|
20396
|
+
for (const mention of scan.mentions) {
|
|
20397
|
+
if (mention.platform === platform) explicit.add(mention.id);
|
|
20398
|
+
const counts = mention.platform === platform || mention.platform === null && (prefixes.length === 0 || touchesAny(pr.files ?? [], prefixes));
|
|
20399
|
+
if (!counts || seen.has(mention.id)) continue;
|
|
20400
|
+
seen.add(mention.id);
|
|
20401
|
+
ids.push(mention.id);
|
|
20402
|
+
}
|
|
20403
|
+
}
|
|
20404
|
+
return { ids, warnings, inferred: ids.filter((id) => !explicit.has(id)) };
|
|
20405
|
+
}
|
|
20406
|
+
function readMentions(file2) {
|
|
20407
|
+
let parsed;
|
|
20408
|
+
try {
|
|
20409
|
+
parsed = JSON.parse(readFileSync9(file2, "utf8"));
|
|
20410
|
+
} catch (e) {
|
|
20411
|
+
return { error: `Could not read ${file2}: ${e.message}` };
|
|
20412
|
+
}
|
|
20413
|
+
if (!Array.isArray(parsed)) return { error: `${file2} must be a JSON array of pull requests` };
|
|
20414
|
+
const prs = [];
|
|
20415
|
+
for (const [i, raw] of parsed.entries()) {
|
|
20416
|
+
if (typeof raw !== "object" || raw === null) return { error: `${file2}[${i}] must be an object` };
|
|
20417
|
+
const r = raw;
|
|
20418
|
+
prs.push({
|
|
20419
|
+
number: typeof r.number === "number" && Number.isFinite(r.number) ? r.number : 0,
|
|
20420
|
+
title: typeof r.title === "string" ? r.title : "",
|
|
20421
|
+
body: typeof r.body === "string" ? r.body : "",
|
|
20422
|
+
files: Array.isArray(r.files) ? r.files.filter((f) => typeof f === "string") : []
|
|
20423
|
+
});
|
|
20424
|
+
}
|
|
20425
|
+
return prs;
|
|
20426
|
+
}
|
|
20427
|
+
function describeFailure2(status, baseUrl, body) {
|
|
20428
|
+
if (status === 401) return `Unauthorized \u2014 check ARKAIK_TOKEN (create one at ${baseUrl}/settings/tokens).`;
|
|
20429
|
+
if (status === 403) return "Forbidden \u2014 this token lacks the release:append scope (or graph:write).";
|
|
20430
|
+
if (status === 404) return `No linked project in this account \u2014 check ${LINK_FILE2}.`;
|
|
20431
|
+
if (status === 409) return "The project changed under every retry \u2014 run again.";
|
|
20432
|
+
return `Request failed (${status})${body.message ? ` \u2014 ${body.message}` : body.error ? ` \u2014 ${body.error}` : ""}.`;
|
|
20433
|
+
}
|
|
20434
|
+
async function runLive(argv, options = {}) {
|
|
20435
|
+
const log = options.log ?? ((m) => console.log(m));
|
|
20436
|
+
const errorLog = options.errorLog ?? ((m) => console.error(m));
|
|
20437
|
+
const env = options.env ?? process.env;
|
|
20438
|
+
const cwd = options.cwd ?? process.cwd();
|
|
20439
|
+
const doFetch = options.httpClient ?? ((...args) => fetch(...args));
|
|
20440
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
20441
|
+
log(USAGE11);
|
|
20442
|
+
return { ok: true };
|
|
20443
|
+
}
|
|
20444
|
+
const positional = [];
|
|
20445
|
+
for (let i = 0; i < argv.length; i++) {
|
|
20446
|
+
const arg = argv[i];
|
|
20447
|
+
if (VALUED_FLAGS.has(arg)) {
|
|
20448
|
+
i++;
|
|
20449
|
+
continue;
|
|
20450
|
+
}
|
|
20451
|
+
if (arg.startsWith("--")) {
|
|
20452
|
+
if (KNOWN_FLAGS.has(arg)) continue;
|
|
20453
|
+
errorLog(`Unknown flag ${arg}. Flags take a separate value (--mentions file.json), see arkaik live --help.`);
|
|
20454
|
+
return { ok: false };
|
|
20455
|
+
}
|
|
20456
|
+
if (arg.includes("@")) {
|
|
20457
|
+
errorLog(`"${arg}": positional ids take no @platform \u2014 the platform comes from --platform.`);
|
|
20458
|
+
return { ok: false };
|
|
20459
|
+
}
|
|
20460
|
+
if (!ACCEPTANCE_ID.test(arg)) {
|
|
20461
|
+
errorLog(`"${arg}" is not an acceptance id (they start with AC-). Flags take one value each; see arkaik live --help.`);
|
|
20462
|
+
return { ok: false };
|
|
20463
|
+
}
|
|
20464
|
+
positional.push(arg);
|
|
20465
|
+
}
|
|
20466
|
+
const platformArg = flagValue2(argv, "--platform");
|
|
20467
|
+
if (!platformArg) {
|
|
20468
|
+
errorLog(`--platform is required: arkaik live --platform <${PLATFORM_IDS.join("|")}> \u2026`);
|
|
20469
|
+
return { ok: false };
|
|
20470
|
+
}
|
|
20471
|
+
if (!isPlatformId(platformArg)) {
|
|
20472
|
+
errorLog(`"${platformArg}" is not a platform. Expected one of: ${PLATFORM_IDS.join(", ")}.`);
|
|
20473
|
+
return { ok: false };
|
|
20474
|
+
}
|
|
20475
|
+
const platform = platformArg;
|
|
20476
|
+
const detail = flagValue2(argv, "--detail");
|
|
20477
|
+
const mentionsFile = flagValue2(argv, "--mentions");
|
|
20478
|
+
const paths = (flagValue2(argv, "--paths") ?? "").split(",").map((p) => p.trim()).filter(Boolean);
|
|
20479
|
+
const dryRun = argv.includes("--dry-run");
|
|
20480
|
+
const linkPath = join8(cwd, LINK_FILE2);
|
|
20481
|
+
let link;
|
|
20482
|
+
try {
|
|
20483
|
+
link = JSON.parse(readFileSync9(linkPath, "utf8"));
|
|
20484
|
+
} catch {
|
|
20485
|
+
errorLog(`No ${LINK_FILE2}. Run \`arkaik link --project <id>\` first \u2014 live only targets hosted projects.`);
|
|
20486
|
+
return { ok: false };
|
|
20487
|
+
}
|
|
20488
|
+
const projectId = link.project_id;
|
|
20489
|
+
if (!projectId) {
|
|
20490
|
+
errorLog(`${LINK_FILE2} has no project_id. Run \`arkaik link --project <id>\`.`);
|
|
20491
|
+
return { ok: false };
|
|
20492
|
+
}
|
|
20493
|
+
const baseUrl = (flagValue2(argv, "--remote") ?? env.ARKAIK_URL ?? link.remote ?? DEFAULT_BASE_URL2).replace(/\/+$/, "");
|
|
20494
|
+
const ids = [];
|
|
20495
|
+
const seen = /* @__PURE__ */ new Set();
|
|
20496
|
+
const add = (id) => {
|
|
20497
|
+
if (!seen.has(id)) {
|
|
20498
|
+
seen.add(id);
|
|
20499
|
+
ids.push(id);
|
|
20500
|
+
}
|
|
20501
|
+
};
|
|
20502
|
+
for (const id of positional) add(id);
|
|
20503
|
+
const inferred = /* @__PURE__ */ new Set();
|
|
20504
|
+
if (mentionsFile) {
|
|
20505
|
+
const prs = readMentions(resolve9(cwd, mentionsFile));
|
|
20506
|
+
if (!Array.isArray(prs)) {
|
|
20507
|
+
errorLog(prs.error);
|
|
20508
|
+
return { ok: false };
|
|
20509
|
+
}
|
|
20510
|
+
const derived = deriveLiveIds(prs, platform, paths);
|
|
20511
|
+
for (const warning of derived.warnings) errorLog(`warning: ${warning}`);
|
|
20512
|
+
for (const id of derived.ids) add(id);
|
|
20513
|
+
for (const id of derived.inferred) if (!positional.includes(id)) inferred.add(id);
|
|
20514
|
+
}
|
|
20515
|
+
if (ids.length === 0) {
|
|
20516
|
+
log(`Nothing to mark live on ${platform}.`);
|
|
20517
|
+
return { ok: true, ids };
|
|
20518
|
+
}
|
|
20519
|
+
const hasDetail = detail !== void 0 && detail !== "";
|
|
20520
|
+
const entries = ids.map((node_id) => ({ node_id, platform, ...hasDetail ? { detail } : {} }));
|
|
20521
|
+
if (dryRun) {
|
|
20522
|
+
log(`Would mark ${platform} live for ${ids.length} acceptance(s) on ${projectId} (${baseUrl}):`);
|
|
20523
|
+
for (const entry of entries) log(` ${entry.node_id}@${platform}${hasDetail ? ` \u2014 ${detail}` : ""}`);
|
|
20524
|
+
return { ok: true, ids };
|
|
20525
|
+
}
|
|
20526
|
+
const token = env.ARKAIK_TOKEN;
|
|
20527
|
+
if (!token) {
|
|
20528
|
+
errorLog(`ARKAIK_TOKEN is not set. Create a release:append token at ${baseUrl}/settings/tokens and export it.`);
|
|
20529
|
+
return { ok: false };
|
|
20530
|
+
}
|
|
20531
|
+
const post = async (chunk) => {
|
|
20532
|
+
let res;
|
|
20533
|
+
try {
|
|
20534
|
+
res = await doFetch(`${baseUrl}/api/graph/projects/${encodeURIComponent(projectId)}/live`, {
|
|
20535
|
+
method: "POST",
|
|
20536
|
+
headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
|
|
20537
|
+
body: JSON.stringify({ entries: chunk })
|
|
20538
|
+
});
|
|
20539
|
+
} catch (e) {
|
|
20540
|
+
errorLog(`Could not reach ${baseUrl}: ${e.message}`);
|
|
20541
|
+
return null;
|
|
20542
|
+
}
|
|
20543
|
+
let body = {};
|
|
20544
|
+
try {
|
|
20545
|
+
body = await res.json();
|
|
20546
|
+
} catch {
|
|
20547
|
+
}
|
|
20548
|
+
return { res, body };
|
|
20549
|
+
};
|
|
20550
|
+
let landed = 0;
|
|
20551
|
+
for (let start = 0; start < entries.length; start += MAX_ENTRIES_PER_REQUEST) {
|
|
20552
|
+
const end = Math.min(start + MAX_ENTRIES_PER_REQUEST, entries.length) - 1;
|
|
20553
|
+
let chunk = entries.slice(start, end + 1).map((entry, i) => ({ entry, at: start + i }));
|
|
20554
|
+
let resent = false;
|
|
20555
|
+
for (; ; ) {
|
|
20556
|
+
const sent = await post(chunk.map((c) => c.entry));
|
|
20557
|
+
if (!sent) return { ok: false, ids };
|
|
20558
|
+
const { res, body } = sent;
|
|
20559
|
+
if (res.status === 422 && body.refusals) {
|
|
20560
|
+
const refusals = body.refusals;
|
|
20561
|
+
const droppable = !resent && refusals.every((r) => DROPPABLE_REASONS.has(r.reason) && inferred.has(r.node_id));
|
|
20562
|
+
if (droppable) {
|
|
20563
|
+
const dropped = /* @__PURE__ */ new Set();
|
|
20564
|
+
for (const r of refusals) {
|
|
20565
|
+
errorLog(`warning: ${r.node_id}@${r.platform} was inferred from a bare mention and the project does not list it that way (${r.reason}) \u2014 dropped`);
|
|
20566
|
+
dropped.add(r.node_id);
|
|
20567
|
+
}
|
|
20568
|
+
chunk = chunk.filter((c) => !dropped.has(c.entry.node_id));
|
|
20569
|
+
resent = true;
|
|
20570
|
+
if (chunk.length === 0) {
|
|
20571
|
+
log(`Nothing left to send in entries ${start}\u2013${end} after dropping inferred ids.`);
|
|
20572
|
+
break;
|
|
20573
|
+
}
|
|
20574
|
+
continue;
|
|
20575
|
+
}
|
|
20576
|
+
errorLog(
|
|
20577
|
+
landed > 0 ? `Refused \u2014 entries ${start}\u2013${end} wrote nothing; the ${landed} before them were applied above (a re-run skips them):` : "Refused \u2014 nothing was written:"
|
|
20578
|
+
);
|
|
20579
|
+
for (const r of refusals) {
|
|
20580
|
+
const at2 = chunk[r.index]?.at ?? start + r.index;
|
|
20581
|
+
errorLog(` entries[${at2}] ${r.node_id}@${r.platform}: ${r.reason}${r.detail ? ` \u2014 ${r.detail}` : ""}`);
|
|
20582
|
+
}
|
|
20583
|
+
errorLog("Re-run with the other ids as arguments \u2014 acceptances already live are skipped, so a retry is safe.");
|
|
20584
|
+
return { ok: false, ids };
|
|
20585
|
+
}
|
|
20586
|
+
if (!res.ok) {
|
|
20587
|
+
errorLog(describeFailure2(res.status, baseUrl, body));
|
|
20588
|
+
return { ok: false, ids };
|
|
20589
|
+
}
|
|
20590
|
+
for (const a of body.applied ?? []) log(`${a.node_id}: ${a.from} \u2192 ${a.to} [${a.platform}]`);
|
|
20591
|
+
for (const sk of body.skipped ?? []) log(`${sk.node_id}: already live [${sk.platform}]`);
|
|
20592
|
+
landed += chunk.length;
|
|
20593
|
+
break;
|
|
20594
|
+
}
|
|
20595
|
+
}
|
|
20596
|
+
return { ok: true, ids };
|
|
20597
|
+
}
|
|
20598
|
+
function runLiveCli(argv) {
|
|
20599
|
+
void runLive(argv).then((result) => {
|
|
20600
|
+
if (!result.ok) process.exit(1);
|
|
20601
|
+
});
|
|
20602
|
+
}
|
|
20603
|
+
|
|
20604
|
+
// src/commands/restore.ts
|
|
20605
|
+
import { existsSync as existsSync9, linkSync, mkdirSync as mkdirSync6, readFileSync as readFileSync10, unlinkSync, writeFileSync as writeFileSync9 } from "node:fs";
|
|
20606
|
+
import { join as join9, resolve as resolve10 } from "node:path";
|
|
20607
|
+
var LINK_FILE3 = "docs/arkaik/arkaik.json";
|
|
20313
20608
|
var DEFAULT_BUNDLE_PATH9 = "docs/arkaik/bundle.json";
|
|
20314
20609
|
var DEFAULT_API_BASE2 = "https://arkaik.app";
|
|
20315
|
-
var
|
|
20610
|
+
var USAGE12 = `arkaik restore [options] [path]
|
|
20316
20611
|
|
|
20317
20612
|
Replace the linked hosted project's bundle, journal AND quality section with
|
|
20318
20613
|
a local bundle \u2014
|
|
@@ -20532,7 +20827,7 @@ function describeQualityLoss(hostedQuality, qualityRoot, noQuality, foldNotice)
|
|
|
20532
20827
|
lines.push("The outbound bundle has no section because the fold found nothing to build one from:");
|
|
20533
20828
|
lines.push(` ${foldNotice}`);
|
|
20534
20829
|
}
|
|
20535
|
-
if (!existsSync9(
|
|
20830
|
+
if (!existsSync9(join9(qualityRoot, QUALITY_DIR))) {
|
|
20536
20831
|
lines.push(
|
|
20537
20832
|
`There is no ${QUALITY_DIR}/ under ${qualityRoot} at all. If this project's sidecars live somewhere else, point --root at that repo and the section is rebuilt rather than removed.`
|
|
20538
20833
|
);
|
|
@@ -20550,27 +20845,27 @@ async function runRestore(options = {}) {
|
|
|
20550
20845
|
const noQuality = options.noQuality ?? false;
|
|
20551
20846
|
const allowQualityLoss = options.allowQualityLoss ?? false;
|
|
20552
20847
|
const httpClient = options.httpClient ?? DEFAULT_HTTP_CLIENT;
|
|
20553
|
-
const linkPath =
|
|
20848
|
+
const linkPath = join9(cwd, LINK_FILE3);
|
|
20554
20849
|
if (!existsSync9(linkPath)) {
|
|
20555
|
-
return fatalResult5(dryRun, `No ${
|
|
20850
|
+
return fatalResult5(dryRun, `No ${LINK_FILE3}. Run \`arkaik link\` first \u2014 restore only targets hosted projects.`);
|
|
20556
20851
|
}
|
|
20557
20852
|
let link;
|
|
20558
20853
|
try {
|
|
20559
|
-
link = JSON.parse(
|
|
20854
|
+
link = JSON.parse(readFileSync10(linkPath, "utf8"));
|
|
20560
20855
|
} catch (e) {
|
|
20561
|
-
return fatalResult5(dryRun, `Could not parse ${
|
|
20856
|
+
return fatalResult5(dryRun, `Could not parse ${LINK_FILE3}: ${e.message}`);
|
|
20562
20857
|
}
|
|
20563
20858
|
const projectId = link.project_id;
|
|
20564
|
-
if (!projectId) return fatalResult5(dryRun, `${
|
|
20859
|
+
if (!projectId) return fatalResult5(dryRun, `${LINK_FILE3} has no project_id. Run \`arkaik link --project <id>\`.`);
|
|
20565
20860
|
const baseUrl = (options.apiBase ?? env.ARKAIK_URL ?? link.remote ?? DEFAULT_API_BASE2).replace(/\/+$/, "");
|
|
20566
20861
|
const encodedProjectId = encodeURIComponent(projectId);
|
|
20567
20862
|
const token = env.ARKAIK_TOKEN;
|
|
20568
20863
|
if (!token) return fatalResult5(dryRun, `ARKAIK_TOKEN is not set. Create a token at ${baseUrl}/settings/tokens and export it.`);
|
|
20569
|
-
const bundlePath =
|
|
20864
|
+
const bundlePath = resolve10(cwd, options.path ?? DEFAULT_BUNDLE_PATH9);
|
|
20570
20865
|
if (!existsSync9(bundlePath)) return fatalResult5(dryRun, `No bundle at ${bundlePath}. Run \`arkaik merge\` (or \`arkaik pack\`) first.`);
|
|
20571
20866
|
let localRaw;
|
|
20572
20867
|
try {
|
|
20573
|
-
localRaw = JSON.parse(
|
|
20868
|
+
localRaw = JSON.parse(readFileSync10(bundlePath, "utf8"));
|
|
20574
20869
|
} catch (e) {
|
|
20575
20870
|
return fatalResult5(dryRun, `Could not parse ${bundlePath}: ${e.message}`);
|
|
20576
20871
|
}
|
|
@@ -20664,15 +20959,15 @@ async function runRestore(options = {}) {
|
|
|
20664
20959
|
if ((removedNodes.length > 0 || removedEdges.length > 0) && !allowDeletions) {
|
|
20665
20960
|
return fatalResult5(dryRun, describeDeletions(removedNodes, removedEdges, bundlePath), qualityFields);
|
|
20666
20961
|
}
|
|
20667
|
-
const backupDir =
|
|
20962
|
+
const backupDir = join9(cwd, "docs", "arkaik", ".backups");
|
|
20668
20963
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
20669
|
-
const backupPath =
|
|
20964
|
+
const backupPath = join9(backupDir, `${stamp}-bundle.json`);
|
|
20670
20965
|
const backupContent = `${JSON.stringify(exported, null, 2)}
|
|
20671
20966
|
`;
|
|
20672
20967
|
try {
|
|
20673
20968
|
mkdirSync6(backupDir, { recursive: true });
|
|
20674
20969
|
writeBackupFile(backupPath, backupContent);
|
|
20675
|
-
JSON.parse(
|
|
20970
|
+
JSON.parse(readFileSync10(backupPath, "utf8"));
|
|
20676
20971
|
} catch (e) {
|
|
20677
20972
|
return fatalResult5(
|
|
20678
20973
|
dryRun,
|
|
@@ -20772,7 +21067,7 @@ function runRestoreCli(argv) {
|
|
|
20772
21067
|
for (let i = 0; i < argv.length; i++) {
|
|
20773
21068
|
const arg = argv[i];
|
|
20774
21069
|
if (arg === "-h" || arg === "--help") {
|
|
20775
|
-
console.log(
|
|
21070
|
+
console.log(USAGE12);
|
|
20776
21071
|
process.exitCode = 0;
|
|
20777
21072
|
return;
|
|
20778
21073
|
} else if (arg === "--dry-run") {
|
|
@@ -20789,35 +21084,35 @@ function runRestoreCli(argv) {
|
|
|
20789
21084
|
const value = argv[++i];
|
|
20790
21085
|
if (value === void 0) fail10(`Missing value for --audit
|
|
20791
21086
|
|
|
20792
|
-
${
|
|
21087
|
+
${USAGE12}`);
|
|
20793
21088
|
audit = value;
|
|
20794
21089
|
} else if (arg === "--root") {
|
|
20795
21090
|
const value = argv[++i];
|
|
20796
21091
|
if (value === void 0) fail10(`Missing value for --root
|
|
20797
21092
|
|
|
20798
|
-
${
|
|
21093
|
+
${USAGE12}`);
|
|
20799
21094
|
root = value;
|
|
20800
21095
|
} else if (arg === "--api") {
|
|
20801
21096
|
const value = argv[++i];
|
|
20802
21097
|
if (value === void 0) fail10(`Missing value for --api
|
|
20803
21098
|
|
|
20804
|
-
${
|
|
21099
|
+
${USAGE12}`);
|
|
20805
21100
|
apiBase = value;
|
|
20806
21101
|
} else if (arg.startsWith("-")) {
|
|
20807
21102
|
fail10(`Unknown option: ${arg}
|
|
20808
21103
|
|
|
20809
|
-
${
|
|
21104
|
+
${USAGE12}`);
|
|
20810
21105
|
} else {
|
|
20811
21106
|
positionals.push(arg);
|
|
20812
21107
|
}
|
|
20813
21108
|
}
|
|
20814
21109
|
if (positionals.length > 1) fail10(`Unexpected argument(s): ${positionals.slice(1).join(" ")}
|
|
20815
21110
|
|
|
20816
|
-
${
|
|
21111
|
+
${USAGE12}`);
|
|
20817
21112
|
if (noQuality && audit !== void 0) {
|
|
20818
21113
|
fail10(`--audit and --no-quality contradict each other: one names an audit to fold, the other removes the section
|
|
20819
21114
|
|
|
20820
|
-
${
|
|
21115
|
+
${USAGE12}`);
|
|
20821
21116
|
}
|
|
20822
21117
|
runRestore({ path: positionals[0], dryRun, allowHistoryLoss, allowDeletions, noQuality, allowQualityLoss, audit, root, apiBase }).then((result) => reportRestore(result)).catch((e) => fail10(`FATAL: ${e.message}`));
|
|
20823
21118
|
}
|
|
@@ -20829,11 +21124,11 @@ import path5 from "node:path";
|
|
|
20829
21124
|
|
|
20830
21125
|
// src/lib/bootstrap/corpus.ts
|
|
20831
21126
|
import { spawnSync } from "node:child_process";
|
|
20832
|
-
import { existsSync as existsSync11, readdirSync as readdirSync3, readFileSync as
|
|
21127
|
+
import { existsSync as existsSync11, readdirSync as readdirSync3, readFileSync as readFileSync12, writeFileSync as writeFileSync11 } from "node:fs";
|
|
20833
21128
|
import path2 from "node:path";
|
|
20834
21129
|
|
|
20835
21130
|
// src/lib/bootstrap/paths.ts
|
|
20836
|
-
import { existsSync as existsSync10, mkdirSync as mkdirSync7, readFileSync as
|
|
21131
|
+
import { existsSync as existsSync10, mkdirSync as mkdirSync7, readFileSync as readFileSync11, writeFileSync as writeFileSync10 } from "node:fs";
|
|
20837
21132
|
import path from "node:path";
|
|
20838
21133
|
var BOOTSTRAP_ROOT = ".arkaik";
|
|
20839
21134
|
var CORPUS_DIR = ".arkaik/corpus";
|
|
@@ -20853,7 +21148,7 @@ function ensureDir(dirPath) {
|
|
|
20853
21148
|
function ensureGitignored(cwd) {
|
|
20854
21149
|
const file2 = path.join(cwd, ".gitignore");
|
|
20855
21150
|
const line2 = `${BOOTSTRAP_ROOT}/`;
|
|
20856
|
-
const current = existsSync10(file2) ?
|
|
21151
|
+
const current = existsSync10(file2) ? readFileSync11(file2, "utf8") : "";
|
|
20857
21152
|
const ignored = current.split("\n").map((l) => l.trim()).some((l) => l === line2 || l === BOOTSTRAP_ROOT);
|
|
20858
21153
|
if (ignored) return false;
|
|
20859
21154
|
const prefix = current.length > 0 && !current.endsWith("\n") ? "\n" : "";
|
|
@@ -20972,7 +21267,7 @@ function listFiles(cwd) {
|
|
|
20972
21267
|
}
|
|
20973
21268
|
function buildDocsManifest(cwd, files) {
|
|
20974
21269
|
return files.filter((f) => f.startsWith("docs/") && f.endsWith(".md")).map((f) => {
|
|
20975
|
-
const text =
|
|
21270
|
+
const text = readFileSync12(path2.join(cwd, f), "utf8");
|
|
20976
21271
|
const heading = /^#\s+(.+)$/m.exec(text);
|
|
20977
21272
|
return { path: f, title: heading ? heading[1].trim() : path2.basename(f, ".md") };
|
|
20978
21273
|
});
|
|
@@ -20987,7 +21282,7 @@ function buildSurfaceInventory(files) {
|
|
|
20987
21282
|
}
|
|
20988
21283
|
function buildCorpus(options) {
|
|
20989
21284
|
const { cwd } = options;
|
|
20990
|
-
const raw = options.fromJson ? JSON.parse(
|
|
21285
|
+
const raw = options.fromJson ? JSON.parse(readFileSync12(path2.resolve(cwd, options.fromJson), "utf8")) : options.fromGit ? fetchPrsViaGit(cwd) : fetchPrsViaGh(cwd, options.limit);
|
|
20991
21286
|
let prs = normalizePrs(raw);
|
|
20992
21287
|
let sinceDroppedUndated = 0;
|
|
20993
21288
|
if (options.since) {
|
|
@@ -21018,11 +21313,11 @@ function buildCorpus(options) {
|
|
|
21018
21313
|
function readCorpusPrs(cwd) {
|
|
21019
21314
|
const file2 = at(cwd, PRS_FILE);
|
|
21020
21315
|
if (!existsSync11(file2)) return [];
|
|
21021
|
-
return
|
|
21316
|
+
return readFileSync12(file2, "utf8").split("\n").filter(Boolean).map((line2) => JSON.parse(line2));
|
|
21022
21317
|
}
|
|
21023
21318
|
|
|
21024
21319
|
// src/lib/bootstrap/fragments.ts
|
|
21025
|
-
import { existsSync as existsSync12, readFileSync as
|
|
21320
|
+
import { existsSync as existsSync12, readFileSync as readFileSync13 } from "node:fs";
|
|
21026
21321
|
import path3 from "node:path";
|
|
21027
21322
|
function isArrayOfObjects(value) {
|
|
21028
21323
|
return value === void 0 || Array.isArray(value) && value.every((v) => typeof v === "object" && v !== null && !Array.isArray(v));
|
|
@@ -21054,7 +21349,7 @@ function loadFragments(cwd, manifest) {
|
|
|
21054
21349
|
}
|
|
21055
21350
|
let parsed;
|
|
21056
21351
|
try {
|
|
21057
|
-
parsed = JSON.parse(
|
|
21352
|
+
parsed = JSON.parse(readFileSync13(file2, "utf8"));
|
|
21058
21353
|
} catch (err) {
|
|
21059
21354
|
problems.push({ unit: unit2.id, message: `not valid JSON: ${err instanceof Error ? err.message : "parse error"}` });
|
|
21060
21355
|
continue;
|
|
@@ -21091,7 +21386,7 @@ function renderIndex(bundle) {
|
|
|
21091
21386
|
}
|
|
21092
21387
|
|
|
21093
21388
|
// src/lib/bootstrap/manifest.ts
|
|
21094
|
-
import { existsSync as existsSync13, readFileSync as
|
|
21389
|
+
import { existsSync as existsSync13, readFileSync as readFileSync14, writeFileSync as writeFileSync12 } from "node:fs";
|
|
21095
21390
|
import path4 from "node:path";
|
|
21096
21391
|
|
|
21097
21392
|
// src/lib/bootstrap/era-window.ts
|
|
@@ -21202,7 +21497,7 @@ function readProfile(cwd) {
|
|
|
21202
21497
|
const file2 = at(cwd, PROFILE_FILE2);
|
|
21203
21498
|
if (!existsSync13(file2)) return null;
|
|
21204
21499
|
try {
|
|
21205
|
-
return JSON.parse(
|
|
21500
|
+
return JSON.parse(readFileSync14(file2, "utf8"));
|
|
21206
21501
|
} catch (err) {
|
|
21207
21502
|
throw new Error(`cannot read ${PROFILE_FILE2}: ${err instanceof Error ? err.message : String(err)}`);
|
|
21208
21503
|
}
|
|
@@ -21211,7 +21506,7 @@ function readManifest(cwd) {
|
|
|
21211
21506
|
const file2 = at(cwd, MANIFEST_FILE);
|
|
21212
21507
|
if (!existsSync13(file2)) return null;
|
|
21213
21508
|
try {
|
|
21214
|
-
return JSON.parse(
|
|
21509
|
+
return JSON.parse(readFileSync14(file2, "utf8"));
|
|
21215
21510
|
} catch (err) {
|
|
21216
21511
|
throw new Error(`cannot read ${MANIFEST_FILE}: ${err instanceof Error ? err.message : String(err)}`);
|
|
21217
21512
|
}
|
|
@@ -21227,7 +21522,7 @@ function detectMode(cwd, bundlePath) {
|
|
|
21227
21522
|
if (!existsSync13(file2)) return "greenfield";
|
|
21228
21523
|
let parsed;
|
|
21229
21524
|
try {
|
|
21230
|
-
parsed = JSON.parse(
|
|
21525
|
+
parsed = JSON.parse(readFileSync14(file2, "utf8"));
|
|
21231
21526
|
} catch (err) {
|
|
21232
21527
|
throw new Error(`cannot read bundle at ${bundlePath}: ${err instanceof Error ? err.message : String(err)}`);
|
|
21233
21528
|
}
|
|
@@ -21680,7 +21975,7 @@ function mergeFragments(input) {
|
|
|
21680
21975
|
}
|
|
21681
21976
|
|
|
21682
21977
|
// src/lib/bootstrap/slice.ts
|
|
21683
|
-
import { existsSync as existsSync14, readFileSync as
|
|
21978
|
+
import { existsSync as existsSync14, readFileSync as readFileSync15 } from "node:fs";
|
|
21684
21979
|
|
|
21685
21980
|
// src/lib/bootstrap/body-budget.ts
|
|
21686
21981
|
var LAB_NOTE_HEADING_RE = /^##\s+Lab Note.*$/m;
|
|
@@ -21723,7 +22018,7 @@ function boundBody(body) {
|
|
|
21723
22018
|
// src/lib/bootstrap/slice.ts
|
|
21724
22019
|
function readJsonArray(file2) {
|
|
21725
22020
|
if (!existsSync14(file2)) return [];
|
|
21726
|
-
const parsed = JSON.parse(
|
|
22021
|
+
const parsed = JSON.parse(readFileSync15(file2, "utf8"));
|
|
21727
22022
|
return Array.isArray(parsed) ? parsed : [];
|
|
21728
22023
|
}
|
|
21729
22024
|
function toPosix(value) {
|
|
@@ -21797,7 +22092,7 @@ function resolveSlice(cwd, unit2) {
|
|
|
21797
22092
|
}
|
|
21798
22093
|
|
|
21799
22094
|
// src/commands/bootstrap.ts
|
|
21800
|
-
var
|
|
22095
|
+
var USAGE13 = `arkaik bootstrap <subcommand> [options]
|
|
21801
22096
|
|
|
21802
22097
|
Subcommands:
|
|
21803
22098
|
corpus [options] Mine merged PRs, docs and surfaces into .arkaik/corpus/.
|
|
@@ -22127,7 +22422,7 @@ ${MERGE_USAGE}`);
|
|
|
22127
22422
|
function runBootstrap(argv) {
|
|
22128
22423
|
const [sub, ...rest] = argv;
|
|
22129
22424
|
if (sub === void 0 || sub === "-h" || sub === "--help" || sub === "help") {
|
|
22130
|
-
console.log(
|
|
22425
|
+
console.log(USAGE13);
|
|
22131
22426
|
process.exit(0);
|
|
22132
22427
|
}
|
|
22133
22428
|
switch (sub) {
|
|
@@ -22149,7 +22444,7 @@ function runBootstrap(argv) {
|
|
|
22149
22444
|
default:
|
|
22150
22445
|
console.error(`Unknown bootstrap subcommand: ${sub}
|
|
22151
22446
|
|
|
22152
|
-
${
|
|
22447
|
+
${USAGE13}`);
|
|
22153
22448
|
process.exit(1);
|
|
22154
22449
|
}
|
|
22155
22450
|
}
|
|
@@ -22283,8 +22578,8 @@ Pass --domain-name "<display name>" to define it, or use an existing domain code
|
|
|
22283
22578
|
}
|
|
22284
22579
|
|
|
22285
22580
|
// src/commands/kritik.ts
|
|
22286
|
-
import { existsSync as existsSync16, readFileSync as
|
|
22287
|
-
var
|
|
22581
|
+
import { existsSync as existsSync16, readFileSync as readFileSync16 } from "node:fs";
|
|
22582
|
+
var USAGE14 = `arkaik kritik <subcommand> [options]
|
|
22288
22583
|
|
|
22289
22584
|
Audit this product's quality with the Kritik framework: a maturity level per
|
|
22290
22585
|
criterion per surface backed by evidence, findings carrying risk and cost, and
|
|
@@ -22526,7 +22821,7 @@ function textOrFile(value) {
|
|
|
22526
22821
|
if (!value.startsWith("@")) return value;
|
|
22527
22822
|
const path6 = value.slice(1);
|
|
22528
22823
|
if (!existsSync16(path6)) fail12(`kritik: no file at ${path6}`);
|
|
22529
|
-
return
|
|
22824
|
+
return readFileSync16(path6, "utf8").trim();
|
|
22530
22825
|
}
|
|
22531
22826
|
function currentAuditId() {
|
|
22532
22827
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -23502,7 +23797,7 @@ ${CRITERION_USAGE}`);
|
|
|
23502
23797
|
try {
|
|
23503
23798
|
if (single.from !== void 0) {
|
|
23504
23799
|
if (!existsSync16(single.from)) fail12(`kritik: no file at ${single.from}`);
|
|
23505
|
-
criterion = JSON.parse(
|
|
23800
|
+
criterion = JSON.parse(readFileSync16(single.from, "utf8"));
|
|
23506
23801
|
} else {
|
|
23507
23802
|
const anchors = {};
|
|
23508
23803
|
for (const spec of many.anchor) {
|
|
@@ -23557,7 +23852,7 @@ function runKritik(args) {
|
|
|
23557
23852
|
const { rest, common } = takeCommon(args);
|
|
23558
23853
|
const [sub, ...subArgs] = rest;
|
|
23559
23854
|
if (sub === void 0 || sub === "--help" || sub === "-h" || sub === "help") {
|
|
23560
|
-
console.log(
|
|
23855
|
+
console.log(USAGE14);
|
|
23561
23856
|
process.exit(sub === void 0 ? 1 : 0);
|
|
23562
23857
|
}
|
|
23563
23858
|
switch (sub) {
|
|
@@ -23586,12 +23881,12 @@ function runKritik(args) {
|
|
|
23586
23881
|
default:
|
|
23587
23882
|
fail12(`kritik: unknown subcommand "${sub}"
|
|
23588
23883
|
|
|
23589
|
-
${
|
|
23884
|
+
${USAGE14}`);
|
|
23590
23885
|
}
|
|
23591
23886
|
}
|
|
23592
23887
|
|
|
23593
23888
|
// src/index.ts
|
|
23594
|
-
var
|
|
23889
|
+
var USAGE15 = `arkaik \u2014 CLI for Arkaik project bundles
|
|
23595
23890
|
|
|
23596
23891
|
Usage:
|
|
23597
23892
|
arkaik <command> [options]
|
|
@@ -23609,6 +23904,8 @@ Commands:
|
|
|
23609
23904
|
--delete <id> --key <owner_key> removes a snapshot.
|
|
23610
23905
|
link [options] [path] Point this repo at a hosted project so an agent can edit it.
|
|
23611
23906
|
--list shows the projects your token can reach.
|
|
23907
|
+
live --platform <p> [ids] Mark acceptances live on one platform from a deploy (release:append token).
|
|
23908
|
+
--mentions <file> derives them from merged pull requests.
|
|
23612
23909
|
restore [options] [path] Replace the linked project's bundle, journal + quality (backs up first).
|
|
23613
23910
|
bootstrap <sub> [options] One-time onboarding: mine, plan, slice, merge a map from a repo.
|
|
23614
23911
|
kritik <sub> [options] Quality audits: score criteria, open findings, roll up the matrix.
|
|
@@ -23618,11 +23915,11 @@ Options:
|
|
|
23618
23915
|
-v, --version Print the version.
|
|
23619
23916
|
|
|
23620
23917
|
Run "arkaik <command> --help" for command-specific help.`;
|
|
23621
|
-
var VERSION = "0.
|
|
23918
|
+
var VERSION = "0.10.0";
|
|
23622
23919
|
function main(argv) {
|
|
23623
23920
|
const [command, ...rest] = argv;
|
|
23624
23921
|
if (command === void 0 || command === "--help" || command === "-h" || command === "help") {
|
|
23625
|
-
console.log(
|
|
23922
|
+
console.log(USAGE15);
|
|
23626
23923
|
process.exit(0);
|
|
23627
23924
|
}
|
|
23628
23925
|
if (command === "--version" || command === "-v" || command === "version") {
|
|
@@ -23660,6 +23957,9 @@ function main(argv) {
|
|
|
23660
23957
|
case "link":
|
|
23661
23958
|
runLinkCli(rest);
|
|
23662
23959
|
return;
|
|
23960
|
+
case "live":
|
|
23961
|
+
runLiveCli(rest);
|
|
23962
|
+
return;
|
|
23663
23963
|
case "restore":
|
|
23664
23964
|
runRestoreCli(rest);
|
|
23665
23965
|
return;
|
|
@@ -23672,7 +23972,7 @@ function main(argv) {
|
|
|
23672
23972
|
default:
|
|
23673
23973
|
console.error(`Unknown command: ${command}
|
|
23674
23974
|
`);
|
|
23675
|
-
console.error(
|
|
23975
|
+
console.error(USAGE15);
|
|
23676
23976
|
process.exit(1);
|
|
23677
23977
|
}
|
|
23678
23978
|
}
|
package/package.json
CHANGED