@epoch-agent/cli 0.10.1 → 0.12.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 +107 -8
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -492,7 +492,8 @@ var BUDGET_FIELDS = {
|
|
|
492
492
|
};
|
|
493
493
|
var SCALAR_FIELDS = {
|
|
494
494
|
maxTurns: isTurnLimit,
|
|
495
|
-
contextLength: isPositiveInt
|
|
495
|
+
contextLength: isPositiveInt,
|
|
496
|
+
maxOutputTokens: isPositiveInt
|
|
496
497
|
};
|
|
497
498
|
var SECTION_FIELDS = {
|
|
498
499
|
budget: BUDGET_FIELDS,
|
|
@@ -504,6 +505,11 @@ var SECTION_FIELDS = {
|
|
|
504
505
|
memoryCharLimit: isPositiveInt,
|
|
505
506
|
userCharLimit: isPositiveInt,
|
|
506
507
|
indexCharLimit: isPositiveInt
|
|
508
|
+
},
|
|
509
|
+
sessions: {
|
|
510
|
+
autoPrune: (v) => v === "true" || v === "false",
|
|
511
|
+
retentionDays: isPositiveInt,
|
|
512
|
+
vacuumAfterPrune: (v) => v === "true" || v === "false"
|
|
507
513
|
}
|
|
508
514
|
};
|
|
509
515
|
function knownKeys() {
|
|
@@ -3349,11 +3355,19 @@ function assertHttpUrl(value) {
|
|
|
3349
3355
|
);
|
|
3350
3356
|
}
|
|
3351
3357
|
// src/commands/sessions.ts
|
|
3352
|
-
import {
|
|
3358
|
+
import { writeFileSync as writeFileSync2 } from "fs";
|
|
3359
|
+
import {
|
|
3360
|
+
isNonInteractive as isNonInteractive7,
|
|
3361
|
+
redactLine,
|
|
3362
|
+
resolveProjectRoot as resolveProjectRoot3,
|
|
3363
|
+
SessionManager
|
|
3364
|
+
} from "@epoch-agent/core";
|
|
3353
3365
|
import { dbPath, t as t24, uiDateLocale as uiDateLocale2 } from "@epoch-agent/infra";
|
|
3354
3366
|
var log7 = (msg) => process.stdout.write(msg + "\n");
|
|
3355
3367
|
var SHORT_ID_LEN2 = 8;
|
|
3356
3368
|
var PICK_LIMIT = 20;
|
|
3369
|
+
var DEFAULT_RETENTION_DAYS = 90;
|
|
3370
|
+
var VACUUM_MIN_FREELIST_RATIO = 0.25;
|
|
3357
3371
|
function whenOf(startedAt) {
|
|
3358
3372
|
return startedAt ? new Date(startedAt).toLocaleString(uiDateLocale2()) : t24("sessions.when_unknown");
|
|
3359
3373
|
}
|
|
@@ -3362,11 +3376,14 @@ function titleOf(s) {
|
|
|
3362
3376
|
}
|
|
3363
3377
|
function registerSessionsCommand(program2) {
|
|
3364
3378
|
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) => {
|
|
3379
|
+
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
3380
|
withSessions((sm) => {
|
|
3367
|
-
const r = sm.list({
|
|
3381
|
+
const r = sm.list({
|
|
3382
|
+
limit: parseInt(opts.limit, 10),
|
|
3383
|
+
...opts.archived ? { archived: true } : {}
|
|
3384
|
+
});
|
|
3368
3385
|
if (r.sessions.length === 0) {
|
|
3369
|
-
log7(` ${t24("sessions.list_empty")}`);
|
|
3386
|
+
log7(` ${t24(opts.archived ? "sessions.list_empty_archived" : "sessions.list_empty")}`);
|
|
3370
3387
|
return;
|
|
3371
3388
|
}
|
|
3372
3389
|
for (const s of r.sessions) {
|
|
@@ -3374,6 +3391,85 @@ function registerSessionsCommand(program2) {
|
|
|
3374
3391
|
}
|
|
3375
3392
|
});
|
|
3376
3393
|
});
|
|
3394
|
+
cmd.command("archive").description(t24("sessions.cmd_archive")).argument("<id>", t24("sessions.arg_id")).action((id) => {
|
|
3395
|
+
const resolved = resolveSessionId(id, { includeArchived: true });
|
|
3396
|
+
if (!resolved.ok) throw new CliError(resolved.error, EXIT_CODES.FAILURE);
|
|
3397
|
+
withSessions((sm) => sm.archive(resolved.id));
|
|
3398
|
+
log7(t24("sessions.archived_ok", { id: resolved.id.slice(0, SHORT_ID_LEN2) }));
|
|
3399
|
+
});
|
|
3400
|
+
cmd.command("unarchive").description(t24("sessions.cmd_unarchive")).argument("<id>", t24("sessions.arg_id")).action((id) => {
|
|
3401
|
+
const resolved = resolveSessionId(id, { includeArchived: true });
|
|
3402
|
+
if (!resolved.ok) throw new CliError(resolved.error, EXIT_CODES.FAILURE);
|
|
3403
|
+
withSessions((sm) => sm.unarchive(resolved.id));
|
|
3404
|
+
log7(t24("sessions.unarchived_ok", { id: resolved.id.slice(0, SHORT_ID_LEN2) }));
|
|
3405
|
+
});
|
|
3406
|
+
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) => {
|
|
3407
|
+
const resolved = resolveSessionId(id, { includeArchived: true });
|
|
3408
|
+
if (!resolved.ok) throw new CliError(resolved.error, EXIT_CODES.FAILURE);
|
|
3409
|
+
const format = opts.format === "md" ? "markdown" : opts.format === "json" ? "json" : null;
|
|
3410
|
+
if (format === null) {
|
|
3411
|
+
throw new CliError(
|
|
3412
|
+
t24("sessions.err_format", { format: opts.format }),
|
|
3413
|
+
EXIT_CODES.FAILURE,
|
|
3414
|
+
t24("sessions.err_format_hint")
|
|
3415
|
+
);
|
|
3416
|
+
}
|
|
3417
|
+
const raw = withSessions((sm) => sm.export(resolved.id, format));
|
|
3418
|
+
const body = opts.redact ? raw.split("\n").map(redactLine).join("\n") : raw;
|
|
3419
|
+
if (!file || file === "-") {
|
|
3420
|
+
process.stdout.write(body.endsWith("\n") ? body : body + "\n");
|
|
3421
|
+
return;
|
|
3422
|
+
}
|
|
3423
|
+
writeFileSync2(file, body.endsWith("\n") ? body : body + "\n", "utf8");
|
|
3424
|
+
log7(t24("sessions.export_ok", { file }));
|
|
3425
|
+
});
|
|
3426
|
+
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(
|
|
3427
|
+
(opts) => {
|
|
3428
|
+
const days = Number(opts.olderThan);
|
|
3429
|
+
if (!Number.isFinite(days) || days <= 0) {
|
|
3430
|
+
throw new CliError(t24("sessions.err_days", { value: opts.olderThan }), EXIT_CODES.FAILURE);
|
|
3431
|
+
}
|
|
3432
|
+
const olderThanMs = Date.now() - days * 24 * 60 * 60 * 1e3;
|
|
3433
|
+
const select2 = {
|
|
3434
|
+
olderThanMs,
|
|
3435
|
+
...opts.archivedOnly ? { archived: true } : {},
|
|
3436
|
+
...opts.includePinned ? { includePinned: true } : {}
|
|
3437
|
+
};
|
|
3438
|
+
const { victims, openCount } = withSessions((sm) => ({
|
|
3439
|
+
victims: sm.pruneCandidates(select2),
|
|
3440
|
+
openCount: sm.openPruneMatches({
|
|
3441
|
+
olderThanMs,
|
|
3442
|
+
...opts.includePinned ? { includePinned: true } : {}
|
|
3443
|
+
})
|
|
3444
|
+
}));
|
|
3445
|
+
if (victims.length === 0) {
|
|
3446
|
+
log7(t24("sessions.prune_none", { days }));
|
|
3447
|
+
if (openCount > 0) log7(t24("sessions.prune_open_skipped", { count: openCount }));
|
|
3448
|
+
return;
|
|
3449
|
+
}
|
|
3450
|
+
log7(t24("sessions.prune_head"));
|
|
3451
|
+
for (const s of victims) {
|
|
3452
|
+
log7(` ${s.id.slice(0, SHORT_ID_LEN2)} ${whenOf(s.updatedAt)} ${titleOf(s)}`);
|
|
3453
|
+
}
|
|
3454
|
+
if (openCount > 0) log7(t24("sessions.prune_open_skipped", { count: openCount }));
|
|
3455
|
+
if (!opts.yes) {
|
|
3456
|
+
log7(t24("sessions.prune_preview", { count: victims.length, days }));
|
|
3457
|
+
return;
|
|
3458
|
+
}
|
|
3459
|
+
let removed = 0;
|
|
3460
|
+
withSessions((sm) => {
|
|
3461
|
+
for (const s of victims) if (sm.delete(s.id)) removed++;
|
|
3462
|
+
});
|
|
3463
|
+
log7(t24("sessions.prune_done", { count: removed }));
|
|
3464
|
+
if (removed > 0) {
|
|
3465
|
+
const ratio = withSessions((sm) => sm.freelistRatio());
|
|
3466
|
+
if (ratio > VACUUM_MIN_FREELIST_RATIO) {
|
|
3467
|
+
const report = withSessions((sm) => sm.reclaimFts(true));
|
|
3468
|
+
if (report.vacuumed) log7(t24("sessions.prune_vacuumed"));
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
}
|
|
3472
|
+
);
|
|
3377
3473
|
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
3474
|
const resolved = resolveSessionId(id);
|
|
3379
3475
|
if (!resolved.ok) {
|
|
@@ -3382,14 +3478,16 @@ function registerSessionsCommand(program2) {
|
|
|
3382
3478
|
await runOnce(query || t24("sessions.default_query"), {}, resolved.id);
|
|
3383
3479
|
});
|
|
3384
3480
|
}
|
|
3385
|
-
function resolveSessionId(input2) {
|
|
3481
|
+
function resolveSessionId(input2, opts = {}) {
|
|
3386
3482
|
return withSessions((sm) => {
|
|
3387
3483
|
if (!input2) {
|
|
3388
3484
|
const latest = sm.getLatest()?.meta.id;
|
|
3389
3485
|
return latest ? { ok: true, id: latest } : { ok: false, error: t24("sessions.err_none") };
|
|
3390
3486
|
}
|
|
3391
3487
|
if (sm.get(input2)) return { ok: true, id: input2 };
|
|
3392
|
-
const
|
|
3488
|
+
const pool = sm.list({ limit: 200 }).sessions;
|
|
3489
|
+
const all = opts.includeArchived ? [...pool, ...sm.list({ limit: 200, archived: true }).sessions] : pool;
|
|
3490
|
+
const candidates = all.filter((s) => s.id.startsWith(input2)).map((s) => s.id);
|
|
3393
3491
|
if (candidates.length === 1) return { ok: true, id: candidates[0] };
|
|
3394
3492
|
if (candidates.length === 0) {
|
|
3395
3493
|
return { ok: false, error: t24("sessions.err_not_found", { input: input2 }) };
|
|
@@ -4028,6 +4126,7 @@ async function runDoctor(opts) {
|
|
|
4028
4126
|
}
|
|
4029
4127
|
}
|
|
4030
4128
|
// src/schedule/manage.ts
|
|
4129
|
+
import { removeRecordings } from "@epoch-agent/core";
|
|
4031
4130
|
import { automationLogsDir, t as t30 } from "@epoch-agent/infra";
|
|
4032
4131
|
async function runSetEnabled(idOrPrefix, enabled) {
|
|
4033
4132
|
const ctx = await openSchedule();
|
|
@@ -4048,8 +4147,8 @@ async function runRemove(idOrPrefix) {
|
|
|
4048
4147
|
const def = mustFind(ctx.store, idOrPrefix);
|
|
4049
4148
|
if (def.osTaskId) reportRegistration(await ctx.registrar.unregister(def), false);
|
|
4050
4149
|
ctx.store.remove(def.id);
|
|
4150
|
+
removeRecordings(automationLogsDir(def.id, ctx.homeDir));
|
|
4051
4151
|
log9(t30("schedule.removed", { name: def.name }));
|
|
4052
|
-
log9(t30("schedule.removed_logs_kept", { dir: automationLogsDir(def.id, ctx.homeDir) }));
|
|
4053
4152
|
} finally {
|
|
4054
4153
|
ctx.close();
|
|
4055
4154
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@epoch-agent/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.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/server": "0.
|
|
30
|
-
"@epoch-agent/
|
|
25
|
+
"@epoch-agent/core": "0.12.0",
|
|
26
|
+
"@epoch-agent/infra": "0.12.0",
|
|
27
|
+
"@epoch-agent/protocol": "0.12.0",
|
|
28
|
+
"@epoch-agent/runtime": "0.12.0",
|
|
29
|
+
"@epoch-agent/server": "0.12.0",
|
|
30
|
+
"@epoch-agent/tui": "^0.12.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^22.20.1",
|