introsio 0.0.0-stage → 0.1.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 +15 -0
- package/LICENSE +21 -0
- package/README.md +196 -3
- package/agents/claude.mjs +73 -0
- package/agents/codex.mjs +66 -0
- package/agents/common.mjs +150 -0
- package/agents/cursor.mjs +62 -0
- package/agents/gemini.mjs +59 -0
- package/agents/index.mjs +10 -0
- package/agents/opencode.mjs +64 -0
- package/agents/vscode.mjs +45 -0
- package/agents/windsurf.mjs +32 -0
- package/cli.mjs +452 -0
- package/hook/engine.mjs +213 -0
- package/hook/features/claims.mjs +232 -0
- package/hook/features/gates.mjs +134 -0
- package/hook/features/git.mjs +203 -0
- package/hook/features/log.mjs +70 -0
- package/hook/features/notes.mjs +86 -0
- package/hook/features/stopGuard.mjs +41 -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 +87 -0
- package/lib/config.mjs +63 -0
- package/lib/git.mjs +42 -0
- package/lib/jsonFile.mjs +76 -0
- package/lib/lock.mjs +51 -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 +55 -6
- package/templates/execute.md +14 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `introsio` (the `int` CLI) are recorded here.
|
|
4
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/) and the
|
|
5
|
+
project uses [semantic versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- MIT license (`LICENSE`), `author`, and this changelog.
|
|
11
|
+
|
|
12
|
+
## [0.2.0]
|
|
13
|
+
|
|
14
|
+
- Global setup for Claude Code, Codex, Gemini CLI, Cursor, OpenCode, VS Code
|
|
15
|
+
and Windsurf; `/introsio-execute`; stop-guard and related hooks; `int stats`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mahesh Rasapalli
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,196 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# int — connect any coding agent to Introsio
|
|
2
|
+
|
|
3
|
+
One command connects your coding agents to Introsio, gives them a
|
|
4
|
+
`/introsio-execute` command for running a Developer Mode project, and installs
|
|
5
|
+
hooks that keep Introsio in step with what the agent actually did.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Needs Node 18 or newer and one or more coding agents.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npx introsio setup # try it once, nothing stays installed
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g introsio # keeps the `int` command (`introsio` works too)
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
int setup # connect your agents, once per computer
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
From a clone of this repository, before the package is published:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
node agent-kit/cli.mjs setup
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`setup` finds the agents on this computer, or takes `--agents claude,codex,…`. It
|
|
30
|
+
installs **globally**, so it works in every repository you open, and copies the
|
|
31
|
+
hook engine to `~/.introsio/kit`, so the hooks never depend on this checkout.
|
|
32
|
+
|
|
33
|
+
| Agent | Connect (MCP) | `/introsio-execute` | Hooks |
|
|
34
|
+
|---|---|---|---|
|
|
35
|
+
| Claude Code | `claude mcp add` (user scope) | `~/.claude/commands/` | blocking |
|
|
36
|
+
| Codex | `~/.codex/config.toml` | `/prompts:introsio-execute` | blocking |
|
|
37
|
+
| Gemini CLI | `~/.gemini/settings.json` | `~/.gemini/commands/` | blocking |
|
|
38
|
+
| Cursor | `~/.cursor/mcp.json` | `~/.cursor/commands/` | blocking (stop-hook reliability varies by Cursor version) |
|
|
39
|
+
| OpenCode | `opencode.json` | `commands/` | blocking (a plugin) |
|
|
40
|
+
| VS Code (Copilot) | user `mcp.json` | prompt file | none |
|
|
41
|
+
| Windsurf | `mcp_config.json` | `int print-execute` → paste as a rule | none |
|
|
42
|
+
|
|
43
|
+
**Signing in.** No key is stored anywhere. Each agent signs in through its own MCP
|
|
44
|
+
OAuth flow (Introsio supports dynamic client registration and PKCE). `setup` tells
|
|
45
|
+
you the exact step for each agent, for example `/mcp` in Claude Code or
|
|
46
|
+
`codex mcp login introsio`.
|
|
47
|
+
|
|
48
|
+
## How it works
|
|
49
|
+
|
|
50
|
+
The agent runs a project with the server's loop: `claimTask` → work → `completeTask`
|
|
51
|
+
with an outcome (ADR-0008). The hooks never call Introsio themselves; they have no
|
|
52
|
+
credential. They watch the agent's own Introsio calls and make sure it finishes
|
|
53
|
+
the loop.
|
|
54
|
+
|
|
55
|
+
- **After each Introsio call**, the hook records what the session holds: a
|
|
56
|
+
successful `claimTask` opens a task, a successful `completeTask` (or `updateTask`
|
|
57
|
+
to blocked/pending) closes it, and a refused call changes nothing. State lives
|
|
58
|
+
in `~/.introsio/sessions/<session>.json`, one file per session, so parallel
|
|
59
|
+
agents never collide.
|
|
60
|
+
- **When the agent tries to stop** with a task still open, it is sent back once,
|
|
61
|
+
with the exact call to make — and told to follow what the user asked first: if
|
|
62
|
+
the user only wanted the task claimed or asked to pause, it releases it instead
|
|
63
|
+
of doing the work. Stopping again with the same tasks open is taken as a
|
|
64
|
+
decision: it is let go with a visible warning and not asked again. Agents whose
|
|
65
|
+
hooks don't see MCP calls have the open set rebuilt from the transcript, read
|
|
66
|
+
incrementally.
|
|
67
|
+
- A hook costs **no tokens** unless it prints. The engine decides in under a
|
|
68
|
+
millisecond; one hook process, including Node start-up, takes about 50 ms.
|
|
69
|
+
`INTROSIO_HOOKS=off` turns every hook off for a session.
|
|
70
|
+
|
|
71
|
+
The hooks also include the following checks. Each one can be switched off
|
|
72
|
+
(`int disable <name>`).
|
|
73
|
+
|
|
74
|
+
| Feature | What it does |
|
|
75
|
+
|---|---|
|
|
76
|
+
| `stop-guard` | No finishing while a claimed task is open |
|
|
77
|
+
| `test-gate` | `completeTask` waits for the repo's check command (`int gate set "npm test"`). Passes are cached per work tree, and a failure sends the last 40 lines back |
|
|
78
|
+
| `shipped-gate` | **local** mode: work must be committed. **github** mode: committed, pushed, off the default branch, `outcome.branch` recorded |
|
|
79
|
+
| `push-guard` | No push to the default branch, no force push, no mirror; in local mode, no push at all |
|
|
80
|
+
| `secrets` | Commits and pushes adding keys, private keys or `.env` files are refused, naming the file:line, never the value |
|
|
81
|
+
| `scope` | One soft note per file edited outside the files the task names |
|
|
82
|
+
| `worker-id` | Refuses a claim with another live session's workerId, and a second claim without one |
|
|
83
|
+
| `compact-recovery` | After context compaction: the task, workerId, subtask progress and context revision |
|
|
84
|
+
| `lease` | One reminder when a claim is 60% through its lease with no progress reported |
|
|
85
|
+
| `reread` | Refuses once a context read the agent already has, or a schedule read straight after `nowReady` |
|
|
86
|
+
| `log` | `~/.introsio/log.jsonl`, summed up by `int stats` |
|
|
87
|
+
|
|
88
|
+
The gates and git guards only act in sessions that have used Introsio, and only
|
|
89
|
+
on tasks that session claimed. Completing a personal task, or pushing in a repo
|
|
90
|
+
that has nothing to do with Introsio, is never touched.
|
|
91
|
+
|
|
92
|
+
### Modes: keep the code on this computer, or ship it to GitHub
|
|
93
|
+
|
|
94
|
+
| Mode | Before a task can be Done | `git push` |
|
|
95
|
+
|---|---|---|
|
|
96
|
+
| `github` (auto when the Introsio project is linked to a GitHub repository) | committed, pushed on its own branch, `outcome.branch` recorded | allowed, except to the default branch or forced |
|
|
97
|
+
| `local` (auto otherwise) | committed | blocked |
|
|
98
|
+
| `off` | no check | no check |
|
|
99
|
+
|
|
100
|
+
Set a mode per repository with `int mode local`, `int mode github`,
|
|
101
|
+
`int mode off` or `int mode auto`.
|
|
102
|
+
|
|
103
|
+
## Edge cases (researched, reproduced, fixed)
|
|
104
|
+
|
|
105
|
+
Each of these was first reproduced against the earlier kit, then fixed, and is kept
|
|
106
|
+
as a regression test in `test/edgecases.test.js` (same numbers).
|
|
107
|
+
|
|
108
|
+
| # | What broke | What the kit does now |
|
|
109
|
+
|---|---|---|
|
|
110
|
+
| R1 | Agents run the hooks of parallel tool calls at the same time; concurrent writes lost claims (10 of 12 kept) | Every session update runs under a per-session lock (`lib/lock.mjs`, stale locks taken over after 10 s, fail-open after 4 s) |
|
|
111
|
+
| R2 | A timed-out test gate left its child processes (test workers) running | The gate runs in its own process group; on timeout, on exit, or if the agent kills the hook, the whole group is killed (`lib/processTree.mjs`) |
|
|
112
|
+
| R3 | A diff over 16 MB made the gate cache blind to changes, so stale passes were reused | The cache key is the `git stash create` tree id plus every untracked file's size/mtime; an unreadable tree is never cached |
|
|
113
|
+
| R4 | A bare `git push` from a branch whose upstream is main went through | A bare push is checked against `@{push}` (honours `push.default`) |
|
|
114
|
+
| R5 | The person's own uncommitted files blocked the agent's completion forever | Only the task's files are checked (edited this session ∪ `outcome.files`); with none known, the refusal says to list them |
|
|
115
|
+
| R6 | A Claude subagent's stop was blocked by its parent's claim | `SubagentStop` is not hooked |
|
|
116
|
+
| R7 | A claim on a deleted task re-blocked every later stop | A 404 drops the claim; a set that was let go never re-blocks |
|
|
117
|
+
| R8 | Payloads without a session id all shared one "unknown" session | The agent process id becomes the session key |
|
|
118
|
+
| R9 | A crashed session's workerId was refused after a restart | A clash counts only if the other agent process is alive (or, without a pid, heard from in the last 10 min) |
|
|
119
|
+
| R10 | A failing gate printing one huge line flooded the context | Output tail: 40 lines × 300 chars, 3000 in all; every message at most 6000 chars |
|
|
120
|
+
| R11 | AWS's documented example key (in tests everywhere) blocked commits | Lines with `EXAMPLE`, `int:allow-secret`, `pragma: allowlist secret`, `gitleaks:allow` or `nosec` are skipped |
|
|
121
|
+
| R12 | GUI apps (Cursor, VS Code) start without the shell's PATH, so `node` (nvm, fnm, Homebrew) wasn't found | Global hooks name the absolute Node that ran `int setup`; `int doctor` warns when it disappears |
|
|
122
|
+
| R13 | Windows paths were written with doubled backslashes | Paths in commands use forward slashes |
|
|
123
|
+
| R14 | A gate timeout above the agents' 900 s hook timeout was accepted, so the agent cut the hook off and the completion went through unchecked | At most 840 s, enforced by the CLI and the engine |
|
|
124
|
+
| R15 | Codex Stop got empty stdout where Codex expects JSON | Codex always gets JSON (`{}` when there's nothing to say) |
|
|
125
|
+
| R16 | A task another worker took over still held this session | A 409 naming another worker drops the claim and tells the agent |
|
|
126
|
+
| R17 | The guard made the agent do work the user had said not to do (found in a real Claude Code run) | The message puts the user's instruction first and offers release (`statusState: "pending"`); one reminder only |
|
|
127
|
+
| R18 | An agent that keeps stdin open hung the hook | The payload is read until it parses (2 s idle, 10 s cap) |
|
|
128
|
+
| R19 | A long Codex transcript was re-parsed on every stop (85 MB: ~300 ms each) | Read incrementally from a saved offset (~50 ms after the first) |
|
|
129
|
+
| R20 | The re-read guard refused context to a subagent that never had it | The refusal says to call again; the second identical call goes through |
|
|
130
|
+
| R21 | A parallel worker without a workerId was told to reuse its parent's | It is told to pick its own (`<id>-2`) |
|
|
131
|
+
| R22 | A hand-broken settings file was silently replaced by the next command | Commands refuse to write a settings file they cannot read; hooks keep running on defaults |
|
|
132
|
+
| R23 | Internal hook errors vanished | They go to `~/.introsio/errors.log` (1 MB, rotated); `int doctor` shows recent ones; the agent still gets valid output |
|
|
133
|
+
| R24 | On Windows, git (`C:/…`), Node (`C:\…`) and temp folders (`MAHESH~1`) spell one folder three ways, so `int mode` / `int gate` settings were never found by the hooks and edited files looked "outside" the repo (found on the first Windows run) | One canonical spelling (`canonicalPath` / `repoKey` in `lib/paths.mjs`, case-insensitive on Windows) for every settings key and file comparison; CI now runs on Windows, macOS and Linux |
|
|
134
|
+
|
|
135
|
+
Tested end to end with Claude Code 2.1.312 (headless `claude -p`, a stub Introsio
|
|
136
|
+
MCP server over stdio, the installed hooks):
|
|
137
|
+
- a claim is recorded from Claude's real payload, and the stop is refused until `completeTask`;
|
|
138
|
+
- "only claim it" leaves the work undone, and the agent stops after one reminder;
|
|
139
|
+
- a failing gate refuses the first `completeTask` in PreToolUse; the agent reads the
|
|
140
|
+
failure, fixes it, commits locally (local mode: no push) and completes.
|
|
141
|
+
|
|
142
|
+
## Commands
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
int setup [--agents a,b] [--project <repo>] [--url <mcp url>] [--dry-run]
|
|
146
|
+
int uninstall [--agents a,b] [--project <repo>]
|
|
147
|
+
int status | doctor
|
|
148
|
+
int mode github|local|off|auto
|
|
149
|
+
int gate set "<cmd>" [--timeout <sec>] | gate off | gate run | gate
|
|
150
|
+
int features | enable <name> | disable <name>
|
|
151
|
+
int claims | claims clear
|
|
152
|
+
int stats [--since 7d] [--project <id>] [--json]
|
|
153
|
+
int print-execute
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
- `--project <repo>` installs into one repository instead (committed, so a team
|
|
157
|
+
shares it). The kit is copied to `<repo>/.introsio/kit` and the configs use
|
|
158
|
+
repo-relative paths.
|
|
159
|
+
- `--url` points the agents at another MCP server, such as a local backend; it is
|
|
160
|
+
remembered.
|
|
161
|
+
- A config file with comments is never rewritten. `setup` prints what to add to it.
|
|
162
|
+
- `uninstall` removes only what `setup` added.
|
|
163
|
+
|
|
164
|
+
## Layout
|
|
165
|
+
|
|
166
|
+
- `cli.mjs` — the `int` command
|
|
167
|
+
- `agents/<agent>.mjs` — one adapter per agent: detect, connect, command, hooks, uninstall, status
|
|
168
|
+
- `hook/introsio-hook.mjs` → `normalize.mjs` (each agent's payload into one shape) → `engine.mjs` (the decisions) → `respond.mjs` (each agent's output format)
|
|
169
|
+
- `hook/features/*.mjs` — one pure module per feature
|
|
170
|
+
- `opencode/introsio.template.js` — the OpenCode plugin (it imports the same engine)
|
|
171
|
+
- `templates/execute.md` — the `/introsio-execute` procedure, rendered into each agent's command format
|
|
172
|
+
|
|
173
|
+
Tests: `npm run test:agent-kit` from the repo root. They use plain
|
|
174
|
+
`node:assert/strict`, a scratch HOME and real git repositories.
|
|
175
|
+
|
|
176
|
+
Hook formats follow each agent's documentation as of October 2026. Agents change
|
|
177
|
+
these often: run `int doctor` after updating an agent.
|
|
178
|
+
|
|
179
|
+
## Publishing a release (maintainers)
|
|
180
|
+
|
|
181
|
+
The package is `introsio` on npm (commands `int` and `introsio`).
|
|
182
|
+
|
|
183
|
+
1. Bump `version` in `package.json` (`int doctor` tells users on older hooks to re-run `int setup`), and merge.
|
|
184
|
+
2. Add the repository secret `NPM_TOKEN` once (an npm Automation token that may publish `introsio`).
|
|
185
|
+
3. Tag the release; `.github/workflows/agent-kit-release.yml` runs the tests, checks the tag against the version, and publishes with provenance:
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
git tag agent-kit-v0.2.0 && git push origin agent-kit-v0.2.0
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
To publish by hand instead: `npm login`, then `npm publish` from this folder (the tests run first via `prepublishOnly`).
|
|
192
|
+
|
|
193
|
+
## License
|
|
194
|
+
|
|
195
|
+
[MIT](./LICENSE) © Mahesh Rasapalli. This license covers the `int` CLI in
|
|
196
|
+
`agent-kit/` only; the Introsio service it connects to is a separate product.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Claude Code: MCP via `claude mcp add` (or ~/.claude.json / .mcp.json), /introsio-execute as a command, hooks in settings.json.
|
|
2
|
+
import { join, editJson, setMatcherHooks, removeMatcherHooks, hasOurHooks, hookCommand, markdownCommand, existsDir, existsFile, hasCli, SERVER_NAME, COMMAND_NAME } from './common.mjs';
|
|
3
|
+
import { readJsonSafe } from '../lib/jsonFile.mjs';
|
|
4
|
+
|
|
5
|
+
const paths = (ctx) => (ctx.scope === 'project'
|
|
6
|
+
? { settings: join(ctx.root, '.claude', 'settings.json'), mcp: join(ctx.root, '.mcp.json'), command: join(ctx.root, '.claude', 'commands', `${COMMAND_NAME}.md`) }
|
|
7
|
+
: { settings: join(ctx.home, '.claude', 'settings.json'), mcp: join(ctx.home, '.claude.json'), command: join(ctx.home, '.claude', 'commands', `${COMMAND_NAME}.md`) });
|
|
8
|
+
|
|
9
|
+
function hookGroups(ctx) {
|
|
10
|
+
const cmd = (event, timeout) => ({ type: 'command', command: hookCommand(ctx, 'claude', event), timeout });
|
|
11
|
+
return {
|
|
12
|
+
SessionStart: [{ matcher: 'compact', hooks: [cmd('SessionStart', 10)] }],
|
|
13
|
+
PreToolUse: [
|
|
14
|
+
// Completion runs the test gate, so it may take minutes.
|
|
15
|
+
{ matcher: 'mcp__.*', hooks: [cmd('PreToolUse', 900)] },
|
|
16
|
+
{ matcher: 'Bash', hooks: [cmd('PreToolUse', 60)] },
|
|
17
|
+
],
|
|
18
|
+
PostToolUse: [{ matcher: '.*', hooks: [cmd('PostToolUse', 15)] }],
|
|
19
|
+
PreCompact: [{ hooks: [cmd('PreCompact', 10)] }],
|
|
20
|
+
Stop: [{ hooks: [cmd('Stop', 15)] }],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
id: 'claude',
|
|
26
|
+
label: 'Claude Code',
|
|
27
|
+
hooks: 'blocking',
|
|
28
|
+
detect: (ctx) => existsDir(join(ctx.home, '.claude')) || hasCli('claude', ctx.env),
|
|
29
|
+
install(ctx, writer) {
|
|
30
|
+
const p = paths(ctx);
|
|
31
|
+
const report = { connect: null, command: p.command, hooks: 'blocking', next: [] };
|
|
32
|
+
if (ctx.scope === 'user' && hasCli('claude', ctx.env)) {
|
|
33
|
+
const listed = writer.run('claude', ['mcp', 'get', SERVER_NAME]);
|
|
34
|
+
if (listed.ok && !writer.dryRun && listed.out.includes(ctx.url)) report.connect = 'already connected';
|
|
35
|
+
else {
|
|
36
|
+
if (listed.ok && !writer.dryRun) writer.run('claude', ['mcp', 'remove', '--scope', 'user', SERVER_NAME]);
|
|
37
|
+
const added = writer.run('claude', ['mcp', 'add', '--scope', 'user', '--transport', 'http', SERVER_NAME, ctx.url]);
|
|
38
|
+
report.connect = added.ok ? 'added' : `could not add (${added.out.slice(0, 120)}) — run: claude mcp add --scope user --transport http ${SERVER_NAME} ${ctx.url}`;
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
const result = editJson(writer, p.mcp, (config) => {
|
|
42
|
+
config.mcpServers = config.mcpServers ?? {};
|
|
43
|
+
const next = { type: 'http', url: ctx.url };
|
|
44
|
+
if (JSON.stringify(config.mcpServers[SERVER_NAME]) === JSON.stringify(next)) return false;
|
|
45
|
+
config.mcpServers[SERVER_NAME] = next;
|
|
46
|
+
return true;
|
|
47
|
+
});
|
|
48
|
+
report.connect = result.error ?? (result.manual ? `manual — add "${SERVER_NAME}": { "type": "http", "url": "${ctx.url}" } to mcpServers in ${p.mcp}` : result.changed ? 'added' : 'already connected');
|
|
49
|
+
}
|
|
50
|
+
report.next.push('In Claude Code run /mcp, pick "introsio" and sign in. Then: /introsio-execute <project>');
|
|
51
|
+
writer.writeText(p.command, markdownCommand(ctx, { frontmatter: { 'argument-hint': '<project name or id>' } }));
|
|
52
|
+
const hooks = editJson(writer, p.settings, (settings) => setMatcherHooks(settings, hookGroups(ctx)));
|
|
53
|
+
if (hooks.manual || hooks.error) report.hooks = hooks.error ?? `manual — ${p.settings} has comments; add the hooks shown by \`int setup --print claude\``;
|
|
54
|
+
return report;
|
|
55
|
+
},
|
|
56
|
+
uninstall(ctx, writer) {
|
|
57
|
+
const p = paths(ctx);
|
|
58
|
+
if (ctx.scope === 'user' && hasCli('claude', ctx.env)) writer.run('claude', ['mcp', 'remove', '--scope', 'user', SERVER_NAME]);
|
|
59
|
+
else editJson(writer, p.mcp, (config) => (config.mcpServers?.[SERVER_NAME] ? (delete config.mcpServers[SERVER_NAME], true) : false));
|
|
60
|
+
editJson(writer, p.settings, (settings) => removeMatcherHooks(settings));
|
|
61
|
+
writer.remove(p.command);
|
|
62
|
+
},
|
|
63
|
+
status(ctx) {
|
|
64
|
+
const p = paths(ctx);
|
|
65
|
+
const mcp = readJsonSafe(p.mcp, {});
|
|
66
|
+
return {
|
|
67
|
+
connect: mcp.mcpServers?.[SERVER_NAME] ? 'yes' : (ctx.scope === 'user' ? 'see `claude mcp list`' : 'no'),
|
|
68
|
+
command: existsFile(p.command),
|
|
69
|
+
hooks: hasOurHooks(readJsonSafe(p.settings, {})) ? 'blocking' : 'not installed',
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
print: (ctx) => ({ hooks: hookGroups(ctx) }),
|
|
73
|
+
};
|
package/agents/codex.mjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Codex: MCP server in config.toml (a managed block), /prompts:introsio-execute, hooks in hooks.json.
|
|
2
|
+
import { join, editJson, setMatcherHooks, removeMatcherHooks, hasOurHooks, hookCommand, markdownCommand, existsDir, existsFile, hasCli, SERVER_NAME, COMMAND_NAME } from './common.mjs';
|
|
3
|
+
import { readJsonSafe, readText } from '../lib/jsonFile.mjs';
|
|
4
|
+
import { withBlock, withoutBlock, hasBlock } from '../lib/managedBlock.mjs';
|
|
5
|
+
|
|
6
|
+
const base = (ctx) => (ctx.scope === 'project' ? join(ctx.root, '.codex') : join(ctx.home, '.codex'));
|
|
7
|
+
const paths = (ctx) => ({
|
|
8
|
+
config: join(base(ctx), 'config.toml'),
|
|
9
|
+
hooks: join(base(ctx), 'hooks.json'),
|
|
10
|
+
command: join(base(ctx), 'prompts', `${COMMAND_NAME}.md`),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
function hookGroups(ctx) {
|
|
14
|
+
const cmd = (event, timeout) => ({ type: 'command', command: hookCommand(ctx, 'codex', event), timeout });
|
|
15
|
+
return {
|
|
16
|
+
SessionStart: [{ hooks: [cmd('SessionStart', 10)] }],
|
|
17
|
+
PreToolUse: [{ matcher: 'mcp__.*|Bash|shell|exec_command', hooks: [cmd('PreToolUse', 900)] }],
|
|
18
|
+
PostToolUse: [{ matcher: '.*', hooks: [cmd('PostToolUse', 15)] }],
|
|
19
|
+
PreCompact: [{ hooks: [cmd('PreCompact', 10)] }],
|
|
20
|
+
PostCompact: [{ hooks: [cmd('PostCompact', 10)] }],
|
|
21
|
+
Stop: [{ hooks: [cmd('Stop', 15)] }],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** True when the user already configured [mcp_servers.introsio] themselves (outside our block). */
|
|
26
|
+
const userDefinedServer = (text) => /^\s*\[mcp_servers\.introsio\]/m.test(withoutBlock(text ?? ''));
|
|
27
|
+
|
|
28
|
+
export default {
|
|
29
|
+
id: 'codex',
|
|
30
|
+
label: 'Codex',
|
|
31
|
+
hooks: 'blocking',
|
|
32
|
+
detect: (ctx) => existsDir(join(ctx.home, '.codex')) || hasCli('codex', ctx.env),
|
|
33
|
+
install(ctx, writer) {
|
|
34
|
+
const p = paths(ctx);
|
|
35
|
+
const report = { connect: null, command: p.command, hooks: 'blocking', next: [] };
|
|
36
|
+
const text = readText(p.config) ?? '';
|
|
37
|
+
if (userDefinedServer(text)) report.connect = 'already configured in config.toml';
|
|
38
|
+
else {
|
|
39
|
+
const body = `[mcp_servers.${SERVER_NAME}]\nurl = ${JSON.stringify(ctx.url)}`;
|
|
40
|
+
report.connect = writer.writeText(p.config, withBlock(text, body)) ? 'added' : 'already connected';
|
|
41
|
+
}
|
|
42
|
+
report.next.push(`Sign in: codex mcp login ${SERVER_NAME}. Then in Codex: /prompts:${COMMAND_NAME} <project>`);
|
|
43
|
+
report.next.push('If your Codex version keeps hooks behind a flag, add to config.toml: [features] codex_hooks = true');
|
|
44
|
+
writer.writeText(p.command, markdownCommand(ctx, { frontmatter: { 'argument-hint': '<project name or id>' } }));
|
|
45
|
+
const hooks = editJson(writer, p.hooks, (config) => setMatcherHooks(config, hookGroups(ctx)));
|
|
46
|
+
if (hooks.manual || hooks.error) report.hooks = hooks.error ?? `manual — ${p.hooks} has comments`;
|
|
47
|
+
return report;
|
|
48
|
+
},
|
|
49
|
+
uninstall(ctx, writer) {
|
|
50
|
+
const p = paths(ctx);
|
|
51
|
+
const text = readText(p.config);
|
|
52
|
+
if (text && hasBlock(text)) writer.writeText(p.config, withoutBlock(text));
|
|
53
|
+
editJson(writer, p.hooks, (config) => removeMatcherHooks(config));
|
|
54
|
+
writer.remove(p.command);
|
|
55
|
+
},
|
|
56
|
+
status(ctx) {
|
|
57
|
+
const p = paths(ctx);
|
|
58
|
+
const text = readText(p.config) ?? '';
|
|
59
|
+
return {
|
|
60
|
+
connect: hasBlock(text) || userDefinedServer(text) ? 'yes' : 'no',
|
|
61
|
+
command: existsFile(p.command),
|
|
62
|
+
hooks: hasOurHooks(readJsonSafe(p.hooks, {})) ? 'blocking' : 'not installed',
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
print: (ctx) => ({ hooks: hookGroups(ctx) }),
|
|
66
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
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
|
+
export class Writer {
|
|
13
|
+
constructor({ dryRun = false } = {}) {
|
|
14
|
+
this.dryRun = dryRun;
|
|
15
|
+
this.actions = [];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
writeText(file, text) {
|
|
19
|
+
if (readText(file) === text) return false;
|
|
20
|
+
this.actions.push(`write ${file}`);
|
|
21
|
+
if (!this.dryRun) writeAtomic(file, text);
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
writeJson(file, value) {
|
|
26
|
+
return this.writeText(file, `${JSON.stringify(value, null, 2)}\n`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
remove(file) {
|
|
30
|
+
if (!fs.existsSync(file)) return false;
|
|
31
|
+
this.actions.push(`remove ${file}`);
|
|
32
|
+
if (!this.dryRun) fs.rmSync(file, { recursive: true, force: true });
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
run(command, args) {
|
|
37
|
+
this.actions.push(`run ${command} ${args.join(' ')}`);
|
|
38
|
+
if (this.dryRun) return { ok: true, out: '' };
|
|
39
|
+
const result = spawnSync(command, args, { encoding: 'utf8', timeout: 30000, shell: process.platform === 'win32' });
|
|
40
|
+
return { ok: result.status === 0, out: `${result.stdout ?? ''}${result.stderr ?? ''}`.trim() };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** True when `command` is on PATH (never in tests — they must not touch the real tools). */
|
|
45
|
+
export function hasCli(command, env = process.env) {
|
|
46
|
+
if (env.INTROSIO_TEST_HOME) return false;
|
|
47
|
+
const result = spawnSync(command, ['--version'], { encoding: 'utf8', timeout: 10000, shell: process.platform === 'win32' });
|
|
48
|
+
return result.status === 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Merges into a JSON config. A file with comments is never rewritten (that
|
|
53
|
+
* would drop them): the caller gets `{ manual: true }` and prints a snippet.
|
|
54
|
+
*/
|
|
55
|
+
export function editJson(writer, file, mutate) {
|
|
56
|
+
const raw = readText(file);
|
|
57
|
+
let value = {};
|
|
58
|
+
if (raw !== null && raw.trim()) {
|
|
59
|
+
try {
|
|
60
|
+
value = JSON.parse(raw);
|
|
61
|
+
} catch {
|
|
62
|
+
try {
|
|
63
|
+
JSON.parse(stripJsonComments(raw));
|
|
64
|
+
return { manual: true };
|
|
65
|
+
} catch {
|
|
66
|
+
return { error: `${file} is not valid JSON — left untouched` };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const changed = mutate(value);
|
|
71
|
+
if (changed === false) return { changed: false };
|
|
72
|
+
return { changed: writer.writeJson(file, value) };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const isOurs = (entry) => JSON.stringify(entry ?? {}).includes(HOOK_MARK);
|
|
76
|
+
|
|
77
|
+
/** Claude / Codex / Gemini hook shape: { Event: [ { matcher, hooks: [ { type, command, timeout } ] } ] }. */
|
|
78
|
+
export function setMatcherHooks(root, groups) {
|
|
79
|
+
removeMatcherHooks(root);
|
|
80
|
+
root.hooks = root.hooks && typeof root.hooks === 'object' ? root.hooks : {};
|
|
81
|
+
for (const [event, entries] of Object.entries(groups)) {
|
|
82
|
+
root.hooks[event] = [...(root.hooks[event] ?? []), ...entries];
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function removeMatcherHooks(root) {
|
|
88
|
+
if (!root.hooks || typeof root.hooks !== 'object') return false;
|
|
89
|
+
let changed = false;
|
|
90
|
+
for (const [event, list] of Object.entries(root.hooks)) {
|
|
91
|
+
if (!Array.isArray(list)) continue;
|
|
92
|
+
const kept = list
|
|
93
|
+
.map((group) => (group && Array.isArray(group.hooks) ? { ...group, hooks: group.hooks.filter((hook) => !isOurs(hook)) } : group))
|
|
94
|
+
.filter((group) => !(group && Array.isArray(group.hooks) && group.hooks.length === 0) && !(group && !Array.isArray(group.hooks) && isOurs(group)));
|
|
95
|
+
if (kept.length !== list.length || JSON.stringify(kept) !== JSON.stringify(list)) changed = true;
|
|
96
|
+
if (kept.length) root.hooks[event] = kept;
|
|
97
|
+
else delete root.hooks[event];
|
|
98
|
+
}
|
|
99
|
+
if (Object.keys(root.hooks).length === 0) delete root.hooks;
|
|
100
|
+
return changed;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const hasOurHooks = (root) => isOurs(root?.hooks);
|
|
104
|
+
|
|
105
|
+
/** Forward slashes work for Node and for every shell an agent may use on Windows. */
|
|
106
|
+
const portable = (file) => String(file).replace(/\\/g, '/');
|
|
107
|
+
const quote = (file) => `"${portable(file)}"`;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The command line an agent runs for one event. Globally it names the absolute
|
|
111
|
+
* Node binary that ran setup: GUI apps (Cursor, VS Code) often start without the
|
|
112
|
+
* shell's PATH, so a bare `node` (nvm, fnm, Homebrew) is not found there.
|
|
113
|
+
* In a project it stays `node` + a repo-relative path, since teammates differ.
|
|
114
|
+
*/
|
|
115
|
+
export function hookCommand(ctx, agent, event) {
|
|
116
|
+
const tail = `${agent}${event ? ` ${event}` : ''}`;
|
|
117
|
+
if (ctx.scope === 'project') {
|
|
118
|
+
const script = agent === 'claude' ? '"$CLAUDE_PROJECT_DIR"/.introsio/kit/hook/introsio-hook.mjs' : '.introsio/kit/hook/introsio-hook.mjs';
|
|
119
|
+
return `node ${script} ${tail}`;
|
|
120
|
+
}
|
|
121
|
+
return `${quote(ctx.nodePath ?? process.execPath)} ${quote(ctx.hookScript)} ${tail}`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The Node binary a global hook command uses ("" when the command is not ours). */
|
|
125
|
+
export function nodePathOf(command) {
|
|
126
|
+
const match = String(command ?? '').match(/^"([^"]+)"\s+"[^"]*introsio-hook\.mjs"/);
|
|
127
|
+
return match ? match[1] : '';
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** The execute procedure, with `$ARGUMENTS` rendered the way an agent's commands expect. */
|
|
131
|
+
export function executeText(ctx, argumentToken = '$ARGUMENTS') {
|
|
132
|
+
return ctx.executeTemplate.replaceAll('$ARGUMENTS', argumentToken).trim();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function markdownCommand(ctx, { frontmatter = {}, argumentToken } = {}) {
|
|
136
|
+
const lines = Object.entries({ description: DESCRIPTION, ...frontmatter }).map(([key, value]) => `${key}: ${value}`);
|
|
137
|
+
return `---\n${lines.join('\n')}\n---\n\n${executeText(ctx, argumentToken)}\n`;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function existsDir(dir) {
|
|
141
|
+
try {
|
|
142
|
+
return fs.statSync(dir).isDirectory();
|
|
143
|
+
} catch {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export const join = path.join;
|
|
149
|
+
|
|
150
|
+
export const existsFile = (file) => (fs.existsSync(file) ? 'yes' : 'no');
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Cursor: MCP in mcp.json, /introsio-execute in commands/, hooks in hooks.json (version 1 format).
|
|
2
|
+
import { join, editJson, hookCommand, markdownCommand, existsDir, existsFile, 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) => ({ mcp: join(base(ctx), 'mcp.json'), hooks: join(base(ctx), 'hooks.json'), command: join(base(ctx), 'commands', `${COMMAND_NAME}.md`) });
|
|
7
|
+
|
|
8
|
+
const EVENTS = ['beforeMCPExecution', 'afterMCPExecution', 'beforeShellExecution', 'afterFileEdit', 'stop'];
|
|
9
|
+
|
|
10
|
+
function removeOurs(config) {
|
|
11
|
+
if (!config.hooks) return false;
|
|
12
|
+
let changed = false;
|
|
13
|
+
for (const [event, list] of Object.entries(config.hooks)) {
|
|
14
|
+
if (!Array.isArray(list)) continue;
|
|
15
|
+
const kept = list.filter((hook) => !String(hook?.command ?? '').includes(HOOK_MARK));
|
|
16
|
+
if (kept.length !== list.length) changed = true;
|
|
17
|
+
if (kept.length) config.hooks[event] = kept;
|
|
18
|
+
else delete config.hooks[event];
|
|
19
|
+
}
|
|
20
|
+
return changed;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default {
|
|
24
|
+
id: 'cursor',
|
|
25
|
+
label: 'Cursor',
|
|
26
|
+
hooks: 'blocking (stop hook reliability varies by Cursor version)',
|
|
27
|
+
detect: (ctx) => existsDir(join(ctx.home, '.cursor')),
|
|
28
|
+
install(ctx, writer) {
|
|
29
|
+
const p = paths(ctx);
|
|
30
|
+
const report = { connect: null, command: p.command, hooks: 'blocking', next: [] };
|
|
31
|
+
const mcp = editJson(writer, p.mcp, (config) => {
|
|
32
|
+
config.mcpServers = config.mcpServers ?? {};
|
|
33
|
+
if (config.mcpServers[SERVER_NAME]?.url === ctx.url) return false;
|
|
34
|
+
config.mcpServers[SERVER_NAME] = { url: ctx.url };
|
|
35
|
+
return true;
|
|
36
|
+
});
|
|
37
|
+
report.connect = mcp.error ?? (mcp.manual ? `manual — add "${SERVER_NAME}": { "url": "${ctx.url}" } to ${p.mcp}` : mcp.changed ? 'added' : 'already connected');
|
|
38
|
+
report.next.push('In Cursor: Settings → MCP → introsio → Connect (sign in). Then in Agent chat: /introsio-execute <project>');
|
|
39
|
+
writer.writeText(p.command, markdownCommand(ctx, { argumentToken: 'the project named after the command' }));
|
|
40
|
+
const hooks = editJson(writer, p.hooks, (config) => {
|
|
41
|
+
config.version = config.version ?? 1;
|
|
42
|
+
config.hooks = config.hooks ?? {};
|
|
43
|
+
removeOurs(config);
|
|
44
|
+
for (const event of EVENTS) config.hooks[event] = [...(config.hooks[event] ?? []), { command: hookCommand(ctx, 'cursor', event) }];
|
|
45
|
+
return true;
|
|
46
|
+
});
|
|
47
|
+
if (hooks.manual || hooks.error) report.hooks = hooks.error ?? 'manual';
|
|
48
|
+
return report;
|
|
49
|
+
},
|
|
50
|
+
uninstall(ctx, writer) {
|
|
51
|
+
const p = paths(ctx);
|
|
52
|
+
editJson(writer, p.mcp, (config) => (config.mcpServers?.[SERVER_NAME] ? (delete config.mcpServers[SERVER_NAME], true) : false));
|
|
53
|
+
editJson(writer, p.hooks, (config) => removeOurs(config));
|
|
54
|
+
writer.remove(p.command);
|
|
55
|
+
},
|
|
56
|
+
status(ctx) {
|
|
57
|
+
const p = paths(ctx);
|
|
58
|
+
const hooks = JSON.stringify(readJsonSafe(p.hooks, {}));
|
|
59
|
+
return { connect: readJsonSafe(p.mcp, {}).mcpServers?.[SERVER_NAME] ? 'yes' : 'no', command: existsFile(p.command), hooks: hooks.includes(HOOK_MARK) ? 'blocking' : 'not installed' };
|
|
60
|
+
},
|
|
61
|
+
print: (ctx) => ({ version: 1, hooks: Object.fromEntries(EVENTS.map((event) => [event, [{ command: hookCommand(ctx, 'cursor', event) }]])) }),
|
|
62
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Gemini CLI: MCP + hooks in settings.json, /introsio-execute as a TOML command.
|
|
2
|
+
import { join, editJson, setMatcherHooks, removeMatcherHooks, hasOurHooks, hookCommand, executeText, existsDir, existsFile, hasCli, SERVER_NAME, COMMAND_NAME, DESCRIPTION } 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) => ({ settings: join(base(ctx), 'settings.json'), command: join(base(ctx), 'commands', `${COMMAND_NAME}.toml`) });
|
|
7
|
+
|
|
8
|
+
function hookGroups(ctx) {
|
|
9
|
+
// Gemini timeouts are milliseconds.
|
|
10
|
+
const cmd = (event, timeout) => ({ name: 'introsio', type: 'command', command: hookCommand(ctx, 'gemini', event), timeout });
|
|
11
|
+
return {
|
|
12
|
+
SessionStart: [{ matcher: '*', hooks: [cmd('SessionStart', 10_000)] }],
|
|
13
|
+
BeforeTool: [{ matcher: '.*', hooks: [cmd('BeforeTool', 900_000)] }],
|
|
14
|
+
AfterTool: [{ matcher: '.*', hooks: [cmd('AfterTool', 15_000)] }],
|
|
15
|
+
PreCompress: [{ matcher: '*', hooks: [cmd('PreCompress', 10_000)] }],
|
|
16
|
+
AfterAgent: [{ matcher: '*', hooks: [cmd('AfterAgent', 15_000)] }],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const tomlString = (text) => `"""\n${text.replaceAll('\\', '\\\\').replaceAll('"""', '\\"\\"\\"')}\n"""`;
|
|
21
|
+
|
|
22
|
+
export default {
|
|
23
|
+
id: 'gemini',
|
|
24
|
+
label: 'Gemini CLI',
|
|
25
|
+
hooks: 'blocking',
|
|
26
|
+
detect: (ctx) => existsDir(join(ctx.home, '.gemini')) || hasCli('gemini', ctx.env),
|
|
27
|
+
install(ctx, writer) {
|
|
28
|
+
const p = paths(ctx);
|
|
29
|
+
const report = { connect: null, command: p.command, hooks: 'blocking', next: [] };
|
|
30
|
+
const result = editJson(writer, p.settings, (settings) => {
|
|
31
|
+
settings.mcpServers = settings.mcpServers ?? {};
|
|
32
|
+
const before = JSON.stringify(settings);
|
|
33
|
+
if (!settings.mcpServers[SERVER_NAME]) settings.mcpServers[SERVER_NAME] = { httpUrl: ctx.url };
|
|
34
|
+
else settings.mcpServers[SERVER_NAME].httpUrl = ctx.url;
|
|
35
|
+
setMatcherHooks(settings, hookGroups(ctx));
|
|
36
|
+
return JSON.stringify(settings) !== before;
|
|
37
|
+
});
|
|
38
|
+
report.connect = result.error ?? (result.manual ? `manual — ${p.settings} has comments; add mcpServers.${SERVER_NAME} = { "httpUrl": "${ctx.url}" }` : 'added');
|
|
39
|
+
if (result.manual || result.error) report.hooks = 'manual';
|
|
40
|
+
report.next.push(`In Gemini CLI run /mcp auth ${SERVER_NAME} to sign in. Then: /${COMMAND_NAME} <project>`);
|
|
41
|
+
writer.writeText(p.command, `description = ${JSON.stringify(DESCRIPTION)}\nprompt = ${tomlString(executeText(ctx, '{{args}}'))}\n`);
|
|
42
|
+
return report;
|
|
43
|
+
},
|
|
44
|
+
uninstall(ctx, writer) {
|
|
45
|
+
const p = paths(ctx);
|
|
46
|
+
editJson(writer, p.settings, (settings) => {
|
|
47
|
+
const had = !!settings.mcpServers?.[SERVER_NAME];
|
|
48
|
+
if (had) delete settings.mcpServers[SERVER_NAME];
|
|
49
|
+
return removeMatcherHooks(settings) || had;
|
|
50
|
+
});
|
|
51
|
+
writer.remove(p.command);
|
|
52
|
+
},
|
|
53
|
+
status(ctx) {
|
|
54
|
+
const p = paths(ctx);
|
|
55
|
+
const settings = readJsonSafe(p.settings, {});
|
|
56
|
+
return { connect: settings.mcpServers?.[SERVER_NAME] ? 'yes' : 'no', command: existsFile(p.command), hooks: hasOurHooks(settings) ? 'blocking' : 'not installed' };
|
|
57
|
+
},
|
|
58
|
+
print: (ctx) => ({ hooks: hookGroups(ctx) }),
|
|
59
|
+
};
|