@epoch-agent/cli 0.10.1 → 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.
- package/dist/index.js +103 -6
- 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() {
|
|
@@ -3349,11 +3354,19 @@ function assertHttpUrl(value) {
|
|
|
3349
3354
|
);
|
|
3350
3355
|
}
|
|
3351
3356
|
// src/commands/sessions.ts
|
|
3352
|
-
import {
|
|
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";
|
|
3353
3364
|
import { dbPath, t as t24, uiDateLocale as uiDateLocale2 } from "@epoch-agent/infra";
|
|
3354
3365
|
var log7 = (msg) => process.stdout.write(msg + "\n");
|
|
3355
3366
|
var SHORT_ID_LEN2 = 8;
|
|
3356
3367
|
var PICK_LIMIT = 20;
|
|
3368
|
+
var DEFAULT_RETENTION_DAYS = 90;
|
|
3369
|
+
var VACUUM_MIN_FREELIST_RATIO = 0.25;
|
|
3357
3370
|
function whenOf(startedAt) {
|
|
3358
3371
|
return startedAt ? new Date(startedAt).toLocaleString(uiDateLocale2()) : t24("sessions.when_unknown");
|
|
3359
3372
|
}
|
|
@@ -3362,11 +3375,14 @@ function titleOf(s) {
|
|
|
3362
3375
|
}
|
|
3363
3376
|
function registerSessionsCommand(program2) {
|
|
3364
3377
|
const cmd = program2.command("sessions").alias("session").description(t24("sessions.cmd_root"));
|
|
3365
|
-
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) => {
|
|
3366
3379
|
withSessions((sm) => {
|
|
3367
|
-
const r = sm.list({
|
|
3380
|
+
const r = sm.list({
|
|
3381
|
+
limit: parseInt(opts.limit, 10),
|
|
3382
|
+
...opts.archived ? { archived: true } : {}
|
|
3383
|
+
});
|
|
3368
3384
|
if (r.sessions.length === 0) {
|
|
3369
|
-
log7(` ${t24("sessions.list_empty")}`);
|
|
3385
|
+
log7(` ${t24(opts.archived ? "sessions.list_empty_archived" : "sessions.list_empty")}`);
|
|
3370
3386
|
return;
|
|
3371
3387
|
}
|
|
3372
3388
|
for (const s of r.sessions) {
|
|
@@ -3374,6 +3390,85 @@ function registerSessionsCommand(program2) {
|
|
|
3374
3390
|
}
|
|
3375
3391
|
});
|
|
3376
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
|
+
);
|
|
3377
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) => {
|
|
3378
3473
|
const resolved = resolveSessionId(id);
|
|
3379
3474
|
if (!resolved.ok) {
|
|
@@ -3382,14 +3477,16 @@ function registerSessionsCommand(program2) {
|
|
|
3382
3477
|
await runOnce(query || t24("sessions.default_query"), {}, resolved.id);
|
|
3383
3478
|
});
|
|
3384
3479
|
}
|
|
3385
|
-
function resolveSessionId(input2) {
|
|
3480
|
+
function resolveSessionId(input2, opts = {}) {
|
|
3386
3481
|
return withSessions((sm) => {
|
|
3387
3482
|
if (!input2) {
|
|
3388
3483
|
const latest = sm.getLatest()?.meta.id;
|
|
3389
3484
|
return latest ? { ok: true, id: latest } : { ok: false, error: t24("sessions.err_none") };
|
|
3390
3485
|
}
|
|
3391
3486
|
if (sm.get(input2)) return { ok: true, id: input2 };
|
|
3392
|
-
const
|
|
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);
|
|
3393
3490
|
if (candidates.length === 1) return { ok: true, id: candidates[0] };
|
|
3394
3491
|
if (candidates.length === 0) {
|
|
3395
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.
|
|
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/
|
|
26
|
-
"@epoch-agent/
|
|
27
|
-
"@epoch-agent/
|
|
28
|
-
"@epoch-agent/
|
|
29
|
-
"@epoch-agent/
|
|
30
|
-
"@epoch-agent/
|
|
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",
|