@asanabrial/estigia 0.1.1 → 0.3.0
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/estigia.js +88 -10
- package/package.json +1 -1
package/bin/estigia.js
CHANGED
|
@@ -17,7 +17,7 @@ const TARGETS = {
|
|
|
17
17
|
"darwin-x64": { triple: "x86_64-apple-darwin", archive: "tar.gz", exe: "estigia" },
|
|
18
18
|
"darwin-arm64": { triple: "aarch64-apple-darwin", archive: "tar.gz", exe: "estigia" },
|
|
19
19
|
"win32-x64": { triple: "x86_64-pc-windows-msvc", archive: "zip", exe: "estigia.exe" },
|
|
20
|
-
"win32-arm64": { triple: "
|
|
20
|
+
"win32-arm64": { triple: "x86_64-pc-windows-msvc", archive: "zip", exe: "estigia.exe" },
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
class EstigiaError extends Error {}
|
|
@@ -88,6 +88,25 @@ function installedVersion(binary) {
|
|
|
88
88
|
return match ? match[1] : null;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
function parsedVersion(text) {
|
|
92
|
+
const match = /^(\d+)\.(\d+)\.(\d+)/.exec(text || "");
|
|
93
|
+
return match ? match.slice(1).map(Number) : null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function isNewer(installed, wanted) {
|
|
97
|
+
const found = parsedVersion(installed);
|
|
98
|
+
const asked = parsedVersion(wanted);
|
|
99
|
+
if (!found || !asked) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
for (let index = 0; index < 3; index += 1) {
|
|
103
|
+
if (found[index] !== asked[index]) {
|
|
104
|
+
return found[index] > asked[index];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
|
|
91
110
|
function extract(archivePath, into) {
|
|
92
111
|
const tar =
|
|
93
112
|
process.platform === "win32"
|
|
@@ -134,34 +153,93 @@ async function install(tag, target, binary) {
|
|
|
134
153
|
}
|
|
135
154
|
fs.chmodSync(candidate, 0o755);
|
|
136
155
|
|
|
137
|
-
const
|
|
138
|
-
|
|
156
|
+
const admitted = spawnSync(candidate, ["__record-install", "--check"], {
|
|
157
|
+
encoding: "utf8",
|
|
158
|
+
stdio: ["ignore", process.stderr, "pipe"],
|
|
139
159
|
});
|
|
140
|
-
|
|
141
|
-
|
|
160
|
+
const loaderWords = (admitted.stderr || "").trim();
|
|
161
|
+
if (admitted.error || admitted.status === 126 || admitted.status === 127) {
|
|
162
|
+
const words = admitted.error ? admitted.error.message : loaderWords;
|
|
163
|
+
let detail = `this platform cannot run the ${target.triple} archive, and that is the reason`;
|
|
164
|
+
if (words) {
|
|
165
|
+
detail += `; the loader said: ${words}`;
|
|
166
|
+
}
|
|
167
|
+
if (target.triple.endsWith("-unknown-linux-gnu")) {
|
|
168
|
+
detail += `\n The published ${target.triple} archives need glibc 2.39 or newer.`;
|
|
169
|
+
}
|
|
170
|
+
fail(
|
|
171
|
+
`the downloaded candidate could not be executed, so it was not asked to record itself: ${detail}\n` +
|
|
172
|
+
" Build on this machine instead: cargo install estigia " +
|
|
173
|
+
`(main: cargo install --git https://github.com/${REPO})\n` +
|
|
174
|
+
" Refusing to replace the installed executable.",
|
|
175
|
+
);
|
|
142
176
|
}
|
|
143
|
-
|
|
177
|
+
process.stderr.write(admitted.stderr || "");
|
|
178
|
+
if (admitted.status !== 0) {
|
|
144
179
|
fail("candidate lifecycle admission failed; refusing to replace the installed executable");
|
|
145
180
|
}
|
|
146
181
|
|
|
147
182
|
fs.mkdirSync(path.dirname(binary), { recursive: true });
|
|
148
183
|
const placed = `${binary}.${process.pid}.new`;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
184
|
+
try {
|
|
185
|
+
fs.copyFileSync(candidate, placed);
|
|
186
|
+
fs.chmodSync(placed, 0o755);
|
|
187
|
+
fs.renameSync(placed, binary);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
fs.rmSync(placed, { force: true });
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const recorded = spawnSync(binary, ["__record-install"], {
|
|
194
|
+
encoding: "utf8",
|
|
195
|
+
stdio: ["ignore", process.stderr, "pipe"],
|
|
196
|
+
});
|
|
197
|
+
process.stderr.write(recorded.stderr || "");
|
|
198
|
+
if (recorded.error || recorded.status !== 0) {
|
|
199
|
+
let disposal = "it was removed, so the installer can retry";
|
|
200
|
+
try {
|
|
201
|
+
fs.rmSync(binary, { force: true });
|
|
202
|
+
} catch (error) {
|
|
203
|
+
disposal = `it could not be removed (${error.message}), so delete ${binary} before retrying`;
|
|
204
|
+
}
|
|
205
|
+
const words = recorded.signal
|
|
206
|
+
? `signal ${recorded.signal}`
|
|
207
|
+
: recorded.error
|
|
208
|
+
? recorded.error.message
|
|
209
|
+
: `exit ${recorded.status}`;
|
|
210
|
+
fail(`the replaced executable could not record its lifecycle (${words}); ${disposal}`);
|
|
211
|
+
}
|
|
152
212
|
} finally {
|
|
153
213
|
fs.rmSync(staging, { recursive: true, force: true });
|
|
154
214
|
}
|
|
155
215
|
}
|
|
156
216
|
|
|
217
|
+
// What the launcher does about the binary already at the path, decided in one
|
|
218
|
+
// place: run it (`run`), keep it because it is newer (`keep-newer`), or install
|
|
219
|
+
// the release (`install`). A newer binary wins even when `ESTIGIA_VERSION` pins
|
|
220
|
+
// an older release, because the lifecycle refuses a downgrade machine-wide and
|
|
221
|
+
// the pinned archive would be rejected after the download; `docs/lifecycle.md`
|
|
222
|
+
// states that contract.
|
|
223
|
+
function plannedOutcome(installed, wanted) {
|
|
224
|
+
if (installed === wanted) {
|
|
225
|
+
return "run";
|
|
226
|
+
}
|
|
227
|
+
return isNewer(installed, wanted) ? "keep-newer" : "install";
|
|
228
|
+
}
|
|
229
|
+
|
|
157
230
|
async function main() {
|
|
158
231
|
const target = resolveTarget();
|
|
159
232
|
const { version } = require("../package.json");
|
|
160
233
|
const tag = process.env.ESTIGIA_VERSION || `v${version}`;
|
|
161
234
|
const binary = path.join(installDirectory(), target.exe);
|
|
162
235
|
|
|
163
|
-
|
|
236
|
+
const installed = installedVersion(binary);
|
|
237
|
+
const wanted = tag.replace(/^v/, "");
|
|
238
|
+
const outcome = plannedOutcome(installed, wanted);
|
|
239
|
+
if (outcome === "install") {
|
|
164
240
|
await install(tag, target, binary);
|
|
241
|
+
} else if (outcome === "keep-newer") {
|
|
242
|
+
say(`using the newer installed estigia ${installed} at ${binary}`);
|
|
165
243
|
}
|
|
166
244
|
|
|
167
245
|
const result = spawnSync(binary, process.argv.slice(2), { stdio: "inherit" });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asanabrial/estigia",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"mcpName": "io.github.asanabrial/estigia",
|
|
5
5
|
"description": "Guardrails for AI coding agents (Claude Code, Codex, OpenCode, Pi): an MCP server and hooks that verify issue claims, bind reviews to exact commits and gate merges",
|
|
6
6
|
"bin": {
|