aimancli 0.2.0__py3-none-any.whl
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.
- aiman/__init__.py +0 -0
- aiman/cli.py +53 -0
- aiman/core/__init__.py +1 -0
- aiman/core/classifiers.py +38 -0
- aiman/core/pipeline.py +129 -0
- aiman/core/registry.py +15 -0
- aiman/core/safety.py +63 -0
- aiman/core/tagger.py +70 -0
- aiman/core/tool.py +61 -0
- aiman/tools/__init__.py +0 -0
- aiman/tools/find/__init__.py +63 -0
- aiman/tools/find/fixture.py +63 -0
- aiman/tools/find/rules.py +208 -0
- aiman/tools/find/schema.json +98 -0
- aiman/tools/find/slots.py +224 -0
- aiman/tools/find/templates.py +690 -0
- aiman/tools/ls/__init__.py +42 -0
- aiman/tools/ls/fixture.py +88 -0
- aiman/tools/ls/rules.py +109 -0
- aiman/tools/ls/schema.json +28 -0
- aiman/tools/ls/slots.py +245 -0
- aiman/tools/ls/templates.py +422 -0
- aimancli-0.2.0.dist-info/METADATA +99 -0
- aimancli-0.2.0.dist-info/RECORD +28 -0
- aimancli-0.2.0.dist-info/WHEEL +5 -0
- aimancli-0.2.0.dist-info/entry_points.txt +2 -0
- aimancli-0.2.0.dist-info/licenses/LICENSE +674 -0
- aimancli-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Generate intent -> `ls` command pairs for `aiman ls "<intent>"`.
|
|
3
|
+
|
|
4
|
+
Coverage follows `man ls` (GNU coreutils 9.4): -a/-A, -l/-g/-o/-n/-1, -h, -S/-t/-X/-v/-U, -r,
|
|
5
|
+
-u/-c/--time=birth, -R, -d, -i, -s, -F/-p, -B, -L, -I, --group-directories-first, --full-time,
|
|
6
|
+
--time-style=long-iso, plus globs and | head / tail / wc -l. The man page has no EXAMPLES
|
|
7
|
+
section, so IDIOMS holds hand-written common usage.
|
|
8
|
+
|
|
9
|
+
Most rows come from g_combo(): a verb, a path and 0-3 modifiers, written through
|
|
10
|
+
slots.build() so every command is canonical. g_variant() re-spells some of them
|
|
11
|
+
(flag order, long options) to exercise parse() normalisation.
|
|
12
|
+
"""
|
|
13
|
+
import random
|
|
14
|
+
import re
|
|
15
|
+
|
|
16
|
+
from aiman.tools.find.templates import EXTS
|
|
17
|
+
|
|
18
|
+
from . import slots
|
|
19
|
+
|
|
20
|
+
SEED = 42
|
|
21
|
+
rng = random.Random(SEED)
|
|
22
|
+
pairs = []
|
|
23
|
+
|
|
24
|
+
# ---------------------------------------------------------------- vocab
|
|
25
|
+
PATHS = [
|
|
26
|
+
(".", ["", "", "", "here", "in the current directory", "in this folder", "in cwd", "in the current dir"]),
|
|
27
|
+
("/var/log", ["in /var/log", "under /var/log", "inside /var/log", "in the log directory"]),
|
|
28
|
+
("/etc", ["in /etc", "inside /etc", "in the config directory"]),
|
|
29
|
+
("/tmp", ["in /tmp", "in the temp directory", "in the tmp folder"]),
|
|
30
|
+
("~", ["in my home directory", "in ~", "in my home folder", "in home"]),
|
|
31
|
+
("~/Downloads", ["in ~/Downloads", "in my downloads folder", "in Downloads", "in the downloads directory"]),
|
|
32
|
+
("~/Documents", ["in ~/Documents", "in my documents folder", "in Documents"]),
|
|
33
|
+
("~/Desktop", ["on my desktop", "in ~/Desktop"]),
|
|
34
|
+
("/usr/bin", ["in /usr/bin", "inside /usr/bin"]),
|
|
35
|
+
("src", ["in src", "in the src directory", "inside src/", "in the source folder"]),
|
|
36
|
+
("/", ["in /", "in the root directory", "at the filesystem root"]),
|
|
37
|
+
("/srv/www", ["in /srv/www", "in the web root"]),
|
|
38
|
+
("/opt", ["in /opt", "under /opt"]),
|
|
39
|
+
("/home", ["in /home", "under /home"]),
|
|
40
|
+
("/var/lib/docker", ["in /var/lib/docker"]),
|
|
41
|
+
("projects/api", ["in projects/api", "inside projects/api"]),
|
|
42
|
+
]
|
|
43
|
+
FILES = ["/etc/passwd", "/etc/hosts", "~/.bashrc", "/var/log/syslog", "/usr/bin/python3", "/etc/fstab",
|
|
44
|
+
"notes.txt", "README.md", "/etc/nginx/nginx.conf", "script.sh"]
|
|
45
|
+
VERBS = ["list", "show", "ls", "display", "show me", "list the contents", "print", "give me", "list out", "view"]
|
|
46
|
+
OBJECTS = ["", "", "files", "the files", "everything", "all files", "the contents", "entries", "what's there"]
|
|
47
|
+
PREFIXES = ["report", "test", "backup", "img", "data", "draft", "log", "config"]
|
|
48
|
+
SUBSTRS = ["2024", "old", "final", "copy", "temp", "v2", "invoice", "cache"]
|
|
49
|
+
IGNORE_EXTS = ["pyc", "o", "swp", "log", "tmp", "json"]
|
|
50
|
+
IGNORE_NAMES = ["node_modules", "__pycache__", "venv", ".git", "build", "dist", "target"]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _long(s):
|
|
54
|
+
if s["format"] in (None, "1") and s["time_style"] != "full-time":
|
|
55
|
+
s["format"] = "l"
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _set(**kv):
|
|
59
|
+
def f(s):
|
|
60
|
+
for k, v in kv.items():
|
|
61
|
+
s[k] = v
|
|
62
|
+
return f
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _and_long(**kv):
|
|
66
|
+
def f(s):
|
|
67
|
+
_set(**kv)(s)
|
|
68
|
+
_long(s)
|
|
69
|
+
return f
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# (groups it occupies, apply(slots), phrases). "single" = needs a long listing (clashes with -1).
|
|
73
|
+
MODS = [
|
|
74
|
+
({"format"}, _set(format="l"), ["in long format", "with details", "with full details", "in long listing format",
|
|
75
|
+
"with permissions and owners", "with sizes and dates", "in detail", "verbosely"]),
|
|
76
|
+
({"format", "single"}, _set(format="1"), ["one per line", "one entry per line", "in a single column",
|
|
77
|
+
"one file per line"]),
|
|
78
|
+
({"format"}, _set(format="n"), ["with numeric user and group ids", "showing uid and gid numbers",
|
|
79
|
+
"with numeric owners"]),
|
|
80
|
+
({"format"}, _set(format="g"), ["in long format without the owner", "with details but no owner column"]),
|
|
81
|
+
({"format"}, _set(format="o"), ["in long format without the group", "with details but no group column"]),
|
|
82
|
+
({"format", "time_style", "single"}, _set(time_style="full-time"),
|
|
83
|
+
["with full timestamps", "with full date and time", "with exact modification times", "with complete timestamps"]),
|
|
84
|
+
({"time_style", "single"}, _and_long(time_style="long-iso"), ["with ISO dates", "with dates in ISO format",
|
|
85
|
+
"with long-iso timestamps"]),
|
|
86
|
+
({"all"}, _set(all="a"), ["including hidden files", "with hidden files", "including dotfiles",
|
|
87
|
+
"showing hidden files too", "with hidden ones", "including hidden entries",
|
|
88
|
+
"even hidden files"]),
|
|
89
|
+
({"all"}, _set(all="A"), ["including hidden files but not . and ..", "with dotfiles except . and ..",
|
|
90
|
+
"almost all entries", "with hidden files, without . and .."]),
|
|
91
|
+
({"human", "single"}, _and_long(human=True), ["with human-readable sizes", "with readable file sizes",
|
|
92
|
+
"human readable", "with sizes in KB and MB", "with friendly sizes"]),
|
|
93
|
+
({"sort", "reverse"}, _set(sort="S"), ["sorted by size", "largest first", "biggest first", "by size",
|
|
94
|
+
"biggest to smallest", "ordered by size"]),
|
|
95
|
+
({"sort", "reverse"}, _set(sort="S", reverse=True), ["smallest first", "sorted by size, smallest first",
|
|
96
|
+
"smallest to largest", "by size ascending"]),
|
|
97
|
+
({"sort", "reverse"}, _set(sort="t"), ["sorted by modification time", "newest first", "most recently modified first",
|
|
98
|
+
"by date, newest first", "latest first", "sorted by date", "by time"]),
|
|
99
|
+
({"sort", "reverse"}, _set(sort="t", reverse=True), ["oldest first", "sorted by date, oldest first",
|
|
100
|
+
"newest last", "by time, oldest first", "oldest to newest"]),
|
|
101
|
+
({"sort"}, _set(sort="X"), ["sorted by extension", "grouped by file type", "by extension", "ordered by suffix"]),
|
|
102
|
+
({"sort"}, _set(sort="v"), ["in natural number order", "with version sort", "sorting numbers naturally",
|
|
103
|
+
"in version order"]),
|
|
104
|
+
({"sort", "reverse"}, _set(sort="U"), ["unsorted", "in directory order", "without sorting", "in raw disk order"]),
|
|
105
|
+
({"sort", "reverse"}, _set(reverse=True), ["in reverse order", "reverse alphabetical", "Z to A",
|
|
106
|
+
"in reverse alphabetical order"]),
|
|
107
|
+
({"sort", "time", "reverse"}, _set(sort="t", time="u"), ["sorted by access time", "most recently accessed first",
|
|
108
|
+
"by last access"]),
|
|
109
|
+
({"time", "single"}, _and_long(time="u"), ["showing access times", "with last access time", "with atime"]),
|
|
110
|
+
({"sort", "time", "reverse"}, _set(sort="t", time="c"), ["sorted by status change time", "by ctime",
|
|
111
|
+
"most recently changed metadata first"]),
|
|
112
|
+
({"time", "single"}, _and_long(time="c"), ["showing change times", "with ctime", "with status change time"]),
|
|
113
|
+
({"sort", "time", "reverse"}, _set(sort="t", time="birth"), ["sorted by creation time", "newest created first",
|
|
114
|
+
"by birth time"]),
|
|
115
|
+
({"time", "single"}, _and_long(time="birth"), ["with creation time", "showing birth time", "with creation dates"]),
|
|
116
|
+
({"recursive", "directory", "glob"}, _set(recursive=True), ["recursively", "including subdirectories",
|
|
117
|
+
"and all subfolders", "recursing into subdirectories",
|
|
118
|
+
"with everything below it"]),
|
|
119
|
+
({"inode"}, _set(inode=True), ["with inode numbers", "showing inodes", "with the inode of each file"]),
|
|
120
|
+
({"blocks"}, _set(blocks=True), ["with allocated size in blocks", "showing block counts", "with disk blocks used"]),
|
|
121
|
+
({"indicator"}, _set(indicator="F"), ["with type indicators", "marking directories and executables",
|
|
122
|
+
"with a symbol after each type", "classified"]),
|
|
123
|
+
({"indicator"}, _set(indicator="p"), ["with a slash after directories", "marking folders with /",
|
|
124
|
+
"with trailing slashes on dirs"]),
|
|
125
|
+
({"backups"}, _set(backups=True), ["ignoring backup files ending in ~", "without ~ backup files",
|
|
126
|
+
"skipping editor backups", "hiding files ending with ~"]),
|
|
127
|
+
({"deref"}, _set(deref=True), ["following symlinks", "dereferencing symbolic links", "resolving symlinks"]),
|
|
128
|
+
({"dirs_first"}, _set(dirs_first=True), ["with folders first", "directories first",
|
|
129
|
+
"grouping directories before files", "dirs before files"]),
|
|
130
|
+
]
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _ignore_mod():
|
|
134
|
+
if rng.random() < 0.5:
|
|
135
|
+
e = rng.choice(IGNORE_EXTS)
|
|
136
|
+
ph = rng.choice([f"ignoring {e} files", f"excluding .{e} files", f"hiding *.{e} files",
|
|
137
|
+
f"without the .{e} files", f"skipping {e} files"])
|
|
138
|
+
return ph, f"*.{e}"
|
|
139
|
+
n = rng.choice(IGNORE_NAMES)
|
|
140
|
+
return rng.choice([f"ignoring {n}", f"excluding {n}", f"hiding {n}", f"except {n}", f"skipping {n}"]), n
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
# ---------------------------------------------------------------- helpers
|
|
144
|
+
def _path():
|
|
145
|
+
p, phr = rng.choice(PATHS)
|
|
146
|
+
return p, rng.choice(phr)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def join_intent(*parts):
|
|
150
|
+
s = re.sub(r"\s+", " ", " ".join(p for p in parts if p)).strip()
|
|
151
|
+
s = s.replace(" ,", ",")
|
|
152
|
+
r = rng.random()
|
|
153
|
+
# upper-case only the first letter: str.capitalize() would lowercase paths like ~/Downloads
|
|
154
|
+
return s[:1].upper() + s[1:] if r < 0.15 else s + "?" if r < 0.2 else s
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def add(intent, s):
|
|
158
|
+
c = slots.build(s)
|
|
159
|
+
p = slots.parse(c)
|
|
160
|
+
if p is not None:
|
|
161
|
+
c = slots.build(p) # normalise e.g. -l + --full-time
|
|
162
|
+
pairs.append((intent, c))
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def add_raw(intent, cmd):
|
|
166
|
+
pairs.append((intent, cmd))
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _mods(s, k, taken=()):
|
|
170
|
+
used, phrases = set(taken), []
|
|
171
|
+
for m in rng.sample(MODS, len(MODS)):
|
|
172
|
+
if len(phrases) >= k:
|
|
173
|
+
break
|
|
174
|
+
groups, fn, phr = m
|
|
175
|
+
if groups & used:
|
|
176
|
+
continue
|
|
177
|
+
used |= groups
|
|
178
|
+
fn(s)
|
|
179
|
+
phrases.append(rng.choice(phr))
|
|
180
|
+
if k and "ignore" not in used and rng.random() < 0.08:
|
|
181
|
+
ph, ig = _ignore_mod()
|
|
182
|
+
s["ignore"] = ig
|
|
183
|
+
phrases.append(ph)
|
|
184
|
+
return phrases
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def _joinmods(ph):
|
|
188
|
+
if len(ph) < 2:
|
|
189
|
+
return " ".join(ph)
|
|
190
|
+
sep = rng.choice([" ", ", ", " and "])
|
|
191
|
+
return sep.join(ph[:-1]) + rng.choice([sep, " and "]) + ph[-1]
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def _glob():
|
|
195
|
+
"""-> (glob, object phrase, kind)"""
|
|
196
|
+
r = rng.random()
|
|
197
|
+
if r < 0.5:
|
|
198
|
+
e, phr = rng.choice(list(EXTS.items()))
|
|
199
|
+
return f"*.{e}", rng.choice(phr), "ext"
|
|
200
|
+
if r < 0.65:
|
|
201
|
+
w = rng.choice(PREFIXES)
|
|
202
|
+
return f"{w}*", rng.choice([f"files starting with {w}", f"files beginning with {w}",
|
|
203
|
+
f"names that start with {w}", f"{w}* files"]), "prefix"
|
|
204
|
+
if r < 0.8:
|
|
205
|
+
w = rng.choice(SUBSTRS)
|
|
206
|
+
return f"*{w}*", rng.choice([f"files with {w} in the name", f"files whose name contains {w}",
|
|
207
|
+
f"files named like *{w}*"]), "contains"
|
|
208
|
+
if r < 0.92:
|
|
209
|
+
return "*/", rng.choice(["only directories", "just the folders", "subdirectories only",
|
|
210
|
+
"only the directories", "only folders", "directories only"]), "dirs"
|
|
211
|
+
return ".*", rng.choice(["only hidden files", "just the dotfiles", "hidden entries only",
|
|
212
|
+
"only the hidden files"]), "hidden"
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
# ---------------------------------------------------------------- generators
|
|
216
|
+
def g_combo():
|
|
217
|
+
s = slots.empty()
|
|
218
|
+
p, pp = _path()
|
|
219
|
+
s["path"] = [p]
|
|
220
|
+
taken = set()
|
|
221
|
+
obj = rng.choice(OBJECTS)
|
|
222
|
+
if rng.random() < 0.3:
|
|
223
|
+
g, obj, kind = _glob()
|
|
224
|
+
s["glob"] = g
|
|
225
|
+
taken |= {"glob", "recursive"}
|
|
226
|
+
if kind in ("dirs", "hidden"):
|
|
227
|
+
s["directory"] = True
|
|
228
|
+
taken |= {"directory", "all"} if kind == "hidden" else {"directory"}
|
|
229
|
+
k = rng.choices([0, 1, 2, 3], [5, 35, 35, 25])[0]
|
|
230
|
+
ph = _joinmods(_mods(s, k, taken))
|
|
231
|
+
v = rng.choice(VERBS)
|
|
232
|
+
if v == "list the contents" and obj:
|
|
233
|
+
v = "list"
|
|
234
|
+
if rng.random() < 0.7:
|
|
235
|
+
add(join_intent(v, obj, pp, ph), s)
|
|
236
|
+
else:
|
|
237
|
+
add(join_intent(v, obj, ph, pp), s)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def g_whats_in():
|
|
241
|
+
s = slots.empty()
|
|
242
|
+
p, phr = rng.choice([x for x in PATHS if x[0] != "."])
|
|
243
|
+
pp = rng.choice(phr)
|
|
244
|
+
s["path"] = [p]
|
|
245
|
+
lead = rng.choice(["what's in", "what is in", "contents of", "what files are in"])
|
|
246
|
+
where = pp.split(" ", 1)[1] if pp.startswith(("in ", "on ", "under ", "inside ", "at ")) else pp
|
|
247
|
+
add(join_intent(lead, where, _joinmods(_mods(s, rng.choice([0, 1, 1, 2])))), s)
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
TOPN = [("t", False, ["newest", "most recently modified", "latest", "most recent", "last modified"]),
|
|
251
|
+
("t", True, ["oldest", "least recently modified"]),
|
|
252
|
+
("S", False, ["largest", "biggest", "heaviest"]),
|
|
253
|
+
("S", True, ["smallest", "tiniest"])]
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def g_topn():
|
|
257
|
+
s = slots.empty()
|
|
258
|
+
p, pp = _path()
|
|
259
|
+
s["path"] = [p]
|
|
260
|
+
srt, rev, adj = rng.choice(TOPN)
|
|
261
|
+
s["sort"], s["reverse"] = srt, rev
|
|
262
|
+
n = str(rng.choice([3, 5, 5, 10, 10, 20, 15, 8, 2, 50]))
|
|
263
|
+
s["action"], s["args"] = "| head -n {N}", {"N": n}
|
|
264
|
+
a = rng.choice(adj)
|
|
265
|
+
noun = "files"
|
|
266
|
+
if rng.random() < 0.25:
|
|
267
|
+
e, phr = rng.choice(list(EXTS.items()))
|
|
268
|
+
s["glob"], noun = f"*.{e}", rng.choice(phr)
|
|
269
|
+
t = rng.choice([f"show the {n} {a} {noun}", f"list the {n} {a} {noun}", f"{n} {a} {noun}",
|
|
270
|
+
f"top {n} {a} {noun}", f"which are the {n} {a} {noun}", f"the {a} {n} {noun}"])
|
|
271
|
+
add(join_intent(t, pp), s)
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def g_head_tail():
|
|
275
|
+
s = slots.empty()
|
|
276
|
+
p, pp = _path()
|
|
277
|
+
s["path"] = [p]
|
|
278
|
+
n = str(rng.choice([3, 5, 10, 20]))
|
|
279
|
+
if rng.random() < 0.5:
|
|
280
|
+
s["action"], t = "| head -n {N}", rng.choice([f"first {n} entries", f"the first {n} files", f"only {n} files"])
|
|
281
|
+
else:
|
|
282
|
+
s["action"], t = "| tail -n {N}", rng.choice([f"last {n} entries", f"the last {n} files alphabetically",
|
|
283
|
+
f"the final {n} names"])
|
|
284
|
+
s["args"] = {"N": n}
|
|
285
|
+
add(join_intent(rng.choice(["show", "list"]), t, pp), s)
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def g_count():
|
|
289
|
+
s = slots.empty()
|
|
290
|
+
p, pp = _path()
|
|
291
|
+
s["path"] = [p]
|
|
292
|
+
s["action"] = "| wc -l"
|
|
293
|
+
r = rng.random()
|
|
294
|
+
if r < 0.5:
|
|
295
|
+
t = rng.choice(["how many files are there", "count the files", "count entries", "number of files",
|
|
296
|
+
"how many entries are", "count items"])
|
|
297
|
+
elif r < 0.7:
|
|
298
|
+
e, phr = rng.choice(list(EXTS.items()))
|
|
299
|
+
s["glob"] = f"*.{e}"
|
|
300
|
+
ph = rng.choice(phr)
|
|
301
|
+
t = rng.choice([f"how many {ph} are there", f"count the {ph}", f"number of {ph}"])
|
|
302
|
+
elif r < 0.85:
|
|
303
|
+
s["all"] = "A"
|
|
304
|
+
t = rng.choice(["count all files including hidden ones", "how many entries including dotfiles",
|
|
305
|
+
"count everything including hidden files"])
|
|
306
|
+
else:
|
|
307
|
+
s["glob"], s["directory"] = "*/", True
|
|
308
|
+
t = rng.choice(["how many directories are there", "count the folders", "number of subdirectories"])
|
|
309
|
+
add(join_intent(t, pp), s)
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def g_dir_itself():
|
|
313
|
+
s = slots.empty()
|
|
314
|
+
p, _ = rng.choice([x for x in PATHS if x[0] not in (".",)])
|
|
315
|
+
s["path"], s["directory"], s["format"] = [p], True, "l"
|
|
316
|
+
t = rng.choice([f"show permissions of the {p} directory itself", f"long listing of {p} itself, not its contents",
|
|
317
|
+
f"details of the folder {p}, not what's inside", f"show the owner of directory {p}",
|
|
318
|
+
f"permissions on {p} itself"])
|
|
319
|
+
if rng.random() < 0.2:
|
|
320
|
+
s["format"], s["inode"] = None, True
|
|
321
|
+
t = rng.choice([f"inode number of the directory {p} itself", f"show the inode of {p} itself"])
|
|
322
|
+
add(join_intent(t), s)
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def g_file_info():
|
|
326
|
+
s = slots.empty()
|
|
327
|
+
f = rng.choice(FILES)
|
|
328
|
+
s["path"] = [f]
|
|
329
|
+
r = rng.random()
|
|
330
|
+
if r < 0.6:
|
|
331
|
+
s["format"] = "l"
|
|
332
|
+
t = rng.choice([f"show details of {f}", f"permissions of {f}", f"who owns {f}", f"long listing for {f}",
|
|
333
|
+
f"is {f} a symlink", f"show size and date of {f}"])
|
|
334
|
+
if rng.random() < 0.3:
|
|
335
|
+
s["human"] = True
|
|
336
|
+
t = rng.choice([f"how big is {f}", f"size of {f} in human readable form"])
|
|
337
|
+
elif r < 0.8:
|
|
338
|
+
s["inode"] = True
|
|
339
|
+
t = rng.choice([f"inode number of {f}", f"show the inode of {f}"])
|
|
340
|
+
else:
|
|
341
|
+
s["format"], s["time_style"] = None, "full-time"
|
|
342
|
+
t = rng.choice([f"exact modification time of {f}", f"full timestamp of {f}"])
|
|
343
|
+
add(join_intent(t), s)
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
def g_multi_path():
|
|
347
|
+
a, b = rng.sample([x for x in PATHS if x[0] not in (".", "/")], 2)
|
|
348
|
+
s = slots.empty()
|
|
349
|
+
s["path"] = [a[0], b[0]]
|
|
350
|
+
ph = _joinmods(_mods(s, rng.choice([0, 1, 1, 2]), {"glob"}))
|
|
351
|
+
add(join_intent(rng.choice(["list", "show"]), a[0], "and", b[0], ph), s)
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
INV_LONG = {}
|
|
355
|
+
for _k, _v in slots.LONG.items():
|
|
356
|
+
INV_LONG.setdefault(_v, _k)
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
def g_variant():
|
|
360
|
+
"""A combo row re-spelled: shuffled flags, split flags or long options (same slots)."""
|
|
361
|
+
n0 = len(pairs)
|
|
362
|
+
g_combo()
|
|
363
|
+
intent, canon = pairs.pop(n0)
|
|
364
|
+
head, sep, pipe = canon.partition(" | ")
|
|
365
|
+
toks = head.split(" ")
|
|
366
|
+
if len(toks) < 2 or not toks[1].startswith("-") or toks[1].startswith("--"):
|
|
367
|
+
pairs.append((intent, canon))
|
|
368
|
+
return
|
|
369
|
+
chars = list(toks[1][1:])
|
|
370
|
+
rng.shuffle(chars)
|
|
371
|
+
r = rng.random()
|
|
372
|
+
if r < 0.4:
|
|
373
|
+
flags = ["-" + "".join(chars)]
|
|
374
|
+
elif r < 0.7:
|
|
375
|
+
flags = ["-" + c for c in chars]
|
|
376
|
+
else:
|
|
377
|
+
flags = [INV_LONG.get(c, "-" + c) if rng.random() < 0.6 else "-" + c for c in chars]
|
|
378
|
+
add_raw(intent, " ".join([toks[0]] + flags + toks[2:]) + (sep + pipe if sep else ""))
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
GENS = [(g_combo, 3200), (g_whats_in, 150), (g_topn, 400), (g_head_tail, 120), (g_count, 300),
|
|
382
|
+
(g_dir_itself, 120), (g_file_info, 200), (g_multi_path, 120), (g_variant, 350)]
|
|
383
|
+
|
|
384
|
+
IDIOMS = [
|
|
385
|
+
("list everything with details, oldest first", "ls -ltr"),
|
|
386
|
+
("show all files with human readable sizes", "ls -lah"),
|
|
387
|
+
("long listing of all files including hidden with readable sizes", "ls -lah"),
|
|
388
|
+
("list files by size with readable sizes", "ls -lhS"),
|
|
389
|
+
("list only directories", "ls -d */"),
|
|
390
|
+
("count entries in the current directory", "ls | wc -l"),
|
|
391
|
+
("show the 10 most recently modified files", "ls -t | head -n 10"),
|
|
392
|
+
("show hidden files only", "ls -d .*"),
|
|
393
|
+
("long listing of /etc itself", "ls -ld /etc"),
|
|
394
|
+
("show inode numbers of files here", "ls -i"),
|
|
395
|
+
("recursively list everything under src", "ls -R src"),
|
|
396
|
+
("list files with full timestamps", "ls --full-time"),
|
|
397
|
+
("list directories first, with details", "ls -l --group-directories-first"),
|
|
398
|
+
("list all files including hidden in one column", "ls -1a"),
|
|
399
|
+
("show numeric owner ids in /home", "ls -n /home"),
|
|
400
|
+
("list /etc ignoring conf files", "ls -I '*.conf' /etc"),
|
|
401
|
+
("what did I change most recently", "ls -lt"),
|
|
402
|
+
("biggest files first in my downloads folder", "ls -lS ~/Downloads"),
|
|
403
|
+
("list hidden config files in my home directory", "ls -d ~/.*"),
|
|
404
|
+
("show everything in long format sorted by size", "ls --format=long --sort=size"),
|
|
405
|
+
]
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
def generate(seed=SEED):
|
|
409
|
+
"""Return unique (intent, command) pairs, deterministic for a given seed."""
|
|
410
|
+
rng.seed(seed)
|
|
411
|
+
pairs.clear()
|
|
412
|
+
for g, n in GENS:
|
|
413
|
+
for _ in range(n):
|
|
414
|
+
g()
|
|
415
|
+
pairs.extend(IDIOMS)
|
|
416
|
+
seen, out = set(), []
|
|
417
|
+
for i, c in pairs:
|
|
418
|
+
i = i.strip()
|
|
419
|
+
if i and i.lower() not in seen:
|
|
420
|
+
seen.add(i.lower())
|
|
421
|
+
out.append((i, c))
|
|
422
|
+
return out
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aimancli
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Tiny on-device models that turn plain-English intent into Linux commands
|
|
5
|
+
License-Expression: GPL-3.0-or-later
|
|
6
|
+
Project-URL: Homepage, https://github.com/experimente-oo-r/aiman
|
|
7
|
+
Project-URL: Source, https://github.com/experimente-oo-r/aiman
|
|
8
|
+
Project-URL: Issues, https://github.com/experimente-oo-r/aiman/issues
|
|
9
|
+
Requires-Python: >=3.9
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: scikit-learn>=1.2
|
|
13
|
+
Requires-Dist: joblib
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest; extra == "dev"
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# aiman
|
|
19
|
+
|
|
20
|
+
Tiny on-device models that turn plain-English intent into Linux commands, one command at a time.
|
|
21
|
+
|
|
22
|
+
```console
|
|
23
|
+
$ aiman find "delete .log files older than 30 days in /var/log"
|
|
24
|
+
find /var/log -type f -name '*.log' -mtime +30 -delete
|
|
25
|
+
destructive -- would affect 3 item(s):
|
|
26
|
+
/var/log/app.log
|
|
27
|
+
...
|
|
28
|
+
type 'yes' to run:
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
No LLM and no GPU: each tool is a slot-filling model (a token tagger plus a few sentence
|
|
32
|
+
classifiers, about 5 MB) and a deterministic rule engine that writes the command.
|
|
33
|
+
Destructive commands are previewed and need an explicit `yes`.
|
|
34
|
+
|
|
35
|
+
## Benchmark: aiman find vs Qwen2.5-Coder-0.5B (Q4_K_M, llama.cpp)
|
|
36
|
+
|
|
37
|
+
Same intents, same machine (x86_64, 8 CPUs). Latency is per intent.
|
|
38
|
+
|
|
39
|
+
| Metric | aiman | Qwen 0.5B Q4 |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| Size on disk | 5.3 MB | 491.4 MB |
|
|
42
|
+
| Cold start + answer, median | 1722 ms | 1208 ms |
|
|
43
|
+
| Warm answer, median | 22.1 ms | 528.0 ms |
|
|
44
|
+
| Warm answer, p95 | 24.7 ms | 907.3 ms |
|
|
45
|
+
| Accuracy, val (templated), in-schema | 97.1% (202/208) | 17.3% (36/208) |
|
|
46
|
+
| Accuracy, val (templated), all items | 86.7% (202/233) | 15.5% (36/233) |
|
|
47
|
+
|
|
48
|
+
**Caveat:** the validation set comes from the same template generator aiman is trained on,
|
|
49
|
+
so these accuracy numbers favour aiman and overstate how it does on real phrasing. Qwen gets
|
|
50
|
+
a 2-shot prompt with greedy decoding and no fine-tuning. Reproduce with `pytest -m bench -s`
|
|
51
|
+
(see `tests/test_llm_baseline.py`); full output in `results/baseline.md`.
|
|
52
|
+
|
|
53
|
+
## Per-tool accuracy
|
|
54
|
+
|
|
55
|
+
| Tool | Status | In-schema accuracy (val) | Model size |
|
|
56
|
+
|------|--------|--------------------------|-----------|
|
|
57
|
+
| find | v0.1 | 97.1% | 5.2 MB |
|
|
58
|
+
| ls | v0.2 | 99.2% | 3.6 MB |
|
|
59
|
+
|
|
60
|
+
## Quick start
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install -e . # needs scikit-learn, joblib
|
|
64
|
+
aiman all find # build dataset -> train -> evaluate (~35 s on a laptop CPU)
|
|
65
|
+
aiman find -n "count jpg files in my home folder"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Layout
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
aiman/
|
|
72
|
+
cli.py aiman <tool> "intent" | build | train | eval | all | list
|
|
73
|
+
core/ shared by every tool
|
|
74
|
+
tool.py plugin contract (Tool base class)
|
|
75
|
+
tagger.py span tagger (BIO)
|
|
76
|
+
classifiers.py sentence classifiers
|
|
77
|
+
pipeline.py dataset -> labels -> train -> evaluate -> Predictor
|
|
78
|
+
safety.py show / preview / confirm / run
|
|
79
|
+
registry.py discovers aiman/tools/*
|
|
80
|
+
tools/
|
|
81
|
+
find/ one folder per command
|
|
82
|
+
schema.json slots the tool understands
|
|
83
|
+
templates.py intent -> command data generator
|
|
84
|
+
slots.py parse / build / tag / targets
|
|
85
|
+
rules.py lexicons, normalisers, assemble()
|
|
86
|
+
fixture.py sandbox for validation and equivalence
|
|
87
|
+
tests/
|
|
88
|
+
data/, models/ generated, git-ignored
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Adding a command
|
|
92
|
+
|
|
93
|
+
1. Copy `aiman/tools/find/` to `aiman/tools/<cmd>/`.
|
|
94
|
+
2. Write `schema.json`: the slots the command needs.
|
|
95
|
+
3. Write `templates.py`: intent/command pairs covering its options.
|
|
96
|
+
4. Implement the `Tool` methods (see `aiman/core/tool.py`).
|
|
97
|
+
5. Add `tests/test_<cmd>.py`, run `aiman all <cmd>` and `pytest`.
|
|
98
|
+
|
|
99
|
+
See [ROADMAP.md](ROADMAP.md) for the order commands are added.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
aiman/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
aiman/cli.py,sha256=f7KT9XJgzsji1DYsVZ0nivIBJo3ATqhMdFCfxRMpLmE,1668
|
|
3
|
+
aiman/core/__init__.py,sha256=uHQuK_wfubHMzKxyn4YnmKUIOMc-BOcWYQUarmh-zw4,80
|
|
4
|
+
aiman/core/classifiers.py,sha256=9z_M4r9wZlHICcWzojTrt4uOWCduXRxAA3kevL4lFPI,1259
|
|
5
|
+
aiman/core/pipeline.py,sha256=lZecIWXcAbYRbeQrmysdCVG120CyzuhhEkRpgcy8cCM,4798
|
|
6
|
+
aiman/core/registry.py,sha256=0jIm89tkZsOCSMWJbEHmDaG_B8yzyiiULnmPl--4MBs,455
|
|
7
|
+
aiman/core/safety.py,sha256=TLCw-sWYZJ5g_ZCXIdvq4VGEo2yyz7NPUWe-QAZ1VZs,2064
|
|
8
|
+
aiman/core/tagger.py,sha256=XewUxDghICtOCkoJEvrnyi0MW1rBbpfuZ7fdD-W5QCQ,2274
|
|
9
|
+
aiman/core/tool.py,sha256=JcwKr_AdUZSS-pcGvTRDr6QzA2W6rqKnecehWRDaI3w,2288
|
|
10
|
+
aiman/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
aiman/tools/find/__init__.py,sha256=tMLs4yTCLK4ZLFZyeHqvmqPqmM6Eztep-LE8GFOep3E,1952
|
|
12
|
+
aiman/tools/find/fixture.py,sha256=-hB0xPaVM6P3x2VZjqPNbwemYK2445bS-NqdUwwbVj4,2553
|
|
13
|
+
aiman/tools/find/rules.py,sha256=W1sbrAoYZVoqSah_ogDqua4i1QG1qB5Iz4V57D9YyVw,9363
|
|
14
|
+
aiman/tools/find/schema.json,sha256=0LoVy-jmxz0DnHtBpuhxoZ9f0tGfjXUGGHy95BblqzY,1738
|
|
15
|
+
aiman/tools/find/slots.py,sha256=q0ok9qqYKkf1pV2hcxEhSz96LuMRZBRQcu5WviF26u4,9220
|
|
16
|
+
aiman/tools/find/templates.py,sha256=XXeisCEwYRjbCP0kkD6xqwZ3Letm6MSvuFMyHGB3OKU,26789
|
|
17
|
+
aiman/tools/ls/__init__.py,sha256=Iuuqn79HfleYCBQCIkjR_sf5K1WPv8POuQvY-zLlzQA,1164
|
|
18
|
+
aiman/tools/ls/fixture.py,sha256=Uv0yEqk5WYTQ5pNiRLSoNlP06mMeM3SCc_GrrND1rco,3345
|
|
19
|
+
aiman/tools/ls/rules.py,sha256=8974BqHyJGoLQgz3o-Wf_bTEXXWf3No5XddcmNL38lQ,4352
|
|
20
|
+
aiman/tools/ls/schema.json,sha256=xAmPEiaOILqAzMnwX84en9fbrGC20BZP1iYqwIRMVnE,1511
|
|
21
|
+
aiman/tools/ls/slots.py,sha256=IxgYl5bhJii1ZxdH_LjjdszpUkRoJtqOTogWeA_qfp8,8931
|
|
22
|
+
aiman/tools/ls/templates.py,sha256=43t2yh3uVW7kAVY_yirXFJN2nw--X-j0rPr3ioJNAr8,19739
|
|
23
|
+
aimancli-0.2.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
24
|
+
aimancli-0.2.0.dist-info/METADATA,sha256=XBhsmWRN1xgI6xRYc_8xeWlJfAyq_3ckSxuTb9_T4QI,3778
|
|
25
|
+
aimancli-0.2.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
26
|
+
aimancli-0.2.0.dist-info/entry_points.txt,sha256=JB-xKtKvTaG6UTxR6ClTFqjax2OuYDvOaA9zf9tiSGc,41
|
|
27
|
+
aimancli-0.2.0.dist-info/top_level.txt,sha256=6UlZohEQ6xRmJNCJ7_kyZUuff1XzTmEkqvcu8hFMQBg,6
|
|
28
|
+
aimancli-0.2.0.dist-info/RECORD,,
|