@phyzess/kitto 0.0.0-stage → 0.1.1
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/CHANGELOG.md +35 -0
- package/README.md +24 -2
- package/bin/kitto.mjs +24 -0
- package/bin/maintain.mjs +9 -0
- package/integration/cordis.patch.yml +3 -0
- package/integration/dsh.mjs +21 -0
- package/integration/pi.mjs +14 -0
- package/integration/plugin.json +6 -0
- package/integration/skills/kitto/SKILL.md +39 -0
- package/lib/dependencies.mjs +178 -0
- package/lib/host-config.mjs +70 -0
- package/lib/kitto.mjs +576 -0
- package/lib/pi_config.py +330 -0
- package/lib/update-notice.mjs +26 -0
- package/lib/versions.mjs +139 -0
- package/package.json +16 -4
- package/sync.sh +480 -0
package/lib/pi_config.py
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Structural merge helpers for pi-config sync.
|
|
3
|
+
|
|
4
|
+
Three responsibilities, each exposed as a subcommand so sync.sh can stay in bash:
|
|
5
|
+
|
|
6
|
+
merge-settings repo settings + machine settings + machine-only packages -> machine settings
|
|
7
|
+
sanitize-settings machine settings -> repo settings (drops volatile keys)
|
|
8
|
+
merge-mcp repo + platform + machine local + machine -> machine mcp.json
|
|
9
|
+
|
|
10
|
+
Shared definitions are updated while machine overrides and runtime switches
|
|
11
|
+
stay local. Preview helpers write only their explicit output path.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import os
|
|
18
|
+
import sys
|
|
19
|
+
import tempfile
|
|
20
|
+
|
|
21
|
+
VOLATILE_KEYS = ("lastChangelogVersion", "extensionChangelogVersions")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# ---------------------------------------------------------------- helpers
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def load(path: str, default=None):
|
|
28
|
+
if not path or not os.path.exists(path):
|
|
29
|
+
return default
|
|
30
|
+
with open(path, encoding="utf-8") as fh:
|
|
31
|
+
try:
|
|
32
|
+
return json.load(fh)
|
|
33
|
+
except json.JSONDecodeError as exc:
|
|
34
|
+
sys.exit(f"invalid JSON in {path}: {exc}")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def dump(path: str, data) -> bool:
|
|
38
|
+
"""Write JSON atomically. Returns True when the file changed."""
|
|
39
|
+
text = json.dumps(data, indent=2, ensure_ascii=False) + "\n"
|
|
40
|
+
old = None
|
|
41
|
+
if os.path.exists(path):
|
|
42
|
+
with open(path, encoding="utf-8") as fh:
|
|
43
|
+
old = fh.read()
|
|
44
|
+
if old == text:
|
|
45
|
+
return False
|
|
46
|
+
os.makedirs(os.path.dirname(path) or ".", exist_ok=True)
|
|
47
|
+
fd, tmp = tempfile.mkstemp(dir=os.path.dirname(path) or ".", prefix=".kitto-")
|
|
48
|
+
try:
|
|
49
|
+
with os.fdopen(fd, "w", encoding="utf-8") as fh:
|
|
50
|
+
fh.write(text)
|
|
51
|
+
os.replace(tmp, path)
|
|
52
|
+
finally:
|
|
53
|
+
if os.path.exists(tmp):
|
|
54
|
+
os.unlink(tmp)
|
|
55
|
+
return True
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def dump_semantic(path: str, data) -> bool:
|
|
59
|
+
"""Like dump(), but leaves the file byte-identical when the JSON means the
|
|
60
|
+
same thing. Keeps the repo's own formatting until a real change lands."""
|
|
61
|
+
if os.path.exists(path) and load(path) == data:
|
|
62
|
+
return False
|
|
63
|
+
return dump(path, data)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def read_list(path: str) -> list[str]:
|
|
67
|
+
if not os.path.exists(path):
|
|
68
|
+
return []
|
|
69
|
+
out = []
|
|
70
|
+
with open(path, encoding="utf-8") as fh:
|
|
71
|
+
for raw in fh:
|
|
72
|
+
value = raw.strip()
|
|
73
|
+
if value.startswith("#"):
|
|
74
|
+
continue
|
|
75
|
+
if value:
|
|
76
|
+
out.append(value)
|
|
77
|
+
return out
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def write_list(path: str, values: list[str]) -> None:
|
|
81
|
+
os.makedirs(os.path.dirname(path) or ".", exist_ok=True)
|
|
82
|
+
body = "\n".join(values)
|
|
83
|
+
with open(path, "w", encoding="utf-8") as fh:
|
|
84
|
+
fh.write(f"# generated by sync.sh pull — machine-only pi packages\n{body}\n" if body else
|
|
85
|
+
"# generated by sync.sh pull — machine-only pi packages\n")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def deep_merge(base, over):
|
|
89
|
+
"""Dicts merge recursively, everything else is replaced by `over`."""
|
|
90
|
+
if isinstance(base, dict) and isinstance(over, dict):
|
|
91
|
+
out = dict(base)
|
|
92
|
+
for key, value in over.items():
|
|
93
|
+
out[key] = deep_merge(out[key], value) if key in out else value
|
|
94
|
+
return out
|
|
95
|
+
return over
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def unique(seq):
|
|
99
|
+
seen = set()
|
|
100
|
+
out = []
|
|
101
|
+
for item in seq:
|
|
102
|
+
key = json.dumps(item, sort_keys=True)
|
|
103
|
+
if key not in seen:
|
|
104
|
+
seen.add(key)
|
|
105
|
+
out.append(item)
|
|
106
|
+
return out
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# ---------------------------------------------------------------- commands
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def package_key(package):
|
|
113
|
+
source = package if isinstance(package, str) else package.get("source", "")
|
|
114
|
+
if source.startswith("npm:"):
|
|
115
|
+
spec = source.removeprefix("npm:")
|
|
116
|
+
if spec.rfind("@") > 0:
|
|
117
|
+
source = "npm:" + spec.rsplit("@", 1)[0]
|
|
118
|
+
elif source.startswith(("git:github.com/", "https://github.com/")):
|
|
119
|
+
repo = source.split("github.com/", 1)[1].split("@", 1)[0].removesuffix(".git")
|
|
120
|
+
source = "github.com/" + repo
|
|
121
|
+
return source
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def cmd_list_shared_packages(argv: list[str]) -> int:
|
|
125
|
+
repo_path, skip_path = argv
|
|
126
|
+
skip = {package_key(item) for item in read_list(skip_path)}
|
|
127
|
+
for package in load(repo_path)["packages"]:
|
|
128
|
+
if package_key(package) not in skip:
|
|
129
|
+
print(package if isinstance(package, str) else package["source"])
|
|
130
|
+
return 0
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def cmd_merge_settings(argv: list[str]) -> int:
|
|
134
|
+
repo_path, machine_path, local_dir, out_path = argv
|
|
135
|
+
repo_cfg = load(repo_path, {}) or {}
|
|
136
|
+
machine_cfg = load(machine_path, {}) or {}
|
|
137
|
+
for key in VOLATILE_KEYS:
|
|
138
|
+
repo_cfg.pop(key, None)
|
|
139
|
+
|
|
140
|
+
extra_path = os.path.join(local_dir, "packages.txt")
|
|
141
|
+
skip = {package_key(item) for item in read_list(os.path.join(local_dir, "packages.skip.txt"))}
|
|
142
|
+
|
|
143
|
+
extra = read_list(extra_path)
|
|
144
|
+
previous = load(os.path.join(local_dir, "managed-packages.json"), []) or []
|
|
145
|
+
# Unknown packages remain local. Previously managed entries can be removed
|
|
146
|
+
# by deleting them from the shared source. No source mutation during preview.
|
|
147
|
+
repo_pkgs = repo_cfg.get("packages", [])
|
|
148
|
+
extra = unique(extra + [p for p in machine_cfg.get("packages", [])
|
|
149
|
+
if p not in repo_pkgs and p not in previous])
|
|
150
|
+
|
|
151
|
+
overrides = load(os.path.join(local_dir, "settings.json"), {}) or {}
|
|
152
|
+
|
|
153
|
+
# Start from what the machine already has (keeps runtime keys), let the repo
|
|
154
|
+
# own the keys it declares, then apply this machine's overrides.
|
|
155
|
+
result = dict(machine_cfg)
|
|
156
|
+
for key, value in repo_cfg.items():
|
|
157
|
+
result[key] = value
|
|
158
|
+
result = deep_merge(result, overrides)
|
|
159
|
+
|
|
160
|
+
before = list(machine_cfg.get("packages", []))
|
|
161
|
+
packages = unique(
|
|
162
|
+
[p for p in (repo_pkgs + extra)
|
|
163
|
+
if package_key(p) not in skip]
|
|
164
|
+
)
|
|
165
|
+
result["packages"] = packages
|
|
166
|
+
|
|
167
|
+
changed = dump(out_path, result)
|
|
168
|
+
added = [p for p in packages if p not in before]
|
|
169
|
+
removed = [p for p in before if p not in packages]
|
|
170
|
+
print(f"settings: {'updated' if changed else 'unchanged'}")
|
|
171
|
+
if added:
|
|
172
|
+
print(" packages added: " + ", ".join(map(str, added)))
|
|
173
|
+
if removed:
|
|
174
|
+
print(" packages dropped: " + ", ".join(map(str, removed)))
|
|
175
|
+
if extra:
|
|
176
|
+
print(" machine-only packages kept: " + ", ".join(map(str, extra)))
|
|
177
|
+
return 0
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def cmd_record_settings(argv: list[str]) -> int:
|
|
181
|
+
"""Record ownership only after a successful real settings deployment."""
|
|
182
|
+
repo_path, machine_path, local_dir = argv
|
|
183
|
+
repo = load(repo_path, {}).get("packages", [])
|
|
184
|
+
machine = load(machine_path, {}).get("packages", [])
|
|
185
|
+
extra_path = os.path.join(local_dir, "packages.txt")
|
|
186
|
+
extra = unique(read_list(extra_path) + [p for p in machine if p not in repo])
|
|
187
|
+
# Pi object-form package entries are preserved in settings but not flattened
|
|
188
|
+
# into a text list. The ownership record still supports them.
|
|
189
|
+
write_list(extra_path, [p for p in extra if isinstance(p, str)])
|
|
190
|
+
dump(os.path.join(local_dir, "managed-packages.json"), repo)
|
|
191
|
+
return 0
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def restore_overrides(out, repo, overrides):
|
|
195
|
+
"""Remove machine-owned values from export, restoring shared defaults."""
|
|
196
|
+
result = dict(out)
|
|
197
|
+
for key, value in overrides.items():
|
|
198
|
+
if isinstance(value, dict) and isinstance(result.get(key), dict):
|
|
199
|
+
result[key] = restore_overrides(result[key], repo.get(key, {})
|
|
200
|
+
if isinstance(repo.get(key), dict) else {}, value)
|
|
201
|
+
if not result[key] and key not in repo:
|
|
202
|
+
result.pop(key)
|
|
203
|
+
elif key in repo:
|
|
204
|
+
result[key] = repo[key]
|
|
205
|
+
else:
|
|
206
|
+
result.pop(key, None)
|
|
207
|
+
return result
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def cmd_sanitize_settings(argv: list[str]) -> int:
|
|
211
|
+
machine_path, repo_path, local_dir, out_path = argv
|
|
212
|
+
machine = load(machine_path, {}) or {}
|
|
213
|
+
repo = load(repo_path, {}) or {}
|
|
214
|
+
extra = read_list(os.path.join(local_dir, "packages.txt"))
|
|
215
|
+
skip = read_list(os.path.join(local_dir, "packages.skip.txt"))
|
|
216
|
+
|
|
217
|
+
# Repo owns the key order so pushes stay diff-quiet; machine values win so
|
|
218
|
+
# local edits (theme, defaults, …) still travel upstream.
|
|
219
|
+
repo_pkgs = list(repo.get("packages", []))
|
|
220
|
+
mach_pkgs = list(machine.get("packages", []))
|
|
221
|
+
dropped = [p for p in mach_pkgs if p in extra or p in skip]
|
|
222
|
+
additions = [p for p in mach_pkgs if p not in repo_pkgs and p not in extra and p not in skip]
|
|
223
|
+
packages = unique(repo_pkgs + additions)
|
|
224
|
+
|
|
225
|
+
out: dict = {}
|
|
226
|
+
for key in repo:
|
|
227
|
+
if key in VOLATILE_KEYS:
|
|
228
|
+
continue
|
|
229
|
+
out[key] = packages if key == "packages" else machine.get(key, repo[key])
|
|
230
|
+
if "packages" not in out:
|
|
231
|
+
out["packages"] = packages
|
|
232
|
+
for key, value in machine.items():
|
|
233
|
+
if key in out or key in VOLATILE_KEYS:
|
|
234
|
+
continue
|
|
235
|
+
out[key] = value
|
|
236
|
+
|
|
237
|
+
overrides = load(os.path.join(local_dir, "settings.json"), {}) or {}
|
|
238
|
+
out = restore_overrides(out, repo, overrides)
|
|
239
|
+
changed = dump_semantic(out_path, out)
|
|
240
|
+
print(f"settings: {'exported' if changed else 'unchanged'}")
|
|
241
|
+
if dropped:
|
|
242
|
+
print(" machine-only packages left out: " + ", ".join(map(str, dropped)))
|
|
243
|
+
if additions:
|
|
244
|
+
print(" new packages taken upstream: " + ", ".join(map(str, additions)))
|
|
245
|
+
return 0
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def cmd_merge_mcp(argv: list[str]) -> int:
|
|
249
|
+
repo_path, platform_path, local_path, machine_path, out_path = argv
|
|
250
|
+
sources = [("machine", machine_path), ("repo", repo_path),
|
|
251
|
+
("platform", platform_path), ("local", local_path)]
|
|
252
|
+
merged: dict[str, dict] = {}
|
|
253
|
+
for _, path in sources:
|
|
254
|
+
cfg = load(path, {}) or {}
|
|
255
|
+
for name, entry in (cfg.get("mcpServers") or {}).items():
|
|
256
|
+
if name.startswith("_") or not isinstance(entry, dict):
|
|
257
|
+
continue
|
|
258
|
+
merged[name] = deep_merge(merged.get(name, {}), entry)
|
|
259
|
+
machine = load(machine_path, {}) or {}
|
|
260
|
+
local = (load(local_path, {}) or {}).get("mcpServers", {})
|
|
261
|
+
for name, entry in machine.get("mcpServers", {}).items():
|
|
262
|
+
if name not in merged or not isinstance(entry, dict):
|
|
263
|
+
continue
|
|
264
|
+
for key in ("enabled", "exposure", "toolExposure"):
|
|
265
|
+
if key in entry and key not in local.get(name, {}):
|
|
266
|
+
merged[name][key] = entry[key]
|
|
267
|
+
changed = dump(out_path, {**machine, "mcpServers": merged})
|
|
268
|
+
enabled = [n for n, e in merged.items() if e.get("enabled", True)]
|
|
269
|
+
disabled = [n for n, e in merged.items() if not e.get("enabled", True)]
|
|
270
|
+
print(f"mcp: {'updated' if changed else 'unchanged'} ({len(merged)} servers)")
|
|
271
|
+
if enabled:
|
|
272
|
+
print(" enabled: " + ", ".join(enabled))
|
|
273
|
+
if disabled:
|
|
274
|
+
print(" disabled: " + ", ".join(disabled))
|
|
275
|
+
return 0
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def cmd_export_mcp(argv: list[str]) -> int:
|
|
279
|
+
repo_path, machine_path, platform_path, local_path, private_path, out_path = argv
|
|
280
|
+
repo = (load(repo_path, {}) or {}).get("mcpServers") or {}
|
|
281
|
+
machine = (load(machine_path, {}) or {}).get("mcpServers") or {}
|
|
282
|
+
platform = (load(platform_path, {}) or {}).get("mcpServers") or {}
|
|
283
|
+
local = (load(local_path, {}) or {}).get("mcpServers") or {}
|
|
284
|
+
private = (load(private_path, {}) or {}).get("mcpServers") or {}
|
|
285
|
+
|
|
286
|
+
out: dict[str, dict] = {}
|
|
287
|
+
replaced: list[str] = []
|
|
288
|
+
dropped: list[str] = []
|
|
289
|
+
for name, entry in machine.items():
|
|
290
|
+
if name in local or name in private:
|
|
291
|
+
if name in repo:
|
|
292
|
+
out[name] = repo[name]
|
|
293
|
+
dropped.append(name)
|
|
294
|
+
continue
|
|
295
|
+
if name in platform:
|
|
296
|
+
if name in repo:
|
|
297
|
+
out[name] = repo[name] # platform override is machine-specific
|
|
298
|
+
replaced.append(name)
|
|
299
|
+
else:
|
|
300
|
+
dropped.append(name) # platform-only server never ships
|
|
301
|
+
continue
|
|
302
|
+
out[name] = entry
|
|
303
|
+
|
|
304
|
+
changed = dump_semantic(out_path, {"mcpServers": out})
|
|
305
|
+
print(f"mcp: {'exported' if changed else 'unchanged'} ({len(out)} servers)")
|
|
306
|
+
if dropped:
|
|
307
|
+
print(" left out (local/platform/private): " + ", ".join(sorted(dropped)))
|
|
308
|
+
if replaced:
|
|
309
|
+
print(" repo entry kept instead of machine override: " + ", ".join(sorted(replaced)))
|
|
310
|
+
return 0
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
COMMANDS = {
|
|
314
|
+
"list-shared-packages": cmd_list_shared_packages,
|
|
315
|
+
"record-settings": cmd_record_settings,
|
|
316
|
+
"merge-settings": cmd_merge_settings,
|
|
317
|
+
"sanitize-settings": cmd_sanitize_settings,
|
|
318
|
+
"merge-mcp": cmd_merge_mcp,
|
|
319
|
+
"export-mcp": cmd_export_mcp,
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def main(argv: list[str]) -> int:
|
|
324
|
+
if len(argv) < 2 or argv[1] not in COMMANDS:
|
|
325
|
+
sys.exit("usage: pi_config.py {merge-settings|sanitize-settings|merge-mcp|export-mcp} ...")
|
|
326
|
+
return COMMANDS[argv[1]](argv[2:])
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
if __name__ == "__main__":
|
|
330
|
+
sys.exit(main(sys.argv))
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { readFile, writeFile, mkdir } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
export function newerStable(candidate, current) {
|
|
5
|
+
if (!/^\d+\.\d+\.\d+$/.test(candidate) || !/^\d+\.\d+\.\d+(?:-[\w.]+)?$/.test(current)) return false;
|
|
6
|
+
const a = candidate.split('.').map(Number), b = current.split(/[.-]/).slice(0, 3).map(Number);
|
|
7
|
+
for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] > b[i];
|
|
8
|
+
return current.includes('-');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// One bounded registry request per day, only for Kitto itself. No host/plugin scan.
|
|
12
|
+
// Errors (including unpublished packages, offline or unwritable cache) are silent.
|
|
13
|
+
export async function updateNotice(home, current, { fetcher = fetch, now = Date.now() } = {}) {
|
|
14
|
+
try {
|
|
15
|
+
const path = join(home, 'update-check.json');
|
|
16
|
+
let cache = {};
|
|
17
|
+
try { cache = JSON.parse(await readFile(path, 'utf8')); } catch {}
|
|
18
|
+
if (Number.isFinite(cache.checkedAt) && now - cache.checkedAt < 86_400_000 && now >= cache.checkedAt) return;
|
|
19
|
+
await mkdir(home, { recursive: true });
|
|
20
|
+
await writeFile(path, JSON.stringify({ checkedAt: now }), { mode: 0o600 });
|
|
21
|
+
const result = await fetcher('https://registry.npmjs.org/@phyzess%2fkitto/latest', { signal: AbortSignal.timeout(2000) });
|
|
22
|
+
if (!result.ok) return;
|
|
23
|
+
const metadata = await result.json();
|
|
24
|
+
if (newerStable(metadata.version, current)) return `Kitto ${metadata.version} is available. Ask the Kitto skill to review the update.`;
|
|
25
|
+
} catch { /* Maintenance must never prevent an agent session from starting. */ }
|
|
26
|
+
}
|
package/lib/versions.mjs
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFile, readdir } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { dependencyPlan, executable, npmSpec, npxPackage, optionalJson, piServers, query } from './dependencies.mjs';
|
|
5
|
+
import { hostSkillRoots } from './host-config.mjs';
|
|
6
|
+
|
|
7
|
+
const version = output => output?.match(/\d+\.\d+\.\d+(?:-[\w.-]+)?/)?.[0] || null;
|
|
8
|
+
|
|
9
|
+
async function entries(path) {
|
|
10
|
+
try { return await readdir(path, { withFileTypes: true }); }
|
|
11
|
+
catch (error) { if (error.code === 'ENOENT') return []; throw error; }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function resources(root, revision, hashTree) {
|
|
15
|
+
const rows = [];
|
|
16
|
+
for (const entry of await entries(root)) {
|
|
17
|
+
const path = join(root, entry.name);
|
|
18
|
+
if (!entry.isDirectory() || !(await entries(path)).some(file => file.name === 'SKILL.md' && file.isFile())) continue;
|
|
19
|
+
rows.push({ kind: 'skill', name: entry.name, revision, contentSha256: await hashTree(path, true) });
|
|
20
|
+
}
|
|
21
|
+
return rows;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function piVersions(state, revision) {
|
|
25
|
+
const rows = [];
|
|
26
|
+
const settings = await optionalJson(join(state.source, 'config/pi/settings.json'));
|
|
27
|
+
const machine = await optionalJson(join(state.piHome, 'settings.json'), settings);
|
|
28
|
+
const specs = new Map();
|
|
29
|
+
for (const list of [settings.packages || [], machine.packages || []]) {
|
|
30
|
+
for (const entry of list) {
|
|
31
|
+
const source = typeof entry === 'string' ? entry : entry.source;
|
|
32
|
+
if (source?.startsWith('npm:')) {
|
|
33
|
+
const [name, target] = npmSpec(source);
|
|
34
|
+
specs.set(name, target);
|
|
35
|
+
} else if (source) {
|
|
36
|
+
if (!rows.some(row => row.name === source)) rows.push({ name: source, kind: 'source', installed: null });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
for (const [name, target] of specs) {
|
|
41
|
+
const manifest = await optionalJson(join(state.piHome, 'npm/node_modules', name, 'package.json'));
|
|
42
|
+
rows.push({ kind: 'npm', name, target, installed: manifest.version || null });
|
|
43
|
+
}
|
|
44
|
+
for (const [id, server] of Object.entries(await piServers(state))) {
|
|
45
|
+
const [name, target] = npxPackage(server);
|
|
46
|
+
if (name) rows.push({ kind: 'npm', name, target, installed: null, mcp: id, note: 'Version resolved by npx at launch.' });
|
|
47
|
+
else rows.push({ kind: 'external', name: server.command, mcp: id, path: executable(server.command) || null });
|
|
48
|
+
}
|
|
49
|
+
const extensions = join(state.source, 'config/pi/extensions');
|
|
50
|
+
for (const file of await entries(extensions)) {
|
|
51
|
+
if (!file.isFile() || !file.name.endsWith('.ts')) continue;
|
|
52
|
+
rows.push({ kind: 'extension', name: file.name, revision, contentSha256: createHash('sha256').update(await readFile(join(extensions, file.name))).digest('hex') });
|
|
53
|
+
}
|
|
54
|
+
return rows.map(row => ({ ...row, owner: 'pi' }));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function codexVersions(state) {
|
|
58
|
+
const output = query('codex', ['plugin', 'list', '--json'], { ...process.env, CODEX_HOME: state.codexHome });
|
|
59
|
+
if (!output) return [{ kind: 'inventory', owner: 'codex', note: 'Native plugin inventory unavailable.' }];
|
|
60
|
+
try {
|
|
61
|
+
return JSON.parse(output).installed.map(plugin => ({
|
|
62
|
+
kind: 'plugin', owner: 'codex', name: plugin.pluginId, installed: plugin.version || null, enabled: plugin.enabled,
|
|
63
|
+
}));
|
|
64
|
+
} catch {
|
|
65
|
+
return [{ kind: 'inventory', owner: 'codex', note: 'Unrecognized native plugin inventory.' }];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function dshVersions(state) {
|
|
70
|
+
const profile = state.dshProfile || 'web';
|
|
71
|
+
const root = join(state.dshHome, 'profiles', profile);
|
|
72
|
+
const manifest = await optionalJson(join(root, 'package.json'));
|
|
73
|
+
const rows = [];
|
|
74
|
+
for (const name of manifest.dsh?.profile?.bundles || []) {
|
|
75
|
+
const target = manifest.dependencies?.[name];
|
|
76
|
+
const bundled = !target;
|
|
77
|
+
const installed = bundled ? {} : await optionalJson(join(root, 'node_modules', name, 'package.json'));
|
|
78
|
+
rows.push({ kind: bundled ? 'bundle' : 'npm', owner: 'dsh', profile,
|
|
79
|
+
name, target: target || null, installed: installed.version || (name === '@phyzess/kitto' ? state.version : null),
|
|
80
|
+
note: bundled ? 'Bundled with DSH.' : undefined });
|
|
81
|
+
}
|
|
82
|
+
return rows;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function upstream(kind, name) {
|
|
86
|
+
const encoded = encodeURIComponent(name);
|
|
87
|
+
const url = kind === 'npm' ? `https://registry.npmjs.org/${encoded}` : `https://pypi.org/pypi/${encoded}/json`;
|
|
88
|
+
try {
|
|
89
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(10_000) });
|
|
90
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
91
|
+
const data = await response.json();
|
|
92
|
+
if (kind === 'pypi') return { source: url, version: data.info.version, requiresPython: data.info.requires_python };
|
|
93
|
+
const channels = Object.fromEntries(Object.entries(data['dist-tags'] || {}).filter(
|
|
94
|
+
([tag]) => ['latest', 'next', 'alpha', 'beta', 'canary'].includes(tag),
|
|
95
|
+
));
|
|
96
|
+
const requirements = Object.fromEntries(Object.entries(channels).map(([tag, value]) => {
|
|
97
|
+
const release = data.versions?.[value];
|
|
98
|
+
return [tag, { engines: release?.engines, peers: release?.peerDependencies, deprecated: release?.deprecated }];
|
|
99
|
+
}));
|
|
100
|
+
return { source: url, channels, requirements };
|
|
101
|
+
} catch (error) {
|
|
102
|
+
return { source: url, error: error.message };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export async function versionReport(state, hosts, pnpmVersion, online, hashTree) {
|
|
107
|
+
const rows = [{ kind: 'npm', owner: 'kitto', name: '@phyzess/kitto', installed: state.version }];
|
|
108
|
+
for (const name of state.agents) {
|
|
109
|
+
rows.push({ kind: 'npm', owner: name, name: hosts[name].package, installed: version(query(name, ['--version'])), tested: hosts[name].version });
|
|
110
|
+
}
|
|
111
|
+
if (state.agents.includes('dsh')) rows.push({ kind: 'npm', owner: 'dsh', name: 'pnpm', installed: version(query('pnpm', ['--version'])), tested: pnpmVersion });
|
|
112
|
+
const revision = query('git', ['-C', state.source, 'rev-parse', 'HEAD']);
|
|
113
|
+
if (state.agents.includes('pi')) rows.push(...await piVersions(state, revision));
|
|
114
|
+
if (state.agents.includes('codex')) rows.push(...await codexVersions(state));
|
|
115
|
+
if (state.agents.includes('dsh')) rows.push(...await dshVersions(state));
|
|
116
|
+
for (const { name, source } of [{ name: 'shared', source: join(state.source, 'skills') }, ...hostSkillRoots(state)]) {
|
|
117
|
+
rows.push(...(await resources(source, revision, hashTree)).map(row => ({ ...row, owner: name })));
|
|
118
|
+
}
|
|
119
|
+
for (const tool of await dependencyPlan(state)) {
|
|
120
|
+
const kind = { mise: 'npm', pip: 'pypi', brew: 'brew' }[tool.manager] || 'external';
|
|
121
|
+
rows.push({ ...tool, kind });
|
|
122
|
+
}
|
|
123
|
+
if (online) {
|
|
124
|
+
const groups = new Map();
|
|
125
|
+
for (const row of rows.filter(row => ['npm', 'pypi'].includes(row.kind))) {
|
|
126
|
+
const key = `${row.kind}:${row.name}`;
|
|
127
|
+
if (!groups.has(key)) groups.set(key, []);
|
|
128
|
+
groups.get(key).push(row);
|
|
129
|
+
}
|
|
130
|
+
const batches = [...groups.values()];
|
|
131
|
+
for (let i = 0; i < batches.length; i += 6) {
|
|
132
|
+
await Promise.all(batches.slice(i, i + 6).map(async group => {
|
|
133
|
+
const result = await upstream(group[0].kind, group[0].name);
|
|
134
|
+
for (const row of group) row.upstream = result;
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return { checkedAt: new Date().toISOString(), online, components: rows };
|
|
139
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phyzess/kitto",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
}
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Portable personal configuration for Pi, Codex and DeepSeek Harness",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": { "kitto": "bin/kitto.mjs" },
|
|
7
|
+
"engines": { "node": ">=22.0.0", "dsh": ">=0.2.2-rc.1 <0.3.0" },
|
|
8
|
+
"publishConfig": { "access": "public" },
|
|
9
|
+
"repository": { "type": "git", "url": "git+https://github.com/phyzess/kitto.git" },
|
|
10
|
+
"files": ["bin/*.mjs", "lib/*.mjs", "lib/*.py", "integration/", "sync.sh", "CHANGELOG.md"],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "node --test tests/kitto.test.mjs",
|
|
13
|
+
"prepublishOnly": "npm test && python3 -m unittest discover -s tests -v",
|
|
14
|
+
"release": "node scripts/release.mjs"
|
|
15
|
+
},
|
|
16
|
+
"pi": { "extensions": ["./integration/pi.mjs"], "skills": ["./integration/skills"] },
|
|
17
|
+
"dsh": { "manifestVersion": 1, "bundle": { "patch": "./integration/cordis.patch.yml" } }
|
|
18
|
+
}
|