@pushary/agent-hooks 1.6.4 → 1.7.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 +19 -0
- package/README.md +3 -2
- package/dist/bin/pushary-bell-hook.js +23 -24
- package/dist/bin/pushary-bell.js +10 -11
- package/dist/bin/pushary-claude.js +27 -28
- package/dist/bin/pushary-clean.js +173 -71
- package/dist/bin/pushary-codex-bridge.js +17 -18
- package/dist/bin/pushary-codex-hook.js +30 -31
- package/dist/bin/pushary-codex.js +12 -13
- package/dist/bin/pushary-connect.js +14 -15
- package/dist/bin/pushary-cowork.js +5 -6
- package/dist/bin/pushary-daemon.js +27 -28
- package/dist/bin/pushary-disconnect.js +17 -18
- package/dist/bin/pushary-doctor.js +104 -41
- package/dist/bin/pushary-elicitation-hook.js +24 -25
- package/dist/bin/pushary-gemini-bridge.js +12 -13
- package/dist/bin/pushary-gemini-hook.js +27 -28
- package/dist/bin/pushary-hook.js +31 -32
- package/dist/bin/pushary-login.js +14 -16
- package/dist/bin/pushary-logout.js +8 -9
- package/dist/bin/pushary-mcp.d.ts +1 -0
- package/dist/bin/pushary-mcp.js +56 -0
- package/dist/bin/pushary-mode.js +10 -11
- package/dist/bin/pushary-notification-hook.js +27 -28
- package/dist/bin/pushary-opencode-hook.js +26 -27
- package/dist/bin/pushary-permission-denied-hook.js +31 -32
- package/dist/bin/pushary-permission-hook.js +30 -31
- package/dist/bin/pushary-post-hook.js +27 -28
- package/dist/bin/pushary-prompt-hook.js +27 -28
- package/dist/bin/pushary-session-end-hook.js +27 -28
- package/dist/bin/pushary-session-start-hook.js +31 -32
- package/dist/bin/pushary-setup.js +235 -100
- package/dist/bin/pushary-stats.js +5 -6
- package/dist/bin/pushary-status.js +16 -17
- package/dist/bin/pushary-stop-hook.js +27 -28
- package/dist/bin/pushary-stopfailure-hook.js +27 -28
- package/dist/bin/pushary-suggestions.js +5 -5
- package/dist/bin/pushary-transcript-register.js +19 -20
- package/dist/bin/pushary-transcripts.js +7 -8
- package/dist/bin/pushary-upgrade.js +20 -21
- package/dist/bin/pushary-wait.js +10 -11
- package/dist/bin/pushary.js +6 -7
- package/dist/chunk-2FU43B5Q.js +120 -0
- package/dist/{chunk-6NLWK6ZV.js → chunk-3QE3BHBW.js} +2 -2
- package/dist/{chunk-NYMPLNV3.js → chunk-3QORH5EJ.js} +3 -3
- package/dist/{chunk-LFMOYHPY.js → chunk-3T35OE7C.js} +2 -2
- package/dist/{chunk-5U3FJ6YF.js → chunk-42XR73I2.js} +8 -8
- package/dist/{chunk-UGKDBJJX.js → chunk-43SSQCWO.js} +3 -3
- package/dist/{chunk-K32C2RGK.js → chunk-454KMJHF.js} +17 -9
- package/dist/{chunk-YUGGNZSF.js → chunk-4C4NRDIC.js} +1 -1
- package/dist/{chunk-HUB4Q35G.js → chunk-55RO62FV.js} +1 -1
- package/dist/{chunk-YQMFGWBD.js → chunk-62TEPRWQ.js} +1 -1
- package/dist/{chunk-P4BNYJ5Q.js → chunk-6PV2JQ64.js} +2 -2
- package/dist/{chunk-53DN77WB.js → chunk-6SJQ442W.js} +2 -2
- package/dist/{chunk-UAP556WK.js → chunk-7GI6QC3M.js} +2 -2
- package/dist/{chunk-D3K2FPPJ.js → chunk-7GYGVQBU.js} +8 -8
- package/dist/{chunk-OZE2TQX5.js → chunk-AAGLDXH4.js} +5 -5
- package/dist/{chunk-XJG2FUWS.js → chunk-AHWJHLG5.js} +9 -30
- package/dist/{chunk-P4UYILQK.js → chunk-BYVB3RX3.js} +2 -2
- package/dist/{chunk-EA3IELHP.js → chunk-EIZW73P5.js} +6 -2
- package/dist/{chunk-BY2CRWBO.js → chunk-H6JV44TE.js} +1 -1
- package/dist/{chunk-3LU74H52.js → chunk-IGBDOZUO.js} +1 -1
- package/dist/{chunk-N62KAMMY.js → chunk-JMBG47WV.js} +30 -1
- package/dist/{chunk-DESAUCH2.js → chunk-JTQDP4ZL.js} +4 -6
- package/dist/{chunk-LJEL7IB5.js → chunk-KBLIVEFJ.js} +5 -5
- package/dist/{chunk-VOCZHOXV.js → chunk-KSNAAMU5.js} +4 -4
- package/dist/{chunk-5UWV5GHM.js → chunk-MCNS4725.js} +1 -1
- package/dist/{chunk-I3XJATMR.js → chunk-MWVCDP64.js} +1 -1
- package/dist/chunk-NAAZCNKI.js +757 -0
- package/dist/{chunk-3VZX4NSP.js → chunk-NID4UZDN.js} +1 -1
- package/dist/{chunk-BJENQBMH.js → chunk-NQFGVAT6.js} +8 -4
- package/dist/{chunk-XOMH53NB.js → chunk-O5JD7UI5.js} +1 -1
- package/dist/{chunk-5RUIFDTP.js → chunk-O5PRIYFZ.js} +30 -2
- package/dist/{chunk-OSJEMXSR.js → chunk-OAL44FM2.js} +1 -1
- package/dist/{chunk-66H2QQAK.js → chunk-OTZHT34O.js} +1 -1
- package/dist/{chunk-DZTKLE7Q.js → chunk-P5CBNSYL.js} +1 -1
- package/dist/{chunk-GBL4BTG3.js → chunk-Q7QRR6YL.js} +2 -2
- package/dist/{chunk-YPONELWS.js → chunk-QPR33SHS.js} +6 -6
- package/dist/{chunk-LDRGVXLR.js → chunk-SNWNA3MQ.js} +1 -1
- package/dist/{chunk-5SWQZ6HY.js → chunk-SVEMF2VO.js} +4 -4
- package/dist/{chunk-VHNDE3ZD.js → chunk-UPKP67TA.js} +2 -2
- package/dist/{chunk-PJF7L7AA.js → chunk-VCMFKZON.js} +2 -2
- package/dist/{chunk-H6XU22TN.js → chunk-WM3U2RUK.js} +8 -8
- package/dist/{chunk-ZA5UXRNE.js → chunk-WSC53O7I.js} +3 -3
- package/dist/{chunk-7CLTSZOL.js → chunk-WZWXBTRF.js} +3 -3
- package/dist/{chunk-YXPGFRRW.js → chunk-XDASEYRS.js} +3 -3
- package/dist/{chunk-CAS7GFWI.js → chunk-XFNVG3OV.js} +75 -5
- package/dist/{chunk-I2YUMZLE.js → chunk-XMN37YJH.js} +1 -1
- package/dist/{chunk-LQI7W4RG.js → chunk-XPMOCJHN.js} +1 -1
- package/dist/{chunk-VA2R64I7.js → chunk-XPTCPU6V.js} +1 -1
- package/dist/{chunk-PBKEYMAO.js → chunk-Y6GKOZBT.js} +1 -1
- package/dist/{chunk-JOGA3TL2.js → chunk-YQN7S57T.js} +6 -6
- package/dist/{chunk-R4HVHTNA.js → chunk-YZKS3ME3.js} +2 -2
- package/dist/chunk-ZEMSCGDD.js +87 -0
- package/dist/{chunk-EREBZHN2.js → chunk-ZIIYTQHC.js} +4 -4
- package/dist/{reapply-4DAJKNVP.js → reapply-66GQIBXN.js} +9 -10
- package/dist/src/index.js +19 -20
- package/package.json +2 -1
- package/dist/chunk-GU3EJCVV.js +0 -43
- package/dist/chunk-HWJW3CPO.js +0 -65
- package/dist/chunk-NFH73H5B.js +0 -360
- package/dist/chunk-P32LPT2L.js +0 -6
|
@@ -0,0 +1,757 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MCP_BRIDGE_BINARY
|
|
3
|
+
} from "./chunk-2FU43B5Q.js";
|
|
4
|
+
import {
|
|
5
|
+
openCodeConfigDirFrom
|
|
6
|
+
} from "./chunk-NID4UZDN.js";
|
|
7
|
+
import {
|
|
8
|
+
codexHomeFrom
|
|
9
|
+
} from "./chunk-454KMJHF.js";
|
|
10
|
+
import {
|
|
11
|
+
HOOK_COMPATIBLE_PROFILES
|
|
12
|
+
} from "./chunk-XFNVG3OV.js";
|
|
13
|
+
|
|
14
|
+
// src/fx-config.ts
|
|
15
|
+
var FX_SERVER_NAME = "pushary";
|
|
16
|
+
var FX_OPERATION_TIMEOUT_MS = 75e3;
|
|
17
|
+
var FX_PROFILE_MAX_BYTES = 1024 * 1024 - 1;
|
|
18
|
+
var FX_SETTINGS_MAX_BYTES = 64 * 1024;
|
|
19
|
+
var FX_PUSHARY_TOOLS_RULE = "mcp_pushary_*";
|
|
20
|
+
var FX_TOOL_DISCOVERY_NOTE = 'In fx, these tools are named mcp_pushary_ask_user, mcp_pushary_send_notification, mcp_pushary_wait_for_answer, mcp_pushary_cancel_question and mcp_pushary_propose_scope. fx does not load them at the start of a turn: call mcp_select_tool with the exact name, for example {"name": "mcp_pushary_ask_user"}, then call the tool. For fx this replaces the guidance above to ask the whole round in the terminal while the user is there: ask every question through mcp_pushary_ask_user, even while the user is at this terminal, rather than through ask_user_question. fx cannot show its own question prompt in the Mac notch or on the phone, so a question asked there waits unseen once the user steps away. Ask in your reply instead only when a Pushary handoffAction tells you to ask here, or when mcp_pushary_ask_user is unavailable or fails without one.';
|
|
21
|
+
var ALLOW_ACTION = "allow";
|
|
22
|
+
var PERMISSION_KEY = "permission";
|
|
23
|
+
var WORKSPACES_KEY = "workspaces";
|
|
24
|
+
var CANONICAL_SERVERS_KEY = "mcp";
|
|
25
|
+
var ALIAS_SERVERS_KEY = "mcpServers";
|
|
26
|
+
var LOCAL_TRANSPORT = "local";
|
|
27
|
+
var SERVER_TRANSPORTS = /* @__PURE__ */ new Set(["local", "stdio", "http", "sse"]);
|
|
28
|
+
var STDIO_TRANSPORTS = /* @__PURE__ */ new Set(["local", "stdio"]);
|
|
29
|
+
var AMBIGUOUS_SERVER_KEYS = /* @__PURE__ */ new Set([
|
|
30
|
+
"mcpserver",
|
|
31
|
+
"mcpservers",
|
|
32
|
+
"modelcontextprotocol",
|
|
33
|
+
"modelcontextprotocolserver",
|
|
34
|
+
"modelcontextprotocolservers",
|
|
35
|
+
"servers"
|
|
36
|
+
]);
|
|
37
|
+
var PROFILE_SCAN_LIMIT = 64;
|
|
38
|
+
var PROFILE_KEY_BYTES_LIMIT = 128;
|
|
39
|
+
var FX_JSON_REFUSALS = {
|
|
40
|
+
"too-large": "is larger than fx reads",
|
|
41
|
+
"unparseable": "is not strict JSON (fx rejects comments, trailing commas and a byte-order mark)",
|
|
42
|
+
"duplicate-key": "repeats a key, which fx rejects",
|
|
43
|
+
"root-not-object": "is not a JSON object"
|
|
44
|
+
};
|
|
45
|
+
var FX_PROFILE_REFUSALS = {
|
|
46
|
+
...FX_JSON_REFUSALS,
|
|
47
|
+
"servers-not-object": 'has an "mcp" or "mcpServers" value that is not an object',
|
|
48
|
+
"ambiguous-server-key": "holds servers under a key fx does not read, so fx refuses to edit it too",
|
|
49
|
+
"too-many-keys": "has more top-level keys than fx checks for misplaced servers, so fx refuses to edit it too"
|
|
50
|
+
};
|
|
51
|
+
var FX_SETTINGS_REFUSALS = {
|
|
52
|
+
...FX_JSON_REFUSALS,
|
|
53
|
+
"permission-not-object": 'has a "permission" value that is not an object',
|
|
54
|
+
"invalid-permission-rule": "has a permission rule fx rejects, so fx ignores the whole file",
|
|
55
|
+
"invalid-permission-mode": "has a permission_mode fx does not recognise, so fx ignores the whole file"
|
|
56
|
+
};
|
|
57
|
+
var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
58
|
+
var stringTokenEnd = (text, start) => {
|
|
59
|
+
let index = start + 1;
|
|
60
|
+
while (index < text.length && text[index] !== '"') index += text[index] === "\\" ? 2 : 1;
|
|
61
|
+
return index;
|
|
62
|
+
};
|
|
63
|
+
var hasDuplicateObjectKeys = (json) => {
|
|
64
|
+
const scopes = [];
|
|
65
|
+
let expectingKey = false;
|
|
66
|
+
for (let index = 0; index < json.length; index += 1) {
|
|
67
|
+
const char = json[index];
|
|
68
|
+
if (char === '"') {
|
|
69
|
+
const end = stringTokenEnd(json, index);
|
|
70
|
+
const scope = scopes.at(-1);
|
|
71
|
+
if (expectingKey && scope) {
|
|
72
|
+
const key = JSON.parse(json.slice(index, end + 1));
|
|
73
|
+
if (typeof key === "string" && scope.has(key)) return true;
|
|
74
|
+
if (typeof key === "string") scope.add(key);
|
|
75
|
+
expectingKey = false;
|
|
76
|
+
}
|
|
77
|
+
index = end;
|
|
78
|
+
} else if (char === "{") {
|
|
79
|
+
scopes.push(/* @__PURE__ */ new Set());
|
|
80
|
+
expectingKey = true;
|
|
81
|
+
} else if (char === "[") {
|
|
82
|
+
scopes.push(null);
|
|
83
|
+
expectingKey = false;
|
|
84
|
+
} else if (char === "}" || char === "]") {
|
|
85
|
+
scopes.pop();
|
|
86
|
+
expectingKey = false;
|
|
87
|
+
} else if (char === ",") {
|
|
88
|
+
expectingKey = scopes.at(-1) instanceof Set;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
};
|
|
93
|
+
var normalizedServerKey = (key) => key.replace(/[^A-Za-z0-9]/g, "").toLowerCase();
|
|
94
|
+
var looksLikeServerEntry = (value) => {
|
|
95
|
+
const entry = asRecord(value);
|
|
96
|
+
if (!entry) return false;
|
|
97
|
+
return typeof entry.command === "string" || Array.isArray(entry.command) || typeof entry.url === "string" || typeof entry.type === "string" && SERVER_TRANSPORTS.has(entry.type);
|
|
98
|
+
};
|
|
99
|
+
var holdsServerEntries = (value) => Object.values(asRecord(value) ?? {}).some(looksLikeServerEntry);
|
|
100
|
+
var isServerMapKey = (key) => key === CANONICAL_SERVERS_KEY || key === ALIAS_SERVERS_KEY;
|
|
101
|
+
var exceedsScanLimit = (value) => Object.keys(asRecord(value) ?? {}).length > PROFILE_SCAN_LIMIT;
|
|
102
|
+
var isAmbiguousServerKey = (key, value) => {
|
|
103
|
+
if (isServerMapKey(key)) return false;
|
|
104
|
+
const scanned = Buffer.byteLength(key) > PROFILE_KEY_BYTES_LIMIT || AMBIGUOUS_SERVER_KEYS.has(normalizedServerKey(key));
|
|
105
|
+
return scanned && (exceedsScanLimit(value) || holdsServerEntries(value));
|
|
106
|
+
};
|
|
107
|
+
var misplacedServersRefusal = (profile) => {
|
|
108
|
+
if (exceedsScanLimit(profile)) return "too-many-keys";
|
|
109
|
+
return Object.keys(profile).some((key) => isAmbiguousServerKey(key, profile[key])) ? "ambiguous-server-key" : null;
|
|
110
|
+
};
|
|
111
|
+
var fxServersKeyOf = (profile) => !(CANONICAL_SERVERS_KEY in profile) && ALIAS_SERVERS_KEY in profile ? ALIAS_SERVERS_KEY : CANONICAL_SERVERS_KEY;
|
|
112
|
+
var refused = (reason) => ({ kind: "refused", reason });
|
|
113
|
+
var parseJson = (text) => {
|
|
114
|
+
try {
|
|
115
|
+
return { ok: true, value: JSON.parse(text) };
|
|
116
|
+
} catch {
|
|
117
|
+
return { ok: false };
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
var readFxJsonObject = (text, maxBytes) => {
|
|
121
|
+
if (Buffer.byteLength(text) > maxBytes) return { kind: "refused", reason: "too-large" };
|
|
122
|
+
if (!text.trim()) return { kind: "object", value: {} };
|
|
123
|
+
const parsed = parseJson(text);
|
|
124
|
+
if (!parsed.ok) return { kind: "refused", reason: "unparseable" };
|
|
125
|
+
if (hasDuplicateObjectKeys(text)) return { kind: "refused", reason: "duplicate-key" };
|
|
126
|
+
const value = asRecord(parsed.value);
|
|
127
|
+
return value ? { kind: "object", value } : { kind: "refused", reason: "root-not-object" };
|
|
128
|
+
};
|
|
129
|
+
var readFxProfile = (text) => {
|
|
130
|
+
const read = readFxJsonObject(text, FX_PROFILE_MAX_BYTES);
|
|
131
|
+
if (read.kind === "refused") return refused(read.reason);
|
|
132
|
+
const profile = read.value;
|
|
133
|
+
const serversKey = fxServersKeyOf(profile);
|
|
134
|
+
if (serversKey in profile && !asRecord(profile[serversKey])) return refused("servers-not-object");
|
|
135
|
+
const misplaced = misplacedServersRefusal(profile);
|
|
136
|
+
return misplaced ? refused(misplaced) : { kind: "profile", profile };
|
|
137
|
+
};
|
|
138
|
+
var fxPusharyEntry = (command) => ({
|
|
139
|
+
type: LOCAL_TRANSPORT,
|
|
140
|
+
command,
|
|
141
|
+
operation_timeout_ms: FX_OPERATION_TIMEOUT_MS
|
|
142
|
+
});
|
|
143
|
+
var withFxPusharyServer = (profile, entry) => {
|
|
144
|
+
const serversKey = fxServersKeyOf(profile);
|
|
145
|
+
return {
|
|
146
|
+
...profile,
|
|
147
|
+
[serversKey]: { ...asRecord(profile[serversKey]), [FX_SERVER_NAME]: { ...entry, command: [...entry.command] } }
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
var emptiedMapCanGo = (profile, serversKey) => serversKey === ALIAS_SERVERS_KEY || !(ALIAS_SERVERS_KEY in profile);
|
|
151
|
+
var withoutFxPusharyServer = (profile) => {
|
|
152
|
+
const serversKey = fxServersKeyOf(profile);
|
|
153
|
+
const servers = asRecord(profile[serversKey]);
|
|
154
|
+
if (!servers || !(FX_SERVER_NAME in servers)) return { profile, removed: false };
|
|
155
|
+
const remaining = Object.fromEntries(Object.entries(servers).filter(([name]) => name !== FX_SERVER_NAME));
|
|
156
|
+
const withoutServers = Object.fromEntries(Object.entries(profile).filter(([key]) => key !== serversKey));
|
|
157
|
+
const dropsMap = Object.keys(remaining).length === 0 && emptiedMapCanGo(profile, serversKey);
|
|
158
|
+
return {
|
|
159
|
+
profile: dropsMap ? withoutServers : { ...profile, [serversKey]: remaining },
|
|
160
|
+
removed: true
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
var namesBridge = (part) => typeof part === "string" && part.includes(MCP_BRIDGE_BINARY);
|
|
164
|
+
var commandNamesBridge = (command) => Array.isArray(command) ? command.some(namesBridge) : namesBridge(command);
|
|
165
|
+
var isFxPusharyEntry = (value) => {
|
|
166
|
+
const entry = asRecord(value);
|
|
167
|
+
if (!entry || entry.enabled === false) return false;
|
|
168
|
+
const transport = typeof entry.type === "string" ? entry.type : LOCAL_TRANSPORT;
|
|
169
|
+
return STDIO_TRANSPORTS.has(transport) && (commandNamesBridge(entry.command) || commandNamesBridge(entry.args));
|
|
170
|
+
};
|
|
171
|
+
var fxPusharyEntryOf = (profile) => asRecord(profile[fxServersKeyOf(profile)])?.[FX_SERVER_NAME];
|
|
172
|
+
var isBridgeTarget = (part) => namesBridge(part);
|
|
173
|
+
var fxBridgeTargetOf = (value) => {
|
|
174
|
+
const entry = asRecord(value);
|
|
175
|
+
const parts = [entry?.command, entry?.args].flatMap((part) => Array.isArray(part) ? part : [part]);
|
|
176
|
+
return parts.find(isBridgeTarget);
|
|
177
|
+
};
|
|
178
|
+
var fxFileText = (value, maxBytes) => {
|
|
179
|
+
const text = JSON.stringify(value);
|
|
180
|
+
return Buffer.byteLength(text) > maxBytes ? { kind: "refused", reason: "too-large" } : { kind: "text", text };
|
|
181
|
+
};
|
|
182
|
+
var fxProfileText = (profile) => fxFileText(profile, FX_PROFILE_MAX_BYTES);
|
|
183
|
+
var fxSettingsText = (settings) => fxFileText(settings, FX_SETTINGS_MAX_BYTES);
|
|
184
|
+
var readFxSettings = (text) => {
|
|
185
|
+
const read = readFxJsonObject(text, FX_SETTINGS_MAX_BYTES);
|
|
186
|
+
if (read.kind === "refused") return read;
|
|
187
|
+
const invalid = fxSettingsRejection(read.value);
|
|
188
|
+
if (invalid) return { kind: "refused", reason: invalid };
|
|
189
|
+
const permission = read.value[PERMISSION_KEY];
|
|
190
|
+
if (permission !== void 0 && !asRecord(permission)) return { kind: "refused", reason: "permission-not-object" };
|
|
191
|
+
return { kind: "settings", settings: read.value };
|
|
192
|
+
};
|
|
193
|
+
var withPusharyToolsAllowed = (settings) => {
|
|
194
|
+
const permission = asRecord(settings[PERMISSION_KEY]) ?? {};
|
|
195
|
+
const existing = permission[FX_PUSHARY_TOOLS_RULE];
|
|
196
|
+
if (existing === ALLOW_ACTION) return { settings, change: "present" };
|
|
197
|
+
if (existing !== void 0) return { settings, change: "user-rule-kept" };
|
|
198
|
+
return {
|
|
199
|
+
settings: { ...settings, [PERMISSION_KEY]: { ...permission, [FX_PUSHARY_TOOLS_RULE]: ALLOW_ACTION } },
|
|
200
|
+
change: "added"
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
var withoutPermissionRule = (settings, permission, rule) => {
|
|
204
|
+
const remaining = Object.fromEntries(Object.entries(permission).filter(([name]) => name !== rule));
|
|
205
|
+
const withoutPermission = Object.fromEntries(Object.entries(settings).filter(([key]) => key !== PERMISSION_KEY));
|
|
206
|
+
return Object.keys(remaining).length === 0 ? withoutPermission : { ...settings, [PERMISSION_KEY]: remaining };
|
|
207
|
+
};
|
|
208
|
+
var withoutPusharyToolsAllowed = (settings) => {
|
|
209
|
+
const permission = asRecord(settings[PERMISSION_KEY]);
|
|
210
|
+
if (!permission || permission[FX_PUSHARY_TOOLS_RULE] !== ALLOW_ACTION) return { settings, removed: false };
|
|
211
|
+
return { settings: withoutPermissionRule(settings, permission, FX_PUSHARY_TOOLS_RULE), removed: true };
|
|
212
|
+
};
|
|
213
|
+
var pusharyToolsAllowed = (settings) => asRecord(settings[PERMISSION_KEY])?.[FX_PUSHARY_TOOLS_RULE] === ALLOW_ACTION;
|
|
214
|
+
var overridesPusharyRule = (workspace) => {
|
|
215
|
+
const permission = asRecord(asRecord(workspace)?.[PERMISSION_KEY]);
|
|
216
|
+
return permission !== void 0 && !(FX_PUSHARY_TOOLS_RULE in permission);
|
|
217
|
+
};
|
|
218
|
+
var workspacesOverridingPusharyRule = (settings) => Object.entries(asRecord(settings[WORKSPACES_KEY]) ?? {}).filter(([, workspace]) => overridesPusharyRule(workspace)).map(([path]) => path);
|
|
219
|
+
var FX_QUESTION_TOOL = "ask_user_question";
|
|
220
|
+
var DENY_ACTION = "deny";
|
|
221
|
+
var GLOBAL_TARGET_PATTERN = "*";
|
|
222
|
+
var PERMISSION_MODE_KEY = "permission_mode";
|
|
223
|
+
var FX_PERMISSION_MODE_ENV = "FX_PERMISSION_MODE";
|
|
224
|
+
var FX_DEFAULT_PERMISSION_MODE = "auto";
|
|
225
|
+
var FX_PERMISSION_MODE_SPELLINGS = {
|
|
226
|
+
ask: "ask",
|
|
227
|
+
auto: "auto",
|
|
228
|
+
"full-access": "full-access",
|
|
229
|
+
"full access": "full-access",
|
|
230
|
+
yolo: "full-access"
|
|
231
|
+
};
|
|
232
|
+
var FX_RULE_WHITESPACE = /^[ \t\r\n]+|[ \t\r\n]+$/g;
|
|
233
|
+
var FX_QUESTION_RULE_RECEIPT = { rule: FX_QUESTION_TOOL, action: DENY_ACTION };
|
|
234
|
+
var isFxQuestionRuleReceipt = (value) => {
|
|
235
|
+
const receipt = asRecord(value);
|
|
236
|
+
return receipt?.rule === FX_QUESTION_TOOL && receipt.action === DENY_ACTION;
|
|
237
|
+
};
|
|
238
|
+
var isFxRuleAction = (value) => value === "allow" || value === "ask" || value === DENY_ACTION;
|
|
239
|
+
var fxRuleAction = (value) => {
|
|
240
|
+
if (typeof value !== "string") return null;
|
|
241
|
+
const action = value.toLowerCase();
|
|
242
|
+
return isFxRuleAction(action) ? action : null;
|
|
243
|
+
};
|
|
244
|
+
var parseFxPermissionMode = (value) => typeof value === "string" ? FX_PERMISSION_MODE_SPELLINGS[value.toLowerCase()] ?? null : null;
|
|
245
|
+
var trimFxRuleText = (text) => text.replace(FX_RULE_WHITESPACE, "");
|
|
246
|
+
var isValidPatternMap = (value) => {
|
|
247
|
+
const patterns = asRecord(value);
|
|
248
|
+
return patterns !== void 0 && Object.values(patterns).every((action) => fxRuleAction(action) !== null);
|
|
249
|
+
};
|
|
250
|
+
var isValidPermissionValue = (value) => {
|
|
251
|
+
if (fxRuleAction(value) !== null) return true;
|
|
252
|
+
const permission = asRecord(value);
|
|
253
|
+
return permission !== void 0 && Object.entries(permission).every(([name, rule]) => trimFxRuleText(name).length > 0 && (fxRuleAction(rule) !== null || isValidPatternMap(rule)));
|
|
254
|
+
};
|
|
255
|
+
var permissionScopeRejection = (scope) => {
|
|
256
|
+
if (scope[PERMISSION_KEY] !== void 0 && !isValidPermissionValue(scope[PERMISSION_KEY])) return "invalid-permission-rule";
|
|
257
|
+
if (scope[PERMISSION_MODE_KEY] !== void 0 && parseFxPermissionMode(scope[PERMISSION_MODE_KEY]) === null) return "invalid-permission-mode";
|
|
258
|
+
return null;
|
|
259
|
+
};
|
|
260
|
+
var workspaceScopes = (settings) => Object.values(asRecord(settings[WORKSPACES_KEY]) ?? {}).flatMap((workspace) => {
|
|
261
|
+
const scope = asRecord(workspace);
|
|
262
|
+
return scope ? [scope] : [];
|
|
263
|
+
});
|
|
264
|
+
var fxSettingsRejection = (settings) => [settings, ...workspaceScopes(settings)].map(permissionScopeRejection).find((rejection) => rejection !== null) ?? null;
|
|
265
|
+
var rulesOfPermissionEntry = ([name, value]) => {
|
|
266
|
+
const permission = trimFxRuleText(name);
|
|
267
|
+
const action = fxRuleAction(value);
|
|
268
|
+
if (action) return [{ permission, pattern: GLOBAL_TARGET_PATTERN, action }];
|
|
269
|
+
return Object.entries(asRecord(value) ?? {}).flatMap(([pattern, target]) => {
|
|
270
|
+
const targetAction = fxRuleAction(target);
|
|
271
|
+
return targetAction ? [{ permission, pattern: trimFxRuleText(pattern), action: targetAction }] : [];
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
var fxPermissionRules = (permission) => {
|
|
275
|
+
const everything = fxRuleAction(permission);
|
|
276
|
+
if (everything) return [{ permission: GLOBAL_TARGET_PATTERN, pattern: GLOBAL_TARGET_PATTERN, action: everything }];
|
|
277
|
+
return Object.entries(asRecord(permission) ?? {}).flatMap(rulesOfPermissionEntry);
|
|
278
|
+
};
|
|
279
|
+
var fxWildcardMatch = (pattern, candidate) => {
|
|
280
|
+
let patternIndex = 0;
|
|
281
|
+
let candidateIndex = 0;
|
|
282
|
+
let starIndex = null;
|
|
283
|
+
let starCandidateIndex = 0;
|
|
284
|
+
while (candidateIndex < candidate.length) {
|
|
285
|
+
if (patternIndex < pattern.length && (pattern[patternIndex] === "?" || pattern[patternIndex] === candidate[candidateIndex])) {
|
|
286
|
+
patternIndex += 1;
|
|
287
|
+
candidateIndex += 1;
|
|
288
|
+
} else if (patternIndex < pattern.length && pattern[patternIndex] === "*") {
|
|
289
|
+
starIndex = patternIndex;
|
|
290
|
+
patternIndex += 1;
|
|
291
|
+
starCandidateIndex = candidateIndex;
|
|
292
|
+
} else if (starIndex === null) {
|
|
293
|
+
return false;
|
|
294
|
+
} else {
|
|
295
|
+
starCandidateIndex += 1;
|
|
296
|
+
candidateIndex = starCandidateIndex;
|
|
297
|
+
patternIndex = starIndex + 1;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
while (pattern[patternIndex] === "*") patternIndex += 1;
|
|
301
|
+
return patternIndex === pattern.length;
|
|
302
|
+
};
|
|
303
|
+
var DIRECTORY_TREE_SUFFIX = "/**";
|
|
304
|
+
var directoryTreeMatches = (pattern, candidate) => {
|
|
305
|
+
if (!pattern.endsWith(DIRECTORY_TREE_SUFFIX)) return false;
|
|
306
|
+
const directory = pattern.slice(0, -DIRECTORY_TREE_SUFFIX.length);
|
|
307
|
+
return candidate === directory || candidate.startsWith(directory) && candidate[directory.length] === "/";
|
|
308
|
+
};
|
|
309
|
+
var targetMatches = (pattern, candidate) => directoryTreeMatches(pattern, candidate) || fxWildcardMatch(pattern, candidate);
|
|
310
|
+
var isGlobalTargetPattern = (pattern) => /^\*+$/.test(pattern);
|
|
311
|
+
var decisionForTarget = (rules, target) => rules.filter((rule) => targetMatches(rule.pattern, target)).at(-1)?.action ?? null;
|
|
312
|
+
var reopensTool = (rules, rule) => rule.action !== DENY_ACTION && decisionForTarget(rules, rule.pattern) !== DENY_ACTION && decisionForTarget(rules, rule.pattern) !== null;
|
|
313
|
+
var fxRulesHideTool = (rules, toolName) => {
|
|
314
|
+
const matching = rules.filter((rule) => fxWildcardMatch(rule.permission, toolName));
|
|
315
|
+
const lastGlobalRule = matching.filter((rule) => isGlobalTargetPattern(rule.pattern)).at(-1);
|
|
316
|
+
if (lastGlobalRule?.action !== DENY_ACTION) return false;
|
|
317
|
+
return !matching.slice(matching.lastIndexOf(lastGlobalRule) + 1).some((rule) => reopensTool(matching, rule));
|
|
318
|
+
};
|
|
319
|
+
var effectivePermissionMode = (scope, environment) => parseFxPermissionMode(environment[FX_PERMISSION_MODE_ENV]) ?? parseFxPermissionMode(scope[PERMISSION_MODE_KEY]) ?? FX_DEFAULT_PERMISSION_MODE;
|
|
320
|
+
var fxRunsWithoutRules = (settings, environment) => effectivePermissionMode(settings, environment) === "full-access";
|
|
321
|
+
var fxQuestionToolHidden = (permission) => fxRulesHideTool(fxPermissionRules(permission), FX_QUESTION_TOOL);
|
|
322
|
+
var fxQuestionRouting = (settings, environment) => {
|
|
323
|
+
if (fxRunsWithoutRules(settings, environment)) return "full-access";
|
|
324
|
+
return fxQuestionToolHidden(settings[PERMISSION_KEY]) ? "routed" : "overridden";
|
|
325
|
+
};
|
|
326
|
+
var withQuestionsRoutedToPushary = (settings) => {
|
|
327
|
+
const permission = asRecord(settings[PERMISSION_KEY]) ?? {};
|
|
328
|
+
const existing = permission[FX_QUESTION_TOOL];
|
|
329
|
+
if (existing === void 0) {
|
|
330
|
+
return { settings: { ...settings, [PERMISSION_KEY]: { ...permission, [FX_QUESTION_TOOL]: DENY_ACTION } }, change: "added" };
|
|
331
|
+
}
|
|
332
|
+
return { settings, change: fxRuleAction(existing) === DENY_ACTION ? "present" : "user-rule-kept" };
|
|
333
|
+
};
|
|
334
|
+
var withoutQuestionsRoutedToPushary = (settings, receipt) => {
|
|
335
|
+
const permission = asRecord(settings[PERMISSION_KEY]);
|
|
336
|
+
if (!permission || permission[FX_QUESTION_TOOL] === void 0) return { settings, outcome: "absent" };
|
|
337
|
+
if (!receipt) return { settings, outcome: "not-ours" };
|
|
338
|
+
if (fxRuleAction(permission[FX_QUESTION_TOOL]) !== DENY_ACTION) return { settings, outcome: "changed-after-setup" };
|
|
339
|
+
return { settings: withoutPermissionRule(settings, permission, FX_QUESTION_TOOL), outcome: "removed" };
|
|
340
|
+
};
|
|
341
|
+
var workspaceShowsQuestionTool = (workspace) => {
|
|
342
|
+
const scope = asRecord(workspace);
|
|
343
|
+
if (!scope) return false;
|
|
344
|
+
if (parseFxPermissionMode(scope[PERMISSION_MODE_KEY]) === "full-access") return true;
|
|
345
|
+
return scope[PERMISSION_KEY] !== void 0 && !fxQuestionToolHidden(scope[PERMISSION_KEY]);
|
|
346
|
+
};
|
|
347
|
+
var workspacesShowingQuestionTool = (settings) => Object.entries(asRecord(settings[WORKSPACES_KEY]) ?? {}).filter(([, workspace]) => workspaceShowsQuestionTool(workspace)).map(([path]) => path);
|
|
348
|
+
|
|
349
|
+
// src/fx-files.ts
|
|
350
|
+
import { existsSync, lstatSync, readFileSync, realpathSync } from "fs";
|
|
351
|
+
import { relative, isAbsolute } from "path";
|
|
352
|
+
var readFxFile = (path, read) => {
|
|
353
|
+
if (!existsSync(path)) return { kind: "missing" };
|
|
354
|
+
let text;
|
|
355
|
+
try {
|
|
356
|
+
text = readFileSync(path, "utf-8");
|
|
357
|
+
} catch {
|
|
358
|
+
return { kind: "unreadable" };
|
|
359
|
+
}
|
|
360
|
+
return read(text);
|
|
361
|
+
};
|
|
362
|
+
var isInside = (child, parent) => {
|
|
363
|
+
const path = relative(parent, child);
|
|
364
|
+
return path !== "" && !path.startsWith("..") && !isAbsolute(path);
|
|
365
|
+
};
|
|
366
|
+
var fxIgnoresInstructionsFile = (path, fxDir) => {
|
|
367
|
+
const link = lstatSync(path, { throwIfNoEntry: false });
|
|
368
|
+
if (!link?.isSymbolicLink()) return false;
|
|
369
|
+
try {
|
|
370
|
+
return !isInside(realpathSync(path), realpathSync(fxDir));
|
|
371
|
+
} catch {
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
// src/vscode-config.ts
|
|
377
|
+
import { homedir } from "os";
|
|
378
|
+
import { join } from "path";
|
|
379
|
+
var PLUGIN_LOCATIONS_KEY = "chat.pluginLocations";
|
|
380
|
+
var blankJsonComments = (text) => {
|
|
381
|
+
let out = "";
|
|
382
|
+
let i = 0;
|
|
383
|
+
let inString = false;
|
|
384
|
+
let escaped = false;
|
|
385
|
+
while (i < text.length) {
|
|
386
|
+
const ch = text[i];
|
|
387
|
+
if (inString) {
|
|
388
|
+
out += ch;
|
|
389
|
+
if (escaped) escaped = false;
|
|
390
|
+
else if (ch === "\\") escaped = true;
|
|
391
|
+
else if (ch === '"') inString = false;
|
|
392
|
+
i += 1;
|
|
393
|
+
continue;
|
|
394
|
+
}
|
|
395
|
+
if (ch === '"') {
|
|
396
|
+
inString = true;
|
|
397
|
+
out += ch;
|
|
398
|
+
i += 1;
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
if (ch === "/" && text[i + 1] === "/") {
|
|
402
|
+
while (i < text.length && text[i] !== "\n") {
|
|
403
|
+
out += " ";
|
|
404
|
+
i += 1;
|
|
405
|
+
}
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
if (ch === "/" && text[i + 1] === "*") {
|
|
409
|
+
const end = text.indexOf("*/", i + 2);
|
|
410
|
+
const stop = end === -1 ? text.length : end + 2;
|
|
411
|
+
while (i < stop) {
|
|
412
|
+
out += text[i] === "\n" ? "\n" : " ";
|
|
413
|
+
i += 1;
|
|
414
|
+
}
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
out += ch;
|
|
418
|
+
i += 1;
|
|
419
|
+
}
|
|
420
|
+
return out;
|
|
421
|
+
};
|
|
422
|
+
var asRecord2 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
423
|
+
var parseJsonc = (text) => {
|
|
424
|
+
const blanked = blankJsonComments(text);
|
|
425
|
+
const withoutTrailingCommas = blanked.replace(/,(\s*[}\]])/g, "$1");
|
|
426
|
+
try {
|
|
427
|
+
return asRecord2(JSON.parse(withoutTrailingCommas));
|
|
428
|
+
} catch {
|
|
429
|
+
return void 0;
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
var rootBraceIndex = (text) => blankJsonComments(text).indexOf("{");
|
|
433
|
+
var detectIndent = (text) => {
|
|
434
|
+
const match = /\n([ \t]+)"/.exec(text);
|
|
435
|
+
return match?.[1] ?? " ";
|
|
436
|
+
};
|
|
437
|
+
var freshDocument = (pluginDir, indent = " ") => `${JSON.stringify({ [PLUGIN_LOCATIONS_KEY]: { [pluginDir]: true } }, null, indent)}
|
|
438
|
+
`;
|
|
439
|
+
var registerPluginLocation = (existing, pluginDir) => {
|
|
440
|
+
if (existing === null || existing.trim() === "") {
|
|
441
|
+
return { kind: "created", content: freshDocument(pluginDir) };
|
|
442
|
+
}
|
|
443
|
+
const indent = detectIndent(existing);
|
|
444
|
+
try {
|
|
445
|
+
const parsed2 = asRecord2(JSON.parse(existing));
|
|
446
|
+
if (parsed2) {
|
|
447
|
+
const locations2 = asRecord2(parsed2[PLUGIN_LOCATIONS_KEY]) ?? {};
|
|
448
|
+
if (locations2[pluginDir] === true) return { kind: "already" };
|
|
449
|
+
parsed2[PLUGIN_LOCATIONS_KEY] = { ...locations2, [pluginDir]: true };
|
|
450
|
+
return { kind: "merged", content: `${JSON.stringify(parsed2, null, indent)}
|
|
451
|
+
` };
|
|
452
|
+
}
|
|
453
|
+
} catch {
|
|
454
|
+
}
|
|
455
|
+
const parsed = parseJsonc(existing);
|
|
456
|
+
if (!parsed) return { kind: "manual" };
|
|
457
|
+
const locations = asRecord2(parsed[PLUGIN_LOCATIONS_KEY]);
|
|
458
|
+
if (locations?.[pluginDir] === true) return { kind: "already" };
|
|
459
|
+
if (parsed[PLUGIN_LOCATIONS_KEY] !== void 0) return { kind: "manual" };
|
|
460
|
+
const brace = rootBraceIndex(existing);
|
|
461
|
+
if (brace === -1) return { kind: "manual" };
|
|
462
|
+
const needsComma = Object.keys(parsed).length > 0;
|
|
463
|
+
const line = `
|
|
464
|
+
${indent}${JSON.stringify(PLUGIN_LOCATIONS_KEY)}: { ${JSON.stringify(pluginDir)}: true }${needsComma ? "," : ""}`;
|
|
465
|
+
return {
|
|
466
|
+
kind: "inserted",
|
|
467
|
+
content: `${existing.slice(0, brace + 1)}${line}${existing.slice(brace + 1)}`
|
|
468
|
+
};
|
|
469
|
+
};
|
|
470
|
+
var unregisterPluginLocation = (existing, pluginDir) => {
|
|
471
|
+
if (existing === null || existing.trim() === "") return { kind: "absent" };
|
|
472
|
+
const indent = detectIndent(existing);
|
|
473
|
+
try {
|
|
474
|
+
const parsed2 = asRecord2(JSON.parse(existing));
|
|
475
|
+
if (parsed2) {
|
|
476
|
+
const locations2 = asRecord2(parsed2[PLUGIN_LOCATIONS_KEY]);
|
|
477
|
+
if (!locations2 || !(pluginDir in locations2)) return { kind: "absent" };
|
|
478
|
+
const remaining = { ...locations2 };
|
|
479
|
+
delete remaining[pluginDir];
|
|
480
|
+
if (Object.keys(remaining).length === 0) delete parsed2[PLUGIN_LOCATIONS_KEY];
|
|
481
|
+
else parsed2[PLUGIN_LOCATIONS_KEY] = remaining;
|
|
482
|
+
return { kind: "removed", content: `${JSON.stringify(parsed2, null, indent)}
|
|
483
|
+
` };
|
|
484
|
+
}
|
|
485
|
+
} catch {
|
|
486
|
+
}
|
|
487
|
+
const parsed = parseJsonc(existing);
|
|
488
|
+
if (!parsed) return { kind: "manual" };
|
|
489
|
+
const locations = asRecord2(parsed[PLUGIN_LOCATIONS_KEY]);
|
|
490
|
+
if (!locations || !(pluginDir in locations)) return { kind: "absent" };
|
|
491
|
+
const line = new RegExp(
|
|
492
|
+
`\\n[ \\t]*${escapeRegExp(JSON.stringify(PLUGIN_LOCATIONS_KEY))}\\s*:\\s*\\{\\s*${escapeRegExp(JSON.stringify(pluginDir))}\\s*:\\s*true\\s*\\},?`
|
|
493
|
+
);
|
|
494
|
+
if (!line.test(existing)) return { kind: "manual" };
|
|
495
|
+
return { kind: "removed", content: existing.replace(line, "") };
|
|
496
|
+
};
|
|
497
|
+
var escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
498
|
+
var isPluginRegistered = (existing, pluginDir) => {
|
|
499
|
+
if (!existing) return false;
|
|
500
|
+
const parsed = parseJsonc(existing);
|
|
501
|
+
return asRecord2(parsed?.[PLUGIN_LOCATIONS_KEY])?.[pluginDir] === true;
|
|
502
|
+
};
|
|
503
|
+
var pluginLocationSnippet = (pluginDir) => `"${PLUGIN_LOCATIONS_KEY}": {
|
|
504
|
+
${JSON.stringify(pluginDir)}: true
|
|
505
|
+
}`;
|
|
506
|
+
var VSCODE_PRODUCTS = ["Code", "Code - Insiders"];
|
|
507
|
+
var settingsRoot = (home, platform) => {
|
|
508
|
+
if (platform === "darwin") return join(home, "Library", "Application Support");
|
|
509
|
+
if (platform === "win32") return process.env.APPDATA?.trim() || join(home, "AppData", "Roaming");
|
|
510
|
+
return process.env.XDG_CONFIG_HOME?.trim() || join(home, ".config");
|
|
511
|
+
};
|
|
512
|
+
var vscodeSettingsCandidates = (home = homedir(), platform = process.platform) => {
|
|
513
|
+
const root = settingsRoot(home, platform);
|
|
514
|
+
return VSCODE_PRODUCTS.map((product) => join(root, product, "User", "settings.json"));
|
|
515
|
+
};
|
|
516
|
+
var vscodeSettingsTargets = (exists, home, platform) => {
|
|
517
|
+
const candidates = vscodeSettingsCandidates(home, platform);
|
|
518
|
+
const present = candidates.filter((path) => exists(path));
|
|
519
|
+
return present.length > 0 ? present : candidates.slice(0, 1);
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
// src/setup/detect.ts
|
|
523
|
+
import { execSync } from "child_process";
|
|
524
|
+
import { existsSync as existsSync2 } from "fs";
|
|
525
|
+
import { homedir as homedir2 } from "os";
|
|
526
|
+
import { dirname, join as join2 } from "path";
|
|
527
|
+
var whichCommand = () => process.platform === "win32" ? "where" : "which";
|
|
528
|
+
var binaryOnPath = (binary) => {
|
|
529
|
+
try {
|
|
530
|
+
execSync(`${whichCommand()} ${binary}`, { stdio: "ignore", timeout: 5e3 });
|
|
531
|
+
return true;
|
|
532
|
+
} catch {
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
var defaultDeps = { onPath: binaryOnPath, exists: existsSync2 };
|
|
537
|
+
var detectAgent = (probe, deps = defaultDeps) => {
|
|
538
|
+
const checked = [];
|
|
539
|
+
if (probe.binary) {
|
|
540
|
+
checked.push(`${whichCommand()} ${probe.binary}`);
|
|
541
|
+
if (deps.onPath(probe.binary)) {
|
|
542
|
+
return { kind: "installed", evidence: `${probe.binary} on PATH`, strong: true };
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
for (const path of probe.paths) {
|
|
546
|
+
checked.push(path);
|
|
547
|
+
if (deps.exists(path)) return { kind: "installed", evidence: path, strong: true };
|
|
548
|
+
}
|
|
549
|
+
for (const marker of probe.configMarkers) {
|
|
550
|
+
checked.push(marker);
|
|
551
|
+
if (deps.exists(marker)) return { kind: "installed", evidence: marker, strong: false };
|
|
552
|
+
}
|
|
553
|
+
if (probe.binary === null && probe.paths.length === 0 && probe.configMarkers.length === 0) {
|
|
554
|
+
return { kind: "unknown" };
|
|
555
|
+
}
|
|
556
|
+
return { kind: "not-found", checked };
|
|
557
|
+
};
|
|
558
|
+
var agentProbes = (home = homedir2()) => ({
|
|
559
|
+
claude_code: {
|
|
560
|
+
binary: "claude",
|
|
561
|
+
// The native installer puts it here, outside a default non-login PATH.
|
|
562
|
+
paths: [join2(home, ".local", "bin", "claude")],
|
|
563
|
+
configMarkers: [join2(home, ".claude")]
|
|
564
|
+
},
|
|
565
|
+
codex: {
|
|
566
|
+
binary: "codex",
|
|
567
|
+
paths: [],
|
|
568
|
+
configMarkers: [codexHomeFrom(home)]
|
|
569
|
+
},
|
|
570
|
+
gemini_cli: {
|
|
571
|
+
binary: "gemini",
|
|
572
|
+
paths: [],
|
|
573
|
+
configMarkers: [join2(home, ".gemini")]
|
|
574
|
+
},
|
|
575
|
+
hermes: {
|
|
576
|
+
binary: "hermes",
|
|
577
|
+
paths: [],
|
|
578
|
+
configMarkers: [join2(home, ".hermes")]
|
|
579
|
+
},
|
|
580
|
+
cursor: {
|
|
581
|
+
// GUI editor. `cursor` on PATH only exists if the user ran "Install 'cursor'
|
|
582
|
+
// command in PATH" from the command palette, which most never do.
|
|
583
|
+
binary: "cursor",
|
|
584
|
+
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")],
|
|
585
|
+
configMarkers: [join2(home, ".cursor")]
|
|
586
|
+
},
|
|
587
|
+
vscode: {
|
|
588
|
+
// Like Cursor, a GUI editor: `code` on PATH only exists if the user ran
|
|
589
|
+
// "Shell Command: Install 'code' command in PATH", which on macOS is opt-in.
|
|
590
|
+
binary: "code",
|
|
591
|
+
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")],
|
|
592
|
+
// The settings directory rather than ~/.vscode, because the settings
|
|
593
|
+
// directory is what this installer actually writes to. Insiders counts:
|
|
594
|
+
// someone running only Insiders still has VS Code.
|
|
595
|
+
configMarkers: vscodeSettingsCandidates(home).map((path) => dirname(path))
|
|
596
|
+
},
|
|
597
|
+
opencode: {
|
|
598
|
+
binary: "opencode",
|
|
599
|
+
paths: [],
|
|
600
|
+
// Resolved rather than spelled: OpenCode honours OPENCODE_CONFIG_DIR and then
|
|
601
|
+
// XDG_CONFIG_HOME, and `~/.opencode` — the obvious guess — is a path it has
|
|
602
|
+
// never used.
|
|
603
|
+
configMarkers: [openCodeConfigDirFrom(home)]
|
|
604
|
+
},
|
|
605
|
+
fx: {
|
|
606
|
+
binary: null,
|
|
607
|
+
paths: [join2(home, ".fx", "settings.json"), join2(home, ".fx", "sessions"), join2(home, ".fx", "history.jsonl")],
|
|
608
|
+
configMarkers: []
|
|
609
|
+
},
|
|
610
|
+
...compatibleProbes(),
|
|
611
|
+
// "Other" is a set of printed instructions for any MCP or HTTP client. There is
|
|
612
|
+
// nothing to detect, and it must never be auto-selected.
|
|
613
|
+
custom: { binary: null, paths: [], configMarkers: [] }
|
|
614
|
+
});
|
|
615
|
+
var compatibleProbes = () => HOOK_COMPATIBLE_PROFILES.reduce((probes, profile) => ({
|
|
616
|
+
...probes,
|
|
617
|
+
[profile.agentType]: {
|
|
618
|
+
binary: profile.binary,
|
|
619
|
+
paths: [],
|
|
620
|
+
configMarkers: []
|
|
621
|
+
}
|
|
622
|
+
}), {});
|
|
623
|
+
var detectAllAgents = (deps = defaultDeps, home) => {
|
|
624
|
+
const probes = agentProbes(home);
|
|
625
|
+
return Object.keys(probes).map((agent) => ({
|
|
626
|
+
agent,
|
|
627
|
+
result: detectAgent(probes[agent], deps)
|
|
628
|
+
}));
|
|
629
|
+
};
|
|
630
|
+
var isDetected = (result) => result.kind === "installed";
|
|
631
|
+
var shortenHome = (path, home = homedir2()) => home && path.startsWith(home) ? `~${path.slice(home.length)}` : path;
|
|
632
|
+
var describeDetection = (result, home) => {
|
|
633
|
+
if (result.kind !== "installed") return null;
|
|
634
|
+
const evidence = shortenHome(result.evidence, home);
|
|
635
|
+
return result.strong ? evidence : `${evidence}, config only`;
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
// src/instruction-file.ts
|
|
639
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, writeFileSync, mkdirSync, rmSync } from "fs";
|
|
640
|
+
import { dirname as dirname2 } from "path";
|
|
641
|
+
var PUSHARY_BEGIN = "<!-- BEGIN PUSHARY (managed by @pushary/agent-hooks; do not edit this block) -->";
|
|
642
|
+
var PUSHARY_END = "<!-- END PUSHARY -->";
|
|
643
|
+
var instructionBody = (label) => `## Pushary notifications and approvals
|
|
644
|
+
|
|
645
|
+
You have Pushary MCP tools that reach the user on their phone. Use them proactively. Do not wait for the user to ask.
|
|
646
|
+
|
|
647
|
+
- 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. Read \`answered\`, \`status\` and the returned handoff instead of assuming the tool blocked. Silence is not consent; choice/text answers do not authorize a separate action.
|
|
648
|
+
- Ask once, on one channel. If you also have a built-in way to prompt the user, use that or \`ask_user\` for a given question, never both. \`ask_user\` is the one that reaches the user when they are away from this machine, so prefer it. Raising both strands the user in whichever prompt you are not waiting on.
|
|
649
|
+
- Honor authorization already granted in this session. Ask before a risky or irreversible action outside that authorization, or when an enforced host policy requires it. Do not ask again for an already authorized step, and never bypass an enforced gate. When a Pushary hook result says the user approved a specific command after a denial, rerunning that exact command is the approved path and not a bypass of that gate.
|
|
650
|
+
- Call \`propose_scope\` only for an unresolved or requested file boundary. A ratified scope narrows what may proceed; it does not bypass other approval rules. Do not add a plan approval merely because work spans several files, and do not propose a new scope mid-run just to widen it. Let the installed gate request any scope expansion before the edit executes. Only file paths are checked, and only on tool calls that carry one, so put a boundary that is not a path (recipients, channels, spend, systems you will not open) in \`promises\` and never in \`allowedPaths\`. Read the \`enforces\` field that comes back: an empty array means nothing in that contract is checked automatically, and you must say so rather than report that a scope is in force. \`hookSeen: false\` means no hook has reported that sessionId, so the gate will never find the contract: fix the session id rather than proceeding as if a scope were in force.
|
|
651
|
+
- Before a task of more than two steps, break it into steps and find the forks. Settle by yourself every fork that a file, a command or a tool call can answer, then ask the rest as one numbered round with your recommended answer against each. A question in the terminal is free; a push is not. When the user is at the terminal, ask the whole round there. When the user is away, send only the fork that stops the run, and decide the rest on your recommendation.
|
|
652
|
+
- 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.
|
|
653
|
+
- When meaningful work finishes while the user is away, or they requested an alert, call \`send_notification\` so the user knows it is done. Skip trivial completions and duplicate reports to someone already reading. Always pass \`context\` with a \`type\` of "task_complete", "error" or "info": it is what tells Pushary this is a task update, so the user's own setting for where updates land can route it.
|
|
654
|
+
- Confirm notifications can offer lock-screen actions; arbitrary choices and text open the app. The Mac notch handles personal account questions, not Partner customer enrollment.
|
|
655
|
+
- Use \`cancel_question\` to retract a pending question once it is no longer needed.
|
|
656
|
+
- 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.
|
|
657
|
+
|
|
658
|
+
Pass \`agentName\` as "${label} - <project folder name>" so the user knows which session is asking. If a question times out, follow \`handoffAction\` when present, otherwise \`nextAction\`: poll once, then cancel a live phone question before asking in the current client. If cancellation returns \`handoffAction: "stop"\`, stop. Otherwise, if cancellation returns false, poll once for 1 second and honor the answer that won the race.`;
|
|
659
|
+
var renderAgentInstructions = (label) => instructionBody(label);
|
|
660
|
+
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 (3-day trial): https://pushary.com/sign-up?utm_source=agents-md&utm_medium=teammate";
|
|
661
|
+
var renderProjectAgentInstructions = (label) => `${instructionBody(label)}
|
|
662
|
+
|
|
663
|
+
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}`;
|
|
664
|
+
var wrap = (body) => `${PUSHARY_BEGIN}
|
|
665
|
+
${body}
|
|
666
|
+
${PUSHARY_END}`;
|
|
667
|
+
var writeInstructionBlock = (filePath, body) => {
|
|
668
|
+
const dir = dirname2(filePath);
|
|
669
|
+
if (!existsSync3(dir)) mkdirSync(dir, { recursive: true });
|
|
670
|
+
let existing = "";
|
|
671
|
+
try {
|
|
672
|
+
existing = readFileSync2(filePath, "utf-8");
|
|
673
|
+
} catch {
|
|
674
|
+
}
|
|
675
|
+
const block = wrap(body);
|
|
676
|
+
const start = existing.indexOf(PUSHARY_BEGIN);
|
|
677
|
+
const end = existing.indexOf(PUSHARY_END);
|
|
678
|
+
let next;
|
|
679
|
+
if (start !== -1 && end !== -1 && end > start) {
|
|
680
|
+
next = existing.slice(0, start) + block + existing.slice(end + PUSHARY_END.length);
|
|
681
|
+
} else {
|
|
682
|
+
const prefix = existing.trim() ? existing.replace(/\s*$/, "") + "\n\n" : "";
|
|
683
|
+
next = prefix + block + "\n";
|
|
684
|
+
}
|
|
685
|
+
writeFileSync(filePath, next, "utf-8");
|
|
686
|
+
};
|
|
687
|
+
var removeInstructionBlock = (filePath) => {
|
|
688
|
+
let existing = "";
|
|
689
|
+
try {
|
|
690
|
+
existing = readFileSync2(filePath, "utf-8");
|
|
691
|
+
} catch {
|
|
692
|
+
return false;
|
|
693
|
+
}
|
|
694
|
+
const start = existing.indexOf(PUSHARY_BEGIN);
|
|
695
|
+
const end = existing.indexOf(PUSHARY_END);
|
|
696
|
+
if (start === -1 || end === -1 || end < start) return false;
|
|
697
|
+
const remaining = (existing.slice(0, start) + existing.slice(end + PUSHARY_END.length)).trim();
|
|
698
|
+
if (remaining === "") {
|
|
699
|
+
rmSync(filePath, { force: true });
|
|
700
|
+
} else {
|
|
701
|
+
writeFileSync(filePath, remaining + "\n", "utf-8");
|
|
702
|
+
}
|
|
703
|
+
return true;
|
|
704
|
+
};
|
|
705
|
+
var hasInstructionBlock = (filePath) => {
|
|
706
|
+
try {
|
|
707
|
+
return readFileSync2(filePath, "utf-8").includes(PUSHARY_BEGIN);
|
|
708
|
+
} catch {
|
|
709
|
+
return false;
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
export {
|
|
714
|
+
FX_PUSHARY_TOOLS_RULE,
|
|
715
|
+
FX_TOOL_DISCOVERY_NOTE,
|
|
716
|
+
FX_PROFILE_REFUSALS,
|
|
717
|
+
FX_SETTINGS_REFUSALS,
|
|
718
|
+
readFxProfile,
|
|
719
|
+
fxPusharyEntry,
|
|
720
|
+
withFxPusharyServer,
|
|
721
|
+
withoutFxPusharyServer,
|
|
722
|
+
isFxPusharyEntry,
|
|
723
|
+
fxPusharyEntryOf,
|
|
724
|
+
fxBridgeTargetOf,
|
|
725
|
+
fxProfileText,
|
|
726
|
+
fxSettingsText,
|
|
727
|
+
readFxSettings,
|
|
728
|
+
withPusharyToolsAllowed,
|
|
729
|
+
withoutPusharyToolsAllowed,
|
|
730
|
+
pusharyToolsAllowed,
|
|
731
|
+
workspacesOverridingPusharyRule,
|
|
732
|
+
FX_QUESTION_TOOL,
|
|
733
|
+
FX_QUESTION_RULE_RECEIPT,
|
|
734
|
+
isFxQuestionRuleReceipt,
|
|
735
|
+
fxQuestionRouting,
|
|
736
|
+
withQuestionsRoutedToPushary,
|
|
737
|
+
withoutQuestionsRoutedToPushary,
|
|
738
|
+
workspacesShowingQuestionTool,
|
|
739
|
+
readFxFile,
|
|
740
|
+
fxIgnoresInstructionsFile,
|
|
741
|
+
registerPluginLocation,
|
|
742
|
+
unregisterPluginLocation,
|
|
743
|
+
isPluginRegistered,
|
|
744
|
+
pluginLocationSnippet,
|
|
745
|
+
vscodeSettingsTargets,
|
|
746
|
+
detectAgent,
|
|
747
|
+
agentProbes,
|
|
748
|
+
detectAllAgents,
|
|
749
|
+
isDetected,
|
|
750
|
+
shortenHome,
|
|
751
|
+
describeDetection,
|
|
752
|
+
renderAgentInstructions,
|
|
753
|
+
renderProjectAgentInstructions,
|
|
754
|
+
writeInstructionBlock,
|
|
755
|
+
removeInstructionBlock,
|
|
756
|
+
hasInstructionBlock
|
|
757
|
+
};
|