arkaik 0.13.0 → 0.14.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 +461 -107
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -801,14 +801,14 @@ function promiseAllObject(promisesObj) {
|
|
|
801
801
|
}
|
|
802
802
|
function randomString(length = 10) {
|
|
803
803
|
const chars = "abcdefghijklmnopqrstuvwxyz";
|
|
804
|
-
let
|
|
804
|
+
let str3 = "";
|
|
805
805
|
for (let i = 0; i < length; i++) {
|
|
806
|
-
|
|
806
|
+
str3 += chars[Math.floor(Math.random() * chars.length)];
|
|
807
807
|
}
|
|
808
|
-
return
|
|
808
|
+
return str3;
|
|
809
809
|
}
|
|
810
|
-
function esc(
|
|
811
|
-
return JSON.stringify(
|
|
810
|
+
function esc(str3) {
|
|
811
|
+
return JSON.stringify(str3);
|
|
812
812
|
}
|
|
813
813
|
function slugify(input) {
|
|
814
814
|
return input.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
@@ -922,8 +922,8 @@ var primitiveTypes = /* @__PURE__ */ new Set([
|
|
|
922
922
|
"symbol",
|
|
923
923
|
"undefined"
|
|
924
924
|
]);
|
|
925
|
-
function escapeRegex(
|
|
926
|
-
return
|
|
925
|
+
function escapeRegex(str3) {
|
|
926
|
+
return str3.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
927
927
|
}
|
|
928
928
|
function clone(inst, def, params) {
|
|
929
929
|
const cl = new inst._zod.constr(def ?? inst._zod.def);
|
|
@@ -15021,13 +15021,13 @@ function crossCheckJournal(bundle) {
|
|
|
15021
15021
|
return findings;
|
|
15022
15022
|
}
|
|
15023
15023
|
if (journalRaw.length === 0) return findings;
|
|
15024
|
-
const
|
|
15024
|
+
const str3 = (v) => typeof v === "string" ? v : void 0;
|
|
15025
15025
|
const nodesRaw = Array.isArray(bundle.nodes) ? bundle.nodes : [];
|
|
15026
15026
|
const edgesRaw = Array.isArray(bundle.edges) ? bundle.edges : [];
|
|
15027
15027
|
const snapshotNodeStatus = /* @__PURE__ */ new Map();
|
|
15028
15028
|
const snapshotDecisionStatus = /* @__PURE__ */ new Map();
|
|
15029
15029
|
for (const n of nodesRaw) {
|
|
15030
|
-
const id =
|
|
15030
|
+
const id = str3(n?.id);
|
|
15031
15031
|
if (id !== void 0) {
|
|
15032
15032
|
snapshotNodeStatus.set(id, n.status);
|
|
15033
15033
|
const metadata = n.metadata;
|
|
@@ -15037,7 +15037,7 @@ function crossCheckJournal(bundle) {
|
|
|
15037
15037
|
}
|
|
15038
15038
|
const snapshotEdgeIds = /* @__PURE__ */ new Set();
|
|
15039
15039
|
for (const e of edgesRaw) {
|
|
15040
|
-
const id =
|
|
15040
|
+
const id = str3(e?.id);
|
|
15041
15041
|
if (id !== void 0) snapshotEdgeIds.add(id);
|
|
15042
15042
|
}
|
|
15043
15043
|
const valid = [];
|
|
@@ -15054,9 +15054,9 @@ function crossCheckJournal(bundle) {
|
|
|
15054
15054
|
}
|
|
15055
15055
|
const ev = raw;
|
|
15056
15056
|
const missing = [];
|
|
15057
|
-
if (
|
|
15058
|
-
if (
|
|
15059
|
-
if (
|
|
15057
|
+
if (str3(ev.id) === void 0) missing.push("id");
|
|
15058
|
+
if (str3(ev.ts) === void 0) missing.push("ts");
|
|
15059
|
+
if (str3(ev.type) === void 0) missing.push("type");
|
|
15060
15060
|
if (missing.length > 0) {
|
|
15061
15061
|
findings.push({
|
|
15062
15062
|
path: path6,
|
|
@@ -15073,14 +15073,14 @@ function crossCheckJournal(bundle) {
|
|
|
15073
15073
|
const baselined = /* @__PURE__ */ new Set();
|
|
15074
15074
|
for (const { ev } of valid) {
|
|
15075
15075
|
if (ev.type === "node.created") {
|
|
15076
|
-
const nid =
|
|
15076
|
+
const nid = str3(ev.node_id);
|
|
15077
15077
|
if (nid) everNodes.add(nid);
|
|
15078
15078
|
} else if (ev.type === "edge.added") {
|
|
15079
|
-
const eid =
|
|
15079
|
+
const eid = str3(ev.edge_id);
|
|
15080
15080
|
if (eid) everEdges.add(eid);
|
|
15081
15081
|
} else if (ev.type === "journal.baseline" && Array.isArray(ev.node_ids)) {
|
|
15082
15082
|
for (const raw of ev.node_ids) {
|
|
15083
|
-
const nid =
|
|
15083
|
+
const nid = str3(raw);
|
|
15084
15084
|
if (nid) {
|
|
15085
15085
|
baselined.add(nid);
|
|
15086
15086
|
everNodes.add(nid);
|
|
@@ -15094,18 +15094,18 @@ function crossCheckJournal(bundle) {
|
|
|
15094
15094
|
const lastDecisionStatus = /* @__PURE__ */ new Map();
|
|
15095
15095
|
for (const ev of ordered) {
|
|
15096
15096
|
if (ev.type === "node.created") {
|
|
15097
|
-
const nid =
|
|
15097
|
+
const nid = str3(ev.node_id);
|
|
15098
15098
|
if (nid) created.add(nid);
|
|
15099
15099
|
} else if (ev.type === "node.status_changed") {
|
|
15100
|
-
const nid =
|
|
15100
|
+
const nid = str3(ev.node_id);
|
|
15101
15101
|
if (nid && ev.platform === void 0) {
|
|
15102
|
-
const to =
|
|
15102
|
+
const to = str3(ev.to);
|
|
15103
15103
|
if (to !== void 0) lastProjectStatus.set(nid, to);
|
|
15104
15104
|
}
|
|
15105
15105
|
} else if (ev.type === "decision.status_changed") {
|
|
15106
|
-
const nid =
|
|
15106
|
+
const nid = str3(ev.node_id);
|
|
15107
15107
|
if (nid) {
|
|
15108
|
-
const to =
|
|
15108
|
+
const to = str3(ev.to);
|
|
15109
15109
|
if (to !== void 0) lastDecisionStatus.set(nid, to);
|
|
15110
15110
|
}
|
|
15111
15111
|
}
|
|
@@ -15114,7 +15114,7 @@ function crossCheckJournal(bundle) {
|
|
|
15114
15114
|
const nodeFields = NODE_REF_FIELDS[ev.type];
|
|
15115
15115
|
if (nodeFields) {
|
|
15116
15116
|
for (const field of nodeFields) {
|
|
15117
|
-
const ref =
|
|
15117
|
+
const ref = str3(ev[field]);
|
|
15118
15118
|
if (ref !== void 0 && !everNodes.has(ref)) {
|
|
15119
15119
|
findings.push({
|
|
15120
15120
|
path: `journal[${index}].${field}`,
|
|
@@ -15127,7 +15127,7 @@ function crossCheckJournal(bundle) {
|
|
|
15127
15127
|
}
|
|
15128
15128
|
if (ev.type === "deliverable.shipped" && Array.isArray(ev.node_ids)) {
|
|
15129
15129
|
ev.node_ids.forEach((raw, i) => {
|
|
15130
|
-
const ref =
|
|
15130
|
+
const ref = str3(raw);
|
|
15131
15131
|
if (ref !== void 0 && !everNodes.has(ref)) {
|
|
15132
15132
|
findings.push({
|
|
15133
15133
|
path: `journal[${index}].node_ids[${i}]`,
|
|
@@ -15139,7 +15139,7 @@ function crossCheckJournal(bundle) {
|
|
|
15139
15139
|
});
|
|
15140
15140
|
}
|
|
15141
15141
|
if (ev.type === "edge.removed") {
|
|
15142
|
-
const ref =
|
|
15142
|
+
const ref = str3(ev.edge_id);
|
|
15143
15143
|
if (ref !== void 0 && !everEdges.has(ref)) {
|
|
15144
15144
|
findings.push({
|
|
15145
15145
|
path: `journal[${index}].edge_id`,
|
|
@@ -15183,7 +15183,7 @@ function crossCheckJournal(bundle) {
|
|
|
15183
15183
|
}
|
|
15184
15184
|
const slots = reduceScreenshotSlots(ordered);
|
|
15185
15185
|
nodesRaw.forEach((n, index) => {
|
|
15186
|
-
const nodeId =
|
|
15186
|
+
const nodeId = str3(n?.id);
|
|
15187
15187
|
if (nodeId === void 0) return;
|
|
15188
15188
|
const metadata = isRecord2(n.metadata) ? n.metadata : {};
|
|
15189
15189
|
const shots = isRecord2(metadata.platformScreenshots) ? metadata.platformScreenshots : {};
|
|
@@ -15202,7 +15202,7 @@ function crossCheckJournal(bundle) {
|
|
|
15202
15202
|
agrees = slot !== void 0;
|
|
15203
15203
|
says = "a data URI was recorded";
|
|
15204
15204
|
} else {
|
|
15205
|
-
const url2 =
|
|
15205
|
+
const url2 = str3(last.url);
|
|
15206
15206
|
agrees = slot === url2;
|
|
15207
15207
|
says = url2 === void 0 ? "an unknown value was recorded" : `"${url2}" was recorded`;
|
|
15208
15208
|
}
|
|
@@ -17267,14 +17267,14 @@ function resolveWeighing(section) {
|
|
|
17267
17267
|
const sets = [...BUILT_IN_SETS];
|
|
17268
17268
|
const matrices = [...BUILT_IN_MATRICES];
|
|
17269
17269
|
const skipped = [];
|
|
17270
|
-
const
|
|
17270
|
+
const idOf3 = (entry) => isObject2(entry) ? { ...typeof entry.id === "string" ? { id: entry.id } : {}, ...typeof entry.role === "string" ? { role: entry.role } : {} } : {};
|
|
17271
17271
|
(Array.isArray(section?.sets) ? section.sets : []).forEach((set2, index) => {
|
|
17272
17272
|
if (isWeighingSetShape(set2) && !sets.some((s) => s.id === set2.id)) sets.push(cleaned(set2));
|
|
17273
|
-
else skipped.push({ kind: "set", ...
|
|
17273
|
+
else skipped.push({ kind: "set", ...idOf3(set2), index });
|
|
17274
17274
|
});
|
|
17275
17275
|
(Array.isArray(section?.matrices) ? section.matrices : []).forEach((matrix, index) => {
|
|
17276
17276
|
if (isWeighingMatrixShape(matrix) && !matrices.some((m) => m.id === matrix.id)) matrices.push(matrix);
|
|
17277
|
-
else skipped.push({ kind: "matrix", ...
|
|
17277
|
+
else skipped.push({ kind: "matrix", ...idOf3(matrix), index });
|
|
17278
17278
|
});
|
|
17279
17279
|
return { sets, matrices, skipped };
|
|
17280
17280
|
}
|
|
@@ -19892,6 +19892,62 @@ function burndownSummary(burndown, openNow) {
|
|
|
19892
19892
|
return `${closed} closed${where2} (${tally.resolved} resolved, ${tally.accepted} accepted) \xB7 ${tally.opened} opened \xB7 ${open} open`;
|
|
19893
19893
|
}
|
|
19894
19894
|
|
|
19895
|
+
// ../schema/src/weighing-events.ts
|
|
19896
|
+
var asArray2 = (value) => Array.isArray(value) ? value : [];
|
|
19897
|
+
function timeOf(ts) {
|
|
19898
|
+
const time3 = typeof ts === "string" ? Date.parse(ts) : Number.NaN;
|
|
19899
|
+
return Number.isNaN(time3) ? Number.NEGATIVE_INFINITY : time3;
|
|
19900
|
+
}
|
|
19901
|
+
function assessmentOfEvent(event) {
|
|
19902
|
+
const e = event;
|
|
19903
|
+
const scorer = e.scorer;
|
|
19904
|
+
if (typeof e.matrix !== "string" || e.matrix === "" || typeof e.subject !== "string" || e.subject === "" || typeof e.criterion !== "string" || e.criterion === "" || typeof e.level !== "number" || !Number.isInteger(e.level) || typeof e.confidence !== "number" || typeof e.ts !== "string" || e.ts === "" || typeof scorer !== "object" || scorer === null || typeof scorer.kind !== "string" || // A `rule` row is computed on read and never stored (D3): an event claiming to be one is skipped,
|
|
19905
|
+
// whoever appended it, so a seed can never be forged into a stored cell.
|
|
19906
|
+
scorer.kind === "rule" || typeof scorer.id !== "string") {
|
|
19907
|
+
return void 0;
|
|
19908
|
+
}
|
|
19909
|
+
const { id: _id, actor: _actor, type: _type, v: _v, ...rest } = e;
|
|
19910
|
+
void _id;
|
|
19911
|
+
void _actor;
|
|
19912
|
+
void _type;
|
|
19913
|
+
void _v;
|
|
19914
|
+
return rest;
|
|
19915
|
+
}
|
|
19916
|
+
function foldWeighingEvents(section, events) {
|
|
19917
|
+
const relevant = events.filter((event) => event?.type === WEIGHING_ASSESSMENT_RECORDED || event?.type === WEIGHING_SET_SAVED);
|
|
19918
|
+
if (relevant.length === 0) return section;
|
|
19919
|
+
const assessments = [...asArray2(section?.assessments)];
|
|
19920
|
+
const setTimes = /* @__PURE__ */ new Map();
|
|
19921
|
+
let sets = asArray2(section?.sets);
|
|
19922
|
+
for (const event of relevant) {
|
|
19923
|
+
if (event.type === WEIGHING_ASSESSMENT_RECORDED) {
|
|
19924
|
+
const row = assessmentOfEvent(event);
|
|
19925
|
+
if (row === void 0) continue;
|
|
19926
|
+
const key = assessmentKey(row);
|
|
19927
|
+
const at3 = assessments.findIndex((existing) => assessmentKey(existing) === key);
|
|
19928
|
+
if (at3 === -1) assessments.push(row);
|
|
19929
|
+
else if (timeOf(row.ts) >= timeOf(assessments[at3]?.ts)) assessments[at3] = row;
|
|
19930
|
+
continue;
|
|
19931
|
+
}
|
|
19932
|
+
const set2 = event.set;
|
|
19933
|
+
if (typeof set2 !== "object" || set2 === null || Array.isArray(set2)) continue;
|
|
19934
|
+
const id = set2.id;
|
|
19935
|
+
if (typeof id !== "string" || id === "") continue;
|
|
19936
|
+
const at2 = sets.findIndex((existing) => existing?.id === id);
|
|
19937
|
+
const time3 = timeOf(event.ts);
|
|
19938
|
+
if (at2 === -1) {
|
|
19939
|
+
sets = [...sets, set2];
|
|
19940
|
+
setTimes.set(id, time3);
|
|
19941
|
+
} else {
|
|
19942
|
+
const known = setTimes.get(id);
|
|
19943
|
+
if (known !== void 0 && time3 < known) continue;
|
|
19944
|
+
sets = sets.map((existing, i) => i === at2 ? set2 : existing);
|
|
19945
|
+
setTimes.set(id, time3);
|
|
19946
|
+
}
|
|
19947
|
+
}
|
|
19948
|
+
return { ...section ?? {}, sets, matrices: asArray2(section?.matrices), assessments };
|
|
19949
|
+
}
|
|
19950
|
+
|
|
19895
19951
|
// ../schema/src/weighing-derive.ts
|
|
19896
19952
|
var SEED_SCORER_ID = "seed-claimed";
|
|
19897
19953
|
var SEED_SCORER = Object.freeze({ kind: "rule", id: SEED_SCORER_ID });
|
|
@@ -22998,19 +23054,249 @@ function runShotCli(argv) {
|
|
|
22998
23054
|
// src/commands/restore.ts
|
|
22999
23055
|
import { existsSync as existsSync11, linkSync, mkdirSync as mkdirSync6, readFileSync as readFileSync11, unlinkSync, writeFileSync as writeFileSync10 } from "node:fs";
|
|
23000
23056
|
import { join as join11, resolve as resolve11 } from "node:path";
|
|
23057
|
+
|
|
23058
|
+
// src/lib/restore-merge.ts
|
|
23059
|
+
var RESTORE_ACTOR = "arkaik-restore";
|
|
23060
|
+
var isRecord7 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23061
|
+
var asArray3 = (value) => Array.isArray(value) ? value : [];
|
|
23062
|
+
var str2 = (value) => typeof value === "string" ? value : void 0;
|
|
23063
|
+
var idOf2 = (item) => isRecord7(item) ? str2(item.id) : void 0;
|
|
23064
|
+
var winTime = (ts) => {
|
|
23065
|
+
const t = typeof ts === "string" ? Date.parse(ts) : NaN;
|
|
23066
|
+
return Number.isNaN(t) ? Number.NEGATIVE_INFINITY : t;
|
|
23067
|
+
};
|
|
23068
|
+
function sameJson(a, b) {
|
|
23069
|
+
if (a === b) return true;
|
|
23070
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
23071
|
+
return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((item, i) => sameJson(item, b[i]));
|
|
23072
|
+
}
|
|
23073
|
+
if (!isRecord7(a) || !isRecord7(b)) return false;
|
|
23074
|
+
const keys = Object.keys(a);
|
|
23075
|
+
return keys.length === Object.keys(b).length && keys.every((key) => key in b && sameJson(a[key], b[key]));
|
|
23076
|
+
}
|
|
23077
|
+
function unionById(primary, secondary) {
|
|
23078
|
+
const seen = /* @__PURE__ */ new Set();
|
|
23079
|
+
for (const item of primary) {
|
|
23080
|
+
const id = idOf2(item);
|
|
23081
|
+
if (id !== void 0) seen.add(id);
|
|
23082
|
+
}
|
|
23083
|
+
const merged = [...primary];
|
|
23084
|
+
const added = [];
|
|
23085
|
+
for (const item of secondary) {
|
|
23086
|
+
const id = idOf2(item);
|
|
23087
|
+
if (id !== void 0 && seen.has(id)) continue;
|
|
23088
|
+
if (id !== void 0) seen.add(id);
|
|
23089
|
+
merged.push(item);
|
|
23090
|
+
added.push(item);
|
|
23091
|
+
}
|
|
23092
|
+
return { merged, added };
|
|
23093
|
+
}
|
|
23094
|
+
var isIdList = (value) => Array.isArray(value) && value.every((item) => idOf2(item) !== void 0);
|
|
23095
|
+
function mergeMetadata(hosted, local) {
|
|
23096
|
+
const metadata = { ...hosted, ...local };
|
|
23097
|
+
const kept = [];
|
|
23098
|
+
for (const key of Object.keys(hosted)) {
|
|
23099
|
+
if (!(key in local)) {
|
|
23100
|
+
kept.push(key);
|
|
23101
|
+
continue;
|
|
23102
|
+
}
|
|
23103
|
+
const h = hosted[key];
|
|
23104
|
+
const l = local[key];
|
|
23105
|
+
if (isIdList(h) && isIdList(l)) {
|
|
23106
|
+
const union2 = unionById(l, h);
|
|
23107
|
+
metadata[key] = union2.merged;
|
|
23108
|
+
if (union2.added.length > 0) kept.push(key);
|
|
23109
|
+
} else if (isRecord7(h) && isRecord7(l)) {
|
|
23110
|
+
metadata[key] = { ...h, ...l };
|
|
23111
|
+
if (Object.keys(h).some((inner) => !(inner in l))) kept.push(key);
|
|
23112
|
+
}
|
|
23113
|
+
}
|
|
23114
|
+
return { metadata, kept: kept.sort() };
|
|
23115
|
+
}
|
|
23116
|
+
function reconcileStatuses(nodes, journal, localEventIds) {
|
|
23117
|
+
const lastStatus = /* @__PURE__ */ new Map();
|
|
23118
|
+
const lastDecision = /* @__PURE__ */ new Map();
|
|
23119
|
+
for (const event of journal) {
|
|
23120
|
+
if (!isRecord7(event)) continue;
|
|
23121
|
+
const nodeId = str2(event.node_id);
|
|
23122
|
+
if (nodeId === void 0 || str2(event.to) === void 0) continue;
|
|
23123
|
+
if (event.type === "node.status_changed" && event.platform === void 0) lastStatus.set(nodeId, event);
|
|
23124
|
+
else if (event.type === "decision.status_changed") lastDecision.set(nodeId, event);
|
|
23125
|
+
}
|
|
23126
|
+
const hostedOnly = (event) => {
|
|
23127
|
+
const id = event === void 0 ? void 0 : str2(event.id);
|
|
23128
|
+
return id !== void 0 && !localEventIds.has(id);
|
|
23129
|
+
};
|
|
23130
|
+
const changed = /* @__PURE__ */ new Set();
|
|
23131
|
+
nodes.forEach((node, index) => {
|
|
23132
|
+
const id = idOf2(node);
|
|
23133
|
+
if (id === void 0 || !isRecord7(node)) return;
|
|
23134
|
+
let next = node;
|
|
23135
|
+
const status = lastStatus.get(id);
|
|
23136
|
+
if (hostedOnly(status) && next.status !== status.to) next = { ...next, status: status.to };
|
|
23137
|
+
const decision = lastDecision.get(id);
|
|
23138
|
+
if (hostedOnly(decision)) {
|
|
23139
|
+
const metadata = isRecord7(next.metadata) ? next.metadata : {};
|
|
23140
|
+
if (metadata.decision_status !== decision.to) next = { ...next, metadata: { ...metadata, decision_status: decision.to } };
|
|
23141
|
+
}
|
|
23142
|
+
if (next !== node) {
|
|
23143
|
+
nodes[index] = next;
|
|
23144
|
+
changed.add(id);
|
|
23145
|
+
}
|
|
23146
|
+
});
|
|
23147
|
+
return [...changed].sort();
|
|
23148
|
+
}
|
|
23149
|
+
function mergeWeighing(hosted, local) {
|
|
23150
|
+
if (!isRecord7(hosted)) return { weighing: isRecord7(local) ? local : void 0, kept: 0 };
|
|
23151
|
+
if (!isRecord7(local)) {
|
|
23152
|
+
const kept = asArray3(hosted.sets).length + asArray3(hosted.matrices).length + asArray3(hosted.assessments).length;
|
|
23153
|
+
return { weighing: hosted, kept };
|
|
23154
|
+
}
|
|
23155
|
+
const sets = unionById(asArray3(local.sets), asArray3(hosted.sets));
|
|
23156
|
+
const matrices = unionById(asArray3(local.matrices), asArray3(hosted.matrices));
|
|
23157
|
+
const assessments = [...asArray3(local.assessments)];
|
|
23158
|
+
let keptAssessments = 0;
|
|
23159
|
+
const keyOf = (row) => isRecord7(row) ? assessmentKey(row) : void 0;
|
|
23160
|
+
for (const row of asArray3(hosted.assessments)) {
|
|
23161
|
+
const key = keyOf(row);
|
|
23162
|
+
const at2 = key === void 0 ? -1 : assessments.findIndex((existing) => keyOf(existing) === key);
|
|
23163
|
+
if (at2 === -1) {
|
|
23164
|
+
assessments.push(row);
|
|
23165
|
+
keptAssessments++;
|
|
23166
|
+
} else if (winTime(row.ts) > winTime(assessments[at2].ts)) {
|
|
23167
|
+
assessments[at2] = row;
|
|
23168
|
+
keptAssessments++;
|
|
23169
|
+
}
|
|
23170
|
+
}
|
|
23171
|
+
const weighing = { ...hosted, ...local };
|
|
23172
|
+
if (sets.merged.length > 0 || "sets" in local || "sets" in hosted) weighing.sets = sets.merged;
|
|
23173
|
+
if (matrices.merged.length > 0 || "matrices" in local || "matrices" in hosted) weighing.matrices = matrices.merged;
|
|
23174
|
+
if (assessments.length > 0 || "assessments" in local || "assessments" in hosted) weighing.assessments = assessments;
|
|
23175
|
+
return { weighing, kept: sets.added.length + matrices.added.length + keptAssessments };
|
|
23176
|
+
}
|
|
23177
|
+
function resaveLocalSets(hostedWeighing, hostedJournal, localWeighing, now) {
|
|
23178
|
+
if (!isRecord7(localWeighing)) return [];
|
|
23179
|
+
const savedOnHost = /* @__PURE__ */ new Set();
|
|
23180
|
+
for (const event of hostedJournal) {
|
|
23181
|
+
if (isRecord7(event) && event.type === WEIGHING_SET_SAVED && isRecord7(event.set)) {
|
|
23182
|
+
const id = str2(event.set.id);
|
|
23183
|
+
if (id !== void 0) savedOnHost.add(id);
|
|
23184
|
+
}
|
|
23185
|
+
}
|
|
23186
|
+
if (savedOnHost.size === 0) return [];
|
|
23187
|
+
const hostedReading = foldWeighingEvents(
|
|
23188
|
+
isRecord7(hostedWeighing) ? hostedWeighing : void 0,
|
|
23189
|
+
hostedJournal.filter(isRecord7)
|
|
23190
|
+
);
|
|
23191
|
+
const events = [];
|
|
23192
|
+
for (const set2 of asArray3(localWeighing.sets)) {
|
|
23193
|
+
const id = idOf2(set2);
|
|
23194
|
+
if (id === void 0 || !savedOnHost.has(id)) continue;
|
|
23195
|
+
const onHost = asArray3(hostedReading?.sets).find((existing) => idOf2(existing) === id);
|
|
23196
|
+
if (sameJson(onHost, set2)) continue;
|
|
23197
|
+
events.push(makeEvent(WEIGHING_SET_SAVED, { set: set2 }, { actor: RESTORE_ACTOR, ts: now }));
|
|
23198
|
+
}
|
|
23199
|
+
return events;
|
|
23200
|
+
}
|
|
23201
|
+
function mergeForAppend(hosted, local, now = /* @__PURE__ */ new Date()) {
|
|
23202
|
+
const bundle = { ...hosted, ...local };
|
|
23203
|
+
let metadataKeys = [];
|
|
23204
|
+
if (isRecord7(hosted.project) || isRecord7(local.project)) {
|
|
23205
|
+
const hostedProject = isRecord7(hosted.project) ? hosted.project : {};
|
|
23206
|
+
const localProject = isRecord7(local.project) ? local.project : {};
|
|
23207
|
+
const project = { ...hostedProject, ...localProject };
|
|
23208
|
+
if (isRecord7(hostedProject.metadata)) {
|
|
23209
|
+
const merged = mergeMetadata(hostedProject.metadata, isRecord7(localProject.metadata) ? localProject.metadata : {});
|
|
23210
|
+
project.metadata = merged.metadata;
|
|
23211
|
+
metadataKeys = merged.kept;
|
|
23212
|
+
}
|
|
23213
|
+
bundle.project = project;
|
|
23214
|
+
}
|
|
23215
|
+
const localProjectId = isRecord7(local.project) ? str2(local.project.id) : void 0;
|
|
23216
|
+
const hostedProjectId = isRecord7(hosted.project) ? str2(hosted.project.id) : void 0;
|
|
23217
|
+
const restamp = (item) => localProjectId !== void 0 && localProjectId !== hostedProjectId && isRecord7(item) && item.project_id === hostedProjectId ? { ...item, project_id: localProjectId } : item;
|
|
23218
|
+
const nodes = unionById(asArray3(local.nodes), asArray3(hosted.nodes).map(restamp));
|
|
23219
|
+
const edges = unionById(asArray3(local.edges), asArray3(hosted.edges).map(restamp));
|
|
23220
|
+
const hostedJournal = asArray3(hosted.journal);
|
|
23221
|
+
const localJournal = asArray3(local.journal);
|
|
23222
|
+
const localEventIds = new Set(localJournal.map(idOf2).filter((id) => id !== void 0));
|
|
23223
|
+
const hostedEventIds = new Set(hostedJournal.map(idOf2).filter((id) => id !== void 0));
|
|
23224
|
+
const resaved = resaveLocalSets(hosted.weighing, hostedJournal, local.weighing, now);
|
|
23225
|
+
const journal = orderEvents(unionById([...hostedJournal, ...resaved], localJournal).merged);
|
|
23226
|
+
bundle.journal = journal;
|
|
23227
|
+
const eventsKept = [...hostedEventIds].filter((id) => !localEventIds.has(id)).length;
|
|
23228
|
+
const statuses = reconcileStatuses(nodes.merged, journal, localEventIds);
|
|
23229
|
+
bundle.nodes = nodes.merged;
|
|
23230
|
+
bundle.edges = edges.merged;
|
|
23231
|
+
let qualityKept = false;
|
|
23232
|
+
if (isQualitySection(local.quality)) bundle.quality = local.quality;
|
|
23233
|
+
else if (isQualitySection(hosted.quality)) {
|
|
23234
|
+
bundle.quality = hosted.quality;
|
|
23235
|
+
qualityKept = true;
|
|
23236
|
+
} else delete bundle.quality;
|
|
23237
|
+
const weighing = mergeWeighing(hosted.weighing, local.weighing);
|
|
23238
|
+
if (weighing.weighing === void 0) delete bundle.weighing;
|
|
23239
|
+
else bundle.weighing = weighing.weighing;
|
|
23240
|
+
return {
|
|
23241
|
+
bundle,
|
|
23242
|
+
kept: {
|
|
23243
|
+
nodes: nodes.added.length,
|
|
23244
|
+
edges: edges.added.length,
|
|
23245
|
+
events: eventsKept,
|
|
23246
|
+
metadataKeys,
|
|
23247
|
+
statuses,
|
|
23248
|
+
qualityKept,
|
|
23249
|
+
weighingRows: weighing.kept,
|
|
23250
|
+
setsResaved: resaved.map((event) => String(event.set.id))
|
|
23251
|
+
}
|
|
23252
|
+
};
|
|
23253
|
+
}
|
|
23254
|
+
function describeAppendSummary(kept) {
|
|
23255
|
+
const parts = [];
|
|
23256
|
+
const n = (count, one, many = `${one}s`) => `${count} ${count === 1 ? one : many}`;
|
|
23257
|
+
if (kept.nodes > 0) parts.push(n(kept.nodes, "node"));
|
|
23258
|
+
if (kept.edges > 0) parts.push(n(kept.edges, "edge"));
|
|
23259
|
+
if (kept.events > 0) parts.push(n(kept.events, "journal event"));
|
|
23260
|
+
if (kept.metadataKeys.length > 0) parts.push(`project settings (${kept.metadataKeys.join(", ")})`);
|
|
23261
|
+
if (kept.qualityKept) parts.push("the quality section");
|
|
23262
|
+
if (kept.weighingRows > 0) parts.push(n(kept.weighingRows, "weighing row"));
|
|
23263
|
+
const lines = [
|
|
23264
|
+
parts.length === 0 ? "Append: the hosted project held nothing your bundle lacks." : `Append: kept what only the hosted project had \u2014 ${parts.join(", ")}.`
|
|
23265
|
+
];
|
|
23266
|
+
if (kept.statuses.length > 0) {
|
|
23267
|
+
lines.push(` Took the hosted status of ${kept.statuses.join(", ")}: it was changed on the hosted project after your copy.`);
|
|
23268
|
+
}
|
|
23269
|
+
if (kept.setsResaved.length > 0) {
|
|
23270
|
+
lines.push(` Re-saved criteria set ${kept.setsResaved.join(", ")} from your bundle, so it replaces the hosted version.`);
|
|
23271
|
+
}
|
|
23272
|
+
return lines.join("\n");
|
|
23273
|
+
}
|
|
23274
|
+
|
|
23275
|
+
// src/commands/restore.ts
|
|
23001
23276
|
var LINK_FILE4 = "docs/arkaik/arkaik.json";
|
|
23002
23277
|
var DEFAULT_BUNDLE_PATH10 = "docs/arkaik/bundle.json";
|
|
23003
23278
|
var DEFAULT_API_BASE2 = "https://arkaik.app";
|
|
23004
23279
|
var USAGE13 = `arkaik restore [options] [path]
|
|
23005
23280
|
|
|
23006
|
-
|
|
23007
|
-
|
|
23008
|
-
|
|
23009
|
-
|
|
23010
|
-
|
|
23011
|
-
|
|
23012
|
-
|
|
23013
|
-
|
|
23281
|
+
Land a local bundle on the linked hosted project \u2014 the landing step for a
|
|
23282
|
+
bootstrapped map.
|
|
23283
|
+
|
|
23284
|
+
By default this APPENDS: the local bundle is merged into what the hosted
|
|
23285
|
+
project already holds. Hosted-only events, nodes, edges, project settings,
|
|
23286
|
+
quality and weighing state are all kept; where both sides hold the same id,
|
|
23287
|
+
the local record wins, except a status changed on the hosted project after
|
|
23288
|
+
your copy. Nothing on the hosted project is removed.
|
|
23289
|
+
|
|
23290
|
+
--replace swaps the hosted bundle, journal and sections for the local ones
|
|
23291
|
+
wholesale, removing whatever the local bundle lacks. That is what undoing a
|
|
23292
|
+
restore from a backup needs, and it refuses any loss you have not allowed
|
|
23293
|
+
with an --allow-* flag.
|
|
23294
|
+
|
|
23295
|
+
Before a real run sends anything, this exports the CURRENT hosted state
|
|
23296
|
+
(snapshot + journal) to docs/arkaik/.backups/<timestamp>-bundle.json (next to
|
|
23297
|
+
the link file \u2014 not wherever the local bundle happens to live) and refuses to
|
|
23298
|
+
proceed if that backup cannot be written \u2014 the server keeps no pre-image, so
|
|
23299
|
+
this file is the only way back if the restore turns out to be wrong.
|
|
23014
23300
|
|
|
23015
23301
|
Arguments:
|
|
23016
23302
|
path Path to the local bundle JSON file
|
|
@@ -23024,6 +23310,14 @@ Options:
|
|
|
23024
23310
|
the delta. Sends nothing destructive and takes no
|
|
23025
23311
|
backup (there is nothing to protect against in this
|
|
23026
23312
|
mode).
|
|
23313
|
+
--replace Replace the hosted project wholesale instead of
|
|
23314
|
+
appending to it. Anything the local bundle lacks is
|
|
23315
|
+
removed, so each kind of loss below refuses unless its
|
|
23316
|
+
--allow-* flag is passed too. Undo a restore with
|
|
23317
|
+
the command a real restore prints (--replace with
|
|
23318
|
+
every --allow-* flag).
|
|
23319
|
+
|
|
23320
|
+
Only with --replace:
|
|
23027
23321
|
--allow-history-loss Proceed even though the outbound journal has fewer
|
|
23028
23322
|
events than the hosted one currently holds. Without
|
|
23029
23323
|
this flag, that shrink refuses outright \u2014 it usually
|
|
@@ -23037,22 +23331,6 @@ Options:
|
|
|
23037
23331
|
local copy (edited in the app), not an intended
|
|
23038
23332
|
deletion. Undoing a restore from a backup is the
|
|
23039
23333
|
common case where it IS intended.
|
|
23040
|
-
--no-quality Do not send a quality section: skip the docs/quality/
|
|
23041
|
-
fold AND drop any section the local bundle already
|
|
23042
|
-
carries. Does NOT by itself permit erasing the hosted
|
|
23043
|
-
one \u2014 that needs --allow-quality-loss too, because
|
|
23044
|
-
"don't send mine" and "destroy theirs" are different
|
|
23045
|
-
decisions and only one of them is irreversible.
|
|
23046
|
-
--no-weighing Do not send a weighing section: skip the docs/weighing/
|
|
23047
|
-
fold AND drop any section the local bundle already
|
|
23048
|
-
carries. WARNING: a restore replaces the hosted
|
|
23049
|
-
journal, and an assessment recorded only on the hosted
|
|
23050
|
-
project lives in that journal. The history guard
|
|
23051
|
-
compares COUNTS, so it does NOT reliably protect those
|
|
23052
|
-
events: a repo whose journal is as long as the hosted
|
|
23053
|
-
one passes it while still erasing them. The backup this
|
|
23054
|
-
command writes first holds them; the proper fix is
|
|
23055
|
-
issue #624 (restore appends by default).
|
|
23056
23334
|
--allow-quality-loss Proceed even though the restore would erase a quality
|
|
23057
23335
|
section the hosted project currently has. Without this
|
|
23058
23336
|
flag, that refuses outright \u2014 it usually means
|
|
@@ -23064,6 +23342,24 @@ Options:
|
|
|
23064
23342
|
refuses outright and names the keys \u2014 those settings
|
|
23065
23343
|
are usually edited in the app and never reach the
|
|
23066
23344
|
repo bundle, so a restore would silently delete them.
|
|
23345
|
+
|
|
23346
|
+
Either mode:
|
|
23347
|
+
--no-quality Do not send a quality section: skip the docs/quality/
|
|
23348
|
+
fold AND drop any section the local bundle already
|
|
23349
|
+
carries. An append keeps the hosted section. Under
|
|
23350
|
+
--replace this does NOT by itself permit erasing the
|
|
23351
|
+
hosted one \u2014 that needs --allow-quality-loss too,
|
|
23352
|
+
because "don't send mine" and "destroy theirs" are
|
|
23353
|
+
different decisions and only one is irreversible.
|
|
23354
|
+
--no-weighing Do not send a weighing section: skip the docs/weighing/
|
|
23355
|
+
fold AND drop any section the local bundle already
|
|
23356
|
+
carries. An append keeps the hosted section and every
|
|
23357
|
+
hosted assessment event. WARNING under --replace: an
|
|
23358
|
+
assessment recorded only on the hosted project lives in
|
|
23359
|
+
the journal that --replace overwrites, and the history
|
|
23360
|
+
guard compares COUNTS, so it does not reliably protect
|
|
23361
|
+
those events. The backup this command writes first
|
|
23362
|
+
holds them.
|
|
23067
23363
|
--audit <id> Fold ONE audit's snapshot rather than merging every
|
|
23068
23364
|
audit into current state. An id that is not on disk is
|
|
23069
23365
|
an error, not an empty section.
|
|
@@ -23102,12 +23398,28 @@ function describeVersionReadFailure(status, baseUrl, projectId) {
|
|
|
23102
23398
|
}
|
|
23103
23399
|
function backupNoteFor(backupPath) {
|
|
23104
23400
|
if (!backupPath) return "";
|
|
23105
|
-
return ` Your pre-restore backup is at ${backupPath}. Undo this restore with:
|
|
23401
|
+
return ` Your pre-restore backup is at ${backupPath}. Undo this restore with: ${undoCommandFor(backupPath)}`;
|
|
23402
|
+
}
|
|
23403
|
+
function undoCommandFor(backupPath) {
|
|
23404
|
+
return `arkaik restore --replace --allow-history-loss --allow-deletions --allow-quality-loss --allow-metadata-loss ${backupPath}`;
|
|
23405
|
+
}
|
|
23406
|
+
function allowFlagsOf(options) {
|
|
23407
|
+
return [
|
|
23408
|
+
options.allowHistoryLoss && "--allow-history-loss",
|
|
23409
|
+
options.allowDeletions && "--allow-deletions",
|
|
23410
|
+
options.allowQualityLoss && "--allow-quality-loss",
|
|
23411
|
+
options.allowMetadataLoss && "--allow-metadata-loss"
|
|
23412
|
+
].filter((flag) => typeof flag === "string");
|
|
23413
|
+
}
|
|
23414
|
+
function describeAllowWithoutReplace(flags) {
|
|
23415
|
+
return `${flags.join(", ")} only ${flags.length === 1 ? "applies" : "apply"} with --replace. restore appends by default and removes nothing, so there is no loss to allow. To replace the hosted project (for example to undo a restore from a backup), add --replace.`;
|
|
23106
23416
|
}
|
|
23107
23417
|
async function interpretPutResponse(res, ctx) {
|
|
23108
23418
|
const base = {
|
|
23109
23419
|
ok: true,
|
|
23110
23420
|
dryRun: ctx.dryRun,
|
|
23421
|
+
mode: ctx.mode,
|
|
23422
|
+
kept: ctx.kept,
|
|
23111
23423
|
bundlePath: ctx.bundlePath,
|
|
23112
23424
|
backupPath: ctx.backupPath,
|
|
23113
23425
|
requestSent: true,
|
|
@@ -23261,10 +23573,34 @@ function describeMetadataLoss(dropped, bundlePath) {
|
|
|
23261
23573
|
`Those settings are usually edited in the app and never reach the repo bundle. Copy them into the local bundle's project.metadata (GET .../export has them) so the restore keeps them, or re-run with --allow-metadata-loss if they really are meant to go.`
|
|
23262
23574
|
].join("\n");
|
|
23263
23575
|
}
|
|
23576
|
+
async function fetchExport(httpClient, url2, headers, dryRun) {
|
|
23577
|
+
const why = dryRun ? "An append preview needs it to merge." : "Refusing to restore without a backup.";
|
|
23578
|
+
let exported;
|
|
23579
|
+
try {
|
|
23580
|
+
const exportRes = await httpClient(url2, { headers });
|
|
23581
|
+
if (!exportRes.ok) {
|
|
23582
|
+
return `Could not export the current hosted state (${exportRes.status}). ${why} Nothing was sent.`;
|
|
23583
|
+
}
|
|
23584
|
+
const body = await safeJson(exportRes);
|
|
23585
|
+
exported = body.bundle;
|
|
23586
|
+
} catch (e) {
|
|
23587
|
+
return `Could not export the current hosted state: ${e.message}. ${why}`;
|
|
23588
|
+
}
|
|
23589
|
+
if (typeof exported !== "object" || exported === null || Array.isArray(exported)) {
|
|
23590
|
+
return `The export response was not a bundle. ${why} Nothing was sent.`;
|
|
23591
|
+
}
|
|
23592
|
+
const bundle = exported;
|
|
23593
|
+
if (!Array.isArray(bundle.journal) || !Array.isArray(bundle.nodes) || !Array.isArray(bundle.edges)) {
|
|
23594
|
+
return dryRun ? "The exported bundle is missing nodes, edges, or a journal array, so there is nothing whole to merge into. Nothing was sent." : "The exported bundle is missing nodes, edges, or a journal array \u2014 an incomplete backup would not cover what restore is about to destroy. Refusing to restore. Nothing was sent.";
|
|
23595
|
+
}
|
|
23596
|
+
return bundle;
|
|
23597
|
+
}
|
|
23264
23598
|
async function runRestore(options = {}) {
|
|
23265
23599
|
const cwd = options.cwd ?? process.cwd();
|
|
23266
23600
|
const env = options.env ?? process.env;
|
|
23267
23601
|
const dryRun = options.dryRun ?? false;
|
|
23602
|
+
const replace = options.replace ?? false;
|
|
23603
|
+
const mode = replace ? "replace" : "append";
|
|
23268
23604
|
const allowHistoryLoss = options.allowHistoryLoss ?? false;
|
|
23269
23605
|
const allowDeletions = options.allowDeletions ?? false;
|
|
23270
23606
|
const noQuality = options.noQuality ?? false;
|
|
@@ -23272,6 +23608,8 @@ async function runRestore(options = {}) {
|
|
|
23272
23608
|
const allowQualityLoss = options.allowQualityLoss ?? false;
|
|
23273
23609
|
const allowMetadataLoss = options.allowMetadataLoss ?? false;
|
|
23274
23610
|
const httpClient = options.httpClient ?? DEFAULT_HTTP_CLIENT;
|
|
23611
|
+
const strayAllowFlags = allowFlagsOf(options);
|
|
23612
|
+
if (strayAllowFlags.length > 0 && !replace) return fatalResult5(dryRun, describeAllowWithoutReplace(strayAllowFlags));
|
|
23275
23613
|
const linkPath = join11(cwd, LINK_FILE4);
|
|
23276
23614
|
if (!existsSync11(linkPath)) {
|
|
23277
23615
|
return fatalResult5(dryRun, `No ${LINK_FILE4}. Run \`arkaik link\` first \u2014 restore only targets hosted projects.`);
|
|
@@ -23343,7 +23681,25 @@ async function runRestore(options = {}) {
|
|
|
23343
23681
|
return fatalResult5(dryRun, `Could not read the project: ${e.message}`);
|
|
23344
23682
|
}
|
|
23345
23683
|
const putHeaders = { ...headers, "Content-Type": "application/json", "If-Match": `"${version2}"` };
|
|
23346
|
-
|
|
23684
|
+
let exportedBundle;
|
|
23685
|
+
if (!(replace && dryRun)) {
|
|
23686
|
+
const read = await fetchExport(httpClient, `${baseUrl}/api/graph/projects/${encodedProjectId}/export`, headers, dryRun);
|
|
23687
|
+
if (typeof read === "string") return fatalResult5(dryRun, read, qualityFields);
|
|
23688
|
+
exportedBundle = read;
|
|
23689
|
+
}
|
|
23690
|
+
let sendBundle = outboundBundle;
|
|
23691
|
+
let kept;
|
|
23692
|
+
if (!replace && exportedBundle !== void 0) {
|
|
23693
|
+
try {
|
|
23694
|
+
const merged = mergeForAppend(exportedBundle, outboundBundle);
|
|
23695
|
+
sendBundle = merged.bundle;
|
|
23696
|
+
kept = merged.kept;
|
|
23697
|
+
} catch (e) {
|
|
23698
|
+
return fatalResult5(dryRun, `Could not merge the local bundle into the hosted one: ${e.message}. Nothing was sent.`, qualityFields);
|
|
23699
|
+
}
|
|
23700
|
+
}
|
|
23701
|
+
const putBody = JSON.stringify({ bundle: sendBundle });
|
|
23702
|
+
const resultCtx = { dryRun, bundlePath, version: version2, mode, kept, ...qualityFields };
|
|
23347
23703
|
if (dryRun) {
|
|
23348
23704
|
let res2;
|
|
23349
23705
|
try {
|
|
@@ -23353,51 +23709,36 @@ async function runRestore(options = {}) {
|
|
|
23353
23709
|
body: putBody
|
|
23354
23710
|
});
|
|
23355
23711
|
} catch (e) {
|
|
23356
|
-
return { ok: true, dryRun, bundlePath, requestSent: false, errorMessage: `Network error: ${e.message}` };
|
|
23712
|
+
return { ok: true, dryRun, mode, kept, bundlePath, requestSent: false, errorMessage: `Network error: ${e.message}` };
|
|
23357
23713
|
}
|
|
23358
|
-
return interpretPutResponse(res2,
|
|
23714
|
+
return interpretPutResponse(res2, resultCtx);
|
|
23359
23715
|
}
|
|
23360
|
-
|
|
23361
|
-
|
|
23362
|
-
const exportRes = await httpClient(`${baseUrl}/api/graph/projects/${encodedProjectId}/export`, { headers });
|
|
23363
|
-
if (!exportRes.ok) {
|
|
23364
|
-
return fatalResult5(dryRun, `Could not export the current hosted state (${exportRes.status}). Refusing to restore without a backup. Nothing was sent.`);
|
|
23365
|
-
}
|
|
23366
|
-
const body = await safeJson(exportRes);
|
|
23367
|
-
exported = body.bundle;
|
|
23368
|
-
} catch (e) {
|
|
23369
|
-
return fatalResult5(dryRun, `Could not export the current hosted state: ${e.message}. Refusing to restore without a backup.`);
|
|
23716
|
+
if (exportedBundle === void 0) {
|
|
23717
|
+
return fatalResult5(dryRun, "Internal error: no hosted export in hand for a real restore. Nothing was sent.", qualityFields);
|
|
23370
23718
|
}
|
|
23371
|
-
|
|
23372
|
-
|
|
23373
|
-
|
|
23374
|
-
|
|
23375
|
-
|
|
23376
|
-
|
|
23377
|
-
|
|
23378
|
-
|
|
23379
|
-
|
|
23380
|
-
|
|
23381
|
-
|
|
23382
|
-
|
|
23383
|
-
|
|
23384
|
-
|
|
23385
|
-
|
|
23386
|
-
|
|
23387
|
-
|
|
23388
|
-
|
|
23389
|
-
|
|
23390
|
-
|
|
23391
|
-
|
|
23392
|
-
|
|
23393
|
-
|
|
23394
|
-
if (droppedKeys.length > 0 && !allowMetadataLoss) {
|
|
23395
|
-
return fatalResult5(dryRun, describeMetadataLoss(droppedKeys, bundlePath), qualityFields);
|
|
23396
|
-
}
|
|
23397
|
-
const removedNodes = removedIds(exportedBundle.nodes, Array.isArray(local.nodes) ? local.nodes : []);
|
|
23398
|
-
const removedEdges = removedIds(exportedBundle.edges, Array.isArray(local.edges) ? local.edges : []);
|
|
23399
|
-
if ((removedNodes.length > 0 || removedEdges.length > 0) && !allowDeletions) {
|
|
23400
|
-
return fatalResult5(dryRun, describeDeletions(removedNodes, removedEdges, bundlePath), qualityFields);
|
|
23719
|
+
const exported = exportedBundle;
|
|
23720
|
+
if (replace) {
|
|
23721
|
+
const hostedEventCount = exported.journal.length;
|
|
23722
|
+
if (journalEvents.length < hostedEventCount && !allowHistoryLoss) {
|
|
23723
|
+
return fatalResult5(
|
|
23724
|
+
dryRun,
|
|
23725
|
+
`This restore would replace ${hostedEventCount} hosted journal events with ${journalEvents.length}. Nothing was sent. If that is intended, re-run with --allow-history-loss; otherwise check that ${journalPathFor(bundlePath)} exists and is current.`,
|
|
23726
|
+
qualityFields
|
|
23727
|
+
);
|
|
23728
|
+
}
|
|
23729
|
+
const hostedQuality = exported.quality;
|
|
23730
|
+
if (isQualitySection(hostedQuality) && !isQualitySection(outboundBundle.quality) && !allowQualityLoss) {
|
|
23731
|
+
return fatalResult5(dryRun, describeQualityLoss(hostedQuality, qualityRoot, noQuality, qualityNotice), qualityFields);
|
|
23732
|
+
}
|
|
23733
|
+
const droppedKeys = droppedMetadataKeys(exported.project, outboundBundle.project);
|
|
23734
|
+
if (droppedKeys.length > 0 && !allowMetadataLoss) {
|
|
23735
|
+
return fatalResult5(dryRun, describeMetadataLoss(droppedKeys, bundlePath), qualityFields);
|
|
23736
|
+
}
|
|
23737
|
+
const removedNodes = removedIds(exported.nodes, Array.isArray(local.nodes) ? local.nodes : []);
|
|
23738
|
+
const removedEdges = removedIds(exported.edges, Array.isArray(local.edges) ? local.edges : []);
|
|
23739
|
+
if ((removedNodes.length > 0 || removedEdges.length > 0) && !allowDeletions) {
|
|
23740
|
+
return fatalResult5(dryRun, describeDeletions(removedNodes, removedEdges, bundlePath), qualityFields);
|
|
23741
|
+
}
|
|
23401
23742
|
}
|
|
23402
23743
|
const backupDir = join11(cwd, "docs", "arkaik", ".backups");
|
|
23403
23744
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
@@ -23427,13 +23768,15 @@ Refusing to restore \u2014 this verb replaces the hosted project's snapshot AND
|
|
|
23427
23768
|
return {
|
|
23428
23769
|
ok: true,
|
|
23429
23770
|
dryRun,
|
|
23771
|
+
mode,
|
|
23772
|
+
kept,
|
|
23430
23773
|
bundlePath,
|
|
23431
23774
|
backupPath,
|
|
23432
23775
|
requestSent: false,
|
|
23433
23776
|
errorMessage: `Network error: ${e.message}. Nothing was sent.${backupNoteFor(backupPath)}`
|
|
23434
23777
|
};
|
|
23435
23778
|
}
|
|
23436
|
-
return interpretPutResponse(res, {
|
|
23779
|
+
return interpretPutResponse(res, { ...resultCtx, backupPath });
|
|
23437
23780
|
}
|
|
23438
23781
|
function printDelta(delta) {
|
|
23439
23782
|
if (!delta) return;
|
|
@@ -23467,6 +23810,9 @@ function reportRestore(result) {
|
|
|
23467
23810
|
if (result.qualityNotice !== void 0) {
|
|
23468
23811
|
console.log(result.qualityNotice);
|
|
23469
23812
|
}
|
|
23813
|
+
if (result.kept !== void 0) {
|
|
23814
|
+
console.log(describeAppendSummary(result.kept));
|
|
23815
|
+
}
|
|
23470
23816
|
if (!result.requestSent) {
|
|
23471
23817
|
console.error(result.errorMessage ?? "Restore failed before a request could be sent.");
|
|
23472
23818
|
process.exit(1);
|
|
@@ -23476,13 +23822,13 @@ function reportRestore(result) {
|
|
|
23476
23822
|
console.log("[dry-run] server preview \u2014 nothing was written:");
|
|
23477
23823
|
printDelta(result.delta);
|
|
23478
23824
|
console.log(
|
|
23479
|
-
"Re-run without --dry-run to apply \u2014 that run takes the backup, and only that run checks the history, deletion, quality-loss and metadata-loss guards (all four read the export, which a dry run never fetches)."
|
|
23825
|
+
result.mode === "replace" ? "Re-run without --dry-run to apply \u2014 that run takes the backup, and only that run checks the history, deletion, quality-loss and metadata-loss guards (all four read the export, which a dry run never fetches)." : "Re-run without --dry-run to apply \u2014 that run takes the backup first."
|
|
23480
23826
|
);
|
|
23481
23827
|
} else {
|
|
23482
23828
|
console.log(`Restored. New version ${result.version}.`);
|
|
23483
23829
|
printDelta(result.delta);
|
|
23484
23830
|
if (result.backupPath) {
|
|
23485
|
-
console.log(` Undo this restore with:
|
|
23831
|
+
console.log(` Undo this restore with: ${undoCommandFor(result.backupPath)}`);
|
|
23486
23832
|
}
|
|
23487
23833
|
}
|
|
23488
23834
|
process.exitCode = 0;
|
|
@@ -23496,6 +23842,7 @@ function reportRestore(result) {
|
|
|
23496
23842
|
}
|
|
23497
23843
|
function runRestoreCli(argv) {
|
|
23498
23844
|
let dryRun = false;
|
|
23845
|
+
let replace = false;
|
|
23499
23846
|
let allowHistoryLoss = false;
|
|
23500
23847
|
let allowDeletions = false;
|
|
23501
23848
|
let noQuality = false;
|
|
@@ -23514,6 +23861,8 @@ function runRestoreCli(argv) {
|
|
|
23514
23861
|
return;
|
|
23515
23862
|
} else if (arg === "--dry-run") {
|
|
23516
23863
|
dryRun = true;
|
|
23864
|
+
} else if (arg === "--replace") {
|
|
23865
|
+
replace = true;
|
|
23517
23866
|
} else if (arg === "--allow-history-loss") {
|
|
23518
23867
|
allowHistoryLoss = true;
|
|
23519
23868
|
} else if (arg === "--allow-deletions") {
|
|
@@ -23560,9 +23909,14 @@ ${USAGE13}`);
|
|
|
23560
23909
|
|
|
23561
23910
|
${USAGE13}`);
|
|
23562
23911
|
}
|
|
23912
|
+
const allowFlags = allowFlagsOf({ allowHistoryLoss, allowDeletions, allowQualityLoss, allowMetadataLoss });
|
|
23913
|
+
if (allowFlags.length > 0 && !replace) fail10(`${describeAllowWithoutReplace(allowFlags)}
|
|
23914
|
+
|
|
23915
|
+
${USAGE13}`);
|
|
23563
23916
|
runRestore({
|
|
23564
23917
|
path: positionals[0],
|
|
23565
23918
|
dryRun,
|
|
23919
|
+
replace,
|
|
23566
23920
|
allowHistoryLoss,
|
|
23567
23921
|
allowDeletions,
|
|
23568
23922
|
noQuality,
|
|
@@ -23829,8 +24183,8 @@ function loadFragments(cwd, manifest) {
|
|
|
23829
24183
|
|
|
23830
24184
|
// src/lib/bootstrap/index-view.ts
|
|
23831
24185
|
function tsvField(value, fallback = "") {
|
|
23832
|
-
const
|
|
23833
|
-
return
|
|
24186
|
+
const str3 = value === void 0 || value === null ? fallback : String(value);
|
|
24187
|
+
return str3.replace(/[\t\r\n]+/g, " ");
|
|
23834
24188
|
}
|
|
23835
24189
|
function renderIndex(bundle) {
|
|
23836
24190
|
const nodes = Array.isArray(bundle.nodes) ? bundle.nodes : [];
|
|
@@ -24204,7 +24558,7 @@ function mergeJournal(base, fresh) {
|
|
|
24204
24558
|
}
|
|
24205
24559
|
|
|
24206
24560
|
// src/lib/bootstrap/merge.ts
|
|
24207
|
-
function
|
|
24561
|
+
function asArray4(value) {
|
|
24208
24562
|
return Array.isArray(value) ? value : [];
|
|
24209
24563
|
}
|
|
24210
24564
|
function mergeFragments(input) {
|
|
@@ -24212,14 +24566,14 @@ function mergeFragments(input) {
|
|
|
24212
24566
|
const projectId = String(input.base.project?.id ?? "");
|
|
24213
24567
|
const nodes = /* @__PURE__ */ new Map();
|
|
24214
24568
|
const nodeOrigin = /* @__PURE__ */ new Map();
|
|
24215
|
-
for (const node of
|
|
24569
|
+
for (const node of asArray4(input.base.nodes)) {
|
|
24216
24570
|
const id = String(node.id);
|
|
24217
24571
|
nodes.set(id, { ...node });
|
|
24218
24572
|
nodeOrigin.set(id, "(already in the bundle)");
|
|
24219
24573
|
}
|
|
24220
24574
|
const edges = /* @__PURE__ */ new Map();
|
|
24221
24575
|
const edgeOrigin = /* @__PURE__ */ new Map();
|
|
24222
|
-
for (const edge of
|
|
24576
|
+
for (const edge of asArray4(input.base.edges)) {
|
|
24223
24577
|
const id = String(edge.id ?? edgeId(String(edge.source_id), String(edge.target_id)));
|
|
24224
24578
|
edges.set(id, { ...edge });
|
|
24225
24579
|
edgeOrigin.set(id, "(already in the bundle)");
|
|
@@ -26927,7 +27281,7 @@ Commands:
|
|
|
26927
27281
|
live --platform <p> [ids] Mark acceptances live on one platform from a deploy (release:append token).
|
|
26928
27282
|
--mentions <file> derives them from merged pull requests.
|
|
26929
27283
|
shot [options] [id p value] Record screenshots: --manifest <file> to the hosted door (screenshot:append token), or into the repo bundle.
|
|
26930
|
-
restore [options] [path]
|
|
27284
|
+
restore [options] [path] Append a local bundle to the linked project; --replace swaps it (backs up first).
|
|
26931
27285
|
bootstrap <sub> [options] One-time onboarding: mine, plan, slice, merge a map from a repo.
|
|
26932
27286
|
kritik <sub> [options] Quality audits: score criteria, open findings, roll up the matrix.
|
|
26933
27287
|
|
|
@@ -26936,7 +27290,7 @@ Options:
|
|
|
26936
27290
|
-v, --version Print the version.
|
|
26937
27291
|
|
|
26938
27292
|
Run "arkaik <command> --help" for command-specific help.`;
|
|
26939
|
-
var VERSION = "0.
|
|
27293
|
+
var VERSION = "0.14.0";
|
|
26940
27294
|
function main(argv) {
|
|
26941
27295
|
const [command, ...rest] = argv;
|
|
26942
27296
|
if (command === void 0 || command === "--help" || command === "-h" || command === "help") {
|
package/package.json
CHANGED