@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
package/dist/commands.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { flagBool, flagValue, hasFlag } from './core/flags.js';
|
|
2
|
+
const f = (spelling, hidden) => hidden ? { spelling, hidden } : { spelling };
|
|
3
|
+
const removed = (spelling) => ({ spelling, hidden: true, removed: true });
|
|
4
|
+
export const COMMANDS = [
|
|
5
|
+
{
|
|
6
|
+
name: 'login',
|
|
7
|
+
usage: '[--password] [--device] [--no-browser] [--api-url <u>] [--json]',
|
|
8
|
+
summary: [
|
|
9
|
+
'sign in to Mainwave: shows a code and opens the app to',
|
|
10
|
+
'approve it. --password uses email + password instead',
|
|
11
|
+
'(MAINWAVE_EMAIL / MAINWAVE_PASSWORD drive it',
|
|
12
|
+
'non-interactively); --device forces the browser flow',
|
|
13
|
+
'without a terminal (coding agents); --no-browser',
|
|
14
|
+
'prints the URL',
|
|
15
|
+
],
|
|
16
|
+
adapters: 'none',
|
|
17
|
+
flags: [
|
|
18
|
+
f('--password'),
|
|
19
|
+
f('--device'),
|
|
20
|
+
f('--no-browser'),
|
|
21
|
+
f('--api-url'),
|
|
22
|
+
f('--json'),
|
|
23
|
+
f('--email', true),
|
|
24
|
+
f('--device-timeout', true),
|
|
25
|
+
f('--force', true),
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'logout',
|
|
30
|
+
usage: '',
|
|
31
|
+
summary: ['forget the stored session'],
|
|
32
|
+
adapters: 'none',
|
|
33
|
+
flags: [f('--json', true)],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'whoami',
|
|
37
|
+
usage: '[--json]',
|
|
38
|
+
summary: ['print the signed-in user, org, and endpoints'],
|
|
39
|
+
adapters: 'none',
|
|
40
|
+
flags: [f('--api-url', true), f('--json')],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'setup',
|
|
44
|
+
usage: '[<adapter>...]',
|
|
45
|
+
summary: [
|
|
46
|
+
'run the interactive setup wizard; with no adapter,',
|
|
47
|
+
'every detected tool is configured and the rest are',
|
|
48
|
+
'offered, and with several, configure them all in',
|
|
49
|
+
'one pass. Always writes user-global config',
|
|
50
|
+
],
|
|
51
|
+
adapters: 'many',
|
|
52
|
+
details: [
|
|
53
|
+
'Setup flags (every prompt has one, so scripts and coding agents can drive it):',
|
|
54
|
+
' --api-key <k> --collector-url <u> --api-url <u>',
|
|
55
|
+
' --ucid <id|url> --use-case <name> pin every tool to one use case (by default none',
|
|
56
|
+
" is written: each tool's activity is attributed at ingest",
|
|
57
|
+
' from your identity). A pin survives later default runs;',
|
|
58
|
+
' --no-use-case removes it',
|
|
59
|
+
' --email <e> --new-key',
|
|
60
|
+
' --invite <token> redeem an account-less developer invite: no login, no key',
|
|
61
|
+
' to paste — the token brings its own key, collector, and',
|
|
62
|
+
' identity (mutually exclusive with --api-key/--ucid/--use-case)',
|
|
63
|
+
' --opt-in prompts,tool-details,tool-content,repository|all|none content capture',
|
|
64
|
+
' (default: all on — "--opt-in none" sends metadata only;',
|
|
65
|
+
' repository = repository names on Claude Code telemetry)',
|
|
66
|
+
' --no-markers skip the Mainwave hooks (installed by default): the ticket',
|
|
67
|
+
' & PR markers and, for Claude Code, the plan snapshot',
|
|
68
|
+
' --redaction-file <path> redact the spans the Mainwave hooks send with the rules in',
|
|
69
|
+
' this JSON file, the format the Mainwave SDKs read (flag only:',
|
|
70
|
+
' no prompt). Setup records the path, not a copy, so edits',
|
|
71
|
+
' apply at the next hook run; a file that goes missing or',
|
|
72
|
+
' invalid makes the hooks send nothing. Content a tool exports',
|
|
73
|
+
' through its own OpenTelemetry exporter is not covered:',
|
|
74
|
+
' use --opt-in none to stop sending it',
|
|
75
|
+
' --no-redaction remove the recorded rules file (a run with neither flag keeps it);',
|
|
76
|
+
' the hooks still strip credentials by default',
|
|
77
|
+
' --no-redact-secrets stop stripping credentials (API keys, tokens, private keys) from',
|
|
78
|
+
' the spans the hooks send; --redact-secrets restores the default',
|
|
79
|
+
' --yes --json --no-verify --verify-timeout <seconds>',
|
|
80
|
+
' --skills / --no-skills install the agent skills payload (default: ask, or on in scripts)',
|
|
81
|
+
' --skills-only install only the skills, touching no telemetry config',
|
|
82
|
+
" --remove take this CLI's config for the named tools back off this",
|
|
83
|
+
' machine (Kiro: its hooks file entries and kiro.env)',
|
|
84
|
+
],
|
|
85
|
+
flags: [
|
|
86
|
+
f('--api-key'),
|
|
87
|
+
f('--collector-url'),
|
|
88
|
+
f('--api-url'),
|
|
89
|
+
f('--ucid'),
|
|
90
|
+
f('--use-case'),
|
|
91
|
+
f('--no-use-case'),
|
|
92
|
+
f('--email'),
|
|
93
|
+
f('--new-key'),
|
|
94
|
+
f('--invite'),
|
|
95
|
+
f('--opt-in'),
|
|
96
|
+
f('--no-markers'),
|
|
97
|
+
f('--redaction-file'),
|
|
98
|
+
f('--no-redaction'),
|
|
99
|
+
f('--redact-secrets'),
|
|
100
|
+
f('--no-redact-secrets'),
|
|
101
|
+
f('--yes'),
|
|
102
|
+
f('--json'),
|
|
103
|
+
f('--no-verify'),
|
|
104
|
+
f('--verify-timeout'),
|
|
105
|
+
f('--skills'),
|
|
106
|
+
f('--no-skills'),
|
|
107
|
+
f('--skills-only'),
|
|
108
|
+
f('--remove'),
|
|
109
|
+
removed('--scope'),
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: 'verify',
|
|
114
|
+
usage: '[--ucid <id|url>] [--no-sample] [--timeout <s>] [--json]',
|
|
115
|
+
summary: [
|
|
116
|
+
'push a sample trace and wait for it to land, then',
|
|
117
|
+
'print where your activity appears',
|
|
118
|
+
],
|
|
119
|
+
adapters: 'none',
|
|
120
|
+
flags: [
|
|
121
|
+
f('--ucid'),
|
|
122
|
+
f('--no-sample'),
|
|
123
|
+
f('--timeout'),
|
|
124
|
+
f('--json'),
|
|
125
|
+
f('--api-url', true),
|
|
126
|
+
f('--collector-url', true),
|
|
127
|
+
f('--api-key', true),
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'status',
|
|
132
|
+
usage: '[<adapter>] [--json]',
|
|
133
|
+
summary: ['show current on-disk config for all (or one) adapter'],
|
|
134
|
+
adapters: 'optional',
|
|
135
|
+
flags: [f('--json')],
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: 'edit',
|
|
139
|
+
usage: '<adapter> [--local|--global]',
|
|
140
|
+
summary: [
|
|
141
|
+
'open a settings file in $EDITOR (interactive picker by default;',
|
|
142
|
+
'flag is required in non-TTY)',
|
|
143
|
+
],
|
|
144
|
+
adapters: 'one',
|
|
145
|
+
flags: [f('--local'), f('--global')],
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
name: 'doctor',
|
|
149
|
+
usage: '<adapter> [--validate] [--json]',
|
|
150
|
+
summary: ['show settings hierarchy and run health checks'],
|
|
151
|
+
adapters: 'one',
|
|
152
|
+
flags: [f('--validate'), f('--json')],
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: 'env',
|
|
156
|
+
usage: '<adapter>',
|
|
157
|
+
summary: [
|
|
158
|
+
'print export lines for shell-sourceable adapters',
|
|
159
|
+
'(usage: `eval "$(mainwave-cli env <adapter>)"`)',
|
|
160
|
+
],
|
|
161
|
+
adapters: 'one',
|
|
162
|
+
flags: [],
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
name: 'install-hooks',
|
|
166
|
+
usage: '[--quiet] [--redaction-packs <list>]',
|
|
167
|
+
summary: [
|
|
168
|
+
'install or refresh the Mainwave hook entry and the',
|
|
169
|
+
"latest release's hook scripts, with no prompts or",
|
|
170
|
+
"sign-in (run at session start by an org's managed",
|
|
171
|
+
"settings, and by setup's own session-start hook).",
|
|
172
|
+
"--redaction-packs: the packs an org's managed settings",
|
|
173
|
+
'apply to every Mainwave hook; recorded only from them',
|
|
174
|
+
],
|
|
175
|
+
adapters: 'none',
|
|
176
|
+
flags: [f('--quiet'), f('--redaction-packs')],
|
|
177
|
+
},
|
|
178
|
+
];
|
|
179
|
+
export const isCommand = (name) => COMMANDS.some((c) => c.name === name);
|
|
180
|
+
export const commandFlags = (_command, parsed) => {
|
|
181
|
+
return {
|
|
182
|
+
value: (name) => flagValue(parsed, name),
|
|
183
|
+
bool: (name) => flagBool(parsed, name),
|
|
184
|
+
has: (name) => hasFlag(parsed, name),
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
const SUMMARY_COLUMN = 42;
|
|
188
|
+
export const usageBlock = () => COMMANDS.flatMap((c) => {
|
|
189
|
+
const head = ` mainwave-cli ${c.name}${c.usage === '' ? '' : ` ${c.usage}`}`;
|
|
190
|
+
const indent = ' '.repeat(SUMMARY_COLUMN);
|
|
191
|
+
const [first, ...rest] = c.summary;
|
|
192
|
+
const tail = rest.map((line) => `${indent}${line}`);
|
|
193
|
+
if (first === undefined)
|
|
194
|
+
return [head];
|
|
195
|
+
return head.length < SUMMARY_COLUMN - 1
|
|
196
|
+
? [`${head.padEnd(SUMMARY_COLUMN)}${first}`, ...tail]
|
|
197
|
+
: [head, `${indent}${first}`, ...tail];
|
|
198
|
+
}).join('\n');
|
|
199
|
+
export const detailsBlock = () => COMMANDS.flatMap((c) => c.details ?? []).join('\n');
|
|
200
|
+
export const helpSpellings = (c) => [
|
|
201
|
+
...new Set([c.usage, ...c.summary, ...(c.details ?? [])].join('\n').match(/(?<![\w-])--[a-z][a-z-]*/g) ??
|
|
202
|
+
[]),
|
|
203
|
+
];
|
|
204
|
+
export const commandsManifest = (adapterNames) => ({
|
|
205
|
+
commands: COMMANDS.map((c) => ({
|
|
206
|
+
name: c.name,
|
|
207
|
+
usage: c.usage,
|
|
208
|
+
summary: c.summary.join(' '),
|
|
209
|
+
adapters: c.adapters,
|
|
210
|
+
flags: c.flags.map((flag) => ({
|
|
211
|
+
spelling: flag.spelling,
|
|
212
|
+
hidden: flag.hidden === true,
|
|
213
|
+
removed: flag.removed === true,
|
|
214
|
+
})),
|
|
215
|
+
})),
|
|
216
|
+
adapters: [...adapterNames],
|
|
217
|
+
});
|
package/dist/core/apply.js
CHANGED
|
@@ -260,12 +260,12 @@ export const renderPlan = (plan) => {
|
|
|
260
260
|
}
|
|
261
261
|
};
|
|
262
262
|
export const planHasChanges = (plans) => plans.some((p) => p.changed.length > 0);
|
|
263
|
-
const defaultHookDirs = () => ({
|
|
263
|
+
export const defaultHookDirs = () => ({
|
|
264
264
|
managedDir: managedHooksDir(),
|
|
265
265
|
flatDir: installedHooksDir(),
|
|
266
266
|
});
|
|
267
267
|
export const userHooksPath = (adapter) => adapter.markers?.hooksFile?.path ?? adapter.paths.global;
|
|
268
|
-
export const writePlan = async (plan, dirs = defaultHookDirs()) => {
|
|
268
|
+
export const writePlan = async (plan, dirs = defaultHookDirs(), holdFlat = false) => {
|
|
269
269
|
if (plan.stageHooks) {
|
|
270
270
|
const updated = await syncManagedHooks(await readPackagedMatchers(), packagedHooksDir(), dirs.managedDir, VERSION);
|
|
271
271
|
say('');
|
|
@@ -280,7 +280,7 @@ export const writePlan = async (plan, dirs = defaultHookDirs()) => {
|
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
282
|
const bundled = plan.adapter.bundledHookScripts ?? [];
|
|
283
|
-
if (bundled.length > 0) {
|
|
283
|
+
if (bundled.length > 0 && !holdFlat) {
|
|
284
284
|
const dest = await copyHookScripts(bundled, packagedHooksDir(), dirs.flatDir);
|
|
285
285
|
say('');
|
|
286
286
|
say(color.dim(`Hook scripts refreshed in ${dest}.`));
|
|
@@ -5,7 +5,7 @@ import { color } from './format.js';
|
|
|
5
5
|
import { pinnedUseCase } from './pinned-use-case.js';
|
|
6
6
|
import { login, me, publicConfig, tokenExpiry } from './platform.js';
|
|
7
7
|
import { isInteractive } from './tty.js';
|
|
8
|
-
import { activeSession, clearSession, readCredentials, readSettings, resolveEndpoints, updateSettings, writeCredentials, } from './store.js';
|
|
8
|
+
import { activeSession, assertSettingsWritable, clearSession, readCredentials, readSettings, resolveEndpoints, updateSettings, writeCredentials, } from './store.js';
|
|
9
9
|
const usesPasswordFlow = (options) => {
|
|
10
10
|
if (options.usePassword === true)
|
|
11
11
|
return true;
|
|
@@ -61,6 +61,7 @@ export const runLogin = async (options = {}) => {
|
|
|
61
61
|
}
|
|
62
62
|
return 0;
|
|
63
63
|
}
|
|
64
|
+
await assertSettingsWritable();
|
|
64
65
|
const token = usesPasswordFlow(options)
|
|
65
66
|
? await passwordLogin(apiUrl, options)
|
|
66
67
|
: await deviceLogin(apiUrl, {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { commandOwnership } from '../markers.js';
|
|
2
2
|
export const KIRO_HOOK_TIMEOUT_SECONDS = 10;
|
|
3
|
-
|
|
3
|
+
const kiroHookName = (trigger) => `Mainwave: ${trigger}`;
|
|
4
4
|
const isPlainObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
5
5
|
const isCommandEntry = (v) => isPlainObject(v) &&
|
|
6
6
|
typeof v.trigger === 'string' &&
|
package/dist/core/doctor.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { spawnSync } from 'node:child_process';
|
|
2
2
|
import { platform as osPlatform } from 'node:os';
|
|
3
|
-
import { isAbsolute } from 'node:path';
|
|
3
|
+
import { dirname, isAbsolute } from 'node:path';
|
|
4
4
|
import { envFileCodec } from './codecs/env-file.js';
|
|
5
5
|
import { activeHierarchy, computeEffective, effectiveFrom, flattenEffective, nativeIdentityReason, } from './effective-settings.js';
|
|
6
6
|
import { ValidateError } from './errors.js';
|
|
7
7
|
import { color, maskForDisplay } from './format.js';
|
|
8
|
-
import { collectBehaviourHookIssues } from './behaviour-hooks.js';
|
|
8
|
+
import { collectBehaviourHookIssues, scanBehaviourHooks } from './behaviour-hooks.js';
|
|
9
9
|
import { isManagedIdentityConfig, isManagedLayer, policyState } from './layer-policy.js';
|
|
10
10
|
import { collectMarkerIssues, DEFAULT_MARKER_TOOL, managedHooksDir, matchersForTool, readPackagedMatchers, scanForMarkers, } from './markers.js';
|
|
11
|
+
import { flatCopyIssues } from './hook-copies.js';
|
|
11
12
|
import { readExistingEnv } from './settings.js';
|
|
12
13
|
import { hookShellMissingFor, teamUcidStanding } from './apply.js';
|
|
13
14
|
import { adapterEffective, primaryCarries } from './status.js';
|
|
15
|
+
import { hasRulesFile, redactionLines, redactionView, sendsUnredactedContent, uncoveredNotice, } from './redaction.js';
|
|
14
16
|
import { readSettings } from './store.js';
|
|
15
17
|
import { emitJson } from './ui.js';
|
|
16
18
|
import { validateCollector } from './validate.js';
|
|
@@ -463,6 +465,55 @@ const renderChecks = (issues) => {
|
|
|
463
465
|
console.log(`${prefix} ${issue.message}`);
|
|
464
466
|
}
|
|
465
467
|
};
|
|
468
|
+
const hooksInstalled = async (adapter) => {
|
|
469
|
+
if (adapter.behaviourHooks !== undefined) {
|
|
470
|
+
return (await scanBehaviourHooks(adapter.behaviourHooks)).some((s) => s.status === 'present');
|
|
471
|
+
}
|
|
472
|
+
if (adapter.markers !== undefined) {
|
|
473
|
+
return (await scanForMarkers(await markerLayers(adapter))).some((s) => s.groups.length > 0);
|
|
474
|
+
}
|
|
475
|
+
return false;
|
|
476
|
+
};
|
|
477
|
+
const redactionScope = (adapter) => adapter.name === 'claude-code' ? { configDir: dirname(adapter.paths.global) } : {};
|
|
478
|
+
const redactionIssues = async (adapter, effective, view) => {
|
|
479
|
+
const installed = await hooksInstalled(adapter);
|
|
480
|
+
if (view.state === 'off') {
|
|
481
|
+
return installed
|
|
482
|
+
? [
|
|
483
|
+
{
|
|
484
|
+
level: 'warn',
|
|
485
|
+
message: `Credential redaction is off, so the ${adapter.displayName} hooks send API keys, tokens and private keys ` +
|
|
486
|
+
'in the spans they send as they are. Run setup with --redact-secrets to turn the default back on.',
|
|
487
|
+
},
|
|
488
|
+
]
|
|
489
|
+
: [];
|
|
490
|
+
}
|
|
491
|
+
const copies = installed
|
|
492
|
+
? await flatCopyIssues(hasRulesFile(view), undefined, view.org !== undefined)
|
|
493
|
+
: [];
|
|
494
|
+
if (view.state === 'error') {
|
|
495
|
+
return installed
|
|
496
|
+
? [
|
|
497
|
+
{
|
|
498
|
+
level: 'error',
|
|
499
|
+
message: view.cause === 'org'
|
|
500
|
+
? `Your organization's redaction packs can't be loaded, so the ${adapter.displayName} hooks send nothing: ` +
|
|
501
|
+
`${view.reason}. Update mainwave-cli, then start a new Claude Code session to refresh the hooks.`
|
|
502
|
+
: `Redaction rules file is unusable, so the ${adapter.displayName} hooks send nothing: ` +
|
|
503
|
+
`${view.reason}. Fix the file, or run setup with --redaction-file <path> or --no-redaction.`,
|
|
504
|
+
},
|
|
505
|
+
...copies,
|
|
506
|
+
]
|
|
507
|
+
: [];
|
|
508
|
+
}
|
|
509
|
+
const shape = adapter.parseEnv(flattenEffective(effective));
|
|
510
|
+
const uncovered = !hasRulesFile(view) ||
|
|
511
|
+
shape.collectorUrl === undefined ||
|
|
512
|
+
!sendsUnredactedContent(adapter, shape.optIns)
|
|
513
|
+
? []
|
|
514
|
+
: [{ level: 'warn', message: uncoveredNotice([adapter]) }];
|
|
515
|
+
return [...uncovered, ...copies];
|
|
516
|
+
};
|
|
466
517
|
const markerMatchers = (adapter, matchers) => matchersForTool(matchers, adapter.markers?.runtimeTool ?? DEFAULT_MARKER_TOOL);
|
|
467
518
|
const hookChoices = async (adapter) => {
|
|
468
519
|
const { hooks } = await readSettings();
|
|
@@ -479,10 +530,11 @@ const markerLayers = async (adapter) => {
|
|
|
479
530
|
{ id: 'user', label: 'User hooks file', path: hooksFile.path, kind: 'file' },
|
|
480
531
|
];
|
|
481
532
|
};
|
|
482
|
-
const markerIssuesFor = async (adapter, effective) => adapter.markers
|
|
533
|
+
const markerIssuesFor = async (adapter, effective, redaction) => adapter.markers
|
|
483
534
|
? collectMarkerIssues(await scanForMarkers(await markerLayers(adapter)), VERSION, markerMatchers(adapter, await readPackagedMatchers()), await skippedMarkerScans(effective), await hookChoices(adapter), adapter.markers.runtimeTool ?? DEFAULT_MARKER_TOOL, {
|
|
484
535
|
managedDir: managedHooksDir(),
|
|
485
536
|
hookShellMissing: await hookShellMissingFor(adapter, () => flattenEffective(effective)),
|
|
537
|
+
redaction: redaction.state === 'off' ? 'off' : hasRulesFile(redaction) ? 'file' : 'default',
|
|
486
538
|
})
|
|
487
539
|
: [];
|
|
488
540
|
const skippedMarkerScans = async (effective) => {
|
|
@@ -523,7 +575,7 @@ const runValidate = async (effective, adapter) => {
|
|
|
523
575
|
throw err;
|
|
524
576
|
}
|
|
525
577
|
};
|
|
526
|
-
const doctorJson = async (adapter, effective, issues, validation) => ({
|
|
578
|
+
const doctorJson = async (adapter, effective, issues, validation, redaction) => ({
|
|
527
579
|
adapter: adapter.name,
|
|
528
580
|
displayName: adapter.displayName,
|
|
529
581
|
files: effective.scans.map((scan) => ({
|
|
@@ -539,6 +591,7 @@ const doctorJson = async (adapter, effective, issues, validation) => ({
|
|
|
539
591
|
value: maskForDisplay(entry.key, entry.value),
|
|
540
592
|
layer: entry.source.layer.id,
|
|
541
593
|
})),
|
|
594
|
+
redaction,
|
|
542
595
|
issues: issues.map((issue) => ({ level: issue.level, message: issue.message })),
|
|
543
596
|
validation,
|
|
544
597
|
});
|
|
@@ -556,9 +609,17 @@ export const runDoctor = async (adapter, options = {}) => {
|
|
|
556
609
|
}
|
|
557
610
|
renderEffectiveEnv(effective, adapter);
|
|
558
611
|
console.log();
|
|
559
|
-
const
|
|
612
|
+
const redaction = redactionView(redactionScope(adapter));
|
|
613
|
+
console.log(color.bold('Redaction:'));
|
|
614
|
+
for (const line of redactionLines(redaction, ' '))
|
|
615
|
+
console.log(line);
|
|
616
|
+
console.log();
|
|
617
|
+
const issues = [
|
|
618
|
+
...collectIssues(effective, adapter, await attributionContext(adapter, effective)),
|
|
619
|
+
...(await redactionIssues(adapter, effective, redaction)),
|
|
620
|
+
];
|
|
560
621
|
const shellEnvIssues = await checkShellEnv(adapter);
|
|
561
|
-
const markerIssues = await markerIssuesFor(adapter, effective);
|
|
622
|
+
const markerIssues = await markerIssuesFor(adapter, effective, redaction);
|
|
562
623
|
const behaviourHookIssues = adapter.behaviourHooks
|
|
563
624
|
? await collectBehaviourHookIssues(adapter.behaviourHooks, VERSION)
|
|
564
625
|
: [];
|
|
@@ -581,15 +642,17 @@ export const runDoctor = async (adapter, options = {}) => {
|
|
|
581
642
|
};
|
|
582
643
|
const runDoctorJson = async (adapter, options) => {
|
|
583
644
|
const effective = await computeEffective(adapter);
|
|
645
|
+
const redaction = redactionView(redactionScope(adapter));
|
|
584
646
|
const issues = [
|
|
585
647
|
...collectIssues(effective, adapter, await attributionContext(adapter, effective)),
|
|
648
|
+
...(await redactionIssues(adapter, effective, redaction)),
|
|
586
649
|
...(await checkShellEnv(adapter)),
|
|
587
|
-
...(await markerIssuesFor(adapter, effective)),
|
|
650
|
+
...(await markerIssuesFor(adapter, effective, redaction)),
|
|
588
651
|
...(adapter.behaviourHooks
|
|
589
652
|
? await collectBehaviourHookIssues(adapter.behaviourHooks, VERSION)
|
|
590
653
|
: []),
|
|
591
654
|
];
|
|
592
655
|
const validation = options.validate ? await runValidate(effective, adapter) : undefined;
|
|
593
|
-
emitJson(await doctorJson(adapter, effective, issues, validation));
|
|
656
|
+
emitJson(await doctorJson(adapter, effective, issues, validation, redaction));
|
|
594
657
|
return issues.some((i) => i.level === 'error') || validation?.ok === false ? 1 : 0;
|
|
595
658
|
};
|
|
@@ -2,8 +2,7 @@ export const HOOK_ENTRY_SCRIPT = 'mainwave-hook.sh';
|
|
|
2
2
|
export const HOOK_DISPATCHER_SCRIPT = 'mainwave-hook.mjs';
|
|
3
3
|
export const HOOK_NODE_ENTRY_SCRIPT = 'mainwave-hook-node.mjs';
|
|
4
4
|
export const ORG_DELIVERED_MARK = 'org-delivered';
|
|
5
|
-
|
|
6
|
-
export const ENTRY_HOSTS = ['claude-code', 'codex'];
|
|
5
|
+
const HOOK_ENTRY_MARK = 'mainwave hook entry v2';
|
|
7
6
|
export const CODEX_BASH_FILTER = [
|
|
8
7
|
'*pr*create*',
|
|
9
8
|
'*mr*create*',
|
|
@@ -11,7 +10,7 @@ export const CODEX_BASH_FILTER = [
|
|
|
11
10
|
'*merge_requests*',
|
|
12
11
|
'*git*commit*',
|
|
13
12
|
];
|
|
14
|
-
|
|
13
|
+
const entryRouteKey = ({ host, event, route }) => `${host}/${event}/${route ?? ''}`;
|
|
15
14
|
const SAFE_TOKEN = /^[A-Za-z0-9._+-]+$/;
|
|
16
15
|
const shQuote = (value) => `'${value.replace(/'/g, `'\\''`)}'`;
|
|
17
16
|
export const renderHookEntry = ({ versionId, version, nodePath, routes, }) => {
|
package/dist/core/format.js
CHANGED
|
@@ -25,7 +25,6 @@ const maskHeaderCollection = (value) => {
|
|
|
25
25
|
return redacted;
|
|
26
26
|
return hasCredentialShape(value) ? UNREADABLE : value;
|
|
27
27
|
};
|
|
28
|
-
export const maskAuthHeader = (value) => maskHeaderCollection(value);
|
|
29
28
|
export const maskForDisplay = (envKey, value) => {
|
|
30
29
|
if (isBearerValue(value))
|
|
31
30
|
return maskBearerValue(value);
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { existsSync, promises as fs } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import { adapters } from '../adapters/index.js';
|
|
5
|
+
import { ORG_PACKS_SUPPORT } from '../../hooks/redaction.mjs';
|
|
6
|
+
import { copyHookScripts, managedHooksDir, installedHooksDir, packagedHooksDir, readPackagedMatchers, REDACTION_HOOK_MODULES, releaseBeforeRedaction, syncManagedHooks, } from './markers.js';
|
|
7
|
+
import { VERSION } from './version.js';
|
|
8
|
+
export const FLAT_SHARED_HOOK_MODULES = [
|
|
9
|
+
...REDACTION_HOOK_MODULES,
|
|
10
|
+
'vocabulary.mjs',
|
|
11
|
+
'marker-core.mjs',
|
|
12
|
+
];
|
|
13
|
+
const SHARED_PATTERN = new Set(FLAT_SHARED_HOOK_MODULES);
|
|
14
|
+
const IMPORTED_MODULES = ['marker-core.mjs', 'vocabulary.mjs'];
|
|
15
|
+
const flatScripts = async (dir) => (await fs.readdir(dir).catch(() => []))
|
|
16
|
+
.filter((f) => f.endsWith('.mjs') && !SHARED_PATTERN.has(f))
|
|
17
|
+
.sort();
|
|
18
|
+
const bundledScriptNames = () => [
|
|
19
|
+
...new Set(Object.values(adapters)
|
|
20
|
+
.flatMap((a) => a.bundledHookScripts ?? [])
|
|
21
|
+
.filter((f) => !SHARED_PATTERN.has(f))),
|
|
22
|
+
];
|
|
23
|
+
const IMPORT_FROM = /\b(?:import|export)\s*\{([^}]*)\}\s*from\s*['"]\.\/(marker-core|vocabulary)\.mjs['"]/g;
|
|
24
|
+
const importedNames = (source) => {
|
|
25
|
+
const found = new Map();
|
|
26
|
+
for (const [, list, module] of source.matchAll(IMPORT_FROM)) {
|
|
27
|
+
const names = found.get(`${module}.mjs`) ?? new Set();
|
|
28
|
+
for (const part of list.replace(/\/\/.*$/gm, '').split(',')) {
|
|
29
|
+
const name = part.trim().split(/\s+as\s+/)[0];
|
|
30
|
+
if (name)
|
|
31
|
+
names.add(name);
|
|
32
|
+
}
|
|
33
|
+
found.set(`${module}.mjs`, names);
|
|
34
|
+
}
|
|
35
|
+
return found;
|
|
36
|
+
};
|
|
37
|
+
export const describeBreaks = (breaks) => breaks.map((b) => `${b.script} ${b.reason}`).join('; ');
|
|
38
|
+
const incompatibilities = async (flatDir, srcDir, replaced) => {
|
|
39
|
+
const exported = new Map();
|
|
40
|
+
for (const module of IMPORTED_MODULES) {
|
|
41
|
+
const loaded = await import(pathToFileURL(join(srcDir, module)).href);
|
|
42
|
+
exported.set(module, new Set(Object.keys(loaded)));
|
|
43
|
+
}
|
|
44
|
+
const problems = [];
|
|
45
|
+
for (const script of (await flatScripts(flatDir)).filter((f) => !replaced.has(f))) {
|
|
46
|
+
const source = await fs.readFile(join(flatDir, script), 'utf8').catch(() => '');
|
|
47
|
+
for (const [module, names] of importedNames(source)) {
|
|
48
|
+
const missing = [...names].filter((n) => !exported.get(module)?.has(n));
|
|
49
|
+
if (missing.length > 0) {
|
|
50
|
+
problems.push({ script, reason: `imports ${missing.join(', ')} from ${module}` });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return problems;
|
|
55
|
+
};
|
|
56
|
+
const replacedScripts = (flatDir) => new Set(bundledScriptNames().filter((f) => existsSync(join(flatDir, f))));
|
|
57
|
+
export const flatRefreshBreaks = async (flatDir, srcDir = packagedHooksDir()) => {
|
|
58
|
+
if (!existsSync(join(flatDir, 'marker-core.mjs')))
|
|
59
|
+
return [];
|
|
60
|
+
return incompatibilities(flatDir, srcDir, replacedScripts(flatDir)).catch(() => []);
|
|
61
|
+
};
|
|
62
|
+
const breakAdvice = (breaks, flatDir) => `Setup leaves ${flatDir} as it is while ${describeBreaks(breaks)}, which this release no longer provides. ` +
|
|
63
|
+
`Remove ${breaks.map((b) => b.script).join(', ')} from it, then re-run setup.`;
|
|
64
|
+
const reasonOf = (err) => (err instanceof Error ? err.message : String(err));
|
|
65
|
+
const refreshFlatCopies = async (flatDir, srcDir) => {
|
|
66
|
+
if (!existsSync(join(flatDir, 'marker-core.mjs')))
|
|
67
|
+
return { flat: [] };
|
|
68
|
+
try {
|
|
69
|
+
const problems = await incompatibilities(flatDir, srcDir, replacedScripts(flatDir));
|
|
70
|
+
if (problems.length > 0)
|
|
71
|
+
return { flat: [], skipped: problems };
|
|
72
|
+
const files = [...FLAT_SHARED_HOOK_MODULES, ...replacedScripts(flatDir)];
|
|
73
|
+
await copyHookScripts(files, srcDir, flatDir);
|
|
74
|
+
return { flat: files };
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
return { flat: [], failed: `the hook scripts in ${flatDir}: ${reasonOf(err)}` };
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const appliesOrgPacks = (text) => text.includes(ORG_PACKS_SUPPORT);
|
|
81
|
+
export const refreshFlatCopiesForOrgPacks = async (flatDir = installedHooksDir(), srcDir = packagedHooksDir()) => {
|
|
82
|
+
const text = await fs.readFile(join(flatDir, 'redaction.mjs'), 'utf8').catch(() => '');
|
|
83
|
+
if (appliesOrgPacks(text))
|
|
84
|
+
return { flat: [] };
|
|
85
|
+
return refreshFlatCopies(flatDir, srcDir);
|
|
86
|
+
};
|
|
87
|
+
export const refreshInstalledHooks = async (passStaged, dirs, srcDir = packagedHooksDir()) => {
|
|
88
|
+
const flat = await refreshFlatCopies(dirs.flatDir, srcDir);
|
|
89
|
+
const result = {
|
|
90
|
+
flat: flat.flat,
|
|
91
|
+
...(flat.skipped === undefined ? {} : { skipped: flat.skipped }),
|
|
92
|
+
staged: false,
|
|
93
|
+
};
|
|
94
|
+
const failures = flat.failed === undefined ? [] : [flat.failed];
|
|
95
|
+
if (!passStaged && (await releaseBeforeRedaction(dirs.managedDir)) !== undefined) {
|
|
96
|
+
try {
|
|
97
|
+
await syncManagedHooks(await readPackagedMatchers(srcDir), srcDir, dirs.managedDir, VERSION);
|
|
98
|
+
result.staged = true;
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
failures.push(`the managed hooks in ${dirs.managedDir}: ${reasonOf(err)}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (failures.length > 0)
|
|
105
|
+
result.failed = failures.join('; ');
|
|
106
|
+
return result;
|
|
107
|
+
};
|
|
108
|
+
export const copyAdvice = (copy) => copy.blockedBy === undefined
|
|
109
|
+
? 'Re-run setup for any tool, which refreshes every hook copy on this machine.'
|
|
110
|
+
: breakAdvice(copy.blockedBy, copy.path);
|
|
111
|
+
const appliesRedaction = (text) => /['"]\.\/redaction\.mjs['"]/.test(text);
|
|
112
|
+
const unredactedFlatCopies = async (flatDir = installedHooksDir(), orgRecorded = false) => {
|
|
113
|
+
const text = await fs.readFile(join(flatDir, 'marker-core.mjs'), 'utf8').catch(() => null);
|
|
114
|
+
if (text === null)
|
|
115
|
+
return [];
|
|
116
|
+
let orgOnly = false;
|
|
117
|
+
if (appliesRedaction(text)) {
|
|
118
|
+
if (!orgRecorded)
|
|
119
|
+
return [];
|
|
120
|
+
const rules = await fs.readFile(join(flatDir, 'redaction.mjs'), 'utf8').catch(() => null);
|
|
121
|
+
if (rules === null || appliesOrgPacks(rules))
|
|
122
|
+
return [];
|
|
123
|
+
orgOnly = true;
|
|
124
|
+
}
|
|
125
|
+
const scripts = await flatScripts(flatDir);
|
|
126
|
+
if (scripts.length === 0)
|
|
127
|
+
return [];
|
|
128
|
+
const blockedBy = await flatRefreshBreaks(flatDir);
|
|
129
|
+
return [
|
|
130
|
+
{
|
|
131
|
+
path: flatDir,
|
|
132
|
+
what: `the hook scripts ${scripts.join(', ')}`,
|
|
133
|
+
...(blockedBy.length > 0 ? { blockedBy } : {}),
|
|
134
|
+
...(orgOnly ? { orgPacks: true } : {}),
|
|
135
|
+
},
|
|
136
|
+
];
|
|
137
|
+
};
|
|
138
|
+
export const unredactedHookCopies = async (dirs = { managedDir: managedHooksDir(), flatDir: installedHooksDir() }, orgRecorded = false) => {
|
|
139
|
+
const release = await releaseBeforeRedaction(dirs.managedDir);
|
|
140
|
+
return [
|
|
141
|
+
...(release === undefined
|
|
142
|
+
? []
|
|
143
|
+
: [{ path: release.dir, what: `the hooks of managed release ${release.id}` }]),
|
|
144
|
+
...(await unredactedFlatCopies(dirs.flatDir, orgRecorded)),
|
|
145
|
+
];
|
|
146
|
+
};
|
|
147
|
+
export const flatCopyIssues = async (rulesFile, flatDir = installedHooksDir(), orgRecorded = false) => (await unredactedFlatCopies(flatDir, orgRecorded)).map((copy) => copy.orgPacks === true
|
|
148
|
+
? {
|
|
149
|
+
level: 'error',
|
|
150
|
+
message: `Your organization's redaction packs are set, but ${copy.what} in ${copy.path} predate them (its redaction.mjs does not read them), ` +
|
|
151
|
+
`so they send spans without the packs. ${copyAdvice(copy)}`,
|
|
152
|
+
}
|
|
153
|
+
: {
|
|
154
|
+
level: rulesFile ? 'error' : 'warn',
|
|
155
|
+
message: `${rulesFile ? 'Redaction rules are set' : 'Credential redaction is on by default'}, but ${copy.what} in ${copy.path} predate redaction (its marker-core.mjs does not load them), ` +
|
|
156
|
+
`so they send spans without applying redaction rules. ${copyAdvice(copy)}`,
|
|
157
|
+
});
|