kaizen-agent 1.61.6 → 1.62.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/README.md +2 -2
- package/agents/kaizen-builder.md +3 -0
- package/agents/kaizen-planner.md +3 -0
- package/agents/kaizen-reviewer.md +2 -0
- package/assets/kaizen-logo.png +0 -0
- package/assets/kaizen.ico +0 -0
- package/cli/__pycache__/computer-helper.cpython-314.pyc +0 -0
- package/cli/accounts.test.ts +126 -0
- package/cli/accounts.ts +116 -0
- package/cli/add-project.ts +4 -2
- package/cli/agent-prefs.test.ts +127 -0
- package/cli/agent-prefs.ts +106 -0
- package/cli/board.test.ts +4 -5
- package/cli/computer-helper.py +299 -0
- package/cli/computer.test.ts +155 -0
- package/cli/computer.ts +66 -0
- package/cli/dashboard.ts +14 -15
- package/cli/install.ts +67 -4
- package/cli/keep-awake.ts +30 -0
- package/cli/project-tree.test.ts +1 -0
- package/cli/pty.test.ts +2 -1
- package/cli/pty.ts +6 -5
- package/cli/report.test.ts +59 -0
- package/cli/report.ts +62 -0
- package/cli/restart.test.ts +1 -0
- package/cli/settings.test.ts +21 -1
- package/cli/settings.ts +19 -11
- package/cli/setup.test.ts +2 -2
- package/cli/skills.test.ts +89 -0
- package/cli/skills.ts +112 -0
- package/cli/state.test.ts +46 -4
- package/cli/state.ts +127 -41
- package/cli/term-image.test.ts +23 -0
- package/cli/term-image.ts +26 -0
- package/cli/usage.test.ts +8 -2
- package/cli/usage.ts +8 -6
- package/cli/video.test.ts +5 -5
- package/cli/web-accept.test.ts +1 -0
- package/cli/web-decide.test.ts +1 -0
- package/cli/web-pr.test.ts +1 -0
- package/cli/web-skills.test.ts +32 -0
- package/cli/web-symlink.test.ts +1 -0
- package/cli/web.ts +179 -20
- package/cli/workers.test.ts +319 -0
- package/cli/workers.ts +380 -0
- package/cli/worktree.test.ts +21 -2
- package/cli/worktree.ts +21 -2
- package/package.json +1 -1
- package/skills/kaizen/config.default.yml +33 -1
- package/skills/kaizen/settings.md +1 -1
- package/skills/kaizen/skill.json +1 -0
- package/skills/kaizen/spec-build.md +22 -2
- package/skills/kaizen/spec-main.md +9 -0
- package/skills/kaizen/spec-plan.md +18 -1
- package/skills/kaizen/spec-review.md +4 -0
- package/skills/kaizen/spec.md +15 -0
- package/skills/kaizen-help/SKILL.md +1 -0
- package/skills/kaizen-help/skill.json +1 -0
- package/skills/media/kaizen-book/skill.json +1 -0
- package/skills/media/kaizen-deck/skill.json +1 -0
- package/skills/media/kaizen-video/scripts/__pycache__/intake.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/make_film.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/make_tiktok.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/render_cut.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/sfx.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/srt.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/transcribe.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/scripts/__pycache__/vo.cpython-314.pyc +0 -0
- package/skills/media/kaizen-video/skill.json +1 -0
- package/skills/optional/kaizen-computer/SKILL.md +38 -0
- package/skills/optional/kaizen-computer/skill.json +1 -0
- package/web/board/add-project.ts +3 -3
- package/web/board/agent-favicons.ts +9 -0
- package/web/board/agent-term.ts +1 -1
- package/web/board/api.ts +1 -1
- package/web/board/approvals.ts +1 -1
- package/web/board/cards.ts +50 -7
- package/web/board/dictation.ts +46 -3
- package/web/board/fixes.ts +1 -1
- package/web/board/home.ts +1 -1
- package/web/board/icebox.ts +1 -1
- package/web/board/keys.ts +5 -15
- package/web/board/onboarding.ts +1 -1
- package/web/board/panel.ts +24 -20
- package/web/board/phone.ts +4 -1
- package/web/board/run-view.ts +11 -6
- package/web/board/settings-accounts.ts +60 -0
- package/web/board/settings-agents.ts +102 -0
- package/web/board/settings-orchestration.ts +32 -0
- package/web/board/settings-pages.test.ts +5 -0
- package/web/board/settings-pages.ts +10 -4
- package/web/board/settings-skills.ts +47 -0
- package/web/board/settings-voice.test.ts +18 -0
- package/web/board/settings-voice.ts +28 -0
- package/web/board/settings.ts +40 -4
- package/web/board/terms.ts +2 -2
- package/web/board/update.ts +1 -1
- package/web/board/ws-board.test.ts +6 -0
- package/web/board/ws-board.ts +2 -0
- package/web/board.html +15 -3
- package/web/board.js +134 -84
- package/web/notebook.js +2 -2
- package/web/notes.html +3 -3
- package/web/term.js +27 -27
- package/web/term.ts +25 -3
- package/web/video.html +2 -2
- package/web/video.js +2 -2
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Reads and acts on the Linux accessibility tree (AT-SPI) for `kaizen computer`.
|
|
3
|
+
|
|
4
|
+
One JSON object on stdout per call. Verbs: check, apps, windows, state, click,
|
|
5
|
+
set-value, type. Written for kaizen; the limits and the two refusals below are the
|
|
6
|
+
point: an app on the blocklist is matched by name before anything of it is read, and
|
|
7
|
+
a password field never gives a value or takes text.
|
|
8
|
+
"""
|
|
9
|
+
import json
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
import time
|
|
13
|
+
|
|
14
|
+
MAX_NODES, MAX_DEPTH, MAX_TEXT, MAX_INPUT = 300, 8, 200, 10000
|
|
15
|
+
# Matched as a lowercase part of the app's name, before its tree is read.
|
|
16
|
+
BLOCKED = (
|
|
17
|
+
"1password", "bitwarden", "keepass", "lastpass", "dashlane", "enpass", "nordpass",
|
|
18
|
+
"proton pass", "keeper", "roboform", "seahorse", "kwallet", "gnome-keyring", "authy",
|
|
19
|
+
"authenticator", "yubico", "ente auth", "buttercup", "psono",
|
|
20
|
+
)
|
|
21
|
+
SECURE = "password text"
|
|
22
|
+
SETTLE = 0.3 # apps repaint their accessible a moment after an action; the next read should see it
|
|
23
|
+
SHOWN_STATES = ("checked", "selected", "focused", "editable", "expanded", "collapsed", "busy", "required")
|
|
24
|
+
CLICK_NAMES = ("click", "press", "activate", "jump", "toggle", "select")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Fail(Exception):
|
|
28
|
+
def __init__(self, code, msg):
|
|
29
|
+
super().__init__(msg)
|
|
30
|
+
self.code, self.msg = code, msg
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def blocked(name):
|
|
34
|
+
n = (name or "").lower()
|
|
35
|
+
return any(b in n for b in BLOCKED)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class Node:
|
|
39
|
+
"""One accessible. Tests swap in a fake with the same methods."""
|
|
40
|
+
|
|
41
|
+
def __init__(self, a):
|
|
42
|
+
self.a = a
|
|
43
|
+
|
|
44
|
+
def role(self):
|
|
45
|
+
return self.a.get_role_name() or ""
|
|
46
|
+
|
|
47
|
+
def name(self):
|
|
48
|
+
return self.a.get_name() or ""
|
|
49
|
+
|
|
50
|
+
def states(self):
|
|
51
|
+
return [getattr(s, "value_nick", str(s)).replace("-", " ") for s in self.a.get_state_set().get_states()]
|
|
52
|
+
|
|
53
|
+
def count(self):
|
|
54
|
+
return self.a.get_child_count()
|
|
55
|
+
|
|
56
|
+
def child(self, i):
|
|
57
|
+
c = self.a.get_child_at_index(i)
|
|
58
|
+
return Node(c) if c else None
|
|
59
|
+
|
|
60
|
+
def text(self, cap):
|
|
61
|
+
from gi.repository import Atspi
|
|
62
|
+
t = self.a.get_text_iface()
|
|
63
|
+
return None if t is None else Atspi.Text.get_text(t, 0, min(Atspi.Text.get_character_count(t), cap))
|
|
64
|
+
|
|
65
|
+
def number(self):
|
|
66
|
+
from gi.repository import Atspi
|
|
67
|
+
v = self.a.get_value_iface()
|
|
68
|
+
return None if v is None else Atspi.Value.get_current_value(v)
|
|
69
|
+
|
|
70
|
+
def actions(self):
|
|
71
|
+
from gi.repository import Atspi
|
|
72
|
+
i = self.a.get_action_iface()
|
|
73
|
+
return [] if i is None else [Atspi.Action.get_action_name(i, n) for n in range(Atspi.Action.get_n_actions(i))]
|
|
74
|
+
|
|
75
|
+
def do(self, n):
|
|
76
|
+
from gi.repository import Atspi
|
|
77
|
+
return Atspi.Action.do_action(self.a.get_action_iface(), n)
|
|
78
|
+
|
|
79
|
+
def editable(self):
|
|
80
|
+
return self.a.get_editable_text_iface() is not None
|
|
81
|
+
|
|
82
|
+
def set_text(self, s):
|
|
83
|
+
from gi.repository import Atspi
|
|
84
|
+
return Atspi.EditableText.set_text_contents(self.a.get_editable_text_iface(), s)
|
|
85
|
+
|
|
86
|
+
def append_text(self, s):
|
|
87
|
+
from gi.repository import Atspi
|
|
88
|
+
e, t = self.a.get_editable_text_iface(), self.a.get_text_iface()
|
|
89
|
+
end = Atspi.Text.get_character_count(t) if t is not None else 0
|
|
90
|
+
return Atspi.EditableText.insert_text(e, end, s, len(s.encode("utf-8")))
|
|
91
|
+
|
|
92
|
+
def set_number(self, x):
|
|
93
|
+
from gi.repository import Atspi
|
|
94
|
+
v = self.a.get_value_iface()
|
|
95
|
+
return v is not None and Atspi.Value.set_current_value(v, x)
|
|
96
|
+
|
|
97
|
+
def focus(self):
|
|
98
|
+
from gi.repository import Atspi
|
|
99
|
+
try:
|
|
100
|
+
return Atspi.Component.grab_focus(self.a.get_component_iface())
|
|
101
|
+
except Exception: # some toolkits refuse focus; typing still works
|
|
102
|
+
return False
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def secure(n):
|
|
106
|
+
return n.role() == SECURE
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def describe(n, path, depth, budget):
|
|
110
|
+
"""The node and what is under it, inside the limits. A secure field's text is never asked for."""
|
|
111
|
+
budget[0] -= 1
|
|
112
|
+
d = {"id": path, "role": n.role(), "name": n.name()[:MAX_TEXT]}
|
|
113
|
+
if secure(n):
|
|
114
|
+
d["secure"] = True
|
|
115
|
+
else:
|
|
116
|
+
t = n.text(MAX_TEXT + 1) if "text" in n.role() or "entry" in n.role() or n.editable() else None
|
|
117
|
+
if t:
|
|
118
|
+
d["value"] = t[:MAX_TEXT] + ("…" if len(t) > MAX_TEXT else "")
|
|
119
|
+
else:
|
|
120
|
+
x = n.number()
|
|
121
|
+
if x is not None and any(k in n.role() for k in ("slider", "spin", "scroll bar")):
|
|
122
|
+
d["value"] = x
|
|
123
|
+
st = n.states()
|
|
124
|
+
d["states"] = [s for s in SHOWN_STATES if s in st] + ([] if "enabled" in st or "sensitive" in st else ["disabled"])
|
|
125
|
+
acts = n.actions()
|
|
126
|
+
if acts:
|
|
127
|
+
d["actions"] = acts
|
|
128
|
+
kids = []
|
|
129
|
+
if depth >= MAX_DEPTH:
|
|
130
|
+
if n.count():
|
|
131
|
+
d["truncated"] = True
|
|
132
|
+
else:
|
|
133
|
+
for i in range(n.count()):
|
|
134
|
+
if budget[0] <= 0:
|
|
135
|
+
d["truncated"] = True
|
|
136
|
+
break
|
|
137
|
+
c = n.child(i)
|
|
138
|
+
if c is not None and "showing" in c.states():
|
|
139
|
+
kids.append(describe(c, f"{path}.{i}", depth + 1, budget))
|
|
140
|
+
if kids:
|
|
141
|
+
d["children"] = kids
|
|
142
|
+
return d
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def desktop():
|
|
146
|
+
try:
|
|
147
|
+
import gi
|
|
148
|
+
gi.require_version("Atspi", "2.0")
|
|
149
|
+
from gi.repository import Atspi
|
|
150
|
+
except Exception as e:
|
|
151
|
+
raise Fail("no-atspi", f"AT-SPI bindings missing: {e}")
|
|
152
|
+
Atspi.init()
|
|
153
|
+
try:
|
|
154
|
+
return Node(Atspi.get_desktop(0))
|
|
155
|
+
except Exception as e:
|
|
156
|
+
raise Fail("no-a11y", f"accessibility bus unreachable: {e}")
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def app_names(root):
|
|
160
|
+
out = []
|
|
161
|
+
for i in range(root.count()):
|
|
162
|
+
try:
|
|
163
|
+
c = root.child(i)
|
|
164
|
+
except Exception:
|
|
165
|
+
continue
|
|
166
|
+
if c is not None and c.name():
|
|
167
|
+
out.append((c.name(), c))
|
|
168
|
+
return out
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def find_app(root, want):
|
|
172
|
+
"""The one app matching, refused by name before its windows or tree are touched."""
|
|
173
|
+
w, apps = want.lower(), app_names(root)
|
|
174
|
+
hits = [a for a in apps if a[0].lower() == w] or [a for a in apps if w in a[0].lower()]
|
|
175
|
+
if not hits:
|
|
176
|
+
raise Fail("app-not-found", f"no app named {want}")
|
|
177
|
+
if len(hits) > 1:
|
|
178
|
+
raise Fail("ambiguous-app", "several apps match: " + ", ".join(h[0] for h in hits))
|
|
179
|
+
if blocked(hits[0][0]):
|
|
180
|
+
raise Fail("blocked-app", f"{hits[0][0]} is a password manager")
|
|
181
|
+
return hits[0][1]
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def windows_of(app):
|
|
185
|
+
out = []
|
|
186
|
+
for i in range(app.count()):
|
|
187
|
+
w = app.child(i)
|
|
188
|
+
if w is not None:
|
|
189
|
+
out.append((i, w))
|
|
190
|
+
return out
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def resolve(app, path):
|
|
194
|
+
n = app
|
|
195
|
+
try:
|
|
196
|
+
for p in str(path).split("."):
|
|
197
|
+
n = n.child(int(p))
|
|
198
|
+
if n is None:
|
|
199
|
+
raise ValueError
|
|
200
|
+
except Exception:
|
|
201
|
+
raise Fail("stale-ref", f"no node {path}")
|
|
202
|
+
return n
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def check():
|
|
206
|
+
out = {"python": sys.version.split()[0], "session": os.environ.get("XDG_SESSION_TYPE") or "unknown"}
|
|
207
|
+
try:
|
|
208
|
+
root = desktop()
|
|
209
|
+
out.update(atspi=True, a11y=True, apps=root.count())
|
|
210
|
+
except Fail as f:
|
|
211
|
+
out.update(atspi=f.code != "no-atspi", a11y=False, error=f.msg)
|
|
212
|
+
out["ok"] = bool(out.get("a11y"))
|
|
213
|
+
return out
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def switched_on():
|
|
217
|
+
"""The user's on-list, read here too: run by hand with the skill off, the helper refuses."""
|
|
218
|
+
try:
|
|
219
|
+
with open(os.path.join(os.path.expanduser("~"), ".kaizen", "skills-on.json"), encoding="utf8") as f:
|
|
220
|
+
return "kaizen-computer" in json.load(f)
|
|
221
|
+
except (OSError, ValueError, TypeError):
|
|
222
|
+
return False
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def run(verb, a):
|
|
226
|
+
if verb == "check":
|
|
227
|
+
return check()
|
|
228
|
+
if not switched_on():
|
|
229
|
+
raise Fail("disabled", "Desktop control is turned off")
|
|
230
|
+
need = {"apps": 0, "windows": 1, "state": (1, 2), "click": 2, "set-value": 3, "type": 3}.get(verb)
|
|
231
|
+
if need is None or len(a) not in ((need,) if isinstance(need, int) else need):
|
|
232
|
+
raise Fail("bad-usage", f"bad call: {verb}")
|
|
233
|
+
root = desktop()
|
|
234
|
+
if verb == "apps":
|
|
235
|
+
return {"ok": True, "apps": [{"name": n, "windows": c.count(), "blocked": blocked(n)} for n, c in app_names(root)]}
|
|
236
|
+
app = find_app(root, a[0])
|
|
237
|
+
if verb == "windows":
|
|
238
|
+
return {"ok": True, "app": a[0], "windows": [{"index": i, "title": w.name()} for i, w in windows_of(app)]}
|
|
239
|
+
if verb == "state":
|
|
240
|
+
ws = windows_of(app)
|
|
241
|
+
i = int(a[1]) if len(a) > 1 and a[1].isdigit() else (ws[0][0] if ws else None)
|
|
242
|
+
w = next((w for j, w in ws if j == i), None)
|
|
243
|
+
if w is None:
|
|
244
|
+
raise Fail("window-not-found", "no such window")
|
|
245
|
+
budget = [MAX_NODES]
|
|
246
|
+
tree = describe(w, str(i), 0, budget)
|
|
247
|
+
return {"ok": True, "app": a[0], "window": i, "nodes": MAX_NODES - budget[0], "tree": tree}
|
|
248
|
+
return act(app, verb, a)
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def act(app, verb, a):
|
|
252
|
+
n = resolve(app, a[1])
|
|
253
|
+
if verb == "click":
|
|
254
|
+
names = n.actions()
|
|
255
|
+
pick = next((i for i, x in enumerate(names) if x.lower() in CLICK_NAMES), 0 if names else None)
|
|
256
|
+
if pick is None:
|
|
257
|
+
raise Fail("no-action", "that node has no action")
|
|
258
|
+
n.do(pick)
|
|
259
|
+
time.sleep(SETTLE)
|
|
260
|
+
return {"ok": True, "did": names[pick]}
|
|
261
|
+
# set-value and type: a secure field is refused before any text is read or written.
|
|
262
|
+
if secure(n):
|
|
263
|
+
raise Fail("secure-field", "that field is a password field")
|
|
264
|
+
text = a[2]
|
|
265
|
+
if len(text) > MAX_INPUT:
|
|
266
|
+
raise Fail("too-large", "text over the input limit")
|
|
267
|
+
if verb == "set-value":
|
|
268
|
+
if n.editable():
|
|
269
|
+
n.set_text(text)
|
|
270
|
+
else:
|
|
271
|
+
try:
|
|
272
|
+
x = float(text)
|
|
273
|
+
except ValueError:
|
|
274
|
+
raise Fail("not-editable", "that node takes a number, not text")
|
|
275
|
+
if not n.set_number(x):
|
|
276
|
+
raise Fail("not-editable", "that node cannot be set")
|
|
277
|
+
time.sleep(SETTLE)
|
|
278
|
+
got = n.text(MAX_TEXT) if n.editable() else n.number()
|
|
279
|
+
return {"ok": True, "value": got}
|
|
280
|
+
if not n.editable():
|
|
281
|
+
raise Fail("not-editable", "that node is not an editable field")
|
|
282
|
+
n.focus()
|
|
283
|
+
n.append_text(text)
|
|
284
|
+
time.sleep(SETTLE)
|
|
285
|
+
return {"ok": True, "value": n.text(MAX_TEXT)}
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def main(argv):
|
|
289
|
+
try:
|
|
290
|
+
out = run(argv[0] if argv else "", argv[1:])
|
|
291
|
+
except Fail as f:
|
|
292
|
+
out = {"ok": False, "code": f.code, "error": f.msg}
|
|
293
|
+
except Exception as e: # a toolkit error is reported, not a traceback
|
|
294
|
+
out = {"ok": False, "code": "helper-failed", "error": f"{type(e).__name__}: {e}"}
|
|
295
|
+
print(json.dumps(out, ensure_ascii=False))
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
if __name__ == "__main__":
|
|
299
|
+
main(sys.argv[1:])
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { afterEach, beforeEach, expect, test } from "bun:test";
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { computer, computerCheck } from "./computer.ts";
|
|
6
|
+
import { bundledSkills, setSkill, skillsHeld, skillsToLink } from "./skills.ts";
|
|
7
|
+
|
|
8
|
+
const repo = join(import.meta.dir, "..");
|
|
9
|
+
let t: string, home: string, fake: string[];
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
t = mkdtempSync(join(tmpdir(), "kz-computer-"));
|
|
12
|
+
home = join(t, "home");
|
|
13
|
+
mkdirSync(join(home, ".claude"), { recursive: true });
|
|
14
|
+
// A stand-in helper: prints the argv it was given, so a test sees exactly what arrived.
|
|
15
|
+
const f = join(t, "fake.js");
|
|
16
|
+
writeFileSync(f, `const a = process.argv.slice(2);
|
|
17
|
+
if (a[0] === "big") console.log(JSON.stringify({ ok: true, pad: "x".repeat(300000) }));
|
|
18
|
+
else if (a[0] === "state" && a[1] === "nope") console.log(JSON.stringify({ ok: false, code: "app-not-found", error: "no app" }));
|
|
19
|
+
else console.log(JSON.stringify({ ok: true, argv: a }));`);
|
|
20
|
+
fake = [process.execPath, f];
|
|
21
|
+
});
|
|
22
|
+
afterEach(() => rmSync(t, { recursive: true, force: true }));
|
|
23
|
+
const turnOn = () => setSkill(repo, home, "kaizen-computer", true, true);
|
|
24
|
+
|
|
25
|
+
test("G-01: off after install and upgrade, with no links; on needs confirm", () => {
|
|
26
|
+
const s = bundledSkills(repo).find((x) => x.id === "kaizen-computer")!;
|
|
27
|
+
expect([s.group, s.offByDefault]).toEqual(["optional", true]);
|
|
28
|
+
const held = skillsHeld(repo, home);
|
|
29
|
+
expect(held).toContain("kaizen-computer");
|
|
30
|
+
const rels = bundledSkills(repo).map((x) => x.rel);
|
|
31
|
+
for (const global of [true, false]) expect(skillsToLink(rels, [], global, held)).not.toContain("optional/kaizen-computer");
|
|
32
|
+
expect(skillsToLink(["kaizen"], [], true, ["kaizen"])).toEqual(["kaizen"]);
|
|
33
|
+
expect(setSkill(repo, home, "kaizen-computer", true)).toBe("confirm required");
|
|
34
|
+
expect(skillsHeld(repo, home)).toContain("kaizen-computer");
|
|
35
|
+
expect(turnOn()).toBeNull();
|
|
36
|
+
expect(skillsHeld(repo, home)).not.toContain("kaizen-computer");
|
|
37
|
+
expect(skillsToLink(rels, [], true, skillsHeld(repo, home))).toContain("optional/kaizen-computer");
|
|
38
|
+
expect(setSkill(repo, home, "kaizen-computer", false)).toBeNull();
|
|
39
|
+
expect(skillsHeld(repo, home)).toContain("kaizen-computer");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("G-02: every command refuses while off, before the helper runs", async () => {
|
|
43
|
+
for (const argv of [["apps"], ["windows", "a"], ["state", "a"], ["click", "a", "0"], ["set-value", "a", "0", "x"], ["type", "a", "0", "x"], ["nonsense"]]) {
|
|
44
|
+
const r = await computer(argv, { home, cmd: fake });
|
|
45
|
+
expect(r.code).toBe(1);
|
|
46
|
+
expect(r.out).toMatchObject({ ok: false, code: "disabled" });
|
|
47
|
+
expect(String(r.out.recovery)).toContain("Settings");
|
|
48
|
+
}
|
|
49
|
+
turnOn();
|
|
50
|
+
expect((await computer(["apps"], { home, cmd: fake })).out.ok).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("G-05: arguments reach the helper as plain argv, output is capped, bad calls and errors carry recovery", async () => {
|
|
54
|
+
turnOn();
|
|
55
|
+
const evil = "x; touch /tmp/kz-pwn $(id) `id` | cat";
|
|
56
|
+
const r = await computer(["type", "App Name", "0.1", evil], { home, cmd: fake });
|
|
57
|
+
expect(r.out.argv).toEqual(["type", "App Name", "0.1", evil]);
|
|
58
|
+
expect(await computer(["state", "a", "b", "c"], { home, cmd: fake })).toMatchObject({ code: 1, out: { code: "bad-usage" } });
|
|
59
|
+
expect((await computer(["big"], { home, cmd: fake })).code).toBe(1); // not a verb
|
|
60
|
+
const huge = await computer(["apps"], { home, cmd: [process.execPath, "-e", 'console.log(JSON.stringify({ok:true,pad:"x".repeat(300000)}))'] });
|
|
61
|
+
expect(huge.out).toMatchObject({ ok: false, code: "too-large" });
|
|
62
|
+
const err = await computer(["state", "nope"], { home, cmd: fake });
|
|
63
|
+
expect(err.out).toMatchObject({ ok: false, code: "app-not-found" });
|
|
64
|
+
expect(String(err.out.recovery)).toContain("apps");
|
|
65
|
+
const junk = await computer(["apps"], { home, cmd: [process.execPath, "-e", "console.log('not json')"] });
|
|
66
|
+
expect(junk.out).toMatchObject({ code: "helper-failed" });
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// The helper's own logic, on fake nodes: no desktop needed. Skipped where python3 is missing.
|
|
70
|
+
const py = Bun.which("python3");
|
|
71
|
+
const probe = (body: string) => {
|
|
72
|
+
const dir = join(repo, "cli");
|
|
73
|
+
const code = `import sys, json\nsys.path.insert(0, ${JSON.stringify(dir)})\nimport importlib.util as u\nspec = u.spec_from_file_location("h", ${JSON.stringify(join(dir, "computer-helper.py"))})\nh = u.module_from_spec(spec); spec.loader.exec_module(h)\n${body}`;
|
|
74
|
+
const r = Bun.spawnSync([py!, "-I", "-c", code], { stdout: "pipe", stderr: "pipe" });
|
|
75
|
+
if (r.exitCode) throw new Error(r.stderr.toString());
|
|
76
|
+
return JSON.parse(r.stdout.toString());
|
|
77
|
+
};
|
|
78
|
+
const FAKE = `
|
|
79
|
+
class F(h.Node):
|
|
80
|
+
def __init__(s, role, name="", kids=(), text=None, edit=False, st=("showing", "enabled")):
|
|
81
|
+
s._r, s._n, s.k, s._t, s._e, s._s, s.log = role, name, list(kids), text, edit, list(st), []
|
|
82
|
+
def role(s): return s._r
|
|
83
|
+
def name(s): return s._n
|
|
84
|
+
def states(s): return s._s
|
|
85
|
+
def count(s): return len(s.k)
|
|
86
|
+
def child(s, i): return s.k[i]
|
|
87
|
+
def text(s, cap):
|
|
88
|
+
if s._r == h.SECURE: raise AssertionError("secret read")
|
|
89
|
+
return s._t
|
|
90
|
+
def number(s): return None
|
|
91
|
+
def actions(s): return []
|
|
92
|
+
def editable(s): return s._e
|
|
93
|
+
def set_text(s, v): s.log.append(("set", v))
|
|
94
|
+
def append_text(s, v): s.log.append(("add", v))
|
|
95
|
+
def focus(s): return True
|
|
96
|
+
`;
|
|
97
|
+
|
|
98
|
+
test.skipIf(!py)("G-03: a password manager is matched by name before its tree is read", () => {
|
|
99
|
+
const r = probe(`${FAKE}
|
|
100
|
+
class Boom(F):
|
|
101
|
+
def count(s): raise AssertionError("tree read")
|
|
102
|
+
def child(s, i): raise AssertionError("tree read")
|
|
103
|
+
root = F("desktop", kids=[Boom("application", "KeePassXC"), F("application", "Editor")])
|
|
104
|
+
try: h.find_app(root, "keepass"); got = "no refusal"
|
|
105
|
+
except h.Fail as f: got = f.code
|
|
106
|
+
print(json.dumps({"got": got, "other": h.find_app(root, "edit").name(), "flag": [h.blocked(x) for x in ("1Password", "Bitwarden", "gedit")]}))`);
|
|
107
|
+
expect(r).toEqual({ got: "blocked-app", other: "Editor", flag: [true, true, false] });
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test.skipIf(!py)("G-04: a secure field gives no value and refuses set-value and type; the tree is capped", () => {
|
|
111
|
+
const r = probe(`${FAKE}
|
|
112
|
+
pw = F("password text", "Password", text="hunter2", edit=True)
|
|
113
|
+
box = F("text", "Name", text="ada", edit=True)
|
|
114
|
+
win = F("frame", "Login", kids=[box, pw])
|
|
115
|
+
app = F("application", "Login", kids=[win])
|
|
116
|
+
d = h.describe(win, "0", 0, [300])
|
|
117
|
+
codes = []
|
|
118
|
+
for verb in ("set-value", "type"):
|
|
119
|
+
try: h.act(app, verb, [app.name(), "0.1", "x"]); codes.append("accepted")
|
|
120
|
+
except h.Fail as f: codes.append(f.code)
|
|
121
|
+
big = F("frame", "W", kids=[F("button", "b" + str(i)) for i in range(1000)])
|
|
122
|
+
cap = h.describe(big, "0", 0, [300])
|
|
123
|
+
deep = F("frame", "d")
|
|
124
|
+
n = deep
|
|
125
|
+
for i in range(20):
|
|
126
|
+
c = F("panel", "p"); n.k.append(c); n = c
|
|
127
|
+
dd = h.describe(deep, "0", 0, [300])
|
|
128
|
+
depth = 0; x = dd
|
|
129
|
+
while x.get("children"): x = x["children"][0]; depth += 1
|
|
130
|
+
print(json.dumps({"pw": d["children"][1], "box": d["children"][0].get("value"), "nodes": len(cap["children"]), "trunc": cap.get("truncated"), "depth": depth, "long": len(h.describe(F("text", "n", text="y" * 900), "0", 0, [9])["value"]), "pwlog": pw.log, "codes": codes}))`);
|
|
131
|
+
expect(r.pw).toEqual({ id: "0.1", role: "password text", name: "Password", secure: true, states: [] });
|
|
132
|
+
expect(r.box).toBe("ada");
|
|
133
|
+
expect(r.codes).toEqual(["secure-field", "secure-field"]);
|
|
134
|
+
expect([r.nodes, r.trunc, r.depth, r.pwlog]).toEqual([299, true, 8, []]);
|
|
135
|
+
expect(r.long).toBeLessThanOrEqual(201);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("the row's check never throws, and Wayland shows its note", () => {
|
|
139
|
+
const c = computerCheck([process.execPath, "-e", 'console.log(JSON.stringify({ok:true,atspi:true,a11y:false}))']);
|
|
140
|
+
expect(c.needs).toEqual([{ name: "AT-SPI bindings", found: true }, { name: "accessibility on", found: false }]);
|
|
141
|
+
expect(computerCheck([process.execPath, "-e", "process.exit(3)"]).needs.every((n) => !n.found)).toBe(true);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// The real helper, run by hand with no on-list: it must refuse by itself, not rely on computer.ts.
|
|
145
|
+
test.skipIf(!py)("the helper refuses on its own while the skill is off, and a corrupt on-list counts as off", () => {
|
|
146
|
+
const run = (verb: string[]) => JSON.parse(Bun.spawnSync([py!, "-I", join(repo, "cli", "computer-helper.py"), ...verb], { env: { ...process.env, HOME: home, USERPROFILE: home }, stdout: "pipe", stderr: "ignore" }).stdout.toString());
|
|
147
|
+
for (const v of [["apps"], ["state", "a"], ["click", "a", "0"], ["set-value", "a", "0", "x"], ["type", "a", "0", "x"]]) expect(run(v)).toMatchObject({ ok: false, code: "disabled" });
|
|
148
|
+
mkdirSync(join(home, ".kaizen"), { recursive: true });
|
|
149
|
+
writeFileSync(join(home, ".kaizen", "skills-on.json"), "{not json");
|
|
150
|
+
expect(run(["apps"])).toMatchObject({ code: "disabled" });
|
|
151
|
+
writeFileSync(join(home, ".kaizen", "skills-on.json"), JSON.stringify(["kaizen-deck"]));
|
|
152
|
+
expect(run(["apps"])).toMatchObject({ code: "disabled" });
|
|
153
|
+
writeFileSync(join(home, ".kaizen", "skills-on.json"), JSON.stringify(["kaizen-computer"]));
|
|
154
|
+
expect(run(["apps"]).code).not.toBe("disabled"); // on: it goes on to the desktop, which may have no bus here
|
|
155
|
+
});
|
package/cli/computer.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// `kaizen computer`: desktop control through the Linux accessibility tree, for the
|
|
2
|
+
// kaizen-computer skill. It refuses every verb until that skill is turned on, passes
|
|
3
|
+
// arguments to cli/computer-helper.py without a shell, and prints one JSON result per
|
|
4
|
+
// call; each error carries a `recovery` step.
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { skillsOn } from "./skills.ts";
|
|
7
|
+
|
|
8
|
+
export const SKILL = "kaizen-computer";
|
|
9
|
+
const HELPER = join(import.meta.dir, "computer-helper.py");
|
|
10
|
+
const MAX_OUT = 200_000, TIMEOUT = 15_000;
|
|
11
|
+
const VERBS: Record<string, [number, number]> = { apps: [0, 0], windows: [1, 1], state: [1, 2], click: [2, 2], "set-value": [3, 3], type: [3, 3] };
|
|
12
|
+
const USAGE = "apps | windows <app> | state <app> [window] | click <app> <id> | set-value <app> <id> <value> | type <app> <id> <text>";
|
|
13
|
+
|
|
14
|
+
const RECOVERY: Record<string, string> = {
|
|
15
|
+
disabled: "Ask the user to turn on Desktop control in Settings → Skills. Do not try another way to reach the desktop.",
|
|
16
|
+
unsupported: "Desktop control works on Linux only. Tell the user; do not retry.",
|
|
17
|
+
"bad-usage": `Call it as: kaizen computer ${USAGE}.`,
|
|
18
|
+
"no-python": "Install python3 with PyGObject and AT-SPI (Arch: python-gobject at-spi2-core; Debian: python3-gi gir1.2-atspi-2.0), then retry.",
|
|
19
|
+
"no-atspi": "Install the AT-SPI Python bindings (Arch: python-gobject at-spi2-core; Debian: python3-gi gir1.2-atspi-2.0), then retry.",
|
|
20
|
+
"no-a11y": "Accessibility is off or its bus is not running. Ask the user to enable it (GNOME: Settings → Accessibility; others: start at-spi-bus-launcher), then retry.",
|
|
21
|
+
"app-not-found": "Run `kaizen computer apps` and use a name from that list. An app with accessibility off, or not started, is not listed; ask the user to open it.",
|
|
22
|
+
"ambiguous-app": "Use a longer part of the app's name, or the exact name from `kaizen computer apps`.",
|
|
23
|
+
"blocked-app": "Password managers are never read or operated. Stop and tell the user; do not look for another way in.",
|
|
24
|
+
"window-not-found": "Run `kaizen computer windows <app>` and pass an index from it.",
|
|
25
|
+
"stale-ref": "The window changed. Run `kaizen computer state <app>` again and use an id from the new result.",
|
|
26
|
+
"secure-field": "Password fields are never read or filled. Ask the user to enter it themselves.",
|
|
27
|
+
"no-action": "That node cannot be clicked. Run `state` and pick a node that lists `actions`, such as a button.",
|
|
28
|
+
"not-editable": "That node takes no text. Pick a node whose states include `editable`, or a slider for a number.",
|
|
29
|
+
"too-large": "Send less text, or split it into several calls.",
|
|
30
|
+
timeout: "The app did not answer in time. Check it is not frozen, then retry once.",
|
|
31
|
+
"helper-failed": "The helper broke on this call. Run `kaizen computer apps` to check the setup, then retry once; if it repeats, tell the user.",
|
|
32
|
+
};
|
|
33
|
+
const fail = (code: string, error: string) => ({ out: { ok: false, code, error, recovery: RECOVERY[code] ?? RECOVERY["helper-failed"] }, code: 1 });
|
|
34
|
+
|
|
35
|
+
export type Opts = { home: string; cmd?: string[] };
|
|
36
|
+
|
|
37
|
+
export async function computer(argv: string[], o: Opts): Promise<{ out: Record<string, unknown>; code: number }> {
|
|
38
|
+
if (!skillsOn(o.home).includes(SKILL)) return fail("disabled", "Desktop control is turned off");
|
|
39
|
+
const [verb = "", ...args] = argv, n = VERBS[verb];
|
|
40
|
+
if (!n || args.length < n[0] || args.length > n[1]) return fail("bad-usage", `bad call: ${argv.join(" ")}`);
|
|
41
|
+
if (!o.cmd && process.platform !== "linux") return fail("unsupported", "Linux only");
|
|
42
|
+
const py = o.cmd ? null : Bun.which("python3");
|
|
43
|
+
if (!o.cmd && !py) return fail("no-python", "python3 not found");
|
|
44
|
+
// Argv only: the model's text reaches the helper as plain arguments, never a shell line.
|
|
45
|
+
const p = Bun.spawn([...(o.cmd ?? [py!, "-I", HELPER]), verb, ...args], { stdin: "ignore", stdout: "pipe", stderr: "ignore", timeout: TIMEOUT });
|
|
46
|
+
const text = await new Response(p.stdout).text();
|
|
47
|
+
await p.exited;
|
|
48
|
+
if (p.signalCode) return fail("timeout", "helper timed out");
|
|
49
|
+
if (text.length > MAX_OUT) return fail("too-large", "result over the output limit");
|
|
50
|
+
let r: any;
|
|
51
|
+
try { r = JSON.parse(text); } catch { return fail("helper-failed", "helper returned no JSON"); }
|
|
52
|
+
if (!r || typeof r !== "object") return fail("helper-failed", "helper returned no JSON");
|
|
53
|
+
return r.ok === false ? fail(String(r.code ?? "helper-failed"), String(r.error ?? "failed")) : { out: r, code: 0 };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// What Settings shows on the row: what this machine lacks, from the helper's own check.
|
|
57
|
+
export function computerCheck(cmd?: string[]): { needs: { name: string; found: boolean }[]; note: string } {
|
|
58
|
+
const wayland = process.env.XDG_SESSION_TYPE === "wayland";
|
|
59
|
+
const note = (wayland ? "Wayland: keyboard shortcuts and screenshots are not available. Values, accessibility actions and typing into fields work where the app exposes them. " : "") + "Password managers are blocked by app name only: one in a browser or under another name is not.";
|
|
60
|
+
const py = Bun.which("python3");
|
|
61
|
+
if (!cmd && (process.platform !== "linux" || !py)) return { needs: [{ name: process.platform === "linux" ? "python3" : "Linux", found: false }], note };
|
|
62
|
+
const r = Bun.spawnSync([...(cmd ?? [py!, "-I", HELPER]), "check"], { stdout: "pipe", stderr: "ignore", timeout: 5000 });
|
|
63
|
+
let c: any = {};
|
|
64
|
+
try { c = JSON.parse(r.stdout.toString()); } catch { /* an unreadable check counts as missing */ }
|
|
65
|
+
return { needs: [{ name: "AT-SPI bindings", found: c.atspi === true }, { name: "accessibility on", found: c.a11y === true }], note };
|
|
66
|
+
}
|
package/cli/dashboard.ts
CHANGED
|
@@ -24,20 +24,19 @@ const c = {
|
|
|
24
24
|
red: (s: string) => rgb(232, 80, 80, s),
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
// The
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"⠀⠀⠀⠀⠀⠀⠀⠳⣀⣨⠥⠤⠶⠾⣅⣀⠞⠉⠉⠉⠉⠀⠀⠀",
|
|
27
|
+
// The K mark, the K of the wordmark, as in site/media/favicon.svg.
|
|
28
|
+
const MARK = [
|
|
29
|
+
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀",
|
|
30
|
+
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀",
|
|
31
|
+
"⠀⠀⠀⠀⠀⠀⠀⠀██⠀⠀⠀⠀██⠀⠀⠀⠀⠀⠀⠀⠀",
|
|
32
|
+
"⠀⠀⠀⠀⠀⠀⠀⠀██⠀⠀██⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀",
|
|
33
|
+
"⠀⠀⠀⠀⠀⠀⠀⠀████⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀",
|
|
34
|
+
"⠀⠀⠀⠀⠀⠀⠀⠀████⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀",
|
|
35
|
+
"⠀⠀⠀⠀⠀⠀⠀⠀██⠀⠀██⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀",
|
|
36
|
+
"⠀⠀⠀⠀⠀⠀⠀⠀██⠀⠀⠀⠀██⠀⠀⠀⠀⠀⠀⠀⠀",
|
|
37
|
+
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀",
|
|
38
|
+
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀",
|
|
39
|
+
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀",
|
|
41
40
|
];
|
|
42
41
|
|
|
43
42
|
// Compact block wordmark (28 columns x 3 rows).
|
|
@@ -950,7 +949,7 @@ export async function dashboard(
|
|
|
950
949
|
// the runs -- the thing you opened this for -- below the fold on a short window.
|
|
951
950
|
const cols = stdout.columns ?? 80, rows = stdout.rows ?? 24;
|
|
952
951
|
const wide = cols >= 64;
|
|
953
|
-
const art =
|
|
952
|
+
const art = MARK;
|
|
954
953
|
const at = 2; // where the text sits against it
|
|
955
954
|
|
|
956
955
|
// Every width below is measured, not guessed: the mascot's own width plus the
|