@mainwave/cli 0.9.0 → 0.10.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/README.md +32 -1
- package/dist/adapters/cursor.js +2 -0
- package/dist/adapters/index.js +3 -0
- package/dist/adapters/kiro.js +361 -0
- package/dist/core/apply.js +10 -5
- package/dist/core/behaviour-hooks.js +7 -7
- package/dist/core/codecs/kiro-hooks-json.js +76 -0
- package/dist/core/doctor.js +1 -1
- package/dist/core/interview.js +62 -14
- package/dist/core/remove.js +67 -0
- package/dist/core/settings.js +17 -2
- package/dist/core/skills.js +47 -1
- package/dist/core/wizard.js +18 -2
- package/dist/main.js +12 -0
- package/hooks/cursor-otlp.mjs +3 -26
- package/hooks/kiro-otlp.mjs +570 -0
- package/hooks/marker-core.mjs +95 -1
- package/hooks/vocabulary.d.mts +1 -0
- package/hooks/vocabulary.mjs +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,6 +16,8 @@ Installs as the `mainwave-cli` command. Requires Node 22.13 or newer.
|
|
|
16
16
|
| `copilot-chat` | GitHub Copilot Chat in VS Code |
|
|
17
17
|
| `cursor` | Cursor |
|
|
18
18
|
| `cursor-enterprise` | Cursor (Enterprise OTel export) |
|
|
19
|
+
| `kiro-ide` | Kiro IDE (1.0 or newer) |
|
|
20
|
+
| `kiro-cli` | Kiro CLI (2.13 or newer, V3) |
|
|
19
21
|
|
|
20
22
|
## Setup
|
|
21
23
|
|
|
@@ -58,6 +60,35 @@ re-run, and never shared with your other tools. If the id it already has is also
|
|
|
58
60
|
tools' config, or is your own stored use case — which is what earlier versions of the CLI wrote —
|
|
59
61
|
setup mints a separate team id and says so.
|
|
60
62
|
|
|
63
|
+
Kiro has no exporter of its own to point at Mainwave, so setup installs a Kiro hook instead: one
|
|
64
|
+
file, `~/.kiro/hooks/mainwave.json` (other files in that directory are left alone), that runs a small
|
|
65
|
+
script on session start, prompt submit, each tool call, agent file changes, the end of each turn and,
|
|
66
|
+
in Kiro CLI, session end. Each event becomes one span carrying the Kiro session id, the event, the
|
|
67
|
+
tool name and the kind of file change — never file paths, tool input or output. Prompt text is off
|
|
68
|
+
for Kiro unless you pass `--opt-in prompts`. The script prints nothing, always exits successfully and
|
|
69
|
+
hands the upload to a background process, so it never blocks, slows or steers a Kiro session. Your
|
|
70
|
+
email is the account `kiro-cli whoami` reports — it is how Kiro activity is matched to Kiro's own
|
|
71
|
+
usage export — unless you pass `--email`; without a Kiro sign-in it falls back to your Mainwave
|
|
72
|
+
sign-in, then your git email. Kiro CLI records sessions only in V3 mode (`kiro-cli --v3`); its 2.x
|
|
73
|
+
default mode doesn't read global hooks. Kiro hooks carry no tokens or cost, and `--ucid` doesn't
|
|
74
|
+
apply to them: Kiro activity is always attributed from your email. To take it off again:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
mainwave-cli setup kiro-ide --remove # or kiro-cli; both together to remove everything
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Kiro IDE and Kiro CLI run the same hooks file, and the hook can't always tell which one ran it. With
|
|
81
|
+
only one of them set up, sessions from the other are reported under the one you set up. With both
|
|
82
|
+
set up, Kiro CLI run in an editor's terminal (VS Code, Cursor, Kiro) is reported as the IDE, apart
|
|
83
|
+
from its session-end event. After you remove kiro-ide, that terminal session is taken for the IDE and
|
|
84
|
+
dropped, apart from its session-end event; after you remove kiro-cli, it is still reported as the
|
|
85
|
+
IDE, and Kiro CLI in a plain terminal is dropped.
|
|
86
|
+
|
|
87
|
+
Removing one of the two keeps the hooks for the other, and the hook stops sending the removed one's
|
|
88
|
+
sessions; removing the last one removes Mainwave's entries from `~/.kiro/hooks/mainwave.json` (the
|
|
89
|
+
file too, if nothing else is in it), Mainwave's instructions from `~/.kiro/steering/mainwave.md`
|
|
90
|
+
(likewise) and `~/.mainwave/kiro.env` with its backups (they hold your key; setup writes it again).
|
|
91
|
+
|
|
61
92
|
Validation names the organization the key belongs to, so a key from the wrong workspace is caught
|
|
62
93
|
before anything is written. To pin every tool to one specific use case instead — a shared or team
|
|
63
94
|
one — pass `--ucid <id|url>` or `--use-case <name>`. A pin you set that way stays: re-running setup
|
|
@@ -162,7 +193,7 @@ Setup installs three skills alongside the telemetry config — one detection, on
|
|
|
162
193
|
|
|
163
194
|
The bundles are copied to `~/.mainwave/skills/`, then registered on each tool's own instruction
|
|
164
195
|
surface: a native skill directory for Claude Code, `AGENTS.md` for Codex, `copilot-instructions.md`
|
|
165
|
-
for Copilot, a rules file for Cursor. Claude Desktop has no such surface and is reported as a no-op
|
|
196
|
+
for Copilot, a rules file for Cursor, a steering file for Kiro. Claude Desktop has no such surface and is reported as a no-op
|
|
166
197
|
rather than counted as installed.
|
|
167
198
|
|
|
168
199
|
The payload is installed at user scope, like the telemetry config — the skills teach an agent how to
|
package/dist/adapters/cursor.js
CHANGED
|
@@ -147,6 +147,8 @@ export const cursor = {
|
|
|
147
147
|
additionalWrites: [hooksWrite],
|
|
148
148
|
bundledHookScripts: ['marker-core.mjs', 'vocabulary.mjs', 'cursor-otlp.mjs'],
|
|
149
149
|
behaviourHooks: {
|
|
150
|
+
toolName: 'Cursor',
|
|
151
|
+
setupCommand: 'mainwave-cli setup cursor',
|
|
150
152
|
layers: HOOKS_LAYERS,
|
|
151
153
|
codec: cursorHooksJsonCodec,
|
|
152
154
|
script: 'cursor-otlp.mjs',
|
package/dist/adapters/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { copilotChat } from './copilot-chat.js';
|
|
|
5
5
|
import { copilotCli } from './copilot-cli.js';
|
|
6
6
|
import { cursor } from './cursor.js';
|
|
7
7
|
import { cursorEnterprise } from './cursor-enterprise.js';
|
|
8
|
+
import { kiroCli, kiroIde } from './kiro.js';
|
|
8
9
|
export const adapters = {
|
|
9
10
|
[claudeCode.name]: claudeCode,
|
|
10
11
|
[claudeDesktop.name]: claudeDesktop,
|
|
@@ -13,5 +14,7 @@ export const adapters = {
|
|
|
13
14
|
[copilotCli.name]: copilotCli,
|
|
14
15
|
[cursor.name]: cursor,
|
|
15
16
|
[cursorEnterprise.name]: cursorEnterprise,
|
|
17
|
+
[kiroIde.name]: kiroIde,
|
|
18
|
+
[kiroCli.name]: kiroCli,
|
|
16
19
|
};
|
|
17
20
|
export const adapterNames = () => Object.keys(adapters).sort();
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { promises as fsp, readFileSync, statSync } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { basename, dirname, join } from 'node:path';
|
|
5
|
+
import { envFileCodec } from '../core/codecs/env-file.js';
|
|
6
|
+
import { kiroHooksJsonCodec } from '../core/codecs/kiro-hooks-json.js';
|
|
7
|
+
import { hasBinary, hasPath } from '../core/detect.js';
|
|
8
|
+
import { buildHeaders, HEADER_NAME, headerBearerToken, kvPairsHeaders } from '../core/headers.js';
|
|
9
|
+
import { prepareUpdate, readExistingEnv } from '../core/settings.js';
|
|
10
|
+
import { hookLogDir, installedHooksDir, MANAGED_BY } from '../core/markers.js';
|
|
11
|
+
import { planBlockRemoval } from '../core/skills.js';
|
|
12
|
+
import { VERSION } from '../core/version.js';
|
|
13
|
+
const SOURCE = {
|
|
14
|
+
ide: 'coding_agent.kiro_ide',
|
|
15
|
+
cli: 'coding_agent.kiro_cli',
|
|
16
|
+
};
|
|
17
|
+
export const kiroHome = (env = process.env) => env.KIRO_HOME && env.KIRO_HOME.trim() !== '' ? env.KIRO_HOME : join(homedir(), '.kiro');
|
|
18
|
+
const CONFIG_MANAGED_KEYS = [
|
|
19
|
+
'OTEL_EXPORTER_OTLP_ENDPOINT',
|
|
20
|
+
'OTEL_EXPORTER_OTLP_HEADERS',
|
|
21
|
+
'OTEL_LOG_USER_PROMPTS',
|
|
22
|
+
];
|
|
23
|
+
export const KIRO_SURFACE_KEY = {
|
|
24
|
+
ide: 'MAINWAVE_KIRO_IDE',
|
|
25
|
+
cli: 'MAINWAVE_KIRO_CLI',
|
|
26
|
+
};
|
|
27
|
+
const ADAPTER_NAME = { ide: 'kiro-ide', cli: 'kiro-cli' };
|
|
28
|
+
const OTHER = { ide: 'cli', cli: 'ide' };
|
|
29
|
+
const CONFIG_GLOBAL = join(homedir(), '.mainwave', 'kiro.env');
|
|
30
|
+
const CONFIG_LOCAL = join('.mainwave', 'kiro.env');
|
|
31
|
+
const HOOKS_FILE = 'mainwave.json';
|
|
32
|
+
const HOOKS_GLOBAL = join(kiroHome(), 'hooks', HOOKS_FILE);
|
|
33
|
+
const HOOKS_LOCAL = join('.kiro', 'hooks', HOOKS_FILE);
|
|
34
|
+
const STEERING_FILE = 'mainwave.md';
|
|
35
|
+
const STEERING_GLOBAL = join(kiroHome(), 'steering', STEERING_FILE);
|
|
36
|
+
export const KIRO_HOOK_SCRIPT = 'kiro-otlp.mjs';
|
|
37
|
+
export const KIRO_TRIGGERS = [
|
|
38
|
+
'SessionStart',
|
|
39
|
+
'UserPromptSubmit',
|
|
40
|
+
'PostToolUse',
|
|
41
|
+
'PostFileCreate',
|
|
42
|
+
'PostFileSave',
|
|
43
|
+
'PostFileDelete',
|
|
44
|
+
'Stop',
|
|
45
|
+
'SessionEnd',
|
|
46
|
+
];
|
|
47
|
+
export const hookKey = (trigger) => `hooks.${trigger}`;
|
|
48
|
+
const HOOKS_MANAGED_KEYS = KIRO_TRIGGERS.map(hookKey);
|
|
49
|
+
export const buildKiroHookCommand = (scriptPath, version, trigger, plat = process.platform) => {
|
|
50
|
+
const args = `${MANAGED_BY}@${version} --trigger ${trigger}`;
|
|
51
|
+
return plat === 'win32'
|
|
52
|
+
? `cmd /d /s /c ""node" "${scriptPath}" ${args} >NUL 2>&1 & exit /b 0"`
|
|
53
|
+
: `sh -c '[ -f "$0" ] && node "$0" ${args} >/dev/null 2>&1; exit 0' "${scriptPath}"`;
|
|
54
|
+
};
|
|
55
|
+
const hookCommand = (trigger) => buildKiroHookCommand(join(installedHooksDir(), KIRO_HOOK_SCRIPT), VERSION, trigger);
|
|
56
|
+
const stripTrailingSlash = (url) => url.replace(/\/+$/, '');
|
|
57
|
+
const parseHeaders = (raw) => kvPairsHeaders.decode(raw) ?? {};
|
|
58
|
+
export const emailFromWhoami = (stdout) => {
|
|
59
|
+
let parsed;
|
|
60
|
+
try {
|
|
61
|
+
parsed = JSON.parse(stdout);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
const seen = [parsed];
|
|
67
|
+
for (let i = 0; i < seen.length && i < 200; i++) {
|
|
68
|
+
const v = seen[i];
|
|
69
|
+
if (v === null || typeof v !== 'object')
|
|
70
|
+
continue;
|
|
71
|
+
for (const [k, child] of Object.entries(v)) {
|
|
72
|
+
if (typeof child === 'string' &&
|
|
73
|
+
/e-?mail/i.test(k) &&
|
|
74
|
+
/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(child.trim())) {
|
|
75
|
+
return child.trim();
|
|
76
|
+
}
|
|
77
|
+
if (child !== null && typeof child === 'object')
|
|
78
|
+
seen.push(child);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
};
|
|
83
|
+
export const parseKiroCliVersion = (stdout) => /(\d+)\.(\d+)\.(\d+)/.exec(stdout)?.[0];
|
|
84
|
+
const run = (args) => {
|
|
85
|
+
try {
|
|
86
|
+
const r = spawnSync('kiro-cli', args, { encoding: 'utf8', timeout: 5000 });
|
|
87
|
+
return r.status === 0 ? r.stdout : undefined;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
let whoamiOnce;
|
|
94
|
+
export const KIRO_CLI = {
|
|
95
|
+
version: () => {
|
|
96
|
+
const out = run(['--version']);
|
|
97
|
+
return out === undefined ? undefined : parseKiroCliVersion(out);
|
|
98
|
+
},
|
|
99
|
+
whoamiEmail: () => {
|
|
100
|
+
if (!whoamiOnce) {
|
|
101
|
+
const out = run(['whoami', '--format', 'json']);
|
|
102
|
+
whoamiOnce = { email: out === undefined ? undefined : emailFromWhoami(out) };
|
|
103
|
+
}
|
|
104
|
+
return whoamiOnce.email;
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
export const KIRO_CLI_MIN_VERSION = '2.13.0';
|
|
108
|
+
const versionAtLeast = (v, min) => {
|
|
109
|
+
const a = v.split('.').map(Number);
|
|
110
|
+
const b = min.split('.').map(Number);
|
|
111
|
+
for (let i = 0; i < 3; i++) {
|
|
112
|
+
if ((a[i] ?? 0) !== (b[i] ?? 0))
|
|
113
|
+
return (a[i] ?? 0) > (b[i] ?? 0);
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
};
|
|
117
|
+
export const kiroActivityPath = (home = homedir()) => join(hookLogDir(home), 'kiro.log.ok');
|
|
118
|
+
export const KIRO_STALE_DAYS = 7;
|
|
119
|
+
export const kiroHooksRegistered = (path = HOOKS_GLOBAL) => {
|
|
120
|
+
try {
|
|
121
|
+
const doc = kiroHooksJsonCodec.parse(readFileSync(path, 'utf8'), path);
|
|
122
|
+
return Object.keys(kiroHooksJsonCodec.readEnv(doc)).length > 0;
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
export const kiroActivityIssue = (path = kiroActivityPath(), registered = kiroHooksRegistered(), now = new Date()) => {
|
|
129
|
+
let mtime;
|
|
130
|
+
try {
|
|
131
|
+
mtime = statSync(path).mtime;
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
mtime = undefined;
|
|
135
|
+
}
|
|
136
|
+
if (mtime && registered && now.getTime() - mtime.getTime() > KIRO_STALE_DAYS * 86_400_000) {
|
|
137
|
+
return {
|
|
138
|
+
level: 'warn',
|
|
139
|
+
message: `The Kiro hooks are registered but the last span was delivered ${mtime.toISOString()}, ` +
|
|
140
|
+
`over ${KIRO_STALE_DAYS} days ago. If you used Kiro since, check ${join(hookLogDir(), 'kiro.log')}.`,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return mtime
|
|
144
|
+
? { level: 'info', message: `Last Kiro hook span delivered ${mtime.toISOString()}.` }
|
|
145
|
+
: {
|
|
146
|
+
level: 'info',
|
|
147
|
+
message: 'No Kiro hook span delivered yet. Start a new Kiro session (the hooks load at session start), ' +
|
|
148
|
+
`then check ${join(hookLogDir(), 'kiro.log')} for skips and failures.`,
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
export const kiroCliIssues = (version = KIRO_CLI.version()) => {
|
|
152
|
+
const v3 = 'Mainwave records Kiro CLI sessions only in V3 mode (`kiro-cli --v3`); the 2.x default mode ' +
|
|
153
|
+
'reads hooks from agent configs, not ~/.kiro/hooks/, and is not supported.';
|
|
154
|
+
if (version === undefined) {
|
|
155
|
+
return [
|
|
156
|
+
{ level: 'warn', message: `Kiro CLI not found on PATH (\`kiro-cli --version\`). ${v3}` },
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
if (!versionAtLeast(version, KIRO_CLI_MIN_VERSION)) {
|
|
160
|
+
return [
|
|
161
|
+
{
|
|
162
|
+
level: 'error',
|
|
163
|
+
message: `Kiro CLI ${version} is older than ${KIRO_CLI_MIN_VERSION}, which global hooks need. Update Kiro CLI. ${v3}`,
|
|
164
|
+
},
|
|
165
|
+
];
|
|
166
|
+
}
|
|
167
|
+
return [{ level: 'info', message: `Kiro CLI ${version}. ${v3}` }];
|
|
168
|
+
};
|
|
169
|
+
export const planKiroRemoval = async (removing, paths = {
|
|
170
|
+
config: CONFIG_GLOBAL,
|
|
171
|
+
hooks: HOOKS_GLOBAL,
|
|
172
|
+
steering: STEERING_GLOBAL,
|
|
173
|
+
}) => {
|
|
174
|
+
const env = (await readExistingEnv(paths.config, envFileCodec)) ?? {};
|
|
175
|
+
const surfaces = ['ide', 'cli'].filter((s) => env[KIRO_SURFACE_KEY[s]] === '1');
|
|
176
|
+
const source = parseHeaders(env.OTEL_EXPORTER_OTLP_HEADERS ?? '')[HEADER_NAME.source];
|
|
177
|
+
const installed = surfaces.length > 0
|
|
178
|
+
? surfaces
|
|
179
|
+
: source === SOURCE.cli
|
|
180
|
+
? ['cli']
|
|
181
|
+
: source === SOURCE.ide
|
|
182
|
+
? ['ide']
|
|
183
|
+
: [];
|
|
184
|
+
const asked = ['ide', 'cli'].filter((s) => removing.includes(ADAPTER_NAME[s]));
|
|
185
|
+
const steps = installed.length === 0
|
|
186
|
+
? []
|
|
187
|
+
: asked
|
|
188
|
+
.filter((s) => !installed.includes(s))
|
|
189
|
+
.map((s) => ({ kind: 'note', note: `${ADAPTER_NAME[s]} isn't set up.` }));
|
|
190
|
+
const removed = installed.length === 0 ? asked : asked.filter((s) => installed.includes(s));
|
|
191
|
+
if (removed.length === 0)
|
|
192
|
+
return steps;
|
|
193
|
+
const remaining = installed.filter((s) => !removed.includes(s));
|
|
194
|
+
if (remaining.length > 0) {
|
|
195
|
+
const update = await prepareUpdate({
|
|
196
|
+
path: paths.config,
|
|
197
|
+
newEnv: Object.fromEntries(removed.map((s) => [KIRO_SURFACE_KEY[s], '0'])),
|
|
198
|
+
managedKeys: removed.map((s) => KIRO_SURFACE_KEY[s]),
|
|
199
|
+
codec: envFileCodec,
|
|
200
|
+
});
|
|
201
|
+
steps.push({
|
|
202
|
+
kind: 'update',
|
|
203
|
+
update,
|
|
204
|
+
note: `${paths.config}: drop ${removed.map((s) => ADAPTER_NAME[s]).join(', ')}; the hooks stay for ${remaining.map((s) => ADAPTER_NAME[s]).join(', ')}`,
|
|
205
|
+
});
|
|
206
|
+
return steps;
|
|
207
|
+
}
|
|
208
|
+
const hooks = await prepareUpdate({
|
|
209
|
+
path: paths.hooks,
|
|
210
|
+
newEnv: {},
|
|
211
|
+
managedKeys: HOOKS_MANAGED_KEYS,
|
|
212
|
+
codec: kiroHooksJsonCodec,
|
|
213
|
+
mode: 0o644,
|
|
214
|
+
});
|
|
215
|
+
const left = hooks.next.hooks ?? [];
|
|
216
|
+
if (hooks.exists) {
|
|
217
|
+
steps.push(left.length === 0
|
|
218
|
+
? {
|
|
219
|
+
kind: 'delete',
|
|
220
|
+
path: paths.hooks,
|
|
221
|
+
note: `${paths.hooks}: delete (only Mainwave hooks in it)`,
|
|
222
|
+
}
|
|
223
|
+
: {
|
|
224
|
+
kind: 'update',
|
|
225
|
+
update: hooks,
|
|
226
|
+
note: `${paths.hooks}: remove the Mainwave hooks, keep ${left.length} other`,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
const steering = await planBlockRemoval(paths.steering);
|
|
230
|
+
if (steering)
|
|
231
|
+
steps.push(steering);
|
|
232
|
+
if ((await readExistingEnv(paths.config, envFileCodec)) !== null) {
|
|
233
|
+
steps.push({
|
|
234
|
+
kind: 'delete',
|
|
235
|
+
path: paths.config,
|
|
236
|
+
backup: false,
|
|
237
|
+
note: `${paths.config}: delete`,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
const prefix = `${basename(paths.config)}.bak.`;
|
|
241
|
+
const backups = await fsp.readdir(dirname(paths.config)).catch(() => []);
|
|
242
|
+
for (const name of backups.filter((n) => n.startsWith(prefix)).sort()) {
|
|
243
|
+
const path = join(dirname(paths.config), name);
|
|
244
|
+
steps.push({ kind: 'delete', path, backup: false, note: `${path}: delete (holds the API key)` });
|
|
245
|
+
}
|
|
246
|
+
return steps;
|
|
247
|
+
};
|
|
248
|
+
const kiroAdapter = (surface) => {
|
|
249
|
+
const source = SOURCE[surface];
|
|
250
|
+
const buildEnv = ({ collectorUrl, apiKey, optIns, userEmail, passAdapters, }) => ({
|
|
251
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: stripTrailingSlash(collectorUrl),
|
|
252
|
+
OTEL_EXPORTER_OTLP_HEADERS: kvPairsHeaders.encode(buildHeaders({ apiKey, source, userEmail })),
|
|
253
|
+
...(optIns.userPrompts ? { OTEL_LOG_USER_PROMPTS: '1' } : {}),
|
|
254
|
+
[KIRO_SURFACE_KEY[surface]]: '1',
|
|
255
|
+
...(passAdapters?.includes(ADAPTER_NAME[OTHER[surface]])
|
|
256
|
+
? { [KIRO_SURFACE_KEY[OTHER[surface]]]: '1' }
|
|
257
|
+
: {}),
|
|
258
|
+
});
|
|
259
|
+
const parseEnv = (env) => {
|
|
260
|
+
if (!CONFIG_MANAGED_KEYS.some((k) => k in env))
|
|
261
|
+
return {};
|
|
262
|
+
const out = {};
|
|
263
|
+
const endpoint = env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
264
|
+
if (endpoint)
|
|
265
|
+
out.collectorUrl = stripTrailingSlash(endpoint);
|
|
266
|
+
const raw = env.OTEL_EXPORTER_OTLP_HEADERS;
|
|
267
|
+
if (raw) {
|
|
268
|
+
const headers = parseHeaders(raw);
|
|
269
|
+
const token = headerBearerToken(headers[HEADER_NAME.authorization]);
|
|
270
|
+
if (token)
|
|
271
|
+
out.apiKey = token;
|
|
272
|
+
const email = headers[HEADER_NAME.userEmail];
|
|
273
|
+
if (email)
|
|
274
|
+
out.userEmail = email;
|
|
275
|
+
}
|
|
276
|
+
out.optIns = {
|
|
277
|
+
userPrompts: env.OTEL_LOG_USER_PROMPTS === '1',
|
|
278
|
+
toolDetails: true,
|
|
279
|
+
toolContent: true,
|
|
280
|
+
};
|
|
281
|
+
return out;
|
|
282
|
+
};
|
|
283
|
+
const normalizeForGenericChecks = (env) => {
|
|
284
|
+
const raw = env.OTEL_EXPORTER_OTLP_HEADERS;
|
|
285
|
+
return {
|
|
286
|
+
endpoint: env.OTEL_EXPORTER_OTLP_ENDPOINT,
|
|
287
|
+
auth: raw ? parseHeaders(raw)[HEADER_NAME.authorization] : undefined,
|
|
288
|
+
ucid: undefined,
|
|
289
|
+
};
|
|
290
|
+
};
|
|
291
|
+
const hooksWrite = {
|
|
292
|
+
id: 'kiro-hooks',
|
|
293
|
+
label: 'Kiro hooks',
|
|
294
|
+
codec: kiroHooksJsonCodec,
|
|
295
|
+
path: HOOKS_GLOBAL,
|
|
296
|
+
localPath: HOOKS_LOCAL,
|
|
297
|
+
mode: 0o644,
|
|
298
|
+
managedKeys: HOOKS_MANAGED_KEYS,
|
|
299
|
+
build: () => Object.fromEntries(KIRO_TRIGGERS.map((t) => [hookKey(t), hookCommand(t)])),
|
|
300
|
+
parse: () => ({}),
|
|
301
|
+
};
|
|
302
|
+
const collectChecks = () => [
|
|
303
|
+
{
|
|
304
|
+
level: 'info',
|
|
305
|
+
message: 'Kiro hooks carry session behaviour only (sessions, prompts, tool calls, file operations) — ' +
|
|
306
|
+
"no tokens or cost; those come from Kiro's enterprise usage export, when your org has it.",
|
|
307
|
+
},
|
|
308
|
+
...(surface === 'cli' ? kiroCliIssues() : []),
|
|
309
|
+
kiroActivityIssue(),
|
|
310
|
+
];
|
|
311
|
+
return {
|
|
312
|
+
name: surface === 'ide' ? 'kiro-ide' : 'kiro-cli',
|
|
313
|
+
displayName: surface === 'ide' ? 'Kiro IDE' : 'Kiro CLI',
|
|
314
|
+
paths: {
|
|
315
|
+
local: CONFIG_LOCAL,
|
|
316
|
+
global: CONFIG_GLOBAL,
|
|
317
|
+
localIgnored: `The Kiro hook ignores ${CONFIG_LOCAL}: it reads only ~/.mainwave/kiro.env`,
|
|
318
|
+
},
|
|
319
|
+
instructionSurface: {
|
|
320
|
+
kind: 'instructions-file',
|
|
321
|
+
global: STEERING_GLOBAL,
|
|
322
|
+
local: join('.kiro', 'steering', STEERING_FILE),
|
|
323
|
+
label: 'steering file',
|
|
324
|
+
},
|
|
325
|
+
runInstruction: surface === 'ide'
|
|
326
|
+
? 'Kiro (start a new session so the hooks load)'
|
|
327
|
+
: 'kiro-cli --v3 (start a new session so the hooks load)',
|
|
328
|
+
detect: surface === 'ide'
|
|
329
|
+
? () => hasBinary('kiro') ||
|
|
330
|
+
hasPath('/Applications/Kiro.app') ||
|
|
331
|
+
hasPath(join(homedir(), 'Applications', 'Kiro.app'))
|
|
332
|
+
: () => hasBinary('kiro-cli'),
|
|
333
|
+
injectsIdentity: true,
|
|
334
|
+
carriesNoUcid: true,
|
|
335
|
+
defaultOptIns: { userPrompts: false },
|
|
336
|
+
removal: { group: 'kiro', plan: (removing) => planKiroRemoval(removing) },
|
|
337
|
+
detectIdentityEmail: () => KIRO_CLI.whoamiEmail(),
|
|
338
|
+
codec: envFileCodec,
|
|
339
|
+
managedEnvKeys: [...CONFIG_MANAGED_KEYS, KIRO_SURFACE_KEY[surface]],
|
|
340
|
+
hierarchy: [{ id: 'user', label: 'User (global)', path: CONFIG_GLOBAL, kind: 'file' }],
|
|
341
|
+
hookReadsConfigFile: true,
|
|
342
|
+
buildEnv,
|
|
343
|
+
parseEnv,
|
|
344
|
+
collectChecks,
|
|
345
|
+
normalizeForGenericChecks,
|
|
346
|
+
additionalWrites: [hooksWrite],
|
|
347
|
+
bundledHookScripts: ['marker-core.mjs', 'vocabulary.mjs', KIRO_HOOK_SCRIPT],
|
|
348
|
+
behaviourHooks: {
|
|
349
|
+
toolName: 'Kiro',
|
|
350
|
+
setupCommand: `mainwave-cli setup ${surface === 'ide' ? 'kiro-ide' : 'kiro-cli'}`,
|
|
351
|
+
layers: [
|
|
352
|
+
{ id: 'project', label: 'Workspace', path: HOOKS_LOCAL, kind: 'file' },
|
|
353
|
+
{ id: 'user', label: 'User (global)', path: HOOKS_GLOBAL, kind: 'file' },
|
|
354
|
+
],
|
|
355
|
+
codec: kiroHooksJsonCodec,
|
|
356
|
+
script: KIRO_HOOK_SCRIPT,
|
|
357
|
+
},
|
|
358
|
+
};
|
|
359
|
+
};
|
|
360
|
+
export const kiroIde = kiroAdapter('ide');
|
|
361
|
+
export const kiroCli = kiroAdapter('cli');
|
package/dist/core/apply.js
CHANGED
|
@@ -66,25 +66,30 @@ const decideTeamUcid = async (adapter, existing, stored) => {
|
|
|
66
66
|
}
|
|
67
67
|
return { status: 'kept', id: existing };
|
|
68
68
|
};
|
|
69
|
+
export const effectiveOptIns = (adapter, optIns, explicit) => explicit ? optIns : { ...optIns, ...adapter.defaultOptIns };
|
|
69
70
|
export const planAdapter = async (adapter, answers, context = {}) => {
|
|
70
71
|
const { primary, additional } = writeTargets(adapter);
|
|
71
|
-
const
|
|
72
|
+
const explicitUcid = adapter.carriesNoUcid ? undefined : answers.ucid;
|
|
73
|
+
const explicit = explicitUcid !== undefined;
|
|
72
74
|
const pin = context.unpin ? undefined : context.storedUseCase;
|
|
73
75
|
const needsDisk = !explicit && (pin?.pinned === true || adapter.teamUcid === true);
|
|
74
76
|
const onDiskUcid = needsDisk
|
|
75
77
|
? (context.onDisk ?? (await readPrefill(adapter)).values).ucid
|
|
76
78
|
: undefined;
|
|
77
|
-
const keptPin = !explicit && pin?.pinned === true && onDiskUcid === pin.id;
|
|
79
|
+
const keptPin = !adapter.carriesNoUcid && !explicit && pin?.pinned === true && onDiskUcid === pin.id;
|
|
78
80
|
const teamUcid = adapter.teamUcid && !explicit && !keptPin
|
|
79
81
|
?
|
|
80
82
|
await decideTeamUcid(adapter, onDiskUcid, context.storedUseCase && { ...context.storedUseCase, pinned: pin?.pinned })
|
|
81
83
|
: undefined;
|
|
82
84
|
const input = {
|
|
83
|
-
ucid:
|
|
85
|
+
ucid: explicitUcid ?? (keptPin ? pin.id : teamUcid?.id),
|
|
84
86
|
collectorUrl: answers.collectorUrl,
|
|
85
87
|
apiKey: answers.apiKey,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
...(context.pass ? { passAdapters: context.pass } : {}),
|
|
89
|
+
optIns: effectiveOptIns(adapter, answers.optIns, answers.optInsExplicit === true),
|
|
90
|
+
userEmail: adapter.injectsIdentity || adapter.stampsIdentityAttr
|
|
91
|
+
? (answers.adapterEmails?.[adapter.name] ?? answers.userEmail)
|
|
92
|
+
: undefined,
|
|
88
93
|
};
|
|
89
94
|
const primaryUpdate = await prepareUpdate({
|
|
90
95
|
path: primary,
|
|
@@ -40,7 +40,7 @@ export const collectBehaviourHookIssues = async (cap, currentVersion, scan = sca
|
|
|
40
40
|
if (s.status === 'error') {
|
|
41
41
|
issues.push({
|
|
42
42
|
level: 'warn',
|
|
43
|
-
message:
|
|
43
|
+
message: `${cap.toolName} hooks file could not be parsed: ${s.path} — ${s.error ?? 'invalid JSON'}.`,
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -48,7 +48,7 @@ export const collectBehaviourHookIssues = async (cap, currentVersion, scan = sca
|
|
|
48
48
|
if (present.length === 0) {
|
|
49
49
|
issues.push({
|
|
50
50
|
level: 'info',
|
|
51
|
-
message:
|
|
51
|
+
message: `${cap.toolName} behaviour hook is not registered in any hooks file layer — re-run \`${cap.setupCommand}\` to enable it.`,
|
|
52
52
|
});
|
|
53
53
|
return issues;
|
|
54
54
|
}
|
|
@@ -58,8 +58,8 @@ export const collectBehaviourHookIssues = async (cap, currentVersion, scan = sca
|
|
|
58
58
|
if (version !== undefined && version !== currentVersion) {
|
|
59
59
|
issues.push({
|
|
60
60
|
level: 'warn',
|
|
61
|
-
message:
|
|
62
|
-
|
|
61
|
+
message: `${cap.toolName} hook in ${s.path} was written by @mainwave/cli@${version}; you are running ${currentVersion}. ` +
|
|
62
|
+
`Re-run \`${cap.setupCommand}\` to refresh it — a stale registration can silently stop emitting.`,
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
const script = scriptPathFromCommand(command);
|
|
@@ -70,13 +70,13 @@ export const collectBehaviourHookIssues = async (cap, currentVersion, scan = sca
|
|
|
70
70
|
catch {
|
|
71
71
|
issues.push({
|
|
72
72
|
level: 'error',
|
|
73
|
-
message:
|
|
73
|
+
message: `${cap.toolName} hook script is missing: ${script} — the hook no-ops silently (fail-open). Re-run \`${cap.setupCommand}\`.`,
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
if (basename(script) !== cap.script) {
|
|
77
77
|
issues.push({
|
|
78
78
|
level: 'warn',
|
|
79
|
-
message:
|
|
79
|
+
message: `${cap.toolName} hook in ${s.path} points at ${basename(script)}, not the expected ${cap.script}. ` +
|
|
80
80
|
'Re-run setup to refresh the registration.',
|
|
81
81
|
});
|
|
82
82
|
}
|
|
@@ -85,7 +85,7 @@ export const collectBehaviourHookIssues = async (cap, currentVersion, scan = sca
|
|
|
85
85
|
if (s.layerId === 'managed') {
|
|
86
86
|
issues.push({
|
|
87
87
|
level: 'info',
|
|
88
|
-
message:
|
|
88
|
+
message: `${cap.toolName} behaviour hook is pinned by managed/enterprise settings (${s.path}) — it applies to every user on this machine and can't be changed without admin access.`,
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { commandOwnership } from '../markers.js';
|
|
2
|
+
export const KIRO_HOOK_TIMEOUT_SECONDS = 10;
|
|
3
|
+
export const kiroHookName = (trigger) => `Mainwave: ${trigger}`;
|
|
4
|
+
const isPlainObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
5
|
+
const isCommandEntry = (v) => isPlainObject(v) &&
|
|
6
|
+
typeof v.trigger === 'string' &&
|
|
7
|
+
isPlainObject(v.action) &&
|
|
8
|
+
typeof v.action.command === 'string';
|
|
9
|
+
const isOwned = (v) => isCommandEntry(v) && commandOwnership(v.action.command) !== null;
|
|
10
|
+
const triggerOfKey = (key) => key.startsWith('hooks.') ? key.slice('hooks.'.length) : undefined;
|
|
11
|
+
const parse = (body, path) => {
|
|
12
|
+
let parsed;
|
|
13
|
+
try {
|
|
14
|
+
parsed = JSON.parse(body);
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
throw new Error(`failed to parse ${path} as JSON: ${err.message}`);
|
|
18
|
+
}
|
|
19
|
+
if (!isPlainObject(parsed)) {
|
|
20
|
+
throw new Error(`${path}: expected a JSON object at the top level`);
|
|
21
|
+
}
|
|
22
|
+
return parsed;
|
|
23
|
+
};
|
|
24
|
+
const serialize = (doc) => {
|
|
25
|
+
if (!isPlainObject(doc))
|
|
26
|
+
throw new Error('expected a Kiro hooks document');
|
|
27
|
+
return JSON.stringify(doc, null, 2) + '\n';
|
|
28
|
+
};
|
|
29
|
+
const empty = () => ({ version: 'v1', hooks: [] });
|
|
30
|
+
const hooksOf = (doc) => {
|
|
31
|
+
if (doc.hooks === undefined)
|
|
32
|
+
return [];
|
|
33
|
+
if (!Array.isArray(doc.hooks))
|
|
34
|
+
throw new Error('Kiro hooks file: `hooks` is not an array');
|
|
35
|
+
return doc.hooks;
|
|
36
|
+
};
|
|
37
|
+
const readEnv = (doc) => {
|
|
38
|
+
if (!isPlainObject(doc))
|
|
39
|
+
throw new Error('expected a Kiro hooks document');
|
|
40
|
+
const out = {};
|
|
41
|
+
for (const entry of hooksOf(doc)) {
|
|
42
|
+
if (isOwned(entry) && !(`hooks.${entry.trigger}` in out)) {
|
|
43
|
+
out[`hooks.${entry.trigger}`] = entry.action.command;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
};
|
|
48
|
+
const applyEnv = (doc, newEnv, _managedKeys) => {
|
|
49
|
+
const base = isPlainObject(doc) ? structuredClone(doc) : {};
|
|
50
|
+
base.version = typeof base.version === 'string' ? base.version : 'v1';
|
|
51
|
+
const kept = hooksOf(base).filter((e) => !isOwned(e));
|
|
52
|
+
const ours = Object.entries(newEnv).flatMap(([key, command]) => {
|
|
53
|
+
const trigger = triggerOfKey(key);
|
|
54
|
+
return trigger === undefined
|
|
55
|
+
? []
|
|
56
|
+
: [
|
|
57
|
+
{
|
|
58
|
+
name: kiroHookName(trigger),
|
|
59
|
+
trigger,
|
|
60
|
+
action: { type: 'command', command },
|
|
61
|
+
timeout: KIRO_HOOK_TIMEOUT_SECONDS,
|
|
62
|
+
enabled: true,
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
});
|
|
66
|
+
base.hooks = [...kept, ...ours];
|
|
67
|
+
return base;
|
|
68
|
+
};
|
|
69
|
+
export const kiroHooksJsonCodec = {
|
|
70
|
+
format: 'json',
|
|
71
|
+
parse,
|
|
72
|
+
serialize,
|
|
73
|
+
empty,
|
|
74
|
+
readEnv,
|
|
75
|
+
applyEnv,
|
|
76
|
+
};
|
package/dist/core/doctor.js
CHANGED
|
@@ -72,7 +72,7 @@ const renderEffectiveEnv = (effective, adapter) => {
|
|
|
72
72
|
};
|
|
73
73
|
const collectEnvFileTargets = (adapter) => {
|
|
74
74
|
const targets = [];
|
|
75
|
-
if (adapter.codec.format === 'env') {
|
|
75
|
+
if (adapter.codec.format === 'env' && !adapter.hookReadsConfigFile) {
|
|
76
76
|
targets.push({
|
|
77
77
|
label: 'Primary',
|
|
78
78
|
path: adapter.paths.global,
|