@mainwave/cli 0.9.0 → 0.11.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 +41 -2
- package/dist/adapters/claude-code.js +2 -1
- package/dist/adapters/copilot-chat.js +7 -13
- package/dist/adapters/copilot-cli.js +9 -12
- 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 +20 -7
- 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/entry-script.js +7 -1
- package/dist/core/install-hooks.js +11 -2
- package/dist/core/interview.js +62 -14
- package/dist/core/markers.js +5 -3
- package/dist/core/post-setup.js +5 -22
- package/dist/core/remove.js +67 -0
- package/dist/core/settings.js +17 -2
- package/dist/core/skills.js +50 -4
- package/dist/core/store.js +1 -1
- package/dist/core/url.js +1 -0
- package/dist/core/wizard.js +28 -3
- package/dist/main.js +12 -0
- package/hooks/cursor-otlp.mjs +3 -26
- package/hooks/git-commit-marker.mjs +406 -0
- package/hooks/kiro-otlp.mjs +570 -0
- package/hooks/mainwave-hook.mjs +6 -4
- package/hooks/marker-core.mjs +95 -1
- package/hooks/matchers.json +20 -3
- package/hooks/vocabulary.d.mts +14 -0
- package/hooks/vocabulary.mjs +49 -1
- package/package.json +7 -7
- package/skills/mainwave-instrument-node/SKILL.md +12 -6
- package/skills/mainwave-instrument-node/reference/api.md +14 -14
- package/skills/mainwave-instrument-node/reference/frameworks.md +10 -8
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
|
|
@@ -139,7 +170,7 @@ mainwave-cli setup claude-code codex \
|
|
|
139
170
|
| `--ucid <id\|url>` / `--use-case <name>` / `--no-use-case` | pin one use case, or `--no-use-case` to unpin (default: none) |
|
|
140
171
|
| `--email <e>` | attribution identity for tools that need it injected |
|
|
141
172
|
| `--opt-in prompts,tool-details,tool-content,repository` (or `all` / `none`) | content capture (default: all on; `none` sends metadata only; `repository` is Claude Code's repository names) |
|
|
142
|
-
| `--no-markers` | skip the Mainwave hooks (installed by default):
|
|
173
|
+
| `--no-markers` | skip the Mainwave hooks (installed by default): ticket, PR & commit markers, the Claude plan snapshot |
|
|
143
174
|
| `--new-key` | mint a fresh machine key instead of reusing this machine's |
|
|
144
175
|
| `--yes` | write without the confirmation prompt |
|
|
145
176
|
| `--no-verify` / `--verify-timeout <s>` | the closing first-span check |
|
|
@@ -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
|
|
@@ -198,6 +229,14 @@ title, project id and the changed-file count. Never ticket bodies, never diff co
|
|
|
198
229
|
open — a telemetry problem can never block or slow a coding session — and count forward only from
|
|
199
230
|
when you enable them.
|
|
200
231
|
|
|
232
|
+
The same install adds a **commit marker**: when a Bash command that begins with `git` runs
|
|
233
|
+
`git commit`, the hook reads each new commit with `git show --numstat` (5 seconds at most) and
|
|
234
|
+
emits one event per commit. What leaves your machine: the commit's id and its parent's id, how many
|
|
235
|
+
files it changes and how many lines it adds and removes, and for each file its path inside the
|
|
236
|
+
repository, its added and removed line counts and whether it is binary (a binary file counts 0
|
|
237
|
+
lines). Never the commit message, never file contents. A commit that fails sends nothing, and so
|
|
238
|
+
does `git commit --quiet`, which prints no commit line to read.
|
|
239
|
+
|
|
201
240
|
For Claude Code, the same install adds a **Claude plan snapshot**: a hook on Claude Code's
|
|
202
241
|
`UserPromptSubmit` event (each prompt you submit) that reads Claude Code's local account record (`.claude.json`) and sends one event every time
|
|
203
242
|
it runs. What leaves your machine: your Claude account id, organization id and email (the identity
|
|
@@ -84,6 +84,7 @@ const parseEnv = (env) => {
|
|
|
84
84
|
};
|
|
85
85
|
return out;
|
|
86
86
|
};
|
|
87
|
+
const stripTrailingSlash = (url) => url.replace(/\/+$/, '');
|
|
87
88
|
const buildEnv = ({ ucid, collectorUrl, apiKey, optIns, userEmail, }) => {
|
|
88
89
|
const env = {
|
|
89
90
|
CLAUDE_CODE_ENABLE_TELEMETRY: '1',
|
|
@@ -92,7 +93,7 @@ const buildEnv = ({ ucid, collectorUrl, apiKey, optIns, userEmail, }) => {
|
|
|
92
93
|
OTEL_METRICS_EXPORTER: 'otlp',
|
|
93
94
|
OTEL_LOGS_EXPORTER: 'otlp',
|
|
94
95
|
OTEL_EXPORTER_OTLP_PROTOCOL: 'http/protobuf',
|
|
95
|
-
OTEL_EXPORTER_OTLP_ENDPOINT: collectorUrl,
|
|
96
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: stripTrailingSlash(collectorUrl),
|
|
96
97
|
OTEL_EXPORTER_OTLP_HEADERS: `Authorization=Bearer ${apiKey}`,
|
|
97
98
|
OTEL_RESOURCE_ATTRIBUTES: buildResourceAttrs(ucid, userEmail),
|
|
98
99
|
};
|
|
@@ -114,30 +114,24 @@ const normalizeForGenericChecks = (env) => ({
|
|
|
114
114
|
auth: undefined,
|
|
115
115
|
ucid: undefined,
|
|
116
116
|
});
|
|
117
|
-
const printPostSetupInstructions = (_input
|
|
118
|
-
const envFile = scope === 'local' ? ENV_FILE_LOCAL_PATH : ENV_FILE_GLOBAL_PATH;
|
|
117
|
+
const printPostSetupInstructions = (_input) => {
|
|
119
118
|
if (osPlatform() === 'win32') {
|
|
120
119
|
return [
|
|
121
120
|
color.bold('Make the OTEL vars visible to VS Code on next launch:'),
|
|
122
121
|
'',
|
|
123
|
-
` Copy the four KEY=VALUE lines from ${color.cyan(
|
|
122
|
+
` Copy the four KEY=VALUE lines from ${color.cyan(ENV_FILE_GLOBAL_PATH)}, then in PowerShell run`,
|
|
124
123
|
` ${color.cyan('setx KEY "VALUE"')} for each.`,
|
|
125
124
|
'',
|
|
126
125
|
color.dim(' Fully close and reopen VS Code (close all windows + tray icon).'),
|
|
127
126
|
color.dim(' `code --reload-window` is not enough — env is captured at process start.'),
|
|
128
127
|
].join('\n');
|
|
129
128
|
}
|
|
130
|
-
const epilogue = scope === 'global'
|
|
131
|
-
? [
|
|
132
|
-
'',
|
|
133
|
-
color.bold('Then fully restart VS Code:'),
|
|
134
|
-
color.dim(' Cmd+Q + reopen (Reload Window is NOT enough — env is captured once per'),
|
|
135
|
-
color.dim(' process by the shell-env resolver on GUI launch).'),
|
|
136
|
-
]
|
|
137
|
-
: ['', color.bold('Then launch VS Code from this terminal:'), ` ${color.cyan('code .')}`];
|
|
138
129
|
return [
|
|
139
|
-
renderEnvFileBlock(
|
|
140
|
-
|
|
130
|
+
renderEnvFileBlock(ENV_FILE_GLOBAL_PATH),
|
|
131
|
+
'',
|
|
132
|
+
color.bold('Then fully restart VS Code:'),
|
|
133
|
+
color.dim(' Cmd+Q + reopen (Reload Window is NOT enough — env is captured once per'),
|
|
134
|
+
color.dim(' process by the shell-env resolver on GUI launch).'),
|
|
141
135
|
'',
|
|
142
136
|
color.dim('Verify the GUI shell-env reflects the file:'),
|
|
143
137
|
` ${color.cyan('mainwave-cli doctor copilot-chat --validate')}`,
|
|
@@ -58,18 +58,15 @@ const normalizeForGenericChecks = (env) => {
|
|
|
58
58
|
}
|
|
59
59
|
return { endpoint, auth, ucid };
|
|
60
60
|
};
|
|
61
|
-
const printPostSetupInstructions = (_input
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
` ${color.cyan('copilot')}`,
|
|
71
|
-
].join('\n');
|
|
72
|
-
};
|
|
61
|
+
const printPostSetupInstructions = (_input) => [
|
|
62
|
+
renderEnvFileBlock(GLOBAL_PATH),
|
|
63
|
+
'',
|
|
64
|
+
color.dim('Cross-shell alternative (any shell):'),
|
|
65
|
+
` ${color.cyan('eval "$(mainwave-cli env copilot-cli)"')}`,
|
|
66
|
+
'',
|
|
67
|
+
color.bold('Then run:'),
|
|
68
|
+
` ${color.cyan('copilot')}`,
|
|
69
|
+
].join('\n');
|
|
73
70
|
const HIERARCHY = [
|
|
74
71
|
{
|
|
75
72
|
id: 'projectLocal',
|
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
|
@@ -4,7 +4,7 @@ import { adapters } from '../adapters/index.js';
|
|
|
4
4
|
import { activeHierarchy, effectiveEnv } from './effective-settings.js';
|
|
5
5
|
import { color, renderDiff } from './format.js';
|
|
6
6
|
import { claudeHookShellMissing, GIT_BASH_FIX, GIT_BASH_MISSING_REASON } from './git-bash.js';
|
|
7
|
-
import { activeManagedScans, BOOTSTRAP_KEY, commandGeneration, copyHookScripts, DEFAULT_MARKER_TOOL, describeMarkersPlan, hooksBlocked, hostRunsBootstrap, installedHooksDir, isPlanSnapshot, isPlanSnapshotRoute, legacyCommandSends, managedDeliversEntry, managedDeliversPlanSnapshot, managedHooksDir, managedMarkerDeliveries, matchersForTool, packagedHooksDir, planMarkers, prepareMarkersFile, readPackagedMatchers, routeLabel, scanForMarkers, scanRoutes, selectHookMatchers, syncManagedHooks, syncOrgDelivered, userHookGroups, writeOptOutFlags, } from './markers.js';
|
|
7
|
+
import { activeManagedScans, BOOTSTRAP_KEY, commandGeneration, copyHookScripts, DEFAULT_MARKER_TOOL, deliveryKey, describeMarkersPlan, hooksBlocked, hostRunsBootstrap, installedHooksDir, isPlanSnapshot, isPlanSnapshotRoute, legacyCommandSends, managedDeliversEntry, managedDeliversPlanSnapshot, managedHooksDir, managedMarkerDeliveries, matchersForTool, packagedHooksDir, planMarkers, prepareMarkersFile, readPackagedMatchers, routeLabel, scanForMarkers, scanRoutes, selectHookMatchers, syncManagedHooks, syncOrgDelivered, userHookGroups, writeOptOutFlags, } from './markers.js';
|
|
8
8
|
import { isManagedLayer } from './layer-policy.js';
|
|
9
9
|
import { adapterEffective } from './status.js';
|
|
10
10
|
import { applyUpdate, prepareUpdate, readExistingEnv } from './settings.js';
|
|
@@ -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,
|
|
@@ -101,6 +106,7 @@ export const planAdapter = async (adapter, answers, context = {}) => {
|
|
|
101
106
|
let hookHost = null;
|
|
102
107
|
let stageHooks = false;
|
|
103
108
|
let hookEvents = [];
|
|
109
|
+
let hookRoutes = [];
|
|
104
110
|
let orgDeliversEntry = false;
|
|
105
111
|
let hookShellMissing = false;
|
|
106
112
|
if (markersOn !== null) {
|
|
@@ -118,6 +124,12 @@ export const planAdapter = async (adapter, answers, context = {}) => {
|
|
|
118
124
|
...selected.map((m) => m.event),
|
|
119
125
|
]),
|
|
120
126
|
];
|
|
127
|
+
hookRoutes = [
|
|
128
|
+
...new Set([
|
|
129
|
+
...(stageHooks && hostRunsBootstrap(hookHost) ? [BOOTSTRAP_KEY] : []),
|
|
130
|
+
...selected.map((m) => deliveryKey(m.event, m.route)),
|
|
131
|
+
]),
|
|
132
|
+
];
|
|
121
133
|
const managedScans = adapter.markers?.hooksFile
|
|
122
134
|
? []
|
|
123
135
|
: await scanForMarkers((await activeHierarchy(adapter)).filter(isManagedLayer));
|
|
@@ -177,6 +189,7 @@ export const planAdapter = async (adapter, answers, context = {}) => {
|
|
|
177
189
|
hookHost,
|
|
178
190
|
stageHooks,
|
|
179
191
|
hookEvents,
|
|
192
|
+
hookRoutes,
|
|
180
193
|
orgDeliversEntry,
|
|
181
194
|
hookShellMissing,
|
|
182
195
|
...(teamUcid ? { teamUcid } : {}),
|
|
@@ -359,7 +372,7 @@ export const printPostSetup = (plan) => {
|
|
|
359
372
|
'starts, resumes or forks: it refreshes the hook scripts from the latest release and keeps the hooks above ' +
|
|
360
373
|
'current, on the same events only — a new kind of hook waits for your next setup run.'));
|
|
361
374
|
}
|
|
362
|
-
const snippet = plan.adapter.printPostSetupInstructions?.(plan.input
|
|
375
|
+
const snippet = plan.adapter.printPostSetupInstructions?.(plan.input);
|
|
363
376
|
if (snippet) {
|
|
364
377
|
say('');
|
|
365
378
|
say(snippet);
|