@phyzess/kitto 0.0.0-stage → 0.2.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/CHANGELOG.md +42 -0
- package/README.md +32 -2
- package/bin/kitto.mjs +35 -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/scoped-codex/session-start.mjs +59 -0
- package/integration/scoped-dsh/index.mjs +124 -0
- package/integration/scoped-dsh/native.mjs +8 -0
- package/integration/scoped-pi/index.mjs +62 -0
- package/integration/skills/kitto/SKILL.md +39 -0
- package/lib/dependencies.mjs +178 -0
- package/lib/environment-setup.mjs +43 -0
- package/lib/host-config.mjs +70 -0
- package/lib/kitto.mjs +616 -0
- package/lib/pi_config.py +330 -0
- package/lib/scope-codex.mjs +76 -0
- package/lib/scope-dsh.mjs +92 -0
- package/lib/scope-pi.mjs +41 -0
- package/lib/scope-service.mjs +261 -0
- package/lib/scope-setup.mjs +140 -0
- package/lib/scopes.mjs +51 -0
- package/lib/setup-wizard.mjs +241 -0
- package/lib/update-notice.mjs +26 -0
- package/lib/versions.mjs +139 -0
- package/package.json +16 -4
- package/sync.sh +480 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { checkSelectedHosts, installMissingHosts, maintain, setup } from './kitto.mjs';
|
|
4
|
+
import { query } from './dependencies.mjs';
|
|
5
|
+
import { configureServiceEnvironment } from './scope-service.mjs';
|
|
6
|
+
|
|
7
|
+
export async function runEnvironmentSetup(plan) {
|
|
8
|
+
const { unit, deps, installAgents, dryRun, dshProfile } = plan;
|
|
9
|
+
const source = plan.source && existsSync(plan.source) ? resolve(plan.source) : plan.source;
|
|
10
|
+
const workspace = plan.workspace && resolve(plan.workspace);
|
|
11
|
+
const agents = plan.agents.filter(name => name !== 'dsh' || !unit);
|
|
12
|
+
const serviceOptions = { unit, source, deps, workspace, global: true, installAgents: plan.serviceInstallAgents ?? false, dshProfile };
|
|
13
|
+
if (unit) await configureServiceEnvironment({ ...serviceOptions, dryRun: true });
|
|
14
|
+
if (agents.length) {
|
|
15
|
+
const options = { agents, 'dry-run': dryRun };
|
|
16
|
+
if (agents.includes('dsh')) options['dsh-profile'] = dshProfile;
|
|
17
|
+
if (source === false) {
|
|
18
|
+
checkSelectedHosts(agents, installAgents);
|
|
19
|
+
if (!dryRun && installAgents) installMissingHosts(agents);
|
|
20
|
+
} else {
|
|
21
|
+
await setup({ ...options, source, 'install-agents': installAgents, keepExistingSkills: true });
|
|
22
|
+
}
|
|
23
|
+
// The DSH adapter imports modules from its native CLI, which may still be pending in a preview.
|
|
24
|
+
const scopedAgents = agents.filter(name => !(dryRun && installAgents && name === 'dsh' && query('dsh', ['--version']) === null));
|
|
25
|
+
if (scopedAgents.length !== agents.length) console.log('DSH scope registration will run after its CLI is installed.');
|
|
26
|
+
if (scopedAgents.length) {
|
|
27
|
+
const scope = { ...options, agents: scopedAgents };
|
|
28
|
+
if (!scopedAgents.includes('dsh')) delete scope['dsh-profile'];
|
|
29
|
+
await setup({ ...scope, global: true });
|
|
30
|
+
if (workspace) await setup({ ...scope, 'workspace-parent': workspace });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (unit && !dryRun) await configureServiceEnvironment({ ...serviceOptions, dryRun: false });
|
|
34
|
+
if (agents.length && deps && source !== false) {
|
|
35
|
+
if (dryRun) console.log('安装时将检查配置仓库声明的辅助工具和依赖。');
|
|
36
|
+
else await maintain(['deps', '--apply']);
|
|
37
|
+
}
|
|
38
|
+
if (dryRun) return;
|
|
39
|
+
console.log('环境配置已完成。以后在项目目录开启新会话即可。');
|
|
40
|
+
if (workspace) console.log('未来新建的工作区也会生效:' + workspace + '/<工作区>/AGENTS.md');
|
|
41
|
+
if (agents.includes('codex')) console.log('首次使用 Codex 时,在 /hooks 中确认信任 Kitto 的 SessionStart hook。');
|
|
42
|
+
if (plan.agents.includes('dsh')) console.log('已运行的 DSH 需要重启对应服务或 profile 以加载配置。');
|
|
43
|
+
}
|
|
@@ -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
|
+
}
|