ai-engineering-loop 1.14.0 → 1.15.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/.agents/{workflows/ai-engineering-loop.md → skills/ai-engineering-loop/SKILL.md} +8 -6
- package/.agents/skills/ai-engineering-loop/references/loop-hosts.md +44 -0
- package/.claude/skills/ai-engineering-loop/SKILL.md +9 -10
- package/.claude/skills/ai-engineering-loop/references/loop-hosts.md +44 -0
- package/CHANGELOG.md +47 -0
- package/README.md +52 -6
- package/adapters/dot/README.md +1 -1
- package/bin/ai-engineering-loop.js +296 -11
- package/core/grill-policy.md +1 -1
- package/core/runtime-safety.md +2 -1
- package/lib/auto-update.js +3 -1
- package/lib/cli-args.js +11 -0
- package/lib/doctor.js +4 -15
- package/lib/host-skill-build.js +15 -15
- package/lib/hosts/agent-formats.js +135 -0
- package/lib/hosts/commands.js +126 -0
- package/lib/hosts/detect.js +56 -0
- package/lib/hosts/doctor.js +76 -0
- package/lib/hosts/redetect.js +60 -0
- package/lib/hosts/registry.js +271 -0
- package/lib/hosts/table.js +35 -0
- package/lib/run-abandon.js +116 -0
- package/lib/sync-hosts.js +155 -112
- package/package.json +2 -3
- package/.agents/devil-advocate.md +0 -79
- package/.agents/judge.md +0 -58
- package/.claude/commands/ai-engineering-loop.md +0 -11
- package/.gemini/skills/ai-engineering-loop/SKILL.md +0 -61
- package/.gemini/skills/animate/RECIPES.md +0 -324
- package/.gemini/skills/animate/SKILL.md +0 -207
- package/.gemini/skills/animate-expo/RECIPES.md +0 -385
- package/.gemini/skills/animate-expo/SKILL.md +0 -263
- package/.gemini/skills/animation-vocabulary/SKILL.md +0 -181
- package/.gemini/skills/apple-design/SKILL.md +0 -290
- package/.gemini/skills/ask-sonner/API.md +0 -64
- package/.gemini/skills/ask-sonner/SKILL.md +0 -88
- package/.gemini/skills/backend-development/SKILL.md +0 -272
- package/.gemini/skills/backend-development/references/api-design-guidelines.md +0 -95
- package/.gemini/skills/backend-development/references/query-and-database-best-practices.md +0 -53
- package/.gemini/skills/backend-development/references/security-checklist.md +0 -60
- package/.gemini/skills/emil-design-eng/SKILL.md +0 -674
- package/.gemini/skills/find-animation-opportunities/SKILL.md +0 -140
- package/.gemini/skills/improve-animations/AUDIT.md +0 -115
- package/.gemini/skills/improve-animations/PLAN-TEMPLATE.md +0 -73
- package/.gemini/skills/improve-animations/SKILL.md +0 -109
- package/.gemini/skills/mobile-native/SKILL.md +0 -311
- package/.gemini/skills/pick-ui-library/SKILL.md +0 -85
- package/.gemini/skills/prototype/PICKER.md +0 -197
- package/.gemini/skills/prototype/SKILL.md +0 -98
- package/.gemini/skills/review-animations/SKILL.md +0 -120
- package/.gemini/skills/review-animations/STANDARDS.md +0 -187
- package/.gemini/skills/write-swift/SKILL.md +0 -396
- package/.grok/commands/ai-engineering-loop.md +0 -11
- package/.grok/skills/ai-engineering-loop/SKILL.md +0 -62
- package/.grok/skills/ai-engineering-loop/references/loop-commands.md +0 -20
- package/.grok/skills/ai-engineering-loop/references/loop-deliver.md +0 -8
- package/.grok/skills/ai-engineering-loop/references/loop-goal.md +0 -10
- package/.grok/skills/ai-engineering-loop/references/loop-maker.md +0 -8
- package/.grok/skills/ai-engineering-loop/references/loop-review.md +0 -18
- package/.grok/skills/ai-engineering-loop/references/loop-risky.md +0 -9
- package/.grok/skills/ai-engineering-loop/references/loop-verify.md +0 -20
- package/.grok/skills/animate/RECIPES.md +0 -324
- package/.grok/skills/animate/SKILL.md +0 -207
- package/.grok/skills/animate-expo/RECIPES.md +0 -385
- package/.grok/skills/animate-expo/SKILL.md +0 -263
- package/.grok/skills/animation-vocabulary/SKILL.md +0 -181
- package/.grok/skills/apple-design/SKILL.md +0 -290
- package/.grok/skills/ask-sonner/API.md +0 -64
- package/.grok/skills/ask-sonner/SKILL.md +0 -88
- package/.grok/skills/backend-development/SKILL.md +0 -272
- package/.grok/skills/backend-development/references/api-design-guidelines.md +0 -95
- package/.grok/skills/backend-development/references/query-and-database-best-practices.md +0 -53
- package/.grok/skills/backend-development/references/security-checklist.md +0 -60
- package/.grok/skills/emil-design-eng/SKILL.md +0 -674
- package/.grok/skills/find-animation-opportunities/SKILL.md +0 -140
- package/.grok/skills/improve-animations/AUDIT.md +0 -115
- package/.grok/skills/improve-animations/PLAN-TEMPLATE.md +0 -73
- package/.grok/skills/improve-animations/SKILL.md +0 -109
- package/.grok/skills/mobile-native/SKILL.md +0 -311
- package/.grok/skills/pick-ui-library/SKILL.md +0 -85
- package/.grok/skills/prototype/PICKER.md +0 -197
- package/.grok/skills/prototype/SKILL.md +0 -98
- package/.grok/skills/review-animations/SKILL.md +0 -120
- package/.grok/skills/review-animations/STANDARDS.md +0 -187
- package/.grok/skills/write-swift/SKILL.md +0 -396
- /package/{.gemini → .agents}/skills/ai-engineering-loop/references/loop-commands.md +0 -0
- /package/{.gemini → .agents}/skills/ai-engineering-loop/references/loop-deliver.md +0 -0
- /package/{.gemini → .agents}/skills/ai-engineering-loop/references/loop-goal.md +0 -0
- /package/{.gemini → .agents}/skills/ai-engineering-loop/references/loop-maker.md +0 -0
- /package/{.gemini → .agents}/skills/ai-engineering-loop/references/loop-review.md +0 -0
- /package/{.gemini → .agents}/skills/ai-engineering-loop/references/loop-risky.md +0 -0
- /package/{.gemini → .agents}/skills/ai-engineering-loop/references/loop-verify.md +0 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Reviewer subagents (devil-advocate, judge) rendered per host format (#48+).
|
|
4
|
+
// One body (agents/shared/<name>.body.md) and one description per agent; each
|
|
5
|
+
// formatter only adds the host's frontmatter or wrapper, so the reviewer
|
|
6
|
+
// contract stays identical everywhere.
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
|
|
11
|
+
const AGENTS = Object.freeze(['devil-advocate', 'judge']);
|
|
12
|
+
|
|
13
|
+
function readText(file) {
|
|
14
|
+
return fs.readFileSync(file, 'utf8').replace(/\r\n?/g, '\n');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Description comes from the canonical Claude agent file so it is written once.
|
|
18
|
+
function agentSpec(root, name) {
|
|
19
|
+
if (!AGENTS.includes(name)) throw new Error(`Unknown reviewer agent "${name}"`);
|
|
20
|
+
const body = readText(path.join(root, 'agents', 'shared', `${name}.body.md`)).replace(/\s+$/, '\n');
|
|
21
|
+
const claude = readText(path.join(root, '.claude', 'agents', `${name}.md`));
|
|
22
|
+
const line = claude.split('\n').find((l) => l.startsWith('description:'));
|
|
23
|
+
if (!line) throw new Error(`.claude/agents/${name}.md has no description`);
|
|
24
|
+
return { name, description: line.slice('description:'.length).trim(), body };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function frontmatter(fields) {
|
|
28
|
+
const lines = Object.entries(fields).map(([key, value]) => {
|
|
29
|
+
if (Array.isArray(value)) return `${key}:\n${value.map((v) => ` - ${v}`).join('\n')}`;
|
|
30
|
+
return `${key}: ${value}`;
|
|
31
|
+
});
|
|
32
|
+
return `---\n${lines.join('\n')}\n---\n\n`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// TOML multi-line literal string: no escapes, so the body must not contain '''.
|
|
36
|
+
function tomlLiteral(text) {
|
|
37
|
+
if (text.includes("'''")) throw new Error("agent body must not contain ''' for codex-toml");
|
|
38
|
+
return `'''\n${text}'''`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function tomlString(text) {
|
|
42
|
+
return JSON.stringify(text);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const FORMATS = Object.freeze({
|
|
46
|
+
// Canonical files committed in the repo (their frontmatter is host-tuned).
|
|
47
|
+
// https://code.claude.com/docs/en/sub-agents
|
|
48
|
+
'claude-md': { file: (name) => `${name}.md`, src: (name) => `.claude/agents/${name}.md` },
|
|
49
|
+
// https://docs.x.ai/build/features/subagents
|
|
50
|
+
'grok-md': { file: (name) => `${name}.md`, src: (name) => `.grok/agents/${name}.md` },
|
|
51
|
+
// https://developers.openai.com/codex/subagents: name, description,
|
|
52
|
+
// developer_instructions required; reviewers run read-only.
|
|
53
|
+
'codex-toml': {
|
|
54
|
+
file: (name) => `${name}.toml`,
|
|
55
|
+
render: (spec) => [
|
|
56
|
+
`name = ${tomlString(spec.name)}`,
|
|
57
|
+
`description = ${tomlString(spec.description)}`,
|
|
58
|
+
'sandbox_mode = "read-only"',
|
|
59
|
+
`developer_instructions = ${tomlLiteral(spec.body)}`,
|
|
60
|
+
''
|
|
61
|
+
].join('\n')
|
|
62
|
+
},
|
|
63
|
+
// https://geminicli.com/docs/core/subagents/: tools omitted = inherit.
|
|
64
|
+
'gemini-md': {
|
|
65
|
+
file: (name) => `${name}.md`,
|
|
66
|
+
render: (spec) => frontmatter({ name: spec.name, description: spec.description, kind: 'local' }) + spec.body
|
|
67
|
+
},
|
|
68
|
+
// https://cursor.com/docs/subagents
|
|
69
|
+
'cursor-md': {
|
|
70
|
+
file: (name) => `${name}.md`,
|
|
71
|
+
render: (spec) => frontmatter({ name: spec.name, description: spec.description, model: 'inherit', readonly: true }) + spec.body
|
|
72
|
+
},
|
|
73
|
+
// https://opencode.ai/docs/agents/: file name is the agent name; reviewers never edit.
|
|
74
|
+
'opencode-md': {
|
|
75
|
+
file: (name) => `${name}.md`,
|
|
76
|
+
render: (spec) => `---\ndescription: ${spec.description}\nmode: subagent\npermission:\n edit: deny\n---\n\n${spec.body}`
|
|
77
|
+
},
|
|
78
|
+
// https://docs.factory.ai/harness/subagents: Task subagent_type targets.
|
|
79
|
+
'factory-md': {
|
|
80
|
+
file: (name) => `${name}.md`,
|
|
81
|
+
render: (spec) => frontmatter({ name: spec.name, description: spec.description, model: 'inherit', tools: 'read-only' }) + spec.body
|
|
82
|
+
},
|
|
83
|
+
// https://docs.augmentcode.com/cli/subagents: tools omitted = all tools.
|
|
84
|
+
'augment-md': {
|
|
85
|
+
file: (name) => `${name}.md`,
|
|
86
|
+
render: (spec) => frontmatter({ name: spec.name, description: spec.description }) + spec.body
|
|
87
|
+
},
|
|
88
|
+
// Qwen Code docs (qwenlm.github.io/qwen-code-docs, Features > Subagents): approvalMode plan = no edits.
|
|
89
|
+
'qwen-md': {
|
|
90
|
+
file: (name) => `${name}.md`,
|
|
91
|
+
render: (spec) => frontmatter({ name: spec.name, description: spec.description, model: 'inherit', approvalMode: 'plan' }) + spec.body
|
|
92
|
+
},
|
|
93
|
+
// https://kiro.dev/docs/cli/custom-agents/configuration-reference/ (Markdown agents, CLI V3 / IDE 1.0).
|
|
94
|
+
'kiro-md': {
|
|
95
|
+
file: (name) => `${name}.md`,
|
|
96
|
+
render: (spec) => frontmatter({ name: spec.name, description: spec.description, tools: ['read'] }) + spec.body
|
|
97
|
+
},
|
|
98
|
+
// https://junie.jetbrains.com/docs/junie-cli-subagents.html (tool names from the documented examples).
|
|
99
|
+
'junie-md': {
|
|
100
|
+
file: (name) => `${name}.md`,
|
|
101
|
+
render: (spec) => frontmatter({ name: spec.name, description: spec.description, tools: ['Read', 'Grep'] }) + spec.body
|
|
102
|
+
},
|
|
103
|
+
// https://docs.github.com/en/copilot/reference/custom-agents-configuration
|
|
104
|
+
'copilot-agent-md': {
|
|
105
|
+
file: (name) => `${name}.agent.md`,
|
|
106
|
+
render: (spec) => frontmatter({ name: spec.name, description: spec.description }) + spec.body
|
|
107
|
+
},
|
|
108
|
+
// https://antigravity.google/docs/subagents (tool names from the documented example only:
|
|
109
|
+
// an unknown tool name can hang the subagent).
|
|
110
|
+
'antigravity-md': {
|
|
111
|
+
file: (name) => `${name}.md`,
|
|
112
|
+
render: (spec) => frontmatter({
|
|
113
|
+
name: spec.name,
|
|
114
|
+
description: spec.description,
|
|
115
|
+
tools: ['view_file', 'grep_search', 'run_command'],
|
|
116
|
+
subagent: true,
|
|
117
|
+
mainAgent: false
|
|
118
|
+
}) + spec.body
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
function renderAgent(root, format, name) {
|
|
123
|
+
const fmt = FORMATS[format];
|
|
124
|
+
if (!fmt) throw new Error(`Unknown agent format "${format}"`);
|
|
125
|
+
if (fmt.src) return readText(path.join(root, fmt.src(name)));
|
|
126
|
+
return fmt.render(agentSpec(root, name));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function agentFileName(format, name) {
|
|
130
|
+
const fmt = FORMATS[format];
|
|
131
|
+
if (!fmt) throw new Error(`Unknown agent format "${format}"`);
|
|
132
|
+
return fmt.file(name);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
module.exports = { AGENTS, FORMATS, agentSpec, renderAgent, agentFileName };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// `setup` and `hosts list|enable|disable` (#49). Pure helpers: they compute and
|
|
4
|
+
// persist the host selection in ~/.ai-engineering-loop/config.json; the CLI
|
|
5
|
+
// then runs the normal sync (manifest-based copy and cleanup).
|
|
6
|
+
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { HOSTS, HOST_IDS, OUT_OF_SCOPE, SHARED_SKILLS_DIR, getHost, usesSharedSkills } = require('./registry.js');
|
|
9
|
+
const { detectHosts } = require('./detect.js');
|
|
10
|
+
const { readUserConfig, writeUserConfig } = require('../user-state.js');
|
|
11
|
+
|
|
12
|
+
function parseHostIds(raw) {
|
|
13
|
+
const values = (Array.isArray(raw) ? raw : String(raw || '').split(','))
|
|
14
|
+
.flatMap((value) => String(value).split(','))
|
|
15
|
+
.map((value) => value.trim().toLowerCase())
|
|
16
|
+
.filter(Boolean);
|
|
17
|
+
const unknown = values.filter((id) => !HOST_IDS.includes(id));
|
|
18
|
+
if (unknown.length) {
|
|
19
|
+
const err = new Error(`Unknown host(s): ${unknown.join(', ')}. Known: ${HOST_IDS.join(', ')}`);
|
|
20
|
+
err.code = 'UNKNOWN_HOST';
|
|
21
|
+
throw err;
|
|
22
|
+
}
|
|
23
|
+
return [...new Set(values)];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function skillLocation(host) {
|
|
27
|
+
return usesSharedSkills(host) ? `~/${SHARED_SKILLS_DIR} (shared)` : `~/${host.skills.dir}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function listHosts({ home, env = process.env, selection }) {
|
|
31
|
+
const detected = new Map(detectHosts({ home, env }).map((d) => [d.id, d]));
|
|
32
|
+
return HOSTS.map((host) => {
|
|
33
|
+
const d = detected.get(host.id);
|
|
34
|
+
return {
|
|
35
|
+
id: host.id,
|
|
36
|
+
name: host.name,
|
|
37
|
+
tier: host.tier,
|
|
38
|
+
detected: d.detected,
|
|
39
|
+
via: [...d.dirs.map((dir) => `~/${dir}`), ...d.bins.map((bin) => `PATH:${path.basename(bin)}`)],
|
|
40
|
+
enabled: selection.enabled.has(host.id),
|
|
41
|
+
disabled: selection.disabled.has(host.id),
|
|
42
|
+
skills: skillLocation(host),
|
|
43
|
+
agents: host.agents ? `~/${host.agents.dir}` : null
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function formatHostsList(rows, selection) {
|
|
49
|
+
const lines = [`Hosts (${selection.source === 'config' ? `saved selection, mode ${selection.mode}` : 'no setup yet: hosts with a config folder are synced'})`];
|
|
50
|
+
lines.push(` ${'id'.padEnd(16)} ${'enabled'.padEnd(8)} ${'detected'.padEnd(28)} skills`);
|
|
51
|
+
for (const row of rows) {
|
|
52
|
+
const state = row.enabled ? 'yes' : row.disabled ? 'off' : '-';
|
|
53
|
+
lines.push(` ${row.id.padEnd(16)} ${state.padEnd(8)} ${(row.detected ? row.via.join(',') : '-').slice(0, 28).padEnd(28)} ${row.skills}`);
|
|
54
|
+
}
|
|
55
|
+
lines.push(`Out of scope (no native skills): ${OUT_OF_SCOPE.map((h) => h.name).join(', ')}.`);
|
|
56
|
+
return lines.join('\n');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function savedHosts(home) {
|
|
60
|
+
const config = readUserConfig(home);
|
|
61
|
+
return config.hosts && typeof config.hosts === 'object' && Array.isArray(config.hosts.enabled) ? config.hosts : null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function writeHosts(home, { enabled, disabled, mode, extra = {} }) {
|
|
65
|
+
const next = {
|
|
66
|
+
...(savedHosts(home) || {}),
|
|
67
|
+
...extra,
|
|
68
|
+
enabled: HOST_IDS.filter((id) => enabled.has(id)),
|
|
69
|
+
disabled: HOST_IDS.filter((id) => disabled.has(id) && !enabled.has(id)),
|
|
70
|
+
mode: mode === 'auto' ? 'auto' : 'manual',
|
|
71
|
+
updatedAt: new Date().toISOString()
|
|
72
|
+
};
|
|
73
|
+
writeUserConfig({ hosts: next }, home);
|
|
74
|
+
return { enabled: new Set(next.enabled), disabled: new Set(next.disabled), source: 'config', mode: next.mode };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Starting point for enable/disable before any setup: whatever is synced today.
|
|
78
|
+
function changeHosts({ home, selection, enable = [], disable = [] }) {
|
|
79
|
+
const enabled = new Set(selection.enabled);
|
|
80
|
+
const disabled = new Set(selection.disabled);
|
|
81
|
+
for (const id of enable) {
|
|
82
|
+
enabled.add(id);
|
|
83
|
+
disabled.delete(id);
|
|
84
|
+
}
|
|
85
|
+
for (const id of disable) {
|
|
86
|
+
enabled.delete(id);
|
|
87
|
+
disabled.add(id);
|
|
88
|
+
}
|
|
89
|
+
return writeHosts(home, { enabled, disabled, mode: selection.mode || 'manual' });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Detection mode for agents installed later (decision 4 on #54): the
|
|
93
|
+
// interactive prompt suggests `auto` (Enter = auto); every non-interactive path
|
|
94
|
+
// (--yes, CI, scripts) stays `manual` unless --mode says otherwise.
|
|
95
|
+
const SETUP_MODE_DEFAULTS = Object.freeze({ interactive: 'auto', nonInteractive: 'manual' });
|
|
96
|
+
const SETUP_MODE_QUESTION = 'Sync agents you install later automatically? [Y/n] (recommended: Y = auto) ';
|
|
97
|
+
|
|
98
|
+
function setupMode({ modeArg = null, interactive = false, answer = '' } = {}) {
|
|
99
|
+
if (modeArg) return modeArg;
|
|
100
|
+
if (!interactive) return SETUP_MODE_DEFAULTS.nonInteractive;
|
|
101
|
+
const value = String(answer || '').trim().toLowerCase();
|
|
102
|
+
if (!value) return SETUP_MODE_DEFAULTS.interactive;
|
|
103
|
+
return ['y', 'yes', 'auto'].includes(value) ? 'auto' : 'manual';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function applySetup({ home, ids, mode }) {
|
|
107
|
+
return writeHosts(home, {
|
|
108
|
+
enabled: new Set(ids),
|
|
109
|
+
disabled: new Set(),
|
|
110
|
+
mode,
|
|
111
|
+
extra: { setupAt: new Date().toISOString() }
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
module.exports = {
|
|
116
|
+
parseHostIds,
|
|
117
|
+
listHosts,
|
|
118
|
+
formatHostsList,
|
|
119
|
+
savedHosts,
|
|
120
|
+
changeHosts,
|
|
121
|
+
applySetup,
|
|
122
|
+
setupMode,
|
|
123
|
+
SETUP_MODE_DEFAULTS,
|
|
124
|
+
SETUP_MODE_QUESTION,
|
|
125
|
+
getHost
|
|
126
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Host detection (#49): a config directory under $HOME, or an executable on
|
|
4
|
+
// PATH. PATH entries are only stat()ed; nothing is ever executed, so detection
|
|
5
|
+
// is safe to run from `status`, `--json`, and CI.
|
|
6
|
+
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const { HOSTS } = require('./registry.js');
|
|
10
|
+
|
|
11
|
+
function isExecutableFile(file, platform) {
|
|
12
|
+
try {
|
|
13
|
+
const stat = fs.statSync(file);
|
|
14
|
+
if (!stat.isFile()) return false;
|
|
15
|
+
return platform === 'win32' ? true : (stat.mode & 0o111) !== 0;
|
|
16
|
+
} catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function findOnPath(name, env = process.env, platform = process.platform) {
|
|
22
|
+
const raw = env.PATH || env.Path || '';
|
|
23
|
+
const dirs = raw.split(path.delimiter).filter(Boolean);
|
|
24
|
+
const exts = platform === 'win32'
|
|
25
|
+
? ['', ...(env.PATHEXT || '.EXE;.CMD;.BAT;.COM').split(';').filter(Boolean)]
|
|
26
|
+
: [''];
|
|
27
|
+
for (const dir of dirs) {
|
|
28
|
+
for (const ext of exts) {
|
|
29
|
+
const candidate = path.join(dir, name + ext);
|
|
30
|
+
if (isExecutableFile(candidate, platform)) return candidate;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function detectHost(host, { home, env = process.env, platform = process.platform } = {}) {
|
|
37
|
+
const dirs = host.detect.dirs.filter((rel) => {
|
|
38
|
+
try {
|
|
39
|
+
return fs.statSync(path.join(home, rel)).isDirectory();
|
|
40
|
+
} catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const bins = [];
|
|
45
|
+
for (const name of host.detect.bins || []) {
|
|
46
|
+
const found = findOnPath(name, env, platform);
|
|
47
|
+
if (found) bins.push(found);
|
|
48
|
+
}
|
|
49
|
+
return { id: host.id, detected: dirs.length > 0 || bins.length > 0, dirs, bins };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function detectHosts(options = {}) {
|
|
53
|
+
return (options.hosts || HOSTS).map((host) => detectHost(host, options));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = { findOnPath, detectHost, detectHosts };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// `hosts doctor` (#52): for every enabled host, how many copies of the core
|
|
4
|
+
// skill it can see across the folders it scans, whether they are identical,
|
|
5
|
+
// and which AEL files a sync would still write. Read-only.
|
|
6
|
+
|
|
7
|
+
const crypto = require('crypto');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const { HOSTS, usesSharedSkills } = require('./registry.js');
|
|
11
|
+
|
|
12
|
+
const CORE_SKILL = 'ai-engineering-loop';
|
|
13
|
+
|
|
14
|
+
function sha256(buf) {
|
|
15
|
+
return crypto.createHash('sha256').update(buf).digest('hex');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function realOrSelf(file) {
|
|
19
|
+
try {
|
|
20
|
+
return fs.realpathSync(file);
|
|
21
|
+
} catch {
|
|
22
|
+
return file;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function visibleCopies(host, home, skill = CORE_SKILL) {
|
|
27
|
+
const seen = new Map();
|
|
28
|
+
for (const dir of host.reads) {
|
|
29
|
+
const file = path.join(home, dir, skill, 'SKILL.md');
|
|
30
|
+
let buf;
|
|
31
|
+
try {
|
|
32
|
+
buf = fs.readFileSync(file);
|
|
33
|
+
} catch {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const real = realOrSelf(file);
|
|
37
|
+
if (!seen.has(real)) seen.set(real, { path: `~/${dir}/${skill}/SKILL.md`, sha256: sha256(buf) });
|
|
38
|
+
}
|
|
39
|
+
return [...seen.values()];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// `plan` is planHostSync(...) output; groups are host ids plus 'shared'.
|
|
43
|
+
function hostsDoctor({ home, selection, plan }) {
|
|
44
|
+
const rows = [];
|
|
45
|
+
for (const host of HOSTS) {
|
|
46
|
+
if (!selection.enabled.has(host.id)) continue;
|
|
47
|
+
const copies = visibleCopies(host, home);
|
|
48
|
+
const hashes = new Set(copies.map((c) => c.sha256));
|
|
49
|
+
const groupIds = new Set([host.id, ...(usesSharedSkills(host) ? ['shared'] : [])]);
|
|
50
|
+
const resync = plan
|
|
51
|
+
.filter((item) => groupIds.has(item.id) && item.action === 'copy')
|
|
52
|
+
.map((item) => item.dest.startsWith(home) ? `~${item.dest.slice(home.length)}` : item.dest);
|
|
53
|
+
const problems = [];
|
|
54
|
+
if (!copies.length) problems.push('core skill not installed');
|
|
55
|
+
if (hashes.size > 1) problems.push(`${copies.length} copies with different content`);
|
|
56
|
+
if (resync.length) problems.push(`${resync.length} file(s) need sync`);
|
|
57
|
+
rows.push({ id: host.id, name: host.name, copies, identical: hashes.size <= 1, resync, ok: problems.length === 0, problems });
|
|
58
|
+
}
|
|
59
|
+
return { ok: rows.every((row) => row.ok), hosts: rows };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function formatHostsDoctor(report) {
|
|
63
|
+
if (!report.hosts.length) return 'hosts doctor: no host is enabled. Run "ai-engineering-loop setup".';
|
|
64
|
+
const lines = ['hosts doctor (core skill copies each host can see):'];
|
|
65
|
+
for (const row of report.hosts) {
|
|
66
|
+
const where = row.copies.map((c) => c.path).join(', ') || '-';
|
|
67
|
+
lines.push(` ${row.ok ? '✓' : '✗'} ${row.id.padEnd(16)} ${row.copies.length} cop${row.copies.length === 1 ? 'y' : 'ies'}${row.copies.length > 1 ? (row.identical ? ' (identical)' : ' (DIFFERENT)') : ''}: ${where}`);
|
|
68
|
+
for (const problem of row.problems) lines.push(` ${problem}`);
|
|
69
|
+
for (const file of row.resync.slice(0, 5)) lines.push(` needs sync: ${file}`);
|
|
70
|
+
if (row.resync.length > 5) lines.push(` ... and ${row.resync.length - 5} more`);
|
|
71
|
+
}
|
|
72
|
+
if (!report.ok) lines.push('Fix: "ai-engineering-loop sync-hosts" (edited files are kept; remove an old copy by hand if it differs).');
|
|
73
|
+
return lines.join('\n');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = { CORE_SKILL, visibleCopies, hostsDoctor, formatHostsDoctor };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Re-detection of agents installed after `setup` (#52). Detection is stat-only
|
|
4
|
+
// (see detect.js), so this is cheap enough for `status` and `update auto`.
|
|
5
|
+
// - hosts.mode auto: `update auto` enables new hosts and syncs them.
|
|
6
|
+
// - hosts.mode manual: a short notice, once per new host, at most once a day,
|
|
7
|
+
// never in CI, JSON output, or with AEL_NO_AUTO_UPDATE.
|
|
8
|
+
|
|
9
|
+
const { HOST_IDS } = require('./registry.js');
|
|
10
|
+
const { detectHosts } = require('./detect.js');
|
|
11
|
+
const { savedHosts } = require('./commands.js');
|
|
12
|
+
const { readUserConfig, writeUserConfig, userStatePath, readJsonFile, writeJsonFile } = require('../user-state.js');
|
|
13
|
+
|
|
14
|
+
const NOTICE_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
15
|
+
const truthy = (value) => ['1', 'true', 'yes'].includes(String(value || '').trim().toLowerCase());
|
|
16
|
+
|
|
17
|
+
// Hosts detected now that the saved selection has never seen (neither enabled
|
|
18
|
+
// nor disabled). Null before `setup`: legacy mode already follows config folders.
|
|
19
|
+
function findNewHosts({ home, env = process.env }) {
|
|
20
|
+
const saved = savedHosts(home);
|
|
21
|
+
if (!saved) return null;
|
|
22
|
+
const known = new Set([...(saved.enabled || []), ...(Array.isArray(saved.disabled) ? saved.disabled : [])]);
|
|
23
|
+
return detectHosts({ home, env }).filter((d) => d.detected && !known.has(d.id)).map((d) => d.id);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function quietHere(env = process.env) {
|
|
27
|
+
return truthy(env.CI) || truthy(env.AEL_NO_AUTO_UPDATE);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Called by `update auto` (already a no-op in CI / AEL_NO_AUTO_UPDATE / policy
|
|
31
|
+
// off). Only global installs enable hosts on their own.
|
|
32
|
+
function autoEnableNewHosts({ home, env = process.env, scope }) {
|
|
33
|
+
if (quietHere(env)) return { added: [], reason: 'quiet' };
|
|
34
|
+
const saved = savedHosts(home);
|
|
35
|
+
if (!saved || saved.mode !== 'auto') return { added: [], reason: saved ? 'mode-manual' : 'no-setup' };
|
|
36
|
+
if (scope !== 'global') return { added: [], reason: 'not-global' };
|
|
37
|
+
const fresh = findNewHosts({ home, env }) || [];
|
|
38
|
+
if (!fresh.length) return { added: [] };
|
|
39
|
+
const enabled = HOST_IDS.filter((id) => saved.enabled.includes(id) || fresh.includes(id));
|
|
40
|
+
writeUserConfig({ hosts: { ...readUserConfig(home).hosts, enabled, updatedAt: new Date().toISOString() } }, home);
|
|
41
|
+
return { added: fresh };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Manual mode (or auto mode outside a syncing run): a one-line notice.
|
|
45
|
+
function newHostsNotice({ home, env = process.env, now = Date.now() }) {
|
|
46
|
+
if (quietHere(env)) return null;
|
|
47
|
+
const saved = savedHosts(home);
|
|
48
|
+
if (!saved || saved.mode === 'auto') return null;
|
|
49
|
+
const fresh = findNewHosts({ home, env }) || [];
|
|
50
|
+
const stampFile = userStatePath('hosts-notice.json', home);
|
|
51
|
+
const state = readJsonFile(stampFile, {});
|
|
52
|
+
const notified = new Set(Array.isArray(state.notified) ? state.notified : []);
|
|
53
|
+
const unseen = fresh.filter((id) => !notified.has(id));
|
|
54
|
+
if (!unseen.length) return null;
|
|
55
|
+
if (state.at && now - Date.parse(state.at) < NOTICE_INTERVAL_MS) return null;
|
|
56
|
+
writeJsonFile(stampFile, { at: new Date(now).toISOString(), notified: [...notified, ...unseen] });
|
|
57
|
+
return `ai-engineering-loop: new agent${unseen.length === 1 ? '' : 's'} detected: ${unseen.join(', ')}. Add with "ai-engineering-loop hosts enable ${unseen.join(' ')}" (or "setup --mode auto"; silence: AEL_NO_AUTO_UPDATE=1).`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = { NOTICE_INTERVAL_MS, findNewHosts, autoEnableNewHosts, newHostsNotice };
|