@erdoai/cli 0.37.0 → 0.39.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 (2) hide show
  1. package/dist/index.js +179 -0
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -523,6 +523,28 @@ var ErdoClient = class {
523
523
  `/v1/activity/feed${qs ? `?${qs}` : ""}`
524
524
  );
525
525
  }
526
+ // --- org history ledger ---
527
+ // The append-only org history: consequential actions (approvals decided, pages
528
+ // published, permissions granted/revoked, flag changes, membership changes)
529
+ // with full actor attribution. Read-only, newest-first. since/until are
530
+ // RFC3339; verbs and resource are pre-resolved by the caller.
531
+ listActivityHistory(params) {
532
+ const q = new URLSearchParams();
533
+ if (params?.since) q.set("since", params.since);
534
+ if (params?.until) q.set("until", params.until);
535
+ if (params?.verbs) q.set("verbs", params.verbs);
536
+ if (params?.resource_type) q.set("resource_type", params.resource_type);
537
+ if (params?.resource_id) q.set("resource_id", params.resource_id);
538
+ if (params?.actor_user_id) q.set("actor_user_id", params.actor_user_id);
539
+ if (params?.actor_kind) q.set("actor_kind", params.actor_kind);
540
+ if (params?.limit) q.set("limit", String(params.limit));
541
+ if (params?.offset) q.set("offset", String(params.offset));
542
+ const qs = q.toString();
543
+ return this.request(
544
+ "GET",
545
+ `/v1/activity/history${qs ? `?${qs}` : ""}`
546
+ );
547
+ }
526
548
  // --- knowledge review queue ---
527
549
  listReviewItems(params) {
528
550
  const q = new URLSearchParams();
@@ -728,6 +750,13 @@ var ErdoClient = class {
728
750
  runHeartbeat(id) {
729
751
  return this.request("POST", `/v1/heartbeats/${encodeURIComponent(id)}/run`, {});
730
752
  }
753
+ setHeartbeatState(id, state) {
754
+ return this.request(
755
+ "POST",
756
+ `/v1/heartbeats/${encodeURIComponent(id)}/state`,
757
+ { state }
758
+ );
759
+ }
731
760
  // --- kv (named key/value stores, a.k.a. collections) ---
732
761
  listKVStores() {
733
762
  return this.request("GET", "/v1/kv");
@@ -2398,6 +2427,140 @@ program.command("activity").alias("feed").description(
2398
2427
  }
2399
2428
  }
2400
2429
  );
2430
+ function parseWhen(v) {
2431
+ const dur = /^(\d+)\s*([smhdw])$/.exec(v.trim());
2432
+ if (dur) {
2433
+ const n = parseInt(dur[1], 10);
2434
+ const unitMs = {
2435
+ s: 1e3,
2436
+ m: 6e4,
2437
+ h: 36e5,
2438
+ d: 864e5,
2439
+ w: 6048e5
2440
+ };
2441
+ return new Date(Date.now() - n * unitMs[dur[2]]).toISOString();
2442
+ }
2443
+ const t = Date.parse(v);
2444
+ if (Number.isNaN(t)) {
2445
+ throw new Error(`can't parse time "${v}" \u2014 use a duration like 2h/3d or an RFC3339 timestamp`);
2446
+ }
2447
+ return new Date(t).toISOString();
2448
+ }
2449
+ function shortId(id) {
2450
+ return id.length > 10 ? `${id.slice(0, 8)}\u2026` : id;
2451
+ }
2452
+ function hhmm(iso) {
2453
+ const d = new Date(iso);
2454
+ if (Number.isNaN(d.getTime())) return "??:??";
2455
+ const h = String(d.getHours()).padStart(2, "0");
2456
+ const m = String(d.getMinutes()).padStart(2, "0");
2457
+ return `${h}:${m}`;
2458
+ }
2459
+ function historyActor(e) {
2460
+ switch (e.actor_kind) {
2461
+ case "agent":
2462
+ return e.agent_key || "an agent";
2463
+ case "system":
2464
+ return "Erdo (system)";
2465
+ case "user":
2466
+ return e.actor_user_id ? shortId(e.actor_user_id) : "a user";
2467
+ case "api_token":
2468
+ return "an API token";
2469
+ case "scoped_token":
2470
+ return "a scoped token";
2471
+ default:
2472
+ return e.actor_kind || "someone";
2473
+ }
2474
+ }
2475
+ function historyResource(e) {
2476
+ if (e.resource_title) return e.resource_title;
2477
+ if (e.resource_type && e.resource_id) return `${e.resource_type}/${shortId(e.resource_id)}`;
2478
+ return e.resource_type || "";
2479
+ }
2480
+ function historySentence(e) {
2481
+ const res = historyResource(e);
2482
+ const summary = (e.summary || "").replace(/\s+/g, " ").trim();
2483
+ const head = [historyActor(e), summary].filter(Boolean).join(" ");
2484
+ return res ? `${head} \u2014 ${res}` : head;
2485
+ }
2486
+ function historyAuthMarker(e) {
2487
+ if (e.authorized_by_approval_id) {
2488
+ return ` \xB7 authorized by approval ${shortId(e.authorized_by_approval_id)}`;
2489
+ }
2490
+ if (e.actor_kind === "agent" || e.actor_kind === "system") return " \xB7 autonomous";
2491
+ return "";
2492
+ }
2493
+ function renderHistory(events) {
2494
+ const order = [];
2495
+ const groups = /* @__PURE__ */ new Map();
2496
+ let standalone = 0;
2497
+ for (const e of events) {
2498
+ const key = e.authorized_by_approval_id || e.run_id || `__solo_${standalone++}`;
2499
+ if (!groups.has(key)) {
2500
+ groups.set(key, []);
2501
+ order.push(key);
2502
+ }
2503
+ groups.get(key).push(e);
2504
+ }
2505
+ for (const key of order) {
2506
+ const group = groups.get(key);
2507
+ const ordered = [...group].sort(
2508
+ (a, b) => Date.parse(a.occurred_at) - Date.parse(b.occurred_at)
2509
+ );
2510
+ const [head, ...rest] = ordered;
2511
+ console.log(`${hhmm(head.occurred_at)} ${historySentence(head)}${historyAuthMarker(head)}`);
2512
+ for (const c of rest) {
2513
+ console.log(` ${hhmm(c.occurred_at)} ${historySentence(c)}`);
2514
+ }
2515
+ }
2516
+ }
2517
+ program.command("history").description("The org history \u2014 who did what, when, under whose authority").option("--since <when>", "start of the window: a duration (2h, 3d) or RFC3339 (default 24h)", "24h").option("--until <when>", "end of the window: a duration or RFC3339 timestamp").option("--actor-kind <kind>", "user | agent | system | api_token | scoped_token").option("--actor <user-id>", "only actions by this user id").option("--resource <type:id>", "only actions on this resource, e.g. page:<id>").option("--verb <v>", "comma-separated verbs, e.g. approval.decided,page.published").option("-n, --limit <n>", "max events (default 50, max 200)", (v) => parseInt(v, 10)).option("--json", "raw events JSON").action(
2518
+ async (opts) => {
2519
+ try {
2520
+ const params = {};
2521
+ params.since = parseWhen(opts.since || "24h");
2522
+ if (opts.until) params.until = parseWhen(opts.until);
2523
+ if (opts.actorKind) params.actor_kind = opts.actorKind;
2524
+ if (opts.actor) params.actor_user_id = opts.actor;
2525
+ if (opts.verb) params.verbs = opts.verb;
2526
+ if (opts.limit) params.limit = opts.limit;
2527
+ if (opts.resource) {
2528
+ const idx = opts.resource.indexOf(":");
2529
+ if (idx === -1) {
2530
+ throw new Error(`--resource must be <type:id>, e.g. page:<id> (got "${opts.resource}")`);
2531
+ }
2532
+ params.resource_type = opts.resource.slice(0, idx);
2533
+ params.resource_id = opts.resource.slice(idx + 1);
2534
+ }
2535
+ const res = await new ErdoClient().listActivityHistory(params);
2536
+ if (opts.json) {
2537
+ print(res);
2538
+ return;
2539
+ }
2540
+ const events = res.events ?? [];
2541
+ if (events.length === 0) {
2542
+ const filters = [
2543
+ `since ${opts.since || "24h"}`,
2544
+ opts.until ? `until ${opts.until}` : "",
2545
+ opts.actorKind ? `actor-kind ${opts.actorKind}` : "",
2546
+ opts.actor ? `actor ${opts.actor}` : "",
2547
+ opts.resource ? `resource ${opts.resource}` : "",
2548
+ opts.verb ? `verb ${opts.verb}` : ""
2549
+ ].filter(Boolean).join(", ");
2550
+ console.log(`No history for: ${filters}.`);
2551
+ console.log(
2552
+ "History is append-only and starts when the ledger was enabled for this org \u2014 earlier actions aren't recorded here."
2553
+ );
2554
+ return;
2555
+ }
2556
+ renderHistory(events);
2557
+ console.log(`
2558
+ ${events.length} event${events.length === 1 ? "" : "s"}.`);
2559
+ } catch (e) {
2560
+ fail(e);
2561
+ }
2562
+ }
2563
+ );
2401
2564
  var reviewsCmd = program.command("reviews").description(
2402
2565
  "The Knowledge Review queue \u2014 knowledge patches the critic proposes, investigations, and deduplicated failure signals awaiting a human decision"
2403
2566
  );
@@ -2901,6 +3064,22 @@ autoCmd.command("run <id>").description("Trigger an automation now").action(asyn
2901
3064
  fail(e);
2902
3065
  }
2903
3066
  });
3067
+ autoCmd.command("disable <id>").description("Disable an automation so it stops running").action(async (id) => {
3068
+ try {
3069
+ const h = await new ErdoClient().setHeartbeatState(id, "disabled");
3070
+ console.log(`${h.id} ${h.state} ${h.name}`);
3071
+ } catch (e) {
3072
+ fail(e);
3073
+ }
3074
+ });
3075
+ autoCmd.command("enable <id>").description("Re-enable a disabled automation").action(async (id) => {
3076
+ try {
3077
+ const h = await new ErdoClient().setHeartbeatState(id, "active");
3078
+ console.log(`${h.id} ${h.state} ${h.name}`);
3079
+ } catch (e) {
3080
+ fail(e);
3081
+ }
3082
+ });
2904
3083
  var kvCmd = program.command("kv").description("Named key/value stores");
2905
3084
  kvCmd.command("list").description("List KV stores").action(async () => {
2906
3085
  try {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@erdoai/cli",
3
- "version": "0.37.0",
4
- "description": "Erdo CLI drive datasets, pages, and evals from the terminal or CI",
3
+ "version": "0.39.0",
4
+ "description": "Erdo CLI \u2014 drive datasets, pages, and evals from the terminal or CI",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "erdo": "dist/index.js"