@mainwave/cli 0.11.0 → 0.12.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 +168 -13
- package/dist/adapters/claude-code.js +3 -3
- package/dist/adapters/claude-desktop.js +35 -1
- package/dist/adapters/cursor.js +7 -2
- package/dist/adapters/kiro.js +13 -8
- package/dist/commands.js +217 -0
- package/dist/core/apply.js +3 -3
- package/dist/core/auth-commands.js +2 -1
- package/dist/core/codecs/kiro-hooks-json.js +1 -1
- package/dist/core/doctor.js +71 -8
- package/dist/core/entry-script.js +2 -3
- package/dist/core/format.js +0 -1
- package/dist/core/hook-copies.js +157 -0
- package/dist/core/install-hooks.js +144 -15
- package/dist/core/interview.js +8 -2
- package/dist/core/markers.js +86 -22
- package/dist/core/redaction.js +179 -0
- package/dist/core/skills.js +3 -11
- package/dist/core/status.js +21 -1
- package/dist/core/store.js +254 -4
- package/dist/core/wizard.js +91 -6
- package/dist/main.js +163 -162
- package/hooks/kiro-otlp.mjs +10 -1
- package/hooks/mainwave-hook.mjs +11 -1
- package/hooks/marker-core.mjs +56 -2
- package/hooks/matchers.json +1 -1
- package/hooks/redaction-data.mjs +201 -0
- package/hooks/redaction-json.mjs +215 -0
- package/hooks/redaction-pattern.mjs +503 -0
- package/hooks/redaction.d.mts +84 -0
- package/hooks/redaction.mjs +701 -0
- package/package.json +3 -1
- package/skills/mainwave-instrument/SKILL.md +24 -6
- package/skills/mainwave-instrument/reference/frameworks.md +4 -2
- package/skills/mainwave-instrument/reference/troubleshooting.md +4 -0
- package/skills/mainwave-instrument-node/SKILL.md +83 -38
- package/skills/mainwave-instrument-node/reference/api.md +16 -16
- package/skills/mainwave-instrument-node/reference/frameworks.md +42 -27
- package/skills/mainwave-instrument-node/reference/troubleshooting.md +11 -7
|
@@ -2,12 +2,24 @@ import { basename, dirname, isAbsolute, resolve } from 'node:path';
|
|
|
2
2
|
import { claudeConfigDir } from '../adapters/claude-code.js';
|
|
3
3
|
import { hasPath } from './detect.js';
|
|
4
4
|
import { activeHierarchy } from './effective-settings.js';
|
|
5
|
+
import { refreshFlatCopiesForOrgPacks } from './hook-copies.js';
|
|
5
6
|
import { isManagedLayer } from './layer-policy.js';
|
|
6
|
-
import { bootstrapGroup, buildHookGroups, DEFAULT_MARKER_TOOL, groupEvent, isBootstrapCommand, isDelivered, managedDeliversEntry, managedHooksDir, managedMarkerDeliveries, matchersForTool, packagedHooksDir, prepareMarkersFile, readPackagedMatchers, routeKeyOf, scanForMarkers, syncManagedHooks, syncOrgDelivered, userHookGroups, } from './markers.js';
|
|
7
|
+
import { BOOTSTRAP_KEY, bootstrapGroup, buildHookGroups, DEFAULT_MARKER_TOOL, groupEvent, isBootstrapCommand, installedHooksDir, isDelivered, managedDeliversEntry, managedHooksDir, managedMarkerDeliveries, managedRedactionPacks, managedRunsBootstrap, matchersForTool, packagedHooksDir, prepareMarkersFile, readEntryVersion, readPackagedMatchers, routeKeyOf, scanForMarkers, syncManagedHooks, syncOrgDelivered, userHookGroups, } from './markers.js';
|
|
8
|
+
import { REDACTION_PACKS } from '../../hooks/redaction.mjs';
|
|
7
9
|
import { applyUpdate } from './settings.js';
|
|
8
|
-
import { readSettings } from './store.js';
|
|
10
|
+
import { KEEP_ORG_PACKS, hasOrgEntry, readSettings, settingsPath, syncOrgRedaction, } from './store.js';
|
|
9
11
|
import { VERSION } from './version.js';
|
|
10
|
-
|
|
12
|
+
const ROUTES_BEFORE_RECORD = [
|
|
13
|
+
BOOTSTRAP_KEY,
|
|
14
|
+
'UserPromptSubmit',
|
|
15
|
+
'PostToolUse:gh',
|
|
16
|
+
'PostToolUse:glab',
|
|
17
|
+
'PostToolUse:bash',
|
|
18
|
+
'PostToolUse:git',
|
|
19
|
+
'PostToolUse:linear',
|
|
20
|
+
'PostToolUse:jira',
|
|
21
|
+
'StopFailure',
|
|
22
|
+
];
|
|
11
23
|
export const PAYLOAD_EVENTS = [
|
|
12
24
|
'SessionStart',
|
|
13
25
|
'UserPromptSubmit',
|
|
@@ -15,8 +27,11 @@ export const PAYLOAD_EVENTS = [
|
|
|
15
27
|
'StopFailure',
|
|
16
28
|
];
|
|
17
29
|
const payloadGroup = ({ event: _event, ...group }) => group;
|
|
18
|
-
export const managedPayloadHooks = (matchers) => {
|
|
19
|
-
const groups = [
|
|
30
|
+
export const managedPayloadHooks = (matchers, redactionPacks = []) => {
|
|
31
|
+
const groups = [
|
|
32
|
+
bootstrapGroup(redactionPacks),
|
|
33
|
+
...buildHookGroups(matchersForTool(matchers), 'claude-code'),
|
|
34
|
+
];
|
|
20
35
|
const under = (event) => groups.filter((g) => groupEvent(g) === event).map(payloadGroup);
|
|
21
36
|
return Object.fromEntries(PAYLOAD_EVENTS.map((e) => [e, under(e)]));
|
|
22
37
|
};
|
|
@@ -24,10 +39,15 @@ const defaultPaths = () => ({
|
|
|
24
39
|
srcDir: packagedHooksDir(),
|
|
25
40
|
destDir: managedHooksDir(),
|
|
26
41
|
});
|
|
27
|
-
export const installHooks = async (adapter, paths = defaultPaths()) => {
|
|
42
|
+
export const installHooks = async (adapter, paths = defaultPaths(), { redactionPacks } = {}) => {
|
|
28
43
|
const all = await readPackagedMatchers(paths.srcDir);
|
|
29
|
-
const updated = await syncManagedHooks(all, paths.srcDir, paths.destDir, paths.version ?? VERSION, paths.nodePath);
|
|
30
44
|
if (adapter === undefined) {
|
|
45
|
+
const held = redactionPacks !== undefined && (await readEntryVersion(paths.destDir)) === undefined
|
|
46
|
+
? 'config-dir'
|
|
47
|
+
: undefined;
|
|
48
|
+
const updated = held !== undefined
|
|
49
|
+
? []
|
|
50
|
+
: await syncManagedHooks(all, paths.srcDir, paths.destDir, paths.version ?? VERSION, paths.nodePath);
|
|
31
51
|
return {
|
|
32
52
|
updated,
|
|
33
53
|
destDir: paths.destDir,
|
|
@@ -35,16 +55,61 @@ export const installHooks = async (adapter, paths = defaultPaths()) => {
|
|
|
35
55
|
removedFromUser: 0,
|
|
36
56
|
addedToUser: 0,
|
|
37
57
|
userSettings: undefined,
|
|
58
|
+
...(held === undefined ? {} : { held }),
|
|
38
59
|
};
|
|
39
60
|
}
|
|
40
61
|
const scans = await scanForMarkers((await activeHierarchy(adapter)).filter(isManagedLayer));
|
|
62
|
+
const configDir = dirname(adapter.paths.global);
|
|
63
|
+
const orgPacks = managedRedactionPacks(scans);
|
|
64
|
+
const recorded = orgPacks !== undefined && orgPacks.length > 0 ? orgPacks : undefined;
|
|
65
|
+
const keep = recorded === undefined && !managedRunsBootstrap(scans);
|
|
66
|
+
const hasEntry = (await readEntryVersion(paths.destDir)) !== undefined;
|
|
67
|
+
if (redactionPacks !== undefined && recorded === undefined && !hasEntry) {
|
|
68
|
+
return {
|
|
69
|
+
updated: [],
|
|
70
|
+
destDir: paths.destDir,
|
|
71
|
+
managedDelivers: false,
|
|
72
|
+
removedFromUser: 0,
|
|
73
|
+
addedToUser: 0,
|
|
74
|
+
userSettings: undefined,
|
|
75
|
+
held: 'unreadable',
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const settingsFile = paths.settingsFile ?? settingsPath();
|
|
79
|
+
let sync = 'unchanged';
|
|
80
|
+
let recordProblem;
|
|
81
|
+
const hadRecord = keep && (await hasOrgEntry(configDir, settingsFile).catch(() => false));
|
|
82
|
+
try {
|
|
83
|
+
sync = await syncOrgRedaction(configDir, keep ? KEEP_ORG_PACKS : recorded, settingsFile);
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
if (!hasEntry)
|
|
87
|
+
throw err;
|
|
88
|
+
recordProblem = err instanceof Error ? err.message : String(err);
|
|
89
|
+
}
|
|
90
|
+
const flat = recorded === undefined || recordProblem !== undefined
|
|
91
|
+
? { flat: [] }
|
|
92
|
+
: await refreshFlatCopiesForOrgPacks(paths.flatDir ?? installedHooksDir(), paths.srcDir);
|
|
93
|
+
const orgRedaction = {
|
|
94
|
+
packs: recorded,
|
|
95
|
+
sync,
|
|
96
|
+
flat: flat.flat,
|
|
97
|
+
...(keep ? { kept: { hadRecord } } : {}),
|
|
98
|
+
...(recordProblem === undefined ? {} : { recordProblem }),
|
|
99
|
+
...(flat.failed !== undefined
|
|
100
|
+
? { flatProblem: flat.failed }
|
|
101
|
+
: flat.skipped !== undefined
|
|
102
|
+
? { flatProblem: flat.skipped.map((b) => `${b.script} ${b.reason}`).join('; ') }
|
|
103
|
+
: {}),
|
|
104
|
+
};
|
|
105
|
+
const updated = await syncManagedHooks(all, paths.srcDir, paths.destDir, paths.version ?? VERSION, paths.nodePath);
|
|
41
106
|
const delivered = managedMarkerDeliveries(scans);
|
|
42
|
-
await syncOrgDelivered(managedDeliversEntry(scans),
|
|
107
|
+
await syncOrgDelivered(managedDeliversEntry(scans), configDir, paths.destDir);
|
|
43
108
|
const managedDelivers = delivered.size > 0;
|
|
44
109
|
const stored = paths.stored ?? (await readSettings().catch(() => ({}))).hooks ?? {};
|
|
45
110
|
const userSettings = adapter.paths.global;
|
|
46
111
|
const disclosed = stored.events?.[adapter.name]?.[userSettings];
|
|
47
|
-
const disclosedRoutes = stored.routes?.[adapter.name]?.[userSettings];
|
|
112
|
+
const disclosedRoutes = stored.routes?.[adapter.name]?.[userSettings] ?? ROUTES_BEFORE_RECORD;
|
|
48
113
|
let removedFromUser = 0;
|
|
49
114
|
let addedToUser = 0;
|
|
50
115
|
if ((managedDelivers || disclosed !== undefined) && hasPath(userSettings)) {
|
|
@@ -53,10 +118,7 @@ export const installHooks = async (adapter, paths = defaultPaths()) => {
|
|
|
53
118
|
: userHookGroups(matchersForTool(all, DEFAULT_MARKER_TOOL), { markers: stored.markers?.[adapter.name] ?? true }, delivered, DEFAULT_MARKER_TOOL).filter((g) => disclosed.includes(groupEvent(g)) &&
|
|
54
119
|
g.hooks.every((h) => {
|
|
55
120
|
const key = routeKeyOf(h.command);
|
|
56
|
-
return
|
|
57
|
-
(disclosedRoutes === undefined
|
|
58
|
-
? !ROUTES_BEFORE_RECORD_EXCLUDES.includes(key)
|
|
59
|
-
: disclosedRoutes.includes(key)));
|
|
121
|
+
return key === undefined || disclosedRoutes.includes(key);
|
|
60
122
|
}));
|
|
61
123
|
const { update, plan } = await prepareMarkersFile(userSettings, adapter.codec, groups, 0o600, (ownership, group) => ownership === 'cli' &&
|
|
62
124
|
((!isBootstrapCommand(group.command) &&
|
|
@@ -75,27 +137,44 @@ export const installHooks = async (adapter, paths = defaultPaths()) => {
|
|
|
75
137
|
removedFromUser,
|
|
76
138
|
addedToUser,
|
|
77
139
|
userSettings,
|
|
140
|
+
orgRedaction,
|
|
78
141
|
};
|
|
79
142
|
};
|
|
80
143
|
export const runInstallHooks = async (adapter, options = {}, paths) => {
|
|
81
144
|
let result;
|
|
82
145
|
try {
|
|
83
|
-
result = await installHooks(adapter, paths);
|
|
146
|
+
result = await installHooks(adapter, paths, { redactionPacks: options.redactionPacks });
|
|
84
147
|
}
|
|
85
148
|
catch (err) {
|
|
86
149
|
const reason = err instanceof Error ? err.message : String(err);
|
|
87
150
|
process.stderr.write(`mainwave-cli install-hooks: ${reason}\n`);
|
|
88
151
|
return 1;
|
|
89
152
|
}
|
|
153
|
+
if (result.orgRedaction?.recordProblem !== undefined) {
|
|
154
|
+
process.stderr.write(`mainwave-cli install-hooks: ${result.orgRedaction.recordProblem}\n`);
|
|
155
|
+
}
|
|
90
156
|
if (options.quiet)
|
|
91
157
|
return 0;
|
|
92
158
|
const dest = result.destDir;
|
|
159
|
+
if (result.held === 'config-dir') {
|
|
160
|
+
console.log("CLAUDE_CODE_SUBPROCESS_ENV_SCRUB hid this session's CLAUDE_CONFIG_DIR and the hook input " +
|
|
161
|
+
"didn't name it, so your organization's redaction packs couldn't be recorded. No hooks were " +
|
|
162
|
+
'installed; the next session start that names its config dir installs them.');
|
|
163
|
+
return 0;
|
|
164
|
+
}
|
|
165
|
+
if (result.held === 'unreadable') {
|
|
166
|
+
console.log('--redaction-packs names packs, but no managed settings source this command reads names ' +
|
|
167
|
+
'them (it reads neither an OS-level policy nor a server-managed cache that has not been ' +
|
|
168
|
+
'written yet), so nothing was installed.');
|
|
169
|
+
return 0;
|
|
170
|
+
}
|
|
93
171
|
console.log(result.updated.length > 0
|
|
94
172
|
? `Installed Mainwave hook scripts in ${dest}: ${result.updated.join(', ')}`
|
|
95
173
|
: `Mainwave hook scripts in ${dest} are already current.`);
|
|
96
174
|
if (result.userSettings === undefined) {
|
|
97
175
|
console.log("CLAUDE_CODE_SUBPROCESS_ENV_SCRUB hid this session's CLAUDE_CONFIG_DIR and the hook input " +
|
|
98
|
-
"didn't name it, so no Claude config dir's settings were changed
|
|
176
|
+
"didn't name it, so no Claude config dir's settings were changed" +
|
|
177
|
+
(options.redactionPacks === undefined ? '.' : ', and no redaction packs were recorded.'));
|
|
99
178
|
}
|
|
100
179
|
else if (result.removedFromUser > 0 || result.addedToUser > 0) {
|
|
101
180
|
console.log(`Updated the Mainwave hooks in ${result.userSettings}` +
|
|
@@ -106,8 +185,58 @@ export const runInstallHooks = async (adapter, options = {}, paths) => {
|
|
|
106
185
|
else if (!result.managedDelivers) {
|
|
107
186
|
console.log('No managed settings deliver the Mainwave hooks, so your user settings were left as they are.');
|
|
108
187
|
}
|
|
188
|
+
if (result.orgRedaction !== undefined) {
|
|
189
|
+
for (const line of orgRedactionLines(result.orgRedaction, options.redactionPacks)) {
|
|
190
|
+
console.log(line);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
109
193
|
return 0;
|
|
110
194
|
};
|
|
195
|
+
const orgRedactionLines = (org, asked) => {
|
|
196
|
+
const out = [];
|
|
197
|
+
const known = REDACTION_PACKS;
|
|
198
|
+
if (org.packs === undefined) {
|
|
199
|
+
if (org.kept !== undefined) {
|
|
200
|
+
const tail = org.kept.hadRecord
|
|
201
|
+
? 'so the recorded packs were kept.'
|
|
202
|
+
: 'so no packs are recorded, so none apply.';
|
|
203
|
+
if (asked !== undefined) {
|
|
204
|
+
out.push('--redaction-packs names packs, but no managed settings source this command reads names ' +
|
|
205
|
+
`them, ${tail}`);
|
|
206
|
+
}
|
|
207
|
+
else if (org.kept.hadRecord) {
|
|
208
|
+
out.push(`No managed settings source this command reads runs the Mainwave bootstrap, ${tail}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
else if (asked !== undefined) {
|
|
212
|
+
out.push("--redaction-packs is read from your organization's managed settings, which name none, " +
|
|
213
|
+
'so no redaction packs were recorded.');
|
|
214
|
+
}
|
|
215
|
+
if (org.sync === 'cleared') {
|
|
216
|
+
out.push("Your organization's managed settings no longer set redaction packs; cleared them.");
|
|
217
|
+
}
|
|
218
|
+
return out;
|
|
219
|
+
}
|
|
220
|
+
if (org.sync === 'set') {
|
|
221
|
+
out.push(`Recorded your organization's redaction packs: ${org.packs.join(', ')}.`);
|
|
222
|
+
}
|
|
223
|
+
if (asked !== undefined && asked.join(',') !== org.packs.join(',')) {
|
|
224
|
+
out.push(`Your organization's managed settings name ${org.packs.join(', ')}; those apply, not --redaction-packs.`);
|
|
225
|
+
}
|
|
226
|
+
const unknown = org.packs.filter((name) => !known.includes(name));
|
|
227
|
+
if (unknown.length > 0) {
|
|
228
|
+
out.push(`This release has no redaction pack ${unknown.join(', ')}, so the Mainwave hooks send nothing ` +
|
|
229
|
+
'until one that has them is installed.');
|
|
230
|
+
}
|
|
231
|
+
if (org.flat.length > 0) {
|
|
232
|
+
out.push('Refreshed the Cursor and Kiro hook copies so they apply the packs.');
|
|
233
|
+
}
|
|
234
|
+
if (org.flatProblem !== undefined) {
|
|
235
|
+
out.push(`The Cursor and Kiro hook copies predate redaction packs and were not refreshed (${org.flatProblem}); ` +
|
|
236
|
+
'they send spans without the packs until setup is re-run.');
|
|
237
|
+
}
|
|
238
|
+
return out;
|
|
239
|
+
};
|
|
111
240
|
const HOOK_INPUT_CAP = 1024 * 1024;
|
|
112
241
|
const HOOK_INPUT_WAIT_MS = 2000;
|
|
113
242
|
const TRUTHY = new Set(['1', 'true', 'yes', 'on']);
|
package/dist/core/interview.js
CHANGED
|
@@ -8,7 +8,7 @@ import { promptApiKey, promptCollectorUrl, promptUserEmail } from './prompts.js'
|
|
|
8
8
|
import { storedKeyFor } from './store.js';
|
|
9
9
|
import { say } from './ui.js';
|
|
10
10
|
import { resolveUseCase } from './use-case.js';
|
|
11
|
-
|
|
11
|
+
const DEFAULT_COLLECTOR_URL = 'https://collector.mainwave.com';
|
|
12
12
|
const missing = (what, flag) => new WizardAbort(`${what} is required in a non-interactive run — pass ${flag}`);
|
|
13
13
|
const resolveApiKey = async (input) => {
|
|
14
14
|
if (input.overrides.apiKey)
|
|
@@ -92,7 +92,7 @@ const resolveAdapterEmails = async (input, identityAdapters, general, toolEmail)
|
|
|
92
92
|
}
|
|
93
93
|
return Object.fromEntries(tools.map((a) => [a.name, chosen]));
|
|
94
94
|
};
|
|
95
|
-
|
|
95
|
+
const noIdentityWarning = (headerTools, nonOauth) => {
|
|
96
96
|
const names = [
|
|
97
97
|
...headerTools.map((a) => a.displayName),
|
|
98
98
|
...nonOauth.map(({ adapter, reason }) => `${adapter.displayName} (${reason})`),
|
|
@@ -166,6 +166,12 @@ const sayCaptureNotice = (optIns, adapters, explicit) => {
|
|
|
166
166
|
: undefined,
|
|
167
167
|
optIns.toolDetails ? 'shell commands and file paths' : undefined,
|
|
168
168
|
optIns.toolContent ? 'tool result bodies' : undefined,
|
|
169
|
+
optIns.userPrompts &&
|
|
170
|
+
optIns.toolDetails &&
|
|
171
|
+
optIns.toolContent &&
|
|
172
|
+
adapters.some((a) => a.name === 'claude-desktop')
|
|
173
|
+
? 'raw model request and response bodies, system prompts included (Claude Desktop)'
|
|
174
|
+
: undefined,
|
|
169
175
|
optIns.repository && adapters.some((a) => a.name === 'claude-code')
|
|
170
176
|
? 'repository names (Claude Code)'
|
|
171
177
|
: undefined,
|
package/dist/core/markers.js
CHANGED
|
@@ -7,6 +7,7 @@ import { dropInNames } from './effective-settings.js';
|
|
|
7
7
|
import { GIT_BASH_FIX, GIT_BASH_MISSING_REASON } from './git-bash.js';
|
|
8
8
|
import { entryCommand, entryVersionId, HOOK_DISPATCHER_SCRIPT, HOOK_ENTRY_SCRIPT, HOOK_NODE_ENTRY_SCRIPT, nodeEntryCommand, ORG_DELIVERED_MARK, parseEntryCommand, renderHookEntry, } from './entry-script.js';
|
|
9
9
|
import { isManagedLayer, isPolicyKey } from './layer-policy.js';
|
|
10
|
+
import { canonicalPacks, packOrder } from './redaction.js';
|
|
10
11
|
export const MANAGED_BY = '--managed-by @mainwave/cli';
|
|
11
12
|
export const PAYLOAD_CLI_SPEC = 'latest';
|
|
12
13
|
const OWNED_CLI_MARKERS = [MANAGED_BY, '.mainwave/hooks', '.mainwave\\hooks'];
|
|
@@ -29,13 +30,13 @@ export const commandGeneration = (command) => command.includes(HOOK_ENTRY_SCRIPT
|
|
|
29
30
|
: BOOTSTRAP_RE.test(command)
|
|
30
31
|
? 'bootstrap'
|
|
31
32
|
: 'legacy';
|
|
32
|
-
|
|
33
|
+
const INSTALLED_HOOK_EVENTS = [
|
|
33
34
|
'SessionStart',
|
|
34
35
|
'UserPromptSubmit',
|
|
35
36
|
'PostToolUse',
|
|
36
37
|
'StopFailure',
|
|
37
38
|
];
|
|
38
|
-
|
|
39
|
+
const MARKER_HOOK_EVENTS = INSTALLED_HOOK_EVENTS;
|
|
39
40
|
const ENTRY_EVENTS = [
|
|
40
41
|
'UserPromptSubmit',
|
|
41
42
|
'PostToolUse',
|
|
@@ -63,15 +64,31 @@ export const shellHome = (plat = process.platform, env = process.env, dirExists
|
|
|
63
64
|
return drivePath;
|
|
64
65
|
return env.USERPROFILE || homedir();
|
|
65
66
|
};
|
|
66
|
-
export const installHooksCommand = (version, { quiet = true } = {}) => `cd "$HOME" && npx -y --registry=https://registry.npmjs.org ` +
|
|
67
|
-
`@mainwave/cli@${version} install-hooks${quiet ? ' --quiet' : ''}
|
|
68
|
-
|
|
67
|
+
export const installHooksCommand = (version, { quiet = true, redactionPacks = [], } = {}) => `cd "$HOME" && npx -y --registry=https://registry.npmjs.org ` +
|
|
68
|
+
`@mainwave/cli@${version} install-hooks${quiet ? ' --quiet' : ''}` +
|
|
69
|
+
(redactionPacks.length > 0
|
|
70
|
+
? ` ${REDACTION_PACKS_FLAG} ${canonicalPacks(redactionPacks).join(',')}`
|
|
71
|
+
: '');
|
|
72
|
+
export const bootstrapCommand = (version, redactionPacks = []) => `{ ${installHooksCommand(version, { redactionPacks })}; } >/dev/null 2>&1; exit 0`;
|
|
73
|
+
const REDACTION_PACKS_FLAG = '--redaction-packs';
|
|
74
|
+
export const redactionPacksIn = (command) => {
|
|
75
|
+
const args = /\binstall-hooks\b([^;}]*)/.exec(command)?.[1];
|
|
76
|
+
if (args === undefined)
|
|
77
|
+
return undefined;
|
|
78
|
+
const found = /(?:^|\s)--redaction-packs(?:=|\s+)('[^']*'|"[^"]*"|[^\s'"]+)/.exec(args);
|
|
79
|
+
if (found === null)
|
|
80
|
+
return undefined;
|
|
81
|
+
const value = found[1].replace(/^(['"])(.*)\1$/, '$2');
|
|
82
|
+
return [...new Set(value.split(',').map((n) => n.trim()))].filter((n) => n !== '');
|
|
83
|
+
};
|
|
69
84
|
export const BOOTSTRAP_MATCHER = 'startup|resume|fork';
|
|
70
85
|
export const BOOTSTRAP_KEY = 'SessionStart:bootstrap';
|
|
71
|
-
export const bootstrapGroup = () => ({
|
|
86
|
+
export const bootstrapGroup = (redactionPacks = []) => ({
|
|
72
87
|
event: 'SessionStart',
|
|
73
88
|
matcher: BOOTSTRAP_MATCHER,
|
|
74
|
-
hooks: [
|
|
89
|
+
hooks: [
|
|
90
|
+
{ type: 'command', command: bootstrapCommand(PAYLOAD_CLI_SPEC, redactionPacks), async: true },
|
|
91
|
+
],
|
|
75
92
|
});
|
|
76
93
|
const SAFE_ROUTE = /^[a-z][a-z0-9-]*$/;
|
|
77
94
|
export const readPackagedMatchers = async (dir = packagedHooksDir()) => {
|
|
@@ -138,8 +155,20 @@ export const readPackagedMatchers = async (dir = packagedHooksDir()) => {
|
|
|
138
155
|
};
|
|
139
156
|
});
|
|
140
157
|
};
|
|
141
|
-
const
|
|
142
|
-
|
|
158
|
+
export const REDACTION_HOOK_MODULES = [
|
|
159
|
+
'redaction.mjs',
|
|
160
|
+
'redaction-pattern.mjs',
|
|
161
|
+
'redaction-json.mjs',
|
|
162
|
+
'redaction-data.mjs',
|
|
163
|
+
];
|
|
164
|
+
export const lacksRedactionModules = (dir) => REDACTION_HOOK_MODULES.every((f) => !existsSync(join(dir, f)));
|
|
165
|
+
const SHARED_HOOK_MODULES = [
|
|
166
|
+
'marker-core.mjs',
|
|
167
|
+
'vocabulary.mjs',
|
|
168
|
+
...REDACTION_HOOK_MODULES,
|
|
169
|
+
HOOK_DISPATCHER_SCRIPT,
|
|
170
|
+
];
|
|
171
|
+
const featureModule = (feature) => `${feature}.mjs`;
|
|
143
172
|
export const hookScriptFiles = (matchers) => [
|
|
144
173
|
...SHARED_HOOK_MODULES,
|
|
145
174
|
...new Set(matchers.flatMap((m) => m.features.map(featureModule))),
|
|
@@ -154,8 +183,8 @@ export const copyHookScripts = async (files, srcDir = packagedHooksDir(), destDi
|
|
|
154
183
|
}
|
|
155
184
|
return destDir;
|
|
156
185
|
};
|
|
157
|
-
|
|
158
|
-
|
|
186
|
+
const MANAGED_POINTER = 'current.json';
|
|
187
|
+
const MANAGED_VERSIONS_DIR = 'versions';
|
|
159
188
|
export const MANAGED_ENTRY_SCRIPT = 'managed-entry.mjs';
|
|
160
189
|
const MANAGED_ENTRY_MARK = 'mainwave managed hook entry';
|
|
161
190
|
const RETIRED_GRACE_MS = 10 * 60 * 1000;
|
|
@@ -172,7 +201,7 @@ const LEGACY_SCRIPT_ROUTES = {
|
|
|
172
201
|
'glab-mr-marker.mjs': { event: 'PostToolUse', route: 'glab' },
|
|
173
202
|
'claude-plan-snapshot.mjs': { event: 'UserPromptSubmit' },
|
|
174
203
|
};
|
|
175
|
-
|
|
204
|
+
const legacyScriptReleased = (name) => LEGACY_ENTRY_NAMES.includes(name);
|
|
176
205
|
const VERSION_DIR_RE = /^[A-Za-z0-9][A-Za-z0-9._+-]*$/;
|
|
177
206
|
const versionDirName = (version, files, bodies) => {
|
|
178
207
|
const hash = createHash('sha256');
|
|
@@ -206,6 +235,15 @@ export const readEntryVersion = async (destDir) => {
|
|
|
206
235
|
const text = await fs.readFile(join(destDir, HOOK_ENTRY_SCRIPT), 'utf8').catch(() => null);
|
|
207
236
|
return text === null ? undefined : entryVersionId(text);
|
|
208
237
|
};
|
|
238
|
+
export const releaseBeforeRedaction = async (destDir) => {
|
|
239
|
+
const id = await readEntryVersion(destDir);
|
|
240
|
+
if (id === undefined)
|
|
241
|
+
return undefined;
|
|
242
|
+
const dir = join(destDir, MANAGED_VERSIONS_DIR, id);
|
|
243
|
+
if (!existsSync(join(dir, HOOK_DISPATCHER_SCRIPT)))
|
|
244
|
+
return undefined;
|
|
245
|
+
return lacksRedactionModules(dir) ? { id, dir } : undefined;
|
|
246
|
+
};
|
|
209
247
|
export const stageManagedVersion = async (files, srcDir, destDir, version) => {
|
|
210
248
|
const bodies = await Promise.all(files.map((f) => fs.readFile(join(srcDir, f))));
|
|
211
249
|
const id = versionDirName(version, files, bodies);
|
|
@@ -288,7 +326,7 @@ export const writeHookEntry = async (staged, destDir, routes, nodePath = process
|
|
|
288
326
|
await retire(destDir, previous, staged.id);
|
|
289
327
|
return true;
|
|
290
328
|
};
|
|
291
|
-
|
|
329
|
+
const writeNodeEntry = async (srcDir, destDir) => {
|
|
292
330
|
const body = await fs.readFile(join(srcDir, HOOK_NODE_ENTRY_SCRIPT));
|
|
293
331
|
const path = join(destDir, HOOK_NODE_ENTRY_SCRIPT);
|
|
294
332
|
const current = await fs.readFile(path).catch(() => null);
|
|
@@ -381,7 +419,7 @@ export const resolveManagedScript = async (script) => {
|
|
|
381
419
|
const target = join(dirname(script), MANAGED_VERSIONS_DIR, dir, basename(script));
|
|
382
420
|
return existsSync(target) ? target : undefined;
|
|
383
421
|
};
|
|
384
|
-
|
|
422
|
+
const hooksRootDir = (managedDir = managedHooksDir()) => dirname(managedDir);
|
|
385
423
|
export const optOutFlagPath = (host, optOut, root = hooksRootDir()) => join(root, 'off', host, optOut);
|
|
386
424
|
export const writeOptOutFlags = async (host, on, root = hooksRootDir()) => {
|
|
387
425
|
for (const [optOut, enabled] of Object.entries(on)) {
|
|
@@ -508,7 +546,7 @@ export const ownedGroupsInDoc = (doc) => {
|
|
|
508
546
|
}
|
|
509
547
|
return out;
|
|
510
548
|
};
|
|
511
|
-
|
|
549
|
+
const malformedEventMessage = (event) => `\`hooks.${event}\` in the settings file is not an array, so Mainwave left it untouched and installed no ${event} hook there. ` +
|
|
512
550
|
'Fix or remove that value, then re-run setup.';
|
|
513
551
|
const effectiveMatcher = (matcher) => matcher === undefined || matcher === '' || matcher === '*' ? NO_MATCHER : matcher;
|
|
514
552
|
const sameGroup = (before, after) => before.event === groupEvent(after) &&
|
|
@@ -774,6 +812,17 @@ export const managedMarkerDeliveries = (scans) => new Set(activeManagedScans(sca
|
|
|
774
812
|
const key = routeKeyOf(g.command);
|
|
775
813
|
return key === undefined ? [] : [key];
|
|
776
814
|
})));
|
|
815
|
+
const managedBootstraps = (scans) => activeManagedScans(scans)
|
|
816
|
+
.filter((s) => s.managed)
|
|
817
|
+
.flatMap((s) => s.groups)
|
|
818
|
+
.filter((g) => g.ownership === 'cli' && g.event === 'SessionStart' && isBootstrapCommand(g.command));
|
|
819
|
+
export const managedRedactionPacks = (scans) => {
|
|
820
|
+
const named = managedBootstraps(scans)
|
|
821
|
+
.map((g) => redactionPacksIn(g.command))
|
|
822
|
+
.filter((packs) => packs !== undefined);
|
|
823
|
+
return named.length === 0 ? undefined : packOrder(named.flat());
|
|
824
|
+
};
|
|
825
|
+
export const managedRunsBootstrap = (scans) => managedBootstraps(scans).length > 0;
|
|
777
826
|
export const scanRoutes = (scan, host = DEFAULT_MARKER_TOOL) => [
|
|
778
827
|
...new Set(scan.groups
|
|
779
828
|
.filter((g) => g.ownership === 'cli')
|
|
@@ -1076,7 +1125,7 @@ export const collectMarkerIssues = async (scans, currentVersion, matchers, skipp
|
|
|
1076
1125
|
if (!entryChecked) {
|
|
1077
1126
|
entryChecked = true;
|
|
1078
1127
|
const nodeEntry = cli.some((c) => c.command.includes(HOOK_NODE_ENTRY_SCRIPT));
|
|
1079
|
-
issues.push(...(await entryIssues(layout.managedDir, matchers, g.managed, nodeEntry)));
|
|
1128
|
+
issues.push(...(await entryIssues(layout.managedDir, matchers, g.managed, nodeEntry, layout.redaction ?? 'off')));
|
|
1080
1129
|
}
|
|
1081
1130
|
}
|
|
1082
1131
|
const anyCurrent = cli.some((g) => commandGeneration(g.command) === 'entry');
|
|
@@ -1111,7 +1160,7 @@ export const collectMarkerIssues = async (scans, currentVersion, matchers, skipp
|
|
|
1111
1160
|
}
|
|
1112
1161
|
return issues;
|
|
1113
1162
|
};
|
|
1114
|
-
|
|
1163
|
+
const entryIssues = async (managedDir, matchers, managed, nodeEntry = false, redaction = 'off') => {
|
|
1115
1164
|
const entry = join(managedDir, HOOK_ENTRY_SCRIPT);
|
|
1116
1165
|
const fix = managed
|
|
1117
1166
|
? 'Start a new Claude Code session (the managed settings install it at startup), or ' +
|
|
@@ -1139,12 +1188,27 @@ export const entryIssues = async (managedDir, matchers, managed, nodeEntry = fal
|
|
|
1139
1188
|
}
|
|
1140
1189
|
const missing = hookScriptFiles(matchers).filter((f) => !existsSync(join(release, f)));
|
|
1141
1190
|
if (missing.length > 0) {
|
|
1142
|
-
|
|
1143
|
-
|
|
1191
|
+
const predates = lacksRedactionModules(release);
|
|
1192
|
+
const redactionModules = REDACTION_HOOK_MODULES;
|
|
1193
|
+
const rest = predates ? missing.filter((f) => !redactionModules.includes(f)) : missing;
|
|
1194
|
+
const found = [];
|
|
1195
|
+
if (predates && redaction !== 'off') {
|
|
1196
|
+
found.push({
|
|
1197
|
+
level: redaction === 'file' ? 'error' : 'warn',
|
|
1198
|
+
message: `Release ${id} of the Mainwave hooks predates redaction (it lacks ${REDACTION_HOOK_MODULES.join(', ')}), so its hooks send spans without applying redaction rules` +
|
|
1199
|
+
(redaction === 'file'
|
|
1200
|
+
? ', although redaction is on'
|
|
1201
|
+
: ', although credential redaction is on by default') +
|
|
1202
|
+
`. ${fix}`,
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
if (rest.length > 0) {
|
|
1206
|
+
found.push({
|
|
1144
1207
|
level: 'warn',
|
|
1145
|
-
message: `Release ${id} of the Mainwave hooks lacks ${
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1208
|
+
message: `Release ${id} of the Mainwave hooks lacks ${rest.join(', ')}, so the hooks that need ${rest.length === 1 ? 'it' : 'them'} send nothing until a newer release is installed. ${fix}`,
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
return found;
|
|
1148
1212
|
}
|
|
1149
1213
|
const node = join(managedDir, HOOK_NODE_ENTRY_SCRIPT);
|
|
1150
1214
|
if (nodeEntry && !existsSync(node)) {
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
2
|
+
import { loadHookRedaction, readRedactionFile, recordedOrgPacks, REDACTION_PACKS, } from '../../hooks/redaction.mjs';
|
|
3
|
+
import { tildify } from './post-setup.js';
|
|
4
|
+
export const canonicalPacks = (names) => {
|
|
5
|
+
if (names.length === 0)
|
|
6
|
+
throw new Error('no redaction pack named');
|
|
7
|
+
const known = REDACTION_PACKS;
|
|
8
|
+
const seen = new Set();
|
|
9
|
+
for (const name of names) {
|
|
10
|
+
if (!known.includes(name)) {
|
|
11
|
+
throw new Error(`unknown redaction pack ${JSON.stringify(name)} (known: ${REDACTION_PACKS.join(', ')})`);
|
|
12
|
+
}
|
|
13
|
+
if (seen.has(name))
|
|
14
|
+
throw new Error(`redaction pack ${JSON.stringify(name)} is named twice`);
|
|
15
|
+
seen.add(name);
|
|
16
|
+
}
|
|
17
|
+
return REDACTION_PACKS.filter((name) => seen.has(name));
|
|
18
|
+
};
|
|
19
|
+
export const packOrder = (names) => {
|
|
20
|
+
const known = REDACTION_PACKS;
|
|
21
|
+
return [
|
|
22
|
+
...known.filter((name) => names.includes(name)),
|
|
23
|
+
...new Set(names.filter((name) => !known.includes(name))),
|
|
24
|
+
];
|
|
25
|
+
};
|
|
26
|
+
export const parseRedactionPacks = (value) => {
|
|
27
|
+
if (value === undefined || value.trim() === '') {
|
|
28
|
+
throw new Error(`--redaction-packs requires a comma-separated list of packs (${REDACTION_PACKS.join(', ')})`);
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
return canonicalPacks(value.split(',').map((name) => name.trim()));
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
throw new Error(`--redaction-packs: ${err instanceof Error ? err.message : String(err)}`);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export const redactionView = ({ configDir } = {}) => {
|
|
38
|
+
const loaded = loadHookRedaction({ configDir });
|
|
39
|
+
const configDirs = recordedOrgPacks();
|
|
40
|
+
const scoped = configDir === undefined
|
|
41
|
+
? packOrder(Object.values(configDirs).flat())
|
|
42
|
+
: packOrder(Object.entries(configDirs)
|
|
43
|
+
.filter(([dir]) => isAbsolute(dir) && resolve(dir) === resolve(configDir))
|
|
44
|
+
.flatMap(([, packs]) => packs));
|
|
45
|
+
const org = Object.keys(configDirs).length === 0
|
|
46
|
+
? {}
|
|
47
|
+
: {
|
|
48
|
+
org: {
|
|
49
|
+
setBy: 'managed-settings',
|
|
50
|
+
packs: scoped,
|
|
51
|
+
...(configDir === undefined ? {} : { configDir }),
|
|
52
|
+
configDirs,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
if (loaded.state === 'off')
|
|
56
|
+
return { state: 'off', reason: 'secrets-off', ...org };
|
|
57
|
+
if (loaded.state === 'error') {
|
|
58
|
+
return {
|
|
59
|
+
state: 'error',
|
|
60
|
+
...(loaded.file === undefined ? {} : { file: loaded.file }),
|
|
61
|
+
...(loaded.org === true ? { cause: 'org' } : {}),
|
|
62
|
+
reason: loaded.reason,
|
|
63
|
+
...org,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
state: 'on',
|
|
68
|
+
source: loaded.source,
|
|
69
|
+
...(loaded.source === 'file' ? { file: loaded.file } : {}),
|
|
70
|
+
packs: loaded.redactor.packs,
|
|
71
|
+
summary: loaded.redactor.summary,
|
|
72
|
+
...org,
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
export const hasRulesFile = (view) => view.state === 'error' || (view.state === 'on' && view.source === 'file');
|
|
76
|
+
export const checkRedactionFile = (path) => {
|
|
77
|
+
const file = resolve(path);
|
|
78
|
+
readRedactionFile(file);
|
|
79
|
+
return file;
|
|
80
|
+
};
|
|
81
|
+
export const nextRedactionChoice = (current, change) => {
|
|
82
|
+
if (change.file === undefined && change.noRedaction !== true && change.secrets === undefined) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
const base = typeof current === 'object' && current !== null && !Array.isArray(current);
|
|
86
|
+
const next = base ? { ...current } : {};
|
|
87
|
+
if (change.file !== undefined)
|
|
88
|
+
next.file = change.file;
|
|
89
|
+
else if (change.noRedaction === true)
|
|
90
|
+
delete next.file;
|
|
91
|
+
if (change.secrets === false)
|
|
92
|
+
next.secrets = false;
|
|
93
|
+
else if (change.secrets === true)
|
|
94
|
+
delete next.secrets;
|
|
95
|
+
return Object.keys(next).length === 0 ? null : next;
|
|
96
|
+
};
|
|
97
|
+
const SET_BY_ORG = "set by your organization's managed settings";
|
|
98
|
+
const orgLines = (org, indent) => {
|
|
99
|
+
if (org === undefined)
|
|
100
|
+
return [];
|
|
101
|
+
if (org.configDir !== undefined) {
|
|
102
|
+
return org.packs.length === 0
|
|
103
|
+
? []
|
|
104
|
+
: [`${indent} organization packs: ${org.packs.join(', ')} (${SET_BY_ORG})`];
|
|
105
|
+
}
|
|
106
|
+
const dirs = Object.entries(org.configDirs);
|
|
107
|
+
return [
|
|
108
|
+
`${indent} organization packs (${SET_BY_ORG}), by Claude config dir:`,
|
|
109
|
+
...dirs.map(([dir, packs]) => `${indent} ${tildify(dir)}: ${packs.join(', ')}`),
|
|
110
|
+
];
|
|
111
|
+
};
|
|
112
|
+
export const redactionLines = (view, indent = '') => {
|
|
113
|
+
if (view.state === 'off') {
|
|
114
|
+
return [
|
|
115
|
+
`${indent}off (secrets turned off)`,
|
|
116
|
+
`${indent} credentials are not stripped; run setup with --redact-secrets to turn the default back on`,
|
|
117
|
+
...orgLines(view.org, indent),
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
if (view.state === 'error') {
|
|
121
|
+
return [
|
|
122
|
+
`${indent}error — hooks send nothing until it is fixed`,
|
|
123
|
+
...(view.file === undefined ? [] : [`${indent} rules file: ${tildify(view.file)}`]),
|
|
124
|
+
`${indent} ${view.reason}`,
|
|
125
|
+
...orgLines(view.org, indent),
|
|
126
|
+
];
|
|
127
|
+
}
|
|
128
|
+
return [
|
|
129
|
+
view.file === undefined && (view.org?.packs.length ?? 0) === 0
|
|
130
|
+
? `${indent}on (default)`
|
|
131
|
+
: `${indent}on`,
|
|
132
|
+
...(view.file === undefined ? [] : [`${indent} rules file: ${tildify(view.file)}`]),
|
|
133
|
+
`${indent} packs: ${view.packs.length > 0 ? view.packs.join(', ') : 'none'}`,
|
|
134
|
+
...orgLines(view.org, indent),
|
|
135
|
+
`${indent} summary: ${view.summary}`,
|
|
136
|
+
];
|
|
137
|
+
};
|
|
138
|
+
const PROBE = {
|
|
139
|
+
collectorUrl: 'https://collector.invalid',
|
|
140
|
+
apiKey: 'redaction-probe',
|
|
141
|
+
};
|
|
142
|
+
const carriesOptIns = (adapter) => {
|
|
143
|
+
const all = (on) => ({
|
|
144
|
+
userPrompts: on,
|
|
145
|
+
toolDetails: on,
|
|
146
|
+
toolContent: on,
|
|
147
|
+
repository: on,
|
|
148
|
+
});
|
|
149
|
+
const build = (on) => JSON.stringify(adapter.buildEnv({ ...PROBE, optIns: all(on) }));
|
|
150
|
+
return build(true) !== build(false);
|
|
151
|
+
};
|
|
152
|
+
const exportsNatively = (adapter) => adapter.bundledHookScripts === undefined;
|
|
153
|
+
export const sendsUnredactedContent = (adapter, optIns) => {
|
|
154
|
+
if (!exportsNatively(adapter))
|
|
155
|
+
return false;
|
|
156
|
+
if (!carriesOptIns(adapter))
|
|
157
|
+
return true;
|
|
158
|
+
if (optIns === undefined)
|
|
159
|
+
return false;
|
|
160
|
+
return (optIns.userPrompts || optIns.toolDetails || optIns.toolContent || optIns.repository === true);
|
|
161
|
+
};
|
|
162
|
+
const list = (names) => names.length <= 2 ? names.join(' and ') : `${names.slice(0, -1).join(', ')} and ${names.at(-1)}`;
|
|
163
|
+
export const uncoveredNotice = (uncovered) => {
|
|
164
|
+
const names = uncovered.map((a) => a.displayName);
|
|
165
|
+
const switchable = uncovered.filter(carriesOptIns).map((a) => a.displayName);
|
|
166
|
+
const fixed = uncovered.filter((a) => !carriesOptIns(a)).map((a) => a.displayName);
|
|
167
|
+
return [
|
|
168
|
+
`Redaction covers the spans mainwave-cli's hooks send. ${list(names)} ` +
|
|
169
|
+
`${names.length === 1 ? 'exports' : 'export'} content through ` +
|
|
170
|
+
`${names.length === 1 ? 'its' : 'their'} own OpenTelemetry exporter, which the CLI is not in the ` +
|
|
171
|
+
'path of, so that content is not redacted.',
|
|
172
|
+
...(switchable.length > 0
|
|
173
|
+
? [`Run setup with --opt-in none to stop ${list(switchable)} sending content.`]
|
|
174
|
+
: []),
|
|
175
|
+
...(fixed.length > 0
|
|
176
|
+
? [`${list(fixed)}: what it exports is set where its export is configured, not by --opt-in.`]
|
|
177
|
+
: []),
|
|
178
|
+
].join(' ');
|
|
179
|
+
};
|