1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
use clap::{Parser, Subcommand, ValueEnum};
#[derive(Parser)]
#[command(name = "asobi")]
#[command(version)]
#[command(about = "Asobi: Knowledge Graph & Memory CLI", long_about = None)]
pub(crate) struct Cli {
#[command(subcommand)]
pub(crate) command: Commands,
/// After a mutation, print the affected entity/entities as JSON to stdout
/// (instead of leaving stdout empty). No effect on read commands, which
/// already emit JSON.
#[arg(long, global = true)]
pub(crate) json: bool,
}
#[derive(Subcommand)]
pub(crate) enum Commands {
/// Create new entities in the knowledge graph.
///
/// Accepts one or more `NAME TYPE` pairs:
/// `new A task B concept` creates two entities.
New {
/// Flat list of `NAME TYPE` pairs (count must be a multiple of 2)
#[arg(num_args = 2.., value_names = ["NAME", "TYPE"])]
pairs: Vec<String>,
/// Seed observations at creation: `--obs VALUE` (repeatable)
#[arg(long = "obs", value_name = "OBSERVATION")]
observations: Vec<String>,
},
/// Create relations between entities.
///
/// Accepts one or more `FROM TO TYPE` triples:
/// `link A B uses C D blocks` creates two relations.
Link {
/// Flat list of `FROM TO TYPE` triples (count must be a multiple of 3)
#[arg(num_args = 3.., value_names = ["FROM", "TO", "TYPE"])]
triples: Vec<String>,
},
/// Add observations to existing entities
Obs {
name: String,
#[arg(num_args = 1..)]
contents: Vec<String>,
},
/// Add or update a truth for an entity
Truth {
name: String,
key: String,
value: String,
},
/// Delete a specific truth for an entity
RmTruth { name: String, key: String },
/// Show an entity's truth change history (superseded values with validity windows)
History {
name: String,
/// Limit to a single truth key
key: Option<String>,
},
/// Delete entities and their relations
Rm { names: Vec<String> },
/// Delete specific observations
RmObs {
name: String,
content: String,
/// Match by observation ID instead of content
#[arg(long)]
id: bool,
},
/// Update an existing observation atomically (replaces old content with new content)
UpdateObs {
name: String,
old_content: String,
new_content: String,
/// Match by observation ID instead of content
#[arg(long)]
id: bool,
},
/// Delete specific relations
Unlink {
from: String,
to: String,
relation_type: String,
},
/// Read the entire knowledge graph
Graph,
/// Search for nodes
Search {
/// Search query terms
query: Option<String>,
/// Maximum number of matched nodes to return
#[arg(long, default_value_t = 10)]
limit: usize,
/// Filter by entity truths: `--where KEY=VALUE` (repeatable)
#[arg(long = "where", value_name = "KEY=VALUE")]
filters: Vec<String>,
},
/// Retrieve specific nodes by name
Show {
names: Vec<String>,
/// Expand relations of specified type(s) to include linked entities
#[arg(long, value_name = "RELATION_TYPE")]
expand: Vec<String>,
/// Include observation IDs in detailed list
#[arg(long)]
with_ids: bool,
},
/// Prune old sessions and sync the graph to Markdown topics
Compact {
/// Prune sessions older than N days
#[arg(long, default_value = "90")]
older_than: u32,
},
/// Preview or delete stale terminal sessions and tasks
Purge {
/// Operational entity type to inspect (repeatable)
#[arg(long = "type", value_name = "ENTITY_TYPE", default_values = ["session", "task"])]
entity_types: Vec<String>,
/// Terminal status to inspect (repeatable)
#[arg(long = "status", value_name = "STATUS", default_values = ["DONE", "CLOSED", "ABANDONED"])]
statuses: Vec<String>,
/// Only consider entities inactive for at least this many days
#[arg(long, default_value_t = 30)]
older_than: u32,
/// Apply the deletion; without this flag purge is a dry run
#[arg(long)]
apply: bool,
/// Make the preview mode explicit (the default)
#[arg(long, conflicts_with = "apply")]
dry_run: bool,
},
/// Initialise a Asobi workspace (XDG by default, `--local` for cwd)
Init {
/// Create `.asobi/` and `asobi.toml` in the current directory
/// instead of the user-level XDG paths.
#[arg(long)]
local: bool,
},
/// Show statistics about the knowledge graph
Stats {
/// Show observation counts and limits per entity
#[arg(long)]
per_entity: bool,
},
/// Report the API contract and selected backend capabilities
Capabilities,
/// Emit JSON Schema for command payloads
Schema {
/// Restrict output to one command's response schema
#[arg(long)]
command: Option<String>,
},
/// Generate shell completion scripts
Completions {
/// Shell to generate completions for
#[arg(value_enum)]
shell: CompletionShell,
},
/// Export the knowledge graph to a JSON file
Export {
/// Path to the output JSON file
#[arg(short, long)]
output: Option<String>,
/// Restrict the export to the subgraph rooted at these entities
/// (repeatable). Pulls each root, its `part_of` children (transitively),
/// and the `depends_on` targets they cite. Omit to export the whole graph.
#[arg(long)]
scope: Vec<String>,
/// With --scope, also follow one hop of `supersedes`/`extends` off the
/// cited leaves (the rationale chain behind a decision).
#[arg(long)]
rationale: bool,
},
/// Import a knowledge graph from a JSON file
Import {
/// Path to the input JSON file
file: String,
},
/// Reset the knowledge graph (delete all entities, relations, and observations)
Reset {
/// Force reset without confirmation
#[arg(long)]
force: bool,
},
/// Snapshot the database to a single consistent file (VACUUM INTO)
Backup {
/// Destination path (default: `<data_dir>/backups/asobi-<timestamp>.db`)
#[arg(short, long)]
output: Option<String>,
/// Snapshots to retain in the default backup directory (oldest pruned)
#[arg(long, default_value_t = 3)]
keep: usize,
},
/// Replace the live database with a snapshot file
Restore {
/// Path to the snapshot file to restore from
file: String,
/// Skip the confirmation prompt
#[arg(long)]
force: bool,
},
/// Manage, install, and update AI agent skills
Skills {
#[command(subcommand)]
subcommand: Option<SkillsCommands>,
},
/// Plan and coordinate durable task-dispatcher work
Tasks {
#[command(subcommand)]
subcommand: Option<crate::tasks::TasksCommands>,
},
}
#[derive(Clone, Debug, ValueEnum)]
pub(crate) enum CompletionShell {
Bash,
Elvish,
Fish,
#[value(name = "powershell")]
PowerShell,
Zsh,
}
impl From<CompletionShell> for clap_complete::Shell {
fn from(shell: CompletionShell) -> Self {
match shell {
CompletionShell::Bash => Self::Bash,
CompletionShell::Elvish => Self::Elvish,
CompletionShell::Fish => Self::Fish,
CompletionShell::PowerShell => Self::PowerShell,
CompletionShell::Zsh => Self::Zsh,
}
}
}
#[derive(Subcommand, Debug)]
pub(crate) enum SkillsCommands {
/// Install skills from a git repository or local path
Install {
/// Git URL or local directory path
source: String,
/// Install all skills found
#[arg(long)]
all: bool,
/// Install specific skills by name
#[arg(long, num_args = 1..)]
select: Option<Vec<String>>,
},
/// Update installed skills from their sources
Update {
/// Specific source URL or slug to update (updates all if omitted)
source: Option<String>,
},
/// Remove an installed skill or all skills from a source
Remove {
/// Name of the skill (e.g. skill:slug:name) or source slug/URL
target: String,
},
/// Show the raw body of an installed skill (useful for humans to read without JSON escaping)
Show {
/// Name of the skill (fully qualified e.g. skill:slug:name, or short name)
name: String,
},
}