make-laten 1.0.1 → 1.0.3

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/index.mjs CHANGED
@@ -996,22 +996,361 @@ var RulesAdapter = class {
996
996
  }
997
997
  };
998
998
 
999
- // src/adapter/detector.ts
1000
- import { exec } from "child_process";
1001
- import { promisify } from "util";
999
+ // src/adapter/installer.ts
1002
1000
  import fs3 from "fs/promises";
1003
1001
  import path3 from "path";
1002
+ import { exec } from "child_process";
1003
+ import { promisify } from "util";
1004
1004
  var execAsync = promisify(exec);
1005
+ var RULES_CONTENT = `
1006
+ # make-laten efficiency rules
1007
+
1008
+ ## Token Optimization
1009
+ - When reading files, use \`make-laten read <file>\` for compressed output
1010
+ - When searching code, use \`make-laten grep <pattern>\` for grouped results
1011
+ - When checking git, use \`make-laten git diff\` for condensed output
1012
+ - When fetching web, use \`make-laten fetch <url>\` for compressed content
1013
+
1014
+ ## Quick Commands
1015
+ - \`mread <file>\` \u2014 alias for make-laten read
1016
+ - \`mgrep <pattern>\` \u2014 alias for make-laten grep
1017
+ - \`mdiff\` \u2014 alias for make-laten git diff
1018
+ - \`msearch <query>\` \u2014 alias for make-laten search
1019
+ - \`mfetch <url>\` \u2014 alias for make-laten fetch
1020
+ `;
1021
+ function getHome() {
1022
+ return process.env.HOME || process.env.USERPROFILE || "";
1023
+ }
1024
+ async function commandExists(cmd) {
1025
+ try {
1026
+ await execAsync(`which ${cmd}`, { timeout: 3e3 });
1027
+ return true;
1028
+ } catch {
1029
+ return false;
1030
+ }
1031
+ }
1032
+ var agents = [
1033
+ {
1034
+ name: "terminal (shell aliases)",
1035
+ detected: async () => true,
1036
+ install: async () => {
1037
+ const shellInit = await execAsync("echo $SHELL").then((r) => r.stdout.trim());
1038
+ const rcFile = shellInit.includes("zsh") ? ".zshrc" : ".bashrc";
1039
+ const rcPath = path3.join(getHome(), rcFile);
1040
+ const marker = "make-laten shell";
1041
+ let existing = "";
1042
+ try {
1043
+ existing = await fs3.readFile(rcPath, "utf-8");
1044
+ } catch {
1045
+ }
1046
+ if (!existing.includes(marker)) {
1047
+ const npmRoot = await execAsync("npm root -g").then((r) => r.stdout.trim());
1048
+ const initScript = `
1049
+ # make-laten shell integration
1050
+ source ${npmRoot}/make-laten/shell/init.sh
1051
+ `;
1052
+ await fs3.appendFile(rcPath, initScript);
1053
+ }
1054
+ },
1055
+ uninstall: async () => {
1056
+ const shellInit = await execAsync("echo $SHELL").then((r) => r.stdout.trim());
1057
+ const rcFile = shellInit.includes("zsh") ? ".zshrc" : ".bashrc";
1058
+ const rcPath = path3.join(getHome(), rcFile);
1059
+ try {
1060
+ let content = await fs3.readFile(rcPath, "utf-8");
1061
+ content = content.replace(/\n# make-laten shell integration\nsource .*\/make-laten\/shell\/init\.sh\n/g, "");
1062
+ await fs3.writeFile(rcPath, content);
1063
+ } catch {
1064
+ }
1065
+ }
1066
+ },
1067
+ {
1068
+ name: "claude-code",
1069
+ detected: async () => commandExists("claude"),
1070
+ install: async () => {
1071
+ const hooksDir = path3.join(getHome(), ".claude", "hooks");
1072
+ await fs3.mkdir(hooksDir, { recursive: true });
1073
+ const preHook = `#!/usr/bin/env node
1074
+ const { readFileSync } = require('fs');
1075
+ const input = JSON.parse(readFileSync('/dev/stdin', 'utf-8'));
1076
+ if (input.tool === 'Read' || input.tool === 'Bash') {
1077
+ process.env.MAKE_LATEN_INTERCEPT = '1';
1078
+ }
1079
+ process.stdout.write(JSON.stringify(input));`;
1080
+ const postHook = `#!/usr/bin/env node
1081
+ const { readFileSync } = require('fs');
1082
+ const input = JSON.parse(readFileSync('/dev/stdin', 'utf-8'));
1083
+ if (input.output && input.output.length > 10000) {
1084
+ input.output = input.output.slice(0, 10000) + '\\n... (truncated by make-laten)';
1085
+ }
1086
+ process.stdout.write(JSON.stringify(input));`;
1087
+ await fs3.writeFile(path3.join(hooksDir, "pre-tool-use.js"), preHook);
1088
+ await fs3.writeFile(path3.join(hooksDir, "post-tool-use.js"), postHook);
1089
+ },
1090
+ uninstall: async () => {
1091
+ const hooksDir = path3.join(getHome(), ".claude", "hooks");
1092
+ try {
1093
+ await fs3.rm(path3.join(hooksDir, "pre-tool-use.js"), { force: true });
1094
+ } catch {
1095
+ }
1096
+ try {
1097
+ await fs3.rm(path3.join(hooksDir, "post-tool-use.js"), { force: true });
1098
+ } catch {
1099
+ }
1100
+ }
1101
+ },
1102
+ {
1103
+ name: "cursor",
1104
+ detected: async () => {
1105
+ try {
1106
+ await fs3.access(path3.join(getHome(), ".cursor"));
1107
+ return true;
1108
+ } catch {
1109
+ return false;
1110
+ }
1111
+ },
1112
+ install: async () => {
1113
+ const rulesDir = path3.join(getHome(), ".cursor", "rules");
1114
+ await fs3.mkdir(rulesDir, { recursive: true });
1115
+ const ruleFile = path3.join(rulesDir, "make-laten.mdc");
1116
+ const content = `---
1117
+ description: make-laten efficiency rules
1118
+ globs:
1119
+ ---
1120
+ ${RULES_CONTENT}`;
1121
+ await fs3.writeFile(ruleFile, content);
1122
+ },
1123
+ uninstall: async () => {
1124
+ try {
1125
+ await fs3.rm(path3.join(getHome(), ".cursor", "rules", "make-laten.mdc"), { force: true });
1126
+ } catch {
1127
+ }
1128
+ }
1129
+ },
1130
+ {
1131
+ name: "codex",
1132
+ detected: async () => commandExists("codex"),
1133
+ install: async () => {
1134
+ const agentsMd = path3.join(process.cwd(), "AGENTS.md");
1135
+ let existing = "";
1136
+ try {
1137
+ existing = await fs3.readFile(agentsMd, "utf-8");
1138
+ } catch {
1139
+ }
1140
+ if (!existing.includes("make-laten")) {
1141
+ const content = existing + "\n\n## make-laten Integration\n" + RULES_CONTENT;
1142
+ await fs3.writeFile(agentsMd, content);
1143
+ }
1144
+ },
1145
+ uninstall: async () => {
1146
+ try {
1147
+ let content = await fs3.readFile(path3.join(process.cwd(), "AGENTS.md"), "utf-8");
1148
+ content = content.replace(/\n## make-laten Integration[\s\S]*$/, "");
1149
+ await fs3.writeFile(path3.join(process.cwd(), "AGENTS.md"), content.trim() + "\n");
1150
+ } catch {
1151
+ }
1152
+ }
1153
+ },
1154
+ {
1155
+ name: "windsurf",
1156
+ detected: async () => {
1157
+ try {
1158
+ await fs3.access(path3.join(process.cwd(), ".windsurf"));
1159
+ return true;
1160
+ } catch {
1161
+ try {
1162
+ await fs3.access(path3.join(getHome(), ".windsurf"));
1163
+ return true;
1164
+ } catch {
1165
+ return false;
1166
+ }
1167
+ }
1168
+ },
1169
+ install: async () => {
1170
+ const rulesPath = path3.join(process.cwd(), ".windsurfrules");
1171
+ let existing = "";
1172
+ try {
1173
+ existing = await fs3.readFile(rulesPath, "utf-8");
1174
+ } catch {
1175
+ }
1176
+ if (!existing.includes("make-laten")) {
1177
+ await fs3.writeFile(rulesPath, existing + "\n\n" + RULES_CONTENT);
1178
+ }
1179
+ },
1180
+ uninstall: async () => {
1181
+ try {
1182
+ let content = await fs3.readFile(path3.join(process.cwd(), ".windsurfrules"), "utf-8");
1183
+ content = content.replace(/\n# make-laten efficiency rules[\s\S]*$/, "");
1184
+ await fs3.writeFile(path3.join(process.cwd(), ".windsurfrules"), content.trim() + "\n");
1185
+ } catch {
1186
+ }
1187
+ }
1188
+ },
1189
+ {
1190
+ name: "cline",
1191
+ detected: async () => {
1192
+ try {
1193
+ await fs3.access(path3.join(process.cwd(), ".clinerules"));
1194
+ return true;
1195
+ } catch {
1196
+ try {
1197
+ await fs3.access(path3.join(getHome(), ".cline"));
1198
+ return true;
1199
+ } catch {
1200
+ return false;
1201
+ }
1202
+ }
1203
+ },
1204
+ install: async () => {
1205
+ const rulesPath = path3.join(process.cwd(), ".clinerules");
1206
+ let existing = "";
1207
+ try {
1208
+ existing = await fs3.readFile(rulesPath, "utf-8");
1209
+ } catch {
1210
+ }
1211
+ if (!existing.includes("make-laten")) {
1212
+ await fs3.writeFile(rulesPath, existing + "\n\n" + RULES_CONTENT);
1213
+ }
1214
+ },
1215
+ uninstall: async () => {
1216
+ try {
1217
+ let content = await fs3.readFile(path3.join(process.cwd(), ".clinerules"), "utf-8");
1218
+ content = content.replace(/\n# make-laten efficiency rules[\s\S]*$/, "");
1219
+ await fs3.writeFile(path3.join(process.cwd(), ".clinerules"), content.trim() + "\n");
1220
+ } catch {
1221
+ }
1222
+ }
1223
+ },
1224
+ {
1225
+ name: "copilot",
1226
+ detected: async () => {
1227
+ try {
1228
+ await fs3.access(path3.join(process.cwd(), ".github"));
1229
+ return true;
1230
+ } catch {
1231
+ return false;
1232
+ }
1233
+ },
1234
+ install: async () => {
1235
+ const dir = path3.join(process.cwd(), ".github");
1236
+ await fs3.mkdir(dir, { recursive: true });
1237
+ const instructionsPath = path3.join(dir, "copilot-instructions.md");
1238
+ let existing = "";
1239
+ try {
1240
+ existing = await fs3.readFile(instructionsPath, "utf-8");
1241
+ } catch {
1242
+ }
1243
+ if (!existing.includes("make-laten")) {
1244
+ await fs3.writeFile(instructionsPath, existing + "\n\n## make-laten Efficiency\n" + RULES_CONTENT);
1245
+ }
1246
+ },
1247
+ uninstall: async () => {
1248
+ try {
1249
+ let content = await fs3.readFile(path3.join(process.cwd(), ".github", "copilot-instructions.md"), "utf-8");
1250
+ content = content.replace(/\n## make-laten Efficiency[\s\S]*$/, "");
1251
+ await fs3.writeFile(path3.join(process.cwd(), ".github", "copilot-instructions.md"), content.trim() + "\n");
1252
+ } catch {
1253
+ }
1254
+ }
1255
+ },
1256
+ {
1257
+ name: "opencode",
1258
+ detected: async () => {
1259
+ try {
1260
+ await fs3.access(path3.join(getHome(), ".config", "opencode"));
1261
+ return true;
1262
+ } catch {
1263
+ return false;
1264
+ }
1265
+ },
1266
+ install: async () => {
1267
+ const skillsDir = path3.join(getHome(), ".config", "opencode", "skills", "make-laten");
1268
+ await fs3.mkdir(skillsDir, { recursive: true });
1269
+ const npmRoot = await execAsync("npm root -g").then((r) => r.stdout.trim());
1270
+ const skillSrc = path3.join(npmRoot, "make-laten", "skills", "SKILL.md");
1271
+ try {
1272
+ const skillContent = await fs3.readFile(skillSrc, "utf-8");
1273
+ await fs3.writeFile(path3.join(skillsDir, "SKILL.md"), skillContent);
1274
+ } catch {
1275
+ await fs3.writeFile(path3.join(skillsDir, "SKILL.md"), `---
1276
+ name: make-laten
1277
+ description: Token optimization toolkit
1278
+ ---
1279
+
1280
+ # make-laten Skill
1281
+
1282
+ Use make-laten CLI commands for all file/code/git operations.
1283
+ `);
1284
+ }
1285
+ },
1286
+ uninstall: async () => {
1287
+ try {
1288
+ await fs3.rm(path3.join(getHome(), ".config", "opencode", "skills", "make-laten"), { recursive: true, force: true });
1289
+ } catch {
1290
+ }
1291
+ }
1292
+ }
1293
+ ];
1294
+ var Installer = class {
1295
+ async install() {
1296
+ const installed = [];
1297
+ const skipped = [];
1298
+ for (const agent of agents) {
1299
+ try {
1300
+ const detected = await agent.detected();
1301
+ if (detected) {
1302
+ await agent.install();
1303
+ installed.push(agent.name);
1304
+ } else {
1305
+ skipped.push(agent.name);
1306
+ }
1307
+ } catch {
1308
+ skipped.push(agent.name);
1309
+ }
1310
+ }
1311
+ return { installed, skipped };
1312
+ }
1313
+ async uninstall() {
1314
+ const removed = [];
1315
+ for (const agent of agents) {
1316
+ try {
1317
+ await agent.uninstall();
1318
+ removed.push(agent.name);
1319
+ } catch {
1320
+ }
1321
+ }
1322
+ return { removed };
1323
+ }
1324
+ async status() {
1325
+ const result = [];
1326
+ for (const agent of agents) {
1327
+ try {
1328
+ const detected = await agent.detected();
1329
+ result.push({ name: agent.name, detected, installed: false });
1330
+ } catch {
1331
+ result.push({ name: agent.name, detected: false, installed: false });
1332
+ }
1333
+ }
1334
+ return result;
1335
+ }
1336
+ };
1337
+
1338
+ // src/adapter/detector.ts
1339
+ import { exec as exec2 } from "child_process";
1340
+ import { promisify as promisify2 } from "util";
1341
+ import fs4 from "fs/promises";
1342
+ import path4 from "path";
1343
+ var execAsync2 = promisify2(exec2);
1005
1344
  var AgentDetector = class {
1006
1345
  async detectAgents() {
1007
- const agents = [];
1346
+ const agents2 = [];
1008
1347
  for (const [name, config] of Object.entries(AGENT_CONFIGS)) {
1009
1348
  const detected = await this.detectAgent(name, config.type);
1010
1349
  if (detected) {
1011
- agents.push(detected);
1350
+ agents2.push(detected);
1012
1351
  }
1013
1352
  }
1014
- return agents;
1353
+ return agents2;
1015
1354
  }
1016
1355
  async detectAgent(name, type) {
1017
1356
  const commands = {
@@ -1021,7 +1360,7 @@ var AgentDetector = class {
1021
1360
  };
1022
1361
  if (commands[name]) {
1023
1362
  try {
1024
- const { stdout } = await execAsync(commands[name], { timeout: 5e3 });
1363
+ const { stdout } = await execAsync2(commands[name], { timeout: 5e3 });
1025
1364
  const version = stdout.trim().split("\n")[0];
1026
1365
  const agentPath = await this.getAgentPath(name);
1027
1366
  return { name, type, path: agentPath, version, detected: true };
@@ -1033,7 +1372,7 @@ var AgentDetector = class {
1033
1372
  const rulesPath = AGENT_CONFIGS[name]?.rulesFile;
1034
1373
  if (rulesPath) {
1035
1374
  try {
1036
- await fs3.access(path3.join(process.cwd(), rulesPath));
1375
+ await fs4.access(path4.join(process.cwd(), rulesPath));
1037
1376
  return { name, type, path: process.cwd(), version: null, detected: true };
1038
1377
  } catch {
1039
1378
  return null;
@@ -1045,15 +1384,15 @@ var AgentDetector = class {
1045
1384
  async getAgentPath(name) {
1046
1385
  const home = process.env.HOME || process.env.USERPROFILE || "";
1047
1386
  const paths = {
1048
- "claude-code": path3.join(home, ".claude"),
1049
- "codex": path3.join(home, ".codex"),
1050
- "gemini-cli": path3.join(home, ".gemini")
1387
+ "claude-code": path4.join(home, ".claude"),
1388
+ "codex": path4.join(home, ".codex"),
1389
+ "gemini-cli": path4.join(home, ".gemini")
1051
1390
  };
1052
- return paths[name] || path3.join(home, `.${name}`);
1391
+ return paths[name] || path4.join(home, `.${name}`);
1053
1392
  }
1054
1393
  async hasCommand(cmd) {
1055
1394
  try {
1056
- await execAsync(`which ${cmd}`, { timeout: 3e3 });
1395
+ await execAsync2(`which ${cmd}`, { timeout: 3e3 });
1057
1396
  return true;
1058
1397
  } catch {
1059
1398
  return false;
@@ -1061,62 +1400,6 @@ var AgentDetector = class {
1061
1400
  }
1062
1401
  };
1063
1402
 
1064
- // src/adapter/installer.ts
1065
- var Installer = class {
1066
- detector = new AgentDetector();
1067
- async install() {
1068
- const agents = await this.detector.detectAgents();
1069
- const installed = [];
1070
- const skipped = [];
1071
- for (const agent of agents) {
1072
- try {
1073
- const adapter = this.createAdapter(agent);
1074
- if (adapter.install) {
1075
- await adapter.install(agent.path);
1076
- installed.push(agent.name);
1077
- } else {
1078
- skipped.push(agent.name);
1079
- }
1080
- } catch {
1081
- skipped.push(agent.name);
1082
- }
1083
- }
1084
- return { installed, skipped };
1085
- }
1086
- async uninstall() {
1087
- const agents = await this.detector.detectAgents();
1088
- const removed = [];
1089
- for (const agent of agents) {
1090
- try {
1091
- const adapter = this.createAdapter(agent);
1092
- if (adapter.uninstall) {
1093
- await adapter.uninstall(agent.path);
1094
- removed.push(agent.name);
1095
- }
1096
- } catch {
1097
- }
1098
- }
1099
- return { removed };
1100
- }
1101
- async status() {
1102
- const agents = await this.detector.detectAgents();
1103
- for (const agent of agents) {
1104
- const adapter = this.createAdapter(agent);
1105
- if (adapter.isInstalled) {
1106
- agent.detected = await adapter.isInstalled(agent.path);
1107
- }
1108
- }
1109
- return agents;
1110
- }
1111
- createAdapter(agent) {
1112
- const config = AGENT_CONFIGS[agent.name];
1113
- if (config?.type === "rules") {
1114
- return new RulesAdapter(agent.name);
1115
- }
1116
- return new HookAdapter(agent.name);
1117
- }
1118
- };
1119
-
1120
1403
  // src/adapter/index.ts
1121
1404
  var adapters = /* @__PURE__ */ new Map();
1122
1405
  adapters.set("claude-code", new ClaudeCodeAdapter());