akm-cli
Version:
akm (Agent Knowledge Manager) — a portable, local-first capability library for AI agents. Discover, load, share, and improve reusable skills, scripts, workflows, and knowledge across any shell-capable coding agent, including Claude Code, OpenCode, and Cur
103 lines (102 loc) • 4.57 kB
JavaScript
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
/**
* Observability command cluster — `akm log` (append-only events stream).
*
* `log` reads the append-only state.db events stream.
*
* `log` is a leaf command with the `--since @offset:<id>` durable cursor
* and --ref/--type filters.
*
* The embedded agent guide (`akm hints`) lives in src/cli.ts, so its
* loading code is intentionally outside this module.
*
* The leaf handler's body is a plain `runWithJsonErrors(...) + output(...)`,
* migrated onto `defineJsonCommand`, which emits the same JSON envelope
* (stdout/stderr/exit-code) as the inline form.
*/
import { parsePositiveIntFlag } from "../cli/parse-args.js";
import { defineJsonCommand, output, parseAllFlagValues } from "../cli/shared.js";
import { UsageError } from "../core/errors.js";
import { akmEventsList } from "./log.js";
import { akmTasksHistory } from "./tasks/tasks.js";
// ── `akm log` ────────────────────────────────────────────────────────────────
// Append-only events stream surface (#204). Reads state.db events with
// optional --since/--type/--ref filters.
//
// The internal output()/shape-registry command name is `log-list`. It never
// reaches the wire: `shapeEventsOutput` (src/output/shapes/helpers.ts) builds
// its own envelope and never stamps a `shape` field.
export const logCommand = defineJsonCommand({
meta: {
name: "log",
description: "Deprecated, removed in 0.11: use `akm doctor log`. List events from the append-only state.db events stream",
},
args: {
since: {
type: "string",
description: "ISO timestamp / epoch ms, OR `@offset:<id>` for a durable row-id cursor (resume across processes)",
},
type: { type: "string", description: "Filter by event type (add, remove, remember, feedback, ...)" },
ref: { type: "string", description: "Filter by asset ref ([bundle//]conceptId)" },
run: {
type: "string",
description: "Filter to a workflow run's events (metadata.runId), e.g. the id from `akm run`",
},
"exclude-tags": {
type: "string",
description: "Exclude events matching these tags (repeatable)",
},
"include-tags": {
type: "string",
description: "Only include events with ALL these tags (repeatable)",
},
limit: {
type: "string",
description: "Return only the most recent N events matching every other filter (default: unlimited)",
},
},
run({ args }) {
const excludeTags = parseAllFlagValues("--exclude-tags");
const includeTags = parseAllFlagValues("--include-tags");
const limit = parsePositiveIntFlag(args.limit);
const result = akmEventsList({
since: args.since,
type: args.type,
ref: args.ref,
run: args.run,
...(excludeTags.length > 0 ? { excludeTags } : {}),
...(includeTags.length > 0 ? { includeTags } : {}),
...(limit !== undefined ? { limit } : {}),
});
output("log-list", result);
},
});
/**
* `akm doctor log`: the events stream above, plus `--task <id>` for per-run task
* history (the same rows and fields as `akm task history <id>`, including `trigger`).
*/
export const doctorLogCommand = defineJsonCommand({
meta: {
name: "log",
description: "List events from the append-only state.db events stream, or one task's runs with --task <id>",
},
args: {
...logCommand.args,
task: { type: "string", description: "Task id: list its run history instead of events" },
bundle: { type: "string", description: "Bundle the --task id belongs to" },
},
async run(context) {
const task = context.args.task;
if (task === undefined) {
await logCommand.run?.(context);
return;
}
if (task.trim() === "") {
throw new UsageError("akm doctor log --task needs a task id: --task <id>.", "INVALID_FLAG_VALUE");
}
const limit = parsePositiveIntFlag(context.args.limit);
output("task-history", await akmTasksHistory({ id: task, limit, target: context.args.bundle }));
},
});