@cg3/equip 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/equip.js +67 -4
- package/package.json +1 -1
package/bin/equip.js
CHANGED
|
@@ -142,27 +142,90 @@ function dispatchTool(alias, extraArgs) {
|
|
|
142
142
|
console.error(`Run "equip --help" for usage.`);
|
|
143
143
|
process.exit(1);
|
|
144
144
|
}
|
|
145
|
-
spawnTool(pkg, command, extraArgs);
|
|
145
|
+
spawnTool(pkg, command, extraArgs, null);
|
|
146
146
|
return;
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
// For registered tools, the alias IS the tool name (e.g. "prior")
|
|
150
|
+
spawnTool(entry.package, entry.command, extraArgs, alias);
|
|
150
151
|
}
|
|
151
152
|
|
|
152
|
-
function spawnTool(pkg, command, extraArgs) {
|
|
153
|
+
function spawnTool(pkg, command, extraArgs, toolName) {
|
|
153
154
|
const npxCmd = process.platform === "win32" ? "npx.cmd" : "npx";
|
|
154
155
|
const child = spawn(npxCmd, ["-y", `${pkg}@latest`, command, ...extraArgs], {
|
|
155
156
|
stdio: "inherit",
|
|
156
157
|
shell: process.platform === "win32",
|
|
157
158
|
env: { ...process.env, EQUIP_VERSION },
|
|
158
159
|
});
|
|
159
|
-
child.on("close", (code) =>
|
|
160
|
+
child.on("close", (code) => {
|
|
161
|
+
if (code === 0 && toolName) {
|
|
162
|
+
try { reconcileState(toolName, pkg); } catch {}
|
|
163
|
+
}
|
|
164
|
+
process.exit(code || 0);
|
|
165
|
+
});
|
|
160
166
|
child.on("error", (err) => {
|
|
161
167
|
console.error(`Failed to run ${pkg}: ${err.message}`);
|
|
162
168
|
process.exit(1);
|
|
163
169
|
});
|
|
164
170
|
}
|
|
165
171
|
|
|
172
|
+
/**
|
|
173
|
+
* After a tool finishes, scan platform configs and update state
|
|
174
|
+
* based on what's actually on disk. This ensures state is always
|
|
175
|
+
* accurate regardless of which equip version the tool used internally.
|
|
176
|
+
*/
|
|
177
|
+
function reconcileState(toolName, pkg) {
|
|
178
|
+
const { PLATFORM_REGISTRY } = require("../dist/lib/platforms");
|
|
179
|
+
const { readMcpEntry } = require("../dist/lib/mcp");
|
|
180
|
+
const { trackInstall } = require("../dist/lib/state");
|
|
181
|
+
const { dirExists, fileExists } = require("../dist/lib/detect");
|
|
182
|
+
const _fs = require("fs");
|
|
183
|
+
const _path = require("path");
|
|
184
|
+
|
|
185
|
+
for (const [id, def] of PLATFORM_REGISTRY) {
|
|
186
|
+
// Quick check: is this platform present?
|
|
187
|
+
const dirFound = def.detection.dirs.some(fn => dirExists(fn()));
|
|
188
|
+
const fileFound = def.detection.files.some(fn => fileExists(fn()));
|
|
189
|
+
const configPath = def.configPath();
|
|
190
|
+
if (!dirFound && !fileFound && !fileExists(configPath)) continue;
|
|
191
|
+
|
|
192
|
+
// Check if tool has an MCP entry on this platform
|
|
193
|
+
const entry = readMcpEntry(configPath, def.rootKey, toolName, def.configFormat);
|
|
194
|
+
if (!entry) continue;
|
|
195
|
+
|
|
196
|
+
// Build state record from what's on disk
|
|
197
|
+
const record = {
|
|
198
|
+
configPath,
|
|
199
|
+
transport: entry.command ? "stdio" : "http",
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// Check for rules
|
|
203
|
+
if (def.rulesPath) {
|
|
204
|
+
const rulesPath = def.rulesPath();
|
|
205
|
+
try {
|
|
206
|
+
const content = _fs.readFileSync(rulesPath, "utf-8");
|
|
207
|
+
const versionMatch = content.match(new RegExp(`<!-- ${toolName}:v([\\d.]+) -->`));
|
|
208
|
+
if (versionMatch) {
|
|
209
|
+
record.rulesPath = rulesPath;
|
|
210
|
+
record.rulesVersion = versionMatch[1];
|
|
211
|
+
}
|
|
212
|
+
} catch {}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Check for hooks (look for tool's hook directory)
|
|
216
|
+
const hookDir = _path.join(require("os").homedir(), `.${toolName}`, "hooks");
|
|
217
|
+
try {
|
|
218
|
+
const hookFiles = _fs.readdirSync(hookDir).filter(f => f.endsWith(".js"));
|
|
219
|
+
if (hookFiles.length > 0) {
|
|
220
|
+
record.hookDir = hookDir;
|
|
221
|
+
record.hookScripts = hookFiles;
|
|
222
|
+
}
|
|
223
|
+
} catch {}
|
|
224
|
+
|
|
225
|
+
trackInstall(toolName, pkg, id, record);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
166
229
|
// ─── Main ───────────────────────────────────────────────────
|
|
167
230
|
|
|
168
231
|
const cmd = process.argv[2];
|