vault-go 0.16.0 → 0.16.1
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/dist/hook-install.d.ts +13 -0
- package/dist/hook-install.js +113 -0
- package/dist/hook-runner.d.ts +2 -0
- package/dist/hook-runner.js +9 -0
- package/dist/installer.d.ts +0 -3
- package/dist/installer.js +9 -70
- package/dist/local-install.js +10 -4
- package/package.json +5 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const HOOK_OWNER = "Vault Go: captura e contexto";
|
|
2
|
+
export declare const HOOK_EVENTS: {
|
|
3
|
+
readonly SessionStart: "context";
|
|
4
|
+
readonly UserPromptSubmit: "session-init";
|
|
5
|
+
readonly PreToolUse: "file-context";
|
|
6
|
+
readonly PostToolUse: "observation";
|
|
7
|
+
readonly Stop: "summarize";
|
|
8
|
+
};
|
|
9
|
+
export declare function quoteShell(value: string): string;
|
|
10
|
+
export declare function hookEntryPath(configHome?: string): string;
|
|
11
|
+
export declare function hookCommand(adapter: string, event: string, configHome?: string): string;
|
|
12
|
+
export declare function installClientHooks(client: "claude" | "codex", userHome?: string, configHome?: string): void;
|
|
13
|
+
export declare function repairClientHooks(userHome?: string, configHome?: string): void;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { vaultHome } from "./config.js";
|
|
6
|
+
function readJsonObject(path) {
|
|
7
|
+
if (!existsSync(path))
|
|
8
|
+
return {};
|
|
9
|
+
let parsed;
|
|
10
|
+
try {
|
|
11
|
+
parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
throw new Error(`JSON inválido em ${path}; o arquivo não foi alterado.`, {
|
|
15
|
+
cause: error,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
19
|
+
throw new Error(`Configuração inválida em ${path}; o arquivo não foi alterado.`);
|
|
20
|
+
}
|
|
21
|
+
return parsed;
|
|
22
|
+
}
|
|
23
|
+
function atomicWriteJson(path, value) {
|
|
24
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
25
|
+
const temporary = join(dirname(path), `.${process.pid}.${Date.now()}.tmp`);
|
|
26
|
+
writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\n`, {
|
|
27
|
+
mode: 0o600,
|
|
28
|
+
});
|
|
29
|
+
renameSync(temporary, path);
|
|
30
|
+
chmodSync(path, 0o600);
|
|
31
|
+
}
|
|
32
|
+
export const HOOK_OWNER = "Vault Go: captura e contexto";
|
|
33
|
+
export const HOOK_EVENTS = {
|
|
34
|
+
SessionStart: "context",
|
|
35
|
+
UserPromptSubmit: "session-init",
|
|
36
|
+
PreToolUse: "file-context",
|
|
37
|
+
PostToolUse: "observation",
|
|
38
|
+
Stop: "summarize",
|
|
39
|
+
};
|
|
40
|
+
export function quoteShell(value) {
|
|
41
|
+
return "'" + value.replaceAll("'", "'\\''") + "'";
|
|
42
|
+
}
|
|
43
|
+
export function hookEntryPath(configHome = vaultHome()) {
|
|
44
|
+
const staged = join(configHome, "local-runtime", "dist", "hook-runner.js");
|
|
45
|
+
if (existsSync(staged))
|
|
46
|
+
return staged;
|
|
47
|
+
return join(dirname(fileURLToPath(import.meta.url)), "hook-runner.js");
|
|
48
|
+
}
|
|
49
|
+
export function hookCommand(adapter, event, configHome = vaultHome()) {
|
|
50
|
+
return `${quoteShell(process.execPath)} ${quoteShell(hookEntryPath(configHome))} ${adapter} ${event}`;
|
|
51
|
+
}
|
|
52
|
+
function hookManifest(adapter, configHome = vaultHome()) {
|
|
53
|
+
return {
|
|
54
|
+
hooks: Object.fromEntries(Object.entries(HOOK_EVENTS).map(([name, event]) => [
|
|
55
|
+
name,
|
|
56
|
+
[
|
|
57
|
+
{
|
|
58
|
+
hooks: [
|
|
59
|
+
{
|
|
60
|
+
type: "command",
|
|
61
|
+
command: hookCommand(adapter, event, configHome),
|
|
62
|
+
timeout: event === "context" ? 60 : 20,
|
|
63
|
+
statusMessage: HOOK_OWNER,
|
|
64
|
+
...(event === "observation" ||
|
|
65
|
+
event === "summarize" ||
|
|
66
|
+
event === "file-context"
|
|
67
|
+
? { async: true }
|
|
68
|
+
: {}),
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
])),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export function installClientHooks(client, userHome = homedir(), configHome = vaultHome()) {
|
|
77
|
+
const path = join(userHome, client === "claude" ? ".claude/settings.json" : ".codex/hooks.json");
|
|
78
|
+
const config = readJsonObject(path);
|
|
79
|
+
const hooks = {
|
|
80
|
+
...(config.hooks &&
|
|
81
|
+
typeof config.hooks === "object" &&
|
|
82
|
+
!Array.isArray(config.hooks)
|
|
83
|
+
? config.hooks
|
|
84
|
+
: {}),
|
|
85
|
+
};
|
|
86
|
+
const desired = hookManifest(client, configHome).hooks;
|
|
87
|
+
for (const event of Object.keys(HOOK_EVENTS)) {
|
|
88
|
+
const current = hooks[event];
|
|
89
|
+
const retained = Array.isArray(current)
|
|
90
|
+
? current
|
|
91
|
+
.map((group) => {
|
|
92
|
+
if (!group ||
|
|
93
|
+
typeof group !== "object" ||
|
|
94
|
+
!Array.isArray(group.hooks))
|
|
95
|
+
return group;
|
|
96
|
+
const filtered = group.hooks.filter((hook) => !hook ||
|
|
97
|
+
typeof hook !== "object" ||
|
|
98
|
+
hook.statusMessage !== HOOK_OWNER);
|
|
99
|
+
return { ...group, hooks: filtered };
|
|
100
|
+
})
|
|
101
|
+
.filter((group) => !group ||
|
|
102
|
+
typeof group !== "object" ||
|
|
103
|
+
!Array.isArray(group.hooks) ||
|
|
104
|
+
group.hooks.length > 0)
|
|
105
|
+
: [];
|
|
106
|
+
hooks[event] = [...retained, ...(desired[event] || [])];
|
|
107
|
+
}
|
|
108
|
+
atomicWriteJson(path, { ...config, hooks });
|
|
109
|
+
}
|
|
110
|
+
export function repairClientHooks(userHome = homedir(), configHome = vaultHome()) {
|
|
111
|
+
installClientHooks("claude", userHome, configHome);
|
|
112
|
+
installClientHooks("codex", userHome, configHome);
|
|
113
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { HOOK_EVENTS, runHook } from "./hooks.js";
|
|
3
|
+
const adapter = process.argv[2] ?? "auto";
|
|
4
|
+
const event = process.argv[3];
|
|
5
|
+
if (!event || !HOOK_EVENTS.includes(event)) {
|
|
6
|
+
process.stderr.write("Uso: hook-runner <adaptador> context|session-init|observation|file-context|summarize\n");
|
|
7
|
+
process.exit(1);
|
|
8
|
+
}
|
|
9
|
+
await runHook(adapter, event);
|
package/dist/installer.d.ts
CHANGED
|
@@ -2,9 +2,6 @@ export declare const MCP_SERVER_NAME = "vault-go";
|
|
|
2
2
|
export declare const MCP_SERVER_COMMAND: readonly ["bunx", "--bun", "vault-go@latest", "serve"];
|
|
3
3
|
export declare const MCP_CLIENTS: readonly ["codex", "claude", "claude-desktop", "cursor", "vscode", "copilot", "windsurf", "roo", "opencode"];
|
|
4
4
|
export type McpClient = (typeof MCP_CLIENTS)[number];
|
|
5
|
-
export declare function quoteShell(value: string): string;
|
|
6
|
-
export declare function hookEntryPath(configHome?: string): string;
|
|
7
|
-
export declare function hookCommand(adapter: string, event: string, configHome?: string): string;
|
|
8
5
|
export interface DetectedClient {
|
|
9
6
|
client: McpClient;
|
|
10
7
|
detected: boolean;
|
package/dist/installer.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync, } from 'node:fs';
|
|
2
2
|
import { homedir, platform } from 'node:os';
|
|
3
3
|
import { dirname, join, resolve } from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
4
|
import { spawnSync } from 'node:child_process';
|
|
6
5
|
import { vaultHome } from './config.js';
|
|
7
6
|
import { stageLocalRuntime } from './local-install.js';
|
|
7
|
+
import { installClientHooks } from './hook-install.js';
|
|
8
8
|
export const MCP_SERVER_NAME = 'vault-go';
|
|
9
9
|
export const MCP_SERVER_COMMAND = ['bunx', '--bun', 'vault-go@latest', 'serve'];
|
|
10
10
|
export const MCP_CLIENTS = [
|
|
@@ -18,75 +18,6 @@ export const MCP_CLIENTS = [
|
|
|
18
18
|
'roo',
|
|
19
19
|
'opencode',
|
|
20
20
|
];
|
|
21
|
-
const HOOK_OWNER = 'Vault Go: captura e contexto';
|
|
22
|
-
const HOOK_EVENTS = {
|
|
23
|
-
SessionStart: 'context',
|
|
24
|
-
UserPromptSubmit: 'session-init',
|
|
25
|
-
PreToolUse: 'file-context',
|
|
26
|
-
PostToolUse: 'observation',
|
|
27
|
-
Stop: 'summarize',
|
|
28
|
-
};
|
|
29
|
-
export function quoteShell(value) {
|
|
30
|
-
return "'" + value.replaceAll("'", "'\\''") + "'";
|
|
31
|
-
}
|
|
32
|
-
export function hookEntryPath(configHome = vaultHome()) {
|
|
33
|
-
const staged = join(configHome, 'local-runtime', 'dist', 'index.js');
|
|
34
|
-
if (existsSync(staged))
|
|
35
|
-
return staged;
|
|
36
|
-
return join(dirname(fileURLToPath(import.meta.url)), 'index.js');
|
|
37
|
-
}
|
|
38
|
-
export function hookCommand(adapter, event, configHome = vaultHome()) {
|
|
39
|
-
return `${quoteShell(process.execPath)} ${quoteShell(hookEntryPath(configHome))} hook ${adapter} ${event}`;
|
|
40
|
-
}
|
|
41
|
-
function hookManifest(adapter, configHome = vaultHome()) {
|
|
42
|
-
return {
|
|
43
|
-
hooks: Object.fromEntries(Object.entries(HOOK_EVENTS).map(([name, event]) => [
|
|
44
|
-
name,
|
|
45
|
-
[
|
|
46
|
-
{
|
|
47
|
-
hooks: [
|
|
48
|
-
{
|
|
49
|
-
type: 'command',
|
|
50
|
-
command: hookCommand(adapter, event, configHome),
|
|
51
|
-
timeout: event === 'context' ? 60 : 20,
|
|
52
|
-
statusMessage: HOOK_OWNER,
|
|
53
|
-
...(event === 'observation' || event === 'summarize' || event === 'file-context'
|
|
54
|
-
? { async: true }
|
|
55
|
-
: {}),
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
},
|
|
59
|
-
],
|
|
60
|
-
])),
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function installClientHooks(client, userHome, configHome = vaultHome()) {
|
|
64
|
-
try {
|
|
65
|
-
stageLocalRuntime(configHome);
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
/* tests and incomplete installs still write the hook command */
|
|
69
|
-
}
|
|
70
|
-
const path = join(userHome, client === 'claude' ? '.claude/settings.json' : '.codex/hooks.json');
|
|
71
|
-
const config = readJsonObject(path);
|
|
72
|
-
const hooks = { ...(config.hooks && typeof config.hooks === 'object' && !Array.isArray(config.hooks) ? config.hooks : {}) };
|
|
73
|
-
const desired = hookManifest(client, configHome).hooks;
|
|
74
|
-
for (const event of Object.keys(HOOK_EVENTS)) {
|
|
75
|
-
const current = hooks[event];
|
|
76
|
-
const retained = Array.isArray(current)
|
|
77
|
-
? current
|
|
78
|
-
.map((group) => {
|
|
79
|
-
if (!group || typeof group !== 'object' || !Array.isArray(group.hooks))
|
|
80
|
-
return group;
|
|
81
|
-
const filtered = group.hooks.filter((hook) => !hook || typeof hook !== 'object' || hook.statusMessage !== HOOK_OWNER);
|
|
82
|
-
return { ...group, hooks: filtered };
|
|
83
|
-
})
|
|
84
|
-
.filter((group) => !group || typeof group !== 'object' || !Array.isArray(group.hooks) || group.hooks.length > 0)
|
|
85
|
-
: [];
|
|
86
|
-
hooks[event] = [...retained, ...(desired[event] || [])];
|
|
87
|
-
}
|
|
88
|
-
atomicWriteJson(path, { ...config, hooks });
|
|
89
|
-
}
|
|
90
21
|
const runCommand = (command, args) => spawnSync(command, [...args], { stdio: 'ignore' });
|
|
91
22
|
function readJsonObject(path) {
|
|
92
23
|
if (!existsSync(path))
|
|
@@ -156,6 +87,10 @@ export function installMcpClient(client, options = {}) {
|
|
|
156
87
|
const runner = options.runner ?? runCommand;
|
|
157
88
|
if (client === 'codex') {
|
|
158
89
|
const result = installViaCli(client, 'codex', ['mcp', 'get', MCP_SERVER_NAME], ['mcp', 'add', MCP_SERVER_NAME, '--', ...MCP_SERVER_COMMAND], runner);
|
|
90
|
+
try {
|
|
91
|
+
stageLocalRuntime(vaultHome());
|
|
92
|
+
}
|
|
93
|
+
catch { /* incomplete installs still write hooks */ }
|
|
159
94
|
installClientHooks('codex', home);
|
|
160
95
|
return result;
|
|
161
96
|
}
|
|
@@ -171,6 +106,10 @@ export function installMcpClient(client, options = {}) {
|
|
|
171
106
|
'--',
|
|
172
107
|
...MCP_SERVER_COMMAND,
|
|
173
108
|
], runner);
|
|
109
|
+
try {
|
|
110
|
+
stageLocalRuntime(vaultHome());
|
|
111
|
+
}
|
|
112
|
+
catch { /* incomplete installs still write hooks */ }
|
|
174
113
|
installClientHooks('claude', home);
|
|
175
114
|
return result;
|
|
176
115
|
}
|
package/dist/local-install.js
CHANGED
|
@@ -51,13 +51,10 @@ export function stageLocalRuntime(home = vaultHome(), source = dirname(fileURLTo
|
|
|
51
51
|
mkdirSync(target, { recursive: true, mode: 0o700 });
|
|
52
52
|
chmodSync(root, 0o700);
|
|
53
53
|
chmodSync(target, 0o700);
|
|
54
|
-
const excluded = new Set(["server.js", "installer.js", "cli.js"]);
|
|
55
54
|
if (!existsSync(join(source, "local-worker.js")))
|
|
56
55
|
throw new Error("Local worker is missing. Build or reinstall vault-go first.");
|
|
57
56
|
for (const file of readdirSync(source)) {
|
|
58
|
-
if (!file.endsWith(".js") ||
|
|
59
|
-
file.endsWith(".test.js") ||
|
|
60
|
-
excluded.has(file))
|
|
57
|
+
if (!file.endsWith(".js") || file.endsWith(".test.js"))
|
|
61
58
|
continue;
|
|
62
59
|
const destination = join(target, file);
|
|
63
60
|
copyFileSync(join(source, file), `${destination}.tmp`);
|
|
@@ -76,6 +73,8 @@ export function stageLocalRuntime(home = vaultHome(), source = dirname(fileURLTo
|
|
|
76
73
|
version: manifest.version,
|
|
77
74
|
type: "module",
|
|
78
75
|
}), { mode: 0o600 });
|
|
76
|
+
if (!existsSync(join(target, "hook-runner.js")))
|
|
77
|
+
throw new Error("Hook runner is missing. Build or reinstall vault-go first.");
|
|
79
78
|
return join(target, "local-worker.js");
|
|
80
79
|
}
|
|
81
80
|
export async function startLocal(home = vaultHome()) {
|
|
@@ -218,6 +217,13 @@ export async function replaceLaunchAgent(domain, path, prepare, operations) {
|
|
|
218
217
|
}
|
|
219
218
|
export async function installLocal(home = vaultHome()) {
|
|
220
219
|
const worker = stageLocalRuntime(home);
|
|
220
|
+
try {
|
|
221
|
+
const { repairClientHooks } = await import("./hook-install.js");
|
|
222
|
+
repairClientHooks(homedir(), home);
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
/* settings files may not exist yet */
|
|
226
|
+
}
|
|
221
227
|
if (process.platform !== "darwin") {
|
|
222
228
|
await startLocal(home);
|
|
223
229
|
return { startup: false };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vault-go",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "Servidor MCP universal com autenticação e instalação multi-cliente para a plataforma Vault.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -34,8 +34,12 @@
|
|
|
34
34
|
"dist/config.d.ts",
|
|
35
35
|
"dist/context-engines.js",
|
|
36
36
|
"dist/context-engines.d.ts",
|
|
37
|
+
"dist/hook-install.js",
|
|
38
|
+
"dist/hook-install.d.ts",
|
|
37
39
|
"dist/hook-queue.js",
|
|
38
40
|
"dist/hook-queue.d.ts",
|
|
41
|
+
"dist/hook-runner.js",
|
|
42
|
+
"dist/hook-runner.d.ts",
|
|
39
43
|
"dist/hooks.js",
|
|
40
44
|
"dist/hooks.d.ts",
|
|
41
45
|
"dist/index.js",
|