captain-tool 0.0.117 → 0.0.119
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/bin/captain-tool-setup +189 -1
- package/package.json +5 -5
package/bin/captain-tool-setup
CHANGED
|
@@ -454,6 +454,160 @@ function configureClient(client, binaryPath) {
|
|
|
454
454
|
return configPath;
|
|
455
455
|
}
|
|
456
456
|
|
|
457
|
+
// ── Skill-proof hook (CAP-ADR-0042) ───────────────────────────────────────────
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* The captain-tool binary that runs `hooks …`: the platform binary when one is installed,
|
|
461
|
+
* else a `captain-tool` on PATH (the npm runner forwards `hooks` to its binary). null when
|
|
462
|
+
* there is neither: the hook step is then skipped with a note.
|
|
463
|
+
*
|
|
464
|
+
* WHY the Rust binary does the settings write: one implementation installs, uninstalls and
|
|
465
|
+
* answers the in-chat offer (`enable_skill_proof`), so all three write the same entries.
|
|
466
|
+
*/
|
|
467
|
+
function hooksBinary(binaryPath) {
|
|
468
|
+
if (binaryPath) return binaryPath;
|
|
469
|
+
const name = process.platform === 'win32' ? 'captain-tool.exe' : 'captain-tool';
|
|
470
|
+
for (const dir of (process.env.PATH || '').split(path.delimiter)) {
|
|
471
|
+
if (!dir) continue;
|
|
472
|
+
const candidate = path.join(dir, name);
|
|
473
|
+
try {
|
|
474
|
+
fs.accessSync(candidate, fs.constants.X_OK);
|
|
475
|
+
return candidate;
|
|
476
|
+
} catch (_) {}
|
|
477
|
+
}
|
|
478
|
+
return null;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Run `captain-tool hooks <args…>`. Returns { ok, output }. Never throws: a hook step that
|
|
483
|
+
* fails is reported, and the MCP registration it follows stands.
|
|
484
|
+
*/
|
|
485
|
+
function runHooks(binary, args) {
|
|
486
|
+
const { spawnSync } = require('child_process');
|
|
487
|
+
const res = spawnSync(binary, ['hooks', ...args], {
|
|
488
|
+
encoding: 'utf8',
|
|
489
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
490
|
+
});
|
|
491
|
+
const output = `${res.stdout || ''}${res.stderr || ''}`.trim();
|
|
492
|
+
if (res.error) return { ok: false, output: res.error.message };
|
|
493
|
+
return { ok: res.status === 0, output };
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/** The flags this wizard reads. */
|
|
497
|
+
function parseFlags(argv) {
|
|
498
|
+
return {
|
|
499
|
+
assumeYes: argv.includes('--yes') || argv.includes('-y'),
|
|
500
|
+
uninstall: argv.includes('--uninstall'),
|
|
501
|
+
hooksOnly: argv.includes('--hooks-only'),
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Remove our `captain` registration (and our legacy ones) from one client's config. Only a
|
|
507
|
+
* file that exists is touched, and only when something of ours was in it. Returns true when
|
|
508
|
+
* the file was written.
|
|
509
|
+
*/
|
|
510
|
+
function uninstallClient(client, binaryPath) {
|
|
511
|
+
const configPath = client.configPath(binaryPath);
|
|
512
|
+
if (!fs.existsSync(configPath)) return false;
|
|
513
|
+
const config = readJsonConfig(configPath);
|
|
514
|
+
let changed = false;
|
|
515
|
+
const drop = (root) => {
|
|
516
|
+
if (!root || typeof root !== 'object') return;
|
|
517
|
+
for (const name of [SERVER_NAME, ...LEGACY_NAMES]) {
|
|
518
|
+
if (entryIsOurs(root[name])) {
|
|
519
|
+
delete root[name];
|
|
520
|
+
changed = true;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
drop(config.mcpServers);
|
|
525
|
+
drop(config.servers);
|
|
526
|
+
if (config.projects && typeof config.projects === 'object') {
|
|
527
|
+
for (const proj of Object.values(config.projects)) {
|
|
528
|
+
if (proj && typeof proj === 'object') {
|
|
529
|
+
drop(proj.mcpServers);
|
|
530
|
+
drop(proj.servers);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (changed) atomicWriteJson(configPath, config);
|
|
535
|
+
return changed;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Remove the auto-approval rule (and stale legacy ones) from Claude Code's settings. Only an
|
|
540
|
+
* existing file is touched. Returns how many rules went. `sweepLegacy: false` keeps the
|
|
541
|
+
* legacy-prefixed rules: an unrelated server still uses that name (see
|
|
542
|
+
* hasUnrelatedLegacyServer), so they are live, not stale.
|
|
543
|
+
*/
|
|
544
|
+
function removePermissionRule(permissionsPath, { sweepLegacy = true } = {}) {
|
|
545
|
+
if (!fs.existsSync(permissionsPath)) return 0;
|
|
546
|
+
const settings = readJsonConfig(permissionsPath);
|
|
547
|
+
const allow = settings.permissions && Array.isArray(settings.permissions.allow)
|
|
548
|
+
? settings.permissions.allow
|
|
549
|
+
: null;
|
|
550
|
+
if (!allow) return 0;
|
|
551
|
+
const isOurs = (rule) =>
|
|
552
|
+
typeof rule === 'string' &&
|
|
553
|
+
[PERMISSION_RULE, ...(sweepLegacy ? LEGACY_PERMISSION_PREFIXES : [])].some(
|
|
554
|
+
(p) => rule === p || rule.startsWith(`${p}__`)
|
|
555
|
+
);
|
|
556
|
+
const kept = allow.filter((r) => !isOurs(r));
|
|
557
|
+
const removed = allow.length - kept.length;
|
|
558
|
+
if (removed > 0) {
|
|
559
|
+
settings.permissions.allow = kept;
|
|
560
|
+
atomicWriteJson(permissionsPath, settings);
|
|
561
|
+
}
|
|
562
|
+
return removed;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* `--uninstall`: the MCP registration in every client, the auto-approval rule and the hook
|
|
567
|
+
* entries. `--hooks-only`: the hook entries only, and the person's no is recorded so Captain
|
|
568
|
+
* does not offer skill proof again for 15 days (`hooks decline`).
|
|
569
|
+
*/
|
|
570
|
+
function uninstall(binaryPath, { hooksOnly }) {
|
|
571
|
+
let failed = false;
|
|
572
|
+
if (!hooksOnly) {
|
|
573
|
+
for (const client of CLIENTS) {
|
|
574
|
+
try {
|
|
575
|
+
if (uninstallClient(client, binaryPath)) {
|
|
576
|
+
console.log(`Removed captain from ${client.name}: ${client.configPath(binaryPath)}`);
|
|
577
|
+
}
|
|
578
|
+
} catch (err) {
|
|
579
|
+
console.error(`Could not update ${client.name}: ${err.message}`);
|
|
580
|
+
failed = true;
|
|
581
|
+
}
|
|
582
|
+
if (client.permissionsPath) {
|
|
583
|
+
try {
|
|
584
|
+
// Same promise as the install sweep: an unrelated `captain-tool` server keeps its rules.
|
|
585
|
+
const sweepLegacy = !hasUnrelatedLegacyServer(readJsonConfig(client.configPath(binaryPath)));
|
|
586
|
+
const n = removePermissionRule(client.permissionsPath(), { sweepLegacy });
|
|
587
|
+
if (n > 0) console.log(`Removed ${n} auto-approval rule(s) from ${client.permissionsPath()}`);
|
|
588
|
+
} catch (err) {
|
|
589
|
+
console.error(`Could not update ${client.permissionsPath()}: ${err.message}`);
|
|
590
|
+
failed = true;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
const bin = hooksBinary(binaryPath);
|
|
596
|
+
if (!bin) {
|
|
597
|
+
console.warn('No captain-tool binary found: the skill-proof hook was not removed. Run `captain-tool hooks uninstall` once captain-tool is installed.');
|
|
598
|
+
return !failed && !hooksOnly;
|
|
599
|
+
}
|
|
600
|
+
const removed = runHooks(bin, ['uninstall']);
|
|
601
|
+
if (removed.output) console.log(removed.output);
|
|
602
|
+
if (!removed.ok) failed = true;
|
|
603
|
+
if (hooksOnly) {
|
|
604
|
+
const declined = runHooks(bin, ['decline']);
|
|
605
|
+
if (declined.output) console.log(declined.output);
|
|
606
|
+
if (!declined.ok) failed = true;
|
|
607
|
+
}
|
|
608
|
+
return !failed;
|
|
609
|
+
}
|
|
610
|
+
|
|
457
611
|
// ── Interactive prompt helpers ────────────────────────────────────────────────
|
|
458
612
|
|
|
459
613
|
/**
|
|
@@ -518,7 +672,17 @@ async function main() {
|
|
|
518
672
|
// enables auto-approval without prompting (for scripts/CI). Without the
|
|
519
673
|
// flag, a non-interactive stdin must be rejected up front — see prompt()
|
|
520
674
|
// for why EOF mid-question would otherwise end as a silent exit 0.
|
|
521
|
-
const
|
|
675
|
+
const flags = parseFlags(process.argv);
|
|
676
|
+
const assumeYes = flags.assumeYes;
|
|
677
|
+
|
|
678
|
+
// `--uninstall` (and `--hooks-only`, which removes only the skill-proof hook and records a
|
|
679
|
+
// decline) needs no prompt: it only removes what this wizard added.
|
|
680
|
+
if (flags.uninstall || flags.hooksOnly) {
|
|
681
|
+
const ok = uninstall(binaryPath, { hooksOnly: flags.hooksOnly });
|
|
682
|
+
if (!ok) process.exit(1);
|
|
683
|
+
console.log(flags.hooksOnly ? 'Skill-proof hook removed.' : 'Uninstall complete.');
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
522
686
|
|
|
523
687
|
let selected;
|
|
524
688
|
let wantPermissions = false;
|
|
@@ -652,6 +816,24 @@ async function main() {
|
|
|
652
816
|
}
|
|
653
817
|
}
|
|
654
818
|
|
|
819
|
+
// CAP-ADR-0042 (K8): Captain's skill-proof hook goes into Claude Code's user settings
|
|
820
|
+
// whenever Claude Code was configured, whether or not the Captain extension is in use. A
|
|
821
|
+
// failure here is a warning: the MCP registration above stands.
|
|
822
|
+
if (permIdx !== undefined) {
|
|
823
|
+
const bin = hooksBinary(binaryPath);
|
|
824
|
+
if (!bin) {
|
|
825
|
+
console.warn('Skill-proof hook skipped: no captain-tool binary found. Run `captain-tool hooks install` once captain-tool is installed.');
|
|
826
|
+
} else {
|
|
827
|
+
const installed = runHooks(bin, ['install']);
|
|
828
|
+
if (installed.ok) {
|
|
829
|
+
if (installed.output) console.log(installed.output);
|
|
830
|
+
} else {
|
|
831
|
+
console.warn(`Warning: skill-proof hook not installed: ${installed.output}`);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
console.log('');
|
|
835
|
+
}
|
|
836
|
+
|
|
655
837
|
if (anyFailed) {
|
|
656
838
|
process.exit(1);
|
|
657
839
|
}
|
|
@@ -690,6 +872,12 @@ module.exports = {
|
|
|
690
872
|
applyPermissionRule,
|
|
691
873
|
configurePermissions,
|
|
692
874
|
hasUnrelatedLegacyServer,
|
|
875
|
+
hooksBinary,
|
|
876
|
+
runHooks,
|
|
877
|
+
parseFlags,
|
|
878
|
+
uninstallClient,
|
|
879
|
+
removePermissionRule,
|
|
880
|
+
uninstall,
|
|
693
881
|
// Exported so the npx runner (`captain-tool setup`) can launch the wizard:
|
|
694
882
|
// the require.main gate above means a bare require() runs nothing.
|
|
695
883
|
main,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "captain-tool",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.119",
|
|
4
4
|
"description": "MCP server connecting Claude Desktop and VS Code Copilot to Captain Cloud",
|
|
5
5
|
"bin": {
|
|
6
6
|
"captain-tool": "bin/captain-tool",
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"test": "node test/setup.test.js"
|
|
12
12
|
},
|
|
13
13
|
"optionalDependencies": {
|
|
14
|
-
"@captain-tool/captain-tool-win32-x64": "0.0.
|
|
15
|
-
"@captain-tool/captain-tool-darwin-x64": "0.0.
|
|
16
|
-
"@captain-tool/captain-tool-darwin-arm64": "0.0.
|
|
17
|
-
"@captain-tool/captain-tool-linux-x64": "0.0.
|
|
14
|
+
"@captain-tool/captain-tool-win32-x64": "0.0.119",
|
|
15
|
+
"@captain-tool/captain-tool-darwin-x64": "0.0.119",
|
|
16
|
+
"@captain-tool/captain-tool-darwin-arm64": "0.0.119",
|
|
17
|
+
"@captain-tool/captain-tool-linux-x64": "0.0.119"
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
20
|
"bin/",
|