@mainwave/cli 0.13.1 → 0.15.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 +91 -2
- package/dist/adapters/claude-code.js +4 -21
- package/dist/adapters/codex-cli.js +456 -52
- package/dist/adapters/index.js +4 -2
- package/dist/commands.js +15 -3
- package/dist/core/apply.js +85 -19
- package/dist/core/codecs/toml-profile.js +239 -0
- package/dist/core/codex-trust.js +122 -31
- package/dist/core/detect.js +20 -1
- package/dist/core/doctor.js +72 -12
- package/dist/core/entry-script.js +24 -10
- package/dist/core/install-hooks.js +1 -1
- package/dist/core/markers.js +43 -24
- package/dist/core/pinned-use-case.js +2 -2
- package/dist/core/prompts.js +15 -0
- package/dist/core/remove.js +51 -10
- package/dist/core/setup-removal.js +197 -0
- package/dist/core/status.js +15 -7
- package/dist/core/store.js +37 -0
- package/dist/core/wizard.js +87 -4
- package/dist/main.js +41 -3
- package/hooks/codex-turns.mjs +137 -34
- package/hooks/git-commit-marker.mjs +8 -1
- package/hooks/github-pr-marker.mjs +8 -1
- package/hooks/glab-mr-marker.mjs +8 -1
- package/hooks/jira-ticket-marker.mjs +8 -1
- package/hooks/kiro-otlp.mjs +4 -15
- package/hooks/linear-ticket-marker.mjs +8 -1
- package/hooks/marker-core.mjs +126 -23
- package/hooks/matchers.json +1 -1
- package/hooks/plan-snapshot.mjs +9 -21
- package/package.json +7 -7
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import { tomlOtelCodec } from './codecs/toml-otel.js';
|
|
3
|
+
import { approvedHookKeys, hookTrustKey, mainwaveHookKeys, withoutHookStates, } from './codex-trust.js';
|
|
4
|
+
import { planMarkers, prepareMarkersFile } from './markers.js';
|
|
5
|
+
import { isErrnoCode, isSamePath, prepareUpdate, readExistingEnv } from './settings.js';
|
|
6
|
+
export const planSetupRemoval = async (adapter, options = {}) => {
|
|
7
|
+
const path = adapter.paths.global;
|
|
8
|
+
const env = await readExistingEnv(path, adapter.codec);
|
|
9
|
+
const owns = env !== null && (adapter.holdsOwnSetup?.(env) ?? true);
|
|
10
|
+
const config = await prepareUpdate({
|
|
11
|
+
path,
|
|
12
|
+
newEnv: {},
|
|
13
|
+
managedKeys: owns ? [...adapter.managedEnvKeys, ...(adapter.retiredEnvKeys ?? [])] : [],
|
|
14
|
+
codec: adapter.codec,
|
|
15
|
+
});
|
|
16
|
+
const holdsKey = (fileEnv) => fileEnv !== null && adapter.holdsOwnSetup?.(fileEnv) === true;
|
|
17
|
+
const configKey = holdsKey(env);
|
|
18
|
+
const hooksFile = adapter.markers?.hooksFile;
|
|
19
|
+
const approvals = options.approvals === true;
|
|
20
|
+
let removals;
|
|
21
|
+
let keys = [];
|
|
22
|
+
if (hooksFile === undefined) {
|
|
23
|
+
removals = [{ update: config, markersPlan: null, approvals: 0, holdsKey: configKey }];
|
|
24
|
+
}
|
|
25
|
+
else if (isSamePath(hooksFile.path, path)) {
|
|
26
|
+
const before = config.next;
|
|
27
|
+
const markersPlan = config.exists ? planMarkers(config.next, []) : null;
|
|
28
|
+
if (markersPlan !== null)
|
|
29
|
+
config.next = markersPlan.next;
|
|
30
|
+
const removal = {
|
|
31
|
+
update: config,
|
|
32
|
+
markersPlan,
|
|
33
|
+
approvals: 0,
|
|
34
|
+
holdsKey: configKey,
|
|
35
|
+
};
|
|
36
|
+
if (approvals && markersPlan !== null) {
|
|
37
|
+
keys = mainwaveHookKeys(before, hooksFile.path);
|
|
38
|
+
removal.moved = movedHooks(before, markersPlan.next, hooksFile.path, adapter.trustFiles);
|
|
39
|
+
}
|
|
40
|
+
removals = [removal];
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const hooks = await prepareMarkersFile(hooksFile.path, hooksFile.codec, []);
|
|
44
|
+
const next = hooks.plan.next;
|
|
45
|
+
const empty = next !== null && typeof next === 'object' && Object.keys(next).length === 0;
|
|
46
|
+
const emptied = hooks.update.exists && hooks.plan.changed && empty;
|
|
47
|
+
const linkTarget = emptied && (await fs.lstat(hooksFile.path)).isSymbolicLink()
|
|
48
|
+
? await fs.realpath(hooksFile.path)
|
|
49
|
+
: undefined;
|
|
50
|
+
const removal = {
|
|
51
|
+
update: hooks.update,
|
|
52
|
+
markersPlan: hooks.plan,
|
|
53
|
+
approvals: 0,
|
|
54
|
+
holdsKey: false,
|
|
55
|
+
...(linkTarget !== undefined ? { linkTarget } : emptied ? { remove: true } : {}),
|
|
56
|
+
};
|
|
57
|
+
if (approvals && hooks.plan.removed.length > 0) {
|
|
58
|
+
const body = await fs.readFile(hooksFile.path, 'utf8');
|
|
59
|
+
const before = hooksFile.codec.parse(body, hooksFile.path);
|
|
60
|
+
keys = mainwaveHookKeys(before, hooksFile.path);
|
|
61
|
+
removal.moved = movedHooks(before, hooks.plan.next, hooksFile.path, adapter.trustFiles);
|
|
62
|
+
}
|
|
63
|
+
removals = [{ update: config, markersPlan: null, approvals: 0, holdsKey: configKey }, removal];
|
|
64
|
+
}
|
|
65
|
+
if (keys.length === 0)
|
|
66
|
+
return removals;
|
|
67
|
+
return dropApprovals(removals, adapter.trustFiles ?? [], new Set(keys), (doc) => holdsKey(tomlOtelCodec.readEnv(doc)));
|
|
68
|
+
};
|
|
69
|
+
const movedHooks = (before, after, keySource, trustFiles = []) => {
|
|
70
|
+
const eventsOf = (doc) => isRecord(doc) && isRecord(doc.hooks) ? doc.hooks : {};
|
|
71
|
+
const approved = approvedHookKeys(trustFiles);
|
|
72
|
+
const moved = [];
|
|
73
|
+
const kept = eventsOf(after);
|
|
74
|
+
for (const [event, groups] of Object.entries(eventsOf(before))) {
|
|
75
|
+
const left = kept[event];
|
|
76
|
+
if (!Array.isArray(groups) || !Array.isArray(left))
|
|
77
|
+
continue;
|
|
78
|
+
let at = 0;
|
|
79
|
+
for (const [gi, group] of groups.entries()) {
|
|
80
|
+
if (at >= left.length || JSON.stringify(group) !== JSON.stringify(left[at]))
|
|
81
|
+
continue;
|
|
82
|
+
if (at !== gi && isRecord(group) && Array.isArray(group.hooks)) {
|
|
83
|
+
for (const [hi, handler] of group.hooks.entries()) {
|
|
84
|
+
if (!isRecord(handler) || typeof handler.command !== 'string')
|
|
85
|
+
continue;
|
|
86
|
+
if (approved?.has(hookTrustKey(keySource, event, gi, hi)) === false)
|
|
87
|
+
continue;
|
|
88
|
+
moved.push({ event, command: handler.command });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
at++;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return moved;
|
|
95
|
+
};
|
|
96
|
+
const isRecord = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
97
|
+
const ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/;
|
|
98
|
+
const shownCommand = (command) => {
|
|
99
|
+
const program = command
|
|
100
|
+
.trim()
|
|
101
|
+
.split(/\s+/)
|
|
102
|
+
.find((word) => !ASSIGNMENT.test(word));
|
|
103
|
+
const name = program
|
|
104
|
+
?.replace(/^["']|["']$/g, '')
|
|
105
|
+
.split(/[\\/]/)
|
|
106
|
+
.pop();
|
|
107
|
+
return name ? `${name} (arguments hidden)` : '(command hidden)';
|
|
108
|
+
};
|
|
109
|
+
const dropApprovals = async (removals, trustFiles, keys, holdsKey) => {
|
|
110
|
+
const out = [...removals];
|
|
111
|
+
for (const file of trustFiles) {
|
|
112
|
+
let at = out.findIndex((r) => isSamePath(r.update.path, file));
|
|
113
|
+
if (at < 0) {
|
|
114
|
+
const update = await prepareUpdate({
|
|
115
|
+
path: file,
|
|
116
|
+
newEnv: {},
|
|
117
|
+
managedKeys: [],
|
|
118
|
+
codec: tomlOtelCodec,
|
|
119
|
+
});
|
|
120
|
+
if (!update.exists)
|
|
121
|
+
continue;
|
|
122
|
+
at = out.findIndex((r) => removals.includes(r));
|
|
123
|
+
out.splice(at, 0, {
|
|
124
|
+
update,
|
|
125
|
+
markersPlan: null,
|
|
126
|
+
approvals: 0,
|
|
127
|
+
holdsKey: holdsKey(update.next),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
const removal = out[at];
|
|
131
|
+
const { codec } = removal.update;
|
|
132
|
+
const { text, dropped } = withoutHookStates(codec.serialize(removal.update.next), keys);
|
|
133
|
+
if (dropped === 0)
|
|
134
|
+
continue;
|
|
135
|
+
removal.update.next = codec.parse(text, removal.update.path);
|
|
136
|
+
removal.approvals += dropped;
|
|
137
|
+
}
|
|
138
|
+
return out;
|
|
139
|
+
};
|
|
140
|
+
const removalChanges = ({ update, markersPlan, approvals }) => update.diff.added.length > 0 ||
|
|
141
|
+
update.diff.changed.length > 0 ||
|
|
142
|
+
update.diff.removed.length > 0 ||
|
|
143
|
+
markersPlan?.changed === true ||
|
|
144
|
+
approvals > 0;
|
|
145
|
+
export const removalSteps = async (removals) => Promise.all(removals.filter(removalChanges).map(removalStep));
|
|
146
|
+
const isSymlink = async (path) => {
|
|
147
|
+
try {
|
|
148
|
+
return (await fs.lstat(path)).isSymbolicLink();
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
if (isErrnoCode(err, 'ENOENT'))
|
|
152
|
+
return false;
|
|
153
|
+
throw err;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const removalStep = async (removal) => {
|
|
157
|
+
const { update, markersPlan, approvals, holdsKey } = removal;
|
|
158
|
+
const left = update.codec.serialize(update.next).trim();
|
|
159
|
+
if (left === '' || left === '{}') {
|
|
160
|
+
if (await isSymlink(update.path)) {
|
|
161
|
+
const target = await fs.realpath(update.path);
|
|
162
|
+
return {
|
|
163
|
+
kind: 'update',
|
|
164
|
+
update,
|
|
165
|
+
holdsKey,
|
|
166
|
+
note: `${update.path}: links to ${target}; keep the link and leave that file ` +
|
|
167
|
+
`${left === '{}' ? 'as {}' : 'empty'} (only Mainwave's setup in it)`,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
kind: 'delete',
|
|
172
|
+
path: update.path,
|
|
173
|
+
holdsKey,
|
|
174
|
+
note: `${update.path}: delete (only Mainwave's setup in it)`,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
const hooks = markersPlan?.removed.length ?? 0;
|
|
178
|
+
const parts = [
|
|
179
|
+
...(update.diff.removed.length > 0 ? ["Mainwave's telemetry settings"] : []),
|
|
180
|
+
...(hooks > 0 ? [`${hooks} Mainwave ${hooks === 1 ? 'hook' : 'hooks'}`] : []),
|
|
181
|
+
...(approvals > 0
|
|
182
|
+
? [`Codex's ${approvals === 1 ? 'approval' : 'approvals'} of Mainwave hooks`]
|
|
183
|
+
: []),
|
|
184
|
+
];
|
|
185
|
+
const moved = removal.moved ?? [];
|
|
186
|
+
const reapprove = moved.length === 0
|
|
187
|
+
? ''
|
|
188
|
+
: `\n This moves ${moved.length === 1 ? 'a hook' : 'hooks'} of other tools that Codex ` +
|
|
189
|
+
`approved by position, so Codex will ask you to approve ${moved.length === 1 ? 'it' : 'them'} again:` +
|
|
190
|
+
moved.map((h) => `\n ${h.event}: ${shownCommand(h.command)}`).join('');
|
|
191
|
+
return {
|
|
192
|
+
kind: 'update',
|
|
193
|
+
update,
|
|
194
|
+
holdsKey,
|
|
195
|
+
note: `${update.path}: remove ${parts.join(', ')}; keep the rest${reapprove}`,
|
|
196
|
+
};
|
|
197
|
+
};
|
package/dist/core/status.js
CHANGED
|
@@ -206,9 +206,16 @@ const renderFile = (state, isLast, labelWidth) => {
|
|
|
206
206
|
});
|
|
207
207
|
return lines;
|
|
208
208
|
};
|
|
209
|
-
const
|
|
209
|
+
export const statusSetups = (adapter) => [
|
|
210
|
+
{ adapter },
|
|
211
|
+
...(adapter.doctorSetups?.()?.setups ?? [])
|
|
212
|
+
.filter((s) => s.adapter.paths.global !== adapter.paths.global)
|
|
213
|
+
.map((s) => ({ adapter: s.adapter, setup: s.label })),
|
|
214
|
+
];
|
|
215
|
+
const renderAdapter = async (adapter, setup) => {
|
|
210
216
|
const lines = [''];
|
|
211
|
-
|
|
217
|
+
const title = setup === undefined ? adapter.displayName : `${adapter.displayName}, ${setup}`;
|
|
218
|
+
lines.push(`${color.bold(adapter.name)} ${color.dim(`(${title})`)}`);
|
|
212
219
|
const rows = fileRowsFor(adapter);
|
|
213
220
|
const states = await Promise.all(rows.map(inspectFile));
|
|
214
221
|
const effective = await withNativeIdentity(adapter, states);
|
|
@@ -234,13 +241,14 @@ const renderAdapter = async (adapter) => {
|
|
|
234
241
|
});
|
|
235
242
|
return lines;
|
|
236
243
|
};
|
|
237
|
-
const statusJsonFor = async (adapter) => {
|
|
244
|
+
const statusJsonFor = async (adapter, setup) => {
|
|
238
245
|
const states = await Promise.all(fileRowsFor(adapter).map(inspectFile));
|
|
239
246
|
const effective = await withNativeIdentity(adapter, states);
|
|
240
247
|
const attribution = attributionOf(effective, adapter);
|
|
241
248
|
return {
|
|
242
249
|
adapter: adapter.name,
|
|
243
250
|
displayName: adapter.displayName,
|
|
251
|
+
...(setup === undefined ? {} : { setup }),
|
|
244
252
|
effective: {
|
|
245
253
|
...(effective.ucid !== undefined ? { ucid: effective.ucid } : {}),
|
|
246
254
|
...(effective.collectorUrl !== undefined ? { collectorUrl: effective.collectorUrl } : {}),
|
|
@@ -261,7 +269,7 @@ const statusJsonFor = async (adapter) => {
|
|
|
261
269
|
};
|
|
262
270
|
};
|
|
263
271
|
export const runStatus = async (adapter, options = {}) => {
|
|
264
|
-
const targets = adapter !== undefined ? [adapter] : adapterNames().map((n) => adapters[n]);
|
|
272
|
+
const targets = (adapter !== undefined ? [adapter] : adapterNames().map((n) => adapters[n])).flatMap(statusSetups);
|
|
265
273
|
const redaction = redactionView();
|
|
266
274
|
const unredacted = redaction.state === 'off'
|
|
267
275
|
? []
|
|
@@ -269,7 +277,7 @@ export const runStatus = async (adapter, options = {}) => {
|
|
|
269
277
|
if (options.json) {
|
|
270
278
|
emitJson({
|
|
271
279
|
redaction: redaction.state === 'off' ? redaction : { ...redaction, unredactedHooks: unredacted },
|
|
272
|
-
adapters: await Promise.all(targets.map(statusJsonFor)),
|
|
280
|
+
adapters: await Promise.all(targets.map((t) => statusJsonFor(t.adapter, t.setup))),
|
|
273
281
|
});
|
|
274
282
|
return 0;
|
|
275
283
|
}
|
|
@@ -285,8 +293,8 @@ export const runStatus = async (adapter, options = {}) => {
|
|
|
285
293
|
? ` ✗ ${copy.what} in ${tildify(copy.path)} predate your organization's redaction packs and send spans without them. ${copyAdvice(copy)}`
|
|
286
294
|
: ` ${serious ? '✗' : '!'} ${copy.what} in ${tildify(copy.path)} predate redaction and send spans without it. ${copyAdvice(copy)}`));
|
|
287
295
|
}
|
|
288
|
-
for (const
|
|
289
|
-
for (const line of await renderAdapter(
|
|
296
|
+
for (const t of targets) {
|
|
297
|
+
for (const line of await renderAdapter(t.adapter, t.setup)) {
|
|
290
298
|
console.log(line);
|
|
291
299
|
}
|
|
292
300
|
}
|
package/dist/core/store.js
CHANGED
|
@@ -174,6 +174,43 @@ export const updateSettings = async (patch) => withFileLock(settingsPath(), asyn
|
|
|
174
174
|
await writeJson(settingsPath(), next);
|
|
175
175
|
return next;
|
|
176
176
|
});
|
|
177
|
+
const withoutHookFiles = (hooks, files) => {
|
|
178
|
+
if (!isPlainObject(hooks))
|
|
179
|
+
return undefined;
|
|
180
|
+
const next = { ...hooks };
|
|
181
|
+
let changed = false;
|
|
182
|
+
for (const kind of ['events', 'routes']) {
|
|
183
|
+
const record = next[kind];
|
|
184
|
+
if (!isPlainObject(record))
|
|
185
|
+
continue;
|
|
186
|
+
let kept = record;
|
|
187
|
+
for (const { adapter, file } of files) {
|
|
188
|
+
const perFile = kept[adapter];
|
|
189
|
+
if (!isPlainObject(perFile) || !(file in perFile))
|
|
190
|
+
continue;
|
|
191
|
+
kept = {
|
|
192
|
+
...kept,
|
|
193
|
+
[adapter]: Object.fromEntries(Object.entries(perFile).filter(([f]) => f !== file)),
|
|
194
|
+
};
|
|
195
|
+
changed = true;
|
|
196
|
+
}
|
|
197
|
+
next[kind] = kept;
|
|
198
|
+
}
|
|
199
|
+
return changed ? next : undefined;
|
|
200
|
+
};
|
|
201
|
+
export const forgetHookFiles = async (files) => {
|
|
202
|
+
if (withoutHookFiles((await readSettings()).hooks, files) === undefined)
|
|
203
|
+
return false;
|
|
204
|
+
return withFileLock(settingsPath(), async () => {
|
|
205
|
+
await assertSettingsWritable();
|
|
206
|
+
const current = await readSettings();
|
|
207
|
+
const hooks = withoutHookFiles(current.hooks, files);
|
|
208
|
+
if (hooks === undefined)
|
|
209
|
+
return false;
|
|
210
|
+
await writeJson(settingsPath(), { ...current, hooks });
|
|
211
|
+
return true;
|
|
212
|
+
});
|
|
213
|
+
};
|
|
177
214
|
export const KEEP_ORG_PACKS = 'keep';
|
|
178
215
|
export const hasOrgEntry = async (configDir, path) => orgDirsIn(await readSettingsText(path)).includes(configDir);
|
|
179
216
|
const sameList = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
|
package/dist/core/wizard.js
CHANGED
|
@@ -7,7 +7,7 @@ import { PlatformError, ValidateError, WizardAbort } from './errors.js';
|
|
|
7
7
|
import { color } from './format.js';
|
|
8
8
|
import { runInterview } from './interview.js';
|
|
9
9
|
import { redeemInvite } from './platform.js';
|
|
10
|
-
import { promptApiKey, promptCollectorUrl, promptConfirmWrite, promptSkills } from './prompts.js';
|
|
10
|
+
import { promptApiKey, promptCodexProfileChoice, promptCollectorUrl, promptConfirmWrite, promptSkills, } from './prompts.js';
|
|
11
11
|
import { checkRedactionFile, hasRulesFile, nextRedactionChoice, redactionLines, redactionView, sendsUnredactedContent, uncoveredNotice, } from './redaction.js';
|
|
12
12
|
import { describeBreaks, flatRefreshBreaks, refreshInstalledHooks } from './hook-copies.js';
|
|
13
13
|
import { installSkillsPayload } from './skills.js';
|
|
@@ -19,7 +19,7 @@ import { VERSION } from './version.js';
|
|
|
19
19
|
import { emitJson, say, setJsonMode } from './ui.js';
|
|
20
20
|
import { validateCollector } from './validate.js';
|
|
21
21
|
import { runVerify } from './verify.js';
|
|
22
|
-
import {
|
|
22
|
+
import { CODEX_ADAPTER_NAME, codexCliFor, codexHome, codexHomeIssues, findCodexProfileSetups, homeSharedExporterWarning, otherProfileSetupsNote, parseProfileName, profileConflict, profileFileName, profileOtherExporterWarning, profileRefusal, } from '../adapters/codex-cli.js';
|
|
23
23
|
const validateWithRetry = async (initialUrl, initialKey, interactive) => {
|
|
24
24
|
let url = initialUrl;
|
|
25
25
|
let key = initialKey;
|
|
@@ -241,9 +241,70 @@ export const redeemInviteToOverrides = async (token, apiUrl, options) => {
|
|
|
241
241
|
userEmailFromInvite: true,
|
|
242
242
|
};
|
|
243
243
|
};
|
|
244
|
-
|
|
244
|
+
const resolveCodexAdapters = async (adapters, profile, interactive) => {
|
|
245
|
+
const hasCodex = adapters.some((a) => a.name === CODEX_ADAPTER_NAME);
|
|
246
|
+
if (!hasCodex) {
|
|
247
|
+
if (profile !== undefined) {
|
|
248
|
+
throw new WizardAbort('--profile applies to Codex only: name codex among the tools, e.g. `setup codex --profile ' +
|
|
249
|
+
`${profile}\``);
|
|
250
|
+
}
|
|
251
|
+
return { adapters: [...adapters] };
|
|
252
|
+
}
|
|
253
|
+
const home = codexHome();
|
|
254
|
+
const swap = (codex) => adapters.map((a) => (a.name === CODEX_ADAPTER_NAME ? codex : a));
|
|
255
|
+
const toProfile = (codexProfile) => ({
|
|
256
|
+
adapters: swap(codexCliFor({ kind: 'profile', home, profile: codexProfile })),
|
|
257
|
+
codexProfile,
|
|
258
|
+
});
|
|
259
|
+
if (profile !== undefined) {
|
|
260
|
+
const conflict = profileConflict(home, profile);
|
|
261
|
+
if (conflict !== undefined)
|
|
262
|
+
throw new WizardAbort(conflict);
|
|
263
|
+
return toProfile(profile);
|
|
264
|
+
}
|
|
265
|
+
const found = findCodexProfileSetups(home);
|
|
266
|
+
if (found.length === 0)
|
|
267
|
+
return { adapters: [...adapters] };
|
|
268
|
+
const refused = found.flatMap((p) => {
|
|
269
|
+
const refusal = profileRefusal(home, p);
|
|
270
|
+
return refusal === undefined ? [] : [{ profile: p, refusal }];
|
|
271
|
+
});
|
|
272
|
+
if (refused.length > 0) {
|
|
273
|
+
const run = (p) => `\`mainwave-cli setup codex --profile ${p}\``;
|
|
274
|
+
const healthy = found.filter((p) => !refused.some((r) => r.profile === p));
|
|
275
|
+
throw new WizardAbort([
|
|
276
|
+
...refused.map((r) => `Codex profile ${r.profile} holds a Mainwave setup in a file setup can't edit: ${r.refusal}.`),
|
|
277
|
+
`Until then, ${refused.map((r) => run(r.profile)).join(' and ')} and a switch to all ` +
|
|
278
|
+
'sessions stop on the same problem.',
|
|
279
|
+
...(healthy.length === 0
|
|
280
|
+
? []
|
|
281
|
+
: [
|
|
282
|
+
`To update ${healthy.length === 1 ? 'profile' : 'profiles'} ${healthy.join(', ')} now, ` +
|
|
283
|
+
`run ${healthy.map(run).join(' or ')}.`,
|
|
284
|
+
]),
|
|
285
|
+
].join(' '));
|
|
286
|
+
}
|
|
287
|
+
if (!interactive) {
|
|
288
|
+
const files = found.map(profileFileName).join(', ');
|
|
289
|
+
throw new WizardAbort(`Codex sends to Mainwave only from ${found.length === 1 ? 'profile' : 'profiles'} ${found.join(', ')} (${files} in ${home}). ` +
|
|
290
|
+
`To update it, run \`mainwave-cli setup codex --profile ${found[0]}\`. ` +
|
|
291
|
+
'To send from every Codex session instead, run `mainwave-cli setup codex` in a terminal and choose ' +
|
|
292
|
+
'"switch to all sessions"; that removes Mainwave from the profile files.');
|
|
293
|
+
}
|
|
294
|
+
const choice = await promptCodexProfileChoice(found);
|
|
295
|
+
if (choice.kind === 'profile')
|
|
296
|
+
return toProfile(parseProfileName(choice.profile));
|
|
297
|
+
return {
|
|
298
|
+
adapters: swap({
|
|
299
|
+
...codexCliFor({ kind: 'home', home }),
|
|
300
|
+
replaces: found.map((p) => codexCliFor({ kind: 'profile', home, profile: p })),
|
|
301
|
+
}),
|
|
302
|
+
};
|
|
303
|
+
};
|
|
304
|
+
export const runSetup = async (requested, rawOptions = {}) => {
|
|
245
305
|
setJsonMode(rawOptions.json === true);
|
|
246
306
|
const interactive = isInteractive();
|
|
307
|
+
const { adapters, codexProfile } = await resolveCodexAdapters(requested, rawOptions.profile, interactive);
|
|
247
308
|
const redactionFile = rawOptions.redactionFile === undefined
|
|
248
309
|
? undefined
|
|
249
310
|
: checkRedactionFile(rawOptions.redactionFile);
|
|
@@ -256,7 +317,7 @@ export const runSetup = async (adapters, rawOptions = {}) => {
|
|
|
256
317
|
let credentials = await readCredentials();
|
|
257
318
|
let session = activeSession(credentials, endpoints.apiUrl);
|
|
258
319
|
say(color.bold(`mainwave-cli — setup ${adapters.map((a) => a.displayName).join(', ')}`));
|
|
259
|
-
if (adapters.some((a) => a.name ===
|
|
320
|
+
if (adapters.some((a) => a.name === CODEX_ADAPTER_NAME)) {
|
|
260
321
|
for (const issue of codexHomeIssues()) {
|
|
261
322
|
say(issue.level === 'warn' ? color.yellow(`⚠ ${issue.message}`) : color.dim(issue.message));
|
|
262
323
|
}
|
|
@@ -328,6 +389,20 @@ export const runSetup = async (adapters, rawOptions = {}) => {
|
|
|
328
389
|
`(${plan.keptPin.name ?? plan.keptPin.id}). Pass --no-use-case to unpin it.`));
|
|
329
390
|
}
|
|
330
391
|
}
|
|
392
|
+
const otherExporter = !adapters.some((a) => a.name === CODEX_ADAPTER_NAME)
|
|
393
|
+
? undefined
|
|
394
|
+
: codexProfile === undefined
|
|
395
|
+
? homeSharedExporterWarning(codexHome())
|
|
396
|
+
: profileOtherExporterWarning(codexHome(), codexProfile);
|
|
397
|
+
if (otherExporter !== undefined) {
|
|
398
|
+
say('');
|
|
399
|
+
say(color.yellow(`⚠ ${otherExporter}`));
|
|
400
|
+
}
|
|
401
|
+
const otherProfiles = codexProfile === undefined ? undefined : otherProfileSetupsNote(codexHome(), codexProfile);
|
|
402
|
+
if (otherProfiles !== undefined) {
|
|
403
|
+
say('');
|
|
404
|
+
say(color.yellow(`⚠ ${otherProfiles}`));
|
|
405
|
+
}
|
|
331
406
|
if (planHasChanges(plans) && !options.yes) {
|
|
332
407
|
if (!interactive) {
|
|
333
408
|
throw new WizardAbort('refusing to write without confirmation — pass --yes');
|
|
@@ -391,6 +466,14 @@ export const runSetup = async (adapters, rawOptions = {}) => {
|
|
|
391
466
|
{ ...hooks.routes?.[p.adapter.name], [userHooksPath(p.adapter)]: [...p.hookRoutes] },
|
|
392
467
|
])),
|
|
393
468
|
};
|
|
469
|
+
for (const p of markerTools) {
|
|
470
|
+
for (const file of p.replacedHooksFiles) {
|
|
471
|
+
if (file === userHooksPath(p.adapter))
|
|
472
|
+
continue;
|
|
473
|
+
delete hooks.events[p.adapter.name]?.[file];
|
|
474
|
+
delete hooks.routes[p.adapter.name]?.[file];
|
|
475
|
+
}
|
|
476
|
+
}
|
|
394
477
|
}
|
|
395
478
|
await updateSettings({
|
|
396
479
|
hooks,
|
package/dist/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { claudeCodeFor } from './adapters/claude-code.js';
|
|
2
|
-
import {
|
|
2
|
+
import { CODEX_ADAPTER_NAME, codexCliFor, homeTarget, parseProfileName, profileTarget, } from './adapters/codex-cli.js';
|
|
3
3
|
import { adapterNames, adapters } from './adapters/index.js';
|
|
4
4
|
import { commandFlags, detailsBlock, isCommand, usageBlock } from './commands.js';
|
|
5
5
|
import { runLogin, runLogout, runWhoami } from './core/auth-commands.js';
|
|
@@ -111,7 +111,20 @@ const setupOptions = (parsed) => {
|
|
|
111
111
|
flags.bool('skills-only') === true) {
|
|
112
112
|
throw new WizardAbort('--skills-only touches no telemetry config, so redaction flags do not apply');
|
|
113
113
|
}
|
|
114
|
+
let profile;
|
|
115
|
+
if (flags.has('profile')) {
|
|
116
|
+
if (flags.bool('skills-only') === true) {
|
|
117
|
+
throw new WizardAbort('--skills-only touches no telemetry config, so --profile does not apply');
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
profile = parseProfileName(flags.value('profile'));
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
throw new WizardAbort(err instanceof Error ? err.message : String(err));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
114
126
|
return {
|
|
127
|
+
profile,
|
|
115
128
|
invite,
|
|
116
129
|
redactionFile,
|
|
117
130
|
noRedaction,
|
|
@@ -251,8 +264,24 @@ const HANDLERS = {
|
|
|
251
264
|
process.stderr.write(`mainwave-cli install-hooks: --host takes \`codex\`, not "${host}"\n`);
|
|
252
265
|
return 1;
|
|
253
266
|
}
|
|
267
|
+
if (flags.has('codex-profile') && host !== 'codex') {
|
|
268
|
+
process.stderr.write('mainwave-cli install-hooks: --codex-profile needs --host codex\n');
|
|
269
|
+
return 1;
|
|
270
|
+
}
|
|
254
271
|
if (host === 'codex') {
|
|
255
|
-
|
|
272
|
+
let target;
|
|
273
|
+
try {
|
|
274
|
+
target = flags.has('codex-profile')
|
|
275
|
+
? profileTarget(parseProfileName(flags.value('codex-profile')))
|
|
276
|
+
: homeTarget();
|
|
277
|
+
}
|
|
278
|
+
catch (err) {
|
|
279
|
+
process.stderr.write(`mainwave-cli install-hooks: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
280
|
+
return 1;
|
|
281
|
+
}
|
|
282
|
+
return runInstallCodexHooks(codexCliFor(target), {
|
|
283
|
+
quiet: flags.bool('quiet') === true,
|
|
284
|
+
});
|
|
256
285
|
}
|
|
257
286
|
const dir = await sessionConfigDir();
|
|
258
287
|
return runInstallHooks(dir === undefined ? undefined : claudeCodeFor(dir), {
|
|
@@ -271,7 +300,16 @@ const HANDLERS = {
|
|
|
271
300
|
if (named.length === 0) {
|
|
272
301
|
throw new WizardAbort('--remove needs the tools to remove, e.g. `setup kiro-ide --remove`');
|
|
273
302
|
}
|
|
274
|
-
|
|
303
|
+
let targets = named;
|
|
304
|
+
if (flags.has('profile')) {
|
|
305
|
+
const profile = parseProfileName(flags.value('profile'));
|
|
306
|
+
if (!named.some((a) => a.name === CODEX_ADAPTER_NAME)) {
|
|
307
|
+
throw new WizardAbort('--profile applies to Codex only: name codex among the tools, e.g. ' +
|
|
308
|
+
`\`setup codex --remove --profile ${profile}\``);
|
|
309
|
+
}
|
|
310
|
+
targets = named.map((a) => a.name === CODEX_ADAPTER_NAME ? codexCliFor(profileTarget(profile)) : a);
|
|
311
|
+
}
|
|
312
|
+
return await runRemove(targets, {
|
|
275
313
|
yes: flags.bool('yes') === true,
|
|
276
314
|
json: flags.bool('json') === true,
|
|
277
315
|
});
|