oleander-cli 0.25.4 → 0.26.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 +56 -0
- package/dist/index.cjs +1210 -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 fs7 = 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 (fs7.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) => fs7.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 = fs7.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 join10(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 fs7 = (0, node_1.default)();
|
|
26375
26375
|
const handler = (err, buffer) => {
|
|
26376
26376
|
if (fd) {
|
|
26377
|
-
|
|
26377
|
+
fs7.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 = fs7.openSync(filepath, "r");
|
|
26390
26390
|
let sample = Buffer.allocUnsafe(sampleSize);
|
|
26391
|
-
|
|
26391
|
+
fs7.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
|
+
fs7.readFile(filepath, handler);
|
|
26404
26404
|
});
|
|
26405
26405
|
exports2.detectFile = detectFile;
|
|
26406
26406
|
var detectFileSync = (filepath, opts = {}) => {
|
|
26407
|
-
const
|
|
26407
|
+
const fs7 = (0, node_1.default)();
|
|
26408
26408
|
if (opts && opts.sampleSize) {
|
|
26409
|
-
const fd =
|
|
26409
|
+
const fd = fs7.openSync(filepath, "r");
|
|
26410
26410
|
let sample = Buffer.allocUnsafe(opts.sampleSize);
|
|
26411
|
-
const bytesRead =
|
|
26411
|
+
const bytesRead = fs7.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
|
+
fs7.closeSync(fd);
|
|
26416
26416
|
return (0, exports2.detect)(sample);
|
|
26417
26417
|
}
|
|
26418
|
-
return (0, exports2.detect)(
|
|
26418
|
+
return (0, exports2.detect)(fs7.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.26.0",
|
|
45779
45779
|
description: "oleander CLI",
|
|
45780
45780
|
keywords: [
|
|
45781
45781
|
"cli",
|
|
@@ -46617,11 +46617,1150 @@ 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_fs7 = require("fs");
|
|
46622
|
+
var import_node_path7 = 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/commands.ts
|
|
47318
|
+
function printJson2(value) {
|
|
47319
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}
|
|
47320
|
+
`);
|
|
47321
|
+
}
|
|
47322
|
+
async function loadClient() {
|
|
47323
|
+
try {
|
|
47324
|
+
const cfg = await config.load();
|
|
47325
|
+
if (!cfg.apiKey) throw new Error("No API key configured.");
|
|
47326
|
+
return new NotebooksClient(cfg.apiKey);
|
|
47327
|
+
} catch (error) {
|
|
47328
|
+
if (error instanceof Error) console.error(error.message);
|
|
47329
|
+
console.error(
|
|
47330
|
+
source_default.dim("Run ") + source_default.cyan("oleander configure --profile <name>") + source_default.dim(" to configure a profile")
|
|
47331
|
+
);
|
|
47332
|
+
process.exit(1);
|
|
47333
|
+
}
|
|
47334
|
+
}
|
|
47335
|
+
function startSpinner(json, text) {
|
|
47336
|
+
return json ? null : ora({ text, color: "cyan" }).start();
|
|
47337
|
+
}
|
|
47338
|
+
function exitWithError(spinner, error, fallback2) {
|
|
47339
|
+
const message = error instanceof Error ? error.message : fallback2;
|
|
47340
|
+
if (spinner) {
|
|
47341
|
+
spinner.fail(source_default.red(message));
|
|
47342
|
+
} else {
|
|
47343
|
+
console.error(message);
|
|
47344
|
+
}
|
|
47345
|
+
process.exit(1);
|
|
47346
|
+
}
|
|
47347
|
+
function displayPath(path2) {
|
|
47348
|
+
const rel = (0, import_node_path7.relative)(process.cwd(), path2);
|
|
47349
|
+
return rel && !rel.startsWith("..") ? rel : path2;
|
|
47350
|
+
}
|
|
47351
|
+
async function pullNotebookCommand(slug, options = {}) {
|
|
47352
|
+
const json = isJsonOutput(options.output);
|
|
47353
|
+
const client = await loadClient();
|
|
47354
|
+
const spinner = startSpinner(json, `Pulling ${slug}...`);
|
|
47355
|
+
try {
|
|
47356
|
+
const result = await pullNotebook(client, slug, process.cwd());
|
|
47357
|
+
if (json) {
|
|
47358
|
+
printJson2({ ...result, file: displayPath(result.file) });
|
|
47359
|
+
return;
|
|
47360
|
+
}
|
|
47361
|
+
spinner?.succeed(
|
|
47362
|
+
source_default.green(
|
|
47363
|
+
`Wrote ${displayPath(result.file)}${result.version !== null ? ` (version ${result.version})` : ""}`
|
|
47364
|
+
)
|
|
47365
|
+
);
|
|
47366
|
+
if (result.version === null) {
|
|
47367
|
+
console.log(
|
|
47368
|
+
source_default.yellow(
|
|
47369
|
+
"The server sent no version, so the next push will not check for concurrent edits."
|
|
47370
|
+
)
|
|
47371
|
+
);
|
|
47372
|
+
}
|
|
47373
|
+
} catch (error) {
|
|
47374
|
+
exitWithError(spinner, error, "Failed to pull notebook");
|
|
47375
|
+
}
|
|
47376
|
+
}
|
|
47377
|
+
async function pushNotebookCommand(file, options = {}) {
|
|
47378
|
+
const json = isJsonOutput(options.output);
|
|
47379
|
+
const client = await loadClient();
|
|
47380
|
+
let spinner = null;
|
|
47381
|
+
let printedPlanId = null;
|
|
47382
|
+
try {
|
|
47383
|
+
const notebook = await readNotebookFile(file);
|
|
47384
|
+
spinner = startSpinner(
|
|
47385
|
+
json,
|
|
47386
|
+
options.planId ? `Saving ${notebook.slug}...` : `Planning ${notebook.slug}...`
|
|
47387
|
+
);
|
|
47388
|
+
const outcome = await pushNotebook(client, notebook, {
|
|
47389
|
+
cwd: process.cwd(),
|
|
47390
|
+
run: options.run,
|
|
47391
|
+
planId: options.planId,
|
|
47392
|
+
onPlan: (plan) => {
|
|
47393
|
+
if (json || !spinner) return;
|
|
47394
|
+
spinner.stop();
|
|
47395
|
+
console.log(formatPlan(plan));
|
|
47396
|
+
console.log();
|
|
47397
|
+
printedPlanId = plan.plan_id;
|
|
47398
|
+
if (!plan.requires_approval) {
|
|
47399
|
+
spinner = startSpinner(json, `Saving ${notebook.slug}...`);
|
|
47400
|
+
}
|
|
47401
|
+
}
|
|
47402
|
+
});
|
|
47403
|
+
if (outcome.status !== "saved") {
|
|
47404
|
+
reportUnsaved(outcome, { file, json, spinner, printedPlanId, options });
|
|
47405
|
+
process.exit(1);
|
|
47406
|
+
}
|
|
47407
|
+
const { result } = outcome;
|
|
47408
|
+
let runDetail = null;
|
|
47409
|
+
let timedOut = false;
|
|
47410
|
+
if (!json) {
|
|
47411
|
+
spinner?.succeed(
|
|
47412
|
+
source_default.green(
|
|
47413
|
+
result.draft ? `Saved a draft of ${result.slug} (version ${result.version})` : `Saved ${result.slug} (version ${result.version})`
|
|
47414
|
+
)
|
|
47415
|
+
);
|
|
47416
|
+
console.log(source_default.dim(result.url));
|
|
47417
|
+
if (result.warnings.length) {
|
|
47418
|
+
console.log(source_default.yellow(formatSpecIssues(result.warnings)));
|
|
47419
|
+
}
|
|
47420
|
+
}
|
|
47421
|
+
if (options.run) {
|
|
47422
|
+
if (!result.run) {
|
|
47423
|
+
if (!json) console.log(source_default.yellow("The server did not start a run."));
|
|
47424
|
+
} else {
|
|
47425
|
+
spinner = startSpinner(json, `Running ${result.slug}...`);
|
|
47426
|
+
const waited = await waitForRun2(
|
|
47427
|
+
client,
|
|
47428
|
+
result.slug,
|
|
47429
|
+
result.run.run_id,
|
|
47430
|
+
{
|
|
47431
|
+
onPoll: (detail) => {
|
|
47432
|
+
if (spinner) {
|
|
47433
|
+
const done = detail.cells.filter(
|
|
47434
|
+
(cell) => cell.status !== "pending" && cell.status !== "running"
|
|
47435
|
+
).length;
|
|
47436
|
+
spinner.text = `Running ${result.slug}: ${done}/${detail.cells.length} cells`;
|
|
47437
|
+
}
|
|
47438
|
+
}
|
|
47439
|
+
}
|
|
47440
|
+
);
|
|
47441
|
+
runDetail = waited.detail;
|
|
47442
|
+
timedOut = waited.timedOut;
|
|
47443
|
+
spinner?.stop();
|
|
47444
|
+
}
|
|
47445
|
+
}
|
|
47446
|
+
if (json) {
|
|
47447
|
+
printJson2({ ...outcome, run: runDetail, timed_out: timedOut });
|
|
47448
|
+
} else {
|
|
47449
|
+
if (runDetail) {
|
|
47450
|
+
console.log();
|
|
47451
|
+
console.log(formatRunDetail(runDetail));
|
|
47452
|
+
if (timedOut) {
|
|
47453
|
+
console.log(
|
|
47454
|
+
source_default.yellow(
|
|
47455
|
+
`
|
|
47456
|
+
Still ${runDetail.run.status} after 10 minutes. Check it with oleander notebooks logs ${result.slug} ${runDetail.run.id}.`
|
|
47457
|
+
)
|
|
47458
|
+
);
|
|
47459
|
+
}
|
|
47460
|
+
}
|
|
47461
|
+
if (result.draft) {
|
|
47462
|
+
console.log();
|
|
47463
|
+
console.log(
|
|
47464
|
+
`${result.slug} is live, so this save is a draft: the published version, its schedule and outputs are unchanged.`
|
|
47465
|
+
);
|
|
47466
|
+
if (outcome.publish_plan) {
|
|
47467
|
+
console.log();
|
|
47468
|
+
console.log(formatPlan(outcome.publish_plan));
|
|
47469
|
+
}
|
|
47470
|
+
console.log();
|
|
47471
|
+
console.log(
|
|
47472
|
+
source_default.dim("Publish it with ") + source_default.cyan(
|
|
47473
|
+
publishGuidance(result.slug, outcome.publish_plan?.plan_id)
|
|
47474
|
+
)
|
|
47475
|
+
);
|
|
47476
|
+
}
|
|
47477
|
+
}
|
|
47478
|
+
if (runDetail && (timedOut || isFailedRun(runDetail))) process.exit(1);
|
|
47479
|
+
} catch (error) {
|
|
47480
|
+
exitWithError(spinner, error, "Failed to push notebook");
|
|
47481
|
+
}
|
|
47482
|
+
}
|
|
47483
|
+
function reportUnsaved(outcome, context) {
|
|
47484
|
+
const { json, spinner } = context;
|
|
47485
|
+
if (json) {
|
|
47486
|
+
printJson2(outcome);
|
|
47487
|
+
return;
|
|
47488
|
+
}
|
|
47489
|
+
switch (outcome.status) {
|
|
47490
|
+
case "invalid":
|
|
47491
|
+
spinner?.fail(source_default.red(`${outcome.slug} is not valid`));
|
|
47492
|
+
console.error(formatSpecIssues(outcome.errors));
|
|
47493
|
+
return;
|
|
47494
|
+
case "plan_required": {
|
|
47495
|
+
spinner?.stop();
|
|
47496
|
+
if (context.printedPlanId !== outcome.plan.plan_id) {
|
|
47497
|
+
console.log(formatPlan(outcome.plan));
|
|
47498
|
+
console.log();
|
|
47499
|
+
}
|
|
47500
|
+
const rerun = [
|
|
47501
|
+
"oleander notebooks push",
|
|
47502
|
+
context.file,
|
|
47503
|
+
context.options.run ? "--run" : "",
|
|
47504
|
+
`--plan-id ${outcome.plan.plan_id}`
|
|
47505
|
+
].filter(Boolean).join(" ");
|
|
47506
|
+
console.error(
|
|
47507
|
+
source_default.yellow(
|
|
47508
|
+
"Nothing was saved. This change adds outputs, a schedule, destinations or a budget, so it needs an approved plan."
|
|
47509
|
+
)
|
|
47510
|
+
);
|
|
47511
|
+
console.error(
|
|
47512
|
+
source_default.dim("Review the plan above, then run ") + source_default.cyan(rerun)
|
|
47513
|
+
);
|
|
47514
|
+
return;
|
|
47515
|
+
}
|
|
47516
|
+
case "conflict": {
|
|
47517
|
+
spinner?.fail(source_default.red(`${outcome.slug} changed on the server`));
|
|
47518
|
+
const since = outcome.base_version !== null ? ` since version ${outcome.base_version}` : "";
|
|
47519
|
+
const now = outcome.current_version !== null ? ` (now version ${outcome.current_version})` : "";
|
|
47520
|
+
console.error(`${outcome.message}`);
|
|
47521
|
+
console.error(
|
|
47522
|
+
`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.`
|
|
47523
|
+
);
|
|
47524
|
+
return;
|
|
47525
|
+
}
|
|
47526
|
+
}
|
|
47527
|
+
}
|
|
47528
|
+
async function planNotebookCommand(target, options = {}) {
|
|
47529
|
+
const json = isJsonOutput(options.output);
|
|
47530
|
+
const client = await loadClient();
|
|
47531
|
+
let spinner = null;
|
|
47532
|
+
try {
|
|
47533
|
+
let plan;
|
|
47534
|
+
if (options.publish) {
|
|
47535
|
+
const slug = (0, import_node_fs7.existsSync)(target) ? (await readNotebookFile(target)).slug : target;
|
|
47536
|
+
spinner = startSpinner(json, `Planning the publish of ${slug}...`);
|
|
47537
|
+
plan = await client.planPublish(slug);
|
|
47538
|
+
} else {
|
|
47539
|
+
const notebook = await readNotebookFile(target);
|
|
47540
|
+
spinner = startSpinner(json, `Planning ${notebook.slug}...`);
|
|
47541
|
+
const outcome = await planNotebook(client, notebook);
|
|
47542
|
+
if (outcome.status === "invalid") {
|
|
47543
|
+
if (json) {
|
|
47544
|
+
printJson2(outcome);
|
|
47545
|
+
} else {
|
|
47546
|
+
spinner?.fail(source_default.red(`${notebook.slug} is not valid`));
|
|
47547
|
+
console.error(formatSpecIssues(outcome.errors));
|
|
47548
|
+
}
|
|
47549
|
+
process.exit(1);
|
|
47550
|
+
}
|
|
47551
|
+
plan = outcome.plan;
|
|
47552
|
+
}
|
|
47553
|
+
spinner?.stop();
|
|
47554
|
+
if (json) {
|
|
47555
|
+
printJson2(plan);
|
|
47556
|
+
return;
|
|
47557
|
+
}
|
|
47558
|
+
console.log(formatPlan(plan));
|
|
47559
|
+
if (plan.kind === "publish") {
|
|
47560
|
+
console.log();
|
|
47561
|
+
console.log(
|
|
47562
|
+
source_default.dim("Publish it with ") + source_default.cyan(publishGuidance(plan.slug, plan.plan_id))
|
|
47563
|
+
);
|
|
47564
|
+
}
|
|
47565
|
+
} catch (error) {
|
|
47566
|
+
exitWithError(spinner, error, "Failed to plan notebook");
|
|
47567
|
+
}
|
|
47568
|
+
}
|
|
47569
|
+
async function publishNotebookCommand(slug, options) {
|
|
47570
|
+
const json = isJsonOutput(options.output);
|
|
47571
|
+
const client = await loadClient();
|
|
47572
|
+
const spinner = startSpinner(json, `Publishing ${slug}...`);
|
|
47573
|
+
try {
|
|
47574
|
+
const body = await client.publish(slug, options.plan);
|
|
47575
|
+
const version = typeof body?.version === "number" ? body.version : null;
|
|
47576
|
+
if (version !== null) {
|
|
47577
|
+
const versions = await readNotebookVersions(process.cwd());
|
|
47578
|
+
if (slug in versions) {
|
|
47579
|
+
await recordNotebookVersion(process.cwd(), slug, version);
|
|
47580
|
+
}
|
|
47581
|
+
}
|
|
47582
|
+
if (json) {
|
|
47583
|
+
printJson2(body);
|
|
47584
|
+
return;
|
|
47585
|
+
}
|
|
47586
|
+
spinner?.succeed(
|
|
47587
|
+
source_default.green(
|
|
47588
|
+
`Published ${slug}${version !== null ? ` (version ${version})` : ""}`
|
|
47589
|
+
)
|
|
47590
|
+
);
|
|
47591
|
+
} catch (error) {
|
|
47592
|
+
exitWithError(spinner, error, "Failed to publish notebook");
|
|
47593
|
+
}
|
|
47594
|
+
}
|
|
47595
|
+
async function listRunsCommand(slug, options = {}) {
|
|
47596
|
+
const json = isJsonOutput(options.output);
|
|
47597
|
+
const client = await loadClient();
|
|
47598
|
+
const spinner = startSpinner(json, `Loading runs of ${slug}...`);
|
|
47599
|
+
try {
|
|
47600
|
+
const runs = await client.listRuns(slug);
|
|
47601
|
+
if (json) {
|
|
47602
|
+
printJson2({ runs });
|
|
47603
|
+
return;
|
|
47604
|
+
}
|
|
47605
|
+
spinner?.stop();
|
|
47606
|
+
printTable(
|
|
47607
|
+
{ columns: RUN_COLUMNS, rows: runRows(runs) },
|
|
47608
|
+
{ emptyMessage: `${slug} has no runs yet` }
|
|
47609
|
+
);
|
|
47610
|
+
} catch (error) {
|
|
47611
|
+
exitWithError(spinner, error, "Failed to list runs");
|
|
47612
|
+
}
|
|
47613
|
+
}
|
|
47614
|
+
async function runLogsCommand(slug, runId, options = {}) {
|
|
47615
|
+
const json = isJsonOutput(options.output);
|
|
47616
|
+
const client = await loadClient();
|
|
47617
|
+
try {
|
|
47618
|
+
const lines = await collectLogs(client, slug, runId, {
|
|
47619
|
+
cellId: options.cell,
|
|
47620
|
+
onPage: json ? void 0 : (page) => {
|
|
47621
|
+
for (const line of page) console.log(formatLogLine(line));
|
|
47622
|
+
}
|
|
47623
|
+
});
|
|
47624
|
+
if (json) {
|
|
47625
|
+
printJson2({ lines });
|
|
47626
|
+
return;
|
|
47627
|
+
}
|
|
47628
|
+
if (!lines.length) console.log(source_default.dim("No log lines"));
|
|
47629
|
+
} catch (error) {
|
|
47630
|
+
exitWithError(null, error, "Failed to read logs");
|
|
47631
|
+
}
|
|
47632
|
+
}
|
|
47633
|
+
async function cancelRunCommand(slug, runId, options = {}) {
|
|
47634
|
+
const json = isJsonOutput(options.output);
|
|
47635
|
+
const client = await loadClient();
|
|
47636
|
+
const spinner = startSpinner(json, `Cancelling run ${runId}...`);
|
|
47637
|
+
try {
|
|
47638
|
+
const body = await client.cancelRun(slug, runId);
|
|
47639
|
+
if (json) {
|
|
47640
|
+
printJson2(body);
|
|
47641
|
+
return;
|
|
47642
|
+
}
|
|
47643
|
+
const status = typeof body?.status === "string" ? body.status : typeof body?.run?.status === "string" ? String(body.run.status) : null;
|
|
47644
|
+
spinner?.succeed(
|
|
47645
|
+
source_default.green(
|
|
47646
|
+
`Cancel requested for ${runId}${status ? ` (${status})` : ""}`
|
|
47647
|
+
)
|
|
47648
|
+
);
|
|
47649
|
+
} catch (error) {
|
|
47650
|
+
exitWithError(spinner, error, "Failed to cancel run");
|
|
47651
|
+
}
|
|
47652
|
+
}
|
|
47653
|
+
async function compareRunsCommand(slug, runA, runB, options = {}) {
|
|
47654
|
+
const json = isJsonOutput(options.output);
|
|
47655
|
+
const client = await loadClient();
|
|
47656
|
+
const spinner = startSpinner(json, `Comparing ${runA} and ${runB}...`);
|
|
47657
|
+
try {
|
|
47658
|
+
const compare = await client.compare(slug, runA, runB);
|
|
47659
|
+
if (json) {
|
|
47660
|
+
printJson2(compare);
|
|
47661
|
+
return;
|
|
47662
|
+
}
|
|
47663
|
+
spinner?.stop();
|
|
47664
|
+
console.log(formatCompare(compare));
|
|
47665
|
+
} catch (error) {
|
|
47666
|
+
exitWithError(spinner, error, "Failed to compare runs");
|
|
47667
|
+
}
|
|
47668
|
+
}
|
|
47669
|
+
async function backfillCommand(slug, options) {
|
|
47670
|
+
const json = isJsonOutput(options.output);
|
|
47671
|
+
const client = await loadClient();
|
|
47672
|
+
const { param, from: from3, to, planId } = options;
|
|
47673
|
+
const spinner = startSpinner(
|
|
47674
|
+
json,
|
|
47675
|
+
planId ? `Starting backfill of ${slug}...` : `Planning backfill of ${slug}...`
|
|
47676
|
+
);
|
|
47677
|
+
try {
|
|
47678
|
+
const body = await client.backfill(
|
|
47679
|
+
slug,
|
|
47680
|
+
planId ? { param, from: from3, to, plan_id: planId } : { param, from: from3, to, plan: true }
|
|
47681
|
+
);
|
|
47682
|
+
if (json) {
|
|
47683
|
+
printJson2(body);
|
|
47684
|
+
return;
|
|
47685
|
+
}
|
|
47686
|
+
spinner?.stop();
|
|
47687
|
+
if (!planId) {
|
|
47688
|
+
if (!body.plan) throw new Error("The server returned no plan.");
|
|
47689
|
+
console.log(formatPlan(body.plan));
|
|
47690
|
+
console.log();
|
|
47691
|
+
console.log(
|
|
47692
|
+
source_default.dim("Start it with ") + source_default.cyan(
|
|
47693
|
+
`oleander notebooks backfill ${slug} --param ${param} --from ${from3} --to ${to} --plan-id ${body.plan.plan_id}`
|
|
47694
|
+
)
|
|
47695
|
+
);
|
|
47696
|
+
return;
|
|
47697
|
+
}
|
|
47698
|
+
console.log(
|
|
47699
|
+
source_default.green(`Started backfill ${body.backfill_id ?? ""}`.trim())
|
|
47700
|
+
);
|
|
47701
|
+
const runs = (body.runs ?? []).map((run) => ({
|
|
47702
|
+
...run,
|
|
47703
|
+
id: run.id ?? run.run_id ?? ""
|
|
47704
|
+
}));
|
|
47705
|
+
printTable(
|
|
47706
|
+
{ columns: RUN_COLUMNS, rows: runRows(runs) },
|
|
47707
|
+
{ emptyMessage: "No runs started" }
|
|
47708
|
+
);
|
|
47709
|
+
} catch (error) {
|
|
47710
|
+
exitWithError(spinner, error, "Failed to backfill notebook");
|
|
47711
|
+
}
|
|
47712
|
+
}
|
|
47713
|
+
|
|
47714
|
+
// src/commands/notebooks/index.ts
|
|
47715
|
+
function registerNotebooksCommands(program3) {
|
|
47716
|
+
const notebooks = program3.command("notebooks").description("Edits, plans, runs and publishes notebooks as YAML files").addHelpText(
|
|
47717
|
+
"after",
|
|
47718
|
+
`
|
|
47719
|
+
pull writes <slug>.notebook.yaml exactly as saved and records its version in
|
|
47720
|
+
.oleander/notebooks.json; push sends that version as If-Match, so a save never
|
|
47721
|
+
overwrites someone else's edit. On a live notebook push saves a draft; publish
|
|
47722
|
+
it with the plan id push prints.
|
|
47723
|
+
|
|
47724
|
+
Examples:
|
|
47725
|
+
oleander notebooks pull bluehouse-morning
|
|
47726
|
+
oleander notebooks plan bluehouse-morning.notebook.yaml
|
|
47727
|
+
oleander notebooks push bluehouse-morning.notebook.yaml --run
|
|
47728
|
+
oleander notebooks publish bluehouse-morning --plan <plan_id>
|
|
47729
|
+
oleander notebooks logs bluehouse-morning <run_id> --cell posts_by_hour
|
|
47730
|
+
`
|
|
47731
|
+
);
|
|
47732
|
+
const pull = notebooks.command("pull").description("Write <slug>.notebook.yaml exactly as saved").argument("<slug>", "Notebook slug").action(pullNotebookCommand);
|
|
47733
|
+
addOutputOption(pull);
|
|
47734
|
+
const push = notebooks.command("push").description(
|
|
47735
|
+
"Plan and save a notebook YAML file (a draft, on a live notebook)"
|
|
47736
|
+
).argument("<file>", "Notebook YAML file").option("--run", "Run the notebook after saving and wait for the result").option(
|
|
47737
|
+
"--plan-id <id>",
|
|
47738
|
+
"Apply an approved plan (required when the change adds outputs, a schedule, destinations or a budget)"
|
|
47739
|
+
).action(pushNotebookCommand);
|
|
47740
|
+
addOutputOption(push);
|
|
47741
|
+
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);
|
|
47742
|
+
addOutputOption(plan);
|
|
47743
|
+
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);
|
|
47744
|
+
addOutputOption(publish2);
|
|
47745
|
+
const runs = notebooks.command("runs").description("List a notebook's runs, newest first").argument("<slug>", "Notebook slug").action(listRunsCommand);
|
|
47746
|
+
addOutputOption(runs);
|
|
47747
|
+
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);
|
|
47748
|
+
addOutputOption(logs);
|
|
47749
|
+
const cancel = notebooks.command("cancel").description("Cancel a queued or running run").argument("<slug>", "Notebook slug").argument("<run_id>", "Run id").action(cancelRunCommand);
|
|
47750
|
+
addOutputOption(cancel);
|
|
47751
|
+
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);
|
|
47752
|
+
addOutputOption(compare);
|
|
47753
|
+
const backfill = notebooks.command("backfill").description(
|
|
47754
|
+
"Run once per value of a date param (plans first without --plan-id)"
|
|
47755
|
+
).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);
|
|
47756
|
+
addOutputOption(backfill);
|
|
47757
|
+
}
|
|
47758
|
+
|
|
46620
47759
|
// src/utils/skills.ts
|
|
46621
47760
|
var import_node_child_process3 = require("child_process");
|
|
46622
47761
|
var import_node_os5 = require("os");
|
|
46623
|
-
var
|
|
46624
|
-
var
|
|
47762
|
+
var import_node_fs8 = require("fs");
|
|
47763
|
+
var import_node_path8 = require("path");
|
|
46625
47764
|
var SKILLS_REPO = "OleanderHQ/skills";
|
|
46626
47765
|
var OLEANDER_SKILLS_DIR = ".oleander/skills";
|
|
46627
47766
|
var OLEANDER_SKILL_NAMES = [
|
|
@@ -46654,12 +47793,12 @@ var SkillsInstallError = class extends Error {
|
|
|
46654
47793
|
}
|
|
46655
47794
|
};
|
|
46656
47795
|
function oleanderSkillsDir(homeDir = (0, import_node_os5.homedir)()) {
|
|
46657
|
-
return (0,
|
|
47796
|
+
return (0, import_node_path8.join)(homeDir, OLEANDER_SKILLS_DIR);
|
|
46658
47797
|
}
|
|
46659
47798
|
function readSkillVersion(skillDir) {
|
|
46660
47799
|
try {
|
|
46661
47800
|
const parsed = JSON.parse(
|
|
46662
|
-
(0,
|
|
47801
|
+
(0, import_node_fs8.readFileSync)((0, import_node_path8.join)(skillDir, "metadata.json"), "utf8")
|
|
46663
47802
|
);
|
|
46664
47803
|
return typeof parsed.version === "string" ? parsed.version : null;
|
|
46665
47804
|
} catch {
|
|
@@ -46668,7 +47807,7 @@ function readSkillVersion(skillDir) {
|
|
|
46668
47807
|
}
|
|
46669
47808
|
function skillPresent(skillDir) {
|
|
46670
47809
|
try {
|
|
46671
|
-
(0,
|
|
47810
|
+
(0, import_node_fs8.lstatSync)((0, import_node_path8.join)(skillDir, "SKILL.md"));
|
|
46672
47811
|
return true;
|
|
46673
47812
|
} catch {
|
|
46674
47813
|
return false;
|
|
@@ -46676,19 +47815,19 @@ function skillPresent(skillDir) {
|
|
|
46676
47815
|
}
|
|
46677
47816
|
function isSymlink(path2) {
|
|
46678
47817
|
try {
|
|
46679
|
-
return (0,
|
|
47818
|
+
return (0, import_node_fs8.lstatSync)(path2).isSymbolicLink();
|
|
46680
47819
|
} catch {
|
|
46681
47820
|
return false;
|
|
46682
47821
|
}
|
|
46683
47822
|
}
|
|
46684
47823
|
function presentSkillNames(skillsDir) {
|
|
46685
47824
|
return OLEANDER_SKILL_NAMES.filter(
|
|
46686
|
-
(name) => skillPresent((0,
|
|
47825
|
+
(name) => skillPresent((0, import_node_path8.join)(skillsDir, name))
|
|
46687
47826
|
);
|
|
46688
47827
|
}
|
|
46689
47828
|
function versionFromSkillsDir(skillsDir) {
|
|
46690
47829
|
for (const name of presentSkillNames(skillsDir)) {
|
|
46691
|
-
const version = readSkillVersion((0,
|
|
47830
|
+
const version = readSkillVersion((0, import_node_path8.join)(skillsDir, name));
|
|
46692
47831
|
if (version) {
|
|
46693
47832
|
return version;
|
|
46694
47833
|
}
|
|
@@ -46696,25 +47835,25 @@ function versionFromSkillsDir(skillsDir) {
|
|
|
46696
47835
|
return null;
|
|
46697
47836
|
}
|
|
46698
47837
|
function isInside(path2, dir) {
|
|
46699
|
-
const rel = (0,
|
|
46700
|
-
return rel === "" || !rel.startsWith("..") && !(0,
|
|
47838
|
+
const rel = (0, import_node_path8.relative)(dir, path2);
|
|
47839
|
+
return rel === "" || !rel.startsWith("..") && !(0, import_node_path8.isAbsolute)(rel);
|
|
46701
47840
|
}
|
|
46702
47841
|
function samePath(left2, right2) {
|
|
46703
47842
|
try {
|
|
46704
|
-
return (0,
|
|
47843
|
+
return (0, import_node_fs8.realpathSync)(left2) === (0, import_node_fs8.realpathSync)(right2);
|
|
46705
47844
|
} catch {
|
|
46706
|
-
return (0,
|
|
47845
|
+
return (0, import_node_path8.resolve)(left2) === (0, import_node_path8.resolve)(right2);
|
|
46707
47846
|
}
|
|
46708
47847
|
}
|
|
46709
47848
|
function findRealSkillSource(home, name, storeDir, agentRoots) {
|
|
46710
47849
|
for (const root of agentRoots) {
|
|
46711
|
-
const candidate = (0,
|
|
47850
|
+
const candidate = (0, import_node_path8.join)(home, root.relativeDir, name);
|
|
46712
47851
|
if (!skillPresent(candidate)) {
|
|
46713
47852
|
continue;
|
|
46714
47853
|
}
|
|
46715
47854
|
try {
|
|
46716
|
-
if ((0,
|
|
46717
|
-
const real = (0,
|
|
47855
|
+
if ((0, import_node_fs8.lstatSync)(candidate).isSymbolicLink()) {
|
|
47856
|
+
const real = (0, import_node_fs8.realpathSync)(candidate);
|
|
46718
47857
|
if (isInside(real, storeDir)) {
|
|
46719
47858
|
continue;
|
|
46720
47859
|
}
|
|
@@ -46728,46 +47867,46 @@ function findRealSkillSource(home, name, storeDir, agentRoots) {
|
|
|
46728
47867
|
continue;
|
|
46729
47868
|
}
|
|
46730
47869
|
}
|
|
46731
|
-
const stored = (0,
|
|
47870
|
+
const stored = (0, import_node_path8.join)(storeDir, name);
|
|
46732
47871
|
return skillPresent(stored) ? stored : null;
|
|
46733
47872
|
}
|
|
46734
47873
|
function ensureSymlink(linkPath, dest) {
|
|
46735
|
-
const resolvedDest = (0,
|
|
47874
|
+
const resolvedDest = (0, import_node_path8.resolve)(dest);
|
|
46736
47875
|
try {
|
|
46737
|
-
const stat2 = (0,
|
|
47876
|
+
const stat2 = (0, import_node_fs8.lstatSync)(linkPath);
|
|
46738
47877
|
if (stat2.isSymbolicLink()) {
|
|
46739
|
-
const current = (0,
|
|
47878
|
+
const current = (0, import_node_path8.resolve)((0, import_node_path8.dirname)(linkPath), (0, import_node_fs8.readlinkSync)(linkPath));
|
|
46740
47879
|
if (current === resolvedDest) {
|
|
46741
47880
|
return;
|
|
46742
47881
|
}
|
|
46743
|
-
(0,
|
|
47882
|
+
(0, import_node_fs8.unlinkSync)(linkPath);
|
|
46744
47883
|
} else {
|
|
46745
|
-
(0,
|
|
47884
|
+
(0, import_node_fs8.rmSync)(linkPath, { recursive: true, force: true });
|
|
46746
47885
|
}
|
|
46747
47886
|
} catch {
|
|
46748
47887
|
}
|
|
46749
|
-
(0,
|
|
47888
|
+
(0, import_node_fs8.symlinkSync)(resolvedDest, linkPath, "junction");
|
|
46750
47889
|
}
|
|
46751
47890
|
function syncOleanderSkillStore(homeDir, agentRoots = AGENT_SKILL_ROOTS) {
|
|
46752
47891
|
const storeDir = oleanderSkillsDir(homeDir);
|
|
46753
47892
|
for (const name of OLEANDER_SKILL_NAMES) {
|
|
46754
|
-
const dest = (0,
|
|
47893
|
+
const dest = (0, import_node_path8.join)(storeDir, name);
|
|
46755
47894
|
const source = findRealSkillSource(homeDir, name, storeDir, agentRoots);
|
|
46756
47895
|
if (!source) {
|
|
46757
47896
|
continue;
|
|
46758
47897
|
}
|
|
46759
|
-
(0,
|
|
47898
|
+
(0, import_node_fs8.mkdirSync)(storeDir, { recursive: true });
|
|
46760
47899
|
if (!samePath(source, dest)) {
|
|
46761
|
-
(0,
|
|
46762
|
-
(0,
|
|
47900
|
+
(0, import_node_fs8.rmSync)(dest, { recursive: true, force: true });
|
|
47901
|
+
(0, import_node_fs8.cpSync)(source, dest, { recursive: true, dereference: true });
|
|
46763
47902
|
}
|
|
46764
47903
|
}
|
|
46765
47904
|
for (const name of presentSkillNames(storeDir)) {
|
|
46766
|
-
const dest = (0,
|
|
47905
|
+
const dest = (0, import_node_path8.join)(storeDir, name);
|
|
46767
47906
|
for (const root of agentRoots) {
|
|
46768
|
-
const agentDir = (0,
|
|
46769
|
-
(0,
|
|
46770
|
-
ensureSymlink((0,
|
|
47907
|
+
const agentDir = (0, import_node_path8.join)(homeDir, root.relativeDir);
|
|
47908
|
+
(0, import_node_fs8.mkdirSync)(agentDir, { recursive: true });
|
|
47909
|
+
ensureSymlink((0, import_node_path8.join)(agentDir, name), dest);
|
|
46771
47910
|
}
|
|
46772
47911
|
}
|
|
46773
47912
|
}
|
|
@@ -46786,13 +47925,13 @@ function getSkillsStatus(options = {}) {
|
|
|
46786
47925
|
const agentRoots = options.agentRoots ?? AGENT_SKILL_ROOTS;
|
|
46787
47926
|
const storeNames = presentSkillNames(storeDir);
|
|
46788
47927
|
const agents = agentRoots.map((root) => {
|
|
46789
|
-
const path2 = (0,
|
|
47928
|
+
const path2 = (0, import_node_path8.join)(home, root.relativeDir);
|
|
46790
47929
|
const names = presentSkillNames(path2);
|
|
46791
47930
|
return {
|
|
46792
47931
|
label: root.label,
|
|
46793
47932
|
path: path2,
|
|
46794
47933
|
present: names.length > 0,
|
|
46795
|
-
symlinked: names.length > 0 && names.every((name) => isSymlink((0,
|
|
47934
|
+
symlinked: names.length > 0 && names.every((name) => isSymlink((0, import_node_path8.join)(path2, name)))
|
|
46796
47935
|
};
|
|
46797
47936
|
});
|
|
46798
47937
|
return {
|
|
@@ -47095,6 +48234,7 @@ registerSparkCommands(program2);
|
|
|
47095
48234
|
registerEnvCommands(program2);
|
|
47096
48235
|
registerCatalogCommands(program2);
|
|
47097
48236
|
registerQueriesCommands(program2);
|
|
48237
|
+
registerNotebooksCommands(program2);
|
|
47098
48238
|
registerSkillsCommands(program2);
|
|
47099
48239
|
registerUpgradeCommand(program2);
|
|
47100
48240
|
for (const command of program2.commands) {
|