oleander-cli 0.26.0 → 0.28.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.
Files changed (3) hide show
  1. package/README.md +22 -0
  2. package/dist/index.cjs +620 -67
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -313,7 +313,9 @@ Notebooks round-trip as YAML files, so you (or a coding agent) can edit one in
313
313
  your editor and review it in a pull request like any other code.
314
314
 
315
315
  ```bash
316
+ oleander notebooks list # every notebook you can see
316
317
  oleander notebooks pull bluehouse-morning # writes bluehouse-morning.notebook.yaml
318
+ oleander notebooks pull --all # one file per notebook
317
319
  oleander notebooks plan bluehouse-morning.notebook.yaml # what saving would change
318
320
  oleander notebooks push bluehouse-morning.notebook.yaml --run
319
321
  ```
@@ -359,6 +361,26 @@ oleander notebooks backfill bluehouse-morning --param day --from 2026-11-01 --to
359
361
  `backfill` without `--plan-id` prints the plan and its cost estimate and starts
360
362
  nothing. Every `notebooks` command takes `-o json`.
361
363
 
364
+ ### Sync from a repository
365
+
366
+ `sync` saves every changed `*.notebook.yaml` under a path, so a repository can
367
+ own your notebooks:
368
+
369
+ ```bash
370
+ oleander notebooks sync notebooks/ --dry-run # plan only
371
+ oleander notebooks sync notebooks/ --approve --publish # save and publish
372
+ ```
373
+
374
+ `--approve` applies changes that add outputs, a schedule, destinations or a
375
+ budget. `--publish` publishes live notebooks' drafts. `--summary <file>` writes
376
+ a Markdown report. A removed file leaves its notebook in oleander;
377
+ `--removed-since <git-ref> --delete` deletes it. Start a repository with
378
+ `oleander notebooks pull --all`.
379
+
380
+ In GitHub Actions, use
381
+ [OleanderHQ/sync-oleander-notebooks](https://github.com/OleanderHQ/sync-oleander-notebooks):
382
+ it plans on pull requests and syncs on merge.
383
+
362
384
  ## Guidance for coding agents
363
385
 
364
386
  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 fs7 = require("fs");
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 (fs7.existsSync(localBin)) return localBin;
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) => fs7.existsSync(`${localBin}${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 = fs7.realpathSync(this._scriptPath);
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 join10(s) {
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 fs7 = (0, node_1.default)();
26374
+ const fs9 = (0, node_1.default)();
26375
26375
  const handler = (err, buffer) => {
26376
26376
  if (fd) {
26377
- fs7.closeSync(fd);
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 = fs7.openSync(filepath, "r");
26389
+ fd = fs9.openSync(filepath, "r");
26390
26390
  let sample = Buffer.allocUnsafe(sampleSize);
26391
- fs7.read(fd, sample, 0, sampleSize, opts.offset, (err, bytesRead) => {
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
- fs7.readFile(filepath, handler);
26403
+ fs9.readFile(filepath, handler);
26404
26404
  });
26405
26405
  exports2.detectFile = detectFile;
26406
26406
  var detectFileSync = (filepath, opts = {}) => {
26407
- const fs7 = (0, node_1.default)();
26407
+ const fs9 = (0, node_1.default)();
26408
26408
  if (opts && opts.sampleSize) {
26409
- const fd = fs7.openSync(filepath, "r");
26409
+ const fd = fs9.openSync(filepath, "r");
26410
26410
  let sample = Buffer.allocUnsafe(opts.sampleSize);
26411
- const bytesRead = fs7.readSync(fd, sample, 0, opts.sampleSize, opts.offset);
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
- fs7.closeSync(fd);
26415
+ fs9.closeSync(fd);
26416
26416
  return (0, exports2.detect)(sample);
26417
26417
  }
26418
- return (0, exports2.detect)(fs7.readFileSync(filepath));
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.26.0",
45778
+ version: "0.28.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 import_node_fs7 = require("fs");
46622
- var import_node_path7 = require("path");
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";
@@ -46706,6 +46706,30 @@ var NotebooksClient = class {
46706
46706
  if (!response.ok) throw await failure(response, fallback2);
46707
46707
  return await readBody(response);
46708
46708
  }
46709
+ /** The notebooks the key's user can see. */
46710
+ async listNotebooks() {
46711
+ const body = await this.json(
46712
+ "GET",
46713
+ `${getEndpoint()}/api/v1/notebooks`,
46714
+ "Failed to list notebooks"
46715
+ );
46716
+ return body?.notebooks ?? [];
46717
+ }
46718
+ /**
46719
+ * Delete a notebook with its schedule, run history and result tables.
46720
+ * Resolves false when there was no such notebook.
46721
+ */
46722
+ async deleteNotebook(slug) {
46723
+ const response = await fetch(notebookUrl(slug), {
46724
+ method: "DELETE",
46725
+ headers: this.headers()
46726
+ });
46727
+ if (response.status === 404) return false;
46728
+ if (!response.ok) {
46729
+ throw await failure(response, "Failed to delete notebook");
46730
+ }
46731
+ return true;
46732
+ }
46709
46733
  /** The YAML exactly as saved, and the version it is. */
46710
46734
  async getYaml(slug) {
46711
46735
  const response = await fetch(notebookUrl(slug), {
@@ -47243,6 +47267,26 @@ function formatParams(params) {
47243
47267
  ([key, value]) => `${key}=${typeof value === "string" ? value : JSON.stringify(value)}`
47244
47268
  ).join(" ");
47245
47269
  }
47270
+ var NOTEBOOK_COLUMNS = [
47271
+ "slug",
47272
+ "title",
47273
+ "version",
47274
+ "state",
47275
+ "schedule",
47276
+ "last run",
47277
+ "updated"
47278
+ ];
47279
+ function notebookRows(notebooks) {
47280
+ return notebooks.map((notebook) => [
47281
+ notebook.slug,
47282
+ notebook.title,
47283
+ notebook.version,
47284
+ notebook.draft_version !== null ? `${notebook.live ? "live" : "not live"}, draft ${notebook.draft_version}` : notebook.live ? "live" : "not live",
47285
+ notebook.schedule ? formatSchedule(notebook.schedule) : "",
47286
+ notebook.latest_run ? `${notebook.latest_run.status} ${notebook.latest_run.created_at}` : "",
47287
+ notebook.updated_at
47288
+ ]);
47289
+ }
47246
47290
  var RUN_COLUMNS = [
47247
47291
  "id",
47248
47292
  "trigger",
@@ -47314,6 +47358,327 @@ function publishGuidance(slug, planId) {
47314
47358
  return planId ? `oleander notebooks publish ${slug} --plan ${planId}` : `oleander notebooks plan ${slug} --publish, then oleander notebooks publish ${slug} --plan <plan_id>`;
47315
47359
  }
47316
47360
 
47361
+ // src/commands/notebooks/sync.ts
47362
+ var import_node_child_process3 = require("child_process");
47363
+ var import_node_fs7 = require("fs");
47364
+ var import_node_path7 = require("path");
47365
+ var import_node_util2 = require("util");
47366
+ var NOTEBOOK_FILE_SUFFIX = ".notebook.yaml";
47367
+ var SKIPPED_DIRS = /* @__PURE__ */ new Set(["node_modules"]);
47368
+ async function findNotebookFiles(paths) {
47369
+ const found = /* @__PURE__ */ new Set();
47370
+ for (const path2 of paths) {
47371
+ let stat2;
47372
+ try {
47373
+ stat2 = await import_node_fs7.promises.stat(path2);
47374
+ } catch (error) {
47375
+ if (error.code === "ENOENT") {
47376
+ throw new Error(`Path not found: ${path2}`);
47377
+ }
47378
+ throw error;
47379
+ }
47380
+ if (stat2.isFile()) {
47381
+ found.add(path2);
47382
+ } else if (stat2.isDirectory()) {
47383
+ await walk(path2, found);
47384
+ }
47385
+ }
47386
+ return [...found].sort();
47387
+ }
47388
+ async function walk(dir, found) {
47389
+ const entries = await import_node_fs7.promises.readdir(dir, { withFileTypes: true });
47390
+ for (const entry of entries) {
47391
+ const path2 = (0, import_node_path7.join)(dir, entry.name);
47392
+ if (entry.isDirectory()) {
47393
+ if (entry.name.startsWith(".") || SKIPPED_DIRS.has(entry.name)) continue;
47394
+ await walk(path2, found);
47395
+ } else if (entry.isFile() && entry.name.endsWith(NOTEBOOK_FILE_SUFFIX)) {
47396
+ found.add(path2);
47397
+ }
47398
+ }
47399
+ }
47400
+ function duplicateSlugs(files) {
47401
+ const bySlug = /* @__PURE__ */ new Map();
47402
+ for (const file of files) {
47403
+ bySlug.set(file.slug, [...bySlug.get(file.slug) ?? [], file.path]);
47404
+ }
47405
+ return [...bySlug.entries()].filter(([, paths]) => paths.length > 1).map(([slug, paths]) => `${slug}: ${paths.join(", ")}`);
47406
+ }
47407
+ var FAILED = /* @__PURE__ */ new Set([
47408
+ "needs_approval",
47409
+ "invalid",
47410
+ "conflict",
47411
+ "error"
47412
+ ]);
47413
+ function isFailedSync(status) {
47414
+ return FAILED.has(status);
47415
+ }
47416
+ async function syncNotebook(client, file, options) {
47417
+ const result = {
47418
+ file: file.path,
47419
+ slug: file.slug,
47420
+ status: "error",
47421
+ plan: null,
47422
+ publish_plan: null,
47423
+ version: null,
47424
+ url: null,
47425
+ message: null,
47426
+ errors: []
47427
+ };
47428
+ try {
47429
+ const planned = await planNotebook(client, file);
47430
+ if (planned.status === "invalid") {
47431
+ return { ...result, status: "invalid", errors: planned.errors };
47432
+ }
47433
+ const plan = planned.plan;
47434
+ result.plan = plan;
47435
+ result.version = plan.creates ? null : plan.base_version;
47436
+ if (!plan.creates && !plan.diff.trim()) {
47437
+ return { ...result, status: "unchanged" };
47438
+ }
47439
+ if (options.dryRun) return { ...result, status: "planned" };
47440
+ const takesEffect = !plan.draft || options.publish;
47441
+ if (plan.requires_approval && takesEffect && !options.approve) {
47442
+ return {
47443
+ ...result,
47444
+ status: "needs_approval",
47445
+ message: "Adds outputs, a schedule, destinations or a budget. Rerun with --approve to apply it."
47446
+ };
47447
+ }
47448
+ const response = await client.putYaml(file.slug, file.yaml, {
47449
+ run: false,
47450
+ planId: plan.plan_id
47451
+ });
47452
+ const body = await readBody(response);
47453
+ if (response.status === 422) {
47454
+ const errors = specIssuesFromBody(body);
47455
+ return {
47456
+ ...result,
47457
+ status: "invalid",
47458
+ errors: errors.length ? errors : [
47459
+ {
47460
+ path: "",
47461
+ message: errorMessageFromBody(body, "Invalid notebook")
47462
+ }
47463
+ ]
47464
+ };
47465
+ }
47466
+ if (response.status === 409) {
47467
+ return {
47468
+ ...result,
47469
+ status: "conflict",
47470
+ message: errorMessageFromBody(
47471
+ body,
47472
+ "The notebook changed on the server while syncing"
47473
+ )
47474
+ };
47475
+ }
47476
+ if (!response.ok) {
47477
+ throw new NotebookApiError(
47478
+ response.status,
47479
+ errorMessageFromBody(
47480
+ body,
47481
+ `Failed to save notebook (HTTP ${response.status})`
47482
+ ),
47483
+ body
47484
+ );
47485
+ }
47486
+ const saved = body;
47487
+ result.version = saved.version;
47488
+ result.url = saved.url;
47489
+ await recordIfTracked(options.cwd, file.slug, saved.version);
47490
+ if (!saved.draft) {
47491
+ return { ...result, status: plan.creates ? "created" : "updated" };
47492
+ }
47493
+ if (!options.publish) return { ...result, status: "draft_saved" };
47494
+ const publishPlan = await client.planPublish(file.slug);
47495
+ result.publish_plan = publishPlan;
47496
+ if (publishPlan.requires_approval && !options.approve) {
47497
+ return {
47498
+ ...result,
47499
+ status: "needs_approval",
47500
+ message: "The draft is saved. Publishing it adds outputs, a schedule, destinations or a budget; rerun with --approve to publish it."
47501
+ };
47502
+ }
47503
+ const published = await client.publish(file.slug, publishPlan.plan_id);
47504
+ if (typeof published?.version === "number") {
47505
+ result.version = published.version;
47506
+ await recordIfTracked(options.cwd, file.slug, published.version);
47507
+ }
47508
+ if (typeof published?.url === "string") result.url = published.url;
47509
+ return { ...result, status: "published" };
47510
+ } catch (error) {
47511
+ return {
47512
+ ...result,
47513
+ status: "error",
47514
+ message: error instanceof Error ? error.message : String(error)
47515
+ };
47516
+ }
47517
+ }
47518
+ async function recordIfTracked(cwd, slug, version) {
47519
+ const versions = await readNotebookVersions(cwd);
47520
+ if (slug in versions) await recordNotebookVersion(cwd, slug, version);
47521
+ }
47522
+ var execFileAsync = (0, import_node_util2.promisify)(import_node_child_process3.execFile);
47523
+ async function git(cwd, args2) {
47524
+ try {
47525
+ const { stdout } = await execFileAsync("git", args2, {
47526
+ cwd,
47527
+ maxBuffer: 64 * 1024 * 1024
47528
+ });
47529
+ return stdout;
47530
+ } catch (error) {
47531
+ const stderr = error.stderr?.trim();
47532
+ const command = args2.find(
47533
+ (arg) => !arg.startsWith("-") && !arg.includes("=")
47534
+ );
47535
+ throw new Error(`git ${command} failed${stderr ? `: ${stderr}` : ""}`);
47536
+ }
47537
+ }
47538
+ async function findRemovedNotebooks(cwd, ref, paths, currentSlugs) {
47539
+ const out = await git(cwd, [
47540
+ "-c",
47541
+ "core.quotepath=off",
47542
+ "diff",
47543
+ "--name-only",
47544
+ "-z",
47545
+ "--diff-filter=D",
47546
+ "--find-renames",
47547
+ "--relative",
47548
+ ref,
47549
+ "--",
47550
+ ...paths
47551
+ ]);
47552
+ const removed = [];
47553
+ for (const path2 of out.split("\0")) {
47554
+ if (!path2.endsWith(NOTEBOOK_FILE_SUFFIX)) continue;
47555
+ const yaml = await git(cwd, ["show", `${ref}:./${path2}`]);
47556
+ const slug = readSlugFromYaml(yaml);
47557
+ if (!slug || currentSlugs.has(slug)) continue;
47558
+ if (removed.some((entry) => entry.slug === slug)) continue;
47559
+ removed.push({ path: path2, slug });
47560
+ }
47561
+ return removed.sort((a, b3) => a.path.localeCompare(b3.path));
47562
+ }
47563
+ function removedResult(removed, status, message) {
47564
+ return {
47565
+ file: removed.path,
47566
+ slug: removed.slug,
47567
+ status,
47568
+ plan: null,
47569
+ publish_plan: null,
47570
+ version: null,
47571
+ url: null,
47572
+ message,
47573
+ errors: []
47574
+ };
47575
+ }
47576
+ async function syncRemovedNotebook(client, removed, options) {
47577
+ if (!options.delete) {
47578
+ return removedResult(
47579
+ removed,
47580
+ "kept",
47581
+ "The notebook stays in oleander. Pass --delete to delete it."
47582
+ );
47583
+ }
47584
+ if (options.dryRun) {
47585
+ return removedResult(
47586
+ removed,
47587
+ "would_delete",
47588
+ "Deletes the notebook, its schedule, run history and result tables."
47589
+ );
47590
+ }
47591
+ try {
47592
+ const existed = await client.deleteNotebook(removed.slug);
47593
+ return removedResult(
47594
+ removed,
47595
+ "deleted",
47596
+ existed ? null : "It was already gone."
47597
+ );
47598
+ } catch (error) {
47599
+ return removedResult(
47600
+ removed,
47601
+ "error",
47602
+ error instanceof Error ? error.message : String(error)
47603
+ );
47604
+ }
47605
+ }
47606
+ var STATUS_TEXT = {
47607
+ unchanged: "unchanged",
47608
+ planned: "would change",
47609
+ created: "created",
47610
+ updated: "updated",
47611
+ draft_saved: "draft saved",
47612
+ published: "published",
47613
+ kept: "file removed",
47614
+ would_delete: "would delete",
47615
+ deleted: "deleted",
47616
+ needs_approval: "needs approval",
47617
+ invalid: "invalid",
47618
+ conflict: "conflict",
47619
+ error: "error"
47620
+ };
47621
+ function syncStatusText(status) {
47622
+ return STATUS_TEXT[status];
47623
+ }
47624
+ function planEffect(plan) {
47625
+ if (plan.creates) return "creates the notebook";
47626
+ if (plan.draft) return "saves a draft (the notebook is live)";
47627
+ return `updates version ${plan.base_version}`;
47628
+ }
47629
+ function syncDetail(result) {
47630
+ if (result.status === "invalid") return formatSpecIssues(result.errors);
47631
+ if (result.message) return result.message;
47632
+ if (result.status === "planned" && result.plan) {
47633
+ return [
47634
+ planEffect(result.plan),
47635
+ result.plan.requires_approval ? "needs --approve" : ""
47636
+ ].filter(Boolean).join(", ");
47637
+ }
47638
+ return result.url ?? "";
47639
+ }
47640
+ function mdCell(text) {
47641
+ return text.replace(/\|/g, "\\|").replace(/\r?\n/g, "<br>");
47642
+ }
47643
+ function formatSyncMarkdown(results, options) {
47644
+ const title = options.dryRun ? "oleander notebooks plan" : "oleander notebooks sync";
47645
+ const lines = [`### ${title}`, ""];
47646
+ if (!results.length) {
47647
+ lines.push("No `*.notebook.yaml` files found.", "");
47648
+ return lines.join("\n");
47649
+ }
47650
+ lines.push(
47651
+ "| Notebook | File | Result | Detail |",
47652
+ "| --- | --- | --- | --- |"
47653
+ );
47654
+ for (const result of results) {
47655
+ const file = (0, import_node_path7.relative)(options.cwd, result.file) || result.file;
47656
+ const detail = syncDetail(result);
47657
+ const link = result.url ? `[${result.slug}](${result.url})` : result.slug;
47658
+ lines.push(
47659
+ `| ${mdCell(link)} | \`${mdCell(file)}\` | ${syncStatusText(result.status)} | ${mdCell(
47660
+ detail === result.url ? "" : detail
47661
+ )} |`
47662
+ );
47663
+ }
47664
+ lines.push("");
47665
+ for (const result of results) {
47666
+ const diff = result.plan?.diff?.trim();
47667
+ if (!diff || result.status === "unchanged") continue;
47668
+ lines.push(
47669
+ `<details><summary>${result.slug}: ${result.plan ? planEffect(result.plan) : "diff"}</summary>`,
47670
+ "",
47671
+ "```diff",
47672
+ diff.replace(/```/g, "` ` `"),
47673
+ "```",
47674
+ "",
47675
+ "</details>",
47676
+ ""
47677
+ );
47678
+ }
47679
+ return lines.join("\n");
47680
+ }
47681
+
47317
47682
  // src/commands/notebooks/commands.ts
47318
47683
  function printJson2(value) {
47319
47684
  process.stdout.write(`${JSON.stringify(value, null, 2)}
@@ -47345,30 +47710,70 @@ function exitWithError(spinner, error, fallback2) {
47345
47710
  process.exit(1);
47346
47711
  }
47347
47712
  function displayPath(path2) {
47348
- const rel = (0, import_node_path7.relative)(process.cwd(), path2);
47713
+ const rel = (0, import_node_path8.relative)(process.cwd(), path2);
47349
47714
  return rel && !rel.startsWith("..") ? rel : path2;
47350
47715
  }
47351
- async function pullNotebookCommand(slug, options = {}) {
47716
+ async function listNotebooksCommand(options = {}) {
47352
47717
  const json = isJsonOutput(options.output);
47353
47718
  const client = await loadClient();
47354
- const spinner = startSpinner(json, `Pulling ${slug}...`);
47719
+ const spinner = startSpinner(json, "Loading notebooks...");
47355
47720
  try {
47356
- const result = await pullNotebook(client, slug, process.cwd());
47721
+ const notebooks = await client.listNotebooks();
47357
47722
  if (json) {
47358
- printJson2({ ...result, file: displayPath(result.file) });
47723
+ printJson2({ notebooks });
47359
47724
  return;
47360
47725
  }
47361
- spinner?.succeed(
47362
- source_default.green(
47363
- `Wrote ${displayPath(result.file)}${result.version !== null ? ` (version ${result.version})` : ""}`
47364
- )
47726
+ spinner?.stop();
47727
+ printTable(
47728
+ { columns: NOTEBOOK_COLUMNS, rows: notebookRows(notebooks) },
47729
+ { emptyMessage: "No notebooks yet" }
47365
47730
  );
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."
47731
+ } catch (error) {
47732
+ exitWithError(spinner, error, "Failed to list notebooks");
47733
+ }
47734
+ }
47735
+ async function pullNotebookCommand(slugs, options = {}) {
47736
+ const json = isJsonOutput(options.output);
47737
+ if (options.all ? slugs.length > 0 : slugs.length === 0) {
47738
+ console.error(
47739
+ options.all ? "Pass slugs or --all, not both." : "Pass one or more slugs, or --all."
47740
+ );
47741
+ process.exit(1);
47742
+ }
47743
+ const client = await loadClient();
47744
+ let spinner = null;
47745
+ try {
47746
+ let targets = slugs;
47747
+ if (options.all) {
47748
+ spinner = startSpinner(json, "Loading notebooks...");
47749
+ targets = (await client.listNotebooks()).map((notebook) => notebook.slug);
47750
+ spinner?.stop();
47751
+ }
47752
+ const results = [];
47753
+ for (const slug of targets) {
47754
+ spinner = startSpinner(json, `Pulling ${slug}...`);
47755
+ const result = await pullNotebook(client, slug, process.cwd());
47756
+ results.push({ ...result, file: displayPath(result.file) });
47757
+ spinner?.succeed(
47758
+ source_default.green(
47759
+ `Wrote ${displayPath(result.file)}${result.version !== null ? ` (version ${result.version})` : ""}`
47370
47760
  )
47371
47761
  );
47762
+ if (!json && result.version === null) {
47763
+ console.log(
47764
+ source_default.yellow(
47765
+ "The server sent no version, so the next push will not check for concurrent edits."
47766
+ )
47767
+ );
47768
+ }
47769
+ }
47770
+ spinner = null;
47771
+ if (json) {
47772
+ printJson2(
47773
+ !options.all && results.length === 1 ? results[0] : { pulled: results }
47774
+ );
47775
+ } else if (options.all && !results.length) {
47776
+ console.log(source_default.dim("No notebooks to pull"));
47372
47777
  }
47373
47778
  } catch (error) {
47374
47779
  exitWithError(spinner, error, "Failed to pull notebook");
@@ -47532,7 +47937,7 @@ async function planNotebookCommand(target, options = {}) {
47532
47937
  try {
47533
47938
  let plan;
47534
47939
  if (options.publish) {
47535
- const slug = (0, import_node_fs7.existsSync)(target) ? (await readNotebookFile(target)).slug : target;
47940
+ const slug = (0, import_node_fs8.existsSync)(target) ? (await readNotebookFile(target)).slug : target;
47536
47941
  spinner = startSpinner(json, `Planning the publish of ${slug}...`);
47537
47942
  plan = await client.planPublish(slug);
47538
47943
  } else {
@@ -47710,6 +48115,120 @@ async function backfillCommand(slug, options) {
47710
48115
  exitWithError(spinner, error, "Failed to backfill notebook");
47711
48116
  }
47712
48117
  }
48118
+ var SYNC_COLUMNS = ["notebook", "file", "result", "detail"];
48119
+ async function syncNotebooksCommand(paths, options = {}) {
48120
+ const json = isJsonOutput(options.output);
48121
+ const cwd = process.cwd();
48122
+ let spinner = null;
48123
+ try {
48124
+ const searchPaths = paths.length ? paths : ["."];
48125
+ const found = await findNotebookFiles(searchPaths);
48126
+ const files = await Promise.all(
48127
+ found.map(async (path2) => ({ path: path2, ...await readNotebookFile(path2) }))
48128
+ );
48129
+ const duplicates = duplicateSlugs(
48130
+ files.map((file) => ({ path: displayPath(file.path), slug: file.slug }))
48131
+ );
48132
+ if (duplicates.length) {
48133
+ throw new Error(
48134
+ `More than one file declares the same slug:
48135
+ ${duplicates.join("\n")}`
48136
+ );
48137
+ }
48138
+ if (options.delete && !options.removedSince) {
48139
+ throw new Error(
48140
+ "--delete needs --removed-since <ref> to know which files were removed."
48141
+ );
48142
+ }
48143
+ const removed = options.removedSince ? await findRemovedNotebooks(
48144
+ cwd,
48145
+ options.removedSince,
48146
+ searchPaths,
48147
+ new Set(files.map((file) => file.slug))
48148
+ ) : [];
48149
+ const results = [];
48150
+ if (files.length || removed.length) {
48151
+ const client = await loadClient();
48152
+ for (const file of files) {
48153
+ spinner = startSpinner(
48154
+ json,
48155
+ `${options.dryRun ? "Planning" : "Syncing"} ${file.slug}...`
48156
+ );
48157
+ const result = await syncNotebook(client, file, {
48158
+ cwd,
48159
+ dryRun: options.dryRun,
48160
+ approve: options.approve,
48161
+ publish: options.publish
48162
+ });
48163
+ spinner?.stop();
48164
+ spinner = null;
48165
+ results.push(result);
48166
+ if (!json && options.dryRun && result.plan && result.status === "planned") {
48167
+ console.log(formatPlan(result.plan));
48168
+ console.log();
48169
+ }
48170
+ }
48171
+ for (const entry of removed) {
48172
+ spinner = startSpinner(
48173
+ json,
48174
+ `${options.delete && !options.dryRun ? "Deleting" : "Checking"} ${entry.slug}...`
48175
+ );
48176
+ results.push(
48177
+ await syncRemovedNotebook(client, entry, {
48178
+ dryRun: options.dryRun,
48179
+ delete: options.delete
48180
+ })
48181
+ );
48182
+ spinner?.stop();
48183
+ spinner = null;
48184
+ }
48185
+ }
48186
+ if (options.summary) {
48187
+ await import_node_fs8.promises.appendFile(
48188
+ options.summary,
48189
+ `${formatSyncMarkdown(results, { dryRun: options.dryRun, cwd })}
48190
+ `,
48191
+ "utf8"
48192
+ );
48193
+ }
48194
+ const failed = results.filter((result) => isFailedSync(result.status));
48195
+ if (json) {
48196
+ printJson2({
48197
+ dry_run: !!options.dryRun,
48198
+ results: results.map((result) => ({
48199
+ ...result,
48200
+ file: displayPath(result.file)
48201
+ })),
48202
+ failed: failed.length
48203
+ });
48204
+ } else {
48205
+ printTable(
48206
+ {
48207
+ columns: SYNC_COLUMNS,
48208
+ rows: results.map((result) => [
48209
+ result.slug,
48210
+ displayPath(result.file),
48211
+ syncStatusText(result.status),
48212
+ syncDetail(result)
48213
+ ])
48214
+ },
48215
+ {
48216
+ emptyMessage: `No *.notebook.yaml files under ${searchPaths.join(", ")}`
48217
+ }
48218
+ );
48219
+ if (failed.length) {
48220
+ console.error(
48221
+ source_default.red(
48222
+ `${failed.length} of ${results.length} notebook${results.length === 1 ? "" : "s"} did not sync`
48223
+ )
48224
+ );
48225
+ }
48226
+ }
48227
+ if (failed.length) process.exit(1);
48228
+ } catch (error) {
48229
+ exitWithError(spinner, error, "Failed to sync notebooks");
48230
+ }
48231
+ }
47713
48232
 
47714
48233
  // src/commands/notebooks/index.ts
47715
48234
  function registerNotebooksCommands(program3) {
@@ -47722,6 +48241,7 @@ overwrites someone else's edit. On a live notebook push saves a draft; publish
47722
48241
  it with the plan id push prints.
47723
48242
 
47724
48243
  Examples:
48244
+ oleander notebooks list
47725
48245
  oleander notebooks pull bluehouse-morning
47726
48246
  oleander notebooks plan bluehouse-morning.notebook.yaml
47727
48247
  oleander notebooks push bluehouse-morning.notebook.yaml --run
@@ -47729,7 +48249,9 @@ Examples:
47729
48249
  oleander notebooks logs bluehouse-morning <run_id> --cell posts_by_hour
47730
48250
  `
47731
48251
  );
47732
- const pull = notebooks.command("pull").description("Write <slug>.notebook.yaml exactly as saved").argument("<slug>", "Notebook slug").action(pullNotebookCommand);
48252
+ const list = notebooks.command("list").description("List the organization's notebooks").action(listNotebooksCommand);
48253
+ addOutputOption(list);
48254
+ const pull = notebooks.command("pull").description("Write <slug>.notebook.yaml exactly as saved").argument("[slugs...]", "Notebook slugs").option("--all", "Pull every notebook").action(pullNotebookCommand);
47733
48255
  addOutputOption(pull);
47734
48256
  const push = notebooks.command("push").description(
47735
48257
  "Plan and save a notebook YAML file (a draft, on a live notebook)"
@@ -47738,6 +48260,37 @@ Examples:
47738
48260
  "Apply an approved plan (required when the change adds outputs, a schedule, destinations or a budget)"
47739
48261
  ).action(pushNotebookCommand);
47740
48262
  addOutputOption(push);
48263
+ const sync = notebooks.command("sync").description(
48264
+ "Plan and save every *.notebook.yaml under the given paths (for CI)"
48265
+ ).argument("[paths...]", "Files or directories to search", ["."]).option("--dry-run", "Plan every file and save nothing").option(
48266
+ "--approve",
48267
+ "Apply plans that add outputs, a schedule, destinations or a budget"
48268
+ ).option("--publish", "Publish the draft a save leaves on a live notebook").option(
48269
+ "--summary <file>",
48270
+ "Append a Markdown report, like $GITHUB_STEP_SUMMARY"
48271
+ ).option(
48272
+ "--removed-since <ref>",
48273
+ "Also report notebook files deleted since this git ref"
48274
+ ).option(
48275
+ "--delete",
48276
+ "Delete the notebooks of files removed since --removed-since, with their run history and result tables"
48277
+ ).addHelpText(
48278
+ "after",
48279
+ `
48280
+ The files are the source of truth: sync saves each changed file over what is on
48281
+ the server (a concurrent edit made between its plan and save fails with a
48282
+ conflict instead). Unchanged files are skipped. A notebook whose file is
48283
+ removed stays in oleander unless --removed-since finds the removal and --delete
48284
+ is passed. Exits 1 if any file is invalid, needs --approve, or fails to save or
48285
+ delete.
48286
+
48287
+ Examples:
48288
+ oleander notebooks sync notebooks/ --dry-run --summary "$GITHUB_STEP_SUMMARY"
48289
+ oleander notebooks sync notebooks/ --approve --publish
48290
+ oleander notebooks sync notebooks/ --removed-since HEAD~1 --delete
48291
+ `
48292
+ ).action(syncNotebooksCommand);
48293
+ addOutputOption(sync);
47741
48294
  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
48295
  addOutputOption(plan);
47743
48296
  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);
@@ -47757,10 +48310,10 @@ Examples:
47757
48310
  }
47758
48311
 
47759
48312
  // src/utils/skills.ts
47760
- var import_node_child_process3 = require("child_process");
48313
+ var import_node_child_process4 = require("child_process");
47761
48314
  var import_node_os5 = require("os");
47762
- var import_node_fs8 = require("fs");
47763
- var import_node_path8 = require("path");
48315
+ var import_node_fs9 = require("fs");
48316
+ var import_node_path9 = require("path");
47764
48317
  var SKILLS_REPO = "OleanderHQ/skills";
47765
48318
  var OLEANDER_SKILLS_DIR = ".oleander/skills";
47766
48319
  var OLEANDER_SKILL_NAMES = [
@@ -47793,12 +48346,12 @@ var SkillsInstallError = class extends Error {
47793
48346
  }
47794
48347
  };
47795
48348
  function oleanderSkillsDir(homeDir = (0, import_node_os5.homedir)()) {
47796
- return (0, import_node_path8.join)(homeDir, OLEANDER_SKILLS_DIR);
48349
+ return (0, import_node_path9.join)(homeDir, OLEANDER_SKILLS_DIR);
47797
48350
  }
47798
48351
  function readSkillVersion(skillDir) {
47799
48352
  try {
47800
48353
  const parsed = JSON.parse(
47801
- (0, import_node_fs8.readFileSync)((0, import_node_path8.join)(skillDir, "metadata.json"), "utf8")
48354
+ (0, import_node_fs9.readFileSync)((0, import_node_path9.join)(skillDir, "metadata.json"), "utf8")
47802
48355
  );
47803
48356
  return typeof parsed.version === "string" ? parsed.version : null;
47804
48357
  } catch {
@@ -47807,7 +48360,7 @@ function readSkillVersion(skillDir) {
47807
48360
  }
47808
48361
  function skillPresent(skillDir) {
47809
48362
  try {
47810
- (0, import_node_fs8.lstatSync)((0, import_node_path8.join)(skillDir, "SKILL.md"));
48363
+ (0, import_node_fs9.lstatSync)((0, import_node_path9.join)(skillDir, "SKILL.md"));
47811
48364
  return true;
47812
48365
  } catch {
47813
48366
  return false;
@@ -47815,19 +48368,19 @@ function skillPresent(skillDir) {
47815
48368
  }
47816
48369
  function isSymlink(path2) {
47817
48370
  try {
47818
- return (0, import_node_fs8.lstatSync)(path2).isSymbolicLink();
48371
+ return (0, import_node_fs9.lstatSync)(path2).isSymbolicLink();
47819
48372
  } catch {
47820
48373
  return false;
47821
48374
  }
47822
48375
  }
47823
48376
  function presentSkillNames(skillsDir) {
47824
48377
  return OLEANDER_SKILL_NAMES.filter(
47825
- (name) => skillPresent((0, import_node_path8.join)(skillsDir, name))
48378
+ (name) => skillPresent((0, import_node_path9.join)(skillsDir, name))
47826
48379
  );
47827
48380
  }
47828
48381
  function versionFromSkillsDir(skillsDir) {
47829
48382
  for (const name of presentSkillNames(skillsDir)) {
47830
- const version = readSkillVersion((0, import_node_path8.join)(skillsDir, name));
48383
+ const version = readSkillVersion((0, import_node_path9.join)(skillsDir, name));
47831
48384
  if (version) {
47832
48385
  return version;
47833
48386
  }
@@ -47835,25 +48388,25 @@ function versionFromSkillsDir(skillsDir) {
47835
48388
  return null;
47836
48389
  }
47837
48390
  function isInside(path2, dir) {
47838
- const rel = (0, import_node_path8.relative)(dir, path2);
47839
- return rel === "" || !rel.startsWith("..") && !(0, import_node_path8.isAbsolute)(rel);
48391
+ const rel = (0, import_node_path9.relative)(dir, path2);
48392
+ return rel === "" || !rel.startsWith("..") && !(0, import_node_path9.isAbsolute)(rel);
47840
48393
  }
47841
48394
  function samePath(left2, right2) {
47842
48395
  try {
47843
- return (0, import_node_fs8.realpathSync)(left2) === (0, import_node_fs8.realpathSync)(right2);
48396
+ return (0, import_node_fs9.realpathSync)(left2) === (0, import_node_fs9.realpathSync)(right2);
47844
48397
  } catch {
47845
- return (0, import_node_path8.resolve)(left2) === (0, import_node_path8.resolve)(right2);
48398
+ return (0, import_node_path9.resolve)(left2) === (0, import_node_path9.resolve)(right2);
47846
48399
  }
47847
48400
  }
47848
48401
  function findRealSkillSource(home, name, storeDir, agentRoots) {
47849
48402
  for (const root of agentRoots) {
47850
- const candidate = (0, import_node_path8.join)(home, root.relativeDir, name);
48403
+ const candidate = (0, import_node_path9.join)(home, root.relativeDir, name);
47851
48404
  if (!skillPresent(candidate)) {
47852
48405
  continue;
47853
48406
  }
47854
48407
  try {
47855
- if ((0, import_node_fs8.lstatSync)(candidate).isSymbolicLink()) {
47856
- const real = (0, import_node_fs8.realpathSync)(candidate);
48408
+ if ((0, import_node_fs9.lstatSync)(candidate).isSymbolicLink()) {
48409
+ const real = (0, import_node_fs9.realpathSync)(candidate);
47857
48410
  if (isInside(real, storeDir)) {
47858
48411
  continue;
47859
48412
  }
@@ -47867,46 +48420,46 @@ function findRealSkillSource(home, name, storeDir, agentRoots) {
47867
48420
  continue;
47868
48421
  }
47869
48422
  }
47870
- const stored = (0, import_node_path8.join)(storeDir, name);
48423
+ const stored = (0, import_node_path9.join)(storeDir, name);
47871
48424
  return skillPresent(stored) ? stored : null;
47872
48425
  }
47873
48426
  function ensureSymlink(linkPath, dest) {
47874
- const resolvedDest = (0, import_node_path8.resolve)(dest);
48427
+ const resolvedDest = (0, import_node_path9.resolve)(dest);
47875
48428
  try {
47876
- const stat2 = (0, import_node_fs8.lstatSync)(linkPath);
48429
+ const stat2 = (0, import_node_fs9.lstatSync)(linkPath);
47877
48430
  if (stat2.isSymbolicLink()) {
47878
- const current = (0, import_node_path8.resolve)((0, import_node_path8.dirname)(linkPath), (0, import_node_fs8.readlinkSync)(linkPath));
48431
+ const current = (0, import_node_path9.resolve)((0, import_node_path9.dirname)(linkPath), (0, import_node_fs9.readlinkSync)(linkPath));
47879
48432
  if (current === resolvedDest) {
47880
48433
  return;
47881
48434
  }
47882
- (0, import_node_fs8.unlinkSync)(linkPath);
48435
+ (0, import_node_fs9.unlinkSync)(linkPath);
47883
48436
  } else {
47884
- (0, import_node_fs8.rmSync)(linkPath, { recursive: true, force: true });
48437
+ (0, import_node_fs9.rmSync)(linkPath, { recursive: true, force: true });
47885
48438
  }
47886
48439
  } catch {
47887
48440
  }
47888
- (0, import_node_fs8.symlinkSync)(resolvedDest, linkPath, "junction");
48441
+ (0, import_node_fs9.symlinkSync)(resolvedDest, linkPath, "junction");
47889
48442
  }
47890
48443
  function syncOleanderSkillStore(homeDir, agentRoots = AGENT_SKILL_ROOTS) {
47891
48444
  const storeDir = oleanderSkillsDir(homeDir);
47892
48445
  for (const name of OLEANDER_SKILL_NAMES) {
47893
- const dest = (0, import_node_path8.join)(storeDir, name);
48446
+ const dest = (0, import_node_path9.join)(storeDir, name);
47894
48447
  const source = findRealSkillSource(homeDir, name, storeDir, agentRoots);
47895
48448
  if (!source) {
47896
48449
  continue;
47897
48450
  }
47898
- (0, import_node_fs8.mkdirSync)(storeDir, { recursive: true });
48451
+ (0, import_node_fs9.mkdirSync)(storeDir, { recursive: true });
47899
48452
  if (!samePath(source, dest)) {
47900
- (0, import_node_fs8.rmSync)(dest, { recursive: true, force: true });
47901
- (0, import_node_fs8.cpSync)(source, dest, { recursive: true, dereference: true });
48453
+ (0, import_node_fs9.rmSync)(dest, { recursive: true, force: true });
48454
+ (0, import_node_fs9.cpSync)(source, dest, { recursive: true, dereference: true });
47902
48455
  }
47903
48456
  }
47904
48457
  for (const name of presentSkillNames(storeDir)) {
47905
- const dest = (0, import_node_path8.join)(storeDir, name);
48458
+ const dest = (0, import_node_path9.join)(storeDir, name);
47906
48459
  for (const root of agentRoots) {
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);
48460
+ const agentDir = (0, import_node_path9.join)(homeDir, root.relativeDir);
48461
+ (0, import_node_fs9.mkdirSync)(agentDir, { recursive: true });
48462
+ ensureSymlink((0, import_node_path9.join)(agentDir, name), dest);
47910
48463
  }
47911
48464
  }
47912
48465
  }
@@ -47925,13 +48478,13 @@ function getSkillsStatus(options = {}) {
47925
48478
  const agentRoots = options.agentRoots ?? AGENT_SKILL_ROOTS;
47926
48479
  const storeNames = presentSkillNames(storeDir);
47927
48480
  const agents = agentRoots.map((root) => {
47928
- const path2 = (0, import_node_path8.join)(home, root.relativeDir);
48481
+ const path2 = (0, import_node_path9.join)(home, root.relativeDir);
47929
48482
  const names = presentSkillNames(path2);
47930
48483
  return {
47931
48484
  label: root.label,
47932
48485
  path: path2,
47933
48486
  present: names.length > 0,
47934
- symlinked: names.length > 0 && names.every((name) => isSymlink((0, import_node_path8.join)(path2, name)))
48487
+ symlinked: names.length > 0 && names.every((name) => isSymlink((0, import_node_path9.join)(path2, name)))
47935
48488
  };
47936
48489
  });
47937
48490
  return {
@@ -47943,7 +48496,7 @@ function getSkillsStatus(options = {}) {
47943
48496
  };
47944
48497
  }
47945
48498
  function installSkills(options = {}) {
47946
- const spawn3 = options.spawn ?? ((command, args2, spawnOptions) => (0, import_node_child_process3.spawnSync)(command, args2, spawnOptions));
48499
+ const spawn3 = options.spawn ?? ((command, args2, spawnOptions) => (0, import_node_child_process4.spawnSync)(command, args2, spawnOptions));
47947
48500
  const home = options.homeDir ?? (0, import_node_os5.homedir)();
47948
48501
  const agentRoots = options.agentRoots ?? AGENT_SKILL_ROOTS;
47949
48502
  const env2 = options.homeDir ? { ...process.env, HOME: options.homeDir } : process.env;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oleander-cli",
3
- "version": "0.26.0",
3
+ "version": "0.28.0",
4
4
  "description": "oleander CLI",
5
5
  "keywords": [
6
6
  "cli",