introsio 0.0.0-stage → 0.3.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 +62 -0
- package/LICENSE +21 -0
- package/README.md +291 -3
- package/agents/claude.mjs +80 -0
- package/agents/codex.mjs +67 -0
- package/agents/common.mjs +200 -0
- package/agents/cursor.mjs +67 -0
- package/agents/gemini.mjs +63 -0
- package/agents/index.mjs +10 -0
- package/agents/opencode.mjs +65 -0
- package/agents/vscode.mjs +47 -0
- package/agents/windsurf.mjs +32 -0
- package/cli.mjs +536 -0
- package/hook/engine.mjs +286 -0
- package/hook/features/claims.mjs +265 -0
- package/hook/features/gates.mjs +134 -0
- package/hook/features/git.mjs +243 -0
- package/hook/features/log.mjs +70 -0
- package/hook/features/notes.mjs +88 -0
- package/hook/features/pause.mjs +340 -0
- package/hook/features/stopGuard.mjs +42 -0
- package/hook/features/workerId.mjs +55 -0
- package/hook/introsio-hook.mjs +95 -0
- package/hook/normalize.mjs +171 -0
- package/hook/respond.mjs +46 -0
- package/hook/state.mjs +136 -0
- package/lib/config.mjs +64 -0
- package/lib/git.mjs +120 -0
- package/lib/jsonFile.mjs +103 -0
- package/lib/lock.mjs +182 -0
- package/lib/managedBlock.mjs +19 -0
- package/lib/paths.mjs +59 -0
- package/lib/processTree.mjs +127 -0
- package/opencode/introsio.template.js +55 -0
- package/package.json +54 -6
- package/templates/execute.md +20 -0
- package/templates/pause.md +25 -0
- package/templates/resume.md +22 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// Shared installer plumbing: a writer that can dry-run, careful JSON merging, and our hook entries.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import { readText, stripJsonComments, writeAtomic } from '../lib/jsonFile.mjs';
|
|
6
|
+
|
|
7
|
+
export const SERVER_NAME = 'introsio';
|
|
8
|
+
export const COMMAND_NAME = 'introsio-execute';
|
|
9
|
+
export const HOOK_MARK = 'introsio-hook.mjs';
|
|
10
|
+
export const DESCRIPTION = 'Execute an Introsio Developer Mode project task by task (claim → work → complete)';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The commands every agent gets. `template` is a file in templates/; `$ARGUMENTS`
|
|
14
|
+
* in it is rendered the way each agent passes what the user typed after the command.
|
|
15
|
+
*/
|
|
16
|
+
export const COMMANDS = Object.freeze([
|
|
17
|
+
{ name: COMMAND_NAME, template: 'execute.md', description: DESCRIPTION, argumentHint: '<project name or id>', inputLabel: 'Project name or id' },
|
|
18
|
+
{
|
|
19
|
+
name: 'introsio-pause',
|
|
20
|
+
template: 'pause.md',
|
|
21
|
+
description: 'Pause the Introsio task(s) you hold so they resume exactly later — note, next steps, git snapshot (out of usage, context or time)',
|
|
22
|
+
argumentHint: '[--release] [anything the next session should know]',
|
|
23
|
+
inputLabel: 'Optional: --release, and a note',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'introsio-resume',
|
|
27
|
+
template: 'resume.md',
|
|
28
|
+
description: 'Resume paused or interrupted Introsio work exactly where it stopped — after checking the repository still matches',
|
|
29
|
+
argumentHint: '[task id, or project name or id]',
|
|
30
|
+
inputLabel: 'Optional: task id or project',
|
|
31
|
+
},
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
export class Writer {
|
|
35
|
+
constructor({ dryRun = false } = {}) {
|
|
36
|
+
this.dryRun = dryRun;
|
|
37
|
+
this.actions = [];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
writeText(file, text) {
|
|
41
|
+
if (readText(file) === text) return false;
|
|
42
|
+
this.actions.push(`write ${file}`);
|
|
43
|
+
if (!this.dryRun) writeAtomic(file, text);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
writeJson(file, value) {
|
|
48
|
+
return this.writeText(file, `${JSON.stringify(value, null, 2)}\n`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
remove(file) {
|
|
52
|
+
if (!fs.existsSync(file)) return false;
|
|
53
|
+
this.actions.push(`remove ${file}`);
|
|
54
|
+
if (!this.dryRun) fs.rmSync(file, { recursive: true, force: true });
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
run(command, args) {
|
|
59
|
+
this.actions.push(`run ${command} ${args.join(' ')}`);
|
|
60
|
+
if (this.dryRun) return { ok: true, out: '' };
|
|
61
|
+
const result = spawnSync(command, args, { encoding: 'utf8', timeout: 30000, shell: process.platform === 'win32' });
|
|
62
|
+
return { ok: result.status === 0, out: `${result.stdout ?? ''}${result.stderr ?? ''}`.trim() };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** True when `command` is on PATH (never in tests — they must not touch the real tools). */
|
|
67
|
+
export function hasCli(command, env = process.env) {
|
|
68
|
+
if (env.INTROSIO_TEST_HOME) return false;
|
|
69
|
+
const result = spawnSync(command, ['--version'], { encoding: 'utf8', timeout: 10000, shell: process.platform === 'win32' });
|
|
70
|
+
return result.status === 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Merges into a JSON config. A file with comments is never rewritten (that
|
|
75
|
+
* would drop them): the caller gets `{ manual: true }` and prints a snippet.
|
|
76
|
+
*/
|
|
77
|
+
export function editJson(writer, file, mutate) {
|
|
78
|
+
const raw = readText(file);
|
|
79
|
+
let value = {};
|
|
80
|
+
if (raw !== null && raw.trim()) {
|
|
81
|
+
try {
|
|
82
|
+
value = JSON.parse(raw);
|
|
83
|
+
} catch {
|
|
84
|
+
try {
|
|
85
|
+
JSON.parse(stripJsonComments(raw));
|
|
86
|
+
return { manual: true };
|
|
87
|
+
} catch {
|
|
88
|
+
return { error: `${file} is not valid JSON — left untouched` };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const changed = mutate(value);
|
|
93
|
+
if (changed === false) return { changed: false };
|
|
94
|
+
return { changed: writer.writeJson(file, value) };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const isOurs = (entry) => JSON.stringify(entry ?? {}).includes(HOOK_MARK);
|
|
98
|
+
|
|
99
|
+
/** Claude / Codex / Gemini hook shape: { Event: [ { matcher, hooks: [ { type, command, timeout } ] } ] }. */
|
|
100
|
+
export function setMatcherHooks(root, groups) {
|
|
101
|
+
removeMatcherHooks(root);
|
|
102
|
+
root.hooks = root.hooks && typeof root.hooks === 'object' ? root.hooks : {};
|
|
103
|
+
for (const [event, entries] of Object.entries(groups)) {
|
|
104
|
+
root.hooks[event] = [...(root.hooks[event] ?? []), ...entries];
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function removeMatcherHooks(root) {
|
|
110
|
+
if (!root.hooks || typeof root.hooks !== 'object') return false;
|
|
111
|
+
let changed = false;
|
|
112
|
+
for (const [event, list] of Object.entries(root.hooks)) {
|
|
113
|
+
if (!Array.isArray(list)) continue;
|
|
114
|
+
const kept = list
|
|
115
|
+
.map((group) => (group && Array.isArray(group.hooks) ? { ...group, hooks: group.hooks.filter((hook) => !isOurs(hook)) } : group))
|
|
116
|
+
.filter((group) => !(group && Array.isArray(group.hooks) && group.hooks.length === 0) && !(group && !Array.isArray(group.hooks) && isOurs(group)));
|
|
117
|
+
if (kept.length !== list.length || JSON.stringify(kept) !== JSON.stringify(list)) changed = true;
|
|
118
|
+
if (kept.length) root.hooks[event] = kept;
|
|
119
|
+
else delete root.hooks[event];
|
|
120
|
+
}
|
|
121
|
+
if (Object.keys(root.hooks).length === 0) delete root.hooks;
|
|
122
|
+
return changed;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export const hasOurHooks = (root) => isOurs(root?.hooks);
|
|
126
|
+
|
|
127
|
+
/** Forward slashes work for Node and for every shell an agent may use on Windows. */
|
|
128
|
+
const portable = (file) => String(file).replace(/\\/g, '/');
|
|
129
|
+
const quote = (file) => `"${portable(file)}"`;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The command line an agent runs for one event. Globally it names the absolute
|
|
133
|
+
* Node binary that ran setup: GUI apps (Cursor, VS Code) often start without the
|
|
134
|
+
* shell's PATH, so a bare `node` (nvm, fnm, Homebrew) is not found there.
|
|
135
|
+
* In a project it stays `node` + a repo-relative path, since teammates differ.
|
|
136
|
+
*/
|
|
137
|
+
export function hookCommand(ctx, agent, event) {
|
|
138
|
+
const tail = `${agent}${event ? ` ${event}` : ''}`;
|
|
139
|
+
if (ctx.scope === 'project') {
|
|
140
|
+
const script = agent === 'claude' ? '"$CLAUDE_PROJECT_DIR"/.introsio/kit/hook/introsio-hook.mjs' : '.introsio/kit/hook/introsio-hook.mjs';
|
|
141
|
+
return `node ${script} ${tail}`;
|
|
142
|
+
}
|
|
143
|
+
return `${quote(ctx.nodePath ?? process.execPath)} ${quote(ctx.hookScript)} ${tail}`;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The Node binary a global hook command uses ("" when the command is not ours). */
|
|
147
|
+
export function nodePathOf(command) {
|
|
148
|
+
const match = String(command ?? '').match(/^"([^"]+)"\s+"[^"]*introsio-hook\.mjs"/);
|
|
149
|
+
return match ? match[1] : '';
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** A command's procedure, with `$ARGUMENTS` rendered the way an agent's commands expect. */
|
|
153
|
+
export function commandText(ctx, command = COMMANDS[0], argumentToken = '$ARGUMENTS') {
|
|
154
|
+
const template = ctx.templates?.[command.name] ?? (command.name === COMMAND_NAME ? ctx.executeTemplate : '');
|
|
155
|
+
return String(template ?? '').replaceAll('$ARGUMENTS', argumentToken).trim();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** The execute procedure (kept for callers that only know that one). */
|
|
159
|
+
export function executeText(ctx, argumentToken = '$ARGUMENTS') {
|
|
160
|
+
return commandText(ctx, COMMANDS[0], argumentToken);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** A Markdown command file: frontmatter, then the procedure. `argumentHint: true` adds each command's own hint. */
|
|
164
|
+
export function markdownCommand(ctx, { command = COMMANDS[0], frontmatter = {}, argumentToken, argumentHint = false } = {}) {
|
|
165
|
+
const fields = { description: command.description, ...(argumentHint ? { 'argument-hint': command.argumentHint } : {}), ...frontmatter };
|
|
166
|
+
const lines = Object.entries(fields).map(([key, value]) => `${key}: ${value}`);
|
|
167
|
+
return `---\n${lines.join('\n')}\n---\n\n${commandText(ctx, command, argumentToken)}\n`;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Writes one file per command (`fileFor(name)` → path); returns the paths. */
|
|
171
|
+
export function writeCommands(writer, fileFor, render) {
|
|
172
|
+
return COMMANDS.map((command) => {
|
|
173
|
+
const file = fileFor(command.name);
|
|
174
|
+
writer.writeText(file, render(command));
|
|
175
|
+
return file;
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function removeCommands(writer, fileFor) {
|
|
180
|
+
for (const command of COMMANDS) writer.remove(fileFor(command.name));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** "yes" when every command file is there, "partial — re-run int setup" when some are, "no" otherwise. */
|
|
184
|
+
export function commandsStatus(fileFor) {
|
|
185
|
+
const present = COMMANDS.filter((command) => fs.existsSync(fileFor(command.name))).length;
|
|
186
|
+
if (present === COMMANDS.length) return 'yes';
|
|
187
|
+
return present === 0 ? 'no' : 'partial — re-run int setup';
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function existsDir(dir) {
|
|
191
|
+
try {
|
|
192
|
+
return fs.statSync(dir).isDirectory();
|
|
193
|
+
} catch {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export const join = path.join;
|
|
199
|
+
|
|
200
|
+
export const existsFile = (file) => (fs.existsSync(file) ? 'yes' : 'no');
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Cursor: MCP in mcp.json, /introsio-execute in commands/, hooks in hooks.json (version 1 format).
|
|
2
|
+
import { join, editJson, hookCommand, markdownCommand, writeCommands, removeCommands, commandsStatus, existsDir, SERVER_NAME, COMMAND_NAME, HOOK_MARK } from './common.mjs';
|
|
3
|
+
import { readJsonSafe } from '../lib/jsonFile.mjs';
|
|
4
|
+
|
|
5
|
+
const base = (ctx) => (ctx.scope === 'project' ? join(ctx.root, '.cursor') : join(ctx.home, '.cursor'));
|
|
6
|
+
const paths = (ctx) => ({
|
|
7
|
+
mcp: join(base(ctx), 'mcp.json'),
|
|
8
|
+
hooks: join(base(ctx), 'hooks.json'),
|
|
9
|
+
command: join(base(ctx), 'commands', `${COMMAND_NAME}.md`),
|
|
10
|
+
commandFile: (name) => join(base(ctx), 'commands', `${name}.md`),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const EVENTS = ['beforeMCPExecution', 'afterMCPExecution', 'beforeShellExecution', 'afterFileEdit', 'stop'];
|
|
14
|
+
|
|
15
|
+
function removeOurs(config) {
|
|
16
|
+
if (!config.hooks) return false;
|
|
17
|
+
let changed = false;
|
|
18
|
+
for (const [event, list] of Object.entries(config.hooks)) {
|
|
19
|
+
if (!Array.isArray(list)) continue;
|
|
20
|
+
const kept = list.filter((hook) => !String(hook?.command ?? '').includes(HOOK_MARK));
|
|
21
|
+
if (kept.length !== list.length) changed = true;
|
|
22
|
+
if (kept.length) config.hooks[event] = kept;
|
|
23
|
+
else delete config.hooks[event];
|
|
24
|
+
}
|
|
25
|
+
return changed;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default {
|
|
29
|
+
id: 'cursor',
|
|
30
|
+
label: 'Cursor',
|
|
31
|
+
hooks: 'blocking (stop hook reliability varies by Cursor version)',
|
|
32
|
+
detect: (ctx) => existsDir(join(ctx.home, '.cursor')),
|
|
33
|
+
install(ctx, writer) {
|
|
34
|
+
const p = paths(ctx);
|
|
35
|
+
const report = { connect: null, command: p.command, hooks: 'blocking', next: [] };
|
|
36
|
+
const mcp = editJson(writer, p.mcp, (config) => {
|
|
37
|
+
config.mcpServers = config.mcpServers ?? {};
|
|
38
|
+
if (config.mcpServers[SERVER_NAME]?.url === ctx.url) return false;
|
|
39
|
+
config.mcpServers[SERVER_NAME] = { url: ctx.url };
|
|
40
|
+
return true;
|
|
41
|
+
});
|
|
42
|
+
report.connect = mcp.error ?? (mcp.manual ? `manual — add "${SERVER_NAME}": { "url": "${ctx.url}" } to ${p.mcp}` : mcp.changed ? 'added' : 'already connected');
|
|
43
|
+
report.next.push('In Cursor: Settings → MCP → introsio → Connect (sign in). Then in Agent chat: /introsio-execute <project>');
|
|
44
|
+
writeCommands(writer, p.commandFile, (command) => markdownCommand(ctx, { command, argumentToken: 'what the user wrote after the command' }));
|
|
45
|
+
const hooks = editJson(writer, p.hooks, (config) => {
|
|
46
|
+
config.version = config.version ?? 1;
|
|
47
|
+
config.hooks = config.hooks ?? {};
|
|
48
|
+
removeOurs(config);
|
|
49
|
+
for (const event of EVENTS) config.hooks[event] = [...(config.hooks[event] ?? []), { command: hookCommand(ctx, 'cursor', event) }];
|
|
50
|
+
return true;
|
|
51
|
+
});
|
|
52
|
+
if (hooks.manual || hooks.error) report.hooks = hooks.error ?? 'manual';
|
|
53
|
+
return report;
|
|
54
|
+
},
|
|
55
|
+
uninstall(ctx, writer) {
|
|
56
|
+
const p = paths(ctx);
|
|
57
|
+
editJson(writer, p.mcp, (config) => (config.mcpServers?.[SERVER_NAME] ? (delete config.mcpServers[SERVER_NAME], true) : false));
|
|
58
|
+
editJson(writer, p.hooks, (config) => removeOurs(config));
|
|
59
|
+
removeCommands(writer, p.commandFile);
|
|
60
|
+
},
|
|
61
|
+
status(ctx) {
|
|
62
|
+
const p = paths(ctx);
|
|
63
|
+
const hooks = JSON.stringify(readJsonSafe(p.hooks, {}));
|
|
64
|
+
return { connect: readJsonSafe(p.mcp, {}).mcpServers?.[SERVER_NAME] ? 'yes' : 'no', command: commandsStatus(p.commandFile), hooks: hooks.includes(HOOK_MARK) ? 'blocking' : 'not installed' };
|
|
65
|
+
},
|
|
66
|
+
print: (ctx) => ({ version: 1, hooks: Object.fromEntries(EVENTS.map((event) => [event, [{ command: hookCommand(ctx, 'cursor', event) }]])) }),
|
|
67
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Gemini CLI: MCP + hooks in settings.json, /introsio-execute as a TOML command.
|
|
2
|
+
import { join, editJson, setMatcherHooks, removeMatcherHooks, hasOurHooks, hookCommand, commandText, writeCommands, removeCommands, commandsStatus, existsDir, hasCli, SERVER_NAME, COMMAND_NAME } from './common.mjs';
|
|
3
|
+
import { readJsonSafe } from '../lib/jsonFile.mjs';
|
|
4
|
+
|
|
5
|
+
const base = (ctx) => (ctx.scope === 'project' ? join(ctx.root, '.gemini') : join(ctx.home, '.gemini'));
|
|
6
|
+
const paths = (ctx) => ({
|
|
7
|
+
settings: join(base(ctx), 'settings.json'),
|
|
8
|
+
command: join(base(ctx), 'commands', `${COMMAND_NAME}.toml`),
|
|
9
|
+
commandFile: (name) => join(base(ctx), 'commands', `${name}.toml`),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
function hookGroups(ctx) {
|
|
13
|
+
// Gemini timeouts are milliseconds.
|
|
14
|
+
const cmd = (event, timeout) => ({ name: 'introsio', type: 'command', command: hookCommand(ctx, 'gemini', event), timeout });
|
|
15
|
+
return {
|
|
16
|
+
SessionStart: [{ matcher: '*', hooks: [cmd('SessionStart', 10_000)] }],
|
|
17
|
+
BeforeTool: [{ matcher: '.*', hooks: [cmd('BeforeTool', 900_000)] }],
|
|
18
|
+
AfterTool: [{ matcher: '.*', hooks: [cmd('AfterTool', 15_000)] }],
|
|
19
|
+
PreCompress: [{ matcher: '*', hooks: [cmd('PreCompress', 10_000)] }],
|
|
20
|
+
AfterAgent: [{ matcher: '*', hooks: [cmd('AfterAgent', 15_000)] }],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const tomlString = (text) => `"""\n${text.replaceAll('\\', '\\\\').replaceAll('"""', '\\"\\"\\"')}\n"""`;
|
|
25
|
+
|
|
26
|
+
export default {
|
|
27
|
+
id: 'gemini',
|
|
28
|
+
label: 'Gemini CLI',
|
|
29
|
+
hooks: 'blocking',
|
|
30
|
+
detect: (ctx) => existsDir(join(ctx.home, '.gemini')) || hasCli('gemini', ctx.env),
|
|
31
|
+
install(ctx, writer) {
|
|
32
|
+
const p = paths(ctx);
|
|
33
|
+
const report = { connect: null, command: p.command, hooks: 'blocking', next: [] };
|
|
34
|
+
const result = editJson(writer, p.settings, (settings) => {
|
|
35
|
+
settings.mcpServers = settings.mcpServers ?? {};
|
|
36
|
+
const before = JSON.stringify(settings);
|
|
37
|
+
if (!settings.mcpServers[SERVER_NAME]) settings.mcpServers[SERVER_NAME] = { httpUrl: ctx.url };
|
|
38
|
+
else settings.mcpServers[SERVER_NAME].httpUrl = ctx.url;
|
|
39
|
+
setMatcherHooks(settings, hookGroups(ctx));
|
|
40
|
+
return JSON.stringify(settings) !== before;
|
|
41
|
+
});
|
|
42
|
+
report.connect = result.error ?? (result.manual ? `manual — ${p.settings} has comments; add mcpServers.${SERVER_NAME} = { "httpUrl": "${ctx.url}" }` : 'added');
|
|
43
|
+
if (result.manual || result.error) report.hooks = 'manual';
|
|
44
|
+
report.next.push(`In Gemini CLI run /mcp auth ${SERVER_NAME} to sign in. Then: /${COMMAND_NAME} <project>`);
|
|
45
|
+
writeCommands(writer, p.commandFile, (command) => `description = ${JSON.stringify(command.description)}\nprompt = ${tomlString(commandText(ctx, command, '{{args}}'))}\n`);
|
|
46
|
+
return report;
|
|
47
|
+
},
|
|
48
|
+
uninstall(ctx, writer) {
|
|
49
|
+
const p = paths(ctx);
|
|
50
|
+
editJson(writer, p.settings, (settings) => {
|
|
51
|
+
const had = !!settings.mcpServers?.[SERVER_NAME];
|
|
52
|
+
if (had) delete settings.mcpServers[SERVER_NAME];
|
|
53
|
+
return removeMatcherHooks(settings) || had;
|
|
54
|
+
});
|
|
55
|
+
removeCommands(writer, p.commandFile);
|
|
56
|
+
},
|
|
57
|
+
status(ctx) {
|
|
58
|
+
const p = paths(ctx);
|
|
59
|
+
const settings = readJsonSafe(p.settings, {});
|
|
60
|
+
return { connect: settings.mcpServers?.[SERVER_NAME] ? 'yes' : 'no', command: commandsStatus(p.commandFile), hooks: hasOurHooks(settings) ? 'blocking' : 'not installed' };
|
|
61
|
+
},
|
|
62
|
+
print: (ctx) => ({ hooks: hookGroups(ctx) }),
|
|
63
|
+
};
|
package/agents/index.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import claude from './claude.mjs';
|
|
2
|
+
import codex from './codex.mjs';
|
|
3
|
+
import gemini from './gemini.mjs';
|
|
4
|
+
import cursor from './cursor.mjs';
|
|
5
|
+
import opencode from './opencode.mjs';
|
|
6
|
+
import vscode from './vscode.mjs';
|
|
7
|
+
import windsurf from './windsurf.mjs';
|
|
8
|
+
|
|
9
|
+
export const AGENTS = [claude, codex, gemini, cursor, opencode, vscode, windsurf];
|
|
10
|
+
export const agentById = (id) => AGENTS.find((agent) => agent.id === id);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// OpenCode: MCP in opencode.json, /introsio-execute in commands/, and a plugin (OpenCode has no shell hooks).
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import { join, editJson, markdownCommand, writeCommands, removeCommands, commandsStatus, existsDir, existsFile, hasCli, SERVER_NAME, COMMAND_NAME } from './common.mjs';
|
|
5
|
+
import { readJsonSafe, readText } from '../lib/jsonFile.mjs';
|
|
6
|
+
import { xdgConfigHome } from '../lib/paths.mjs';
|
|
7
|
+
|
|
8
|
+
const paths = (ctx) => {
|
|
9
|
+
const base = ctx.scope === 'project' ? join(ctx.root, '.opencode') : join(xdgConfigHome(ctx.env), 'opencode');
|
|
10
|
+
return {
|
|
11
|
+
config: ctx.scope === 'project' ? join(ctx.root, 'opencode.json') : join(base, 'opencode.json'),
|
|
12
|
+
command: join(base, 'commands', `${COMMAND_NAME}.md`),
|
|
13
|
+
commandFile: (name) => join(base, 'commands', `${name}.md`),
|
|
14
|
+
plugin: join(base, 'plugins', 'introsio.js'),
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function pluginSource(ctx, pluginFile) {
|
|
19
|
+
const template = readText(join(ctx.kitSource, 'opencode', 'introsio.template.js'));
|
|
20
|
+
const target = (file) => {
|
|
21
|
+
const absolute = join(ctx.kitInstallDir, 'hook', file);
|
|
22
|
+
if (ctx.scope !== 'project') return pathToFileURL(absolute).href;
|
|
23
|
+
const relative = path.relative(path.dirname(pluginFile), absolute).split(path.sep).join('/');
|
|
24
|
+
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
25
|
+
};
|
|
26
|
+
return template.replace('__ENGINE__', target('engine.mjs')).replace('__NORMALIZE__', target('normalize.mjs'));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default {
|
|
30
|
+
id: 'opencode',
|
|
31
|
+
label: 'OpenCode',
|
|
32
|
+
hooks: 'blocking (plugin)',
|
|
33
|
+
detect: (ctx) => existsDir(join(xdgConfigHome(ctx.env), 'opencode')) || hasCli('opencode', ctx.env),
|
|
34
|
+
install(ctx, writer) {
|
|
35
|
+
const p = paths(ctx);
|
|
36
|
+
const report = { connect: null, command: p.command, hooks: 'blocking (plugin)', next: [] };
|
|
37
|
+
const config = editJson(writer, p.config, (value) => {
|
|
38
|
+
value.$schema = value.$schema ?? 'https://opencode.ai/config.json';
|
|
39
|
+
value.mcp = value.mcp ?? {};
|
|
40
|
+
const next = { type: 'remote', url: ctx.url, enabled: true };
|
|
41
|
+
if (JSON.stringify(value.mcp[SERVER_NAME]) === JSON.stringify(next)) return false;
|
|
42
|
+
value.mcp[SERVER_NAME] = next;
|
|
43
|
+
return true;
|
|
44
|
+
});
|
|
45
|
+
report.connect = config.error ?? (config.manual ? `manual — add "mcp": { "${SERVER_NAME}": { "type": "remote", "url": "${ctx.url}" } } to ${p.config}` : config.changed ? 'added' : 'already connected');
|
|
46
|
+
report.next.push(`Sign in: opencode mcp auth ${SERVER_NAME}. Then in OpenCode: /${COMMAND_NAME} <project>`);
|
|
47
|
+
writeCommands(writer, p.commandFile, (command) => markdownCommand(ctx, { command }));
|
|
48
|
+
writer.writeText(p.plugin, pluginSource(ctx, p.plugin));
|
|
49
|
+
return report;
|
|
50
|
+
},
|
|
51
|
+
uninstall(ctx, writer) {
|
|
52
|
+
const p = paths(ctx);
|
|
53
|
+
editJson(writer, p.config, (value) => (value.mcp?.[SERVER_NAME] ? (delete value.mcp[SERVER_NAME], true) : false));
|
|
54
|
+
removeCommands(writer, p.commandFile);
|
|
55
|
+
writer.remove(p.plugin);
|
|
56
|
+
},
|
|
57
|
+
status(ctx) {
|
|
58
|
+
const p = paths(ctx);
|
|
59
|
+
return {
|
|
60
|
+
connect: readJsonSafe(p.config, {}).mcp?.[SERVER_NAME] ? 'yes' : 'no',
|
|
61
|
+
command: commandsStatus(p.commandFile),
|
|
62
|
+
hooks: existsFile(p.plugin) === 'yes' ? 'blocking (plugin)' : 'not installed',
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// VS Code (GitHub Copilot agent mode): MCP in the user mcp.json and a /introsio-execute prompt file. No hooks.
|
|
2
|
+
import { join, editJson, commandText, writeCommands, removeCommands, commandsStatus, existsDir, SERVER_NAME, COMMAND_NAME } from './common.mjs';
|
|
3
|
+
import { readJsonSafe } from '../lib/jsonFile.mjs';
|
|
4
|
+
|
|
5
|
+
function userDir(ctx) {
|
|
6
|
+
const platform = ctx.platform ?? process.platform;
|
|
7
|
+
if (platform === 'darwin') return join(ctx.home, 'Library', 'Application Support', 'Code', 'User');
|
|
8
|
+
if (platform === 'win32') return join(ctx.env.APPDATA && !ctx.env.INTROSIO_TEST_HOME ? ctx.env.APPDATA : join(ctx.home, 'AppData', 'Roaming'), 'Code', 'User');
|
|
9
|
+
return join(ctx.home, '.config', 'Code', 'User');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const paths = (ctx) => {
|
|
13
|
+
const prompts = ctx.scope === 'project' ? join(ctx.root, '.github', 'prompts') : join(userDir(ctx), 'prompts');
|
|
14
|
+
const commandFile = (name) => join(prompts, `${name}.prompt.md`);
|
|
15
|
+
return { mcp: ctx.scope === 'project' ? join(ctx.root, '.vscode', 'mcp.json') : join(userDir(ctx), 'mcp.json'), command: commandFile(COMMAND_NAME), commandFile };
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
id: 'vscode',
|
|
20
|
+
label: 'VS Code (Copilot)',
|
|
21
|
+
hooks: 'none — the server still resumes abandoned claims',
|
|
22
|
+
detect: (ctx) => existsDir(userDir(ctx)),
|
|
23
|
+
install(ctx, writer) {
|
|
24
|
+
const p = paths(ctx);
|
|
25
|
+
const report = { connect: null, command: p.command, hooks: 'none', next: [] };
|
|
26
|
+
const mcp = editJson(writer, p.mcp, (config) => {
|
|
27
|
+
config.servers = config.servers ?? {};
|
|
28
|
+
const next = { type: 'http', url: ctx.url };
|
|
29
|
+
if (JSON.stringify(config.servers[SERVER_NAME]) === JSON.stringify(next)) return false;
|
|
30
|
+
config.servers[SERVER_NAME] = next;
|
|
31
|
+
return true;
|
|
32
|
+
});
|
|
33
|
+
report.connect = mcp.error ?? (mcp.manual ? `manual — add "${SERVER_NAME}": { "type": "http", "url": "${ctx.url}" } under "servers" in ${p.mcp}` : mcp.changed ? 'added' : 'already connected');
|
|
34
|
+
report.next.push('In VS Code: open mcp.json and click Start above "introsio" to sign in. Then in Copilot Chat (Agent mode): /introsio-execute <project>');
|
|
35
|
+
writeCommands(writer, p.commandFile, (command) => `---\nmode: agent\ndescription: ${command.description}\n---\n\n${commandText(ctx, command, `\${input:args:${command.inputLabel}}`)}\n`);
|
|
36
|
+
return report;
|
|
37
|
+
},
|
|
38
|
+
uninstall(ctx, writer) {
|
|
39
|
+
const p = paths(ctx);
|
|
40
|
+
editJson(writer, p.mcp, (config) => (config.servers?.[SERVER_NAME] ? (delete config.servers[SERVER_NAME], true) : false));
|
|
41
|
+
removeCommands(writer, p.commandFile);
|
|
42
|
+
},
|
|
43
|
+
status(ctx) {
|
|
44
|
+
const p = paths(ctx);
|
|
45
|
+
return { connect: readJsonSafe(p.mcp, {}).servers?.[SERVER_NAME] ? 'yes' : 'no', command: commandsStatus(p.commandFile), hooks: 'none' };
|
|
46
|
+
},
|
|
47
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Windsurf: MCP in mcp_config.json. No global commands or hooks — setup prints the procedure to paste as a rule.
|
|
2
|
+
import { join, editJson, existsDir, SERVER_NAME } from './common.mjs';
|
|
3
|
+
import { readJsonSafe } from '../lib/jsonFile.mjs';
|
|
4
|
+
|
|
5
|
+
const configFile = (ctx) => join(ctx.home, '.codeium', 'windsurf', 'mcp_config.json');
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
id: 'windsurf',
|
|
9
|
+
label: 'Windsurf',
|
|
10
|
+
hooks: 'none — the server still resumes abandoned claims',
|
|
11
|
+
userOnly: true,
|
|
12
|
+
detect: (ctx) => existsDir(join(ctx.home, '.codeium', 'windsurf')),
|
|
13
|
+
install(ctx, writer) {
|
|
14
|
+
const file = configFile(ctx);
|
|
15
|
+
const report = { connect: null, command: null, hooks: 'none', next: [] };
|
|
16
|
+
const mcp = editJson(writer, file, (config) => {
|
|
17
|
+
config.mcpServers = config.mcpServers ?? {};
|
|
18
|
+
if (config.mcpServers[SERVER_NAME]?.serverUrl === ctx.url) return false;
|
|
19
|
+
config.mcpServers[SERVER_NAME] = { serverUrl: ctx.url };
|
|
20
|
+
return true;
|
|
21
|
+
});
|
|
22
|
+
report.connect = mcp.error ?? (mcp.manual ? `manual — add "${SERVER_NAME}": { "serverUrl": "${ctx.url}" } to ${file}` : mcp.changed ? 'added' : 'already connected');
|
|
23
|
+
report.next.push('In Windsurf: Cascade → MCP servers → refresh, sign in to introsio. For the procedures run `int print-execute`, `int print-pause` and `int print-resume` and save each as a Windsurf workflow.');
|
|
24
|
+
return report;
|
|
25
|
+
},
|
|
26
|
+
uninstall(ctx, writer) {
|
|
27
|
+
editJson(writer, configFile(ctx), (config) => (config.mcpServers?.[SERVER_NAME] ? (delete config.mcpServers[SERVER_NAME], true) : false));
|
|
28
|
+
},
|
|
29
|
+
status(ctx) {
|
|
30
|
+
return { connect: readJsonSafe(configFile(ctx), {}).mcpServers?.[SERVER_NAME] ? 'yes' : 'no', command: 'n/a', hooks: 'none' };
|
|
31
|
+
},
|
|
32
|
+
};
|