oleander-cli 0.25.4 → 0.27.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/README.md +74 -0
- package/dist/index.cjs +1554 -70
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -582,15 +582,15 @@ var require_help = __commonJS({
|
|
|
582
582
|
* @return {string}
|
|
583
583
|
*
|
|
584
584
|
*/
|
|
585
|
-
wrap(str, width,
|
|
585
|
+
wrap(str, width, indent2, minColumnWidth = 40) {
|
|
586
586
|
const indents = " \\f\\t\\v\xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF";
|
|
587
587
|
const manualIndent = new RegExp(`[\\n][${indents}]+`);
|
|
588
588
|
if (str.match(manualIndent)) return str;
|
|
589
|
-
const columnWidth = width -
|
|
589
|
+
const columnWidth = width - indent2;
|
|
590
590
|
if (columnWidth < minColumnWidth) return str;
|
|
591
|
-
const leadingStr = str.slice(0,
|
|
592
|
-
const columnText = str.slice(
|
|
593
|
-
const indentString = " ".repeat(
|
|
591
|
+
const leadingStr = str.slice(0, indent2);
|
|
592
|
+
const columnText = str.slice(indent2).replace("\r\n", "\n");
|
|
593
|
+
const indentString = " ".repeat(indent2);
|
|
594
594
|
const zeroWidthSpace = "\u200B";
|
|
595
595
|
const breaks = `\\s${zeroWidthSpace}`;
|
|
596
596
|
const regex2 = new RegExp(
|
|
@@ -970,7 +970,7 @@ var require_command = __commonJS({
|
|
|
970
970
|
var EventEmitter = require("events").EventEmitter;
|
|
971
971
|
var childProcess = require("child_process");
|
|
972
972
|
var path2 = require("path");
|
|
973
|
-
var
|
|
973
|
+
var fs9 = require("fs");
|
|
974
974
|
var process11 = require("process");
|
|
975
975
|
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
976
976
|
var { CommanderError: CommanderError2 } = require_error();
|
|
@@ -1903,10 +1903,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1903
1903
|
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1904
1904
|
function findFile(baseDir, baseName) {
|
|
1905
1905
|
const localBin = path2.resolve(baseDir, baseName);
|
|
1906
|
-
if (
|
|
1906
|
+
if (fs9.existsSync(localBin)) return localBin;
|
|
1907
1907
|
if (sourceExt.includes(path2.extname(baseName))) return void 0;
|
|
1908
1908
|
const foundExt = sourceExt.find(
|
|
1909
|
-
(ext) =>
|
|
1909
|
+
(ext) => fs9.existsSync(`${localBin}${ext}`)
|
|
1910
1910
|
);
|
|
1911
1911
|
if (foundExt) return `${localBin}${foundExt}`;
|
|
1912
1912
|
return void 0;
|
|
@@ -1918,7 +1918,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1918
1918
|
if (this._scriptPath) {
|
|
1919
1919
|
let resolvedScriptPath;
|
|
1920
1920
|
try {
|
|
1921
|
-
resolvedScriptPath =
|
|
1921
|
+
resolvedScriptPath = fs9.realpathSync(this._scriptPath);
|
|
1922
1922
|
} catch (err) {
|
|
1923
1923
|
resolvedScriptPath = this._scriptPath;
|
|
1924
1924
|
}
|
|
@@ -17494,7 +17494,7 @@ var require_buffer_list = __commonJS({
|
|
|
17494
17494
|
}
|
|
17495
17495
|
}, {
|
|
17496
17496
|
key: "join",
|
|
17497
|
-
value: function
|
|
17497
|
+
value: function join11(s) {
|
|
17498
17498
|
if (this.length === 0) return "";
|
|
17499
17499
|
var p2 = this.head;
|
|
17500
17500
|
var ret = "" + p2.data;
|
|
@@ -20582,11 +20582,11 @@ var require_ora = __commonJS({
|
|
|
20582
20582
|
get indent() {
|
|
20583
20583
|
return this._indent;
|
|
20584
20584
|
}
|
|
20585
|
-
set indent(
|
|
20586
|
-
if (!(
|
|
20585
|
+
set indent(indent2 = 0) {
|
|
20586
|
+
if (!(indent2 >= 0 && Number.isInteger(indent2))) {
|
|
20587
20587
|
throw new Error("The `indent` option must be an integer from 0 and up");
|
|
20588
20588
|
}
|
|
20589
|
-
this._indent =
|
|
20589
|
+
this._indent = indent2;
|
|
20590
20590
|
}
|
|
20591
20591
|
_updateInterval(interval) {
|
|
20592
20592
|
if (interval !== void 0) {
|
|
@@ -26371,10 +26371,10 @@ var require_lib = __commonJS({
|
|
|
26371
26371
|
exports2.analyse = analyse;
|
|
26372
26372
|
var detectFile = (filepath, opts = {}) => new Promise((resolve4, reject) => {
|
|
26373
26373
|
let fd;
|
|
26374
|
-
const
|
|
26374
|
+
const fs9 = (0, node_1.default)();
|
|
26375
26375
|
const handler = (err, buffer) => {
|
|
26376
26376
|
if (fd) {
|
|
26377
|
-
|
|
26377
|
+
fs9.closeSync(fd);
|
|
26378
26378
|
}
|
|
26379
26379
|
if (err) {
|
|
26380
26380
|
reject(err);
|
|
@@ -26386,9 +26386,9 @@ var require_lib = __commonJS({
|
|
|
26386
26386
|
};
|
|
26387
26387
|
const sampleSize = (opts === null || opts === void 0 ? void 0 : opts.sampleSize) || 0;
|
|
26388
26388
|
if (sampleSize > 0) {
|
|
26389
|
-
fd =
|
|
26389
|
+
fd = fs9.openSync(filepath, "r");
|
|
26390
26390
|
let sample = Buffer.allocUnsafe(sampleSize);
|
|
26391
|
-
|
|
26391
|
+
fs9.read(fd, sample, 0, sampleSize, opts.offset, (err, bytesRead) => {
|
|
26392
26392
|
if (err) {
|
|
26393
26393
|
handler(err, null);
|
|
26394
26394
|
} else {
|
|
@@ -26400,22 +26400,22 @@ var require_lib = __commonJS({
|
|
|
26400
26400
|
});
|
|
26401
26401
|
return;
|
|
26402
26402
|
}
|
|
26403
|
-
|
|
26403
|
+
fs9.readFile(filepath, handler);
|
|
26404
26404
|
});
|
|
26405
26405
|
exports2.detectFile = detectFile;
|
|
26406
26406
|
var detectFileSync = (filepath, opts = {}) => {
|
|
26407
|
-
const
|
|
26407
|
+
const fs9 = (0, node_1.default)();
|
|
26408
26408
|
if (opts && opts.sampleSize) {
|
|
26409
|
-
const fd =
|
|
26409
|
+
const fd = fs9.openSync(filepath, "r");
|
|
26410
26410
|
let sample = Buffer.allocUnsafe(opts.sampleSize);
|
|
26411
|
-
const bytesRead =
|
|
26411
|
+
const bytesRead = fs9.readSync(fd, sample, 0, opts.sampleSize, opts.offset);
|
|
26412
26412
|
if (bytesRead < opts.sampleSize) {
|
|
26413
26413
|
sample = sample.subarray(0, bytesRead);
|
|
26414
26414
|
}
|
|
26415
|
-
|
|
26415
|
+
fs9.closeSync(fd);
|
|
26416
26416
|
return (0, exports2.detect)(sample);
|
|
26417
26417
|
}
|
|
26418
|
-
return (0, exports2.detect)(
|
|
26418
|
+
return (0, exports2.detect)(fs9.readFileSync(filepath));
|
|
26419
26419
|
};
|
|
26420
26420
|
exports2.detectFileSync = detectFileSync;
|
|
26421
26421
|
exports2.default = {
|
|
@@ -31803,9 +31803,9 @@ var require_layout_manager = __commonJS({
|
|
|
31803
31803
|
});
|
|
31804
31804
|
});
|
|
31805
31805
|
}
|
|
31806
|
-
function addColSpanCells(
|
|
31807
|
-
for (let rowIndex =
|
|
31808
|
-
let cellColumns =
|
|
31806
|
+
function addColSpanCells(cellRows2) {
|
|
31807
|
+
for (let rowIndex = cellRows2.length - 1; rowIndex >= 0; rowIndex--) {
|
|
31808
|
+
let cellColumns = cellRows2[rowIndex];
|
|
31809
31809
|
for (let columnIndex = 0; columnIndex < cellColumns.length; columnIndex++) {
|
|
31810
31810
|
let cell = cellColumns[columnIndex];
|
|
31811
31811
|
for (let k3 = 1; k3 < cell.colSpan; k3++) {
|
|
@@ -31869,12 +31869,12 @@ var require_layout_manager = __commonJS({
|
|
|
31869
31869
|
});
|
|
31870
31870
|
}
|
|
31871
31871
|
function makeTableLayout(rows) {
|
|
31872
|
-
let
|
|
31873
|
-
layoutTable(
|
|
31874
|
-
fillInTable(
|
|
31875
|
-
addRowSpanCells(
|
|
31876
|
-
addColSpanCells(
|
|
31877
|
-
return
|
|
31872
|
+
let cellRows2 = generateCells(rows);
|
|
31873
|
+
layoutTable(cellRows2);
|
|
31874
|
+
fillInTable(cellRows2);
|
|
31875
|
+
addRowSpanCells(cellRows2);
|
|
31876
|
+
addColSpanCells(cellRows2);
|
|
31877
|
+
return cellRows2;
|
|
31878
31878
|
}
|
|
31879
31879
|
module2.exports = {
|
|
31880
31880
|
makeTableLayout,
|
|
@@ -34767,11 +34767,11 @@ var Ora = class {
|
|
|
34767
34767
|
get indent() {
|
|
34768
34768
|
return this.#indent;
|
|
34769
34769
|
}
|
|
34770
|
-
set indent(
|
|
34771
|
-
if (!(
|
|
34770
|
+
set indent(indent2 = 0) {
|
|
34771
|
+
if (!(indent2 >= 0 && Number.isInteger(indent2))) {
|
|
34772
34772
|
throw new Error("The `indent` option must be an integer from 0 and up");
|
|
34773
34773
|
}
|
|
34774
|
-
this.#indent =
|
|
34774
|
+
this.#indent = indent2;
|
|
34775
34775
|
this.#updateLineCount();
|
|
34776
34776
|
}
|
|
34777
34777
|
get interval() {
|
|
@@ -38728,9 +38728,9 @@ async function describeTableCommand(options) {
|
|
|
38728
38728
|
}
|
|
38729
38729
|
}
|
|
38730
38730
|
function describeField(name, fieldType, depth) {
|
|
38731
|
-
const
|
|
38731
|
+
const indent2 = " ".repeat(depth * 2);
|
|
38732
38732
|
const t = typeof fieldType === "string" ? fieldType : fieldType.type;
|
|
38733
|
-
console.log(
|
|
38733
|
+
console.log(indent2 + source_default.cyan(name) + "(" + t + ")");
|
|
38734
38734
|
if (typeof fieldType !== "string" && fieldType.type === "struct") {
|
|
38735
38735
|
for (const field of fieldType.fields) {
|
|
38736
38736
|
describeField(field.name, field.type, depth + 1);
|
|
@@ -45775,7 +45775,7 @@ var import_fs7 = require("fs");
|
|
|
45775
45775
|
// package.json
|
|
45776
45776
|
var package_default = {
|
|
45777
45777
|
name: "oleander-cli",
|
|
45778
|
-
version: "0.
|
|
45778
|
+
version: "0.27.0",
|
|
45779
45779
|
description: "oleander CLI",
|
|
45780
45780
|
keywords: [
|
|
45781
45781
|
"cli",
|
|
@@ -46617,11 +46617,1494 @@ function registerQueriesCommands(program3) {
|
|
|
46617
46617
|
queries.command("save").description("Save a SQL query by name").argument("<name>", "Query name").argument("[query]", "SQL query text").option("-f, --file <file>", "Read SQL from a file").action(saveSavedQueryCommand);
|
|
46618
46618
|
}
|
|
46619
46619
|
|
|
46620
|
+
// src/commands/notebooks/commands.ts
|
|
46621
|
+
var import_node_fs8 = require("fs");
|
|
46622
|
+
var import_node_path8 = require("path");
|
|
46623
|
+
|
|
46624
|
+
// src/commands/notebooks/client.ts
|
|
46625
|
+
var YAML_CONTENT_TYPE = "application/yaml";
|
|
46626
|
+
var NotebookApiError = class extends Error {
|
|
46627
|
+
constructor(status, message, body) {
|
|
46628
|
+
super(message);
|
|
46629
|
+
this.status = status;
|
|
46630
|
+
this.body = body;
|
|
46631
|
+
this.name = "NotebookApiError";
|
|
46632
|
+
}
|
|
46633
|
+
};
|
|
46634
|
+
function notebookUrl(slug, path2 = "", query = {}) {
|
|
46635
|
+
const params = new URLSearchParams();
|
|
46636
|
+
for (const [key, value] of Object.entries(query)) {
|
|
46637
|
+
if (value !== void 0 && value !== "") params.set(key, value);
|
|
46638
|
+
}
|
|
46639
|
+
const search = params.toString();
|
|
46640
|
+
return `${getEndpoint()}/api/v1/notebooks/${encodeURIComponent(slug)}${path2}${search ? `?${search}` : ""}`;
|
|
46641
|
+
}
|
|
46642
|
+
async function readBody(response) {
|
|
46643
|
+
const text = await response.text();
|
|
46644
|
+
if (!text) return null;
|
|
46645
|
+
try {
|
|
46646
|
+
return JSON.parse(text);
|
|
46647
|
+
} catch {
|
|
46648
|
+
return text;
|
|
46649
|
+
}
|
|
46650
|
+
}
|
|
46651
|
+
function errorMessageFromBody(body, fallback2) {
|
|
46652
|
+
if (typeof body === "string" && body.trim()) return body.trim();
|
|
46653
|
+
if (!body || typeof body !== "object") return fallback2;
|
|
46654
|
+
const record = body;
|
|
46655
|
+
const error = record.error;
|
|
46656
|
+
const details = typeof record.details === "string" && record.details.trim() ? record.details : typeof record.message === "string" && record.message.trim() ? record.message : void 0;
|
|
46657
|
+
if (typeof error === "string" && error.trim()) {
|
|
46658
|
+
return details && details !== error ? `${error}: ${details}` : error;
|
|
46659
|
+
}
|
|
46660
|
+
if (error && typeof error === "object") {
|
|
46661
|
+
const message = error.message;
|
|
46662
|
+
if (typeof message === "string" && message.trim()) return message;
|
|
46663
|
+
}
|
|
46664
|
+
return details ?? fallback2;
|
|
46665
|
+
}
|
|
46666
|
+
async function failure(response, fallback2) {
|
|
46667
|
+
const body = await readBody(response);
|
|
46668
|
+
return new NotebookApiError(
|
|
46669
|
+
response.status,
|
|
46670
|
+
errorMessageFromBody(body, `${fallback2} (HTTP ${response.status})`),
|
|
46671
|
+
body
|
|
46672
|
+
);
|
|
46673
|
+
}
|
|
46674
|
+
function specIssuesFromBody(body) {
|
|
46675
|
+
if (!body || typeof body !== "object") return [];
|
|
46676
|
+
const errors = body.errors;
|
|
46677
|
+
if (!Array.isArray(errors)) return [];
|
|
46678
|
+
return errors.flatMap((issue) => {
|
|
46679
|
+
if (!issue || typeof issue !== "object") return [];
|
|
46680
|
+
const { path: path2, message } = issue;
|
|
46681
|
+
if (typeof message !== "string") return [];
|
|
46682
|
+
return [{ path: typeof path2 === "string" ? path2 : "", message }];
|
|
46683
|
+
});
|
|
46684
|
+
}
|
|
46685
|
+
function versionFromHeaders(headers) {
|
|
46686
|
+
const raw = headers.get("x-notebook-version") ?? headers.get("etag")?.replace(/^W\//, "").replace(/"/g, "");
|
|
46687
|
+
if (!raw) return null;
|
|
46688
|
+
const version = Number(raw.trim());
|
|
46689
|
+
return Number.isInteger(version) ? version : null;
|
|
46690
|
+
}
|
|
46691
|
+
var NotebooksClient = class {
|
|
46692
|
+
constructor(apiKey) {
|
|
46693
|
+
this.apiKey = apiKey;
|
|
46694
|
+
}
|
|
46695
|
+
headers(extra = {}) {
|
|
46696
|
+
return { Authorization: `Bearer ${this.apiKey}`, ...extra };
|
|
46697
|
+
}
|
|
46698
|
+
async json(method, url, fallback2, body) {
|
|
46699
|
+
const response = await fetch(url, {
|
|
46700
|
+
method,
|
|
46701
|
+
headers: this.headers(
|
|
46702
|
+
body === void 0 ? {} : { "Content-Type": "application/json" }
|
|
46703
|
+
),
|
|
46704
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
46705
|
+
});
|
|
46706
|
+
if (!response.ok) throw await failure(response, fallback2);
|
|
46707
|
+
return await readBody(response);
|
|
46708
|
+
}
|
|
46709
|
+
/** The YAML exactly as saved, and the version it is. */
|
|
46710
|
+
async getYaml(slug) {
|
|
46711
|
+
const response = await fetch(notebookUrl(slug), {
|
|
46712
|
+
method: "GET",
|
|
46713
|
+
headers: this.headers({ Accept: YAML_CONTENT_TYPE })
|
|
46714
|
+
});
|
|
46715
|
+
if (!response.ok) throw await failure(response, "Failed to read notebook");
|
|
46716
|
+
const yaml = await response.text();
|
|
46717
|
+
return { yaml, version: versionFromHeaders(response.headers) };
|
|
46718
|
+
}
|
|
46719
|
+
/** PUT the YAML. Returns the raw response so callers can tell 409/422/428 apart. */
|
|
46720
|
+
putYaml(slug, yaml, options) {
|
|
46721
|
+
const headers = this.headers({ "Content-Type": YAML_CONTENT_TYPE });
|
|
46722
|
+
if (options.ifMatch !== void 0 && options.ifMatch !== null) {
|
|
46723
|
+
headers["If-Match"] = String(options.ifMatch);
|
|
46724
|
+
}
|
|
46725
|
+
return fetch(
|
|
46726
|
+
notebookUrl(slug, "", {
|
|
46727
|
+
run: options.run === void 0 ? void 0 : String(options.run),
|
|
46728
|
+
plan_id: options.planId
|
|
46729
|
+
}),
|
|
46730
|
+
{ method: "PUT", headers, body: yaml }
|
|
46731
|
+
);
|
|
46732
|
+
}
|
|
46733
|
+
/** POST the YAML to /plan. Returns the raw response so 422 can be read. */
|
|
46734
|
+
planYaml(slug, yaml) {
|
|
46735
|
+
return fetch(notebookUrl(slug, "/plan"), {
|
|
46736
|
+
method: "POST",
|
|
46737
|
+
headers: this.headers({ "Content-Type": YAML_CONTENT_TYPE }),
|
|
46738
|
+
body: yaml
|
|
46739
|
+
});
|
|
46740
|
+
}
|
|
46741
|
+
planPublish(slug) {
|
|
46742
|
+
return this.json("POST", notebookUrl(slug, "/plan"), "Failed to plan", {
|
|
46743
|
+
publish: true
|
|
46744
|
+
});
|
|
46745
|
+
}
|
|
46746
|
+
publish(slug, planId) {
|
|
46747
|
+
return this.json(
|
|
46748
|
+
"POST",
|
|
46749
|
+
notebookUrl(slug, "/publish"),
|
|
46750
|
+
"Failed to publish notebook",
|
|
46751
|
+
{ plan_id: planId }
|
|
46752
|
+
);
|
|
46753
|
+
}
|
|
46754
|
+
async listRuns(slug) {
|
|
46755
|
+
const body = await this.json(
|
|
46756
|
+
"GET",
|
|
46757
|
+
notebookUrl(slug, "/runs"),
|
|
46758
|
+
"Failed to list runs"
|
|
46759
|
+
);
|
|
46760
|
+
return body?.runs ?? [];
|
|
46761
|
+
}
|
|
46762
|
+
getRun(slug, runId) {
|
|
46763
|
+
return this.json(
|
|
46764
|
+
"GET",
|
|
46765
|
+
notebookUrl(slug, `/runs/${encodeURIComponent(runId)}`),
|
|
46766
|
+
"Failed to get run"
|
|
46767
|
+
);
|
|
46768
|
+
}
|
|
46769
|
+
cancelRun(slug, runId) {
|
|
46770
|
+
return this.json(
|
|
46771
|
+
"POST",
|
|
46772
|
+
notebookUrl(slug, `/runs/${encodeURIComponent(runId)}/cancel`),
|
|
46773
|
+
"Failed to cancel run"
|
|
46774
|
+
);
|
|
46775
|
+
}
|
|
46776
|
+
logs(slug, runId, options = {}) {
|
|
46777
|
+
return this.json(
|
|
46778
|
+
"GET",
|
|
46779
|
+
notebookUrl(slug, `/runs/${encodeURIComponent(runId)}/logs`, {
|
|
46780
|
+
cell_id: options.cellId,
|
|
46781
|
+
cursor: options.cursor ?? void 0
|
|
46782
|
+
}),
|
|
46783
|
+
"Failed to read logs"
|
|
46784
|
+
);
|
|
46785
|
+
}
|
|
46786
|
+
compare(slug, a, b3) {
|
|
46787
|
+
return this.json(
|
|
46788
|
+
"GET",
|
|
46789
|
+
notebookUrl(slug, "/runs/compare", { a, b: b3 }),
|
|
46790
|
+
"Failed to compare runs"
|
|
46791
|
+
);
|
|
46792
|
+
}
|
|
46793
|
+
backfill(slug, body) {
|
|
46794
|
+
return this.json(
|
|
46795
|
+
"POST",
|
|
46796
|
+
notebookUrl(slug, "/backfills"),
|
|
46797
|
+
"Failed to start backfill",
|
|
46798
|
+
body
|
|
46799
|
+
);
|
|
46800
|
+
}
|
|
46801
|
+
};
|
|
46802
|
+
|
|
46803
|
+
// src/commands/notebooks/core.ts
|
|
46804
|
+
var import_node_fs6 = require("fs");
|
|
46805
|
+
var import_node_path6 = require("path");
|
|
46806
|
+
|
|
46807
|
+
// src/commands/notebooks/state.ts
|
|
46808
|
+
var import_node_fs5 = require("fs");
|
|
46809
|
+
var import_node_path5 = require("path");
|
|
46810
|
+
var NOTEBOOKS_STATE_PATH = (0, import_node_path5.join)(".oleander", "notebooks.json");
|
|
46811
|
+
function notebookFileName(slug) {
|
|
46812
|
+
return `${slug}.notebook.yaml`;
|
|
46813
|
+
}
|
|
46814
|
+
function notebooksStateFile(cwd) {
|
|
46815
|
+
return (0, import_node_path5.join)(cwd, NOTEBOOKS_STATE_PATH);
|
|
46816
|
+
}
|
|
46817
|
+
async function readNotebookVersions(cwd) {
|
|
46818
|
+
const file = notebooksStateFile(cwd);
|
|
46819
|
+
let text;
|
|
46820
|
+
try {
|
|
46821
|
+
text = await import_node_fs5.promises.readFile(file, "utf8");
|
|
46822
|
+
} catch (error) {
|
|
46823
|
+
if (error.code === "ENOENT") return {};
|
|
46824
|
+
throw error;
|
|
46825
|
+
}
|
|
46826
|
+
if (!text.trim()) return {};
|
|
46827
|
+
let parsed;
|
|
46828
|
+
try {
|
|
46829
|
+
parsed = JSON.parse(text);
|
|
46830
|
+
} catch {
|
|
46831
|
+
throw new Error(
|
|
46832
|
+
`${NOTEBOOKS_STATE_PATH} is not valid JSON. Fix it, or delete it and run oleander notebooks pull again.`
|
|
46833
|
+
);
|
|
46834
|
+
}
|
|
46835
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
46836
|
+
throw new Error(
|
|
46837
|
+
`${NOTEBOOKS_STATE_PATH} must be an object of slug to version.`
|
|
46838
|
+
);
|
|
46839
|
+
}
|
|
46840
|
+
const versions = {};
|
|
46841
|
+
for (const [slug, version] of Object.entries(parsed)) {
|
|
46842
|
+
if (typeof version === "number" && Number.isInteger(version)) {
|
|
46843
|
+
versions[slug] = version;
|
|
46844
|
+
}
|
|
46845
|
+
}
|
|
46846
|
+
return versions;
|
|
46847
|
+
}
|
|
46848
|
+
async function recordNotebookVersion(cwd, slug, version) {
|
|
46849
|
+
const versions = await readNotebookVersions(cwd);
|
|
46850
|
+
versions[slug] = version;
|
|
46851
|
+
const file = notebooksStateFile(cwd);
|
|
46852
|
+
await import_node_fs5.promises.mkdir((0, import_node_path5.join)(cwd, ".oleander"), { recursive: true });
|
|
46853
|
+
await import_node_fs5.promises.writeFile(file, `${JSON.stringify(versions, null, 2)}
|
|
46854
|
+
`, "utf8");
|
|
46855
|
+
}
|
|
46856
|
+
var TOP_LEVEL_SLUG = /^slug:[ \t]*(["']?)([^"'#\s]+)\1[ \t]*(?:#.*)?$/m;
|
|
46857
|
+
function readSlugFromYaml(yaml) {
|
|
46858
|
+
const match = TOP_LEVEL_SLUG.exec(yaml);
|
|
46859
|
+
return match?.[2] ?? null;
|
|
46860
|
+
}
|
|
46861
|
+
|
|
46862
|
+
// src/commands/notebooks/core.ts
|
|
46863
|
+
var RUN_POLL_INTERVAL_MS = 2e3;
|
|
46864
|
+
var RUN_WAIT_TIMEOUT_MS = 10 * 6e4;
|
|
46865
|
+
var TERMINAL_RUN_STATUSES = /* @__PURE__ */ new Set([
|
|
46866
|
+
"succeeded",
|
|
46867
|
+
"failed",
|
|
46868
|
+
"cancelled",
|
|
46869
|
+
"skipped"
|
|
46870
|
+
]);
|
|
46871
|
+
async function pullNotebook(client, slug, cwd) {
|
|
46872
|
+
const { yaml, version } = await client.getYaml(slug);
|
|
46873
|
+
const file = (0, import_node_path6.join)(cwd, notebookFileName(slug));
|
|
46874
|
+
await import_node_fs6.promises.writeFile(file, yaml, "utf8");
|
|
46875
|
+
if (version !== null) await recordNotebookVersion(cwd, slug, version);
|
|
46876
|
+
return { slug, file, version };
|
|
46877
|
+
}
|
|
46878
|
+
async function readNotebookFile(path2) {
|
|
46879
|
+
let yaml;
|
|
46880
|
+
try {
|
|
46881
|
+
yaml = await import_node_fs6.promises.readFile(path2, "utf8");
|
|
46882
|
+
} catch (error) {
|
|
46883
|
+
if (error.code === "ENOENT") {
|
|
46884
|
+
throw new Error(`File not found: ${path2}`);
|
|
46885
|
+
}
|
|
46886
|
+
throw error;
|
|
46887
|
+
}
|
|
46888
|
+
const slug = readSlugFromYaml(yaml);
|
|
46889
|
+
if (!slug) {
|
|
46890
|
+
throw new Error(
|
|
46891
|
+
`${path2} has no top-level slug. Add a line like "slug: my-notebook".`
|
|
46892
|
+
);
|
|
46893
|
+
}
|
|
46894
|
+
return { slug, yaml };
|
|
46895
|
+
}
|
|
46896
|
+
async function planNotebook(client, file) {
|
|
46897
|
+
const response = await client.planYaml(file.slug, file.yaml);
|
|
46898
|
+
const body = await readBody(response);
|
|
46899
|
+
if (response.status === 422) {
|
|
46900
|
+
return { status: "invalid", errors: issuesOrMessage(body) };
|
|
46901
|
+
}
|
|
46902
|
+
if (!response.ok) {
|
|
46903
|
+
throw new NotebookApiError(
|
|
46904
|
+
response.status,
|
|
46905
|
+
errorMessageFromBody(body, `Failed to plan (HTTP ${response.status})`),
|
|
46906
|
+
body
|
|
46907
|
+
);
|
|
46908
|
+
}
|
|
46909
|
+
return { status: "planned", plan: body };
|
|
46910
|
+
}
|
|
46911
|
+
async function pushNotebook(client, file, options) {
|
|
46912
|
+
const { slug } = file;
|
|
46913
|
+
let plan = null;
|
|
46914
|
+
let planId = options.planId;
|
|
46915
|
+
if (!planId) {
|
|
46916
|
+
const planned = await planNotebook(client, file);
|
|
46917
|
+
if (planned.status === "invalid") {
|
|
46918
|
+
return { status: "invalid", slug, errors: planned.errors, plan: null };
|
|
46919
|
+
}
|
|
46920
|
+
plan = planned.plan;
|
|
46921
|
+
options.onPlan?.(plan);
|
|
46922
|
+
if (plan.requires_approval) {
|
|
46923
|
+
return { status: "plan_required", slug, plan };
|
|
46924
|
+
}
|
|
46925
|
+
planId = plan.plan_id;
|
|
46926
|
+
}
|
|
46927
|
+
const versions = await readNotebookVersions(options.cwd);
|
|
46928
|
+
const baseVersion = versions[slug] ?? null;
|
|
46929
|
+
const response = await client.putYaml(slug, file.yaml, {
|
|
46930
|
+
ifMatch: baseVersion,
|
|
46931
|
+
run: options.run ?? false,
|
|
46932
|
+
planId
|
|
46933
|
+
});
|
|
46934
|
+
const body = await readBody(response);
|
|
46935
|
+
if (response.status === 422) {
|
|
46936
|
+
return { status: "invalid", slug, errors: issuesOrMessage(body), plan };
|
|
46937
|
+
}
|
|
46938
|
+
if (response.status === 428) {
|
|
46939
|
+
const required = body?.plan;
|
|
46940
|
+
if (required) return { status: "plan_required", slug, plan: required };
|
|
46941
|
+
}
|
|
46942
|
+
if (response.status === 409) {
|
|
46943
|
+
const current = body?.current_version;
|
|
46944
|
+
return {
|
|
46945
|
+
status: "conflict",
|
|
46946
|
+
slug,
|
|
46947
|
+
message: errorMessageFromBody(body, "The notebook changed on the server"),
|
|
46948
|
+
base_version: baseVersion,
|
|
46949
|
+
current_version: typeof current === "number" ? current : null
|
|
46950
|
+
};
|
|
46951
|
+
}
|
|
46952
|
+
if (!response.ok) {
|
|
46953
|
+
throw new NotebookApiError(
|
|
46954
|
+
response.status,
|
|
46955
|
+
errorMessageFromBody(
|
|
46956
|
+
body,
|
|
46957
|
+
`Failed to save notebook (HTTP ${response.status})`
|
|
46958
|
+
),
|
|
46959
|
+
body
|
|
46960
|
+
);
|
|
46961
|
+
}
|
|
46962
|
+
const result = body;
|
|
46963
|
+
await recordNotebookVersion(options.cwd, slug, result.version);
|
|
46964
|
+
let publishPlan = null;
|
|
46965
|
+
if (result.draft) {
|
|
46966
|
+
try {
|
|
46967
|
+
publishPlan = await client.planPublish(slug);
|
|
46968
|
+
} catch {
|
|
46969
|
+
}
|
|
46970
|
+
}
|
|
46971
|
+
return {
|
|
46972
|
+
status: "saved",
|
|
46973
|
+
slug,
|
|
46974
|
+
plan,
|
|
46975
|
+
result,
|
|
46976
|
+
publish_plan: publishPlan
|
|
46977
|
+
};
|
|
46978
|
+
}
|
|
46979
|
+
var defaultSleep = (ms) => new Promise((resolve4) => setTimeout(resolve4, ms));
|
|
46980
|
+
async function waitForRun2(client, slug, runId, options = {}) {
|
|
46981
|
+
const interval = options.intervalMs ?? RUN_POLL_INTERVAL_MS;
|
|
46982
|
+
const timeout = options.timeoutMs ?? RUN_WAIT_TIMEOUT_MS;
|
|
46983
|
+
const sleep = options.sleep ?? defaultSleep;
|
|
46984
|
+
const now = options.now ?? Date.now;
|
|
46985
|
+
const deadline = now() + timeout;
|
|
46986
|
+
for (; ; ) {
|
|
46987
|
+
const detail = await client.getRun(slug, runId);
|
|
46988
|
+
options.onPoll?.(detail);
|
|
46989
|
+
if (TERMINAL_RUN_STATUSES.has(detail.run.status)) {
|
|
46990
|
+
return { detail, timedOut: false };
|
|
46991
|
+
}
|
|
46992
|
+
if (now() + interval > deadline) return { detail, timedOut: true };
|
|
46993
|
+
await sleep(interval);
|
|
46994
|
+
}
|
|
46995
|
+
}
|
|
46996
|
+
function isFailedRun(detail) {
|
|
46997
|
+
return detail.run.status !== "succeeded";
|
|
46998
|
+
}
|
|
46999
|
+
async function collectLogs(client, slug, runId, options = {}) {
|
|
47000
|
+
const all = [];
|
|
47001
|
+
const seen = /* @__PURE__ */ new Set();
|
|
47002
|
+
let cursor = null;
|
|
47003
|
+
for (; ; ) {
|
|
47004
|
+
const page = await client.logs(slug, runId, {
|
|
47005
|
+
cellId: options.cellId,
|
|
47006
|
+
cursor
|
|
47007
|
+
});
|
|
47008
|
+
const lines = page?.lines ?? [];
|
|
47009
|
+
all.push(...lines);
|
|
47010
|
+
if (lines.length) options.onPage?.(lines);
|
|
47011
|
+
const next = page?.cursor ?? null;
|
|
47012
|
+
if (!next || !lines.length || seen.has(next)) return all;
|
|
47013
|
+
seen.add(next);
|
|
47014
|
+
cursor = next;
|
|
47015
|
+
}
|
|
47016
|
+
}
|
|
47017
|
+
function issuesOrMessage(body) {
|
|
47018
|
+
const issues = specIssuesFromBody(body);
|
|
47019
|
+
if (issues.length) return issues;
|
|
47020
|
+
return [
|
|
47021
|
+
{ path: "", message: errorMessageFromBody(body, "Invalid notebook") }
|
|
47022
|
+
];
|
|
47023
|
+
}
|
|
47024
|
+
|
|
47025
|
+
// src/commands/notebooks/format.ts
|
|
47026
|
+
function formatSpecIssues(issues) {
|
|
47027
|
+
return issues.map(
|
|
47028
|
+
(issue) => issue.path ? `${issue.path}: ${issue.message}` : issue.message
|
|
47029
|
+
).join("\n");
|
|
47030
|
+
}
|
|
47031
|
+
function indent(text, prefix = " ") {
|
|
47032
|
+
return text.split("\n").map((line) => line ? prefix + line : line).join("\n");
|
|
47033
|
+
}
|
|
47034
|
+
function colorDiff(diff) {
|
|
47035
|
+
return diff.replace(/\n+$/, "").split("\n").map((line) => {
|
|
47036
|
+
if (line.startsWith("+++") || line.startsWith("---")) {
|
|
47037
|
+
return source_default.bold(line);
|
|
47038
|
+
}
|
|
47039
|
+
if (line.startsWith("+")) return source_default.green(line);
|
|
47040
|
+
if (line.startsWith("-")) return source_default.red(line);
|
|
47041
|
+
if (line.startsWith("@@")) return source_default.cyan(line);
|
|
47042
|
+
return line;
|
|
47043
|
+
}).join("\n");
|
|
47044
|
+
}
|
|
47045
|
+
function formatUsd(value) {
|
|
47046
|
+
if (value === null || value === void 0) return "n/a";
|
|
47047
|
+
if (value > 0 && value < 0.01) return "<$0.01";
|
|
47048
|
+
return `$${value.toFixed(2)}`;
|
|
47049
|
+
}
|
|
47050
|
+
function formatDuration(ms) {
|
|
47051
|
+
if (ms === null || ms === void 0) return "";
|
|
47052
|
+
if (ms < 1e3) return `${ms}ms`;
|
|
47053
|
+
const seconds = ms / 1e3;
|
|
47054
|
+
if (seconds < 60) return `${seconds.toFixed(1)}s`;
|
|
47055
|
+
const minutes = Math.floor(seconds / 60);
|
|
47056
|
+
return `${minutes}m${Math.round(seconds % 60)}s`;
|
|
47057
|
+
}
|
|
47058
|
+
function formatSchedule(schedule) {
|
|
47059
|
+
if (schedule === null || schedule === void 0) return "none";
|
|
47060
|
+
if (typeof schedule === "string") return schedule;
|
|
47061
|
+
const parts = Object.entries(schedule).filter(([, value]) => value !== void 0 && value !== null).map(
|
|
47062
|
+
([key, value]) => typeof value === "object" ? `${key}: ${JSON.stringify(value)}` : `${key}: ${String(value)}`
|
|
47063
|
+
);
|
|
47064
|
+
return parts.length ? parts.join(", ") : "none";
|
|
47065
|
+
}
|
|
47066
|
+
function addedRemoved(change) {
|
|
47067
|
+
return [
|
|
47068
|
+
...change.added.map((item) => source_default.green(`+ ${item}`)),
|
|
47069
|
+
...change.removed.map((item) => source_default.red(`- ${item}`))
|
|
47070
|
+
];
|
|
47071
|
+
}
|
|
47072
|
+
function section(title, lines) {
|
|
47073
|
+
return lines.length ? ["", source_default.bold(title), ...lines.map((l2) => ` ${l2}`)] : [];
|
|
47074
|
+
}
|
|
47075
|
+
function formatPlan(plan) {
|
|
47076
|
+
const out = [];
|
|
47077
|
+
const what = plan.kind === "publish" ? `publishes the draft of ${plan.slug}` : plan.kind === "backfill" ? `backfills ${plan.slug}` : plan.kind === "restore" ? `restores a version of ${plan.slug}` : plan.creates ? `creates ${plan.slug}` : plan.draft ? `saves a draft of ${plan.slug} (the notebook is live; the published version is unchanged)` : `updates ${plan.slug} from version ${plan.base_version}`;
|
|
47078
|
+
out.push(`${source_default.bold("Plan")} ${source_default.cyan(plan.plan_id)} ${what}`);
|
|
47079
|
+
const diff = plan.diff?.trim() ? colorDiff(plan.diff) : "";
|
|
47080
|
+
if (diff) {
|
|
47081
|
+
out.push("", source_default.bold("Diff"), indent(diff));
|
|
47082
|
+
} else if (plan.kind === "apply" && !plan.creates) {
|
|
47083
|
+
out.push("", source_default.dim("No changes to the spec"));
|
|
47084
|
+
}
|
|
47085
|
+
out.push(
|
|
47086
|
+
...section(
|
|
47087
|
+
"Outputs",
|
|
47088
|
+
plan.outputs.map((output) => {
|
|
47089
|
+
const marker = output.change === "added" ? source_default.green("+") : output.change === "changed" ? source_default.yellow("~") : " ";
|
|
47090
|
+
const exists = output.exists === null ? "" : output.exists ? ", table exists" : ", new table";
|
|
47091
|
+
const readers = output.readers.length ? source_default.dim(` read by ${output.readers.join(", ")}`) : "";
|
|
47092
|
+
return `${marker} ${output.table} ${source_default.dim(
|
|
47093
|
+
`(${output.mode}${exists}, from cell ${output.cell_id})`
|
|
47094
|
+
)}${readers}`;
|
|
47095
|
+
})
|
|
47096
|
+
)
|
|
47097
|
+
);
|
|
47098
|
+
out.push(
|
|
47099
|
+
...section(
|
|
47100
|
+
"Removed outputs",
|
|
47101
|
+
plan.removed_outputs.map((table) => source_default.red(`- ${table}`))
|
|
47102
|
+
)
|
|
47103
|
+
);
|
|
47104
|
+
const schedule = plan.schedule;
|
|
47105
|
+
if (schedule.changed || schedule.after) {
|
|
47106
|
+
const line = schedule.changed ? `${formatSchedule(schedule.before)} -> ${formatSchedule(schedule.after)}` : formatSchedule(schedule.after);
|
|
47107
|
+
out.push(
|
|
47108
|
+
...section("Schedule", [
|
|
47109
|
+
`${line}${source_default.dim(` (${schedule.runs_per_month} runs a month)`)}`
|
|
47110
|
+
])
|
|
47111
|
+
);
|
|
47112
|
+
}
|
|
47113
|
+
out.push(...section("Destinations", addedRemoved(plan.destinations)));
|
|
47114
|
+
out.push(...section("Packages", addedRemoved(plan.packages)));
|
|
47115
|
+
if (plan.budget.before !== plan.budget.after) {
|
|
47116
|
+
out.push(
|
|
47117
|
+
...section("Budget", [
|
|
47118
|
+
`${formatUsd(plan.budget.before)} -> ${formatUsd(plan.budget.after)} a month`
|
|
47119
|
+
])
|
|
47120
|
+
);
|
|
47121
|
+
}
|
|
47122
|
+
if (plan.grants.missing.length) {
|
|
47123
|
+
out.push(
|
|
47124
|
+
...section(
|
|
47125
|
+
"Grants missing",
|
|
47126
|
+
plan.grants.missing.map((grant) => source_default.red(grant))
|
|
47127
|
+
)
|
|
47128
|
+
);
|
|
47129
|
+
}
|
|
47130
|
+
const cost = plan.cost;
|
|
47131
|
+
const costLine = cost.basis === "none" ? "no estimate" : [
|
|
47132
|
+
`${formatUsd(cost.per_run_usd)} per run`,
|
|
47133
|
+
`${formatUsd(cost.per_month_usd)} per month`,
|
|
47134
|
+
cost.engine_seconds_per_run !== null ? `${Math.round(cost.engine_seconds_per_run)} engine seconds per run` : null
|
|
47135
|
+
].filter(Boolean).join(", ") + source_default.dim(
|
|
47136
|
+
cost.basis === "history" ? " (estimate from recent runs)" : " (estimate)"
|
|
47137
|
+
);
|
|
47138
|
+
out.push(...section("Cost", [costLine]));
|
|
47139
|
+
if (plan.backfill) {
|
|
47140
|
+
const values = plan.backfill.values;
|
|
47141
|
+
const range = values.length > 1 ? `${values[0]} to ${values[values.length - 1]}` : values[0] ?? "";
|
|
47142
|
+
out.push(
|
|
47143
|
+
...section("Backfill", [
|
|
47144
|
+
`${plan.backfill.runs} runs of ${plan.backfill.param}${range ? `: ${range}` : ""}`
|
|
47145
|
+
])
|
|
47146
|
+
);
|
|
47147
|
+
}
|
|
47148
|
+
out.push(
|
|
47149
|
+
...section(
|
|
47150
|
+
"Warnings",
|
|
47151
|
+
plan.warnings.map((warning) => source_default.yellow(formatSpecIssues([warning])))
|
|
47152
|
+
)
|
|
47153
|
+
);
|
|
47154
|
+
out.push(
|
|
47155
|
+
"",
|
|
47156
|
+
plan.requires_approval ? source_default.yellow(
|
|
47157
|
+
`Requires approval: yes. Apply it with plan id ${plan.plan_id}.`
|
|
47158
|
+
) : source_default.dim("Requires approval: no")
|
|
47159
|
+
);
|
|
47160
|
+
return out.join("\n");
|
|
47161
|
+
}
|
|
47162
|
+
function statusColor(status) {
|
|
47163
|
+
switch (status) {
|
|
47164
|
+
case "succeeded":
|
|
47165
|
+
case "reused":
|
|
47166
|
+
return source_default.green;
|
|
47167
|
+
case "failed":
|
|
47168
|
+
return source_default.red;
|
|
47169
|
+
case "cancelled":
|
|
47170
|
+
case "skipped":
|
|
47171
|
+
return source_default.yellow;
|
|
47172
|
+
default:
|
|
47173
|
+
return source_default.cyan;
|
|
47174
|
+
}
|
|
47175
|
+
}
|
|
47176
|
+
function cellRows(cell) {
|
|
47177
|
+
const parts = [];
|
|
47178
|
+
const rowCount = cell.output?.row_count;
|
|
47179
|
+
if (typeof rowCount === "number") {
|
|
47180
|
+
parts.push(`${rowCount} ${rowCount === 1 ? "row" : "rows"}`);
|
|
47181
|
+
}
|
|
47182
|
+
if (cell.output_table) {
|
|
47183
|
+
parts.push(
|
|
47184
|
+
cell.rows_written !== null && cell.rows_written !== void 0 ? `wrote ${cell.rows_written} rows to ${cell.output_table}` : `writes ${cell.output_table}`
|
|
47185
|
+
);
|
|
47186
|
+
}
|
|
47187
|
+
if (cell.engine) parts.push(cell.engine.toLowerCase());
|
|
47188
|
+
if (cell.reused_from_run_id) parts.push(`reused ${cell.reused_from_run_id}`);
|
|
47189
|
+
return parts.join(", ");
|
|
47190
|
+
}
|
|
47191
|
+
function padEnd(text, width) {
|
|
47192
|
+
return text.length >= width ? text : text + " ".repeat(width - text.length);
|
|
47193
|
+
}
|
|
47194
|
+
function formatRunDetail(detail) {
|
|
47195
|
+
const run = detail.run;
|
|
47196
|
+
const header = [
|
|
47197
|
+
`${source_default.bold("Run")} ${run.id}`,
|
|
47198
|
+
statusColor(run.status)(run.status),
|
|
47199
|
+
formatDuration(run.duration_ms),
|
|
47200
|
+
run.cost_usd !== null && run.cost_usd !== void 0 ? formatUsd(run.cost_usd) : ""
|
|
47201
|
+
].filter(Boolean).join(" ");
|
|
47202
|
+
const out = [header];
|
|
47203
|
+
const width = Math.max(4, ...detail.cells.map((cell) => cell.cell_id.length));
|
|
47204
|
+
const statusWidth = Math.max(
|
|
47205
|
+
6,
|
|
47206
|
+
...detail.cells.map((cell) => cell.status.length)
|
|
47207
|
+
);
|
|
47208
|
+
for (const cell of detail.cells) {
|
|
47209
|
+
const status = statusColor(cell.status)(padEnd(cell.status, statusWidth));
|
|
47210
|
+
const rows = cellRows(cell);
|
|
47211
|
+
out.push(
|
|
47212
|
+
` ${padEnd(cell.cell_id, width)} ${status}${rows ? ` ${source_default.dim(rows)}` : ""}`
|
|
47213
|
+
);
|
|
47214
|
+
if (cell.output?.error) {
|
|
47215
|
+
out.push(indent(source_default.red(cell.output.error), " ".repeat(width + 6)));
|
|
47216
|
+
}
|
|
47217
|
+
for (const check of cell.checks ?? []) {
|
|
47218
|
+
if (!check.passed) {
|
|
47219
|
+
out.push(
|
|
47220
|
+
" ".repeat(width + 6) + source_default.red(
|
|
47221
|
+
`check failed: ${check.check}${check.detail ? ` (${check.detail})` : ""}`
|
|
47222
|
+
)
|
|
47223
|
+
);
|
|
47224
|
+
}
|
|
47225
|
+
}
|
|
47226
|
+
}
|
|
47227
|
+
if (run.error) out.push("", source_default.red(run.error));
|
|
47228
|
+
if (run.stale_inputs?.length) {
|
|
47229
|
+
out.push(
|
|
47230
|
+
"",
|
|
47231
|
+
source_default.yellow(
|
|
47232
|
+
`Stale inputs: ${run.stale_inputs.map((input) => input.table).join(", ")}`
|
|
47233
|
+
)
|
|
47234
|
+
);
|
|
47235
|
+
}
|
|
47236
|
+
if (run.summary) out.push("", run.summary);
|
|
47237
|
+
if (run.url) out.push("", source_default.dim(run.url));
|
|
47238
|
+
return out.join("\n");
|
|
47239
|
+
}
|
|
47240
|
+
function formatParams(params) {
|
|
47241
|
+
if (!params) return "";
|
|
47242
|
+
return Object.entries(params).map(
|
|
47243
|
+
([key, value]) => `${key}=${typeof value === "string" ? value : JSON.stringify(value)}`
|
|
47244
|
+
).join(" ");
|
|
47245
|
+
}
|
|
47246
|
+
var RUN_COLUMNS = [
|
|
47247
|
+
"id",
|
|
47248
|
+
"trigger",
|
|
47249
|
+
"status",
|
|
47250
|
+
"version",
|
|
47251
|
+
"params",
|
|
47252
|
+
"created",
|
|
47253
|
+
"duration"
|
|
47254
|
+
];
|
|
47255
|
+
function runRows(runs) {
|
|
47256
|
+
return runs.map((run) => [
|
|
47257
|
+
run.id,
|
|
47258
|
+
run.trigger,
|
|
47259
|
+
run.status,
|
|
47260
|
+
run.notebook_version,
|
|
47261
|
+
formatParams(run.params),
|
|
47262
|
+
run.created_at,
|
|
47263
|
+
formatDuration(run.duration_ms)
|
|
47264
|
+
]);
|
|
47265
|
+
}
|
|
47266
|
+
function formatLogLine(line) {
|
|
47267
|
+
const cell = line.cell_id ? source_default.cyan(`[${line.cell_id}]`) + " " : "";
|
|
47268
|
+
const stream = line.stream === "stderr" ? source_default.red(line.stream) : source_default.dim(line.stream);
|
|
47269
|
+
return `${source_default.dim(line.time)} ${cell}${stream} ${line.line}`;
|
|
47270
|
+
}
|
|
47271
|
+
function numberChange(a, b3) {
|
|
47272
|
+
if (a === null && b3 === null) return "";
|
|
47273
|
+
return `${a ?? "n/a"} -> ${b3 ?? "n/a"}`;
|
|
47274
|
+
}
|
|
47275
|
+
function formatCompare(compare) {
|
|
47276
|
+
const out = [
|
|
47277
|
+
`${source_default.bold("A")} ${compare.a.id} ${compare.a.status} ${compare.a.created_at} v${compare.a.notebook_version}`,
|
|
47278
|
+
`${source_default.bold("B")} ${compare.b.id} ${compare.b.status} ${compare.b.created_at} v${compare.b.notebook_version}`
|
|
47279
|
+
];
|
|
47280
|
+
const inputs = compare.inputs.map((input) => {
|
|
47281
|
+
if (!input.changed) return `${input.table} ${source_default.dim("unchanged")}`;
|
|
47282
|
+
const parts = [
|
|
47283
|
+
input.rows_added !== null ? source_default.green(`+${input.rows_added}`) : null,
|
|
47284
|
+
input.rows_deleted !== null ? source_default.red(`-${input.rows_deleted}`) : null,
|
|
47285
|
+
input.schema_changed ? source_default.yellow("schema changed") : null
|
|
47286
|
+
].filter(Boolean);
|
|
47287
|
+
const writers = input.writers.length ? source_default.dim(
|
|
47288
|
+
` written by ${input.writers.map(
|
|
47289
|
+
(writer) => `${writer.job} (${writer.state}${writer.anomalies ? `, ${writer.anomalies} anomalies` : ""})`
|
|
47290
|
+
).join(", ")}`
|
|
47291
|
+
) : "";
|
|
47292
|
+
return `${input.table} ${parts.join(" ") || "changed"}${writers}`;
|
|
47293
|
+
});
|
|
47294
|
+
out.push(...section("Inputs", inputs));
|
|
47295
|
+
const cells = compare.cells.flatMap((cell) => {
|
|
47296
|
+
const changes = [
|
|
47297
|
+
numberChange(cell.row_count_a, cell.row_count_b),
|
|
47298
|
+
numberChange(cell.number_a, cell.number_b)
|
|
47299
|
+
];
|
|
47300
|
+
const rows = changes[0] ? `rows ${changes[0]}` : "";
|
|
47301
|
+
const number = changes[1] ? `value ${changes[1]}` : "";
|
|
47302
|
+
const text = [rows, number].filter(Boolean).join(", ");
|
|
47303
|
+
return text ? [`${cell.cell_id} ${text}`] : [];
|
|
47304
|
+
});
|
|
47305
|
+
out.push(...section("Cells", cells));
|
|
47306
|
+
if (compare.spec_diff?.trim()) {
|
|
47307
|
+
out.push("", source_default.bold("Spec diff"), indent(colorDiff(compare.spec_diff)));
|
|
47308
|
+
} else {
|
|
47309
|
+
out.push("", source_default.dim("Same spec"));
|
|
47310
|
+
}
|
|
47311
|
+
return out.join("\n");
|
|
47312
|
+
}
|
|
47313
|
+
function publishGuidance(slug, planId) {
|
|
47314
|
+
return planId ? `oleander notebooks publish ${slug} --plan ${planId}` : `oleander notebooks plan ${slug} --publish, then oleander notebooks publish ${slug} --plan <plan_id>`;
|
|
47315
|
+
}
|
|
47316
|
+
|
|
47317
|
+
// src/commands/notebooks/sync.ts
|
|
47318
|
+
var import_node_fs7 = require("fs");
|
|
47319
|
+
var import_node_path7 = require("path");
|
|
47320
|
+
var NOTEBOOK_FILE_SUFFIX = ".notebook.yaml";
|
|
47321
|
+
var SKIPPED_DIRS = /* @__PURE__ */ new Set(["node_modules"]);
|
|
47322
|
+
async function findNotebookFiles(paths) {
|
|
47323
|
+
const found = /* @__PURE__ */ new Set();
|
|
47324
|
+
for (const path2 of paths) {
|
|
47325
|
+
let stat2;
|
|
47326
|
+
try {
|
|
47327
|
+
stat2 = await import_node_fs7.promises.stat(path2);
|
|
47328
|
+
} catch (error) {
|
|
47329
|
+
if (error.code === "ENOENT") {
|
|
47330
|
+
throw new Error(`Path not found: ${path2}`);
|
|
47331
|
+
}
|
|
47332
|
+
throw error;
|
|
47333
|
+
}
|
|
47334
|
+
if (stat2.isFile()) {
|
|
47335
|
+
found.add(path2);
|
|
47336
|
+
} else if (stat2.isDirectory()) {
|
|
47337
|
+
await walk(path2, found);
|
|
47338
|
+
}
|
|
47339
|
+
}
|
|
47340
|
+
return [...found].sort();
|
|
47341
|
+
}
|
|
47342
|
+
async function walk(dir, found) {
|
|
47343
|
+
const entries = await import_node_fs7.promises.readdir(dir, { withFileTypes: true });
|
|
47344
|
+
for (const entry of entries) {
|
|
47345
|
+
const path2 = (0, import_node_path7.join)(dir, entry.name);
|
|
47346
|
+
if (entry.isDirectory()) {
|
|
47347
|
+
if (entry.name.startsWith(".") || SKIPPED_DIRS.has(entry.name)) continue;
|
|
47348
|
+
await walk(path2, found);
|
|
47349
|
+
} else if (entry.isFile() && entry.name.endsWith(NOTEBOOK_FILE_SUFFIX)) {
|
|
47350
|
+
found.add(path2);
|
|
47351
|
+
}
|
|
47352
|
+
}
|
|
47353
|
+
}
|
|
47354
|
+
function duplicateSlugs(files) {
|
|
47355
|
+
const bySlug = /* @__PURE__ */ new Map();
|
|
47356
|
+
for (const file of files) {
|
|
47357
|
+
bySlug.set(file.slug, [...bySlug.get(file.slug) ?? [], file.path]);
|
|
47358
|
+
}
|
|
47359
|
+
return [...bySlug.entries()].filter(([, paths]) => paths.length > 1).map(([slug, paths]) => `${slug}: ${paths.join(", ")}`);
|
|
47360
|
+
}
|
|
47361
|
+
var FAILED = /* @__PURE__ */ new Set([
|
|
47362
|
+
"needs_approval",
|
|
47363
|
+
"invalid",
|
|
47364
|
+
"conflict",
|
|
47365
|
+
"error"
|
|
47366
|
+
]);
|
|
47367
|
+
function isFailedSync(status) {
|
|
47368
|
+
return FAILED.has(status);
|
|
47369
|
+
}
|
|
47370
|
+
async function syncNotebook(client, file, options) {
|
|
47371
|
+
const result = {
|
|
47372
|
+
file: file.path,
|
|
47373
|
+
slug: file.slug,
|
|
47374
|
+
status: "error",
|
|
47375
|
+
plan: null,
|
|
47376
|
+
publish_plan: null,
|
|
47377
|
+
version: null,
|
|
47378
|
+
url: null,
|
|
47379
|
+
message: null,
|
|
47380
|
+
errors: []
|
|
47381
|
+
};
|
|
47382
|
+
try {
|
|
47383
|
+
const planned = await planNotebook(client, file);
|
|
47384
|
+
if (planned.status === "invalid") {
|
|
47385
|
+
return { ...result, status: "invalid", errors: planned.errors };
|
|
47386
|
+
}
|
|
47387
|
+
const plan = planned.plan;
|
|
47388
|
+
result.plan = plan;
|
|
47389
|
+
result.version = plan.creates ? null : plan.base_version;
|
|
47390
|
+
if (!plan.creates && !plan.diff.trim()) {
|
|
47391
|
+
return { ...result, status: "unchanged" };
|
|
47392
|
+
}
|
|
47393
|
+
if (options.dryRun) return { ...result, status: "planned" };
|
|
47394
|
+
const takesEffect = !plan.draft || options.publish;
|
|
47395
|
+
if (plan.requires_approval && takesEffect && !options.approve) {
|
|
47396
|
+
return {
|
|
47397
|
+
...result,
|
|
47398
|
+
status: "needs_approval",
|
|
47399
|
+
message: "Adds outputs, a schedule, destinations or a budget. Rerun with --approve to apply it."
|
|
47400
|
+
};
|
|
47401
|
+
}
|
|
47402
|
+
const response = await client.putYaml(file.slug, file.yaml, {
|
|
47403
|
+
run: false,
|
|
47404
|
+
planId: plan.plan_id
|
|
47405
|
+
});
|
|
47406
|
+
const body = await readBody(response);
|
|
47407
|
+
if (response.status === 422) {
|
|
47408
|
+
const errors = specIssuesFromBody(body);
|
|
47409
|
+
return {
|
|
47410
|
+
...result,
|
|
47411
|
+
status: "invalid",
|
|
47412
|
+
errors: errors.length ? errors : [
|
|
47413
|
+
{
|
|
47414
|
+
path: "",
|
|
47415
|
+
message: errorMessageFromBody(body, "Invalid notebook")
|
|
47416
|
+
}
|
|
47417
|
+
]
|
|
47418
|
+
};
|
|
47419
|
+
}
|
|
47420
|
+
if (response.status === 409) {
|
|
47421
|
+
return {
|
|
47422
|
+
...result,
|
|
47423
|
+
status: "conflict",
|
|
47424
|
+
message: errorMessageFromBody(
|
|
47425
|
+
body,
|
|
47426
|
+
"The notebook changed on the server while syncing"
|
|
47427
|
+
)
|
|
47428
|
+
};
|
|
47429
|
+
}
|
|
47430
|
+
if (!response.ok) {
|
|
47431
|
+
throw new NotebookApiError(
|
|
47432
|
+
response.status,
|
|
47433
|
+
errorMessageFromBody(
|
|
47434
|
+
body,
|
|
47435
|
+
`Failed to save notebook (HTTP ${response.status})`
|
|
47436
|
+
),
|
|
47437
|
+
body
|
|
47438
|
+
);
|
|
47439
|
+
}
|
|
47440
|
+
const saved = body;
|
|
47441
|
+
result.version = saved.version;
|
|
47442
|
+
result.url = saved.url;
|
|
47443
|
+
await recordIfTracked(options.cwd, file.slug, saved.version);
|
|
47444
|
+
if (!saved.draft) {
|
|
47445
|
+
return { ...result, status: plan.creates ? "created" : "updated" };
|
|
47446
|
+
}
|
|
47447
|
+
if (!options.publish) return { ...result, status: "draft_saved" };
|
|
47448
|
+
const publishPlan = await client.planPublish(file.slug);
|
|
47449
|
+
result.publish_plan = publishPlan;
|
|
47450
|
+
if (publishPlan.requires_approval && !options.approve) {
|
|
47451
|
+
return {
|
|
47452
|
+
...result,
|
|
47453
|
+
status: "needs_approval",
|
|
47454
|
+
message: "The draft is saved. Publishing it adds outputs, a schedule, destinations or a budget; rerun with --approve to publish it."
|
|
47455
|
+
};
|
|
47456
|
+
}
|
|
47457
|
+
const published = await client.publish(file.slug, publishPlan.plan_id);
|
|
47458
|
+
if (typeof published?.version === "number") {
|
|
47459
|
+
result.version = published.version;
|
|
47460
|
+
await recordIfTracked(options.cwd, file.slug, published.version);
|
|
47461
|
+
}
|
|
47462
|
+
if (typeof published?.url === "string") result.url = published.url;
|
|
47463
|
+
return { ...result, status: "published" };
|
|
47464
|
+
} catch (error) {
|
|
47465
|
+
return {
|
|
47466
|
+
...result,
|
|
47467
|
+
status: "error",
|
|
47468
|
+
message: error instanceof Error ? error.message : String(error)
|
|
47469
|
+
};
|
|
47470
|
+
}
|
|
47471
|
+
}
|
|
47472
|
+
async function recordIfTracked(cwd, slug, version) {
|
|
47473
|
+
const versions = await readNotebookVersions(cwd);
|
|
47474
|
+
if (slug in versions) await recordNotebookVersion(cwd, slug, version);
|
|
47475
|
+
}
|
|
47476
|
+
var STATUS_TEXT = {
|
|
47477
|
+
unchanged: "unchanged",
|
|
47478
|
+
planned: "would change",
|
|
47479
|
+
created: "created",
|
|
47480
|
+
updated: "updated",
|
|
47481
|
+
draft_saved: "draft saved",
|
|
47482
|
+
published: "published",
|
|
47483
|
+
needs_approval: "needs approval",
|
|
47484
|
+
invalid: "invalid",
|
|
47485
|
+
conflict: "conflict",
|
|
47486
|
+
error: "error"
|
|
47487
|
+
};
|
|
47488
|
+
function syncStatusText(status) {
|
|
47489
|
+
return STATUS_TEXT[status];
|
|
47490
|
+
}
|
|
47491
|
+
function planEffect(plan) {
|
|
47492
|
+
if (plan.creates) return "creates the notebook";
|
|
47493
|
+
if (plan.draft) return "saves a draft (the notebook is live)";
|
|
47494
|
+
return `updates version ${plan.base_version}`;
|
|
47495
|
+
}
|
|
47496
|
+
function syncDetail(result) {
|
|
47497
|
+
if (result.status === "invalid") return formatSpecIssues(result.errors);
|
|
47498
|
+
if (result.message) return result.message;
|
|
47499
|
+
if (result.status === "planned" && result.plan) {
|
|
47500
|
+
return [
|
|
47501
|
+
planEffect(result.plan),
|
|
47502
|
+
result.plan.requires_approval ? "needs --approve" : ""
|
|
47503
|
+
].filter(Boolean).join(", ");
|
|
47504
|
+
}
|
|
47505
|
+
return result.url ?? "";
|
|
47506
|
+
}
|
|
47507
|
+
function mdCell(text) {
|
|
47508
|
+
return text.replace(/\|/g, "\\|").replace(/\r?\n/g, "<br>");
|
|
47509
|
+
}
|
|
47510
|
+
function formatSyncMarkdown(results, options) {
|
|
47511
|
+
const title = options.dryRun ? "oleander notebooks plan" : "oleander notebooks sync";
|
|
47512
|
+
const lines = [`### ${title}`, ""];
|
|
47513
|
+
if (!results.length) {
|
|
47514
|
+
lines.push("No `*.notebook.yaml` files found.", "");
|
|
47515
|
+
return lines.join("\n");
|
|
47516
|
+
}
|
|
47517
|
+
lines.push(
|
|
47518
|
+
"| Notebook | File | Result | Detail |",
|
|
47519
|
+
"| --- | --- | --- | --- |"
|
|
47520
|
+
);
|
|
47521
|
+
for (const result of results) {
|
|
47522
|
+
const file = (0, import_node_path7.relative)(options.cwd, result.file) || result.file;
|
|
47523
|
+
const detail = syncDetail(result);
|
|
47524
|
+
const link = result.url ? `[${result.slug}](${result.url})` : result.slug;
|
|
47525
|
+
lines.push(
|
|
47526
|
+
`| ${mdCell(link)} | \`${mdCell(file)}\` | ${syncStatusText(result.status)} | ${mdCell(
|
|
47527
|
+
detail === result.url ? "" : detail
|
|
47528
|
+
)} |`
|
|
47529
|
+
);
|
|
47530
|
+
}
|
|
47531
|
+
lines.push("");
|
|
47532
|
+
for (const result of results) {
|
|
47533
|
+
const diff = result.plan?.diff?.trim();
|
|
47534
|
+
if (!diff || result.status === "unchanged") continue;
|
|
47535
|
+
lines.push(
|
|
47536
|
+
`<details><summary>${result.slug}: ${result.plan ? planEffect(result.plan) : "diff"}</summary>`,
|
|
47537
|
+
"",
|
|
47538
|
+
"```diff",
|
|
47539
|
+
diff.replace(/```/g, "` ` `"),
|
|
47540
|
+
"```",
|
|
47541
|
+
"",
|
|
47542
|
+
"</details>",
|
|
47543
|
+
""
|
|
47544
|
+
);
|
|
47545
|
+
}
|
|
47546
|
+
return lines.join("\n");
|
|
47547
|
+
}
|
|
47548
|
+
|
|
47549
|
+
// src/commands/notebooks/commands.ts
|
|
47550
|
+
function printJson2(value) {
|
|
47551
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}
|
|
47552
|
+
`);
|
|
47553
|
+
}
|
|
47554
|
+
async function loadClient() {
|
|
47555
|
+
try {
|
|
47556
|
+
const cfg = await config.load();
|
|
47557
|
+
if (!cfg.apiKey) throw new Error("No API key configured.");
|
|
47558
|
+
return new NotebooksClient(cfg.apiKey);
|
|
47559
|
+
} catch (error) {
|
|
47560
|
+
if (error instanceof Error) console.error(error.message);
|
|
47561
|
+
console.error(
|
|
47562
|
+
source_default.dim("Run ") + source_default.cyan("oleander configure --profile <name>") + source_default.dim(" to configure a profile")
|
|
47563
|
+
);
|
|
47564
|
+
process.exit(1);
|
|
47565
|
+
}
|
|
47566
|
+
}
|
|
47567
|
+
function startSpinner(json, text) {
|
|
47568
|
+
return json ? null : ora({ text, color: "cyan" }).start();
|
|
47569
|
+
}
|
|
47570
|
+
function exitWithError(spinner, error, fallback2) {
|
|
47571
|
+
const message = error instanceof Error ? error.message : fallback2;
|
|
47572
|
+
if (spinner) {
|
|
47573
|
+
spinner.fail(source_default.red(message));
|
|
47574
|
+
} else {
|
|
47575
|
+
console.error(message);
|
|
47576
|
+
}
|
|
47577
|
+
process.exit(1);
|
|
47578
|
+
}
|
|
47579
|
+
function displayPath(path2) {
|
|
47580
|
+
const rel = (0, import_node_path8.relative)(process.cwd(), path2);
|
|
47581
|
+
return rel && !rel.startsWith("..") ? rel : path2;
|
|
47582
|
+
}
|
|
47583
|
+
async function pullNotebookCommand(slug, options = {}) {
|
|
47584
|
+
const json = isJsonOutput(options.output);
|
|
47585
|
+
const client = await loadClient();
|
|
47586
|
+
const spinner = startSpinner(json, `Pulling ${slug}...`);
|
|
47587
|
+
try {
|
|
47588
|
+
const result = await pullNotebook(client, slug, process.cwd());
|
|
47589
|
+
if (json) {
|
|
47590
|
+
printJson2({ ...result, file: displayPath(result.file) });
|
|
47591
|
+
return;
|
|
47592
|
+
}
|
|
47593
|
+
spinner?.succeed(
|
|
47594
|
+
source_default.green(
|
|
47595
|
+
`Wrote ${displayPath(result.file)}${result.version !== null ? ` (version ${result.version})` : ""}`
|
|
47596
|
+
)
|
|
47597
|
+
);
|
|
47598
|
+
if (result.version === null) {
|
|
47599
|
+
console.log(
|
|
47600
|
+
source_default.yellow(
|
|
47601
|
+
"The server sent no version, so the next push will not check for concurrent edits."
|
|
47602
|
+
)
|
|
47603
|
+
);
|
|
47604
|
+
}
|
|
47605
|
+
} catch (error) {
|
|
47606
|
+
exitWithError(spinner, error, "Failed to pull notebook");
|
|
47607
|
+
}
|
|
47608
|
+
}
|
|
47609
|
+
async function pushNotebookCommand(file, options = {}) {
|
|
47610
|
+
const json = isJsonOutput(options.output);
|
|
47611
|
+
const client = await loadClient();
|
|
47612
|
+
let spinner = null;
|
|
47613
|
+
let printedPlanId = null;
|
|
47614
|
+
try {
|
|
47615
|
+
const notebook = await readNotebookFile(file);
|
|
47616
|
+
spinner = startSpinner(
|
|
47617
|
+
json,
|
|
47618
|
+
options.planId ? `Saving ${notebook.slug}...` : `Planning ${notebook.slug}...`
|
|
47619
|
+
);
|
|
47620
|
+
const outcome = await pushNotebook(client, notebook, {
|
|
47621
|
+
cwd: process.cwd(),
|
|
47622
|
+
run: options.run,
|
|
47623
|
+
planId: options.planId,
|
|
47624
|
+
onPlan: (plan) => {
|
|
47625
|
+
if (json || !spinner) return;
|
|
47626
|
+
spinner.stop();
|
|
47627
|
+
console.log(formatPlan(plan));
|
|
47628
|
+
console.log();
|
|
47629
|
+
printedPlanId = plan.plan_id;
|
|
47630
|
+
if (!plan.requires_approval) {
|
|
47631
|
+
spinner = startSpinner(json, `Saving ${notebook.slug}...`);
|
|
47632
|
+
}
|
|
47633
|
+
}
|
|
47634
|
+
});
|
|
47635
|
+
if (outcome.status !== "saved") {
|
|
47636
|
+
reportUnsaved(outcome, { file, json, spinner, printedPlanId, options });
|
|
47637
|
+
process.exit(1);
|
|
47638
|
+
}
|
|
47639
|
+
const { result } = outcome;
|
|
47640
|
+
let runDetail = null;
|
|
47641
|
+
let timedOut = false;
|
|
47642
|
+
if (!json) {
|
|
47643
|
+
spinner?.succeed(
|
|
47644
|
+
source_default.green(
|
|
47645
|
+
result.draft ? `Saved a draft of ${result.slug} (version ${result.version})` : `Saved ${result.slug} (version ${result.version})`
|
|
47646
|
+
)
|
|
47647
|
+
);
|
|
47648
|
+
console.log(source_default.dim(result.url));
|
|
47649
|
+
if (result.warnings.length) {
|
|
47650
|
+
console.log(source_default.yellow(formatSpecIssues(result.warnings)));
|
|
47651
|
+
}
|
|
47652
|
+
}
|
|
47653
|
+
if (options.run) {
|
|
47654
|
+
if (!result.run) {
|
|
47655
|
+
if (!json) console.log(source_default.yellow("The server did not start a run."));
|
|
47656
|
+
} else {
|
|
47657
|
+
spinner = startSpinner(json, `Running ${result.slug}...`);
|
|
47658
|
+
const waited = await waitForRun2(
|
|
47659
|
+
client,
|
|
47660
|
+
result.slug,
|
|
47661
|
+
result.run.run_id,
|
|
47662
|
+
{
|
|
47663
|
+
onPoll: (detail) => {
|
|
47664
|
+
if (spinner) {
|
|
47665
|
+
const done = detail.cells.filter(
|
|
47666
|
+
(cell) => cell.status !== "pending" && cell.status !== "running"
|
|
47667
|
+
).length;
|
|
47668
|
+
spinner.text = `Running ${result.slug}: ${done}/${detail.cells.length} cells`;
|
|
47669
|
+
}
|
|
47670
|
+
}
|
|
47671
|
+
}
|
|
47672
|
+
);
|
|
47673
|
+
runDetail = waited.detail;
|
|
47674
|
+
timedOut = waited.timedOut;
|
|
47675
|
+
spinner?.stop();
|
|
47676
|
+
}
|
|
47677
|
+
}
|
|
47678
|
+
if (json) {
|
|
47679
|
+
printJson2({ ...outcome, run: runDetail, timed_out: timedOut });
|
|
47680
|
+
} else {
|
|
47681
|
+
if (runDetail) {
|
|
47682
|
+
console.log();
|
|
47683
|
+
console.log(formatRunDetail(runDetail));
|
|
47684
|
+
if (timedOut) {
|
|
47685
|
+
console.log(
|
|
47686
|
+
source_default.yellow(
|
|
47687
|
+
`
|
|
47688
|
+
Still ${runDetail.run.status} after 10 minutes. Check it with oleander notebooks logs ${result.slug} ${runDetail.run.id}.`
|
|
47689
|
+
)
|
|
47690
|
+
);
|
|
47691
|
+
}
|
|
47692
|
+
}
|
|
47693
|
+
if (result.draft) {
|
|
47694
|
+
console.log();
|
|
47695
|
+
console.log(
|
|
47696
|
+
`${result.slug} is live, so this save is a draft: the published version, its schedule and outputs are unchanged.`
|
|
47697
|
+
);
|
|
47698
|
+
if (outcome.publish_plan) {
|
|
47699
|
+
console.log();
|
|
47700
|
+
console.log(formatPlan(outcome.publish_plan));
|
|
47701
|
+
}
|
|
47702
|
+
console.log();
|
|
47703
|
+
console.log(
|
|
47704
|
+
source_default.dim("Publish it with ") + source_default.cyan(
|
|
47705
|
+
publishGuidance(result.slug, outcome.publish_plan?.plan_id)
|
|
47706
|
+
)
|
|
47707
|
+
);
|
|
47708
|
+
}
|
|
47709
|
+
}
|
|
47710
|
+
if (runDetail && (timedOut || isFailedRun(runDetail))) process.exit(1);
|
|
47711
|
+
} catch (error) {
|
|
47712
|
+
exitWithError(spinner, error, "Failed to push notebook");
|
|
47713
|
+
}
|
|
47714
|
+
}
|
|
47715
|
+
function reportUnsaved(outcome, context) {
|
|
47716
|
+
const { json, spinner } = context;
|
|
47717
|
+
if (json) {
|
|
47718
|
+
printJson2(outcome);
|
|
47719
|
+
return;
|
|
47720
|
+
}
|
|
47721
|
+
switch (outcome.status) {
|
|
47722
|
+
case "invalid":
|
|
47723
|
+
spinner?.fail(source_default.red(`${outcome.slug} is not valid`));
|
|
47724
|
+
console.error(formatSpecIssues(outcome.errors));
|
|
47725
|
+
return;
|
|
47726
|
+
case "plan_required": {
|
|
47727
|
+
spinner?.stop();
|
|
47728
|
+
if (context.printedPlanId !== outcome.plan.plan_id) {
|
|
47729
|
+
console.log(formatPlan(outcome.plan));
|
|
47730
|
+
console.log();
|
|
47731
|
+
}
|
|
47732
|
+
const rerun = [
|
|
47733
|
+
"oleander notebooks push",
|
|
47734
|
+
context.file,
|
|
47735
|
+
context.options.run ? "--run" : "",
|
|
47736
|
+
`--plan-id ${outcome.plan.plan_id}`
|
|
47737
|
+
].filter(Boolean).join(" ");
|
|
47738
|
+
console.error(
|
|
47739
|
+
source_default.yellow(
|
|
47740
|
+
"Nothing was saved. This change adds outputs, a schedule, destinations or a budget, so it needs an approved plan."
|
|
47741
|
+
)
|
|
47742
|
+
);
|
|
47743
|
+
console.error(
|
|
47744
|
+
source_default.dim("Review the plan above, then run ") + source_default.cyan(rerun)
|
|
47745
|
+
);
|
|
47746
|
+
return;
|
|
47747
|
+
}
|
|
47748
|
+
case "conflict": {
|
|
47749
|
+
spinner?.fail(source_default.red(`${outcome.slug} changed on the server`));
|
|
47750
|
+
const since = outcome.base_version !== null ? ` since version ${outcome.base_version}` : "";
|
|
47751
|
+
const now = outcome.current_version !== null ? ` (now version ${outcome.current_version})` : "";
|
|
47752
|
+
console.error(`${outcome.message}`);
|
|
47753
|
+
console.error(
|
|
47754
|
+
`Someone saved ${outcome.slug}${since}${now}. Copy your edits aside, run ` + source_default.cyan(`oleander notebooks pull ${outcome.slug}`) + ` (it overwrites ${outcome.slug}.notebook.yaml), merge your edits into the pulled file, and push again.`
|
|
47755
|
+
);
|
|
47756
|
+
return;
|
|
47757
|
+
}
|
|
47758
|
+
}
|
|
47759
|
+
}
|
|
47760
|
+
async function planNotebookCommand(target, options = {}) {
|
|
47761
|
+
const json = isJsonOutput(options.output);
|
|
47762
|
+
const client = await loadClient();
|
|
47763
|
+
let spinner = null;
|
|
47764
|
+
try {
|
|
47765
|
+
let plan;
|
|
47766
|
+
if (options.publish) {
|
|
47767
|
+
const slug = (0, import_node_fs8.existsSync)(target) ? (await readNotebookFile(target)).slug : target;
|
|
47768
|
+
spinner = startSpinner(json, `Planning the publish of ${slug}...`);
|
|
47769
|
+
plan = await client.planPublish(slug);
|
|
47770
|
+
} else {
|
|
47771
|
+
const notebook = await readNotebookFile(target);
|
|
47772
|
+
spinner = startSpinner(json, `Planning ${notebook.slug}...`);
|
|
47773
|
+
const outcome = await planNotebook(client, notebook);
|
|
47774
|
+
if (outcome.status === "invalid") {
|
|
47775
|
+
if (json) {
|
|
47776
|
+
printJson2(outcome);
|
|
47777
|
+
} else {
|
|
47778
|
+
spinner?.fail(source_default.red(`${notebook.slug} is not valid`));
|
|
47779
|
+
console.error(formatSpecIssues(outcome.errors));
|
|
47780
|
+
}
|
|
47781
|
+
process.exit(1);
|
|
47782
|
+
}
|
|
47783
|
+
plan = outcome.plan;
|
|
47784
|
+
}
|
|
47785
|
+
spinner?.stop();
|
|
47786
|
+
if (json) {
|
|
47787
|
+
printJson2(plan);
|
|
47788
|
+
return;
|
|
47789
|
+
}
|
|
47790
|
+
console.log(formatPlan(plan));
|
|
47791
|
+
if (plan.kind === "publish") {
|
|
47792
|
+
console.log();
|
|
47793
|
+
console.log(
|
|
47794
|
+
source_default.dim("Publish it with ") + source_default.cyan(publishGuidance(plan.slug, plan.plan_id))
|
|
47795
|
+
);
|
|
47796
|
+
}
|
|
47797
|
+
} catch (error) {
|
|
47798
|
+
exitWithError(spinner, error, "Failed to plan notebook");
|
|
47799
|
+
}
|
|
47800
|
+
}
|
|
47801
|
+
async function publishNotebookCommand(slug, options) {
|
|
47802
|
+
const json = isJsonOutput(options.output);
|
|
47803
|
+
const client = await loadClient();
|
|
47804
|
+
const spinner = startSpinner(json, `Publishing ${slug}...`);
|
|
47805
|
+
try {
|
|
47806
|
+
const body = await client.publish(slug, options.plan);
|
|
47807
|
+
const version = typeof body?.version === "number" ? body.version : null;
|
|
47808
|
+
if (version !== null) {
|
|
47809
|
+
const versions = await readNotebookVersions(process.cwd());
|
|
47810
|
+
if (slug in versions) {
|
|
47811
|
+
await recordNotebookVersion(process.cwd(), slug, version);
|
|
47812
|
+
}
|
|
47813
|
+
}
|
|
47814
|
+
if (json) {
|
|
47815
|
+
printJson2(body);
|
|
47816
|
+
return;
|
|
47817
|
+
}
|
|
47818
|
+
spinner?.succeed(
|
|
47819
|
+
source_default.green(
|
|
47820
|
+
`Published ${slug}${version !== null ? ` (version ${version})` : ""}`
|
|
47821
|
+
)
|
|
47822
|
+
);
|
|
47823
|
+
} catch (error) {
|
|
47824
|
+
exitWithError(spinner, error, "Failed to publish notebook");
|
|
47825
|
+
}
|
|
47826
|
+
}
|
|
47827
|
+
async function listRunsCommand(slug, options = {}) {
|
|
47828
|
+
const json = isJsonOutput(options.output);
|
|
47829
|
+
const client = await loadClient();
|
|
47830
|
+
const spinner = startSpinner(json, `Loading runs of ${slug}...`);
|
|
47831
|
+
try {
|
|
47832
|
+
const runs = await client.listRuns(slug);
|
|
47833
|
+
if (json) {
|
|
47834
|
+
printJson2({ runs });
|
|
47835
|
+
return;
|
|
47836
|
+
}
|
|
47837
|
+
spinner?.stop();
|
|
47838
|
+
printTable(
|
|
47839
|
+
{ columns: RUN_COLUMNS, rows: runRows(runs) },
|
|
47840
|
+
{ emptyMessage: `${slug} has no runs yet` }
|
|
47841
|
+
);
|
|
47842
|
+
} catch (error) {
|
|
47843
|
+
exitWithError(spinner, error, "Failed to list runs");
|
|
47844
|
+
}
|
|
47845
|
+
}
|
|
47846
|
+
async function runLogsCommand(slug, runId, options = {}) {
|
|
47847
|
+
const json = isJsonOutput(options.output);
|
|
47848
|
+
const client = await loadClient();
|
|
47849
|
+
try {
|
|
47850
|
+
const lines = await collectLogs(client, slug, runId, {
|
|
47851
|
+
cellId: options.cell,
|
|
47852
|
+
onPage: json ? void 0 : (page) => {
|
|
47853
|
+
for (const line of page) console.log(formatLogLine(line));
|
|
47854
|
+
}
|
|
47855
|
+
});
|
|
47856
|
+
if (json) {
|
|
47857
|
+
printJson2({ lines });
|
|
47858
|
+
return;
|
|
47859
|
+
}
|
|
47860
|
+
if (!lines.length) console.log(source_default.dim("No log lines"));
|
|
47861
|
+
} catch (error) {
|
|
47862
|
+
exitWithError(null, error, "Failed to read logs");
|
|
47863
|
+
}
|
|
47864
|
+
}
|
|
47865
|
+
async function cancelRunCommand(slug, runId, options = {}) {
|
|
47866
|
+
const json = isJsonOutput(options.output);
|
|
47867
|
+
const client = await loadClient();
|
|
47868
|
+
const spinner = startSpinner(json, `Cancelling run ${runId}...`);
|
|
47869
|
+
try {
|
|
47870
|
+
const body = await client.cancelRun(slug, runId);
|
|
47871
|
+
if (json) {
|
|
47872
|
+
printJson2(body);
|
|
47873
|
+
return;
|
|
47874
|
+
}
|
|
47875
|
+
const status = typeof body?.status === "string" ? body.status : typeof body?.run?.status === "string" ? String(body.run.status) : null;
|
|
47876
|
+
spinner?.succeed(
|
|
47877
|
+
source_default.green(
|
|
47878
|
+
`Cancel requested for ${runId}${status ? ` (${status})` : ""}`
|
|
47879
|
+
)
|
|
47880
|
+
);
|
|
47881
|
+
} catch (error) {
|
|
47882
|
+
exitWithError(spinner, error, "Failed to cancel run");
|
|
47883
|
+
}
|
|
47884
|
+
}
|
|
47885
|
+
async function compareRunsCommand(slug, runA, runB, options = {}) {
|
|
47886
|
+
const json = isJsonOutput(options.output);
|
|
47887
|
+
const client = await loadClient();
|
|
47888
|
+
const spinner = startSpinner(json, `Comparing ${runA} and ${runB}...`);
|
|
47889
|
+
try {
|
|
47890
|
+
const compare = await client.compare(slug, runA, runB);
|
|
47891
|
+
if (json) {
|
|
47892
|
+
printJson2(compare);
|
|
47893
|
+
return;
|
|
47894
|
+
}
|
|
47895
|
+
spinner?.stop();
|
|
47896
|
+
console.log(formatCompare(compare));
|
|
47897
|
+
} catch (error) {
|
|
47898
|
+
exitWithError(spinner, error, "Failed to compare runs");
|
|
47899
|
+
}
|
|
47900
|
+
}
|
|
47901
|
+
async function backfillCommand(slug, options) {
|
|
47902
|
+
const json = isJsonOutput(options.output);
|
|
47903
|
+
const client = await loadClient();
|
|
47904
|
+
const { param, from: from3, to, planId } = options;
|
|
47905
|
+
const spinner = startSpinner(
|
|
47906
|
+
json,
|
|
47907
|
+
planId ? `Starting backfill of ${slug}...` : `Planning backfill of ${slug}...`
|
|
47908
|
+
);
|
|
47909
|
+
try {
|
|
47910
|
+
const body = await client.backfill(
|
|
47911
|
+
slug,
|
|
47912
|
+
planId ? { param, from: from3, to, plan_id: planId } : { param, from: from3, to, plan: true }
|
|
47913
|
+
);
|
|
47914
|
+
if (json) {
|
|
47915
|
+
printJson2(body);
|
|
47916
|
+
return;
|
|
47917
|
+
}
|
|
47918
|
+
spinner?.stop();
|
|
47919
|
+
if (!planId) {
|
|
47920
|
+
if (!body.plan) throw new Error("The server returned no plan.");
|
|
47921
|
+
console.log(formatPlan(body.plan));
|
|
47922
|
+
console.log();
|
|
47923
|
+
console.log(
|
|
47924
|
+
source_default.dim("Start it with ") + source_default.cyan(
|
|
47925
|
+
`oleander notebooks backfill ${slug} --param ${param} --from ${from3} --to ${to} --plan-id ${body.plan.plan_id}`
|
|
47926
|
+
)
|
|
47927
|
+
);
|
|
47928
|
+
return;
|
|
47929
|
+
}
|
|
47930
|
+
console.log(
|
|
47931
|
+
source_default.green(`Started backfill ${body.backfill_id ?? ""}`.trim())
|
|
47932
|
+
);
|
|
47933
|
+
const runs = (body.runs ?? []).map((run) => ({
|
|
47934
|
+
...run,
|
|
47935
|
+
id: run.id ?? run.run_id ?? ""
|
|
47936
|
+
}));
|
|
47937
|
+
printTable(
|
|
47938
|
+
{ columns: RUN_COLUMNS, rows: runRows(runs) },
|
|
47939
|
+
{ emptyMessage: "No runs started" }
|
|
47940
|
+
);
|
|
47941
|
+
} catch (error) {
|
|
47942
|
+
exitWithError(spinner, error, "Failed to backfill notebook");
|
|
47943
|
+
}
|
|
47944
|
+
}
|
|
47945
|
+
var SYNC_COLUMNS = ["notebook", "file", "result", "detail"];
|
|
47946
|
+
async function syncNotebooksCommand(paths, options = {}) {
|
|
47947
|
+
const json = isJsonOutput(options.output);
|
|
47948
|
+
const cwd = process.cwd();
|
|
47949
|
+
let spinner = null;
|
|
47950
|
+
try {
|
|
47951
|
+
const searchPaths = paths.length ? paths : ["."];
|
|
47952
|
+
const found = await findNotebookFiles(searchPaths);
|
|
47953
|
+
const files = await Promise.all(
|
|
47954
|
+
found.map(async (path2) => ({ path: path2, ...await readNotebookFile(path2) }))
|
|
47955
|
+
);
|
|
47956
|
+
const duplicates = duplicateSlugs(
|
|
47957
|
+
files.map((file) => ({ path: displayPath(file.path), slug: file.slug }))
|
|
47958
|
+
);
|
|
47959
|
+
if (duplicates.length) {
|
|
47960
|
+
throw new Error(
|
|
47961
|
+
`More than one file declares the same slug:
|
|
47962
|
+
${duplicates.join("\n")}`
|
|
47963
|
+
);
|
|
47964
|
+
}
|
|
47965
|
+
const results = [];
|
|
47966
|
+
if (files.length) {
|
|
47967
|
+
const client = await loadClient();
|
|
47968
|
+
for (const file of files) {
|
|
47969
|
+
spinner = startSpinner(
|
|
47970
|
+
json,
|
|
47971
|
+
`${options.dryRun ? "Planning" : "Syncing"} ${file.slug}...`
|
|
47972
|
+
);
|
|
47973
|
+
const result = await syncNotebook(client, file, {
|
|
47974
|
+
cwd,
|
|
47975
|
+
dryRun: options.dryRun,
|
|
47976
|
+
approve: options.approve,
|
|
47977
|
+
publish: options.publish
|
|
47978
|
+
});
|
|
47979
|
+
spinner?.stop();
|
|
47980
|
+
spinner = null;
|
|
47981
|
+
results.push(result);
|
|
47982
|
+
if (!json && options.dryRun && result.plan && result.status === "planned") {
|
|
47983
|
+
console.log(formatPlan(result.plan));
|
|
47984
|
+
console.log();
|
|
47985
|
+
}
|
|
47986
|
+
}
|
|
47987
|
+
}
|
|
47988
|
+
if (options.summary) {
|
|
47989
|
+
await import_node_fs8.promises.appendFile(
|
|
47990
|
+
options.summary,
|
|
47991
|
+
`${formatSyncMarkdown(results, { dryRun: options.dryRun, cwd })}
|
|
47992
|
+
`,
|
|
47993
|
+
"utf8"
|
|
47994
|
+
);
|
|
47995
|
+
}
|
|
47996
|
+
const failed = results.filter((result) => isFailedSync(result.status));
|
|
47997
|
+
if (json) {
|
|
47998
|
+
printJson2({
|
|
47999
|
+
dry_run: !!options.dryRun,
|
|
48000
|
+
results: results.map((result) => ({
|
|
48001
|
+
...result,
|
|
48002
|
+
file: displayPath(result.file)
|
|
48003
|
+
})),
|
|
48004
|
+
failed: failed.length
|
|
48005
|
+
});
|
|
48006
|
+
} else {
|
|
48007
|
+
printTable(
|
|
48008
|
+
{
|
|
48009
|
+
columns: SYNC_COLUMNS,
|
|
48010
|
+
rows: results.map((result) => [
|
|
48011
|
+
result.slug,
|
|
48012
|
+
displayPath(result.file),
|
|
48013
|
+
syncStatusText(result.status),
|
|
48014
|
+
syncDetail(result)
|
|
48015
|
+
])
|
|
48016
|
+
},
|
|
48017
|
+
{
|
|
48018
|
+
emptyMessage: `No *.notebook.yaml files under ${searchPaths.join(", ")}`
|
|
48019
|
+
}
|
|
48020
|
+
);
|
|
48021
|
+
if (failed.length) {
|
|
48022
|
+
console.error(
|
|
48023
|
+
source_default.red(
|
|
48024
|
+
`${failed.length} of ${results.length} notebook${results.length === 1 ? "" : "s"} did not sync`
|
|
48025
|
+
)
|
|
48026
|
+
);
|
|
48027
|
+
}
|
|
48028
|
+
}
|
|
48029
|
+
if (failed.length) process.exit(1);
|
|
48030
|
+
} catch (error) {
|
|
48031
|
+
exitWithError(spinner, error, "Failed to sync notebooks");
|
|
48032
|
+
}
|
|
48033
|
+
}
|
|
48034
|
+
|
|
48035
|
+
// src/commands/notebooks/index.ts
|
|
48036
|
+
function registerNotebooksCommands(program3) {
|
|
48037
|
+
const notebooks = program3.command("notebooks").description("Edits, plans, runs and publishes notebooks as YAML files").addHelpText(
|
|
48038
|
+
"after",
|
|
48039
|
+
`
|
|
48040
|
+
pull writes <slug>.notebook.yaml exactly as saved and records its version in
|
|
48041
|
+
.oleander/notebooks.json; push sends that version as If-Match, so a save never
|
|
48042
|
+
overwrites someone else's edit. On a live notebook push saves a draft; publish
|
|
48043
|
+
it with the plan id push prints.
|
|
48044
|
+
|
|
48045
|
+
Examples:
|
|
48046
|
+
oleander notebooks pull bluehouse-morning
|
|
48047
|
+
oleander notebooks plan bluehouse-morning.notebook.yaml
|
|
48048
|
+
oleander notebooks push bluehouse-morning.notebook.yaml --run
|
|
48049
|
+
oleander notebooks publish bluehouse-morning --plan <plan_id>
|
|
48050
|
+
oleander notebooks logs bluehouse-morning <run_id> --cell posts_by_hour
|
|
48051
|
+
`
|
|
48052
|
+
);
|
|
48053
|
+
const pull = notebooks.command("pull").description("Write <slug>.notebook.yaml exactly as saved").argument("<slug>", "Notebook slug").action(pullNotebookCommand);
|
|
48054
|
+
addOutputOption(pull);
|
|
48055
|
+
const push = notebooks.command("push").description(
|
|
48056
|
+
"Plan and save a notebook YAML file (a draft, on a live notebook)"
|
|
48057
|
+
).argument("<file>", "Notebook YAML file").option("--run", "Run the notebook after saving and wait for the result").option(
|
|
48058
|
+
"--plan-id <id>",
|
|
48059
|
+
"Apply an approved plan (required when the change adds outputs, a schedule, destinations or a budget)"
|
|
48060
|
+
).action(pushNotebookCommand);
|
|
48061
|
+
addOutputOption(push);
|
|
48062
|
+
const sync = notebooks.command("sync").description(
|
|
48063
|
+
"Plan and save every *.notebook.yaml under the given paths (for CI)"
|
|
48064
|
+
).argument("[paths...]", "Files or directories to search", ["."]).option("--dry-run", "Plan every file and save nothing").option(
|
|
48065
|
+
"--approve",
|
|
48066
|
+
"Apply plans that add outputs, a schedule, destinations or a budget"
|
|
48067
|
+
).option("--publish", "Publish the draft a save leaves on a live notebook").option(
|
|
48068
|
+
"--summary <file>",
|
|
48069
|
+
"Append a Markdown report, like $GITHUB_STEP_SUMMARY"
|
|
48070
|
+
).addHelpText(
|
|
48071
|
+
"after",
|
|
48072
|
+
`
|
|
48073
|
+
The files are the source of truth: sync saves each changed file over what is on
|
|
48074
|
+
the server (a concurrent edit made between its plan and save fails with a
|
|
48075
|
+
conflict instead). Unchanged files are skipped. Notebooks deleted from the
|
|
48076
|
+
repository are left alone. Exits 1 if any file is invalid, needs --approve, or
|
|
48077
|
+
fails to save.
|
|
48078
|
+
|
|
48079
|
+
Examples:
|
|
48080
|
+
oleander notebooks sync notebooks/ --dry-run --summary "$GITHUB_STEP_SUMMARY"
|
|
48081
|
+
oleander notebooks sync notebooks/ --approve --publish
|
|
48082
|
+
`
|
|
48083
|
+
).action(syncNotebooksCommand);
|
|
48084
|
+
addOutputOption(sync);
|
|
48085
|
+
const plan = notebooks.command("plan").description("Show what saving a notebook YAML file would change").argument("<file>", "Notebook YAML file (or a slug, with --publish)").option("--publish", "Plan publishing the notebook's draft instead").action(planNotebookCommand);
|
|
48086
|
+
addOutputOption(plan);
|
|
48087
|
+
const publish2 = notebooks.command("publish").description("Publish a notebook's draft").argument("<slug>", "Notebook slug").requiredOption("--plan <plan_id>", "Plan id of the publish plan").action(publishNotebookCommand);
|
|
48088
|
+
addOutputOption(publish2);
|
|
48089
|
+
const runs = notebooks.command("runs").description("List a notebook's runs, newest first").argument("<slug>", "Notebook slug").action(listRunsCommand);
|
|
48090
|
+
addOutputOption(runs);
|
|
48091
|
+
const logs = notebooks.command("logs").description("Print a run's log lines").argument("<slug>", "Notebook slug").argument("<run_id>", "Run id").option("--cell <id>", "Only this cell's lines").action(runLogsCommand);
|
|
48092
|
+
addOutputOption(logs);
|
|
48093
|
+
const cancel = notebooks.command("cancel").description("Cancel a queued or running run").argument("<slug>", "Notebook slug").argument("<run_id>", "Run id").action(cancelRunCommand);
|
|
48094
|
+
addOutputOption(cancel);
|
|
48095
|
+
const compare = notebooks.command("compare").description("Compare two runs: inputs, per-cell numbers and spec diff").argument("<slug>", "Notebook slug").argument("<run_a>", "Earlier run id").argument("<run_b>", "Later run id").action(compareRunsCommand);
|
|
48096
|
+
addOutputOption(compare);
|
|
48097
|
+
const backfill = notebooks.command("backfill").description(
|
|
48098
|
+
"Run once per value of a date param (plans first without --plan-id)"
|
|
48099
|
+
).argument("<slug>", "Notebook slug").requiredOption("--param <name>", "Date param to backfill, like day").requiredOption("--from <date>", "First value, like 2026-11-01").requiredOption("--to <date>", "Last value, like 2026-11-15").option("--plan-id <id>", "Start the backfill this plan describes").action(backfillCommand);
|
|
48100
|
+
addOutputOption(backfill);
|
|
48101
|
+
}
|
|
48102
|
+
|
|
46620
48103
|
// src/utils/skills.ts
|
|
46621
48104
|
var import_node_child_process3 = require("child_process");
|
|
46622
48105
|
var import_node_os5 = require("os");
|
|
46623
|
-
var
|
|
46624
|
-
var
|
|
48106
|
+
var import_node_fs9 = require("fs");
|
|
48107
|
+
var import_node_path9 = require("path");
|
|
46625
48108
|
var SKILLS_REPO = "OleanderHQ/skills";
|
|
46626
48109
|
var OLEANDER_SKILLS_DIR = ".oleander/skills";
|
|
46627
48110
|
var OLEANDER_SKILL_NAMES = [
|
|
@@ -46654,12 +48137,12 @@ var SkillsInstallError = class extends Error {
|
|
|
46654
48137
|
}
|
|
46655
48138
|
};
|
|
46656
48139
|
function oleanderSkillsDir(homeDir = (0, import_node_os5.homedir)()) {
|
|
46657
|
-
return (0,
|
|
48140
|
+
return (0, import_node_path9.join)(homeDir, OLEANDER_SKILLS_DIR);
|
|
46658
48141
|
}
|
|
46659
48142
|
function readSkillVersion(skillDir) {
|
|
46660
48143
|
try {
|
|
46661
48144
|
const parsed = JSON.parse(
|
|
46662
|
-
(0,
|
|
48145
|
+
(0, import_node_fs9.readFileSync)((0, import_node_path9.join)(skillDir, "metadata.json"), "utf8")
|
|
46663
48146
|
);
|
|
46664
48147
|
return typeof parsed.version === "string" ? parsed.version : null;
|
|
46665
48148
|
} catch {
|
|
@@ -46668,7 +48151,7 @@ function readSkillVersion(skillDir) {
|
|
|
46668
48151
|
}
|
|
46669
48152
|
function skillPresent(skillDir) {
|
|
46670
48153
|
try {
|
|
46671
|
-
(0,
|
|
48154
|
+
(0, import_node_fs9.lstatSync)((0, import_node_path9.join)(skillDir, "SKILL.md"));
|
|
46672
48155
|
return true;
|
|
46673
48156
|
} catch {
|
|
46674
48157
|
return false;
|
|
@@ -46676,19 +48159,19 @@ function skillPresent(skillDir) {
|
|
|
46676
48159
|
}
|
|
46677
48160
|
function isSymlink(path2) {
|
|
46678
48161
|
try {
|
|
46679
|
-
return (0,
|
|
48162
|
+
return (0, import_node_fs9.lstatSync)(path2).isSymbolicLink();
|
|
46680
48163
|
} catch {
|
|
46681
48164
|
return false;
|
|
46682
48165
|
}
|
|
46683
48166
|
}
|
|
46684
48167
|
function presentSkillNames(skillsDir) {
|
|
46685
48168
|
return OLEANDER_SKILL_NAMES.filter(
|
|
46686
|
-
(name) => skillPresent((0,
|
|
48169
|
+
(name) => skillPresent((0, import_node_path9.join)(skillsDir, name))
|
|
46687
48170
|
);
|
|
46688
48171
|
}
|
|
46689
48172
|
function versionFromSkillsDir(skillsDir) {
|
|
46690
48173
|
for (const name of presentSkillNames(skillsDir)) {
|
|
46691
|
-
const version = readSkillVersion((0,
|
|
48174
|
+
const version = readSkillVersion((0, import_node_path9.join)(skillsDir, name));
|
|
46692
48175
|
if (version) {
|
|
46693
48176
|
return version;
|
|
46694
48177
|
}
|
|
@@ -46696,25 +48179,25 @@ function versionFromSkillsDir(skillsDir) {
|
|
|
46696
48179
|
return null;
|
|
46697
48180
|
}
|
|
46698
48181
|
function isInside(path2, dir) {
|
|
46699
|
-
const rel = (0,
|
|
46700
|
-
return rel === "" || !rel.startsWith("..") && !(0,
|
|
48182
|
+
const rel = (0, import_node_path9.relative)(dir, path2);
|
|
48183
|
+
return rel === "" || !rel.startsWith("..") && !(0, import_node_path9.isAbsolute)(rel);
|
|
46701
48184
|
}
|
|
46702
48185
|
function samePath(left2, right2) {
|
|
46703
48186
|
try {
|
|
46704
|
-
return (0,
|
|
48187
|
+
return (0, import_node_fs9.realpathSync)(left2) === (0, import_node_fs9.realpathSync)(right2);
|
|
46705
48188
|
} catch {
|
|
46706
|
-
return (0,
|
|
48189
|
+
return (0, import_node_path9.resolve)(left2) === (0, import_node_path9.resolve)(right2);
|
|
46707
48190
|
}
|
|
46708
48191
|
}
|
|
46709
48192
|
function findRealSkillSource(home, name, storeDir, agentRoots) {
|
|
46710
48193
|
for (const root of agentRoots) {
|
|
46711
|
-
const candidate = (0,
|
|
48194
|
+
const candidate = (0, import_node_path9.join)(home, root.relativeDir, name);
|
|
46712
48195
|
if (!skillPresent(candidate)) {
|
|
46713
48196
|
continue;
|
|
46714
48197
|
}
|
|
46715
48198
|
try {
|
|
46716
|
-
if ((0,
|
|
46717
|
-
const real = (0,
|
|
48199
|
+
if ((0, import_node_fs9.lstatSync)(candidate).isSymbolicLink()) {
|
|
48200
|
+
const real = (0, import_node_fs9.realpathSync)(candidate);
|
|
46718
48201
|
if (isInside(real, storeDir)) {
|
|
46719
48202
|
continue;
|
|
46720
48203
|
}
|
|
@@ -46728,46 +48211,46 @@ function findRealSkillSource(home, name, storeDir, agentRoots) {
|
|
|
46728
48211
|
continue;
|
|
46729
48212
|
}
|
|
46730
48213
|
}
|
|
46731
|
-
const stored = (0,
|
|
48214
|
+
const stored = (0, import_node_path9.join)(storeDir, name);
|
|
46732
48215
|
return skillPresent(stored) ? stored : null;
|
|
46733
48216
|
}
|
|
46734
48217
|
function ensureSymlink(linkPath, dest) {
|
|
46735
|
-
const resolvedDest = (0,
|
|
48218
|
+
const resolvedDest = (0, import_node_path9.resolve)(dest);
|
|
46736
48219
|
try {
|
|
46737
|
-
const stat2 = (0,
|
|
48220
|
+
const stat2 = (0, import_node_fs9.lstatSync)(linkPath);
|
|
46738
48221
|
if (stat2.isSymbolicLink()) {
|
|
46739
|
-
const current = (0,
|
|
48222
|
+
const current = (0, import_node_path9.resolve)((0, import_node_path9.dirname)(linkPath), (0, import_node_fs9.readlinkSync)(linkPath));
|
|
46740
48223
|
if (current === resolvedDest) {
|
|
46741
48224
|
return;
|
|
46742
48225
|
}
|
|
46743
|
-
(0,
|
|
48226
|
+
(0, import_node_fs9.unlinkSync)(linkPath);
|
|
46744
48227
|
} else {
|
|
46745
|
-
(0,
|
|
48228
|
+
(0, import_node_fs9.rmSync)(linkPath, { recursive: true, force: true });
|
|
46746
48229
|
}
|
|
46747
48230
|
} catch {
|
|
46748
48231
|
}
|
|
46749
|
-
(0,
|
|
48232
|
+
(0, import_node_fs9.symlinkSync)(resolvedDest, linkPath, "junction");
|
|
46750
48233
|
}
|
|
46751
48234
|
function syncOleanderSkillStore(homeDir, agentRoots = AGENT_SKILL_ROOTS) {
|
|
46752
48235
|
const storeDir = oleanderSkillsDir(homeDir);
|
|
46753
48236
|
for (const name of OLEANDER_SKILL_NAMES) {
|
|
46754
|
-
const dest = (0,
|
|
48237
|
+
const dest = (0, import_node_path9.join)(storeDir, name);
|
|
46755
48238
|
const source = findRealSkillSource(homeDir, name, storeDir, agentRoots);
|
|
46756
48239
|
if (!source) {
|
|
46757
48240
|
continue;
|
|
46758
48241
|
}
|
|
46759
|
-
(0,
|
|
48242
|
+
(0, import_node_fs9.mkdirSync)(storeDir, { recursive: true });
|
|
46760
48243
|
if (!samePath(source, dest)) {
|
|
46761
|
-
(0,
|
|
46762
|
-
(0,
|
|
48244
|
+
(0, import_node_fs9.rmSync)(dest, { recursive: true, force: true });
|
|
48245
|
+
(0, import_node_fs9.cpSync)(source, dest, { recursive: true, dereference: true });
|
|
46763
48246
|
}
|
|
46764
48247
|
}
|
|
46765
48248
|
for (const name of presentSkillNames(storeDir)) {
|
|
46766
|
-
const dest = (0,
|
|
48249
|
+
const dest = (0, import_node_path9.join)(storeDir, name);
|
|
46767
48250
|
for (const root of agentRoots) {
|
|
46768
|
-
const agentDir = (0,
|
|
46769
|
-
(0,
|
|
46770
|
-
ensureSymlink((0,
|
|
48251
|
+
const agentDir = (0, import_node_path9.join)(homeDir, root.relativeDir);
|
|
48252
|
+
(0, import_node_fs9.mkdirSync)(agentDir, { recursive: true });
|
|
48253
|
+
ensureSymlink((0, import_node_path9.join)(agentDir, name), dest);
|
|
46771
48254
|
}
|
|
46772
48255
|
}
|
|
46773
48256
|
}
|
|
@@ -46786,13 +48269,13 @@ function getSkillsStatus(options = {}) {
|
|
|
46786
48269
|
const agentRoots = options.agentRoots ?? AGENT_SKILL_ROOTS;
|
|
46787
48270
|
const storeNames = presentSkillNames(storeDir);
|
|
46788
48271
|
const agents = agentRoots.map((root) => {
|
|
46789
|
-
const path2 = (0,
|
|
48272
|
+
const path2 = (0, import_node_path9.join)(home, root.relativeDir);
|
|
46790
48273
|
const names = presentSkillNames(path2);
|
|
46791
48274
|
return {
|
|
46792
48275
|
label: root.label,
|
|
46793
48276
|
path: path2,
|
|
46794
48277
|
present: names.length > 0,
|
|
46795
|
-
symlinked: names.length > 0 && names.every((name) => isSymlink((0,
|
|
48278
|
+
symlinked: names.length > 0 && names.every((name) => isSymlink((0, import_node_path9.join)(path2, name)))
|
|
46796
48279
|
};
|
|
46797
48280
|
});
|
|
46798
48281
|
return {
|
|
@@ -47095,6 +48578,7 @@ registerSparkCommands(program2);
|
|
|
47095
48578
|
registerEnvCommands(program2);
|
|
47096
48579
|
registerCatalogCommands(program2);
|
|
47097
48580
|
registerQueriesCommands(program2);
|
|
48581
|
+
registerNotebooksCommands(program2);
|
|
47098
48582
|
registerSkillsCommands(program2);
|
|
47099
48583
|
registerUpgradeCommand(program2);
|
|
47100
48584
|
for (const command of program2.commands) {
|