@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/CHANGELOG.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Kitto
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
- Document setup, synchronization and tag-pinned configuration for Pi, Codex and DSH.
|
|
6
|
+
- Use Node.js 26 LTS for release checks and CI.
|
|
7
|
+
- Validate, tag and publish release snapshots with `npm run release`.
|
|
8
|
+
- Allow switching configuration tags when the Kitto home path uses a filesystem alias.
|
|
9
|
+
|
|
10
|
+
## 0.1.0
|
|
11
|
+
|
|
12
|
+
- Pin the Pi extensions and Context7 package used by the configuration snapshot.
|
|
13
|
+
- Record the configured and last deployed revisions, and switch managed checkouts to explicit Git tags.
|
|
14
|
+
- Declare tools in the configuration repository and report shared versus machine-local changes.
|
|
15
|
+
|
|
16
|
+
- Scope configuration validation and prerequisites to the selected agent. Codex and DSH maintenance no longer needs Python or Pi files.
|
|
17
|
+
- Sync user rules and host-specific skills for Codex and DSH. Remember the selected DSH CLI profile.
|
|
18
|
+
- Plan tool dependencies from enabled Pi MCPs and shared skills. Give optional CodeGraph workflows a native-tool fallback.
|
|
19
|
+
- Report selected host versions, native plugins and bundles, and the actual configured MCP launch versions.
|
|
20
|
+
|
|
21
|
+
- Resume a Kitto-owned checkout after a failed first setup.
|
|
22
|
+
- Summarize dependency readiness and report incomplete managed installs.
|
|
23
|
+
- Keep the last working code checkpoint through failed installation retries.
|
|
24
|
+
- Add previewable code recovery and resumable native integration removal.
|
|
25
|
+
- Keep personal configuration, shared skills and installed agent CLIs in place.
|
|
26
|
+
- Provide `setup --recover` when the installed maintenance runner cannot start.
|
|
27
|
+
- Check DSH's pnpm prerequisite before writes; install it when missing with `--install-agents`.
|
|
28
|
+
- Recognize native registration paths through filesystem aliases without weakening foreign-source checks.
|
|
29
|
+
|
|
30
|
+
## 0.1.0-dev.0
|
|
31
|
+
|
|
32
|
+
- Add global setup and an on-demand maintenance skill for Pi, Codex and DSH.
|
|
33
|
+
- Reuse the Pi configuration merge/export implementation and version inventory.
|
|
34
|
+
- Keep personal configuration outside the distributable npm package.
|
|
35
|
+
- Preserve native launch commands; do not start background services.
|
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Kitto
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Kitto 把这份仓库里的个人配置带到每台开发机。换一台 Mac 或 Linux 机器后,Pi、Codex 和 DeepSeek Harness(DSH)都能用上你熟悉的工作规则和 skills。
|
|
4
|
+
|
|
5
|
+
## 新机安装
|
|
6
|
+
|
|
7
|
+
准备好 Git、Node.js 26 LTS(Kitto 最低要求 Node.js 22),以及你要使用的 agent。在任意目录运行一次:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx --yes github:phyzess/kitto setup
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
这条命令从 GitHub 取得 Kitto,自动识别本机已安装的 agent,把配置部署到当前用户目录。Pi 还需要 Bash 和 Python 3.10+,DSH 需要 pnpm。如果机器上还没有 agent,见[安装选项](docs/usage.md#选择-agent)。
|
|
14
|
+
|
|
15
|
+
## 平时怎么用
|
|
16
|
+
|
|
17
|
+
照常启动 `pi`、`codex` 或 `dsh web`。需要维护配置时,在会话里直接说:
|
|
18
|
+
|
|
19
|
+
- “用 Kitto 看看,这台机器的配置和仓库有什么不同?”
|
|
20
|
+
- “用 Kitto 把仓库里的最新配置同步到这台机器。”
|
|
21
|
+
- “以后所有机器上的 Codex 都用中文回复,把这条写进配置仓库。”
|
|
22
|
+
|
|
23
|
+
想把改动带到另一台机器,先把配置提交并推送到 Git,再在另一台机器上同步。只属于本机的设置可以留在本地。
|
|
24
|
+
|
|
25
|
+
[配置与同步指南](docs/usage.md) · [Pi 配置参考](docs/pi.md) · [版本记录](CHANGELOG.md) · [发布新版本](docs/usage.md#发布新版本)
|
package/bin/kitto.mjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { setup, parseOptions } from '../lib/kitto.mjs';
|
|
3
|
+
|
|
4
|
+
const help = `Kitto — portable personal agent configuration
|
|
5
|
+
|
|
6
|
+
kitto setup [--agents pi,codex,dsh] [--source PATH_OR_GIT_URL] [--ref BRANCH_OR_TAG]
|
|
7
|
+
[--dsh-profile PROFILE] [--install-agents] [--dry-run]
|
|
8
|
+
kitto setup --recover [--dry-run] Restore the last working Kitto code
|
|
9
|
+
|
|
10
|
+
Global user setup only. Defaults to installed agents and phyzess/kitto.
|
|
11
|
+
After setup, start your agent with its native command and ask the Kitto skill
|
|
12
|
+
to inspect, sync or update your configuration. No project initialization.
|
|
13
|
+
Kitto needs Node >=22 and Git. Pi sync also needs Bash and Python >=3.10.
|
|
14
|
+
DSH needs pnpm and uses the web profile by default. Host CLIs have their own Node requirements.
|
|
15
|
+
`;
|
|
16
|
+
try {
|
|
17
|
+
const [command, ...args] = process.argv.slice(2);
|
|
18
|
+
if (!command || command === '--help' || command === '-h') console.log(help);
|
|
19
|
+
else if (command === 'setup') await setup(parseOptions(args));
|
|
20
|
+
else throw new Error(`Unknown command: ${command}. Use kitto --help.`);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error(`Kitto: ${error.message}`);
|
|
23
|
+
process.exitCode = 1;
|
|
24
|
+
}
|
package/bin/maintain.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Internal entry used by the bundled skill, not a second public CLI.
|
|
3
|
+
import { maintain } from '../lib/kitto.mjs';
|
|
4
|
+
try {
|
|
5
|
+
await maintain(process.argv.slice(2));
|
|
6
|
+
} catch (error) {
|
|
7
|
+
console.error(`Kitto: ${error.message}`);
|
|
8
|
+
process.exitCode = 1;
|
|
9
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
|
|
4
|
+
export const name = 'phyzess-kitto';
|
|
5
|
+
export const inject = ['skills'];
|
|
6
|
+
|
|
7
|
+
// Only one catalog entry at startup; the body is loaded on demand.
|
|
8
|
+
export function apply(ctx) {
|
|
9
|
+
const path = fileURLToPath(new URL('./skills/kitto/SKILL.md', import.meta.url));
|
|
10
|
+
const candidate = {
|
|
11
|
+
name: 'kitto', description: 'Inspect, synchronize and update personal agent configuration with Kitto.',
|
|
12
|
+
invocation: { modelInvocable: true, userInvocable: true },
|
|
13
|
+
source: 'bundled', provider: 'phyzess-kitto', rank: 600, locator: path, path,
|
|
14
|
+
resourceBase: { kind: 'directory', path: fileURLToPath(new URL('./skills/kitto/', import.meta.url)) },
|
|
15
|
+
};
|
|
16
|
+
ctx.skills.registerProvider(() => ({
|
|
17
|
+
name: 'phyzess-kitto',
|
|
18
|
+
list: async () => [candidate],
|
|
19
|
+
get: async () => ({ ...candidate, content: (await readFile(path, 'utf8')).replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n/, '') }),
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { kittoHome } from '../lib/kitto.mjs';
|
|
3
|
+
import { updateNotice } from '../lib/update-notice.mjs';
|
|
4
|
+
|
|
5
|
+
// Non-blocking self-update notice; Pi remains responsible for its other packages.
|
|
6
|
+
export default function kitto(pi) {
|
|
7
|
+
pi.on('session_start', (_event, ctx) => {
|
|
8
|
+
if (!ctx.hasUI || process.env.KITTO_UPDATE_CHECK === '0') return;
|
|
9
|
+
void readFile(new URL('../package.json', import.meta.url), 'utf8')
|
|
10
|
+
.then(text => updateNotice(kittoHome(), JSON.parse(text).version))
|
|
11
|
+
.then(notice => { if (notice) ctx.ui.notify(notice, 'info'); })
|
|
12
|
+
.catch(() => {});
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kitto
|
|
3
|
+
description: Inspect, synchronize and update personal agent configuration across machines with Kitto. Use for Kitto setup, configuration drift, dependency versions or syncing personal skills; not for ordinary project tasks.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Use the installed maintenance runner. Setup replaces `KITTO_RUNNER` below with its absolute, shell-quoted path. If it is still a placeholder, Kitto setup has not completed; do not guess an installation path.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
node KITTO_RUNNER status
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Keep normal work in the current native agent. Do not introduce a launcher or modify project configuration. The runner exposes only these maintenance operations:
|
|
13
|
+
|
|
14
|
+
| Operation | Behavior |
|
|
15
|
+
|---|---|
|
|
16
|
+
| `status` | Read installation state and configuration differences locally |
|
|
17
|
+
| `versions` | Read installed and declared component versions |
|
|
18
|
+
| `versions --online` | Also query registry release channels; no installation |
|
|
19
|
+
| `sync` | Preview repository-to-machine configuration deployment |
|
|
20
|
+
| `sync --apply` | Deploy configuration and reconnect native integrations |
|
|
21
|
+
| `update` | Preview the source branch's remote head without fetching |
|
|
22
|
+
| `update --apply` | Fast-forward a clean tracked source branch, then deploy |
|
|
23
|
+
| `export` | Preview sanitized Pi machine-to-repository export |
|
|
24
|
+
| `export --apply` | Write that export to the local source checkout; never commit or push |
|
|
25
|
+
| `deps` / `deps --apply` | Preview / install CLI dependencies needed by the selected hosts and enabled capabilities, only when requested |
|
|
26
|
+
| `recover` / `recover --apply` | Preview / restore the last verified Kitto code checkpoint and reconnect native integrations |
|
|
27
|
+
| `remove` / `remove --apply` | Preview / detach Kitto's native integrations; retain personal configuration, shared skills, CLIs and recovery files |
|
|
28
|
+
|
|
29
|
+
Begin with `status`. For changes, inspect the corresponding preview, explain concrete conflicts or scope, and apply within the user's authorization. A sync may install the source's declared Pi packages. Existing shared skill directories are preserved when different; report conflicts and resolve them with the user rather than deleting them. Local edits or diverged source history stop an update; never reset or stash them automatically.
|
|
30
|
+
|
|
31
|
+
Use `versions --online` when asked about upgrades. Distinguish installed, declared and upstream versions, including prereleases and engine requirements. Registry metadata is not a compatibility test. Kitto does not bulk-upgrade hosts or plugins: use each native manager for explicitly selected upgrades, test the relevant host, and update the source only after validation. Update Kitto itself by rerunning its npm setup entry with the intended package version.
|
|
32
|
+
|
|
33
|
+
For a change intended for every machine, edit the source checkout. Write host-specific changes under the corresponding `config/<agent>/` and common workflows under `skills/`. Show the Git diff, preview and apply sync, and report whether the changes have reached the remote. For this machine only, use the native host's local override. For Codex and DSH instructions, keep local text outside Kitto's managed block. For Pi, use its existing local settings and MCP overrides. When migrating an existing machine, first identify shared content, local changes and machine-specific tools, then transfer only the selected portable items.
|
|
34
|
+
|
|
35
|
+
The source checkout owns shared skills, host-specific skills, Pi settings, and managed instruction blocks for Codex and DSH. Codex and DSH keep their own authentication, model choices, permissions and MCP configuration. Check the current session for any optional tools a skill needs. Read the source's documentation before changing personal assets. Report what changed, skipped conflicts, failures and any required native reload. Stop on errors; rerun only after resolving the cause.
|
|
36
|
+
|
|
37
|
+
Recovery only changes Kitto code and its native registration, preserving the currently deployed personal configuration. It is not a transaction rollback of all earlier file changes or dependency installs. If the installed runner cannot start, use the same package setup entry with `--recover --dry-run`, then `--recover` within the user's request. This external entry also works when recovering an older Kitto version whose skill lacks recovery commands. With no verified checkpoint, rerun setup from a known working package version.
|
|
38
|
+
|
|
39
|
+
Removal is resumable: repeat it after fixing a native-manager error. It never deletes the source checkout, shared skills, agent CLIs or authentication. Native registrations that point to another source are preserved and reported as conflicts. After detaching, use setup to reinstall; ordinary sync must not reconnect a removed integration implicitly. Complete the requested maintenance without running the agent's task through Kitto.
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, statSync, accessSync, constants } from 'node:fs';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { delimiter, join, resolve } from 'node:path';
|
|
5
|
+
|
|
6
|
+
export async function optionalJson(path, fallback = {}) {
|
|
7
|
+
try { return JSON.parse(await readFile(path, 'utf8')); }
|
|
8
|
+
catch (error) { if (error.code === 'ENOENT') return fallback; throw error; }
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function executable(name) {
|
|
12
|
+
const paths = name.includes('/') ? [resolve(name)] : (process.env.PATH || '').split(delimiter).map(dir => resolve(dir, name));
|
|
13
|
+
return paths.find(path => {
|
|
14
|
+
try { accessSync(path, constants.X_OK); return statSync(path).isFile(); }
|
|
15
|
+
catch { return false; }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function query(command, args, env = process.env) {
|
|
20
|
+
const result = spawnSync(command, args, { encoding: 'utf8', timeout: 8000, env });
|
|
21
|
+
return result.status === 0 ? result.stdout.trim() : null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function npmSpec(source) {
|
|
25
|
+
const spec = source.replace(/^npm:/, '');
|
|
26
|
+
const split = spec.lastIndexOf('@');
|
|
27
|
+
return split > 0 ? [spec.slice(0, split), spec.slice(split + 1)] : [spec, null];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function piServers(state) {
|
|
31
|
+
const declared = await optionalJson(join(state.source, 'config/pi/mcp.json'));
|
|
32
|
+
// Once installed, respect the actual selected command and local on/off switches.
|
|
33
|
+
const live = await optionalJson(join(state.piHome, 'mcp.json'), declared);
|
|
34
|
+
return Object.fromEntries(Object.entries(live.mcpServers || {}).filter(
|
|
35
|
+
([name, entry]) => !name.startsWith('_') && entry?.command && entry.enabled !== false,
|
|
36
|
+
));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const legacyRules = [
|
|
40
|
+
{ executable: 'codegraph', skill: 'codegraph', piCommand: 'codegraph' },
|
|
41
|
+
{ executable: 'serena', piCommand: 'serena' },
|
|
42
|
+
{ executable: 'dap-mcp-server', piCommand: 'dap-mcp-server', list: 'mise-tools.txt', manager: 'mise' },
|
|
43
|
+
{ package: 'debugpy', piCommand: 'dap-mcp-server', list: 'pip.txt', manager: 'pip' },
|
|
44
|
+
{ executable: 'ast-grep', piNpx: 'ast-grep-mcp', list: 'brew.txt', manager: 'brew', platform: 'darwin' },
|
|
45
|
+
{ executable: 'ast-grep', package: '@ast-grep/cli', piNpx: 'ast-grep-mcp', list: 'npm.txt', manager: 'mise', platform: 'linux' },
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
export function npxPackage(entry) {
|
|
49
|
+
if (entry.command !== 'npx') return [];
|
|
50
|
+
const spec = entry.args?.find(value => !value.startsWith('-'));
|
|
51
|
+
return spec ? npmSpec(spec) : [];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function listTarget(state, rule) {
|
|
55
|
+
if (!rule.list) return null;
|
|
56
|
+
const path = join(state.source, 'lists', rule.list);
|
|
57
|
+
if (!existsSync(path)) return undefined;
|
|
58
|
+
const lines = (await readFile(path, 'utf8')).split('\n');
|
|
59
|
+
for (const line of lines) {
|
|
60
|
+
const [name, version] = line.split('#', 1)[0].trim().split(/\s+/);
|
|
61
|
+
if (name === (rule.package || rule.executable)) return version ?? null;
|
|
62
|
+
}
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function dependencyRules(state) {
|
|
67
|
+
const entries = await optionalJson(join(state.source, 'config/dependencies.json'), null);
|
|
68
|
+
if (entries === null) return legacyRules;
|
|
69
|
+
if (!Array.isArray(entries)) throw new Error('config/dependencies.json must contain an array.');
|
|
70
|
+
return entries.map((rule, index) => {
|
|
71
|
+
const invalid = () => new Error(`Invalid dependency declaration at config/dependencies.json entry ${index + 1}.`);
|
|
72
|
+
const fields = ['agent', 'platform', 'skill', 'piCommand', 'piNpx', 'executable', 'install'];
|
|
73
|
+
const name = /^[a-zA-Z0-9_][a-zA-Z0-9_.-]*$/;
|
|
74
|
+
const npmName = /^(?:@[a-z0-9_.-]+\/)?[a-z0-9_][a-z0-9_.-]*$/;
|
|
75
|
+
if (!rule || typeof rule !== 'object' || Object.keys(rule).some(key => !fields.includes(key))) throw invalid();
|
|
76
|
+
for (const key of fields.filter(key => key !== 'install')) {
|
|
77
|
+
if (key in rule && (typeof rule[key] !== 'string' || !(key === 'piNpx' ? npmName : name).test(rule[key]))) throw invalid();
|
|
78
|
+
}
|
|
79
|
+
if (!rule.agent && !rule.skill && !rule.piCommand && !rule.piNpx) throw invalid();
|
|
80
|
+
if (rule.agent && !['pi', 'codex', 'dsh'].includes(rule.agent)) throw invalid();
|
|
81
|
+
if (rule.platform && !['darwin', 'linux'].includes(rule.platform)) throw invalid();
|
|
82
|
+
if (!('install' in rule)) {
|
|
83
|
+
if (!rule.executable) throw invalid();
|
|
84
|
+
return rule;
|
|
85
|
+
}
|
|
86
|
+
if (!rule.install || typeof rule.install !== 'object' || Object.keys(rule.install).length !== 1) throw invalid();
|
|
87
|
+
const [[manager, spec]] = Object.entries(rule.install);
|
|
88
|
+
if (!['mise', 'pip', 'brew'].includes(manager) || typeof spec !== 'string') throw invalid();
|
|
89
|
+
const [pkg, target] = manager === 'mise' ? npmSpec(spec) : [spec, null];
|
|
90
|
+
if (manager === 'mise') {
|
|
91
|
+
if (!spec.startsWith('npm:') || !npmName.test(pkg) || !/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(target || '')) throw invalid();
|
|
92
|
+
} else if (!name.test(pkg)) throw invalid();
|
|
93
|
+
if (manager !== 'pip' && !rule.executable) throw invalid();
|
|
94
|
+
return { ...rule, package: pkg, target, manager };
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function dependencyPlan(state) {
|
|
99
|
+
const servers = state.agents.includes('pi') ? await piServers(state) : {};
|
|
100
|
+
const plans = new Map();
|
|
101
|
+
for (const rule of await dependencyRules(state)) {
|
|
102
|
+
if (rule.agent && !state.agents.includes(rule.agent)) continue;
|
|
103
|
+
if (rule.platform && rule.platform !== process.platform) continue;
|
|
104
|
+
const reasons = [];
|
|
105
|
+
if (rule.skill && existsSync(join(state.source, 'skills', rule.skill, 'SKILL.md'))) reasons.push(`shared skill ${rule.skill}`);
|
|
106
|
+
for (const [name, entry] of Object.entries(servers)) {
|
|
107
|
+
if (rule.piCommand === entry.command || (rule.piNpx && rule.piNpx === npxPackage(entry)[0])) reasons.push(`Pi MCP ${name}`);
|
|
108
|
+
}
|
|
109
|
+
if (!reasons.length && rule.agent && !rule.skill && !rule.piCommand && !rule.piNpx) reasons.push(rule.agent);
|
|
110
|
+
if (!reasons.length) continue;
|
|
111
|
+
const target = rule.list ? await listTarget(state, rule) : rule.target ?? null;
|
|
112
|
+
if (target === undefined) continue;
|
|
113
|
+
const name = rule.package || rule.executable;
|
|
114
|
+
if (rule.manager === 'mise' && !target) throw new Error(`Missing declared version for ${name} in lists/${rule.list}.`);
|
|
115
|
+
let installed = null;
|
|
116
|
+
const path = rule.executable ? executable(rule.executable) : undefined;
|
|
117
|
+
if (rule.manager === 'mise') {
|
|
118
|
+
const active = query('mise', ['current', `npm:${name}`]);
|
|
119
|
+
if (active) installed = active.replace(/^v/, '');
|
|
120
|
+
} else if (rule.manager === 'pip') {
|
|
121
|
+
installed = query('python3', ['-m', 'pip', 'show', name])?.match(/^Version: (.+)$/m)?.[1] || null;
|
|
122
|
+
}
|
|
123
|
+
const key = rule.executable ? `executable:${rule.executable}` : `package:${name}`;
|
|
124
|
+
const previous = plans.get(key);
|
|
125
|
+
if (previous?.manager && rule.manager &&
|
|
126
|
+
(previous.manager !== rule.manager || previous.name !== name || previous.target !== target)) {
|
|
127
|
+
throw new Error(`Conflicting dependency declarations for ${rule.executable || name}.`);
|
|
128
|
+
}
|
|
129
|
+
const plan = { name, path, target, installed, manager: rule.manager,
|
|
130
|
+
note: rule.skill ? 'Binary check only. Verify MCP tools in the active session.' : undefined,
|
|
131
|
+
available: rule.manager === 'pip' ? Boolean(installed) : Boolean(path) && (!target || installed === target),
|
|
132
|
+
reason: reasons.join(', ') };
|
|
133
|
+
const selected = previous?.manager || !rule.manager ? previous || plan : plan;
|
|
134
|
+
if (previous) {
|
|
135
|
+
selected.reason = [...new Set([...previous.reason.split(', '), ...reasons])].join(', ');
|
|
136
|
+
selected.note ||= previous.note || plan.note;
|
|
137
|
+
}
|
|
138
|
+
plans.set(key, selected);
|
|
139
|
+
}
|
|
140
|
+
return [...plans.values()];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export async function installDependencies(state, apply) {
|
|
144
|
+
const plans = await dependencyPlan(state);
|
|
145
|
+
if (!plans.length) console.log('No declared dependencies for the enabled hosts and shared skills.');
|
|
146
|
+
const blocked = [], manual = [], attempted = [];
|
|
147
|
+
for (const tool of plans) {
|
|
148
|
+
const { name, target, manager, reason } = tool;
|
|
149
|
+
if (tool.available) { console.log(`Available: ${name} (${reason})`); continue; }
|
|
150
|
+
if (!manager) {
|
|
151
|
+
manual.push(name);
|
|
152
|
+
console.log(`Missing: ${name} (${reason}); install separately if needed.`);
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
const command = manager === 'pip' ? 'python3' : manager;
|
|
156
|
+
const args = manager === 'mise' ? ['use', '-g', `npm:${name}@${target}`]
|
|
157
|
+
: manager === 'pip' ? ['-m', 'pip', 'install', name] : ['install', name];
|
|
158
|
+
if (!executable(command)) {
|
|
159
|
+
blocked.push(`${name} (missing ${command})`);
|
|
160
|
+
console.log(`Missing installer ${command}: ${name} (${reason})`);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
console.log(`${apply ? 'Run' : 'Would run'}: ${[command, ...args].join(' ')} (${reason})`);
|
|
164
|
+
if (apply) {
|
|
165
|
+
const result = spawnSync(command, args, { stdio: 'inherit', timeout: 600_000 });
|
|
166
|
+
if (result.status !== 0) blocked.push(`${name} (${result.error?.message || `exit ${result.status}`})`);
|
|
167
|
+
else attempted.push(name);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (!apply) return;
|
|
171
|
+
const current = attempted.length ? await dependencyPlan(state) : plans;
|
|
172
|
+
const ready = current.filter(tool => tool.available).map(tool => tool.name);
|
|
173
|
+
for (const name of attempted) if (!ready.includes(name)) blocked.push(`${name} (still unavailable after install)`);
|
|
174
|
+
console.log(`Ready: ${ready.join(', ') || 'none'}`);
|
|
175
|
+
console.log(`Manual setup: ${manual.join(', ') || 'none'}`);
|
|
176
|
+
console.log(`Unresolved managed dependencies: ${blocked.join(', ') || 'none'}`);
|
|
177
|
+
if (blocked.length) throw new Error('Some managed dependencies are still unavailable.');
|
|
178
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { lstat, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
|
|
5
|
+
const begin = '<!-- kitto:begin -->', end = '<!-- kitto:end -->';
|
|
6
|
+
const optionalText = async path => {
|
|
7
|
+
try { return await readFile(path, 'utf8'); }
|
|
8
|
+
catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function hostSkillRoots(state) {
|
|
12
|
+
return state.agents.map(name => ({
|
|
13
|
+
name,
|
|
14
|
+
source: join(state.source, 'config', name, 'skills'),
|
|
15
|
+
target: join(state[name + 'Home'], 'skills'),
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function instructionPlan(state) {
|
|
20
|
+
const plans = [];
|
|
21
|
+
for (const name of state.agents.filter(name => name !== 'pi')) {
|
|
22
|
+
const source = await optionalText(join(state.source, 'config', name, 'AGENTS.md'));
|
|
23
|
+
const home = state[name + 'Home'];
|
|
24
|
+
const target = join(home, 'AGENTS.md');
|
|
25
|
+
if (source === null && !state.instructions?.[name]) continue;
|
|
26
|
+
if (source?.includes(begin) || source?.includes(end)) throw new Error(`Reserved Kitto markers in ${name} instructions.`);
|
|
27
|
+
const stat = await lstat(target).catch(error => {
|
|
28
|
+
if (error.code === 'ENOENT') return null;
|
|
29
|
+
throw error;
|
|
30
|
+
});
|
|
31
|
+
if (stat && !stat.isFile()) throw new Error(`Instruction target is not a regular file: ${target}`);
|
|
32
|
+
const before = (await optionalText(target)) || '';
|
|
33
|
+
const start = before.indexOf(begin), finish = before.indexOf(end);
|
|
34
|
+
const previous = state.instructions?.[name];
|
|
35
|
+
const block = source?.trim() ? `${begin}\n${source.trim()}\n${end}\n` : '';
|
|
36
|
+
let after;
|
|
37
|
+
if (start < 0 && finish < 0) {
|
|
38
|
+
after = block ? before + (before && !before.endsWith('\n') ? '\n' : '') + block : before;
|
|
39
|
+
} else {
|
|
40
|
+
if (start < 0 || finish < start || before.indexOf(begin, start + begin.length) !== -1 ||
|
|
41
|
+
before.indexOf(end, finish + end.length) !== -1) throw new Error(`Invalid Kitto block in ${target}. Preserved.`);
|
|
42
|
+
const stop = finish + end.length + (before[finish + end.length] === '\n' ? 1 : 0);
|
|
43
|
+
const current = before.slice(start, stop);
|
|
44
|
+
if (current !== previous && current !== block) throw new Error(`Local changes inside the Kitto block in ${target}. Preserved.`);
|
|
45
|
+
after = before.slice(0, start) + block + before.slice(stop);
|
|
46
|
+
}
|
|
47
|
+
if (name === 'codex' && block && existsSync(join(home, 'AGENTS.override.md'))) {
|
|
48
|
+
console.log('Codex AGENTS.override.md takes precedence over the synced AGENTS.md.');
|
|
49
|
+
}
|
|
50
|
+
plans.push({ name, target, before, after, block, mode: stat?.mode });
|
|
51
|
+
}
|
|
52
|
+
return plans;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function applyInstructions(state, plans) {
|
|
56
|
+
state.instructions ||= {};
|
|
57
|
+
for (const { name, target, before, after, block, mode } of plans) {
|
|
58
|
+
if (after !== before) {
|
|
59
|
+
await mkdir(dirname(target), { recursive: true });
|
|
60
|
+
const temporary = `${target}.${process.pid}.tmp`;
|
|
61
|
+
try {
|
|
62
|
+
await writeFile(temporary, after, { flag: 'wx', mode: mode ?? 0o600 });
|
|
63
|
+
if (((await optionalText(target)) || '') !== before) throw new Error(`Instructions changed during sync: ${target}`);
|
|
64
|
+
await rename(temporary, target);
|
|
65
|
+
} finally { await rm(temporary, { force: true }); }
|
|
66
|
+
}
|
|
67
|
+
if (block) state.instructions[name] = block;
|
|
68
|
+
else delete state.instructions[name];
|
|
69
|
+
}
|
|
70
|
+
}
|