@staix/agent-mem 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.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/brief-curated.ts +8 -4
- package/src/cli-agent-reads.ts +55 -4
- package/src/cli.ts +222 -93
- package/src/commands-table.ts +332 -171
- package/src/index.ts +5 -0
- package/src/memory/capacity-text.ts +100 -0
- package/src/memory/capacity.ts +1 -57
- package/src/memory/commands.ts +45 -9
- package/src/memory/curated-cache-state.ts +22 -3
- package/src/memory/doctor-text.ts +144 -0
- package/src/memory/doctor.ts +9 -86
- package/src/memory/eval-audit-text.ts +62 -0
- package/src/memory/eval-audit.ts +1 -34
- package/src/memory/eval-text.ts +32 -0
- package/src/memory/eval.ts +1 -14
- package/src/memory/formats.ts +2 -0
- package/src/memory/gc-text.ts +22 -0
- package/src/memory/gc.ts +0 -6
- package/src/memory/generation-index.ts +1 -1
- package/src/memory/index-file.ts +1 -1
- package/src/memory/metrics.ts +18 -10
- package/src/memory/migrate-text.ts +32 -0
- package/src/memory/migrate.ts +0 -29
- package/src/memory/prune-text.ts +29 -0
- package/src/memory/prune.ts +0 -26
- package/src/memory/report-text.ts +233 -0
- package/src/memory/shard-migration-text.ts +40 -0
- package/src/memory/shard-migration.ts +0 -37
- package/src/memory/status-text.ts +72 -29
- package/src/memory/store.ts +112 -17
- package/src/memory/style.ts +98 -1
- package/src/memory/sync-placement-bound.ts +2 -2
- package/src/memory/sync-placement-checkpoint-person.ts +1 -1
- package/src/memory/sync-placement-noop-cache.ts +93 -0
- package/src/memory/sync-placement-refusal-category.ts +18 -0
- package/src/memory/sync-placement-transport.ts +43 -7
- package/src/memory/sync-progress-text.ts +7 -0
- package/src/memory/sync-progress.ts +21 -7
- package/src/memory/sync-screen.ts +13 -0
- package/src/memory/work-lists.ts +6 -4
- package/src/setup-drift.ts +1 -1
- package/src/setup-writer-roots.ts +136 -0
- package/src/setup.ts +122 -159
- package/src/sync-placement-writer-context.ts +8 -3
- package/src/ui/plugin.ts +4 -2
- package/src/work-brief-preparation.ts +28 -0
package/src/commands-table.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { HOOK_EVENTS } from "./hook-contract.ts";
|
|
2
2
|
import { GOAL_STATES, KINDS } from "./memory/store.ts";
|
|
3
|
+
import { cellWidth, wrap } from "@staix/cli-output";
|
|
3
4
|
import { wrapReport } from "./memory/style.ts";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
export interface
|
|
6
|
+
/** `number` and `date` are help labels for a text value (#590 H3); the parser and completion treat them as text. */
|
|
7
|
+
export interface OptionDefinition { description: string; details?: string; value?: "text" | "path" | "number" | "date" | readonly string[] }
|
|
8
|
+
export interface ArgumentDefinition { name: string; values?: readonly string[]; path?: boolean; variadic?: boolean; optional?: boolean }
|
|
9
|
+
export type CommandGroup = "read" | "write" | "review" | "maintenance" | "setup";
|
|
7
10
|
export interface CommandDefinition {
|
|
11
|
+
/** #590 H1: one imperative verb phrase, at most 60 ASCII characters, no design references. */
|
|
8
12
|
description: string;
|
|
13
|
+
/** Longer description, shown under `▸ Details` in this command's help. */
|
|
14
|
+
details?: string;
|
|
15
|
+
/** #590 H6: complete command lines, each resolved against `COMMANDS` by the help lint. */
|
|
16
|
+
examples?: readonly string[];
|
|
17
|
+
/** Root overview group of a top-level command (#590 H2). */
|
|
18
|
+
group?: CommandGroup;
|
|
9
19
|
options?: Record<string, OptionDefinition>;
|
|
10
20
|
args?: readonly ArgumentDefinition[];
|
|
11
21
|
commands?: Record<string, CommandDefinition>;
|
|
@@ -14,170 +24,273 @@ export interface CommandDefinition {
|
|
|
14
24
|
policyFree?: boolean;
|
|
15
25
|
defaultCommand?: string;
|
|
16
26
|
}
|
|
17
|
-
const flag = (description: string): OptionDefinition => ({ description });
|
|
18
|
-
const text = (description: string): OptionDefinition => ({ description, value: "text" });
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
"--
|
|
27
|
+
const flag = (description: string, details?: string): OptionDefinition => ({ description, ...(details ? { details } : {}) });
|
|
28
|
+
const text = (description: string, details?: string): OptionDefinition => ({ description, value: "text", ...(details ? { details } : {}) });
|
|
29
|
+
const number = (description: string, details?: string): OptionDefinition => ({ description, value: "number", ...(details ? { details } : {}) });
|
|
30
|
+
const date = (description: string, details?: string): OptionDefinition => ({ description, value: "date", ...(details ? { details } : {}) });
|
|
31
|
+
const path = (description: string, details?: string): OptionDefinition => ({ description, value: "path", ...(details ? { details } : {}) });
|
|
32
|
+
const json = (what: string) => ({ "--json": flag(`Print ${what} as JSON`) });
|
|
33
|
+
const history = { "--history": flag("Read retained supersession and expiry history", "Forgotten text stays hidden."),
|
|
34
|
+
"--as-of": date("Read memory as of a past UTC date or timestamp", "Current forget and prune masks still apply.") };
|
|
35
|
+
const policy = { "--policy-free": flag("Accepted and ignored", "The configured privacy policy always applies.") };
|
|
36
|
+
// Declared on import codex and claude-auto so their handler keeps its own refusal text for these claude-mem flags.
|
|
37
|
+
const claudeMemOnly = Object.fromEntries(["--db", "--limit", "--restart", "--capture-days"].map(name => [name, { description: "Only for import claude-mem; refused here", ...(name === "--restart" ? {} : { value: "text" as const }) }])) as Record<string, OptionDefinition>;
|
|
38
|
+
const CANDIDATE_KINDS = ["correction", "fail", "decay", "memory", "promotion", "consolidation", "model-answer"] as const;
|
|
39
|
+
const filters = (what: string) => ({ ...json(what), "--tier": { description: "Memory tier", value: ["short", "long"] } as OptionDefinition,
|
|
40
|
+
"--kind": { description: "Note kind", value: KINDS } as OptionDefinition, "--peer": text("Author peer"), "--machine": text("Machine ID"),
|
|
41
|
+
"--since": date("Only notes since this ISO date or time"), "--limit": number("Maximum results") });
|
|
25
42
|
export const GLOBAL_OPTIONS = { "--help": flag("Show help"), "--color": { description: "Color output: auto, always or never", value: ["auto", "always", "never"] } as OptionDefinition, "--ascii": flag("Use ASCII markers") };
|
|
26
|
-
export const ROOT_OPTIONS = { "--version": flag("Show version"), ...json };
|
|
43
|
+
export const ROOT_OPTIONS = { "--version": flag("Show version"), ...json("the notes") };
|
|
44
|
+
const setupTargets = ["claude", "codex", "kimi", "pi", "qwen", "jcode", "opencode", "gemini", "agy", "all", "console"] as const;
|
|
27
45
|
export const COMMANDS: Record<string, CommandDefinition> = {
|
|
28
|
-
consolidate: { description: "Queue
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"--
|
|
59
|
-
"--
|
|
46
|
+
consolidate: { group: "review", description: "Queue consolidation candidates for review", details: "Deterministic and project-local. Curated notes change only after explicit acceptance.",
|
|
47
|
+
examples: ["amem consolidate", "amem consolidate --json"], mutates: true,
|
|
48
|
+
options: { ...json("the queued candidates"), "--project": text("This project's key", "Another project is refused; run from its directory.") } },
|
|
49
|
+
setup: { group: "setup", description: "Preview or apply MCP setup and capture hooks",
|
|
50
|
+
details: "Covers native coding CLIs, or the acon console plugin manifest (console). Apply and undo use explicit flags.",
|
|
51
|
+
examples: ["amem setup claude", "amem setup all --apply"],
|
|
52
|
+
options: { ...json("the setup plan"), "--apply": flag("Apply the previewed setup"), "--undo": flag("Restore the original configuration"),
|
|
53
|
+
"--verbose": flag("Show static notes and history lines (human output only)"),
|
|
54
|
+
"--root": path("Register this absolute install root", "Such as <install>/releases/<version>/, resolved to its real path, instead of the running one."),
|
|
55
|
+
"--adopt-current": flag("With --apply: adopt the current wiring", "Keeps a stale setup receipt aside (its entries were replaced at another install root) and adopts the current wiring, which --undo restores.") },
|
|
56
|
+
args: [{ name: "target", values: setupTargets }] },
|
|
57
|
+
skills: { group: "setup", description: "Export packaged skills to a directory", commands: {
|
|
58
|
+
export: { description: "Export self-contained skills", examples: ["amem skills export ./skills"], options: json("the export receipt"), args: [{ name: "dir", path: true }], mutates: true } } },
|
|
59
|
+
mcp: { group: "setup", description: "Run the project-bound MCP stdio server" },
|
|
60
|
+
manifest: { group: "setup", description: "Describe this install, its MCP tools and commands", details: "Package name, version, MCP server and tools (read-only ones marked), and the command list.",
|
|
61
|
+
examples: ["amem manifest --json"], options: json("the manifest") },
|
|
62
|
+
hook: { group: "setup", description: "Run a fail-open, context-only capture hook", examples: ["amem hook SessionStart"], args: [{ name: "event", values: [...HOOK_EVENTS, "jcode"] }] },
|
|
63
|
+
ingest: { group: "setup", description: "Capture native session transcripts incrementally", details: "Runs once per call; no watcher.",
|
|
64
|
+
examples: ["amem ingest codex", "amem ingest pi --since 2026-11-01"], options: { ...json("the ingest receipt"), "--since": date("Only transcripts since this ISO date or time") },
|
|
65
|
+
args: [{ name: "kind", values: ["codex", "kimi", "pi", "qwen"] }] },
|
|
66
|
+
"vault-candidates": { group: "read", description: "List screened durable vault candidates", details: "Per project, or across projects with --all-projects.",
|
|
67
|
+
examples: ["amem vault-candidates", "amem vault-candidates --all-projects --limit 20"],
|
|
68
|
+
options: { ...json("the candidates"), "--limit": number("Maximum candidates per project (1..100)"),
|
|
69
|
+
"--all-projects": flag("List every active project's candidates", "The reply says it crossed projects."), "--project": text("List one named project's candidates") } },
|
|
70
|
+
list: { group: "read", description: "List memory notes", examples: ["amem list --kind decision", "amem list --since 2026-11-01 --limit 20"],
|
|
71
|
+
options: { ...filters("the notes"), ...history, "--ungrouped": flag("Accepted for parity with search", "list never folds notes.") } },
|
|
72
|
+
search: { group: "read", description: "Rank this project's curated notes",
|
|
73
|
+
details: "History, as-of and empty queries keep newest-first filtering.",
|
|
74
|
+
examples: ["amem search release gate", "amem search sync --all-projects"],
|
|
75
|
+
options: { ...filters("the ranked notes"), ...history,
|
|
76
|
+
"--filter": flag("Match every word as a substring, newest first", "Current-project curated notes only; not with --all-projects."),
|
|
77
|
+
"--explain": flag("Show the score factors of each result", "Ranked project-local results only."),
|
|
78
|
+
"--ungrouped": flag("List every note of a task, not the best hit"),
|
|
79
|
+
"--all-projects": flag("Search every active project", "The reply says it crossed projects."),
|
|
80
|
+
"--include-archived": flag("With --all-projects, read archived projects") }, args: [{ name: "words", variadic: true }] },
|
|
81
|
+
brief: { group: "read", description: "Read the fails, decisions and contracts for an intent",
|
|
82
|
+
details: "Fails first, then decisions and contracts, as untrusted data within a UTF-8 byte cap.",
|
|
83
|
+
examples: ["amem brief --for sync-lock", "amem brief --for review --paths src/cli.ts"],
|
|
84
|
+
options: { ...json("the brief"), "--for": text("Explicit intent"), "--paths": text("Named path (repeatable)"), "--symbols": text("Named symbol (repeatable)"),
|
|
85
|
+
"--bytes": number("Brief body byte cap (1..8192, default 2048)") } },
|
|
86
|
+
projects: { group: "read", description: "List the project shards of this memory home", examples: ["amem projects", "amem projects --all"],
|
|
87
|
+
options: { ...json("the projects"), "--all": flag("Include forgotten projects", "Archived projects are always listed.") } },
|
|
88
|
+
usage: { group: "read", description: "Show totals and the largest project shards", examples: ["amem usage", "amem usage --limit 5"],
|
|
89
|
+
options: { ...json("the usage totals"), "--limit": number("Largest shards to list (1..100)"), "--all": flag("Include forgotten projects") } },
|
|
90
|
+
eval: { group: "maintenance", description: "Measure search recall@k and MRR on a question set",
|
|
91
|
+
details: "Replays a local question set against ranked search. No model and no network. Without --set it uses the built-in synthetic set; --set ko uses the built-in Korean one.",
|
|
92
|
+
examples: ["amem eval", "amem eval --set ko --k 1,5"],
|
|
93
|
+
options: { ...json("the eval report"),
|
|
94
|
+
"--set": path("Built-in set name (ko) or a question set file", "A file uses amem.eval/v1. With entries it is self-contained; without them its ids name entries of this project."),
|
|
95
|
+
"--k": text("Cutoffs, comma separated (default 1,5,10)", "Each cutoff is 1..100.") }, commands: {
|
|
96
|
+
audit: { description: "Audit whether stored notes are still right", details: "Sample a private sheet, judge it outside amem, then score it. No model and no network.", options: json("the audit result"), commands: {
|
|
97
|
+
sample: { description: "Draw a seeded sample of notes into a private sheet",
|
|
98
|
+
details: "Stratified over this project's curated notes, with anchor status and empty judge columns, in a 0600 sheet.",
|
|
99
|
+
examples: ["amem eval audit sample --seed s1", "amem eval audit sample --seed s1 --n 20"],
|
|
100
|
+
options: { ...json("the sheet receipt"),
|
|
101
|
+
"--project": text("Project key to audit (default: this directory's)"), "--n": number("Notes to draw (1..200, default 40)"),
|
|
102
|
+
"--seed": text("Required seed: 1..64 of letters, digits, . _ -", "The same seed and store draw the same sample."),
|
|
103
|
+
"--as-of": date("Instant the note ages are measured at", "A canonical UTC date or timestamp; default now. Recorded in the sheet so the same seed and as-of draw the same sample."),
|
|
104
|
+
"--out": path("Sheet path (default: this home's eval/ directory)", "Never overwritten, always 0600.") } },
|
|
105
|
+
score: { description: "Score a filled sheet into content-free counts",
|
|
106
|
+
details: "Counts per kind, age and anchor, and Cohen's kappa. Refuses any leak of note text or a path.",
|
|
107
|
+
examples: ["amem eval audit score ./sheet.tsv"], options: json("the score"), args: [{ name: "sheet" }] },
|
|
108
|
+
} } } },
|
|
109
|
+
spool: { group: "maintenance", description: "Maintain the hook spool outside hooks", options: json("the replay plan or receipt"), commands: {
|
|
110
|
+
replay: { description: "Preview or apply a replay of parked hook records",
|
|
111
|
+
details: "The preview is read-only and shows no record bodies. --apply takes the saved preview.",
|
|
112
|
+
examples: ["amem spool replay --json", "amem spool replay --apply --plan plan.json"], mutates: "apply",
|
|
113
|
+
options: { ...json("the replay plan or receipt"),
|
|
114
|
+
"--source": path("Private parked directory to read instead", "An absolute path, read instead of this home's hook spool."),
|
|
115
|
+
"--apply": flag("Apply the saved preview given with --plan"),
|
|
116
|
+
"--confirm-unverifiable": flag("With --apply: replay unproven cwd mappings too", "Also replays the saved plan's 'needs confirmation' cwd -> project mappings, which this boot cannot prove."),
|
|
117
|
+
"--plan": path("Saved preview from amem spool replay --json") } },
|
|
60
118
|
} },
|
|
61
|
-
gc: { description: "Apply each shard's retention and cap
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
119
|
+
gc: { group: "maintenance", description: "Apply each shard's retention and cap in batches", details: "Previews without --confirm.",
|
|
120
|
+
examples: ["amem gc", "amem gc --confirm --batches 10"], mutates: "confirm",
|
|
121
|
+
options: { ...json("the gc result"), "--confirm": flag("Evict now; without it, preview only"), "--batches": number("Evict windows per shard (1..1000, default 1)") } },
|
|
122
|
+
project: { group: "maintenance", description: "Export, import, archive or forget one project", options: json("the project receipt"), commands: {
|
|
123
|
+
export: { description: "Write one project's memory to a new export file",
|
|
124
|
+
details: "Capture, curated notes, goals and work lists, as JSON, JSONL or Markdown. Never overwrites.",
|
|
125
|
+
examples: ["amem project export repo@1234abcd --to ./repo.json"],
|
|
126
|
+
options: { ...json("the export receipt"), "--to": path("Destination file, outside the memory home"), "--format": { description: "Portable format (default json)", value: ["json", "jsonl", "markdown"] }, ...policy },
|
|
65
127
|
args: [{ name: "key" }] },
|
|
66
|
-
import: { description: "Preview or re-import
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
128
|
+
import: { description: "Preview or re-import notes from a JSONL export", details: "Keeps the original entry ids.",
|
|
129
|
+
examples: ["amem project import repo@1234abcd --from ./repo.jsonl", "amem project import repo@1234abcd --from ./repo.jsonl --confirm"],
|
|
130
|
+
options: { ...json("the import preview or receipt"), "--from": path("JSONL project export"), "--confirm": flag("Write after the preview"),
|
|
131
|
+
"--allow-shared": flag("Permit shared-scope notes from this file"), ...policy }, args: [{ name: "key" }], mutates: "confirm", policyFree: true },
|
|
132
|
+
archive: { description: "Take a cold project out of recall", details: "An append-only op; unarchive brings it back.", examples: ["amem project archive repo@1234abcd"],
|
|
133
|
+
options: json("the archive receipt"), args: [{ name: "key" }], mutates: true },
|
|
134
|
+
unarchive: { description: "Bring an archived project back into recall", details: "An append-only op.", examples: ["amem project unarchive repo@1234abcd"],
|
|
135
|
+
options: json("the unarchive receipt"), args: [{ name: "key" }], mutates: true },
|
|
136
|
+
forget: { description: "Forget one project for good", details: "An append-only op; previews without --confirm.", examples: ["amem project forget repo@1234abcd", "amem project forget repo@1234abcd --confirm"],
|
|
137
|
+
options: { ...json("the forget receipt"), "--confirm": flag("Record the forget after the preview") }, args: [{ name: "key" }], mutates: "confirm" },
|
|
70
138
|
} },
|
|
71
|
-
show: { description: "Show a note", options: { ...json, ...history }, args: [{ name: "id" }] },
|
|
72
|
-
graph: {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
139
|
+
show: { group: "read", description: "Show a note", examples: ["amem show abcdef12", "amem show abcdef12 --history"], options: { ...json("the note"), ...history }, args: [{ name: "id" }] },
|
|
140
|
+
graph: { group: "read", description: "Show the graph around a note or node", examples: ["amem graph abcdef12", "amem graph abcdef12 --hops 2"],
|
|
141
|
+
options: { ...json("the graph"), ...history, "--hops": { description: "Graph depth", value: ["1", "2"] } }, args: [{ name: "id-or-node" }] },
|
|
142
|
+
suggestions: { group: "review", description: "List pending suggestions", examples: ["amem suggestions --json"], options: json("the suggestions") },
|
|
143
|
+
confirm: { group: "review", description: "Confirm a suggestion", examples: ["amem confirm abcdef12"], options: json("the receipt"), args: [{ name: "id" }], mutates: true },
|
|
144
|
+
reject: { group: "review", description: "Reject a suggestion", examples: ["amem reject abcdef12"], options: json("the receipt"), args: [{ name: "id" }], mutates: true },
|
|
145
|
+
promote: { group: "write", description: "Promote a note, or copy it into the repository log",
|
|
146
|
+
details: "With --to repo, appends the note's screened line to this repository's .amem/log.jsonl.",
|
|
147
|
+
examples: ["amem promote abcdef12", "amem promote abcdef12 --to repo --confirm"],
|
|
148
|
+
options: { ...json("the receipt"), ...policy, "--to": { description: "Promote into the repository scope", value: ["repo"] },
|
|
149
|
+
"--confirm": flag("With --to repo: append the previewed line"),
|
|
150
|
+
"--confirm-public": text("With --to repo: the entry id's first 8 characters", "Required unless the repository is verified private.") }, args: [{ name: "id" }], mutates: true, policyFree: true },
|
|
151
|
+
repo: { group: "maintenance", description: "Show or set up this repository's memory log", details: "The repository scope is this repository's .amem/log.jsonl.", options: json("the repository status"), defaultCommand: "status", commands: {
|
|
152
|
+
status: { description: "Show the repository log and what the screen withheld", examples: ["amem repo status --json"], options: json("the repository status") },
|
|
153
|
+
attributes: { description: "Add the merge=union entry to .gitattributes", details: "For .amem/log.jsonl. Previews without --confirm; never committed.",
|
|
154
|
+
examples: ["amem repo attributes", "amem repo attributes --confirm"], mutates: "confirm", options: { "--confirm": flag("Write after the preview") } },
|
|
81
155
|
} },
|
|
82
|
-
demote: { description: "Demote a note", options: json, args: [{ name: "id" }], mutates: true },
|
|
83
|
-
forget: { description: "Forget a note", options: json, args: [{ name: "id" }], mutates: true },
|
|
84
|
-
note: { description: "Write curated notes through the configured policy
|
|
85
|
-
add: { description: "Add one curated note
|
|
86
|
-
|
|
87
|
-
"--
|
|
88
|
-
|
|
89
|
-
|
|
156
|
+
demote: { group: "write", description: "Demote a note", examples: ["amem demote abcdef12"], options: json("the receipt"), args: [{ name: "id" }], mutates: true },
|
|
157
|
+
forget: { group: "write", description: "Forget a note", examples: ["amem forget abcdef12"], options: json("the receipt"), args: [{ name: "id" }], mutates: true },
|
|
158
|
+
note: { group: "write", description: "Write curated notes through the configured policy", options: json("the new note id"), commands: {
|
|
159
|
+
add: { description: "Add one curated note",
|
|
160
|
+
details: "Text as arguments, - to type it until end of input, or no text to open $EDITOR. A fail note takes --approach, --symptom, --cause, --evidence (repeatable) and --retry-when.",
|
|
161
|
+
examples: ["amem note add --kind decision Use one lock per home", "amem note add --kind fail --approach retry --symptom timeout -"], mutates: true,
|
|
162
|
+
options: { ...json("the new note id"),
|
|
163
|
+
"--kind": { description: "Note kind (default finding)", value: KINDS }, "--tier": { description: "Memory tier (default long)", value: ["short", "long"] },
|
|
164
|
+
"--scope": { description: "Scope (default project)", value: ["project", "shared"] }, "--title": text("One-line title"),
|
|
165
|
+
"--approach": text("fail: what was tried"), "--symptom": text("fail: what went wrong"), "--cause": text("fail: why"), "--evidence": text("fail: a reference (repeatable)"),
|
|
166
|
+
"--retry-when": text("fail: when the approach is worth retrying") },
|
|
167
|
+
args: [{ name: "text", variadic: true, optional: true }] },
|
|
90
168
|
} },
|
|
91
|
-
supersede: { description: "Replace a note", options: json, args: [{ name: "old-id" }, { name: "new-id" }], mutates: true },
|
|
92
|
-
rebuild: { description: "Rebuild the derived index", options: json, mutates: true },
|
|
93
|
-
dedupe: { description: "Preview duplicate reconciliation",
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
169
|
+
supersede: { group: "write", description: "Replace a note with a newer one", examples: ["amem supersede abcdef12 0123abcd"], options: json("the receipt"), args: [{ name: "old-id" }, { name: "new-id" }], mutates: true },
|
|
170
|
+
rebuild: { group: "maintenance", description: "Rebuild the derived index", examples: ["amem rebuild"], options: json("the rebuild receipt"), mutates: true },
|
|
171
|
+
dedupe: { group: "maintenance", description: "Preview duplicate reconciliation", examples: ["amem dedupe", "amem dedupe --apply"],
|
|
172
|
+
options: { ...json("the reconciliation preview"), "--apply": flag("Append reconciliation operations") }, mutates: "apply" },
|
|
173
|
+
sync: { group: "maintenance", description: "Sync with a private remote",
|
|
174
|
+
details: "--if-due syncs only when the schedule and the failure backoff allow it; --force ignores both.",
|
|
175
|
+
examples: ["amem sync", "amem sync --if-due"],
|
|
176
|
+
options: { ...json("the sync result"), ...policy, "--remote": text("Private git URL"),
|
|
177
|
+
"--if-due": flag("Sync only when due; stops after 30 seconds", "Due hourly after a success; after failures the wait starts at 15 minutes and doubles up to a day."),
|
|
178
|
+
"--force": flag("With --if-due: ignore the schedule and backoff"),
|
|
179
|
+
"--progress": { description: "Placement sync progress on stderr", value: ["auto", "human", "json", "off"],
|
|
180
|
+
details: "auto prints human lines when stderr is a terminal and nothing otherwise; json prints one versioned event per line. stdout is unchanged." },
|
|
181
|
+
"--status": flag("Show recorded placement sync operations", "Read-only: running, finished or interrupted operations. Opens no memory and takes no lock.") }, mutates: true, policyFree: true },
|
|
182
|
+
machine: { group: "maintenance", description: "Show or label this machine", examples: ["amem machine", "amem machine --label laptop"], options: { ...json("the machine"), "--label": text("Machine label") }, mutates: "label" },
|
|
183
|
+
import: { group: "write", description: "Import external memory", mutates: true, policyFree: true,
|
|
184
|
+
options: { ...json("the import receipt"), ...policy, "--db": path("SQLite database file"), "--limit": number("Maximum observations"), "--restart": flag("Restart the import cursor"),
|
|
185
|
+
"--capture-days": number("Also import recent days into capture") },
|
|
100
186
|
commands: {
|
|
101
|
-
"claude-mem": { description: "Import claude-mem observations",
|
|
102
|
-
|
|
103
|
-
|
|
187
|
+
"claude-mem": { description: "Import claude-mem observations", examples: ["amem import claude-mem", "amem import claude-mem --capture-days 7"],
|
|
188
|
+
options: { ...json("the import receipt"), ...policy, "--db": path("SQLite database file"), "--limit": number("Maximum observations"), "--restart": flag("Restart the import cursor"),
|
|
189
|
+
"--capture-days": number("Also import recent days into capture", "Imports recent claude-mem observations and summaries into capture.") } },
|
|
190
|
+
"claude-auto": { description: "Import Claude Code auto memory as candidates", details: "CLAUDE.md and AGENTS.md stay excluded.", examples: ["amem import claude-auto"],
|
|
191
|
+
options: { ...json("the import receipt"), ...policy, "--from": path("Claude projects directory (default ~/.claude/projects)"), ...claudeMemOnly } },
|
|
192
|
+
codex: { description: "Import Codex memories as review candidates", details: "The originals stay unchanged.", examples: ["amem import codex"],
|
|
193
|
+
options: { ...json("the import receipt"), ...policy, "--from": path("Codex memories directory (default ~/.codex/memories)"), ...claudeMemOnly } },
|
|
104
194
|
} },
|
|
105
|
-
goal: { description: "
|
|
106
|
-
list: { description: "List goals", options: { "--all": flag("Include completed goals") } },
|
|
107
|
-
show: { description: "Show a goal", args: [{ name: "id" }] },
|
|
108
|
-
new: { description: "Create a goal",
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
195
|
+
goal: { group: "write", description: "Track long-term goals", options: json("the goals"), defaultCommand: "list", commands: {
|
|
196
|
+
list: { description: "List goals", examples: ["amem goal list --all"], options: { ...json("the goals"), "--all": flag("Include completed goals") } },
|
|
197
|
+
show: { description: "Show a goal", examples: ["amem goal show abcdef12"], options: json("the goal"), args: [{ name: "id" }] },
|
|
198
|
+
new: { description: "Create a goal", examples: ["amem goal new Ship the sync checkpoint", "amem goal new --shared --milestone draft Write the spec"],
|
|
199
|
+
options: { "--milestone": text("Milestone (repeatable)"), "--depends": text("Dependency goal ID (repeatable)"), "--shared": flag("Share across projects") }, args: [{ name: "title", variadic: true }], mutates: true },
|
|
200
|
+
link: { description: "Link a goal to a host task board task", details: "Needs a host that has a task board; amem alone has none.", examples: ["amem goal link abcdef12 42"], args: [{ name: "id" }, { name: "task-id" }], mutates: true },
|
|
201
|
+
state: { description: "Set a goal's state", examples: ["amem goal state abcdef12 blocked"], args: [{ name: "id" }, { name: "state", values: GOAL_STATES }], mutates: true },
|
|
202
|
+
done: { description: "Complete a goal", examples: ["amem goal done abcdef12"], options: json("the promotion offer"), args: [{ name: "id" }], mutates: true },
|
|
203
|
+
take: { description: "Take a goal lease", examples: ["amem goal take abcdef12", "amem goal take abcdef12 --force"], options: { "--force": flag("Override the prior lease") }, args: [{ name: "id" }], mutates: true },
|
|
113
204
|
} },
|
|
114
|
-
review: { description: "Review machine-local
|
|
115
|
-
targets: { description: "List notes to re-check in
|
|
116
|
-
|
|
205
|
+
review: { group: "review", description: "Review machine-local memory candidates", options: json("the candidates"), defaultCommand: "list", commands: {
|
|
206
|
+
targets: { description: "List notes to re-check, in priority order", examples: ["amem review targets --limit 10"],
|
|
207
|
+
options: { ...json("the targets"), "--project": text("Current project or alias"), "--limit": number("Maximum targets (1..500, default 50)") } },
|
|
208
|
+
list: { description: "List review candidates", examples: ["amem review list --status all", "amem review list --kind fail --json"], options: { ...json("the candidates"),
|
|
117
209
|
"--status": { description: "Candidate status", value: ["pending", "accepting", "accepted", "rejected", "all"] },
|
|
118
|
-
"--kind": { description: "Candidate kind", value:
|
|
210
|
+
"--kind": { description: "Candidate kind", value: CANDIDATE_KINDS }, "--limit": number("Maximum candidates (1..500)"),
|
|
119
211
|
} },
|
|
120
|
-
accept: { description: "Accept one candidate through the
|
|
121
|
-
|
|
122
|
-
|
|
212
|
+
accept: { description: "Accept one candidate through the memory policy", examples: ["amem review accept <full-candidate-id>"],
|
|
213
|
+
options: { ...json("the accepted note"), ...policy, "--kind": { description: "Require the selected candidate kind", value: CANDIDATE_KINDS } }, args: [{ name: "full-candidate-id" }], mutates: true, policyFree: true },
|
|
214
|
+
reject: { description: "Reject one candidate", examples: ["amem review reject <full-candidate-id>"], options: json("the receipt"), args: [{ name: "full-candidate-id" }], mutates: true },
|
|
215
|
+
decide: { description: "Decide one candidate without a terminal",
|
|
216
|
+
details: "Without --confirm it previews the candidate (stamped shown); with --confirm it accepts, rejects or defers it.",
|
|
217
|
+
examples: ["amem review decide <full-candidate-id> accept", "amem review decide <full-candidate-id> reject --confirm"],
|
|
218
|
+
options: { ...json("the decision"), ...policy, "--confirm": flag("Apply the previewed decision") },
|
|
123
219
|
args: [{ name: "full-candidate-id" }, { name: "decision", values: ["accept", "reject", "defer"] }], mutates: "confirm", policyFree: true },
|
|
124
|
-
walk: { description: "Walk the pending candidates one by one:
|
|
220
|
+
walk: { description: "Walk the pending candidates one by one", details: "Accept, edit (as a new note), reject, skip or quit each one.", examples: ["amem review walk", "amem review walk --kind fail"], mutates: true,
|
|
221
|
+
options: { "--kind": { description: "Candidate kind", value: CANDIDATE_KINDS } } },
|
|
125
222
|
} },
|
|
126
|
-
decay: { description: "Preview old live long-term notes
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
"
|
|
133
|
-
|
|
134
|
-
"--
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
...json, "--cap-mb": text("Capture cap in MB"), "--retention-days": text("Capture retention in days"), "--confirm": flag("Write after the preview"),
|
|
158
|
-
"--split": flag("Write the per-shard split of the global budget to each shard's own config") } },
|
|
223
|
+
decay: { group: "review", description: "Preview demoting old notes no open goal protects", details: "Old live long-term notes. Apply only with --apply --confirm.",
|
|
224
|
+
examples: ["amem decay", "amem decay --days 180 --apply --confirm"], mutates: "apply",
|
|
225
|
+
options: { ...json("the decay preview"), "--days": number("Age in whole days (default 90)"), "--propose": flag("Queue unused-injection candidates for review"),
|
|
226
|
+
"--apply": flag("Preview exact revisions", "Combine with --confirm to apply them."), "--confirm": flag("Apply the exact revision preview with --apply"),
|
|
227
|
+
"--forget": flag("Forget instead of demoting", "The confirmation names this action.") }, args: [{ name: "id", variadic: true, optional: true }] },
|
|
228
|
+
migrate: { group: "maintenance", description: "Preview or apply a memory home migration",
|
|
229
|
+
details: "Generation, shard, public prune view and sync placement migrations. Each previews by default and applies only with --apply; --deactivate selects shared v1 explicitly.",
|
|
230
|
+
examples: ["amem migrate --dry-run", "amem migrate --sync-placement --dry-run"], mutates: "apply",
|
|
231
|
+
options: { ...json("the migration receipt"), "--apply": flag("Apply the previewed migration"), "--dry-run": flag("Read-only receipt (default; kept as an alias)"), "--generation": text("Explicit 32-hex generation ID"),
|
|
232
|
+
"--resume": flag("Resume the recorded migration"), "--deactivate": flag("Select shared v1 without deleting a generation"),
|
|
233
|
+
"--shards": flag("Migrate the curated home into shards", "Project and user shards."),
|
|
234
|
+
"--public-prune-view": flag("Enable the v2 public prune view on a split", "Forward-only, on an active split."),
|
|
235
|
+
"--sync-placement": flag("Activate placement sync on this memory home", "Forward-only. Previews by default and applies with --apply; no automatic migration or renewal."),
|
|
236
|
+
"--list-remote": flag("List remote project refs outside the inventory", "By hash, outside the active inventory."),
|
|
237
|
+
"--abandon": flag("Discard an interrupted placement attempt", "Pre-commit only. Initial activation requires both markers to match their original v2 bytes; realm admission requires --confirm."),
|
|
238
|
+
"--admit": text("Admit one new curated project realm", "A realm that appeared after activation, into the same epoch. Previews without --apply."),
|
|
239
|
+
"--from-remote": flag("Admit the named remote-only realm", "Uses the configured placement sync remote."),
|
|
240
|
+
"--confirm": flag("Confirm the previewed abandonment or checkpoint"),
|
|
241
|
+
"--checkpoint": flag("Preview a placement checkpoint", "Person-reviewed: preview by default, then --confirm --plan, --resume or --abandon."),
|
|
242
|
+
"--checkpoint-on-bound": { description: "Preview the sync-run checkpoint opt-in", value: ["on", "off"], details: "Turns the home opt-in on or off; --confirm writes it to amem.config.json." },
|
|
243
|
+
"--plan": path("Saved --checkpoint --json preview to confirm"),
|
|
244
|
+
"--writer-root": path("Writer inventory install root (repeatable)", "An absolute amem install root; repeat it for the complete local writer inventory."),
|
|
245
|
+
} },
|
|
246
|
+
status: { group: "read", description: "Show the memory home, policy and migration state", examples: ["amem status", "amem status --verbose"],
|
|
247
|
+
options: { ...json("the status object"), "--verbose": flag("Show static notes and history lines (human output only)") } },
|
|
248
|
+
formats: { group: "maintenance", description: "Raise format floors in formats.json", commands: {
|
|
249
|
+
raise: { description: "Preview or append a format floor record",
|
|
250
|
+
details: "Previews the record and the writer inventory; appends it to formats.json only with --confirm. Refused while any known writer is below the floor.",
|
|
251
|
+
examples: ["amem formats raise home 0.30.0", "amem formats raise home 0.30.0 --confirm"], mutates: "confirm",
|
|
252
|
+
options: { ...json("the floor preview or record"), "--confirm": flag("Append the previewed record") },
|
|
253
|
+
args: [{ name: "surface", values: ["home", "curated", "capture", "hook-spool", "candidates", "work-lists", "sync"] }, { name: "min-reader" }] },
|
|
159
254
|
} },
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
255
|
+
doctor: { group: "read", description: "Check this project's memory health, read-only",
|
|
256
|
+
details: "Duplicates and stale notes, pending candidates, capture freshness per CLI, the brief's token cost, index equals rebuild, reader leases, the policy in effect, and ingest and sync cadence.",
|
|
257
|
+
examples: ["amem doctor", "amem doctor --json"], options: { ...json("the doctor report"), "--verbose": flag("Show static notes and history lines (human output only)") } },
|
|
258
|
+
prune: { group: "maintenance", description: "Plan or apply exact-entry expiry in a generation", examples: ["amem prune --dry-run --cutoff 2026-01-01", "amem prune --apply --plan plan.json"], mutates: true,
|
|
259
|
+
options: { ...json("the prune plan or receipt"), "--cutoff": date("Canonical UTC expiry cutoff"), "--dry-run": flag("Print a local sealed plan without writes"),
|
|
260
|
+
"--user": flag("Select the user shard after a curated split", "Default: the current project."),
|
|
261
|
+
"--apply": flag("Apply the exact local plan"), "--plan": path("Sealed local plan JSON file") } },
|
|
262
|
+
capacity: { group: "maintenance", description: "Report capture use and propose capture bounds", examples: ["amem capacity", "amem capacity --disk-share 0.05"],
|
|
263
|
+
options: { ...json("the capacity report"), "--disk-share": number("Disk-share bound for the proposal (default 0.02)") }, commands: {
|
|
264
|
+
apply: { description: "Write the proposed capture bounds", details: "To the home capture config, or with --split each shard's share of the global budget.",
|
|
265
|
+
examples: ["amem capacity apply", "amem capacity apply --split --confirm"], mutates: true,
|
|
266
|
+
options: { ...json("the written bounds"), "--disk-share": number("Disk-share bound for the proposal (default 0.02)"),
|
|
267
|
+
"--cap-mb": number("Capture cap in MB"), "--retention-days": number("Capture retention in days"), "--confirm": flag("Write after the preview"),
|
|
268
|
+
"--split": flag("Write each shard's share of the global budget", "To each shard's own config.") } },
|
|
269
|
+
} },
|
|
270
|
+
alias: { group: "maintenance", description: "Map project keys onto a canonical key", options: json("the alias ops"), defaultCommand: "list", commands: {
|
|
271
|
+
list: { description: "List alias ops", examples: ["amem alias list --json"], options: json("the alias ops") },
|
|
272
|
+
add: { description: "Map one key onto its canonical key", details: "An append-only op.", examples: ["amem alias add old@1234abcd new@5678abcd"], options: json("the alias op"), args: [{ name: "from-key" }, { name: "to-key" }], mutates: true },
|
|
273
|
+
remove: { description: "Make an alias key resolve to itself again", details: "An append-only op; the latest op wins.", examples: ["amem alias remove old@1234abcd"], options: json("the alias op"), args: [{ name: "alias-key" }], mutates: true },
|
|
164
274
|
} },
|
|
165
|
-
completion: { description: "Print static shell completion", args: [{ name: "shell", values: ["zsh", "bash", "fish"] }] },
|
|
166
|
-
help: { description: "Show help"
|
|
275
|
+
completion: { group: "setup", description: "Print static shell completion", examples: ["amem completion zsh"], args: [{ name: "shell", values: ["zsh", "bash", "fish"] }] },
|
|
276
|
+
help: { group: "setup", description: "Show help for a command", examples: ["amem help status"], args: [{ name: "command", variadic: true, optional: true }] },
|
|
277
|
+
version: { group: "setup", description: "Show the version" },
|
|
167
278
|
};
|
|
168
279
|
|
|
169
280
|
export interface CompletionDefinition { path: string[]; options: Record<string, OptionDefinition>; args: ArgumentDefinition[]; children: string[] }
|
|
170
281
|
export function completionDefinitions(): CompletionDefinition[] {
|
|
171
282
|
const rows: CompletionDefinition[] = [{ path: [], options: { ...GLOBAL_OPTIONS, ...ROOT_OPTIONS, ...COMMANDS.list!.options }, args: [], children: Object.keys(COMMANDS) }];
|
|
172
|
-
|
|
283
|
+
// #590 H5: a command accepts its own options and the global ones, never a parent's. A group invoked bare also takes its
|
|
284
|
+
// default child's options, because the parser runs that child. Every flag a handler reads is declared on its own entry.
|
|
285
|
+
const walk = (commands: Record<string, CommandDefinition>, path: string[]) => {
|
|
173
286
|
for (const [name, command] of Object.entries(commands)) {
|
|
174
|
-
const next = [...path, name]
|
|
175
|
-
const options = { ...
|
|
287
|
+
const next = [...path, name];
|
|
288
|
+
const options = { ...GLOBAL_OPTIONS, ...command.options, ...(command.defaultCommand ? command.commands?.[command.defaultCommand]?.options : {}) };
|
|
176
289
|
rows.push({ path: next, options, args: [...command.args ?? []], children: Object.keys(command.commands ?? {}) });
|
|
177
|
-
if (command.commands) walk(command.commands, next
|
|
290
|
+
if (command.commands) walk(command.commands, next);
|
|
178
291
|
}
|
|
179
292
|
};
|
|
180
|
-
walk(COMMANDS, []
|
|
293
|
+
walk(COMMANDS, []); return rows;
|
|
181
294
|
}
|
|
182
295
|
export interface ParsedCommand { path: string[]; definition: CommandDefinition; options: Record<string, string | boolean>; positionals: string[]; rawArgs: string[] }
|
|
183
296
|
export class CommandUsageError extends Error { readonly exitCode = 2; }
|
|
@@ -236,44 +349,92 @@ export function parseCommand(argv: readonly string[]): ParsedCommand {
|
|
|
236
349
|
return { path, definition, options, positionals, rawArgs };
|
|
237
350
|
}
|
|
238
351
|
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
const width = Math.min(24, Math.max(...rows.map(([label]) => label.length)));
|
|
246
|
-
return rows.map(([label, description]) => ` ${label.padEnd(width)} ${description}`);
|
|
352
|
+
const valueLabel = (value: NonNullable<OptionDefinition["value"]>) => typeof value === "string" ? `<${value}>` : value.join("|");
|
|
353
|
+
const optionLabel = (name: string, option: OptionDefinition) => `${name}${option.value === undefined ? "" : ` ${valueLabel(option.value)}`}`;
|
|
354
|
+
const argLabel = (arg: ArgumentDefinition) => {
|
|
355
|
+
const body = arg.values && arg.values.length <= 4 ? arg.values.join("|") : `<${arg.name}>`;
|
|
356
|
+
const shown = arg.variadic ? `${body}...` : body;
|
|
357
|
+
return arg.optional ? `[${shown}]` : shown;
|
|
247
358
|
};
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
export function
|
|
359
|
+
const own = (row: CompletionDefinition) => Object.entries(row.options).filter(([name]) => !Object.hasOwn(GLOBAL_OPTIONS, name));
|
|
360
|
+
/** #590 H3: `amem <path> <required> [optional] [options]`; the flags are listed under `▸ Flags`, never inlined. */
|
|
361
|
+
export function usageLine(path: readonly string[]): string {
|
|
362
|
+
const row = completionDefinitions().find(candidate => candidate.path.join(" ") === path.join(" "));
|
|
363
|
+
if (!row || !path.length) return "amem <command> [options]";
|
|
364
|
+
const command = lookupCommand(path)!;
|
|
365
|
+
const args = command.commands && !command.defaultCommand ? ["<command>"] : row.args.map(argLabel);
|
|
366
|
+
return ["amem", ...path, ...args, ...(own(row).length ? ["[options]"] : [])].join(" ");
|
|
367
|
+
}
|
|
368
|
+
export function lookupCommand(path: readonly string[]): CommandDefinition | undefined {
|
|
369
|
+
let commands: Record<string, CommandDefinition> | undefined = COMMANDS, command: CommandDefinition | undefined;
|
|
370
|
+
for (const name of path) { if (!commands || !Object.hasOwn(commands, name)) return undefined; command = commands[name]!; commands = command.commands; }
|
|
371
|
+
return command;
|
|
372
|
+
}
|
|
373
|
+
/** The longest prefix of `argv` that names a command path; an option's value is never a command name. */
|
|
374
|
+
export function commandPath(argv: readonly string[]): string[] {
|
|
251
375
|
const path: string[] = [], rows = completionDefinitions();
|
|
252
|
-
let commands: Record<string, CommandDefinition> | undefined = COMMANDS,
|
|
376
|
+
let commands: Record<string, CommandDefinition> | undefined = COMMANDS, row = rows[0]!;
|
|
253
377
|
for (let i = 0; i < argv.length; i++) {
|
|
254
378
|
const token = argv[i]!;
|
|
255
|
-
if (token.startsWith("
|
|
256
|
-
// An option's value is never a command name.
|
|
257
|
-
if (!token.includes("=") && row.options[token]?.value !== undefined) i++;
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
379
|
+
if (token.startsWith("-")) { if (!token.includes("=") && row.options[token]?.value !== undefined) i++; continue; }
|
|
260
380
|
if (!commands || !Object.hasOwn(commands, token)) break;
|
|
261
|
-
|
|
381
|
+
path.push(token); commands = commands[token]!.commands;
|
|
262
382
|
row = rows.find(candidate => candidate.path.join(" ") === path.join(" "))!;
|
|
263
383
|
}
|
|
384
|
+
return path;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const HELP_WIDTH = 80, LABEL_WIDTH = 28;
|
|
388
|
+
const section = (name: string, count?: number) => `\u25b8 ${name}${count === undefined ? "" : ` (${count})`}`;
|
|
389
|
+
/** #590 H4: one line per row; a label wider than the column puts its text on the next line at the same column. */
|
|
390
|
+
function described(rows: readonly (readonly [string, string])[]): string[] {
|
|
391
|
+
const width = Math.min(LABEL_WIDTH, Math.max(...rows.map(([label]) => cellWidth(label))));
|
|
392
|
+
return rows.flatMap(([label, description]) => cellWidth(label) > width
|
|
393
|
+
? [` ${label}`, ` ${" ".repeat(width)} ${description}`]
|
|
394
|
+
: [` ${label}${" ".repeat(width - cellWidth(label))} ${description}`]);
|
|
395
|
+
}
|
|
396
|
+
const prose = (text: string) => wrap(text, HELP_WIDTH - 2, 0).map(line => ` ${line}`);
|
|
397
|
+
const GLOBAL_LINE = " Global: --help, --color auto|always|never, --ascii";
|
|
398
|
+
const GROUP_TITLE: Record<CommandGroup, string> = { read: "Read", write: "Write", review: "Review", maintenance: "Maintenance", setup: "Setup" };
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* #590 H2/H3: the grouped root overview, or one command's page (`▸ Usage`, `▸ Description`, `▸ Flags`, `▸ Commands`,
|
|
402
|
+
* `▸ Examples`, `▸ Details`). An argv that names no command gets the overview; `amem help <unknown>` refuses in cli.ts.
|
|
403
|
+
*/
|
|
404
|
+
export function commandHelp(argv: readonly string[] = []): string {
|
|
405
|
+
const words = argv.filter(word => word !== "--help" && word !== "-h");
|
|
406
|
+
const path = commandPath(words);
|
|
407
|
+
const command = path.length ? lookupCommand(path) : undefined;
|
|
264
408
|
if (command && path[0] !== "help") {
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
409
|
+
const row = completionDefinitions().find(candidate => candidate.path.join(" ") === path.join(" "))!;
|
|
410
|
+
const flags = own(row);
|
|
411
|
+
const lines = [section("Usage"), ` ${usageLine(path)}`, "", section("Description"), ...prose(command.description)];
|
|
412
|
+
if (flags.length) lines.push("", section("Flags", flags.length), ...described(flags.map(([name, option]) => [optionLabel(name, option), option.description])));
|
|
413
|
+
lines.push(GLOBAL_LINE);
|
|
414
|
+
if (command.commands) lines.push("", section("Commands", Object.keys(command.commands).length),
|
|
415
|
+
...described(Object.entries(command.commands).map(([name, child]) => [name + (name === command.defaultCommand ? " (default)" : ""), child.description])));
|
|
416
|
+
if (command.examples?.length) lines.push("", section("Examples"), ...command.examples.map(example => ` ${example}`));
|
|
417
|
+
const details = [command.details, ...row.args.filter(arg => arg.values && arg.values.length > 4).map(arg => `<${arg.name}>: ${arg.values!.join(", ")}.`), ...flags.filter(([, option]) => option.details).map(([name, option]) => `${name}: ${option.details}`)].filter((item): item is string => !!item);
|
|
418
|
+
if (details.length) lines.push("", section("Details"), ...details.flatMap(prose));
|
|
419
|
+
return lines.join("\n");
|
|
268
420
|
}
|
|
269
|
-
const
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
const summary = description.length > limit ? `${description.slice(0, limit - 3).trimEnd()}...` : description;
|
|
273
|
-
return ` ${name.padEnd(20)} ${summary}`;
|
|
421
|
+
const groups = (Object.keys(GROUP_TITLE) as CommandGroup[]).map(group => {
|
|
422
|
+
const entries = Object.entries(COMMANDS).filter(([, item]) => (item.group ?? "setup") === group);
|
|
423
|
+
return ["", section(GROUP_TITLE[group], entries.length), ...described(entries.map(([name, item]) => [name, item.description]))];
|
|
274
424
|
});
|
|
275
|
-
return ["
|
|
276
|
-
|
|
277
|
-
"
|
|
278
|
-
"review walk and the note editor
|
|
425
|
+
return [section("Usage"), " amem <command> [options]", GLOBAL_LINE, " Get started: amem status, then amem help <command>",
|
|
426
|
+
...groups.flat(),
|
|
427
|
+
"", section("Details"),
|
|
428
|
+
...prose("--policy-free is accepted and ignored; the configured privacy policy applies. Agent-marked reads use the MCP privacy ceiling. Apply and confirm need no terminal; review walk and the note editor stay interactive.")].join("\n");
|
|
279
429
|
}
|
|
430
|
+
/**
|
|
431
|
+
* #590 AC9: true when `line` is one complete amem command that parses against `COMMANDS`. `<id>`-style placeholders are
|
|
432
|
+
* accepted as an argument value. Shared with setup's next steps (#425) so every `->` row is checked the same way.
|
|
433
|
+
*/
|
|
434
|
+
export function isAmemCommand(line: string): boolean {
|
|
435
|
+
const words = line.trim().split(/\s+/);
|
|
436
|
+
if (words[0] !== "amem" || words.length < 2) return false;
|
|
437
|
+
try { parseCommand(words.slice(1).map(word => /^<[a-z-]+>$/.test(word) ? "placeholder" : word)); return true; }
|
|
438
|
+
catch { return false; }
|
|
439
|
+
}
|
|
440
|
+
|