oleander-cli 0.26.0 → 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 +18 -0
- package/dist/index.cjs +396 -52
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -359,6 +359,24 @@ oleander notebooks backfill bluehouse-morning --param day --from 2026-11-01 --to
|
|
|
359
359
|
`backfill` without `--plan-id` prints the plan and its cost estimate and starts
|
|
360
360
|
nothing. Every `notebooks` command takes `-o json`.
|
|
361
361
|
|
|
362
|
+
### Sync from a repository
|
|
363
|
+
|
|
364
|
+
`sync` saves every changed `*.notebook.yaml` under a path, so a repository can
|
|
365
|
+
own your notebooks:
|
|
366
|
+
|
|
367
|
+
```bash
|
|
368
|
+
oleander notebooks sync notebooks/ --dry-run # plan only
|
|
369
|
+
oleander notebooks sync notebooks/ --approve --publish # save and publish
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
`--approve` applies changes that add outputs, a schedule, destinations or a
|
|
373
|
+
budget. `--publish` publishes live notebooks' drafts. `--summary <file>` writes
|
|
374
|
+
a Markdown report. Deleted files are ignored.
|
|
375
|
+
|
|
376
|
+
In GitHub Actions, use
|
|
377
|
+
[OleanderHQ/sync-oleander-notebooks](https://github.com/OleanderHQ/sync-oleander-notebooks):
|
|
378
|
+
it plans on pull requests and syncs on merge.
|
|
379
|
+
|
|
362
380
|
## Guidance for coding agents
|
|
363
381
|
|
|
364
382
|
See [`AGENTS.md`](AGENTS.md) for command discovery, safe automation, and output-handling rules.
|
package/dist/index.cjs
CHANGED
|
@@ -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;
|
|
@@ -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 = {
|
|
@@ -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",
|
|
@@ -46618,8 +46618,8 @@ function registerQueriesCommands(program3) {
|
|
|
46618
46618
|
}
|
|
46619
46619
|
|
|
46620
46620
|
// src/commands/notebooks/commands.ts
|
|
46621
|
-
var
|
|
46622
|
-
var
|
|
46621
|
+
var import_node_fs8 = require("fs");
|
|
46622
|
+
var import_node_path8 = require("path");
|
|
46623
46623
|
|
|
46624
46624
|
// src/commands/notebooks/client.ts
|
|
46625
46625
|
var YAML_CONTENT_TYPE = "application/yaml";
|
|
@@ -47314,6 +47314,238 @@ function publishGuidance(slug, planId) {
|
|
|
47314
47314
|
return planId ? `oleander notebooks publish ${slug} --plan ${planId}` : `oleander notebooks plan ${slug} --publish, then oleander notebooks publish ${slug} --plan <plan_id>`;
|
|
47315
47315
|
}
|
|
47316
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
|
+
|
|
47317
47549
|
// src/commands/notebooks/commands.ts
|
|
47318
47550
|
function printJson2(value) {
|
|
47319
47551
|
process.stdout.write(`${JSON.stringify(value, null, 2)}
|
|
@@ -47345,7 +47577,7 @@ function exitWithError(spinner, error, fallback2) {
|
|
|
47345
47577
|
process.exit(1);
|
|
47346
47578
|
}
|
|
47347
47579
|
function displayPath(path2) {
|
|
47348
|
-
const rel = (0,
|
|
47580
|
+
const rel = (0, import_node_path8.relative)(process.cwd(), path2);
|
|
47349
47581
|
return rel && !rel.startsWith("..") ? rel : path2;
|
|
47350
47582
|
}
|
|
47351
47583
|
async function pullNotebookCommand(slug, options = {}) {
|
|
@@ -47532,7 +47764,7 @@ async function planNotebookCommand(target, options = {}) {
|
|
|
47532
47764
|
try {
|
|
47533
47765
|
let plan;
|
|
47534
47766
|
if (options.publish) {
|
|
47535
|
-
const slug = (0,
|
|
47767
|
+
const slug = (0, import_node_fs8.existsSync)(target) ? (await readNotebookFile(target)).slug : target;
|
|
47536
47768
|
spinner = startSpinner(json, `Planning the publish of ${slug}...`);
|
|
47537
47769
|
plan = await client.planPublish(slug);
|
|
47538
47770
|
} else {
|
|
@@ -47710,6 +47942,95 @@ async function backfillCommand(slug, options) {
|
|
|
47710
47942
|
exitWithError(spinner, error, "Failed to backfill notebook");
|
|
47711
47943
|
}
|
|
47712
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
|
+
}
|
|
47713
48034
|
|
|
47714
48035
|
// src/commands/notebooks/index.ts
|
|
47715
48036
|
function registerNotebooksCommands(program3) {
|
|
@@ -47738,6 +48059,29 @@ Examples:
|
|
|
47738
48059
|
"Apply an approved plan (required when the change adds outputs, a schedule, destinations or a budget)"
|
|
47739
48060
|
).action(pushNotebookCommand);
|
|
47740
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);
|
|
47741
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);
|
|
47742
48086
|
addOutputOption(plan);
|
|
47743
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);
|
|
@@ -47759,8 +48103,8 @@ Examples:
|
|
|
47759
48103
|
// src/utils/skills.ts
|
|
47760
48104
|
var import_node_child_process3 = require("child_process");
|
|
47761
48105
|
var import_node_os5 = require("os");
|
|
47762
|
-
var
|
|
47763
|
-
var
|
|
48106
|
+
var import_node_fs9 = require("fs");
|
|
48107
|
+
var import_node_path9 = require("path");
|
|
47764
48108
|
var SKILLS_REPO = "OleanderHQ/skills";
|
|
47765
48109
|
var OLEANDER_SKILLS_DIR = ".oleander/skills";
|
|
47766
48110
|
var OLEANDER_SKILL_NAMES = [
|
|
@@ -47793,12 +48137,12 @@ var SkillsInstallError = class extends Error {
|
|
|
47793
48137
|
}
|
|
47794
48138
|
};
|
|
47795
48139
|
function oleanderSkillsDir(homeDir = (0, import_node_os5.homedir)()) {
|
|
47796
|
-
return (0,
|
|
48140
|
+
return (0, import_node_path9.join)(homeDir, OLEANDER_SKILLS_DIR);
|
|
47797
48141
|
}
|
|
47798
48142
|
function readSkillVersion(skillDir) {
|
|
47799
48143
|
try {
|
|
47800
48144
|
const parsed = JSON.parse(
|
|
47801
|
-
(0,
|
|
48145
|
+
(0, import_node_fs9.readFileSync)((0, import_node_path9.join)(skillDir, "metadata.json"), "utf8")
|
|
47802
48146
|
);
|
|
47803
48147
|
return typeof parsed.version === "string" ? parsed.version : null;
|
|
47804
48148
|
} catch {
|
|
@@ -47807,7 +48151,7 @@ function readSkillVersion(skillDir) {
|
|
|
47807
48151
|
}
|
|
47808
48152
|
function skillPresent(skillDir) {
|
|
47809
48153
|
try {
|
|
47810
|
-
(0,
|
|
48154
|
+
(0, import_node_fs9.lstatSync)((0, import_node_path9.join)(skillDir, "SKILL.md"));
|
|
47811
48155
|
return true;
|
|
47812
48156
|
} catch {
|
|
47813
48157
|
return false;
|
|
@@ -47815,19 +48159,19 @@ function skillPresent(skillDir) {
|
|
|
47815
48159
|
}
|
|
47816
48160
|
function isSymlink(path2) {
|
|
47817
48161
|
try {
|
|
47818
|
-
return (0,
|
|
48162
|
+
return (0, import_node_fs9.lstatSync)(path2).isSymbolicLink();
|
|
47819
48163
|
} catch {
|
|
47820
48164
|
return false;
|
|
47821
48165
|
}
|
|
47822
48166
|
}
|
|
47823
48167
|
function presentSkillNames(skillsDir) {
|
|
47824
48168
|
return OLEANDER_SKILL_NAMES.filter(
|
|
47825
|
-
(name) => skillPresent((0,
|
|
48169
|
+
(name) => skillPresent((0, import_node_path9.join)(skillsDir, name))
|
|
47826
48170
|
);
|
|
47827
48171
|
}
|
|
47828
48172
|
function versionFromSkillsDir(skillsDir) {
|
|
47829
48173
|
for (const name of presentSkillNames(skillsDir)) {
|
|
47830
|
-
const version = readSkillVersion((0,
|
|
48174
|
+
const version = readSkillVersion((0, import_node_path9.join)(skillsDir, name));
|
|
47831
48175
|
if (version) {
|
|
47832
48176
|
return version;
|
|
47833
48177
|
}
|
|
@@ -47835,25 +48179,25 @@ function versionFromSkillsDir(skillsDir) {
|
|
|
47835
48179
|
return null;
|
|
47836
48180
|
}
|
|
47837
48181
|
function isInside(path2, dir) {
|
|
47838
|
-
const rel = (0,
|
|
47839
|
-
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);
|
|
47840
48184
|
}
|
|
47841
48185
|
function samePath(left2, right2) {
|
|
47842
48186
|
try {
|
|
47843
|
-
return (0,
|
|
48187
|
+
return (0, import_node_fs9.realpathSync)(left2) === (0, import_node_fs9.realpathSync)(right2);
|
|
47844
48188
|
} catch {
|
|
47845
|
-
return (0,
|
|
48189
|
+
return (0, import_node_path9.resolve)(left2) === (0, import_node_path9.resolve)(right2);
|
|
47846
48190
|
}
|
|
47847
48191
|
}
|
|
47848
48192
|
function findRealSkillSource(home, name, storeDir, agentRoots) {
|
|
47849
48193
|
for (const root of agentRoots) {
|
|
47850
|
-
const candidate = (0,
|
|
48194
|
+
const candidate = (0, import_node_path9.join)(home, root.relativeDir, name);
|
|
47851
48195
|
if (!skillPresent(candidate)) {
|
|
47852
48196
|
continue;
|
|
47853
48197
|
}
|
|
47854
48198
|
try {
|
|
47855
|
-
if ((0,
|
|
47856
|
-
const real = (0,
|
|
48199
|
+
if ((0, import_node_fs9.lstatSync)(candidate).isSymbolicLink()) {
|
|
48200
|
+
const real = (0, import_node_fs9.realpathSync)(candidate);
|
|
47857
48201
|
if (isInside(real, storeDir)) {
|
|
47858
48202
|
continue;
|
|
47859
48203
|
}
|
|
@@ -47867,46 +48211,46 @@ function findRealSkillSource(home, name, storeDir, agentRoots) {
|
|
|
47867
48211
|
continue;
|
|
47868
48212
|
}
|
|
47869
48213
|
}
|
|
47870
|
-
const stored = (0,
|
|
48214
|
+
const stored = (0, import_node_path9.join)(storeDir, name);
|
|
47871
48215
|
return skillPresent(stored) ? stored : null;
|
|
47872
48216
|
}
|
|
47873
48217
|
function ensureSymlink(linkPath, dest) {
|
|
47874
|
-
const resolvedDest = (0,
|
|
48218
|
+
const resolvedDest = (0, import_node_path9.resolve)(dest);
|
|
47875
48219
|
try {
|
|
47876
|
-
const stat2 = (0,
|
|
48220
|
+
const stat2 = (0, import_node_fs9.lstatSync)(linkPath);
|
|
47877
48221
|
if (stat2.isSymbolicLink()) {
|
|
47878
|
-
const current = (0,
|
|
48222
|
+
const current = (0, import_node_path9.resolve)((0, import_node_path9.dirname)(linkPath), (0, import_node_fs9.readlinkSync)(linkPath));
|
|
47879
48223
|
if (current === resolvedDest) {
|
|
47880
48224
|
return;
|
|
47881
48225
|
}
|
|
47882
|
-
(0,
|
|
48226
|
+
(0, import_node_fs9.unlinkSync)(linkPath);
|
|
47883
48227
|
} else {
|
|
47884
|
-
(0,
|
|
48228
|
+
(0, import_node_fs9.rmSync)(linkPath, { recursive: true, force: true });
|
|
47885
48229
|
}
|
|
47886
48230
|
} catch {
|
|
47887
48231
|
}
|
|
47888
|
-
(0,
|
|
48232
|
+
(0, import_node_fs9.symlinkSync)(resolvedDest, linkPath, "junction");
|
|
47889
48233
|
}
|
|
47890
48234
|
function syncOleanderSkillStore(homeDir, agentRoots = AGENT_SKILL_ROOTS) {
|
|
47891
48235
|
const storeDir = oleanderSkillsDir(homeDir);
|
|
47892
48236
|
for (const name of OLEANDER_SKILL_NAMES) {
|
|
47893
|
-
const dest = (0,
|
|
48237
|
+
const dest = (0, import_node_path9.join)(storeDir, name);
|
|
47894
48238
|
const source = findRealSkillSource(homeDir, name, storeDir, agentRoots);
|
|
47895
48239
|
if (!source) {
|
|
47896
48240
|
continue;
|
|
47897
48241
|
}
|
|
47898
|
-
(0,
|
|
48242
|
+
(0, import_node_fs9.mkdirSync)(storeDir, { recursive: true });
|
|
47899
48243
|
if (!samePath(source, dest)) {
|
|
47900
|
-
(0,
|
|
47901
|
-
(0,
|
|
48244
|
+
(0, import_node_fs9.rmSync)(dest, { recursive: true, force: true });
|
|
48245
|
+
(0, import_node_fs9.cpSync)(source, dest, { recursive: true, dereference: true });
|
|
47902
48246
|
}
|
|
47903
48247
|
}
|
|
47904
48248
|
for (const name of presentSkillNames(storeDir)) {
|
|
47905
|
-
const dest = (0,
|
|
48249
|
+
const dest = (0, import_node_path9.join)(storeDir, name);
|
|
47906
48250
|
for (const root of agentRoots) {
|
|
47907
|
-
const agentDir = (0,
|
|
47908
|
-
(0,
|
|
47909
|
-
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);
|
|
47910
48254
|
}
|
|
47911
48255
|
}
|
|
47912
48256
|
}
|
|
@@ -47925,13 +48269,13 @@ function getSkillsStatus(options = {}) {
|
|
|
47925
48269
|
const agentRoots = options.agentRoots ?? AGENT_SKILL_ROOTS;
|
|
47926
48270
|
const storeNames = presentSkillNames(storeDir);
|
|
47927
48271
|
const agents = agentRoots.map((root) => {
|
|
47928
|
-
const path2 = (0,
|
|
48272
|
+
const path2 = (0, import_node_path9.join)(home, root.relativeDir);
|
|
47929
48273
|
const names = presentSkillNames(path2);
|
|
47930
48274
|
return {
|
|
47931
48275
|
label: root.label,
|
|
47932
48276
|
path: path2,
|
|
47933
48277
|
present: names.length > 0,
|
|
47934
|
-
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)))
|
|
47935
48279
|
};
|
|
47936
48280
|
});
|
|
47937
48281
|
return {
|