@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
package/dist/core/doctor.js
CHANGED
|
@@ -464,8 +464,8 @@ const renderAdditionalWrites = async (adapter) => {
|
|
|
464
464
|
}
|
|
465
465
|
}
|
|
466
466
|
};
|
|
467
|
-
const renderChecks = (issues) => {
|
|
468
|
-
console.log(color.bold(
|
|
467
|
+
const renderChecks = (issues, title = 'Checks:') => {
|
|
468
|
+
console.log(color.bold(title));
|
|
469
469
|
if (issues.length === 0) {
|
|
470
470
|
console.log(color.green(' ✓ no issues detected'));
|
|
471
471
|
return;
|
|
@@ -541,7 +541,15 @@ const markerLayers = async (adapter) => {
|
|
|
541
541
|
...(hooksFile.localPath
|
|
542
542
|
? [{ id: 'project', label: 'Project hooks file', path: hooksFile.localPath, kind: 'file' }]
|
|
543
543
|
: []),
|
|
544
|
-
{
|
|
544
|
+
{
|
|
545
|
+
id: 'user',
|
|
546
|
+
label: adapter.codexProfile === undefined
|
|
547
|
+
? 'User hooks file'
|
|
548
|
+
: `Profile ${adapter.codexProfile} hooks file`,
|
|
549
|
+
path: hooksFile.path,
|
|
550
|
+
kind: 'file',
|
|
551
|
+
codec: hooksFile.codec,
|
|
552
|
+
},
|
|
545
553
|
];
|
|
546
554
|
};
|
|
547
555
|
const markerIssuesFor = async (adapter, effective, redaction) => adapter.markers
|
|
@@ -558,7 +566,7 @@ const codexTrustIssues = (adapter) => {
|
|
|
558
566
|
const hooksFile = adapter.markers?.hooksFile;
|
|
559
567
|
if (hooksFile === undefined || adapter.markers?.runtimeTool !== 'codex')
|
|
560
568
|
return [];
|
|
561
|
-
const reading = readCodexTrust(hooksFile.path, adapter.
|
|
569
|
+
const reading = readCodexTrust(hooksFile.path, adapter.trustFiles ?? [], hooksFile.path, hooksFile.codec);
|
|
562
570
|
if (reading.state === 'no-hooks')
|
|
563
571
|
return [];
|
|
564
572
|
if (reading.state === 'unreadable') {
|
|
@@ -583,13 +591,21 @@ const codexTrustIssues = (adapter) => {
|
|
|
583
591
|
n.modified > 0 ? `${n.modified} whose approval doesn't match the hook as it is now` : '',
|
|
584
592
|
n.disabled > 0 ? `${n.disabled} turned off in /hooks` : '',
|
|
585
593
|
].filter((p) => p !== '');
|
|
594
|
+
const profile = adapter.codexProfile;
|
|
595
|
+
const start = profile === undefined
|
|
596
|
+
? 'Start Codex and choose "Trust all" at the "Hooks need review" prompt, or open /hooks and trust each one. '
|
|
597
|
+
: `Start \`codex --profile ${profile}\` and choose "Trust all" at the "Hooks need review" prompt there, ` +
|
|
598
|
+
'or open /hooks in it and trust each one. ';
|
|
599
|
+
const exec = profile === undefined
|
|
600
|
+
? '`codex exec` skips them too unless it runs with --dangerously-bypass-hook-trust.'
|
|
601
|
+
: `\`codex exec --profile ${profile}\` skips them until then, unless it runs with --dangerously-bypass-hook-trust.`;
|
|
586
602
|
return [
|
|
587
603
|
{
|
|
588
604
|
level: 'warn',
|
|
589
605
|
message: `Codex skips ${n.total - n.trusted} of ${n.total} Mainwave hooks in ${hooksFile.path} (${parts.join(', ')}), ` +
|
|
590
|
-
|
|
606
|
+
`so they send nothing. ${start}` +
|
|
591
607
|
'Every change to a Mainwave hook needs a new approval, such as setup adding a route or a release changing a command. ' +
|
|
592
|
-
|
|
608
|
+
exec,
|
|
593
609
|
},
|
|
594
610
|
];
|
|
595
611
|
};
|
|
@@ -652,9 +668,46 @@ const doctorJson = async (adapter, effective, issues, validation, redaction) =>
|
|
|
652
668
|
validation,
|
|
653
669
|
});
|
|
654
670
|
export const runDoctor = async (adapter, options = {}) => {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
671
|
+
const many = adapter.doctorSetups?.();
|
|
672
|
+
if (many === undefined) {
|
|
673
|
+
return options.json ? runDoctorJson(adapter, options) : reportSetup(adapter, options);
|
|
674
|
+
}
|
|
675
|
+
const together = many.issues.some((i) => i.level === 'error') ? 1 : 0;
|
|
676
|
+
if (options.json) {
|
|
677
|
+
const setups = [];
|
|
678
|
+
let code = together;
|
|
679
|
+
for (const { label, adapter: setup } of many.setups) {
|
|
680
|
+
const { doc, failed } = await setupJson(setup, options);
|
|
681
|
+
setups.push({ setup: label, ...doc });
|
|
682
|
+
if (failed)
|
|
683
|
+
code = 1;
|
|
684
|
+
}
|
|
685
|
+
emitJson({
|
|
686
|
+
adapter: adapter.name,
|
|
687
|
+
displayName: adapter.displayName,
|
|
688
|
+
setups,
|
|
689
|
+
issues: many.issues.map((issue) => ({ level: issue.level, message: issue.message })),
|
|
690
|
+
});
|
|
691
|
+
return code;
|
|
692
|
+
}
|
|
693
|
+
let code = together;
|
|
694
|
+
const once = many.onceInText;
|
|
695
|
+
for (const [i, { label, adapter: setup }] of many.setups.entries()) {
|
|
696
|
+
if (i > 0)
|
|
697
|
+
console.log();
|
|
698
|
+
const title = `${adapter.displayName}, ${label}`;
|
|
699
|
+
if ((await reportSetup(setup, options, title, once?.replaces)) !== 0)
|
|
700
|
+
code = 1;
|
|
701
|
+
}
|
|
702
|
+
const togetherIssues = [...many.issues, ...(once?.issues ?? [])];
|
|
703
|
+
if (togetherIssues.length > 0) {
|
|
704
|
+
console.log();
|
|
705
|
+
renderChecks(togetherIssues, `${adapter.displayName} setups together:`);
|
|
706
|
+
}
|
|
707
|
+
return code;
|
|
708
|
+
};
|
|
709
|
+
const reportSetup = async (adapter, options, title = adapter.displayName, omit = () => false) => {
|
|
710
|
+
console.log(color.bold(`mainwave-cli doctor — ${title}`));
|
|
658
711
|
console.log();
|
|
659
712
|
const effective = await computeEffective(adapter);
|
|
660
713
|
renderFiles(effective, adapter.hierarchy);
|
|
@@ -679,7 +732,7 @@ export const runDoctor = async (adapter, options = {}) => {
|
|
|
679
732
|
const behaviourHookIssues = adapter.behaviourHooks
|
|
680
733
|
? await collectBehaviourHookIssues(adapter.behaviourHooks, VERSION)
|
|
681
734
|
: [];
|
|
682
|
-
renderChecks([...issues, ...shellEnvIssues, ...markerIssues, ...behaviourHookIssues]);
|
|
735
|
+
renderChecks([...issues, ...shellEnvIssues, ...markerIssues, ...behaviourHookIssues].filter((i) => !omit(i)));
|
|
683
736
|
let validateFailed = false;
|
|
684
737
|
if (options.validate) {
|
|
685
738
|
console.log();
|
|
@@ -697,6 +750,11 @@ export const runDoctor = async (adapter, options = {}) => {
|
|
|
697
750
|
return hasError || validateFailed ? 1 : 0;
|
|
698
751
|
};
|
|
699
752
|
const runDoctorJson = async (adapter, options) => {
|
|
753
|
+
const { doc, failed } = await setupJson(adapter, options);
|
|
754
|
+
emitJson(doc);
|
|
755
|
+
return failed ? 1 : 0;
|
|
756
|
+
};
|
|
757
|
+
const setupJson = async (adapter, options) => {
|
|
700
758
|
const effective = await computeEffective(adapter);
|
|
701
759
|
const redaction = redactionView(redactionScope(adapter));
|
|
702
760
|
const issues = [
|
|
@@ -709,6 +767,8 @@ const runDoctorJson = async (adapter, options) => {
|
|
|
709
767
|
: []),
|
|
710
768
|
];
|
|
711
769
|
const validation = options.validate ? await runValidate(effective, adapter) : undefined;
|
|
712
|
-
|
|
713
|
-
|
|
770
|
+
return {
|
|
771
|
+
doc: await doctorJson(adapter, effective, issues, validation, redaction),
|
|
772
|
+
failed: issues.some((i) => i.level === 'error') || validation?.ok === false,
|
|
773
|
+
};
|
|
714
774
|
};
|
|
@@ -81,15 +81,29 @@ export const entryVersionId = (text) => {
|
|
|
81
81
|
const m = /^\s*V='([A-Za-z0-9._+-]+)'$/m.exec(text);
|
|
82
82
|
return m?.[1];
|
|
83
83
|
};
|
|
84
|
-
|
|
85
|
-
export const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const loose = new RegExp(`(?:${HOOK_ENTRY_SCRIPT.replace('.', '\\.')}|${HOOK_NODE_ENTRY_SCRIPT.replace('.', '\\.')})"?\\s+([A-Za-z0-9_-]+)\\s+([A-Za-z]+)(?:\\s+([A-Za-z0-9_-]+))?`).exec(command);
|
|
90
|
-
if (!loose)
|
|
91
|
-
return undefined;
|
|
92
|
-
return { host: loose[1], event: loose[2], ...(loose[3] ? { route: loose[3] } : {}) };
|
|
84
|
+
const CODEX_PROFILE_ARGS = String.raw `--codex-profile ([A-Za-z0-9_-]{1,64})`;
|
|
85
|
+
export const safeArgs = (args) => {
|
|
86
|
+
for (const a of args) {
|
|
87
|
+
if (!SAFE_TOKEN.test(a))
|
|
88
|
+
throw new Error(`hook command: unsafe argument ${a}`);
|
|
93
89
|
}
|
|
94
|
-
return
|
|
90
|
+
return args;
|
|
91
|
+
};
|
|
92
|
+
const entryWords = (host, event, route, args) => {
|
|
93
|
+
return [host, event, ...(route === undefined ? [] : [route]), ...safeArgs(args)].join(' ');
|
|
94
|
+
};
|
|
95
|
+
export const entryCommand = (host, event, route, args = []) => `f="$HOME/.mainwave/hooks/managed/${HOOK_ENTRY_SCRIPT}"; [ -f "$f" ] && exec sh "$f" ${entryWords(host, event, route, args)}; exit 0`;
|
|
96
|
+
export const nodeEntryCommand = (nodeEntryPath, host, event, route, args = []) => `(if exist "${nodeEntryPath}" node "${nodeEntryPath}" ${entryWords(host, event, route, args)}) & exit /b 0`;
|
|
97
|
+
export const parseEntryCommand = (command) => {
|
|
98
|
+
const strict = new RegExp(`${HOOK_ENTRY_SCRIPT.replace('.', '\\.')}"; \\[ -f "\\$f" \\] && exec sh "\\$f" ([A-Za-z0-9_-]+) ([A-Za-z]+)(?: ([A-Za-z0-9_][A-Za-z0-9_-]*))?(?: ${CODEX_PROFILE_ARGS})?; exit 0`).exec(command);
|
|
99
|
+
const m = strict ??
|
|
100
|
+
new RegExp(`(?:${HOOK_ENTRY_SCRIPT.replace('.', '\\.')}|${HOOK_NODE_ENTRY_SCRIPT.replace('.', '\\.')})"?\\s+([A-Za-z0-9_-]+)\\s+([A-Za-z]+)(?:\\s+([A-Za-z0-9_][A-Za-z0-9_-]*))?(?:\\s+${CODEX_PROFILE_ARGS.replace(' ', '\\s+')}(?![A-Za-z0-9_-]))?`).exec(command);
|
|
101
|
+
if (!m)
|
|
102
|
+
return undefined;
|
|
103
|
+
return {
|
|
104
|
+
host: m[1],
|
|
105
|
+
event: m[2],
|
|
106
|
+
...(m[3] ? { route: m[3] } : {}),
|
|
107
|
+
...(m[4] ? { codexProfile: m[4] } : {}),
|
|
108
|
+
};
|
|
95
109
|
};
|
|
@@ -153,7 +153,7 @@ export const installCodexHooks = async (adapter, paths = defaultPaths()) => {
|
|
|
153
153
|
return { updated, destDir: paths.destDir, addedToUser: 0, userSettings: undefined };
|
|
154
154
|
}
|
|
155
155
|
const disclosedRoutes = stored.routes?.[adapter.name]?.[hooksFile.path] ?? ROUTES_BEFORE_RECORD;
|
|
156
|
-
const wanted = userHookGroups(matchersForTool(all, adapter.markers?.runtimeTool ?? DEFAULT_MARKER_TOOL), { markers: stored.markers?.[adapter.name] ?? true }, new Set(), adapter.markers?.runtimeTool).filter((g) => disclosed.includes(groupEvent(g)) &&
|
|
156
|
+
const wanted = userHookGroups(matchersForTool(all, adapter.markers?.runtimeTool ?? DEFAULT_MARKER_TOOL), { markers: stored.markers?.[adapter.name] ?? true }, new Set(), adapter.markers?.runtimeTool, adapter.markers?.hookArgs).filter((g) => disclosed.includes(groupEvent(g)) &&
|
|
157
157
|
g.hooks.every((h) => {
|
|
158
158
|
const key = routeKeyOf(h.command, adapter.markers?.runtimeTool);
|
|
159
159
|
return key === undefined || disclosedRoutes.includes(key);
|
package/dist/core/markers.js
CHANGED
|
@@ -5,7 +5,7 @@ import { basename, dirname, join, resolve, win32 } from 'node:path';
|
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { dropInNames } from './effective-settings.js';
|
|
7
7
|
import { GIT_BASH_FIX, GIT_BASH_MISSING_REASON } from './git-bash.js';
|
|
8
|
-
import { entryCommand, entryVersionId, HOOK_DISPATCHER_SCRIPT, HOOK_ENTRY_SCRIPT, HOOK_NODE_ENTRY_SCRIPT, nodeEntryCommand, ORG_DELIVERED_MARK, parseEntryCommand, renderHookEntry, } from './entry-script.js';
|
|
8
|
+
import { entryCommand, entryVersionId, HOOK_DISPATCHER_SCRIPT, HOOK_ENTRY_SCRIPT, HOOK_NODE_ENTRY_SCRIPT, nodeEntryCommand, ORG_DELIVERED_MARK, parseEntryCommand, renderHookEntry, safeArgs, } from './entry-script.js';
|
|
9
9
|
import { isManagedLayer, isPolicyKey } from './layer-policy.js';
|
|
10
10
|
import { canonicalPacks, packOrder } from './redaction.js';
|
|
11
11
|
export const MANAGED_BY = '--managed-by @mainwave/cli';
|
|
@@ -77,17 +77,23 @@ export const shellHome = (plat = process.platform, env = process.env, dirExists
|
|
|
77
77
|
return drivePath;
|
|
78
78
|
return env.USERPROFILE || homedir();
|
|
79
79
|
};
|
|
80
|
-
export const installHooksCommand = (version,
|
|
80
|
+
export const installHooksCommand = (version, options = {}) => `cd "$HOME" && ${installHooksNpx(version, options)}`;
|
|
81
|
+
const installHooksNpx = (version, { quiet = true, redactionPacks = [], host = DEFAULT_MARKER_TOOL, args = [] }) => `npx -y --registry=https://registry.npmjs.org ` +
|
|
81
82
|
`@mainwave/cli@${version} install-hooks${quiet ? ' --quiet' : ''}` +
|
|
82
83
|
(host === 'codex' ? ' --host codex' : '') +
|
|
84
|
+
safeArgs(args)
|
|
85
|
+
.map((a) => ` ${a}`)
|
|
86
|
+
.join('') +
|
|
83
87
|
(redactionPacks.length > 0
|
|
84
88
|
? ` ${REDACTION_PACKS_FLAG} ${canonicalPacks(redactionPacks).join(',')}`
|
|
85
89
|
: '');
|
|
90
|
+
export const codexRefreshCommand = (args = []) => args.length === 0
|
|
91
|
+
? `npx @mainwave/cli@${PAYLOAD_CLI_SPEC} install-hooks --host codex`
|
|
92
|
+
: installHooksNpx(PAYLOAD_CLI_SPEC, { host: 'codex', args });
|
|
86
93
|
export const bootstrapCommand = (version, redactionPacks = []) => `{ ${installHooksCommand(version, { redactionPacks })}; } >/dev/null 2>&1; exit 0`;
|
|
87
|
-
export const codexBootstrapCommand = (version, plat = process.platform) => plat === 'win32'
|
|
88
|
-
? `(cd /d "%USERPROFILE%" &&
|
|
89
|
-
|
|
90
|
-
: `{ ${installHooksCommand(version, { host: 'codex' })}; } >/dev/null 2>&1; exit 0`;
|
|
94
|
+
export const codexBootstrapCommand = (version, plat = process.platform, args = []) => plat === 'win32'
|
|
95
|
+
? `(cd /d "%USERPROFILE%" && ${installHooksNpx(version, { host: 'codex', args })}) >NUL 2>&1 & exit /b 0`
|
|
96
|
+
: `{ ${installHooksCommand(version, { host: 'codex', args })}; } >/dev/null 2>&1; exit 0`;
|
|
91
97
|
const REDACTION_PACKS_FLAG = '--redaction-packs';
|
|
92
98
|
export const redactionPacksIn = (command) => {
|
|
93
99
|
const args = /\binstall-hooks\b([^;}]*)/.exec(command)?.[1];
|
|
@@ -101,14 +107,14 @@ export const redactionPacksIn = (command) => {
|
|
|
101
107
|
};
|
|
102
108
|
export const BOOTSTRAP_MATCHER = 'startup|resume|fork';
|
|
103
109
|
export const BOOTSTRAP_KEY = 'SessionStart:bootstrap';
|
|
104
|
-
export const bootstrapGroup = (redactionPacks = [], host = DEFAULT_MARKER_TOOL) => ({
|
|
110
|
+
export const bootstrapGroup = (redactionPacks = [], host = DEFAULT_MARKER_TOOL, args = []) => ({
|
|
105
111
|
event: 'SessionStart',
|
|
106
112
|
matcher: BOOTSTRAP_MATCHER,
|
|
107
113
|
hooks: [
|
|
108
114
|
{
|
|
109
115
|
type: 'command',
|
|
110
116
|
command: host === 'codex'
|
|
111
|
-
? codexBootstrapCommand(PAYLOAD_CLI_SPEC)
|
|
117
|
+
? codexBootstrapCommand(PAYLOAD_CLI_SPEC, process.platform, args)
|
|
112
118
|
: bootstrapCommand(PAYLOAD_CLI_SPEC, redactionPacks),
|
|
113
119
|
async: true,
|
|
114
120
|
},
|
|
@@ -485,9 +491,9 @@ export const buildScriptHookCommand = (scriptPath, version, plat = process.platf
|
|
|
485
491
|
? `node "${scriptPath}" ${MANAGED_BY}@${version}${toolArg}`
|
|
486
492
|
: `f="${scriptPath}"; [ -f "$f" ] && exec node "$f" ${MANAGED_BY}@${version}${toolArg}; exit 0`;
|
|
487
493
|
};
|
|
488
|
-
export const buildHookCommand = (host, event, route, plat = process.platform, managedDir = managedHooksDir()) => host === 'codex' && plat === 'win32'
|
|
489
|
-
? nodeEntryCommand(win32.join(managedDir, HOOK_NODE_ENTRY_SCRIPT), host, event, route)
|
|
490
|
-
: entryCommand(host, event, route);
|
|
494
|
+
export const buildHookCommand = (host, event, route, plat = process.platform, managedDir = managedHooksDir(), args = []) => host === 'codex' && plat === 'win32'
|
|
495
|
+
? nodeEntryCommand(win32.join(managedDir, HOOK_NODE_ENTRY_SCRIPT), host, event, route, args)
|
|
496
|
+
: entryCommand(host, event, route, args);
|
|
491
497
|
export const parseManagedByVersion = (command) => {
|
|
492
498
|
const re = new RegExp(`${MANAGED_BY.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')}@([^\\s;]+)`);
|
|
493
499
|
return re.exec(command)?.[1];
|
|
@@ -508,10 +514,10 @@ export const hookShape = (event, host = DEFAULT_MARKER_TOOL) => {
|
|
|
508
514
|
};
|
|
509
515
|
const CODEX_STOP_TIMEOUT_SEC = 5;
|
|
510
516
|
const CODEX_INTERRUPT_TIMEOUT_SEC = 2;
|
|
511
|
-
const groupFor = (m, host) => {
|
|
517
|
+
const groupFor = (m, host, args) => {
|
|
512
518
|
const hook = {
|
|
513
519
|
type: 'command',
|
|
514
|
-
command: buildHookCommand(host, m.event, m.route),
|
|
520
|
+
command: buildHookCommand(host, m.event, m.route, process.platform, managedHooksDir(), args),
|
|
515
521
|
...hookShape(m.event, host),
|
|
516
522
|
};
|
|
517
523
|
if (m.if !== undefined && host !== 'codex')
|
|
@@ -522,13 +528,13 @@ const groupFor = (m, host) => {
|
|
|
522
528
|
hooks: [hook],
|
|
523
529
|
};
|
|
524
530
|
};
|
|
525
|
-
export const buildHookGroups = (matchers, host = DEFAULT_MARKER_TOOL) => matchers.map((m) => groupFor(m, host));
|
|
531
|
+
export const buildHookGroups = (matchers, host = DEFAULT_MARKER_TOOL, args = []) => matchers.map((m) => groupFor(m, host, args));
|
|
526
532
|
export const hostRunsBootstrap = (host) => host === DEFAULT_MARKER_TOOL || host === 'codex';
|
|
527
|
-
export const userHookGroups = (hosted, on, delivered, host = DEFAULT_MARKER_TOOL) => {
|
|
533
|
+
export const userHookGroups = (hosted, on, delivered, host = DEFAULT_MARKER_TOOL, args = []) => {
|
|
528
534
|
const selected = selectHookMatchers(hosted, on);
|
|
529
535
|
const groups = [
|
|
530
|
-
...(hostRunsBootstrap(host) && selected.length > 0 ? [bootstrapGroup([], host)] : []),
|
|
531
|
-
...buildHookGroups(selected, host),
|
|
536
|
+
...(hostRunsBootstrap(host) && selected.length > 0 ? [bootstrapGroup([], host, args)] : []),
|
|
537
|
+
...buildHookGroups(selected, host, args),
|
|
532
538
|
];
|
|
533
539
|
return groups.filter((g) => {
|
|
534
540
|
const command = g.hooks[0]?.command ?? '';
|
|
@@ -617,6 +623,7 @@ export const planMarkers = (doc, groups, remove = () => true) => {
|
|
|
617
623
|
const identical = new Set();
|
|
618
624
|
const placed = new Set();
|
|
619
625
|
let pruned = false;
|
|
626
|
+
let movedForeign = 0;
|
|
620
627
|
const removedInfo = [];
|
|
621
628
|
for (const event of MARKER_HOOK_EVENTS) {
|
|
622
629
|
if (skipped.has(event))
|
|
@@ -643,6 +650,9 @@ export const planMarkers = (doc, groups, remove = () => true) => {
|
|
|
643
650
|
current.forEach((g, i) => {
|
|
644
651
|
const info = owned[i];
|
|
645
652
|
if (info === null || info === undefined || keep[i]) {
|
|
653
|
+
if (kept.length !== i && groupOwnership(g) === null && isPlainObject(g)) {
|
|
654
|
+
movedForeign += Array.isArray(g.hooks) ? g.hooks.length : 0;
|
|
655
|
+
}
|
|
646
656
|
kept.push(g);
|
|
647
657
|
return;
|
|
648
658
|
}
|
|
@@ -682,6 +692,7 @@ export const planMarkers = (doc, groups, remove = () => true) => {
|
|
|
682
692
|
added,
|
|
683
693
|
unchanged,
|
|
684
694
|
changed: removed.length > 0 || added.length > 0,
|
|
695
|
+
movedForeign,
|
|
685
696
|
skipped: skippedEvents,
|
|
686
697
|
};
|
|
687
698
|
};
|
|
@@ -742,7 +753,7 @@ export const hookLogDir = (home = homedir()) => join(home, '.mainwave', 'logs');
|
|
|
742
753
|
const logFile = (home, label, name, legacyName) => ({
|
|
743
754
|
label,
|
|
744
755
|
path: join(hookLogDir(home), name),
|
|
745
|
-
legacyPath: join(home, legacyName),
|
|
756
|
+
...(legacyName === undefined ? {} : { legacyPath: join(home, legacyName) }),
|
|
746
757
|
});
|
|
747
758
|
export const markerLogFiles = (home = homedir()) => [
|
|
748
759
|
logFile(home, 'Linear tickets', 'ticket-marker.log', '.mainwave-ticket-marker.log'),
|
|
@@ -755,9 +766,13 @@ export const markerLogFiles = (home = homedir()) => [
|
|
|
755
766
|
activityPath: join(hookLogDir(home), 'plan-snapshot.log.ok'),
|
|
756
767
|
},
|
|
757
768
|
logFile(home, 'Claude turn errors', 'claude-events.log', '.mainwave-claude-events.log'),
|
|
769
|
+
{
|
|
770
|
+
...logFile(home, 'Codex turns', 'codex-turns.log'),
|
|
771
|
+
activityPath: join(hookLogDir(home), 'codex-turns.log.ok'),
|
|
772
|
+
},
|
|
758
773
|
];
|
|
759
774
|
export const lastLogActivity = async (lf) => {
|
|
760
|
-
const times = await Promise.all([lf.activityPath ?? lf.path, lf.legacyPath].map((p) => fs.stat(p).then((s) => s.mtime, () => undefined)));
|
|
775
|
+
const times = await Promise.all([lf.activityPath ?? lf.path, ...(lf.legacyPath === undefined ? [] : [lf.legacyPath])].map((p) => fs.stat(p).then((s) => s.mtime, () => undefined)));
|
|
761
776
|
return times
|
|
762
777
|
.filter((t) => t !== undefined)
|
|
763
778
|
.sort((a, b) => b.getTime() - a.getTime())[0];
|
|
@@ -769,9 +784,10 @@ const managedLockValue = (v) => {
|
|
|
769
784
|
return v;
|
|
770
785
|
return v !== 'false';
|
|
771
786
|
};
|
|
772
|
-
const readSettingsDoc = async (path) => {
|
|
787
|
+
const readSettingsDoc = async (path, codec) => {
|
|
773
788
|
try {
|
|
774
|
-
|
|
789
|
+
const body = await fs.readFile(path, 'utf8');
|
|
790
|
+
return codec === undefined ? JSON.parse(body) : codec.parse(body, path);
|
|
775
791
|
}
|
|
776
792
|
catch {
|
|
777
793
|
return null;
|
|
@@ -787,7 +803,7 @@ export const scanForMarkers = async (layers) => {
|
|
|
787
803
|
.map((name) => join(layer.path, name))
|
|
788
804
|
: [layer.path];
|
|
789
805
|
for (const path of paths) {
|
|
790
|
-
const doc = await readSettingsDoc(path);
|
|
806
|
+
const doc = await readSettingsDoc(path, layer.codec);
|
|
791
807
|
if (!isPlainObject(doc))
|
|
792
808
|
continue;
|
|
793
809
|
out.push({
|
|
@@ -1255,8 +1271,11 @@ export const collectMarkerIssues = async (scans, currentVersion, matchers, skipp
|
|
|
1255
1271
|
level: 'info',
|
|
1256
1272
|
message: activity.length > 0
|
|
1257
1273
|
? `Mainwave hook activity — ${activity.join('; ')}.`
|
|
1258
|
-
: 'Mainwave hooks are configured but no hook activity is recorded yet (~/.mainwave/logs/*-marker.log; for plan snapshots, ~/.mainwave/logs/plan-snapshot.log.ok). ' +
|
|
1259
|
-
|
|
1274
|
+
: 'Mainwave hooks are configured but no hook activity is recorded yet (~/.mainwave/logs/*-marker.log; for plan snapshots, ~/.mainwave/logs/plan-snapshot.log.ok; for Codex turns, ~/.mainwave/logs/codex-turns.log.ok, with skip reasons in codex-turns.log). ' +
|
|
1275
|
+
(host === 'codex'
|
|
1276
|
+
? 'Run a Codex session with a prompt'
|
|
1277
|
+
: 'File a ticket or open a PR with `gh pr create`') +
|
|
1278
|
+
', then check the log and the use case activity.',
|
|
1260
1279
|
});
|
|
1261
1280
|
}
|
|
1262
1281
|
return issues;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { adapterNames, adapters } from '../adapters/index.js';
|
|
2
|
-
import { adapterEffective } from './status.js';
|
|
2
|
+
import { adapterEffective, statusSetups } from './status.js';
|
|
3
3
|
export const pinnedUseCase = async (settings, targets = adapterNames().map((n) => adapters[n])) => {
|
|
4
4
|
const stored = settings.useCase;
|
|
5
5
|
if (!stored)
|
|
6
6
|
return undefined;
|
|
7
7
|
const developerTools = targets.filter((a) => !a.teamUcid);
|
|
8
|
-
const effective = await Promise.all(developerTools.map(adapterEffective));
|
|
8
|
+
const effective = await Promise.all(developerTools.flatMap(statusSetups).map((s) => adapterEffective(s.adapter)));
|
|
9
9
|
return effective.some((e) => e.ucid === stored.id) ? stored : undefined;
|
|
10
10
|
};
|
package/dist/core/prompts.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { checkbox, confirm, input, password, select } from '@inquirer/prompts';
|
|
2
2
|
import { maskSecret } from './format.js';
|
|
3
|
+
import { profileFileName } from '../adapters/codex-cli.js';
|
|
3
4
|
const EMAIL_RE = /^[^@\s]+@[^@\s]+\.[^@\s]+$/;
|
|
4
5
|
export const promptAdapters = async (candidates) => {
|
|
5
6
|
const detected = candidates.filter((c) => c.detected);
|
|
@@ -76,3 +77,17 @@ export const promptConfirmWrite = async () => confirm({
|
|
|
76
77
|
message: 'Write file?',
|
|
77
78
|
default: true,
|
|
78
79
|
});
|
|
80
|
+
export const promptCodexProfileChoice = async (profiles) => {
|
|
81
|
+
const files = profiles.map(profileFileName).join(', ');
|
|
82
|
+
const choice = await select({
|
|
83
|
+
message: `Codex sends to Mainwave only from ${profiles.length === 1 ? 'profile' : 'profiles'} ${profiles.join(', ')}. What should setup do?`,
|
|
84
|
+
choices: [
|
|
85
|
+
...profiles.map((p) => ({ name: `update profile ${p}`, value: `profile:${p}` })),
|
|
86
|
+
{
|
|
87
|
+
name: `switch to all sessions (removes Mainwave from ${files})`,
|
|
88
|
+
value: 'home',
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
});
|
|
92
|
+
return choice === 'home' ? { kind: 'home' } : { kind: 'profile', profile: choice.slice(8) };
|
|
93
|
+
};
|
package/dist/core/remove.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { userHooksPath } from './apply.js';
|
|
1
2
|
import { WizardAbort } from './errors.js';
|
|
2
3
|
import { color } from './format.js';
|
|
3
4
|
import { promptConfirmWrite } from './prompts.js';
|
|
4
5
|
import { applyUpdate, removeSettingsFile } from './settings.js';
|
|
6
|
+
import { forgetHookFiles, settingsPath } from './store.js';
|
|
5
7
|
import { isInteractive } from './tty.js';
|
|
6
8
|
import { emitJson, say, setJsonMode } from './ui.js';
|
|
7
9
|
export const runRemove = async (adapters, options = {}) => {
|
|
@@ -26,9 +28,15 @@ export const runRemove = async (adapters, options = {}) => {
|
|
|
26
28
|
if (notes.length === 0) {
|
|
27
29
|
say(color.dim('Nothing to remove: no Mainwave config for these tools is on disk.'));
|
|
28
30
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
const problem = await forgetHookRecords(adapters);
|
|
32
|
+
if (options.json) {
|
|
33
|
+
emitJson({
|
|
34
|
+
status: 'nothing-to-remove',
|
|
35
|
+
tools: adapters.map((a) => a.name),
|
|
36
|
+
...(problem === undefined ? {} : { error: problem }),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return problem === undefined ? 0 : 1;
|
|
32
40
|
}
|
|
33
41
|
say('');
|
|
34
42
|
for (const step of actions)
|
|
@@ -44,24 +52,57 @@ export const runRemove = async (adapters, options = {}) => {
|
|
|
44
52
|
for (const step of actions) {
|
|
45
53
|
if (step.kind === 'update') {
|
|
46
54
|
const result = await applyUpdate(step.update);
|
|
47
|
-
|
|
55
|
+
const backup = result.backupPath;
|
|
56
|
+
done.push({
|
|
57
|
+
path: result.written,
|
|
58
|
+
action: 'updated',
|
|
59
|
+
backup,
|
|
60
|
+
backupHoldsApiKey: backup !== null && step.holdsKey === true,
|
|
61
|
+
});
|
|
48
62
|
}
|
|
49
63
|
else {
|
|
64
|
+
const backup = await removeSettingsFile(step.path, { backup: step.backup !== false });
|
|
50
65
|
done.push({
|
|
51
66
|
path: step.path,
|
|
52
67
|
action: 'deleted',
|
|
53
|
-
backup
|
|
68
|
+
backup,
|
|
69
|
+
backupHoldsApiKey: backup !== null && step.holdsKey === true,
|
|
54
70
|
});
|
|
55
71
|
}
|
|
56
72
|
}
|
|
57
73
|
say('');
|
|
58
74
|
for (const d of done) {
|
|
59
75
|
say(color.green(`✓ ${d.action === 'deleted' ? 'Removed' : 'Updated'} ${d.path}`));
|
|
60
|
-
if (d.backup)
|
|
61
|
-
say(color.dim(` backup: ${d.backup}`));
|
|
76
|
+
if (d.backup) {
|
|
77
|
+
say(color.dim(` backup: ${d.backup}${d.backupHoldsApiKey ? ' (holds your API key)' : ''}`));
|
|
78
|
+
}
|
|
62
79
|
}
|
|
63
80
|
say(color.dim('Restart open sessions of these tools so they stop loading the hooks.'));
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
81
|
+
const problem = await forgetHookRecords(adapters);
|
|
82
|
+
if (options.json) {
|
|
83
|
+
emitJson({
|
|
84
|
+
status: 'removed',
|
|
85
|
+
tools: adapters.map((a) => a.name),
|
|
86
|
+
files: done,
|
|
87
|
+
...(problem === undefined ? {} : { error: problem }),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return problem === undefined ? 0 : 1;
|
|
91
|
+
};
|
|
92
|
+
const forgetHookRecords = async (adapters) => {
|
|
93
|
+
const files = adapters
|
|
94
|
+
.filter((a) => a.markers !== undefined)
|
|
95
|
+
.map((a) => ({ adapter: a.name, file: userHooksPath(a) }));
|
|
96
|
+
if (files.length === 0)
|
|
97
|
+
return undefined;
|
|
98
|
+
try {
|
|
99
|
+
await forgetHookFiles(files);
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
const problem = `Couldn't drop setup's record of the removed hooks from ${settingsPath()}: ` +
|
|
104
|
+
`${err instanceof Error ? err.message : String(err)}. Run the same command again to retry.`;
|
|
105
|
+
say(color.yellow(problem));
|
|
106
|
+
return problem;
|
|
107
|
+
}
|
|
67
108
|
};
|