@phyzess/kitto 0.3.0 → 0.3.2
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 +10 -0
- package/bin/kitto.mjs +13 -1
- package/integration/plugin.json +1 -1
- package/lib/kitto.mjs +196 -28
- package/lib/scope-setup.mjs +1 -1
- package/package.json +1 -1
- package/sync.sh +19 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Kitto
|
|
2
2
|
|
|
3
|
+
## 0.3.2
|
|
4
|
+
|
|
5
|
+
- Locks: the installation lock (`$KITTO_HOME/.lock`) and the Pi adapter's write lock (`<configuration source>/config/pi/local/.sync-lock`) now record their owner — `owner.json` with pid, host, start time and command, or a `pid` file. A refused acquisition therefore reports whether the holder can still exist: `pid N started … is still running`, or `pid N is no longer running` with the statement that the lock is stale. `--break-lock` on `setup`/`update` clears a lock only when its recorded owner is provably gone and never displaces a live operation; a lock without an owner record (an older Kitto, or a hand-made directory) is left for manual inspection. Held locks are released on `SIGINT`/`SIGTERM`, which bash's `EXIT` trap alone never covered for the Pi adapter.
|
|
6
|
+
- Runtime: a failed deployment now says that the refreshed runtime stays unverified (`state.pendingRuntime`) and names both ways forward — rerun `update --apply`, or `setup --recover` to return to the previous runtime.
|
|
7
|
+
- Interpreter probes: `checkPiTools` used an 8s ceiling while the version check rode `run()`'s 600s default, so a version-manager shim (pyenv, asdf, mise) that is slow on its first run aborted the deployment after the runtime swap had already happened. The probe now separates missing, slow and failed: a slow shim warns and continues, while a missing or pre-3.10 interpreter still fails before any write. Docs describe the lock and probe semantics, and tests cover a stale installation and sync lock cleared by `--break-lock`, a live lock that `--break-lock` must refuse, and a stalling `python3` shim that warns instead of stranding the deployment.
|
|
8
|
+
|
|
9
|
+
## 0.3.1
|
|
10
|
+
|
|
11
|
+
- Hosts: a selected host CLI below the tested baseline no longer blocks `setup` or `update`. The version check reports a warning and continues, and each native integration is gated on a capability probe instead of a version comparison (`codex plugin`, `dsh plugin`), so a stale Codex or DSH CLI skips only its own registration while rules, skills and MCP still deploy — for that host and for every other selected host. An unreadable `--version` warns instead of throwing; a missing binary stays fatal because no integration can run. `--require-baseline` restores the previous strict gate for release verification, and `installMissingHosts` still verifies the version it installed itself. Docs record that the baseline is an advisory label and the `kitto hosts --apply` target, not a write precondition.
|
|
12
|
+
|
|
3
13
|
## 0.3.0
|
|
4
14
|
|
|
5
15
|
- Hosts: add the explicit `kitto hosts [--check|--apply] [--host NAME] [--version VERSION]` command for host-CLI upgrade policy (also exposed as the maintenance runner's `hosts` operation). It lists each selected host's installed `--version`, Kitto's validated baseline (`hosts[name].version`) and the exact native-manager command; `--check` is the default and writes nothing. `--apply` installs only the pinned target through `npm install --global <package>@<version>` — Pi and Codex through their npm packages, the DSH CLI through `@deepseek-ai/dsh@<baseline>` with a prerelease baseline kept exact — never `npx`, dist-tags or "latest", never an unselected host, and never automatically. Hosts already newer than the baseline are not downgraded implicitly; `--version` accepts one exact version for one host and warns in check and apply when it is not the validated baseline. The app-managed `desktop` DSH profile (matched case-insensitively) is reported and skipped, not npm-installed. Missing npm, unreadable host versions, permission failures (with npm-prefix/sudo guidance) and post-install verification mismatches fail with actionable errors before or without writing `state.json`; a multi-host failure reports which hosts changed and which did not. `kitto update` is unchanged: it prints host versions/baselines and never upgrades a host.
|
package/bin/kitto.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { mkdir, realpath, rm } from 'node:fs/promises';
|
|
4
4
|
import { join, resolve } from 'node:path';
|
|
5
|
-
import { setup, parseOptions, update } from '../lib/kitto.mjs';
|
|
5
|
+
import { allowStaleLockBreak, setup, parseOptions, update } from '../lib/kitto.mjs';
|
|
6
6
|
import { worktreeCommand } from '../lib/worktree-audit.mjs';
|
|
7
7
|
import { hostsCommand } from '../lib/hosts.mjs';
|
|
8
8
|
import { readScopeRegistry, scopeHome, writeScopeRegistry } from '../lib/scopes.mjs';
|
|
@@ -16,7 +16,9 @@ const help = `Kitto — portable personal agent configuration
|
|
|
16
16
|
kitto setup --workspace PATH [--agents pi,codex,dsh] [--dsh-service UNIT] [--dry-run]
|
|
17
17
|
kitto setup [--agents pi,codex,dsh] [--source PATH_OR_GIT_URL] [--ref BRANCH_OR_TAG]
|
|
18
18
|
[--dsh-profile PROFILE] [--install-agents] [--dry-run]
|
|
19
|
+
[--require-baseline]
|
|
19
20
|
[--include-private|--no-include-private]
|
|
21
|
+
kitto setup --break-lock Continue after a provably abandoned lock (setup/update)
|
|
20
22
|
kitto setup --recover [--dry-run] Restore the last working Kitto code
|
|
21
23
|
kitto update [--check|--apply] [--include-private|--no-include-private]
|
|
22
24
|
Preview (the default; --check makes it explicit) or apply:
|
|
@@ -42,6 +44,8 @@ kitto update only previews unless --apply is used (--check is the same preview,
|
|
|
42
44
|
it updates Kitto's code copy and configuration, never a host CLI or the Kitto package itself.
|
|
43
45
|
Host CLIs are upgraded separately and explicitly with kitto hosts --apply, only to Kitto's validated
|
|
44
46
|
baseline (or an explicit --version). Kitto never upgrades a host automatically.
|
|
47
|
+
A host below that baseline only produces a warning: setup skips the steps that CLI cannot support and
|
|
48
|
+
still deploys every other selected host. Pass --require-baseline to make an untested version fatal.
|
|
45
49
|
Kitto needs Node >=22 and Git. Pi sync also needs Bash and Python >=3.10.
|
|
46
50
|
DSH web/headless needs pnpm and uses the web profile by default. The Desktop app owns the desktop
|
|
47
51
|
profile: Kitto deploys only its global AGENTS.md and skills, never checks or installs a dsh CLI, and
|
|
@@ -172,6 +176,14 @@ async function scopeCommand(args) {
|
|
|
172
176
|
|
|
173
177
|
try {
|
|
174
178
|
const [command, ...args] = process.argv.slice(2);
|
|
179
|
+
// --break-lock is accepted by the commands that take the installation lock.
|
|
180
|
+
// It removes a lock only when the recorded owner is provably gone, so a live
|
|
181
|
+
// operation is never displaced.
|
|
182
|
+
if (['setup', 'update'].includes(command) && args.includes('--break-lock')) {
|
|
183
|
+
allowStaleLockBreak(true);
|
|
184
|
+
args.splice(args.indexOf('--break-lock'), 1);
|
|
185
|
+
console.log('kitto: --break-lock removes a lock only when its recorded owner is no longer running.');
|
|
186
|
+
}
|
|
175
187
|
if (!command || command === '--help' || command === '-h') console.log(help);
|
|
176
188
|
else if (command === 'worktree') {
|
|
177
189
|
if (['start', 'finish', 'apply'].includes(args[0])) {
|
package/integration/plugin.json
CHANGED
package/lib/kitto.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { spawnSync } from 'node:child_process';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
|
-
import { existsSync, mkdtempSync, realpathSync, rmSync } from 'node:fs';
|
|
3
|
+
import { existsSync, mkdtempSync, readFileSync, realpathSync, rmSync } from 'node:fs';
|
|
4
4
|
import { cp, mkdir, mkdtemp, readFile, readdir, rename, rm, writeFile, lstat, readlink, realpath } from 'node:fs/promises';
|
|
5
|
-
import { homedir, tmpdir } from 'node:os';
|
|
5
|
+
import { homedir, hostname, tmpdir } from 'node:os';
|
|
6
6
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
8
|
import { applyInstructions, hostSkillRoots, instructionPlan } from './host-config.mjs';
|
|
@@ -75,7 +75,7 @@ export function parseOptions(args) {
|
|
|
75
75
|
const options = {};
|
|
76
76
|
for (let i = 0; i < args.length; i++) {
|
|
77
77
|
const arg = args[i];
|
|
78
|
-
if (['--dry-run', '--install-agents', '--recover', '--global', '--include-private', '--no-include-private'].includes(arg)) options[arg.slice(2)] = true;
|
|
78
|
+
if (['--dry-run', '--install-agents', '--recover', '--require-baseline', '--global', '--include-private', '--no-include-private'].includes(arg)) options[arg.slice(2)] = true;
|
|
79
79
|
else if (['--agents', '--source', '--ref', '--dsh-profile', '--workspace', '--workspace-parent', '--dsh-service'].includes(arg) && args[i + 1] && !args[i + 1].startsWith('-')) options[arg.slice(2)] = args[++i];
|
|
80
80
|
else throw new Error(`Unknown option or missing value: ${arg}`);
|
|
81
81
|
}
|
|
@@ -97,14 +97,98 @@ async function atomicJson(path, value) {
|
|
|
97
97
|
} finally { await rm(temporary, { force: true }); }
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
// A lock that only says "somebody is here" forces the operator to guess whether
|
|
101
|
+
// the holder is alive. Every lock records its owner, so a failed acquisition
|
|
102
|
+
// reports a fact instead of asking for an inspection: pid 4812 is running, or
|
|
103
|
+
// pid 4812 exited hours ago and this is residue.
|
|
104
|
+
let breakStaleLocks = false;
|
|
105
|
+
export function allowStaleLockBreak(value = true) { breakStaleLocks = value; }
|
|
106
|
+
|
|
107
|
+
const ownedLocks = new Set();
|
|
108
|
+
let lockSignalsBound = false;
|
|
109
|
+
|
|
110
|
+
function lockOwnerRecord() {
|
|
111
|
+
return { pid: process.pid, host: hostname(), startedAt: new Date().toISOString(),
|
|
112
|
+
command: process.argv.slice(2).join(' ').slice(0, 200) };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// EPERM means the pid exists but belongs to another user: still alive.
|
|
116
|
+
function processAlive(pid) {
|
|
117
|
+
if (!Number.isInteger(pid) || pid <= 0) return undefined;
|
|
118
|
+
try { process.kill(pid, 0); return true; }
|
|
119
|
+
catch (error) { return error.code === 'EPERM'; }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function readLockOwner(lock) {
|
|
123
|
+
try { return JSON.parse(await readFile(join(lock, 'owner.json'), 'utf8')); }
|
|
124
|
+
catch { return undefined; }
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function lockMessage(lock, owner, stale) {
|
|
128
|
+
if (!owner) {
|
|
129
|
+
return `${lock} exists without an owner record (an older Kitto, or a directory someone created by hand). `
|
|
130
|
+
+ 'Verify no Kitto process is running, then delete that directory.';
|
|
131
|
+
}
|
|
132
|
+
const who = `pid ${owner.pid}${owner.startedAt ? ` started ${owner.startedAt}` : ''}${owner.command ? ` (${owner.command})` : ''}`;
|
|
133
|
+
return stale
|
|
134
|
+
? `${lock} is a stale lock: ${who} is no longer running. Rerun with --break-lock to remove it, or delete that directory.`
|
|
135
|
+
: `Another Kitto operation holds ${lock}: ${who}. Wait for it to finish.`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function bindLockSignals() {
|
|
139
|
+
if (lockSignalsBound) return;
|
|
140
|
+
lockSignalsBound = true;
|
|
141
|
+
for (const [signal, code] of [['SIGINT', 130], ['SIGTERM', 143]]) {
|
|
142
|
+
process.once(signal, () => {
|
|
143
|
+
for (const lock of ownedLocks) { try { rmSync(lock, { recursive: true, force: true }); } catch { /* best effort */ } }
|
|
144
|
+
process.exit(code);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function acquireLock(home) {
|
|
101
150
|
await mkdir(home, { recursive: true });
|
|
102
151
|
const lock = join(home, '.lock');
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
152
|
+
bindLockSignals();
|
|
153
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
154
|
+
try {
|
|
155
|
+
await mkdir(lock);
|
|
156
|
+
await writeFile(join(lock, 'owner.json'), JSON.stringify(lockOwnerRecord(), null, 1) + '\n', { mode: 0o600 });
|
|
157
|
+
ownedLocks.add(lock);
|
|
158
|
+
return lock;
|
|
159
|
+
} catch (error) {
|
|
160
|
+
if (error.code !== 'EEXIST') throw error;
|
|
161
|
+
const owner = await readLockOwner(lock);
|
|
162
|
+
const stale = owner ? processAlive(owner.pid) === false : false;
|
|
163
|
+
if (stale && breakStaleLocks) {
|
|
164
|
+
await rm(lock, { recursive: true, force: true });
|
|
165
|
+
console.log(`kitto: removed stale lock ${lock} (pid ${owner.pid} is no longer running).`);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
throw new Error(lockMessage(lock, owner, stale));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
throw new Error(`Cannot acquire ${join(home, '.lock')}: a stale lock reappeared after it was cleared.`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// The Pi adapter takes its own lock beside the configuration checkout. A killed
|
|
175
|
+
// sync leaves it behind, and the recorded pid is what makes it actionable.
|
|
176
|
+
function breakStaleSyncLock(state) {
|
|
177
|
+
const lock = join(state.source, 'config/pi/local/.sync-lock');
|
|
178
|
+
if (!existsSync(lock)) return;
|
|
179
|
+
let pid = NaN;
|
|
180
|
+
try { pid = Number(readFileSync(join(lock, 'pid'), 'utf8').trim()); } catch { /* older lock without a pid */ }
|
|
181
|
+
if (processAlive(pid) !== false) return;
|
|
182
|
+
rmSync(lock, { recursive: true, force: true });
|
|
183
|
+
console.log(`kitto: removed stale sync lock ${lock} (pid ${pid} is no longer running).`);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function locked(home, callback) {
|
|
187
|
+
const lock = await acquireLock(home);
|
|
188
|
+
try { return await callback(); } finally {
|
|
189
|
+
ownedLocks.delete(lock);
|
|
190
|
+
await rm(lock, { recursive: true, force: true });
|
|
106
191
|
}
|
|
107
|
-
try { return await callback(); } finally { await rm(lock, { recursive: true }); }
|
|
108
192
|
}
|
|
109
193
|
|
|
110
194
|
async function validateSource({ source, agents }) {
|
|
@@ -163,29 +247,53 @@ export function meetsBaseline(actual, baseline) {
|
|
|
163
247
|
return true;
|
|
164
248
|
}
|
|
165
249
|
|
|
166
|
-
|
|
250
|
+
// Host CLI versions are observations, not gates. An older CLI is reported and
|
|
251
|
+
// the steps it cannot support are skipped, so one stale host never blocks the
|
|
252
|
+
// others; a missing binary stays fatal because no integration can run.
|
|
253
|
+
function hostCapabilities(name, env) {
|
|
254
|
+
const supports = args => spawnSync(name, args, { stdio: 'ignore', timeout: 8000, env }).status === 0;
|
|
255
|
+
if (name === 'codex') return { plugin: supports(['plugin', 'add', '--help']), mcp: supports(['mcp', '--help']) };
|
|
256
|
+
if (name === 'dsh') return { plugin: supports(['plugin', '--help']) };
|
|
257
|
+
return {};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function inspectHost(name) {
|
|
167
261
|
// Codex creates helper files under CODEX_HOME even for --version/--help.
|
|
168
262
|
// Probe with a scratch home so checks never write the user's Codex state.
|
|
169
263
|
const probe = name === 'codex' ? mkdtempSync(join(tmpdir(), 'kitto-codex-check-')) : null;
|
|
170
264
|
const env = probe ? { ...process.env, CODEX_HOME: probe } : process.env;
|
|
171
265
|
try {
|
|
172
|
-
const
|
|
173
|
-
const
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
console.log(`${name}: ${actual} (tested baseline ${expected})`);
|
|
266
|
+
const result = spawnSync(name, ['--version'], { encoding: 'utf8', timeout: 8000, env });
|
|
267
|
+
const stdout = (result.stdout ?? '').trim();
|
|
268
|
+
const actual = stdout.match(/\d+\.\d+\.\d+(?:-[\w.-]+)?/)?.[0] ?? null;
|
|
269
|
+
const baseline = hosts[name].version;
|
|
270
|
+
const missing = result.error?.code === 'ENOENT';
|
|
271
|
+
const detail = (stdout.split('\n')[0] || (result.stderr ?? '').trim().split('\n')[0] || `exit ${result.status}`);
|
|
272
|
+
return {
|
|
273
|
+
name, baseline, actual, status: missing ? 'missing' : actual ? 'found' : 'unreadable', detail,
|
|
274
|
+
meetsBaseline: Boolean(actual) && meetsBaseline(actual, baseline),
|
|
275
|
+
capabilities: missing ? {} : hostCapabilities(name, env),
|
|
276
|
+
};
|
|
184
277
|
} finally {
|
|
185
278
|
if (probe) rmSync(probe, { recursive: true, force: true });
|
|
186
279
|
}
|
|
187
280
|
}
|
|
188
281
|
|
|
282
|
+
// A host below the tested baseline is a warning, never a write barrier: every
|
|
283
|
+
// other selected host is still deployed. --require-baseline restores the old
|
|
284
|
+
// fatal behaviour for release verification.
|
|
285
|
+
function reportHost(report, requireBaseline) {
|
|
286
|
+
const { name, baseline } = report;
|
|
287
|
+
if (report.status === 'unreadable') {
|
|
288
|
+
console.warn(`kitto: ${name}: could not read its version (${report.detail}); continuing, but its native integration is unverified.`);
|
|
289
|
+
} else if (report.meetsBaseline) {
|
|
290
|
+
console.log(`${name}: ${report.actual} (tested baseline ${baseline})`);
|
|
291
|
+
} else {
|
|
292
|
+
const detail = `${name}: ${report.actual} is older than the tested baseline ${baseline}`;
|
|
293
|
+
if (requireBaseline) throw new Error(`${detail}. Upgrade it with \`kitto hosts --apply\`, or drop --require-baseline.`);
|
|
294
|
+
console.warn(`kitto: ${detail}; continuing and skipping the steps this CLI cannot support. Run \`kitto hosts --apply\` when you want the tested baseline.`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
189
297
|
function availableHost(name) {
|
|
190
298
|
if (name !== 'codex') return available(name);
|
|
191
299
|
// Codex creates helper files under CODEX_HOME even for --version.
|
|
@@ -194,7 +302,8 @@ function availableHost(name) {
|
|
|
194
302
|
finally { rmSync(probe, { recursive: true, force: true }); }
|
|
195
303
|
}
|
|
196
304
|
|
|
197
|
-
export function checkSelectedHosts(agents, installAgents) {
|
|
305
|
+
export function checkSelectedHosts(agents, installAgents, options = {}) {
|
|
306
|
+
const reports = [];
|
|
198
307
|
for (const name of agents) {
|
|
199
308
|
if (!availableHost(name)) {
|
|
200
309
|
if (!installAgents) throw new Error(`${name} is missing. Install it natively or add --install-agents (pins ${hosts[name].version}).`);
|
|
@@ -203,14 +312,26 @@ export function checkSelectedHosts(agents, installAgents) {
|
|
|
203
312
|
throw new Error(`Installing ${name} through npm requires Node >=${requiredNode}.`);
|
|
204
313
|
}
|
|
205
314
|
console.log(`Install missing CLI: ${hosts[name].package}@${hosts[name].version}${name === 'dsh' ? ' (prerelease)' : ''}`);
|
|
206
|
-
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
const report = inspectHost(name);
|
|
318
|
+
reports.push(report);
|
|
319
|
+
reportHost(report, options.requireBaseline === true);
|
|
207
320
|
}
|
|
321
|
+
return reports;
|
|
208
322
|
}
|
|
209
323
|
|
|
210
324
|
export function installMissingHosts(agents) {
|
|
211
325
|
for (const name of agents) if (!availableHost(name)) {
|
|
212
326
|
run('npm', ['install', '--global', `${hosts[name].package}@${hosts[name].version}`]);
|
|
213
|
-
|
|
327
|
+
// Unlike the pre-flight check, a fresh install is verified strictly: Kitto
|
|
328
|
+
// chose the version, so a different one means PATH or the prefix is wrong.
|
|
329
|
+
const report = inspectHost(name);
|
|
330
|
+
if (report.status !== 'found' || report.actual !== hosts[name].version) {
|
|
331
|
+
throw new Error(`${name}: npm installed ${hosts[name].version} but the CLI reports ${report.actual ?? report.status}. `
|
|
332
|
+
+ 'Check PATH and the npm global prefix; Kitto wrote no state.');
|
|
333
|
+
}
|
|
334
|
+
console.log(`${name}: ${report.actual} (installed pinned baseline)`);
|
|
214
335
|
}
|
|
215
336
|
}
|
|
216
337
|
|
|
@@ -331,12 +452,37 @@ async function skillPlan(root, destination, owned = {}, keepExisting = false, ke
|
|
|
331
452
|
return plans;
|
|
332
453
|
}
|
|
333
454
|
|
|
455
|
+
function probeTool(name, args = ['--version'], timeout = 8000) {
|
|
456
|
+
const result = spawnSync(name, args, { stdio: 'ignore', timeout });
|
|
457
|
+
if (result.error?.code === 'ENOENT') return 'missing';
|
|
458
|
+
if (result.error?.code === 'ETIMEDOUT') return 'slow';
|
|
459
|
+
if (result.error) return 'failed';
|
|
460
|
+
return result.status === 0 ? 'ok' : 'failed';
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
function slowPythonNotice() {
|
|
464
|
+
console.warn('kitto: python3 did not answer within 8s; continuing. A version-manager shim (pyenv, asdf, mise) can be slow on its '
|
|
465
|
+
+ 'first run, and the sync step reports the real result.');
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// Python is required by the Pi adapter, but the interpreter may be a version
|
|
469
|
+
// manager shim that is far slower than the interpreter it resolves. Only a
|
|
470
|
+
// missing or too-old interpreter stops the run before any write; a probe that
|
|
471
|
+
// times out warns, so a slow shim cannot strand a deployment that otherwise
|
|
472
|
+
// finished. sync.sh still fails loudly when Python is genuinely unusable.
|
|
334
473
|
function checkPiTools() {
|
|
335
|
-
|
|
336
|
-
|
|
474
|
+
if (probeTool('bash') === 'missing') throw new Error('Pi configuration requires bash on PATH.');
|
|
475
|
+
const present = probeTool('python3');
|
|
476
|
+
if (present === 'missing') throw new Error('Pi configuration requires python3 on PATH.');
|
|
477
|
+
if (present === 'failed') throw new Error('python3 is on PATH but cannot run; the Pi adapter needs Python >=3.10.');
|
|
478
|
+
if (present === 'slow') return slowPythonNotice();
|
|
479
|
+
const supported = probeTool('python3', ['-c', 'import sys; sys.exit(0 if sys.version_info >= (3, 10) else 3)']);
|
|
480
|
+
if (supported === 'slow') return slowPythonNotice();
|
|
481
|
+
if (supported !== 'ok') throw new Error('The Pi adapter needs Python >=3.10; upgrade the python3 on PATH.');
|
|
337
482
|
}
|
|
338
483
|
|
|
339
484
|
function syncCommand(state, command, apply = false, codeRoot = join(kittoHome(), 'runtime')) {
|
|
485
|
+
if (breakStaleLocks) breakStaleSyncLock(state);
|
|
340
486
|
checkPiTools();
|
|
341
487
|
return run('bash', [join(codeRoot, 'sync.sh'), command, ...(!apply && command !== 'status' ? ['--dry-run'] : [])], {
|
|
342
488
|
env: { ...process.env, KITTO_CONFIG_ROOT: state.source, KITTO_SHARED_SKILLS_MANAGED: '1',
|
|
@@ -351,6 +497,12 @@ async function connect(state) {
|
|
|
351
497
|
for (const name of state.agents) {
|
|
352
498
|
if (name === 'pi') run('pi', ['install', runtime], { env: { ...process.env, PI_CODING_AGENT_DIR: state.piHome } });
|
|
353
499
|
if (name === 'codex') {
|
|
500
|
+
const codex = inspectHost('codex');
|
|
501
|
+
if (!codex.capabilities.plugin) {
|
|
502
|
+
console.warn('kitto: this codex CLI has no plugin subcommand; skipped the Kitto plugin registration. '
|
|
503
|
+
+ 'Rules, skills and MCP were still deployed.');
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
354
506
|
await mkdir(state.codexHome, { recursive: true });
|
|
355
507
|
const marketplace = join(home, '.agents/plugins/marketplace.json');
|
|
356
508
|
await atomicJson(marketplace, { name: 'phyzess-kitto', plugins: [{ name: 'kitto',
|
|
@@ -365,6 +517,12 @@ async function connect(state) {
|
|
|
365
517
|
console.log('DSH desktop profile: app-managed; skipped Kitto bundle registration (global rules and skills only).');
|
|
366
518
|
continue;
|
|
367
519
|
}
|
|
520
|
+
const dsh = inspectHost('dsh');
|
|
521
|
+
if (!dsh.capabilities.plugin) {
|
|
522
|
+
console.warn(`kitto: this dsh CLI${dsh.actual ? ` (${dsh.actual})` : ''} has no plugin subcommand; `
|
|
523
|
+
+ 'skipped the Kitto bundle registration. Rules and skills were still deployed.');
|
|
524
|
+
continue;
|
|
525
|
+
}
|
|
368
526
|
await mkdir(state.dshHome, { recursive: true });
|
|
369
527
|
run('dsh', ['plugin', '--profile', state.dshProfile || 'web', 'add', runtime], {
|
|
370
528
|
env: { ...process.env, DSH_HOME: state.dshHome, DSH_AGENTS_HOME: state.agentsHome },
|
|
@@ -752,7 +910,15 @@ export async function update(args = []) {
|
|
|
752
910
|
const pending = await refreshRuntime(state, true);
|
|
753
911
|
// The process keeps the code it started with for this deployment; the next
|
|
754
912
|
// Kitto call (and each restarted host) uses the replaced runtime.
|
|
755
|
-
|
|
913
|
+
try {
|
|
914
|
+
await deploy(state, true, plan, packageRoot);
|
|
915
|
+
} catch (error) {
|
|
916
|
+
// The runtime swap already happened on disk but is not verified yet; say
|
|
917
|
+
// so, because otherwise only state.json reveals why recover matters.
|
|
918
|
+
if (pending) console.error(`kitto: runtime ${pending.version} stays unverified because the deployment did not finish. `
|
|
919
|
+
+ 'Rerun `kitto update --apply` to finish, or `kitto setup --recover` to return to the previous runtime.');
|
|
920
|
+
throw error;
|
|
921
|
+
}
|
|
756
922
|
await finalizeRuntime(state, pending);
|
|
757
923
|
console.log(`Kitto update complete: runtime ${state.version}, configuration ${sourceRevision(state.source).commit.slice(0, 7)}. Restart native hosts to load new plugin code.`);
|
|
758
924
|
};
|
|
@@ -863,7 +1029,9 @@ export async function setup(options = {}) {
|
|
|
863
1029
|
console.log(`Global setup: ${agents.join(', ')}; source: ${requested}; Kitto home: ${home}`);
|
|
864
1030
|
// The app-managed Desktop profile has no CLI prerequisite Kitto may install or verify.
|
|
865
1031
|
const checkedAgents = agents.filter(name => !(name === 'dsh' && isDesktopProfile(dshProfile)));
|
|
866
|
-
|
|
1032
|
+
// A stale host is reported and downgraded, never fatal: --require-baseline
|
|
1033
|
+
// restores the strict gate for release verification.
|
|
1034
|
+
checkSelectedHosts(checkedAgents, options['install-agents'], { requireBaseline: options['require-baseline'] === true });
|
|
867
1035
|
const includePrivate = options['include-private'] === true ? true
|
|
868
1036
|
: options['no-include-private'] === true ? false : old.includePrivate === true;
|
|
869
1037
|
const state = { ...old, schema: 1, ready: false, detached: false, removing: false, removedAgents: [], source, agents, dshProfile,
|
package/lib/scope-setup.mjs
CHANGED
|
@@ -64,7 +64,7 @@ export async function setupScope(options) {
|
|
|
64
64
|
throw new Error('Choose exactly one of --global, --workspace PATH or --workspace-parent PATH.');
|
|
65
65
|
}
|
|
66
66
|
for (const key of Object.keys(options)) {
|
|
67
|
-
if (!['global', 'workspace', 'workspace-parent', 'agents', 'dsh-profile', 'dsh-service', 'dry-run'].includes(key)) {
|
|
67
|
+
if (!['global', 'workspace', 'workspace-parent', 'agents', 'dsh-profile', 'dsh-service', 'dry-run', 'require-baseline'].includes(key)) {
|
|
68
68
|
throw new Error('Scoped setup does not support --' + key);
|
|
69
69
|
}
|
|
70
70
|
}
|
package/package.json
CHANGED
package/sync.sh
CHANGED
|
@@ -77,16 +77,33 @@ TMP="$(mktemp -d)"
|
|
|
77
77
|
LOCK=""
|
|
78
78
|
cleanup() {
|
|
79
79
|
rm -rf "$TMP"
|
|
80
|
-
[ -z "$LOCK" ] ||
|
|
80
|
+
[ -z "$LOCK" ] || rm -rf "$LOCK"
|
|
81
81
|
}
|
|
82
82
|
trap cleanup EXIT
|
|
83
|
+
# bash does not run the EXIT trap on SIGTERM/SIGKILL, and a killed sync would
|
|
84
|
+
# leave the write lock behind for the next run to trip over.
|
|
85
|
+
trap 'cleanup; exit 130' INT
|
|
86
|
+
trap 'cleanup; exit 143' TERM
|
|
83
87
|
if [ "$DRY" = 0 ] && [[ "$CMD" =~ ^(pull|push|deps)$ ]]; then
|
|
84
88
|
mkdir -p "$LOCAL"
|
|
85
89
|
if ! mkdir "$LOCAL/.sync-lock" 2>/dev/null; then
|
|
86
|
-
|
|
90
|
+
# Report whether the recorded holder can still be running instead of
|
|
91
|
+
# asking the operator to inspect the directory by hand.
|
|
92
|
+
holder=""
|
|
93
|
+
if [ -f "$LOCAL/.sync-lock/pid" ]; then
|
|
94
|
+
holder="$(cat "$LOCAL/.sync-lock/pid" 2>/dev/null)"
|
|
95
|
+
fi
|
|
96
|
+
if [ -n "$holder" ] && kill -0 "$holder" 2>/dev/null; then
|
|
97
|
+
fail "另一个同步操作仍在运行(pid $holder)。等它结束后重试。"
|
|
98
|
+
elif [ -n "$holder" ]; then
|
|
99
|
+
fail "残留的同步锁:pid $holder 已退出。重跑命令并加 --break-lock 自动清理,或 rm -rf $LOCAL/.sync-lock"
|
|
100
|
+
else
|
|
101
|
+
fail "$LOCAL/.sync-lock 存在但没有 pid 记录(旧版 Kitto 留下的)。确认没有进程在写后 rm -rf $LOCAL/.sync-lock"
|
|
102
|
+
fi
|
|
87
103
|
exit 1
|
|
88
104
|
fi
|
|
89
105
|
LOCK="$LOCAL/.sync-lock"
|
|
106
|
+
printf '%s\n' "$$" > "$LOCK/pid"
|
|
90
107
|
fi
|
|
91
108
|
|
|
92
109
|
run() {
|