oleander-cli 0.27.0 → 0.29.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 +12 -1
- package/dist/index.cjs +353 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -103,6 +103,13 @@ oleander spark jobs submit entrypoint.py \
|
|
|
103
103
|
|
|
104
104
|
## Profiles
|
|
105
105
|
|
|
106
|
+
```bash
|
|
107
|
+
oleander login
|
|
108
|
+
oleander login --profile acme
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`oleander login` opens your browser to approve the sign-in, then saves an API key for the organization you approved it in. Use `--no-browser` on a remote machine to print the link instead. To paste a key yourself, use `oleander configure`:
|
|
112
|
+
|
|
106
113
|
```bash
|
|
107
114
|
oleander configure --profile acme
|
|
108
115
|
oleander configure --profile sandbox
|
|
@@ -313,7 +320,9 @@ Notebooks round-trip as YAML files, so you (or a coding agent) can edit one in
|
|
|
313
320
|
your editor and review it in a pull request like any other code.
|
|
314
321
|
|
|
315
322
|
```bash
|
|
323
|
+
oleander notebooks list # every notebook you can see
|
|
316
324
|
oleander notebooks pull bluehouse-morning # writes bluehouse-morning.notebook.yaml
|
|
325
|
+
oleander notebooks pull --all # one file per notebook
|
|
317
326
|
oleander notebooks plan bluehouse-morning.notebook.yaml # what saving would change
|
|
318
327
|
oleander notebooks push bluehouse-morning.notebook.yaml --run
|
|
319
328
|
```
|
|
@@ -371,7 +380,9 @@ oleander notebooks sync notebooks/ --approve --publish # save and publish
|
|
|
371
380
|
|
|
372
381
|
`--approve` applies changes that add outputs, a schedule, destinations or a
|
|
373
382
|
budget. `--publish` publishes live notebooks' drafts. `--summary <file>` writes
|
|
374
|
-
a Markdown report.
|
|
383
|
+
a Markdown report. A removed file leaves its notebook in oleander;
|
|
384
|
+
`--removed-since <git-ref> --delete` deletes it. Start a repository with
|
|
385
|
+
`oleander notebooks pull --all`.
|
|
375
386
|
|
|
376
387
|
In GitHub Actions, use
|
|
377
388
|
[OleanderHQ/sync-oleander-notebooks](https://github.com/OleanderHQ/sync-oleander-notebooks):
|
package/dist/index.cjs
CHANGED
|
@@ -33207,7 +33207,7 @@ function currentOrganizationSelector() {
|
|
|
33207
33207
|
return organizationOverride ?? envOrganization();
|
|
33208
33208
|
}
|
|
33209
33209
|
function applyCommandProfile(actionCommand) {
|
|
33210
|
-
if (actionCommand.name()
|
|
33210
|
+
if (["configure", "login"].includes(actionCommand.name())) {
|
|
33211
33211
|
return;
|
|
33212
33212
|
}
|
|
33213
33213
|
const profile = actionCommand.optsWithGlobals().profile;
|
|
@@ -45388,7 +45388,7 @@ async function polarsCommand(query, options) {
|
|
|
45388
45388
|
printRowOutput(result.results, options.output);
|
|
45389
45389
|
return;
|
|
45390
45390
|
}
|
|
45391
|
-
const where = result.compute?.distributed ? `Polars Cloud (${result.compute.instanceType ?? "?"} x${result.compute.clusterSize ?? "?"})` : "
|
|
45391
|
+
const where = result.compute?.distributed ? `Polars Cloud (${result.compute.instanceType ?? "?"} x${result.compute.clusterSize ?? "?"})` : "oleander compute";
|
|
45392
45392
|
spinner?.succeed(
|
|
45393
45393
|
source_default.green(
|
|
45394
45394
|
`Polars run complete on ${where}${result.execution_time ? ` (${result.execution_time})` : ""}`
|
|
@@ -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.29.0",
|
|
45779
45779
|
description: "oleander CLI",
|
|
45780
45780
|
keywords: [
|
|
45781
45781
|
"cli",
|
|
@@ -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), {
|
|
@@ -46980,7 +47004,7 @@ var defaultSleep = (ms) => new Promise((resolve4) => setTimeout(resolve4, ms));
|
|
|
46980
47004
|
async function waitForRun2(client, slug, runId, options = {}) {
|
|
46981
47005
|
const interval = options.intervalMs ?? RUN_POLL_INTERVAL_MS;
|
|
46982
47006
|
const timeout = options.timeoutMs ?? RUN_WAIT_TIMEOUT_MS;
|
|
46983
|
-
const
|
|
47007
|
+
const sleep2 = options.sleep ?? defaultSleep;
|
|
46984
47008
|
const now = options.now ?? Date.now;
|
|
46985
47009
|
const deadline = now() + timeout;
|
|
46986
47010
|
for (; ; ) {
|
|
@@ -46990,7 +47014,7 @@ async function waitForRun2(client, slug, runId, options = {}) {
|
|
|
46990
47014
|
return { detail, timedOut: false };
|
|
46991
47015
|
}
|
|
46992
47016
|
if (now() + interval > deadline) return { detail, timedOut: true };
|
|
46993
|
-
await
|
|
47017
|
+
await sleep2(interval);
|
|
46994
47018
|
}
|
|
46995
47019
|
}
|
|
46996
47020
|
function isFailedRun(detail) {
|
|
@@ -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",
|
|
@@ -47315,8 +47359,10 @@ function publishGuidance(slug, planId) {
|
|
|
47315
47359
|
}
|
|
47316
47360
|
|
|
47317
47361
|
// src/commands/notebooks/sync.ts
|
|
47362
|
+
var import_node_child_process3 = require("child_process");
|
|
47318
47363
|
var import_node_fs7 = require("fs");
|
|
47319
47364
|
var import_node_path7 = require("path");
|
|
47365
|
+
var import_node_util2 = require("util");
|
|
47320
47366
|
var NOTEBOOK_FILE_SUFFIX = ".notebook.yaml";
|
|
47321
47367
|
var SKIPPED_DIRS = /* @__PURE__ */ new Set(["node_modules"]);
|
|
47322
47368
|
async function findNotebookFiles(paths) {
|
|
@@ -47473,6 +47519,90 @@ async function recordIfTracked(cwd, slug, version) {
|
|
|
47473
47519
|
const versions = await readNotebookVersions(cwd);
|
|
47474
47520
|
if (slug in versions) await recordNotebookVersion(cwd, slug, version);
|
|
47475
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
|
+
}
|
|
47476
47606
|
var STATUS_TEXT = {
|
|
47477
47607
|
unchanged: "unchanged",
|
|
47478
47608
|
planned: "would change",
|
|
@@ -47480,6 +47610,9 @@ var STATUS_TEXT = {
|
|
|
47480
47610
|
updated: "updated",
|
|
47481
47611
|
draft_saved: "draft saved",
|
|
47482
47612
|
published: "published",
|
|
47613
|
+
kept: "file removed",
|
|
47614
|
+
would_delete: "would delete",
|
|
47615
|
+
deleted: "deleted",
|
|
47483
47616
|
needs_approval: "needs approval",
|
|
47484
47617
|
invalid: "invalid",
|
|
47485
47618
|
conflict: "conflict",
|
|
@@ -47580,27 +47713,67 @@ function displayPath(path2) {
|
|
|
47580
47713
|
const rel = (0, import_node_path8.relative)(process.cwd(), path2);
|
|
47581
47714
|
return rel && !rel.startsWith("..") ? rel : path2;
|
|
47582
47715
|
}
|
|
47583
|
-
async function
|
|
47716
|
+
async function listNotebooksCommand(options = {}) {
|
|
47584
47717
|
const json = isJsonOutput(options.output);
|
|
47585
47718
|
const client = await loadClient();
|
|
47586
|
-
const spinner = startSpinner(json,
|
|
47719
|
+
const spinner = startSpinner(json, "Loading notebooks...");
|
|
47587
47720
|
try {
|
|
47588
|
-
const
|
|
47721
|
+
const notebooks = await client.listNotebooks();
|
|
47589
47722
|
if (json) {
|
|
47590
|
-
printJson2({
|
|
47723
|
+
printJson2({ notebooks });
|
|
47591
47724
|
return;
|
|
47592
47725
|
}
|
|
47593
|
-
spinner?.
|
|
47594
|
-
|
|
47595
|
-
|
|
47596
|
-
|
|
47726
|
+
spinner?.stop();
|
|
47727
|
+
printTable(
|
|
47728
|
+
{ columns: NOTEBOOK_COLUMNS, rows: notebookRows(notebooks) },
|
|
47729
|
+
{ emptyMessage: "No notebooks yet" }
|
|
47597
47730
|
);
|
|
47598
|
-
|
|
47599
|
-
|
|
47600
|
-
|
|
47601
|
-
|
|
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})` : ""}`
|
|
47602
47760
|
)
|
|
47603
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"));
|
|
47604
47777
|
}
|
|
47605
47778
|
} catch (error) {
|
|
47606
47779
|
exitWithError(spinner, error, "Failed to pull notebook");
|
|
@@ -47962,8 +48135,19 @@ async function syncNotebooksCommand(paths, options = {}) {
|
|
|
47962
48135
|
${duplicates.join("\n")}`
|
|
47963
48136
|
);
|
|
47964
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
|
+
) : [];
|
|
47965
48149
|
const results = [];
|
|
47966
|
-
if (files.length) {
|
|
48150
|
+
if (files.length || removed.length) {
|
|
47967
48151
|
const client = await loadClient();
|
|
47968
48152
|
for (const file of files) {
|
|
47969
48153
|
spinner = startSpinner(
|
|
@@ -47984,6 +48168,20 @@ ${duplicates.join("\n")}`
|
|
|
47984
48168
|
console.log();
|
|
47985
48169
|
}
|
|
47986
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
|
+
}
|
|
47987
48185
|
}
|
|
47988
48186
|
if (options.summary) {
|
|
47989
48187
|
await import_node_fs8.promises.appendFile(
|
|
@@ -48043,6 +48241,7 @@ overwrites someone else's edit. On a live notebook push saves a draft; publish
|
|
|
48043
48241
|
it with the plan id push prints.
|
|
48044
48242
|
|
|
48045
48243
|
Examples:
|
|
48244
|
+
oleander notebooks list
|
|
48046
48245
|
oleander notebooks pull bluehouse-morning
|
|
48047
48246
|
oleander notebooks plan bluehouse-morning.notebook.yaml
|
|
48048
48247
|
oleander notebooks push bluehouse-morning.notebook.yaml --run
|
|
@@ -48050,7 +48249,9 @@ Examples:
|
|
|
48050
48249
|
oleander notebooks logs bluehouse-morning <run_id> --cell posts_by_hour
|
|
48051
48250
|
`
|
|
48052
48251
|
);
|
|
48053
|
-
const
|
|
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);
|
|
48054
48255
|
addOutputOption(pull);
|
|
48055
48256
|
const push = notebooks.command("push").description(
|
|
48056
48257
|
"Plan and save a notebook YAML file (a draft, on a live notebook)"
|
|
@@ -48067,18 +48268,26 @@ Examples:
|
|
|
48067
48268
|
).option("--publish", "Publish the draft a save leaves on a live notebook").option(
|
|
48068
48269
|
"--summary <file>",
|
|
48069
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"
|
|
48070
48277
|
).addHelpText(
|
|
48071
48278
|
"after",
|
|
48072
48279
|
`
|
|
48073
48280
|
The files are the source of truth: sync saves each changed file over what is on
|
|
48074
48281
|
the server (a concurrent edit made between its plan and save fails with a
|
|
48075
|
-
conflict instead). Unchanged files are skipped.
|
|
48076
|
-
|
|
48077
|
-
fails to save
|
|
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.
|
|
48078
48286
|
|
|
48079
48287
|
Examples:
|
|
48080
48288
|
oleander notebooks sync notebooks/ --dry-run --summary "$GITHUB_STEP_SUMMARY"
|
|
48081
48289
|
oleander notebooks sync notebooks/ --approve --publish
|
|
48290
|
+
oleander notebooks sync notebooks/ --removed-since HEAD~1 --delete
|
|
48082
48291
|
`
|
|
48083
48292
|
).action(syncNotebooksCommand);
|
|
48084
48293
|
addOutputOption(sync);
|
|
@@ -48101,7 +48310,7 @@ Examples:
|
|
|
48101
48310
|
}
|
|
48102
48311
|
|
|
48103
48312
|
// src/utils/skills.ts
|
|
48104
|
-
var
|
|
48313
|
+
var import_node_child_process4 = require("child_process");
|
|
48105
48314
|
var import_node_os5 = require("os");
|
|
48106
48315
|
var import_node_fs9 = require("fs");
|
|
48107
48316
|
var import_node_path9 = require("path");
|
|
@@ -48287,11 +48496,11 @@ function getSkillsStatus(options = {}) {
|
|
|
48287
48496
|
};
|
|
48288
48497
|
}
|
|
48289
48498
|
function installSkills(options = {}) {
|
|
48290
|
-
const
|
|
48499
|
+
const spawn4 = options.spawn ?? ((command, args2, spawnOptions) => (0, import_node_child_process4.spawnSync)(command, args2, spawnOptions));
|
|
48291
48500
|
const home = options.homeDir ?? (0, import_node_os5.homedir)();
|
|
48292
48501
|
const agentRoots = options.agentRoots ?? AGENT_SKILL_ROOTS;
|
|
48293
48502
|
const env2 = options.homeDir ? { ...process.env, HOME: options.homeDir } : process.env;
|
|
48294
|
-
const result =
|
|
48503
|
+
const result = spawn4("npx", [...SKILLS_ADD_ARGS], {
|
|
48295
48504
|
encoding: "utf8",
|
|
48296
48505
|
env: env2,
|
|
48297
48506
|
shell: process.platform === "win32"
|
|
@@ -48519,12 +48728,130 @@ async function whoamiCommand(options) {
|
|
|
48519
48728
|
printProfileIdentity(current);
|
|
48520
48729
|
}
|
|
48521
48730
|
|
|
48731
|
+
// src/commands/login.ts
|
|
48732
|
+
var import_node_child_process5 = require("child_process");
|
|
48733
|
+
var import_node_os6 = require("os");
|
|
48734
|
+
var CLI_CLIENT_ID = "oleander-cli";
|
|
48735
|
+
var DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
48736
|
+
function registerLoginCommand(program3) {
|
|
48737
|
+
program3.command("login").description("Signs in from your browser and saves an API key").option("--profile <name>", PROFILE_OPTION_DESCRIPTION).option("--no-browser", "Print the sign-in link instead of opening it").addHelpText(
|
|
48738
|
+
"after",
|
|
48739
|
+
`
|
|
48740
|
+
Examples:
|
|
48741
|
+
oleander login
|
|
48742
|
+
oleander login --profile production
|
|
48743
|
+
`
|
|
48744
|
+
).action(loginCommand);
|
|
48745
|
+
}
|
|
48746
|
+
async function postJson(url, body, headers = {}) {
|
|
48747
|
+
const response = await fetch(url, {
|
|
48748
|
+
method: "POST",
|
|
48749
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
48750
|
+
body: JSON.stringify(body)
|
|
48751
|
+
});
|
|
48752
|
+
const data = await response.json().catch(() => ({}));
|
|
48753
|
+
return { status: response.status, data };
|
|
48754
|
+
}
|
|
48755
|
+
function openInBrowser(url) {
|
|
48756
|
+
const [command, args2] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url]] : ["xdg-open", [url]];
|
|
48757
|
+
try {
|
|
48758
|
+
const child = (0, import_node_child_process5.spawn)(command, args2, { stdio: "ignore", detached: true });
|
|
48759
|
+
child.on("error", () => {
|
|
48760
|
+
});
|
|
48761
|
+
child.unref();
|
|
48762
|
+
} catch {
|
|
48763
|
+
}
|
|
48764
|
+
}
|
|
48765
|
+
var sleep = (ms) => new Promise((r2) => setTimeout(r2, ms));
|
|
48766
|
+
async function waitForApproval(endpoint, code, wait2 = sleep) {
|
|
48767
|
+
let intervalSeconds = Math.max(code.interval, 1);
|
|
48768
|
+
const deadline = Date.now() + code.expires_in * 1e3;
|
|
48769
|
+
while (Date.now() < deadline) {
|
|
48770
|
+
await wait2(intervalSeconds * 1e3);
|
|
48771
|
+
const { status, data } = await postJson(
|
|
48772
|
+
`${endpoint}/api/auth/device/token`,
|
|
48773
|
+
{
|
|
48774
|
+
grant_type: DEVICE_GRANT_TYPE,
|
|
48775
|
+
device_code: code.device_code,
|
|
48776
|
+
client_id: CLI_CLIENT_ID
|
|
48777
|
+
}
|
|
48778
|
+
);
|
|
48779
|
+
if (status === 200 && typeof data.access_token === "string") {
|
|
48780
|
+
return data.access_token;
|
|
48781
|
+
}
|
|
48782
|
+
switch (data.error) {
|
|
48783
|
+
case "authorization_pending":
|
|
48784
|
+
continue;
|
|
48785
|
+
case "slow_down":
|
|
48786
|
+
intervalSeconds += 5;
|
|
48787
|
+
continue;
|
|
48788
|
+
case "access_denied":
|
|
48789
|
+
throw new Error("Sign-in was denied in the browser.");
|
|
48790
|
+
case "expired_token":
|
|
48791
|
+
throw new Error("The sign-in code expired. Run oleander login again.");
|
|
48792
|
+
default:
|
|
48793
|
+
throw new Error(
|
|
48794
|
+
typeof data.error_description === "string" ? data.error_description : `Sign-in failed (HTTP ${status}).`
|
|
48795
|
+
);
|
|
48796
|
+
}
|
|
48797
|
+
}
|
|
48798
|
+
throw new Error("The sign-in code expired. Run oleander login again.");
|
|
48799
|
+
}
|
|
48800
|
+
async function loginCommand(options) {
|
|
48801
|
+
const endpoint = getEndpoint();
|
|
48802
|
+
const interactive = isInteractive2();
|
|
48803
|
+
if (interactive) Ie("Signing in to oleander");
|
|
48804
|
+
const requested = await postJson(`${endpoint}/api/auth/device/code`, {
|
|
48805
|
+
client_id: CLI_CLIENT_ID
|
|
48806
|
+
});
|
|
48807
|
+
if (requested.status !== 200) {
|
|
48808
|
+
logger.error(`Could not start sign-in (HTTP ${requested.status}).`);
|
|
48809
|
+
process.exit(1);
|
|
48810
|
+
}
|
|
48811
|
+
const code = requested.data;
|
|
48812
|
+
const message = `Open ${source_default.cyan(code.verification_uri)} and enter ${source_default.bold(code.user_code)}`;
|
|
48813
|
+
if (interactive) M2.step(message);
|
|
48814
|
+
else logger.info(message);
|
|
48815
|
+
if (options.browser) openInBrowser(code.verification_uri_complete);
|
|
48816
|
+
const waiting = interactive ? Y2() : null;
|
|
48817
|
+
waiting?.start("Waiting for approval in your browser");
|
|
48818
|
+
let accessToken;
|
|
48819
|
+
try {
|
|
48820
|
+
accessToken = await waitForApproval(endpoint, code);
|
|
48821
|
+
} catch (error) {
|
|
48822
|
+
waiting?.stop("Not signed in");
|
|
48823
|
+
logger.error(error instanceof Error ? error.message : String(error));
|
|
48824
|
+
process.exit(1);
|
|
48825
|
+
}
|
|
48826
|
+
const issued = await postJson(
|
|
48827
|
+
`${endpoint}/api/v1/cli/api-key`,
|
|
48828
|
+
{ device: (0, import_node_os6.hostname)() },
|
|
48829
|
+
{ Authorization: `Bearer ${accessToken}` }
|
|
48830
|
+
);
|
|
48831
|
+
if (issued.status !== 201) {
|
|
48832
|
+
waiting?.stop("Not signed in");
|
|
48833
|
+
logger.error(
|
|
48834
|
+
typeof issued.data.error === "string" ? issued.data.error : `Could not create an API key (HTTP ${issued.status}).`
|
|
48835
|
+
);
|
|
48836
|
+
process.exit(1);
|
|
48837
|
+
}
|
|
48838
|
+
const key = issued.data;
|
|
48839
|
+
waiting?.stop(`Signed in to ${key.organization.name || key.organization.id}`);
|
|
48840
|
+
const profile = options.profile?.trim() || await currentProfileName() || DEFAULT_PROFILE;
|
|
48841
|
+
await saveProfile(profile, {
|
|
48842
|
+
apiKey: key.api_key,
|
|
48843
|
+
interactive
|
|
48844
|
+
});
|
|
48845
|
+
if (interactive) Se("You're signed in.");
|
|
48846
|
+
}
|
|
48847
|
+
|
|
48522
48848
|
// src/index.ts
|
|
48523
48849
|
var program2 = new Command();
|
|
48524
48850
|
var args = process.argv.slice(2);
|
|
48525
48851
|
program2.name("oleander").description(`oleander CLI (v${VERSION})`).version(VERSION).enablePositionalOptions().option("--profile <name>", PROFILE_OPTION_DESCRIPTION).hook("preAction", (_thisCommand, actionCommand) => {
|
|
48526
48852
|
applyCommandProfile(actionCommand);
|
|
48527
48853
|
});
|
|
48854
|
+
registerLoginCommand(program2);
|
|
48528
48855
|
registerConfigureCommand(program2);
|
|
48529
48856
|
registerSwitchCommand(program2);
|
|
48530
48857
|
registerWhoamiCommand(program2);
|
|
@@ -48585,7 +48912,7 @@ for (const command of program2.commands) {
|
|
|
48585
48912
|
attachProfileOption(command);
|
|
48586
48913
|
}
|
|
48587
48914
|
function attachProfileOption(command) {
|
|
48588
|
-
if (
|
|
48915
|
+
if (["configure", "login", "switch"].includes(command.name())) {
|
|
48589
48916
|
return;
|
|
48590
48917
|
}
|
|
48591
48918
|
command.option("--profile <name>", PROFILE_OPTION_DESCRIPTION);
|