@pushary/agent-hooks 0.66.0 → 0.67.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/CHANGELOG.md +34 -0
- package/data/SKILL.md +105 -30
- package/data/cursor-plugin/skills/pushary/SKILL.md +103 -24
- package/data/vscode-plugin/.claude-plugin/plugin.json +28 -0
- package/data/vscode-plugin/.mcp.json +11 -0
- package/data/vscode-plugin/CHANGELOG.md +11 -0
- package/data/vscode-plugin/LICENSE +21 -0
- package/data/vscode-plugin/README.md +136 -0
- package/data/vscode-plugin/SECURITY.md +56 -0
- package/data/vscode-plugin/assets/logo.png +0 -0
- package/data/vscode-plugin/commands/notify-when-done.md +14 -0
- package/data/vscode-plugin/commands/pushary-test.md +13 -0
- package/data/vscode-plugin/hooks/hooks.json +11 -0
- package/data/vscode-plugin/scripts/pushary-gate.mjs +508 -0
- package/data/vscode-plugin/skills/pushary/SKILL.md +376 -0
- package/dist/bin/pushary-clean.js +29 -4
- package/dist/bin/pushary-connect.js +1 -1
- package/dist/bin/pushary-doctor.js +43 -8
- package/dist/bin/pushary-logout.js +1 -1
- package/dist/bin/pushary-setup.js +130 -8
- package/dist/bin/pushary-status.js +1 -1
- package/dist/bin/pushary-upgrade.js +17 -5
- package/dist/{chunk-RU3CIBXY.js → chunk-7HG4WUIE.js} +4 -0
- package/dist/chunk-KB4ODLGB.js +332 -0
- package/dist/{chunk-QTC7SR6A.js → chunk-V6OA4VPU.js} +24 -5
- package/package.json +2 -7
- package/dist/chunk-6G2BC4ET.js +0 -93
- package/dist/chunk-N7XJ4L2W.js +0 -79
|
@@ -10,13 +10,15 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
describeDetection,
|
|
12
12
|
detectAllAgents,
|
|
13
|
-
isDetected
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
isDetected,
|
|
14
|
+
pluginLocationSnippet,
|
|
15
|
+
registerPluginLocation,
|
|
16
16
|
renderAgentInstructions,
|
|
17
17
|
renderProjectAgentInstructions,
|
|
18
|
+
shortenHome,
|
|
19
|
+
vscodeSettingsTargets,
|
|
18
20
|
writeInstructionBlock
|
|
19
|
-
} from "../chunk-
|
|
21
|
+
} from "../chunk-KB4ODLGB.js";
|
|
20
22
|
import {
|
|
21
23
|
GEMINI_HOOK_BINARY,
|
|
22
24
|
addGeminiHooks,
|
|
@@ -37,15 +39,16 @@ import {
|
|
|
37
39
|
cursorUserHooks,
|
|
38
40
|
geminiMd,
|
|
39
41
|
geminiSettings,
|
|
40
|
-
pusharyConfigFile
|
|
41
|
-
|
|
42
|
+
pusharyConfigFile,
|
|
43
|
+
vscodePluginDir
|
|
44
|
+
} from "../chunk-7HG4WUIE.js";
|
|
42
45
|
import {
|
|
43
46
|
confirmAppConnection,
|
|
44
47
|
connectDevice,
|
|
45
48
|
connectViaAppPairing,
|
|
46
49
|
printConnectInstructions,
|
|
47
50
|
setHumanStream
|
|
48
|
-
} from "../chunk-
|
|
51
|
+
} from "../chunk-V6OA4VPU.js";
|
|
49
52
|
import "../chunk-3EGEA4KH.js";
|
|
50
53
|
import {
|
|
51
54
|
KEY_FILE_MODE,
|
|
@@ -262,7 +265,7 @@ var reportSetupAbortWith = async (deps, reason, exitCode, keyCheck = "unknown")
|
|
|
262
265
|
var reportSetupAbort = (reason, exitCode, keyCheck) => reportSetupAbortWith(defaultDeps, reason, exitCode, keyCheck);
|
|
263
266
|
|
|
264
267
|
// src/setup/options.ts
|
|
265
|
-
var AGENT_CHOICES = ["claude_code", "codex", "gemini_cli", "hermes", "cursor", "custom"];
|
|
268
|
+
var AGENT_CHOICES = ["claude_code", "codex", "gemini_cli", "hermes", "cursor", "vscode", "custom"];
|
|
266
269
|
var CONNECT_MODES = ["app", "browser", "web", "none"];
|
|
267
270
|
var CONNECT_ALIASES = { auto: "app", pwa: "web" };
|
|
268
271
|
var parseConnectMode = (raw) => {
|
|
@@ -340,6 +343,7 @@ var CLAUDE_SETTINGS = claudeSettings();
|
|
|
340
343
|
var CLAUDE_JSON = claudeJson();
|
|
341
344
|
var CURSOR_PLUGIN_DIR = cursorPluginDir();
|
|
342
345
|
var CURSOR_USER_HOOKS = cursorUserHooks();
|
|
346
|
+
var VSCODE_PLUGIN_DIR = vscodePluginDir();
|
|
343
347
|
var CLAUDE_SKILL_DIR = claudeSkillDir();
|
|
344
348
|
var CODEX_HOME = codexHome();
|
|
345
349
|
var CODEX_SKILL_DIR = codexSkillDir();
|
|
@@ -849,6 +853,120 @@ var setupCursor = async (apiKey) => {
|
|
|
849
853
|
console.log(` ${dim("\u2022")} Fully quit and reopen Cursor to load it (a Reload Window may not be enough)`);
|
|
850
854
|
noteManual("Fully quit and reopen Cursor. A Reload Window may not be enough.");
|
|
851
855
|
};
|
|
856
|
+
var resolveBundledVsCodePlugin = () => {
|
|
857
|
+
const dir = dirname(fileURLToPath(import.meta.url));
|
|
858
|
+
const candidates = [
|
|
859
|
+
join(dir, "..", "..", "data", "vscode-plugin"),
|
|
860
|
+
join(dir, "..", "data", "vscode-plugin"),
|
|
861
|
+
join(dir, "..", "..", "..", "vscode-plugin"),
|
|
862
|
+
join(dir, "..", "..", "vscode-plugin")
|
|
863
|
+
];
|
|
864
|
+
return candidates.find((p) => existsSync(join(p, ".claude-plugin", "plugin.json"))) ?? null;
|
|
865
|
+
};
|
|
866
|
+
var pinVsCodeGatePath = (pluginDir) => {
|
|
867
|
+
const hooksPath = join(pluginDir, "hooks", "hooks.json");
|
|
868
|
+
const data = readJson(hooksPath);
|
|
869
|
+
const entries = data.hooks?.PreToolUse;
|
|
870
|
+
if (!Array.isArray(entries) || entries.length === 0) {
|
|
871
|
+
throw new Error("bundled VS Code hooks.json is missing a PreToolUse entry");
|
|
872
|
+
}
|
|
873
|
+
const gate = join(pluginDir, "scripts", "pushary-gate.mjs");
|
|
874
|
+
data.hooks.PreToolUse = entries.map((entry) => ({ ...entry, command: `node "${gate}"` }));
|
|
875
|
+
writeJson(hooksPath, data);
|
|
876
|
+
};
|
|
877
|
+
var registerVsCodePlugin = (pluginDir) => {
|
|
878
|
+
const written = [];
|
|
879
|
+
const manual = [];
|
|
880
|
+
for (const settingsPath of vscodeSettingsTargets(existsSync)) {
|
|
881
|
+
const current = existsSync(settingsPath) ? readFileSync(settingsPath, "utf-8") : null;
|
|
882
|
+
const result = registerPluginLocation(current, pluginDir);
|
|
883
|
+
if (result.kind === "already") continue;
|
|
884
|
+
if (result.kind === "manual") {
|
|
885
|
+
manual.push(settingsPath);
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
888
|
+
if (current !== null) backupFile(settingsPath);
|
|
889
|
+
mkdirSync(dirname(settingsPath), { recursive: true });
|
|
890
|
+
writeFileAtomic(settingsPath, result.content);
|
|
891
|
+
written.push(settingsPath);
|
|
892
|
+
}
|
|
893
|
+
return { written, manual };
|
|
894
|
+
};
|
|
895
|
+
var setupVsCode = async (apiKey) => {
|
|
896
|
+
console.log(`
|
|
897
|
+
${bold("Setting up VS Code")}
|
|
898
|
+
`);
|
|
899
|
+
const source = resolveBundledVsCodePlugin();
|
|
900
|
+
if (!source) throw new Error("bundled VS Code plugin not found in this package");
|
|
901
|
+
await spinner("Installing Pushary plugin", async () => {
|
|
902
|
+
const staging = join(dirname(VSCODE_PLUGIN_DIR), `.pushary-staging-vscode-${process.pid}`);
|
|
903
|
+
const backup = `${VSCODE_PLUGIN_DIR}.pushary-backup-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}`;
|
|
904
|
+
mkdirSync(dirname(VSCODE_PLUGIN_DIR), { recursive: true });
|
|
905
|
+
rmSync(staging, { recursive: true, force: true });
|
|
906
|
+
try {
|
|
907
|
+
cpSync(source, staging, {
|
|
908
|
+
recursive: true,
|
|
909
|
+
filter: (p) => !["tools", "node_modules", ".git", ".DS_Store"].includes(basename(p))
|
|
910
|
+
});
|
|
911
|
+
const staged = readJsonSafe(join(staging, ".claude-plugin", "plugin.json"));
|
|
912
|
+
if (staged.kind !== "ok") {
|
|
913
|
+
throw new Error("staged VS Code plugin is missing or has an unreadable plugin.json");
|
|
914
|
+
}
|
|
915
|
+
const hadExisting = existsSync(VSCODE_PLUGIN_DIR);
|
|
916
|
+
if (hadExisting) renameSync(VSCODE_PLUGIN_DIR, backup);
|
|
917
|
+
try {
|
|
918
|
+
renameSync(staging, VSCODE_PLUGIN_DIR);
|
|
919
|
+
} catch (err) {
|
|
920
|
+
if (hadExisting) renameSync(backup, VSCODE_PLUGIN_DIR);
|
|
921
|
+
throw err;
|
|
922
|
+
}
|
|
923
|
+
if (hadExisting) rmSync(backup, { recursive: true, force: true });
|
|
924
|
+
} finally {
|
|
925
|
+
rmSync(staging, { recursive: true, force: true });
|
|
926
|
+
}
|
|
927
|
+
});
|
|
928
|
+
await spinner("Linking your API key", async () => {
|
|
929
|
+
const mcpPath = join(VSCODE_PLUGIN_DIR, ".mcp.json");
|
|
930
|
+
const mcp = readAgentJson(mcpPath);
|
|
931
|
+
const servers = mcp.mcpServers ?? {};
|
|
932
|
+
if (servers.pushary) {
|
|
933
|
+
servers.pushary.headers = { ...servers.pushary.headers, Authorization: `Bearer ${apiKey}` };
|
|
934
|
+
mcp.mcpServers = servers;
|
|
935
|
+
writeJsonAtomic(mcpPath, mcp, KEY_FILE_MODE);
|
|
936
|
+
}
|
|
937
|
+
pinVsCodeGatePath(VSCODE_PLUGIN_DIR);
|
|
938
|
+
});
|
|
939
|
+
let registration = { written: [], manual: [] };
|
|
940
|
+
await spinner("Registering the plugin with VS Code", async () => {
|
|
941
|
+
registration = registerVsCodePlugin(VSCODE_PLUGIN_DIR);
|
|
942
|
+
});
|
|
943
|
+
console.log();
|
|
944
|
+
console.log(` ${dim("What this configured:")}`);
|
|
945
|
+
console.log(` ${dim("\u2022")} Plugin installed to ${shortenHome(VSCODE_PLUGIN_DIR)} (MCP tools, skill, commands)`);
|
|
946
|
+
for (const path of registration.written) {
|
|
947
|
+
console.log(` ${dim("\u2022")} Registered in ${shortenHome(path)} under chat.pluginLocations`);
|
|
948
|
+
}
|
|
949
|
+
console.log(` ${dim("\u2022")} Risky shell commands route to push approval before they run`);
|
|
950
|
+
if (registration.manual.length > 0) {
|
|
951
|
+
console.log();
|
|
952
|
+
console.log(` ${yellow("!")} ${bold("One step left, by hand")}`);
|
|
953
|
+
console.log(` ${dim("These settings files already have a chat.pluginLocations block, and")}`);
|
|
954
|
+
console.log(` ${dim("they contain comments, so they were left untouched rather than rewritten.")}`);
|
|
955
|
+
console.log(` ${dim("Add this entry inside that block:")}`);
|
|
956
|
+
console.log();
|
|
957
|
+
console.log(` ${cyan(`${JSON.stringify(VSCODE_PLUGIN_DIR)}: true`)}`);
|
|
958
|
+
console.log();
|
|
959
|
+
for (const path of registration.manual) {
|
|
960
|
+
console.log(` ${dim("in")} ${path}`);
|
|
961
|
+
}
|
|
962
|
+
noteManual(
|
|
963
|
+
`Add ${JSON.stringify(VSCODE_PLUGIN_DIR)}: true to the chat.pluginLocations block in ${registration.manual.join(" and ")}. Full snippet:
|
|
964
|
+
${pluginLocationSnippet(VSCODE_PLUGIN_DIR)}`
|
|
965
|
+
);
|
|
966
|
+
}
|
|
967
|
+
console.log(` ${dim("\u2022")} Fully quit and reopen VS Code to load the plugin`);
|
|
968
|
+
noteManual("Fully quit and reopen VS Code. A Reload Window may not pick up a new plugin location.");
|
|
969
|
+
};
|
|
852
970
|
var saveApiKey = async (apiKey) => {
|
|
853
971
|
let result;
|
|
854
972
|
await spinner("Saving your API key", async () => {
|
|
@@ -941,6 +1059,7 @@ var AGENT_SETUP = {
|
|
|
941
1059
|
gemini_cli: setupGemini,
|
|
942
1060
|
hermes: setupHermes,
|
|
943
1061
|
cursor: setupCursor,
|
|
1062
|
+
vscode: setupVsCode,
|
|
944
1063
|
custom: setupCustom
|
|
945
1064
|
};
|
|
946
1065
|
var PROJECT_INSTRUCTION_TARGETS = {
|
|
@@ -1042,6 +1161,7 @@ var AGENT_NAMES = {
|
|
|
1042
1161
|
gemini_cli: "Gemini CLI",
|
|
1043
1162
|
hermes: "Hermes",
|
|
1044
1163
|
cursor: "Cursor",
|
|
1164
|
+
vscode: "VS Code",
|
|
1045
1165
|
custom: "Other"
|
|
1046
1166
|
};
|
|
1047
1167
|
var AGENT_CAPABILITIES = {
|
|
@@ -1050,6 +1170,7 @@ var AGENT_CAPABILITIES = {
|
|
|
1050
1170
|
gemini_cli: "MCP + native hooks + auto-allowed tools",
|
|
1051
1171
|
hermes: "native plugin + auto-error notifications",
|
|
1052
1172
|
cursor: "plugin + permission gate",
|
|
1173
|
+
vscode: "agent plugin + permission gate",
|
|
1053
1174
|
custom: "any MCP or HTTP agent (Windsurf, n8n, custom)"
|
|
1054
1175
|
};
|
|
1055
1176
|
var NAME_COLUMN = Math.max(...Object.values(AGENT_NAMES).map((name) => name.length)) + 2;
|
|
@@ -1111,6 +1232,7 @@ var AGENT_TARGETS = {
|
|
|
1111
1232
|
gemini_cli: [GEMINI_SETTINGS, GEMINI_MD],
|
|
1112
1233
|
hermes: ["the Hermes virtualenv (pip install pushary-hermes)"],
|
|
1113
1234
|
cursor: [join(CURSOR_PLUGIN_DIR, "mcp.json"), CURSOR_USER_HOOKS],
|
|
1235
|
+
vscode: [join(VSCODE_PLUGIN_DIR, ".mcp.json"), ...vscodeSettingsTargets(existsSync)],
|
|
1114
1236
|
custom: ["nothing (prints connection details only)"]
|
|
1115
1237
|
};
|
|
1116
1238
|
var reportDryRun = (apiKey, agents, keyCheck) => {
|
|
@@ -20,8 +20,10 @@ import {
|
|
|
20
20
|
codexHooksJson,
|
|
21
21
|
cursorPluginDir,
|
|
22
22
|
geminiSettings,
|
|
23
|
-
hasCodexHooks
|
|
24
|
-
|
|
23
|
+
hasCodexHooks,
|
|
24
|
+
vscodePluginDir,
|
|
25
|
+
vscodePluginMcp
|
|
26
|
+
} from "../chunk-7HG4WUIE.js";
|
|
25
27
|
import {
|
|
26
28
|
readJsonSafe
|
|
27
29
|
} from "../chunk-6MTNS63X.js";
|
|
@@ -160,8 +162,7 @@ var reapplyGeminiSettings = (apiKey, paths = {}) => {
|
|
|
160
162
|
}
|
|
161
163
|
return { reapplied: hooks || mcp, hooks, mcp };
|
|
162
164
|
};
|
|
163
|
-
var
|
|
164
|
-
const mcpPath = paths.pluginMcpPath ?? join(homedir(), ".cursor", "plugins", "local", "pushary", "mcp.json");
|
|
165
|
+
var reapplyPluginMcp = (mcpPath, apiKey) => {
|
|
165
166
|
if (!apiKey) return { reapplied: false, hooks: false, mcp: false };
|
|
166
167
|
const mcpConfig = readJson(mcpPath);
|
|
167
168
|
if (mcpConfig == null) return { reapplied: false, hooks: false, mcp: false };
|
|
@@ -175,12 +176,18 @@ var reapplyCursorPlugin = (apiKey, paths = {}) => {
|
|
|
175
176
|
return { reapplied: false, hooks: false, mcp: false };
|
|
176
177
|
}
|
|
177
178
|
};
|
|
179
|
+
var reapplyCursorPlugin = (apiKey, paths = {}) => reapplyPluginMcp(
|
|
180
|
+
paths.pluginMcpPath ?? join(homedir(), ".cursor", "plugins", "local", "pushary", "mcp.json"),
|
|
181
|
+
apiKey
|
|
182
|
+
);
|
|
183
|
+
var reapplyVsCodePlugin = (apiKey, paths = {}) => reapplyPluginMcp(paths.pluginMcpPath ?? vscodePluginMcp(), apiKey);
|
|
178
184
|
var reapplyAllAgents = (apiKey) => {
|
|
179
185
|
const runners = [
|
|
180
186
|
{ label: "Claude Code", run: () => reapplyClaudeSettings(apiKey) },
|
|
181
187
|
{ label: "Codex", run: () => reapplyCodexSettings(apiKey) },
|
|
182
188
|
{ label: "Gemini CLI", run: () => reapplyGeminiSettings(apiKey) },
|
|
183
|
-
{ label: "Cursor", run: () => reapplyCursorPlugin(apiKey) }
|
|
189
|
+
{ label: "Cursor", run: () => reapplyCursorPlugin(apiKey) },
|
|
190
|
+
{ label: "VS Code", run: () => reapplyVsCodePlugin(apiKey) }
|
|
184
191
|
];
|
|
185
192
|
const done = [];
|
|
186
193
|
for (const runner of runners) {
|
|
@@ -202,6 +209,11 @@ var detectInstallModes = () => {
|
|
|
202
209
|
upgrade: "updates itself through Cursor",
|
|
203
210
|
present: existsSync2(cursorPluginDir())
|
|
204
211
|
},
|
|
212
|
+
{
|
|
213
|
+
label: "VS Code plugin",
|
|
214
|
+
upgrade: "npx @pushary/agent-hooks@latest setup --agents vscode",
|
|
215
|
+
present: existsSync2(vscodePluginDir())
|
|
216
|
+
},
|
|
205
217
|
{
|
|
206
218
|
label: "Codex config",
|
|
207
219
|
upgrade: "npx @pushary/agent-hooks@latest setup --agents codex",
|
|
@@ -158,6 +158,8 @@ var claudeSkillDir = () => join2(homedir2(), ".claude", "skills", "pushary");
|
|
|
158
158
|
var cursorPluginDir = () => join2(homedir2(), ".cursor", "plugins", "local", "pushary");
|
|
159
159
|
var cursorUserHooks = () => join2(homedir2(), ".cursor", "hooks.json");
|
|
160
160
|
var cursorUserMcp = () => join2(homedir2(), ".cursor", "mcp.json");
|
|
161
|
+
var vscodePluginDir = () => join2(homedir2(), ".pushary", "plugins", "vscode");
|
|
162
|
+
var vscodePluginMcp = () => join2(vscodePluginDir(), ".mcp.json");
|
|
161
163
|
var claudeSettingsLocal = () => join2(homedir2(), ".claude", "settings.local.json");
|
|
162
164
|
var pusharyDir = () => join2(homedir2(), ".pushary");
|
|
163
165
|
var codexSkillDir2 = () => join2(codexHome(), "skills", "pushary");
|
|
@@ -188,6 +190,8 @@ export {
|
|
|
188
190
|
cursorPluginDir,
|
|
189
191
|
cursorUserHooks,
|
|
190
192
|
cursorUserMcp,
|
|
193
|
+
vscodePluginDir,
|
|
194
|
+
vscodePluginMcp,
|
|
191
195
|
claudeSettingsLocal,
|
|
192
196
|
pusharyDir,
|
|
193
197
|
codexSkillDir2,
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import {
|
|
2
|
+
codexHomeFrom
|
|
3
|
+
} from "./chunk-7HG4WUIE.js";
|
|
4
|
+
|
|
5
|
+
// src/vscode-config.ts
|
|
6
|
+
import { homedir } from "os";
|
|
7
|
+
import { join } from "path";
|
|
8
|
+
var PLUGIN_LOCATIONS_KEY = "chat.pluginLocations";
|
|
9
|
+
var blankJsonComments = (text) => {
|
|
10
|
+
let out = "";
|
|
11
|
+
let i = 0;
|
|
12
|
+
let inString = false;
|
|
13
|
+
let escaped = false;
|
|
14
|
+
while (i < text.length) {
|
|
15
|
+
const ch = text[i];
|
|
16
|
+
if (inString) {
|
|
17
|
+
out += ch;
|
|
18
|
+
if (escaped) escaped = false;
|
|
19
|
+
else if (ch === "\\") escaped = true;
|
|
20
|
+
else if (ch === '"') inString = false;
|
|
21
|
+
i += 1;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (ch === '"') {
|
|
25
|
+
inString = true;
|
|
26
|
+
out += ch;
|
|
27
|
+
i += 1;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (ch === "/" && text[i + 1] === "/") {
|
|
31
|
+
while (i < text.length && text[i] !== "\n") {
|
|
32
|
+
out += " ";
|
|
33
|
+
i += 1;
|
|
34
|
+
}
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (ch === "/" && text[i + 1] === "*") {
|
|
38
|
+
const end = text.indexOf("*/", i + 2);
|
|
39
|
+
const stop = end === -1 ? text.length : end + 2;
|
|
40
|
+
while (i < stop) {
|
|
41
|
+
out += text[i] === "\n" ? "\n" : " ";
|
|
42
|
+
i += 1;
|
|
43
|
+
}
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
out += ch;
|
|
47
|
+
i += 1;
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
};
|
|
51
|
+
var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
52
|
+
var parseJsonc = (text) => {
|
|
53
|
+
const blanked = blankJsonComments(text);
|
|
54
|
+
const withoutTrailingCommas = blanked.replace(/,(\s*[}\]])/g, "$1");
|
|
55
|
+
try {
|
|
56
|
+
return asRecord(JSON.parse(withoutTrailingCommas));
|
|
57
|
+
} catch {
|
|
58
|
+
return void 0;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var rootBraceIndex = (text) => blankJsonComments(text).indexOf("{");
|
|
62
|
+
var detectIndent = (text) => {
|
|
63
|
+
const match = /\n([ \t]+)"/.exec(text);
|
|
64
|
+
return match?.[1] ?? " ";
|
|
65
|
+
};
|
|
66
|
+
var freshDocument = (pluginDir, indent = " ") => `${JSON.stringify({ [PLUGIN_LOCATIONS_KEY]: { [pluginDir]: true } }, null, indent)}
|
|
67
|
+
`;
|
|
68
|
+
var registerPluginLocation = (existing, pluginDir) => {
|
|
69
|
+
if (existing === null || existing.trim() === "") {
|
|
70
|
+
return { kind: "created", content: freshDocument(pluginDir) };
|
|
71
|
+
}
|
|
72
|
+
const indent = detectIndent(existing);
|
|
73
|
+
try {
|
|
74
|
+
const parsed2 = asRecord(JSON.parse(existing));
|
|
75
|
+
if (parsed2) {
|
|
76
|
+
const locations2 = asRecord(parsed2[PLUGIN_LOCATIONS_KEY]) ?? {};
|
|
77
|
+
if (locations2[pluginDir] === true) return { kind: "already" };
|
|
78
|
+
parsed2[PLUGIN_LOCATIONS_KEY] = { ...locations2, [pluginDir]: true };
|
|
79
|
+
return { kind: "merged", content: `${JSON.stringify(parsed2, null, indent)}
|
|
80
|
+
` };
|
|
81
|
+
}
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
const parsed = parseJsonc(existing);
|
|
85
|
+
if (!parsed) return { kind: "manual" };
|
|
86
|
+
const locations = asRecord(parsed[PLUGIN_LOCATIONS_KEY]);
|
|
87
|
+
if (locations?.[pluginDir] === true) return { kind: "already" };
|
|
88
|
+
if (parsed[PLUGIN_LOCATIONS_KEY] !== void 0) return { kind: "manual" };
|
|
89
|
+
const brace = rootBraceIndex(existing);
|
|
90
|
+
if (brace === -1) return { kind: "manual" };
|
|
91
|
+
const needsComma = Object.keys(parsed).length > 0;
|
|
92
|
+
const line = `
|
|
93
|
+
${indent}${JSON.stringify(PLUGIN_LOCATIONS_KEY)}: { ${JSON.stringify(pluginDir)}: true }${needsComma ? "," : ""}`;
|
|
94
|
+
return {
|
|
95
|
+
kind: "inserted",
|
|
96
|
+
content: `${existing.slice(0, brace + 1)}${line}${existing.slice(brace + 1)}`
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
var unregisterPluginLocation = (existing, pluginDir) => {
|
|
100
|
+
if (existing === null || existing.trim() === "") return { kind: "absent" };
|
|
101
|
+
const indent = detectIndent(existing);
|
|
102
|
+
try {
|
|
103
|
+
const parsed2 = asRecord(JSON.parse(existing));
|
|
104
|
+
if (parsed2) {
|
|
105
|
+
const locations2 = asRecord(parsed2[PLUGIN_LOCATIONS_KEY]);
|
|
106
|
+
if (!locations2 || !(pluginDir in locations2)) return { kind: "absent" };
|
|
107
|
+
const remaining = { ...locations2 };
|
|
108
|
+
delete remaining[pluginDir];
|
|
109
|
+
if (Object.keys(remaining).length === 0) delete parsed2[PLUGIN_LOCATIONS_KEY];
|
|
110
|
+
else parsed2[PLUGIN_LOCATIONS_KEY] = remaining;
|
|
111
|
+
return { kind: "removed", content: `${JSON.stringify(parsed2, null, indent)}
|
|
112
|
+
` };
|
|
113
|
+
}
|
|
114
|
+
} catch {
|
|
115
|
+
}
|
|
116
|
+
const parsed = parseJsonc(existing);
|
|
117
|
+
if (!parsed) return { kind: "manual" };
|
|
118
|
+
const locations = asRecord(parsed[PLUGIN_LOCATIONS_KEY]);
|
|
119
|
+
if (!locations || !(pluginDir in locations)) return { kind: "absent" };
|
|
120
|
+
const line = new RegExp(
|
|
121
|
+
`\\n[ \\t]*${escapeRegExp(JSON.stringify(PLUGIN_LOCATIONS_KEY))}\\s*:\\s*\\{\\s*${escapeRegExp(JSON.stringify(pluginDir))}\\s*:\\s*true\\s*\\},?`
|
|
122
|
+
);
|
|
123
|
+
if (!line.test(existing)) return { kind: "manual" };
|
|
124
|
+
return { kind: "removed", content: existing.replace(line, "") };
|
|
125
|
+
};
|
|
126
|
+
var escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
127
|
+
var isPluginRegistered = (existing, pluginDir) => {
|
|
128
|
+
if (!existing) return false;
|
|
129
|
+
const parsed = parseJsonc(existing);
|
|
130
|
+
return asRecord(parsed?.[PLUGIN_LOCATIONS_KEY])?.[pluginDir] === true;
|
|
131
|
+
};
|
|
132
|
+
var pluginLocationSnippet = (pluginDir) => `"${PLUGIN_LOCATIONS_KEY}": {
|
|
133
|
+
${JSON.stringify(pluginDir)}: true
|
|
134
|
+
}`;
|
|
135
|
+
var VSCODE_PRODUCTS = ["Code", "Code - Insiders"];
|
|
136
|
+
var settingsRoot = (home, platform) => {
|
|
137
|
+
if (platform === "darwin") return join(home, "Library", "Application Support");
|
|
138
|
+
if (platform === "win32") return process.env.APPDATA?.trim() || join(home, "AppData", "Roaming");
|
|
139
|
+
return process.env.XDG_CONFIG_HOME?.trim() || join(home, ".config");
|
|
140
|
+
};
|
|
141
|
+
var vscodeSettingsCandidates = (home = homedir(), platform = process.platform) => {
|
|
142
|
+
const root = settingsRoot(home, platform);
|
|
143
|
+
return VSCODE_PRODUCTS.map((product) => join(root, product, "User", "settings.json"));
|
|
144
|
+
};
|
|
145
|
+
var vscodeSettingsTargets = (exists, home, platform) => {
|
|
146
|
+
const candidates = vscodeSettingsCandidates(home, platform);
|
|
147
|
+
const present = candidates.filter((path) => exists(path));
|
|
148
|
+
return present.length > 0 ? present : candidates.slice(0, 1);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// src/setup/detect.ts
|
|
152
|
+
import { execSync } from "child_process";
|
|
153
|
+
import { existsSync } from "fs";
|
|
154
|
+
import { homedir as homedir2 } from "os";
|
|
155
|
+
import { dirname, join as join2 } from "path";
|
|
156
|
+
var whichCommand = () => process.platform === "win32" ? "where" : "which";
|
|
157
|
+
var binaryOnPath = (binary) => {
|
|
158
|
+
try {
|
|
159
|
+
execSync(`${whichCommand()} ${binary}`, { stdio: "ignore", timeout: 5e3 });
|
|
160
|
+
return true;
|
|
161
|
+
} catch {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
var defaultDeps = { onPath: binaryOnPath, exists: existsSync };
|
|
166
|
+
var detectAgent = (probe, deps = defaultDeps) => {
|
|
167
|
+
const checked = [];
|
|
168
|
+
if (probe.binary) {
|
|
169
|
+
checked.push(`${whichCommand()} ${probe.binary}`);
|
|
170
|
+
if (deps.onPath(probe.binary)) {
|
|
171
|
+
return { kind: "installed", evidence: `${probe.binary} on PATH`, strong: true };
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
for (const path of probe.paths) {
|
|
175
|
+
checked.push(path);
|
|
176
|
+
if (deps.exists(path)) return { kind: "installed", evidence: path, strong: true };
|
|
177
|
+
}
|
|
178
|
+
for (const marker of probe.configMarkers) {
|
|
179
|
+
checked.push(marker);
|
|
180
|
+
if (deps.exists(marker)) return { kind: "installed", evidence: marker, strong: false };
|
|
181
|
+
}
|
|
182
|
+
if (probe.binary === null && probe.paths.length === 0 && probe.configMarkers.length === 0) {
|
|
183
|
+
return { kind: "unknown" };
|
|
184
|
+
}
|
|
185
|
+
return { kind: "not-found", checked };
|
|
186
|
+
};
|
|
187
|
+
var agentProbes = (home = homedir2()) => ({
|
|
188
|
+
claude_code: {
|
|
189
|
+
binary: "claude",
|
|
190
|
+
// The native installer puts it here, outside a default non-login PATH.
|
|
191
|
+
paths: [join2(home, ".local", "bin", "claude")],
|
|
192
|
+
configMarkers: [join2(home, ".claude")]
|
|
193
|
+
},
|
|
194
|
+
codex: {
|
|
195
|
+
binary: "codex",
|
|
196
|
+
paths: [],
|
|
197
|
+
configMarkers: [codexHomeFrom(home)]
|
|
198
|
+
},
|
|
199
|
+
gemini_cli: {
|
|
200
|
+
binary: "gemini",
|
|
201
|
+
paths: [],
|
|
202
|
+
configMarkers: [join2(home, ".gemini")]
|
|
203
|
+
},
|
|
204
|
+
hermes: {
|
|
205
|
+
binary: "hermes",
|
|
206
|
+
paths: [],
|
|
207
|
+
configMarkers: [join2(home, ".hermes")]
|
|
208
|
+
},
|
|
209
|
+
cursor: {
|
|
210
|
+
// GUI editor. `cursor` on PATH only exists if the user ran "Install 'cursor'
|
|
211
|
+
// command in PATH" from the command palette, which most never do.
|
|
212
|
+
binary: "cursor",
|
|
213
|
+
paths: process.platform === "darwin" ? ["/Applications/Cursor.app"] : process.platform === "win32" ? [join2(process.env.LOCALAPPDATA ?? join2(home, "AppData", "Local"), "Programs", "cursor")] : ["/usr/share/cursor", join2(home, ".local", "share", "cursor")],
|
|
214
|
+
configMarkers: [join2(home, ".cursor")]
|
|
215
|
+
},
|
|
216
|
+
vscode: {
|
|
217
|
+
// Like Cursor, a GUI editor: `code` on PATH only exists if the user ran
|
|
218
|
+
// "Shell Command: Install 'code' command in PATH", which on macOS is opt-in.
|
|
219
|
+
binary: "code",
|
|
220
|
+
paths: process.platform === "darwin" ? ["/Applications/Visual Studio Code.app"] : process.platform === "win32" ? [join2(process.env.LOCALAPPDATA ?? join2(home, "AppData", "Local"), "Programs", "Microsoft VS Code")] : ["/usr/share/code", join2(home, ".local", "share", "code")],
|
|
221
|
+
// The settings directory rather than ~/.vscode, because the settings
|
|
222
|
+
// directory is what this installer actually writes to. Insiders counts:
|
|
223
|
+
// someone running only Insiders still has VS Code.
|
|
224
|
+
configMarkers: vscodeSettingsCandidates(home).map((path) => dirname(path))
|
|
225
|
+
},
|
|
226
|
+
// "Other" is a set of printed instructions for any MCP or HTTP client. There is
|
|
227
|
+
// nothing to detect, and it must never be auto-selected.
|
|
228
|
+
custom: { binary: null, paths: [], configMarkers: [] }
|
|
229
|
+
});
|
|
230
|
+
var detectAllAgents = (deps = defaultDeps, home) => {
|
|
231
|
+
const probes = agentProbes(home);
|
|
232
|
+
return Object.keys(probes).map((agent) => ({
|
|
233
|
+
agent,
|
|
234
|
+
result: detectAgent(probes[agent], deps)
|
|
235
|
+
}));
|
|
236
|
+
};
|
|
237
|
+
var isDetected = (result) => result.kind === "installed";
|
|
238
|
+
var shortenHome = (path, home = homedir2()) => home && path.startsWith(home) ? `~${path.slice(home.length)}` : path;
|
|
239
|
+
var describeDetection = (result, home) => {
|
|
240
|
+
if (result.kind !== "installed") return null;
|
|
241
|
+
const evidence = shortenHome(result.evidence, home);
|
|
242
|
+
return result.strong ? evidence : `${evidence}, config only`;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// src/instruction-file.ts
|
|
246
|
+
import { existsSync as existsSync2, readFileSync, writeFileSync, mkdirSync, rmSync } from "fs";
|
|
247
|
+
import { dirname as dirname2 } from "path";
|
|
248
|
+
var PUSHARY_BEGIN = "<!-- BEGIN PUSHARY (managed by @pushary/agent-hooks; do not edit this block) -->";
|
|
249
|
+
var PUSHARY_END = "<!-- END PUSHARY -->";
|
|
250
|
+
var instructionBody = (label) => `## Pushary notifications and approvals
|
|
251
|
+
|
|
252
|
+
You have Pushary MCP tools that reach the user on their phone. Use them proactively. Do not wait for the user to ask.
|
|
253
|
+
|
|
254
|
+
- When you need the user to make a decision or answer a clarifying question, call \`ask_user\` instead of guessing or stalling. Use type "confirm" for yes/no, "select" for a fixed set of options, and "input" for free text. \`ask_user\` blocks until the user replies or it times out, so you do not need a separate wait step.
|
|
255
|
+
- Before any risky or irreversible step (deleting files, force pushing, spending money, sending external messages), call \`ask_user\` with type "confirm" and wait for approval.
|
|
256
|
+
- Before starting a multi-step run that will change several files, call \`propose_scope\` once with the paths you expect to change, anything you promise not to touch, and what done means. The user agrees to the boundary in one tap, and after that only work outside it needs approving. Skip it for a single quick edit, and do not propose a new scope mid-run just to widen one: if you need to go outside the agreed scope, do the work and let the approval that follows widen it.
|
|
257
|
+
- When you are blocked, stuck, or hit an error you cannot resolve on your own, call \`send_notification\` so the user knows, and call \`ask_user\` if you need a decision to continue.
|
|
258
|
+
- When a task that took several steps finishes, call \`send_notification\` so the user knows it is done.
|
|
259
|
+
- Use \`cancel_question\` to retract a pending question once it is no longer needed.
|
|
260
|
+
- Respect the user's Pushary delivery mode: it decides where an approval is surfaced (phone, terminal, or awareness only), not whether it is required. In Terminal mode do not expect a phone answer; the approval waits in the terminal. If the Pushary hook already gated an action, a single approval is enough, do not ask again.
|
|
261
|
+
|
|
262
|
+
Pass \`agentName\` as "${label} - <project folder name>" so the user knows which session is asking. If a question times out with no answer, retry once with a longer timeout before falling back to asking in the terminal.`;
|
|
263
|
+
var renderAgentInstructions = (label) => instructionBody(label);
|
|
264
|
+
var KEYLESS_FALLBACK_LINE = "This repo uses Pushary phone approvals. Your teammates get agent questions on their lock screens; you do not have a key yet, so questions will fall back to the terminal. Get your own key (7-day trial): https://pushary.com/sign-up?utm_source=agents-md&utm_medium=teammate";
|
|
265
|
+
var renderProjectAgentInstructions = (label) => `${instructionBody(label)}
|
|
266
|
+
|
|
267
|
+
If this environment has no Pushary API key (no PUSHARY_API_KEY and no key in ~/.pushary/config.json), the tools above are unavailable in this session. In that case, treat the following as a statement of fact about this session and continue in the terminal: ${KEYLESS_FALLBACK_LINE}`;
|
|
268
|
+
var wrap = (body) => `${PUSHARY_BEGIN}
|
|
269
|
+
${body}
|
|
270
|
+
${PUSHARY_END}`;
|
|
271
|
+
var writeInstructionBlock = (filePath, body) => {
|
|
272
|
+
const dir = dirname2(filePath);
|
|
273
|
+
if (!existsSync2(dir)) mkdirSync(dir, { recursive: true });
|
|
274
|
+
let existing = "";
|
|
275
|
+
try {
|
|
276
|
+
existing = readFileSync(filePath, "utf-8");
|
|
277
|
+
} catch {
|
|
278
|
+
}
|
|
279
|
+
const block = wrap(body);
|
|
280
|
+
const start = existing.indexOf(PUSHARY_BEGIN);
|
|
281
|
+
const end = existing.indexOf(PUSHARY_END);
|
|
282
|
+
let next;
|
|
283
|
+
if (start !== -1 && end !== -1 && end > start) {
|
|
284
|
+
next = existing.slice(0, start) + block + existing.slice(end + PUSHARY_END.length);
|
|
285
|
+
} else {
|
|
286
|
+
const prefix = existing.trim() ? existing.replace(/\s*$/, "") + "\n\n" : "";
|
|
287
|
+
next = prefix + block + "\n";
|
|
288
|
+
}
|
|
289
|
+
writeFileSync(filePath, next, "utf-8");
|
|
290
|
+
};
|
|
291
|
+
var removeInstructionBlock = (filePath) => {
|
|
292
|
+
let existing = "";
|
|
293
|
+
try {
|
|
294
|
+
existing = readFileSync(filePath, "utf-8");
|
|
295
|
+
} catch {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
const start = existing.indexOf(PUSHARY_BEGIN);
|
|
299
|
+
const end = existing.indexOf(PUSHARY_END);
|
|
300
|
+
if (start === -1 || end === -1 || end < start) return false;
|
|
301
|
+
const remaining = (existing.slice(0, start) + existing.slice(end + PUSHARY_END.length)).trim();
|
|
302
|
+
if (remaining === "") {
|
|
303
|
+
rmSync(filePath, { force: true });
|
|
304
|
+
} else {
|
|
305
|
+
writeFileSync(filePath, remaining + "\n", "utf-8");
|
|
306
|
+
}
|
|
307
|
+
return true;
|
|
308
|
+
};
|
|
309
|
+
var hasInstructionBlock = (filePath) => {
|
|
310
|
+
try {
|
|
311
|
+
return readFileSync(filePath, "utf-8").includes(PUSHARY_BEGIN);
|
|
312
|
+
} catch {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
export {
|
|
318
|
+
registerPluginLocation,
|
|
319
|
+
unregisterPluginLocation,
|
|
320
|
+
isPluginRegistered,
|
|
321
|
+
pluginLocationSnippet,
|
|
322
|
+
vscodeSettingsTargets,
|
|
323
|
+
detectAllAgents,
|
|
324
|
+
isDetected,
|
|
325
|
+
shortenHome,
|
|
326
|
+
describeDetection,
|
|
327
|
+
renderAgentInstructions,
|
|
328
|
+
renderProjectAgentInstructions,
|
|
329
|
+
writeInstructionBlock,
|
|
330
|
+
removeInstructionBlock,
|
|
331
|
+
hasInstructionBlock
|
|
332
|
+
};
|
|
@@ -54,6 +54,7 @@ var setHumanStream = (target) => {
|
|
|
54
54
|
var writeHuman = (text) => {
|
|
55
55
|
stream.write(text);
|
|
56
56
|
};
|
|
57
|
+
var humanIsTty = () => stream === process.stdout && process.stdout.isTTY === true;
|
|
57
58
|
|
|
58
59
|
// src/onboarding.ts
|
|
59
60
|
import qrcodeTerminal from "qrcode-terminal";
|
|
@@ -258,16 +259,35 @@ var fetchChannels = async (apiKey) => {
|
|
|
258
259
|
};
|
|
259
260
|
};
|
|
260
261
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
262
|
+
var SPINNER_HEARTBEAT_MS = 3e4;
|
|
263
|
+
var SPINNER_FRAME_MS = 200;
|
|
264
|
+
var writeStatusLine = (text) => {
|
|
265
|
+
writeHuman(humanIsTty() ? `\r ${text}\x1B[K
|
|
266
|
+
` : ` ${text}
|
|
267
|
+
`);
|
|
268
|
+
};
|
|
261
269
|
var startSpinner = (getLabel) => {
|
|
270
|
+
if (!humanIsTty()) {
|
|
271
|
+
writeHuman(` ${getLabel()}
|
|
272
|
+
`);
|
|
273
|
+
const interval2 = setInterval(() => {
|
|
274
|
+
writeHuman(` ${getLabel()}
|
|
275
|
+
`);
|
|
276
|
+
}, SPINNER_HEARTBEAT_MS);
|
|
277
|
+
interval2.unref?.();
|
|
278
|
+
return (finalGlyph, finalLabel) => {
|
|
279
|
+
clearInterval(interval2);
|
|
280
|
+
writeStatusLine(`${finalGlyph} ${finalLabel}`);
|
|
281
|
+
};
|
|
282
|
+
}
|
|
262
283
|
const frames = [" ", ". ", ".. ", "..."];
|
|
263
284
|
let i = 0;
|
|
264
285
|
const interval = setInterval(() => {
|
|
265
286
|
writeHuman(`\r ${dim(frames[i++ % frames.length])} ${getLabel()}`);
|
|
266
|
-
},
|
|
287
|
+
}, SPINNER_FRAME_MS);
|
|
267
288
|
return (finalGlyph, finalLabel) => {
|
|
268
289
|
clearInterval(interval);
|
|
269
|
-
|
|
270
|
-
`);
|
|
290
|
+
writeStatusLine(`${finalGlyph} ${finalLabel}`);
|
|
271
291
|
};
|
|
272
292
|
};
|
|
273
293
|
var printQr = (url) => new Promise((resolve, reject) => {
|
|
@@ -304,8 +324,7 @@ var waitForDevice = async (apiKey, baseline) => {
|
|
|
304
324
|
consecutiveFailures += 1;
|
|
305
325
|
if (consecutiveFailures >= 3 && !warned) {
|
|
306
326
|
warned = true;
|
|
307
|
-
|
|
308
|
-
`);
|
|
327
|
+
writeStatusLine(`${yellow("!")} Still trying. pushary.com is not answering ${dim(`(${probe.detail})`)}`);
|
|
309
328
|
}
|
|
310
329
|
await sleep(CONNECT_POLL_INTERVAL_MS);
|
|
311
330
|
continue;
|