@epoch-agent/cli 0.10.0 → 0.11.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 +108 -8
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -504,6 +504,11 @@ var SECTION_FIELDS = {
504
504
  memoryCharLimit: isPositiveInt,
505
505
  userCharLimit: isPositiveInt,
506
506
  indexCharLimit: isPositiveInt
507
+ },
508
+ sessions: {
509
+ autoPrune: (v) => v === "true" || v === "false",
510
+ retentionDays: isPositiveInt,
511
+ vacuumAfterPrune: (v) => v === "true" || v === "false"
507
512
  }
508
513
  };
509
514
  function knownKeys() {
@@ -2573,7 +2578,7 @@ import {
2573
2578
  matchPreauthorization,
2574
2579
  mergeHeadlessPolicy
2575
2580
  } from "@epoch-agent/core";
2576
- import { t as t18 } from "@epoch-agent/infra";
2581
+ import { createStreamDecoder, t as t18 } from "@epoch-agent/infra";
2577
2582
  import { APPROVAL_OUTCOMES as APPROVAL_OUTCOMES2, isApprovalOutcome as isApprovalOutcome2 } from "@epoch-agent/protocol";
2578
2583
  var APPROVER_TIMEOUT_MS = 6e4;
2579
2584
  var MAX_STDOUT_BYTES = 64 * 1024;
@@ -2640,8 +2645,10 @@ function askExternalApprover(program2, payload, opts = {}) {
2640
2645
  clearTimeout(timer);
2641
2646
  settle(v);
2642
2647
  };
2648
+ let decoder = null;
2643
2649
  child.stdout?.on("data", (d) => {
2644
- out2 += d.toString("utf-8");
2650
+ decoder ??= createStreamDecoder();
2651
+ out2 += decoder.write(d);
2645
2652
  if (out2.length > MAX_STDOUT_BYTES) {
2646
2653
  child.kill("SIGKILL");
2647
2654
  done({ ok: false, why: t18("approver.too_much_output", { bytes: MAX_STDOUT_BYTES }) });
@@ -2651,6 +2658,7 @@ function askExternalApprover(program2, payload, opts = {}) {
2651
2658
  done({ ok: false, why: t18("approver.spawn_failed", { message: err2.message }) });
2652
2659
  });
2653
2660
  child.on("close", (code) => {
2661
+ out2 += decoder?.end() ?? "";
2654
2662
  if (code !== 0) {
2655
2663
  done({ ok: false, why: t18("approver.bad_exit", { code: code ?? -1 }) });
2656
2664
  return;
@@ -3346,11 +3354,19 @@ function assertHttpUrl(value) {
3346
3354
  );
3347
3355
  }
3348
3356
  // src/commands/sessions.ts
3349
- import { isNonInteractive as isNonInteractive7, resolveProjectRoot as resolveProjectRoot3, SessionManager } from "@epoch-agent/core";
3357
+ import { writeFileSync as writeFileSync2 } from "fs";
3358
+ import {
3359
+ isNonInteractive as isNonInteractive7,
3360
+ redactLine,
3361
+ resolveProjectRoot as resolveProjectRoot3,
3362
+ SessionManager
3363
+ } from "@epoch-agent/core";
3350
3364
  import { dbPath, t as t24, uiDateLocale as uiDateLocale2 } from "@epoch-agent/infra";
3351
3365
  var log7 = (msg) => process.stdout.write(msg + "\n");
3352
3366
  var SHORT_ID_LEN2 = 8;
3353
3367
  var PICK_LIMIT = 20;
3368
+ var DEFAULT_RETENTION_DAYS = 90;
3369
+ var VACUUM_MIN_FREELIST_RATIO = 0.25;
3354
3370
  function whenOf(startedAt) {
3355
3371
  return startedAt ? new Date(startedAt).toLocaleString(uiDateLocale2()) : t24("sessions.when_unknown");
3356
3372
  }
@@ -3359,11 +3375,14 @@ function titleOf(s) {
3359
3375
  }
3360
3376
  function registerSessionsCommand(program2) {
3361
3377
  const cmd = program2.command("sessions").alias("session").description(t24("sessions.cmd_root"));
3362
- cmd.command("list").description(t24("sessions.cmd_list")).option("-n, --limit <n>", t24("sessions.opt_limit"), "10").action((opts) => {
3378
+ cmd.command("list").description(t24("sessions.cmd_list")).option("-n, --limit <n>", t24("sessions.opt_limit"), "10").option("-a, --archived", t24("sessions.opt_archived")).action((opts) => {
3363
3379
  withSessions((sm) => {
3364
- const r = sm.list({ limit: parseInt(opts.limit, 10) });
3380
+ const r = sm.list({
3381
+ limit: parseInt(opts.limit, 10),
3382
+ ...opts.archived ? { archived: true } : {}
3383
+ });
3365
3384
  if (r.sessions.length === 0) {
3366
- log7(` ${t24("sessions.list_empty")}`);
3385
+ log7(` ${t24(opts.archived ? "sessions.list_empty_archived" : "sessions.list_empty")}`);
3367
3386
  return;
3368
3387
  }
3369
3388
  for (const s of r.sessions) {
@@ -3371,6 +3390,85 @@ function registerSessionsCommand(program2) {
3371
3390
  }
3372
3391
  });
3373
3392
  });
3393
+ cmd.command("archive").description(t24("sessions.cmd_archive")).argument("<id>", t24("sessions.arg_id")).action((id) => {
3394
+ const resolved = resolveSessionId(id, { includeArchived: true });
3395
+ if (!resolved.ok) throw new CliError(resolved.error, EXIT_CODES.FAILURE);
3396
+ withSessions((sm) => sm.archive(resolved.id));
3397
+ log7(t24("sessions.archived_ok", { id: resolved.id.slice(0, SHORT_ID_LEN2) }));
3398
+ });
3399
+ cmd.command("unarchive").description(t24("sessions.cmd_unarchive")).argument("<id>", t24("sessions.arg_id")).action((id) => {
3400
+ const resolved = resolveSessionId(id, { includeArchived: true });
3401
+ if (!resolved.ok) throw new CliError(resolved.error, EXIT_CODES.FAILURE);
3402
+ withSessions((sm) => sm.unarchive(resolved.id));
3403
+ log7(t24("sessions.unarchived_ok", { id: resolved.id.slice(0, SHORT_ID_LEN2) }));
3404
+ });
3405
+ cmd.command("export").description(t24("sessions.cmd_export")).argument("<id>", t24("sessions.arg_id")).argument("[file]", t24("sessions.arg_export_file")).option("-f, --format <fmt>", t24("sessions.opt_format"), "json").option("--redact", t24("sessions.opt_redact")).action((id, file, opts) => {
3406
+ const resolved = resolveSessionId(id, { includeArchived: true });
3407
+ if (!resolved.ok) throw new CliError(resolved.error, EXIT_CODES.FAILURE);
3408
+ const format = opts.format === "md" ? "markdown" : opts.format === "json" ? "json" : null;
3409
+ if (format === null) {
3410
+ throw new CliError(
3411
+ t24("sessions.err_format", { format: opts.format }),
3412
+ EXIT_CODES.FAILURE,
3413
+ t24("sessions.err_format_hint")
3414
+ );
3415
+ }
3416
+ const raw = withSessions((sm) => sm.export(resolved.id, format));
3417
+ const body = opts.redact ? raw.split("\n").map(redactLine).join("\n") : raw;
3418
+ if (!file || file === "-") {
3419
+ process.stdout.write(body.endsWith("\n") ? body : body + "\n");
3420
+ return;
3421
+ }
3422
+ writeFileSync2(file, body.endsWith("\n") ? body : body + "\n", "utf8");
3423
+ log7(t24("sessions.export_ok", { file }));
3424
+ });
3425
+ cmd.command("prune").description(t24("sessions.cmd_prune")).option("--older-than <days>", t24("sessions.opt_older_than"), String(DEFAULT_RETENTION_DAYS)).option("--archived-only", t24("sessions.opt_archived_only")).option("--include-pinned", t24("sessions.opt_include_pinned")).option("--yes", t24("sessions.opt_yes")).action(
3426
+ (opts) => {
3427
+ const days = Number(opts.olderThan);
3428
+ if (!Number.isFinite(days) || days <= 0) {
3429
+ throw new CliError(t24("sessions.err_days", { value: opts.olderThan }), EXIT_CODES.FAILURE);
3430
+ }
3431
+ const olderThanMs = Date.now() - days * 24 * 60 * 60 * 1e3;
3432
+ const select2 = {
3433
+ olderThanMs,
3434
+ ...opts.archivedOnly ? { archived: true } : {},
3435
+ ...opts.includePinned ? { includePinned: true } : {}
3436
+ };
3437
+ const { victims, openCount } = withSessions((sm) => ({
3438
+ victims: sm.pruneCandidates(select2),
3439
+ openCount: sm.openPruneMatches({
3440
+ olderThanMs,
3441
+ ...opts.includePinned ? { includePinned: true } : {}
3442
+ })
3443
+ }));
3444
+ if (victims.length === 0) {
3445
+ log7(t24("sessions.prune_none", { days }));
3446
+ if (openCount > 0) log7(t24("sessions.prune_open_skipped", { count: openCount }));
3447
+ return;
3448
+ }
3449
+ log7(t24("sessions.prune_head"));
3450
+ for (const s of victims) {
3451
+ log7(` ${s.id.slice(0, SHORT_ID_LEN2)} ${whenOf(s.updatedAt)} ${titleOf(s)}`);
3452
+ }
3453
+ if (openCount > 0) log7(t24("sessions.prune_open_skipped", { count: openCount }));
3454
+ if (!opts.yes) {
3455
+ log7(t24("sessions.prune_preview", { count: victims.length, days }));
3456
+ return;
3457
+ }
3458
+ let removed = 0;
3459
+ withSessions((sm) => {
3460
+ for (const s of victims) if (sm.delete(s.id)) removed++;
3461
+ });
3462
+ log7(t24("sessions.prune_done", { count: removed }));
3463
+ if (removed > 0) {
3464
+ const ratio = withSessions((sm) => sm.freelistRatio());
3465
+ if (ratio > VACUUM_MIN_FREELIST_RATIO) {
3466
+ const report = withSessions((sm) => sm.reclaimFts(true));
3467
+ if (report.vacuumed) log7(t24("sessions.prune_vacuumed"));
3468
+ }
3469
+ }
3470
+ }
3471
+ );
3374
3472
  cmd.command("resume").description(t24("sessions.cmd_resume")).argument("[id]", t24("sessions.arg_id")).argument("[query]", t24("sessions.arg_query")).action(async (id, query) => {
3375
3473
  const resolved = resolveSessionId(id);
3376
3474
  if (!resolved.ok) {
@@ -3379,14 +3477,16 @@ function registerSessionsCommand(program2) {
3379
3477
  await runOnce(query || t24("sessions.default_query"), {}, resolved.id);
3380
3478
  });
3381
3479
  }
3382
- function resolveSessionId(input2) {
3480
+ function resolveSessionId(input2, opts = {}) {
3383
3481
  return withSessions((sm) => {
3384
3482
  if (!input2) {
3385
3483
  const latest = sm.getLatest()?.meta.id;
3386
3484
  return latest ? { ok: true, id: latest } : { ok: false, error: t24("sessions.err_none") };
3387
3485
  }
3388
3486
  if (sm.get(input2)) return { ok: true, id: input2 };
3389
- const candidates = sm.list({ limit: 200 }).sessions.filter((s) => s.id.startsWith(input2)).map((s) => s.id);
3487
+ const pool = sm.list({ limit: 200 }).sessions;
3488
+ const all = opts.includeArchived ? [...pool, ...sm.list({ limit: 200, archived: true }).sessions] : pool;
3489
+ const candidates = all.filter((s) => s.id.startsWith(input2)).map((s) => s.id);
3390
3490
  if (candidates.length === 1) return { ok: true, id: candidates[0] };
3391
3491
  if (candidates.length === 0) {
3392
3492
  return { ok: false, error: t24("sessions.err_not_found", { input: input2 }) };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epoch-agent/cli",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "private": false,
5
5
  "description": "epoch-agent CLI 入口",
6
6
  "repository": {
@@ -22,12 +22,12 @@
22
22
  "commander": "^15.0.0",
23
23
  "ink": "^7.1.1",
24
24
  "react": "^19.2.8",
25
- "@epoch-agent/protocol": "0.10.0",
26
- "@epoch-agent/core": "0.10.0",
27
- "@epoch-agent/runtime": "0.10.0",
28
- "@epoch-agent/server": "0.10.0",
29
- "@epoch-agent/infra": "0.10.0",
30
- "@epoch-agent/tui": "^0.10.0"
25
+ "@epoch-agent/infra": "0.11.0",
26
+ "@epoch-agent/core": "0.11.0",
27
+ "@epoch-agent/server": "0.11.0",
28
+ "@epoch-agent/protocol": "0.11.0",
29
+ "@epoch-agent/runtime": "0.11.0",
30
+ "@epoch-agent/tui": "^0.11.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^22.20.1",