create-snipara 2.2.15 → 2.2.17
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.js +127 -31
- package/dist/managed-toolchain.d.ts +20 -1
- package/dist/managed-toolchain.js +126 -29
- package/package.json +1 -2
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import { homedir as homedir2 } from "os";
|
|
|
14
14
|
// package.json
|
|
15
15
|
var package_default = {
|
|
16
16
|
name: "create-snipara",
|
|
17
|
-
version: "2.2.
|
|
17
|
+
version: "2.2.17",
|
|
18
18
|
description: "Onboard Snipara Cloud or self-hosted MCP with an automatic project-grounded proof of value",
|
|
19
19
|
main: "dist/index.js",
|
|
20
20
|
type: "module",
|
|
@@ -74,7 +74,6 @@ var package_default = {
|
|
|
74
74
|
},
|
|
75
75
|
devDependencies: {
|
|
76
76
|
"@eslint/js": "^9.39.3",
|
|
77
|
-
"@snipara/project-intelligence-contracts": "workspace:*",
|
|
78
77
|
"@types/node": "^20.17.12",
|
|
79
78
|
"@types/prompts": "^2.4.9",
|
|
80
79
|
"@typescript-eslint/eslint-plugin": "^8.56.0",
|
|
@@ -230,13 +229,16 @@ function assertManagedRuntimeVersions(nodeVersion, pythonVersion) {
|
|
|
230
229
|
const node = /^v?(\d+)\.\d+\.\d+(?:[-+].*)?$/.exec(nodeVersion);
|
|
231
230
|
const python = /^Python (\d+)\.(\d+)\.\d+(?:[a-z0-9.+-]*)?$/i.exec(pythonVersion.trim());
|
|
232
231
|
if (!node || Number(node[1]) < 18 || !python || Number(python[1]) !== 3 || Number(python[2]) < 10)
|
|
233
|
-
throw new Error(
|
|
232
|
+
throw new Error(
|
|
233
|
+
"Local work requires existing Node.js 18+ and Python 3.10+. Update your system runtimes and retry; no operating-system runtime was installed"
|
|
234
|
+
);
|
|
234
235
|
}
|
|
235
236
|
var ManagedInstallerCleanupError = class extends Error {
|
|
236
237
|
};
|
|
237
238
|
var sha = (bytes2) => createHash5("sha256").update(bytes2).digest("hex");
|
|
238
239
|
var uid = () => {
|
|
239
|
-
if (!process.getuid || process.platform === "win32")
|
|
240
|
+
if (!process.getuid || process.platform === "win32")
|
|
241
|
+
throw new Error("Managed local work requires macOS or Linux");
|
|
240
242
|
return process.getuid();
|
|
241
243
|
};
|
|
242
244
|
function exists(file) {
|
|
@@ -268,7 +270,10 @@ function location(options) {
|
|
|
268
270
|
}
|
|
269
271
|
function bytes(file, limit = 65536) {
|
|
270
272
|
owned(file, false);
|
|
271
|
-
const fd = fs.openSync(
|
|
273
|
+
const fd = fs.openSync(
|
|
274
|
+
file,
|
|
275
|
+
fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK
|
|
276
|
+
);
|
|
272
277
|
try {
|
|
273
278
|
const info = fs.fstatSync(fd);
|
|
274
279
|
if (!info.isFile() || info.uid !== uid() || info.size > limit || info.mode & 18)
|
|
@@ -286,7 +291,8 @@ function writePrivate(file, value) {
|
|
|
286
291
|
function protectedCommand(root, command) {
|
|
287
292
|
const real = fs.realpathSync(command);
|
|
288
293
|
if (!real.startsWith(root + path.sep)) throw new Error("Managed command escapes its bundle");
|
|
289
|
-
for (let current = path.dirname(real); current !== root; current = path.dirname(current))
|
|
294
|
+
for (let current = path.dirname(real); current !== root; current = path.dirname(current))
|
|
295
|
+
owned(current, true);
|
|
290
296
|
const info = owned(real, false);
|
|
291
297
|
if (!(info.mode & 73)) throw new Error("Managed command is not executable");
|
|
292
298
|
return real;
|
|
@@ -304,7 +310,8 @@ function readManagedManifest(file, options = {}) {
|
|
|
304
310
|
throw new Error("Managed manifest is outside the private installation");
|
|
305
311
|
const root = path.dirname(target);
|
|
306
312
|
owned(root, true, true);
|
|
307
|
-
if (fs.realpathSync(root) !== root)
|
|
313
|
+
if (fs.realpathSync(root) !== root)
|
|
314
|
+
throw new Error("Managed bundle cannot use linked directories");
|
|
308
315
|
owned(target, false, true);
|
|
309
316
|
const manifest = parseManagedToolchainManifest(JSON.parse(bytes(target).toString("utf8")));
|
|
310
317
|
if (manifest.root !== root || manifest.bundleId !== path.basename(root) || !manifest.capabilities.includes("validation") || !manifest.capabilities.includes("coordination"))
|
|
@@ -340,7 +347,11 @@ function verifyRetainedCompanionBootstrap(command, active, options = {}) {
|
|
|
340
347
|
function managedToolchainStatus(options = {}) {
|
|
341
348
|
const active = path.join(location(options), "active.json");
|
|
342
349
|
if (!exists(active)) return { status: "absent", manifest: null, manifestPath: null };
|
|
343
|
-
return {
|
|
350
|
+
return {
|
|
351
|
+
status: "ready",
|
|
352
|
+
manifest: readManagedManifest(active, options),
|
|
353
|
+
manifestPath: fs.realpathSync(active)
|
|
354
|
+
};
|
|
344
355
|
}
|
|
345
356
|
function program(name) {
|
|
346
357
|
for (const directory of (process.env.PATH ?? "").split(path.delimiter)) {
|
|
@@ -356,7 +367,13 @@ function program(name) {
|
|
|
356
367
|
}
|
|
357
368
|
function cleanEnvironment(root) {
|
|
358
369
|
return {
|
|
359
|
-
PATH: [
|
|
370
|
+
PATH: [
|
|
371
|
+
path.dirname(process.execPath),
|
|
372
|
+
"/usr/local/bin",
|
|
373
|
+
"/opt/homebrew/bin",
|
|
374
|
+
"/usr/bin",
|
|
375
|
+
"/bin"
|
|
376
|
+
].join(path.delimiter),
|
|
360
377
|
HOME: path.join(root, "home"),
|
|
361
378
|
TMPDIR: path.join(root, "tmp"),
|
|
362
379
|
LANG: "C.UTF-8",
|
|
@@ -366,8 +383,10 @@ function cleanEnvironment(root) {
|
|
|
366
383
|
PIP_DISABLE_PIP_VERSION_CHECK: "1",
|
|
367
384
|
PIP_NO_INPUT: "1",
|
|
368
385
|
PIP_CONFIG_FILE: "/dev/null",
|
|
369
|
-
|
|
370
|
-
|
|
386
|
+
// Two distinct absent files inside the private bundle: npm reads an absent config as empty,
|
|
387
|
+
// and refuses to start when the user and global configs are the same path (as two /dev/null were).
|
|
388
|
+
NPM_CONFIG_USERCONFIG: path.join(root, "home", ".npmrc"),
|
|
389
|
+
NPM_CONFIG_GLOBALCONFIG: path.join(root, "home", ".npmrc-global"),
|
|
371
390
|
NPM_CONFIG_IGNORE_SCRIPTS: "true",
|
|
372
391
|
NPM_CONFIG_AUDIT: "false",
|
|
373
392
|
NPM_CONFIG_FUND: "false",
|
|
@@ -408,11 +427,18 @@ var runManagedInstaller = async (input) => new Promise((resolve2, reject) => {
|
|
|
408
427
|
if (!stopped) {
|
|
409
428
|
stopped = true;
|
|
410
429
|
cleanup();
|
|
411
|
-
reject(
|
|
430
|
+
reject(
|
|
431
|
+
new ManagedInstallerCleanupError(
|
|
432
|
+
"Managed installer cleanup could not be observed within its deadline; installation lock retained"
|
|
433
|
+
)
|
|
434
|
+
);
|
|
412
435
|
}
|
|
413
436
|
}, 2e3);
|
|
414
437
|
};
|
|
415
|
-
const timer = setTimeout(
|
|
438
|
+
const timer = setTimeout(
|
|
439
|
+
() => stop("Managed preparation exceeded its bounded deadline"),
|
|
440
|
+
input.timeoutMs
|
|
441
|
+
);
|
|
416
442
|
process.on("SIGINT", interrupted);
|
|
417
443
|
process.on("SIGTERM", interrupted);
|
|
418
444
|
process.on("exit", exiting);
|
|
@@ -437,7 +463,10 @@ var runManagedInstaller = async (input) => new Promise((resolve2, reject) => {
|
|
|
437
463
|
if (stopped) return;
|
|
438
464
|
stopped = true;
|
|
439
465
|
if (stopReason) reject(new Error(stopReason));
|
|
440
|
-
else if (code !== 0)
|
|
466
|
+
else if (code !== 0)
|
|
467
|
+
reject(
|
|
468
|
+
new Error("Managed preparation step failed; the previous active bundle was preserved")
|
|
469
|
+
);
|
|
441
470
|
else resolve2({ stdout: output });
|
|
442
471
|
});
|
|
443
472
|
});
|
|
@@ -445,7 +474,8 @@ function switchPointer(base, name, target) {
|
|
|
445
474
|
const current = path.join(base, name);
|
|
446
475
|
if (exists(current)) {
|
|
447
476
|
const stat = fs.lstatSync(current);
|
|
448
|
-
if (!stat.isSymbolicLink() || stat.uid !== uid())
|
|
477
|
+
if (!stat.isSymbolicLink() || stat.uid !== uid())
|
|
478
|
+
throw new Error("Managed active pointer must be an owned symlink");
|
|
449
479
|
}
|
|
450
480
|
const temporary = path.join(base, `.pointer-${randomUUID2()}`);
|
|
451
481
|
fs.symlinkSync(target, temporary);
|
|
@@ -482,19 +512,25 @@ async function prepareManagedToolchain(options = {}) {
|
|
|
482
512
|
let recovery = null;
|
|
483
513
|
const preserveInvalidSelection = () => {
|
|
484
514
|
const pointer = fs.lstatSync(active);
|
|
485
|
-
if (!pointer.isSymbolicLink() || pointer.uid !== uid())
|
|
515
|
+
if (!pointer.isSymbolicLink() || pointer.uid !== uid())
|
|
516
|
+
throw new Error("Repair refuses a foreign or non-symlink active pointer");
|
|
486
517
|
const target = path.resolve(base, fs.readlinkSync(active));
|
|
487
518
|
if (path.basename(target) !== "toolchain.json" || path.dirname(path.dirname(target)) !== base)
|
|
488
519
|
throw new Error("Repair refuses an active pointer outside the owned installation");
|
|
489
520
|
const root2 = path.dirname(target);
|
|
490
521
|
owned(root2, true, true);
|
|
491
|
-
if (fs.realpathSync(root2) !== root2)
|
|
522
|
+
if (fs.realpathSync(root2) !== root2)
|
|
523
|
+
throw new Error("Repair refuses a linked bundle directory");
|
|
492
524
|
let previousHash = null;
|
|
493
525
|
if (exists(target)) {
|
|
494
526
|
owned(target, false, true);
|
|
495
527
|
previousHash = sha(bytes(target));
|
|
496
528
|
}
|
|
497
|
-
return {
|
|
529
|
+
return {
|
|
530
|
+
priorManifestPath: target,
|
|
531
|
+
priorManifestSha256: previousHash,
|
|
532
|
+
priorSelection: "invalid_owned_bundle"
|
|
533
|
+
};
|
|
498
534
|
};
|
|
499
535
|
if (exists(active)) {
|
|
500
536
|
try {
|
|
@@ -510,13 +546,24 @@ async function prepareManagedToolchain(options = {}) {
|
|
|
510
546
|
for (const [name, component] of Object.entries(manifest.components)) {
|
|
511
547
|
const command = name === "companion" ? process.execPath : component.command;
|
|
512
548
|
const args = name === "companion" ? [component.command, "--version"] : ["--version"];
|
|
513
|
-
const observed = await runner({
|
|
514
|
-
|
|
549
|
+
const observed = await runner({
|
|
550
|
+
command,
|
|
551
|
+
args,
|
|
552
|
+
cwd: manifest.root,
|
|
553
|
+
env: cleanEnvironment(manifest.root),
|
|
554
|
+
timeoutMs: 15e3
|
|
555
|
+
});
|
|
556
|
+
if (!new RegExp(
|
|
557
|
+
`^(?:snipara-${name}[ ,]+)?${component.version.replaceAll(".", "\\.")}$`,
|
|
558
|
+
"i"
|
|
559
|
+
).test(observed.stdout.trim()))
|
|
515
560
|
throw new Error("Managed component version handshake did not match the pinned bundle");
|
|
516
561
|
}
|
|
517
562
|
}
|
|
518
563
|
const selectedPrior = prior;
|
|
519
|
-
if (selectedPrior && Object.entries(MANAGED_VERSIONS).every(
|
|
564
|
+
if (selectedPrior && Object.entries(MANAGED_VERSIONS).every(
|
|
565
|
+
([name, version]) => selectedPrior.components[name].version === version
|
|
566
|
+
)) {
|
|
520
567
|
try {
|
|
521
568
|
await handshake(selectedPrior);
|
|
522
569
|
readManagedManifest(active, options);
|
|
@@ -530,27 +577,64 @@ async function prepareManagedToolchain(options = {}) {
|
|
|
530
577
|
const bundleId = `bundle-${MANAGED_VERSIONS.companion}-${MANAGED_VERSIONS.orchestrator}-${MANAGED_VERSIONS.sandbox}-${randomUUID2()}`;
|
|
531
578
|
const root = path.join(base, bundleId);
|
|
532
579
|
fs.mkdirSync(root, { mode: 448 });
|
|
533
|
-
for (const directory of ["home", "tmp"])
|
|
580
|
+
for (const directory of ["home", "tmp"])
|
|
581
|
+
fs.mkdirSync(path.join(root, directory), { mode: 448 });
|
|
534
582
|
const env = cleanEnvironment(root);
|
|
535
583
|
const run = (command, args, timeoutMs = 3e5) => runner({ command, args, cwd: root, env, timeoutMs });
|
|
536
584
|
try {
|
|
537
|
-
if (recovery)
|
|
585
|
+
if (recovery)
|
|
586
|
+
writePrivate(path.join(root, "recovery.json"), {
|
|
587
|
+
schemaVersion: "snipara.toolchain_recovery.v1",
|
|
588
|
+
...recovery,
|
|
589
|
+
originalBundlePreserved: true
|
|
590
|
+
});
|
|
538
591
|
const python = options.python ?? program("python3"), npm = options.npm ?? program("npm");
|
|
539
|
-
if (![python, npm].every((value) => path.isAbsolute(value)))
|
|
592
|
+
if (![python, npm].every((value) => path.isAbsolute(value)))
|
|
593
|
+
throw new Error("Managed package managers need absolute executable paths");
|
|
540
594
|
const runtime = await run(python, ["--version"], 1e4);
|
|
541
595
|
assertManagedRuntimeVersions(process.versions.node, runtime.stdout);
|
|
542
596
|
const venv = path.join(root, "python"), prefix = path.join(root, "node");
|
|
543
597
|
await run(python, ["-I", "-m", "venv", venv], 6e4);
|
|
544
|
-
await run(path.join(venv, "bin/python"), [
|
|
545
|
-
|
|
598
|
+
await run(path.join(venv, "bin/python"), [
|
|
599
|
+
"-I",
|
|
600
|
+
"-m",
|
|
601
|
+
"pip",
|
|
602
|
+
"install",
|
|
603
|
+
"--no-input",
|
|
604
|
+
"--disable-pip-version-check",
|
|
605
|
+
"snipara-sandbox[validation,mcp]==" + MANAGED_VERSIONS.sandbox,
|
|
606
|
+
"snipara-orchestrator==" + MANAGED_VERSIONS.orchestrator
|
|
607
|
+
]);
|
|
608
|
+
await run(npm, [
|
|
609
|
+
"install",
|
|
610
|
+
"--prefix",
|
|
611
|
+
prefix,
|
|
612
|
+
"--ignore-scripts",
|
|
613
|
+
"--no-audit",
|
|
614
|
+
"--no-fund",
|
|
615
|
+
"--save-exact",
|
|
616
|
+
"snipara-companion@" + MANAGED_VERSIONS.companion
|
|
617
|
+
]);
|
|
546
618
|
const manifest = {
|
|
547
619
|
schemaVersion: "snipara.toolchain.v1",
|
|
548
620
|
bundleId,
|
|
549
621
|
root,
|
|
550
622
|
components: {
|
|
551
|
-
companion: {
|
|
552
|
-
|
|
553
|
-
|
|
623
|
+
companion: {
|
|
624
|
+
version: MANAGED_VERSIONS.companion,
|
|
625
|
+
command: fs.realpathSync(path.join(prefix, "node_modules/.bin/snipara-companion")),
|
|
626
|
+
sha256: ""
|
|
627
|
+
},
|
|
628
|
+
orchestrator: {
|
|
629
|
+
version: MANAGED_VERSIONS.orchestrator,
|
|
630
|
+
command: path.join(venv, "bin/snipara-orchestrator"),
|
|
631
|
+
sha256: ""
|
|
632
|
+
},
|
|
633
|
+
sandbox: {
|
|
634
|
+
version: MANAGED_VERSIONS.sandbox,
|
|
635
|
+
command: path.join(venv, "bin/snipara-sandbox"),
|
|
636
|
+
sha256: ""
|
|
637
|
+
}
|
|
554
638
|
},
|
|
555
639
|
contracts: { taskReference: 1, validation: 1 },
|
|
556
640
|
capabilities: ["validation", "coordination"]
|
|
@@ -563,12 +647,24 @@ async function prepareManagedToolchain(options = {}) {
|
|
|
563
647
|
writePrivate(manifestFile, parseManagedToolchainManifest(manifest));
|
|
564
648
|
await handshake(manifest);
|
|
565
649
|
readManagedManifest(manifestFile, options);
|
|
566
|
-
writePrivate(path.join(root, "prepared.json"), {
|
|
650
|
+
writePrivate(path.join(root, "prepared.json"), {
|
|
651
|
+
schemaVersion: "snipara.toolchain_preparation.v1",
|
|
652
|
+
status: "prepared",
|
|
653
|
+
manifestSha256: sha(bytes(manifestFile)),
|
|
654
|
+
observedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
655
|
+
activationObserved: false
|
|
656
|
+
});
|
|
567
657
|
if (prior) switchPointer(base, "previous.json", path.join(prior.root, "toolchain.json"));
|
|
568
658
|
switchPointer(base, "active.json", manifestFile);
|
|
569
659
|
return manifest;
|
|
570
660
|
} catch (error) {
|
|
571
|
-
writePrivate(path.join(root, "failed.json"), {
|
|
661
|
+
writePrivate(path.join(root, "failed.json"), {
|
|
662
|
+
schemaVersion: "snipara.toolchain_preparation.v1",
|
|
663
|
+
status: "failed",
|
|
664
|
+
observedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
665
|
+
reason: "preparation_or_identity_check_failed",
|
|
666
|
+
priorActivePreserved: true
|
|
667
|
+
});
|
|
572
668
|
throw error;
|
|
573
669
|
}
|
|
574
670
|
});
|
|
@@ -1,4 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
/** Shared data contract only. Filesystem trust and execution belong to consumers. */
|
|
2
|
+
declare const MANAGED_TOOLCHAIN_VERSION: "snipara.toolchain.v1";
|
|
3
|
+
declare const MANAGED_TOOLCHAIN_COMPONENTS: readonly ["companion", "orchestrator", "sandbox"];
|
|
4
|
+
type ManagedToolchainComponentName = typeof MANAGED_TOOLCHAIN_COMPONENTS[number];
|
|
5
|
+
interface ManagedToolchainComponent {
|
|
6
|
+
version: string;
|
|
7
|
+
command: string;
|
|
8
|
+
sha256: string;
|
|
9
|
+
}
|
|
10
|
+
interface ManagedToolchainManifest {
|
|
11
|
+
schemaVersion: typeof MANAGED_TOOLCHAIN_VERSION;
|
|
12
|
+
bundleId: string;
|
|
13
|
+
root: string;
|
|
14
|
+
components: Record<ManagedToolchainComponentName, ManagedToolchainComponent>;
|
|
15
|
+
contracts: {
|
|
16
|
+
taskReference: 1;
|
|
17
|
+
validation: 1;
|
|
18
|
+
};
|
|
19
|
+
capabilities: string[];
|
|
20
|
+
}
|
|
2
21
|
|
|
3
22
|
declare const MANAGED_VERSIONS: Readonly<{
|
|
4
23
|
companion: string;
|
|
@@ -137,13 +137,16 @@ function assertManagedRuntimeVersions(nodeVersion, pythonVersion) {
|
|
|
137
137
|
const node = /^v?(\d+)\.\d+\.\d+(?:[-+].*)?$/.exec(nodeVersion);
|
|
138
138
|
const python = /^Python (\d+)\.(\d+)\.\d+(?:[a-z0-9.+-]*)?$/i.exec(pythonVersion.trim());
|
|
139
139
|
if (!node || Number(node[1]) < 18 || !python || Number(python[1]) !== 3 || Number(python[2]) < 10)
|
|
140
|
-
throw new Error(
|
|
140
|
+
throw new Error(
|
|
141
|
+
"Local work requires existing Node.js 18+ and Python 3.10+. Update your system runtimes and retry; no operating-system runtime was installed"
|
|
142
|
+
);
|
|
141
143
|
}
|
|
142
144
|
var ManagedInstallerCleanupError = class extends Error {
|
|
143
145
|
};
|
|
144
146
|
var sha = (bytes2) => createHash5("sha256").update(bytes2).digest("hex");
|
|
145
147
|
var uid = () => {
|
|
146
|
-
if (!process.getuid || process.platform === "win32")
|
|
148
|
+
if (!process.getuid || process.platform === "win32")
|
|
149
|
+
throw new Error("Managed local work requires macOS or Linux");
|
|
147
150
|
return process.getuid();
|
|
148
151
|
};
|
|
149
152
|
function exists(file) {
|
|
@@ -175,7 +178,10 @@ function location(options) {
|
|
|
175
178
|
}
|
|
176
179
|
function bytes(file, limit = 65536) {
|
|
177
180
|
owned(file, false);
|
|
178
|
-
const fd = fs.openSync(
|
|
181
|
+
const fd = fs.openSync(
|
|
182
|
+
file,
|
|
183
|
+
fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK
|
|
184
|
+
);
|
|
179
185
|
try {
|
|
180
186
|
const info = fs.fstatSync(fd);
|
|
181
187
|
if (!info.isFile() || info.uid !== uid() || info.size > limit || info.mode & 18)
|
|
@@ -193,7 +199,8 @@ function writePrivate(file, value) {
|
|
|
193
199
|
function protectedCommand(root, command) {
|
|
194
200
|
const real = fs.realpathSync(command);
|
|
195
201
|
if (!real.startsWith(root + path.sep)) throw new Error("Managed command escapes its bundle");
|
|
196
|
-
for (let current = path.dirname(real); current !== root; current = path.dirname(current))
|
|
202
|
+
for (let current = path.dirname(real); current !== root; current = path.dirname(current))
|
|
203
|
+
owned(current, true);
|
|
197
204
|
const info = owned(real, false);
|
|
198
205
|
if (!(info.mode & 73)) throw new Error("Managed command is not executable");
|
|
199
206
|
return real;
|
|
@@ -211,7 +218,8 @@ function readManagedManifest(file, options = {}) {
|
|
|
211
218
|
throw new Error("Managed manifest is outside the private installation");
|
|
212
219
|
const root = path.dirname(target);
|
|
213
220
|
owned(root, true, true);
|
|
214
|
-
if (fs.realpathSync(root) !== root)
|
|
221
|
+
if (fs.realpathSync(root) !== root)
|
|
222
|
+
throw new Error("Managed bundle cannot use linked directories");
|
|
215
223
|
owned(target, false, true);
|
|
216
224
|
const manifest = parseManagedToolchainManifest(JSON.parse(bytes(target).toString("utf8")));
|
|
217
225
|
if (manifest.root !== root || manifest.bundleId !== path.basename(root) || !manifest.capabilities.includes("validation") || !manifest.capabilities.includes("coordination"))
|
|
@@ -247,7 +255,11 @@ function verifyRetainedCompanionBootstrap(command, active, options = {}) {
|
|
|
247
255
|
function managedToolchainStatus(options = {}) {
|
|
248
256
|
const active = path.join(location(options), "active.json");
|
|
249
257
|
if (!exists(active)) return { status: "absent", manifest: null, manifestPath: null };
|
|
250
|
-
return {
|
|
258
|
+
return {
|
|
259
|
+
status: "ready",
|
|
260
|
+
manifest: readManagedManifest(active, options),
|
|
261
|
+
manifestPath: fs.realpathSync(active)
|
|
262
|
+
};
|
|
251
263
|
}
|
|
252
264
|
function program(name) {
|
|
253
265
|
for (const directory of (process.env.PATH ?? "").split(path.delimiter)) {
|
|
@@ -263,7 +275,13 @@ function program(name) {
|
|
|
263
275
|
}
|
|
264
276
|
function cleanEnvironment(root) {
|
|
265
277
|
return {
|
|
266
|
-
PATH: [
|
|
278
|
+
PATH: [
|
|
279
|
+
path.dirname(process.execPath),
|
|
280
|
+
"/usr/local/bin",
|
|
281
|
+
"/opt/homebrew/bin",
|
|
282
|
+
"/usr/bin",
|
|
283
|
+
"/bin"
|
|
284
|
+
].join(path.delimiter),
|
|
267
285
|
HOME: path.join(root, "home"),
|
|
268
286
|
TMPDIR: path.join(root, "tmp"),
|
|
269
287
|
LANG: "C.UTF-8",
|
|
@@ -273,8 +291,10 @@ function cleanEnvironment(root) {
|
|
|
273
291
|
PIP_DISABLE_PIP_VERSION_CHECK: "1",
|
|
274
292
|
PIP_NO_INPUT: "1",
|
|
275
293
|
PIP_CONFIG_FILE: "/dev/null",
|
|
276
|
-
|
|
277
|
-
|
|
294
|
+
// Two distinct absent files inside the private bundle: npm reads an absent config as empty,
|
|
295
|
+
// and refuses to start when the user and global configs are the same path (as two /dev/null were).
|
|
296
|
+
NPM_CONFIG_USERCONFIG: path.join(root, "home", ".npmrc"),
|
|
297
|
+
NPM_CONFIG_GLOBALCONFIG: path.join(root, "home", ".npmrc-global"),
|
|
278
298
|
NPM_CONFIG_IGNORE_SCRIPTS: "true",
|
|
279
299
|
NPM_CONFIG_AUDIT: "false",
|
|
280
300
|
NPM_CONFIG_FUND: "false",
|
|
@@ -315,11 +335,18 @@ var runManagedInstaller = async (input) => new Promise((resolve, reject) => {
|
|
|
315
335
|
if (!stopped) {
|
|
316
336
|
stopped = true;
|
|
317
337
|
cleanup();
|
|
318
|
-
reject(
|
|
338
|
+
reject(
|
|
339
|
+
new ManagedInstallerCleanupError(
|
|
340
|
+
"Managed installer cleanup could not be observed within its deadline; installation lock retained"
|
|
341
|
+
)
|
|
342
|
+
);
|
|
319
343
|
}
|
|
320
344
|
}, 2e3);
|
|
321
345
|
};
|
|
322
|
-
const timer = setTimeout(
|
|
346
|
+
const timer = setTimeout(
|
|
347
|
+
() => stop("Managed preparation exceeded its bounded deadline"),
|
|
348
|
+
input.timeoutMs
|
|
349
|
+
);
|
|
323
350
|
process.on("SIGINT", interrupted);
|
|
324
351
|
process.on("SIGTERM", interrupted);
|
|
325
352
|
process.on("exit", exiting);
|
|
@@ -344,7 +371,10 @@ var runManagedInstaller = async (input) => new Promise((resolve, reject) => {
|
|
|
344
371
|
if (stopped) return;
|
|
345
372
|
stopped = true;
|
|
346
373
|
if (stopReason) reject(new Error(stopReason));
|
|
347
|
-
else if (code !== 0)
|
|
374
|
+
else if (code !== 0)
|
|
375
|
+
reject(
|
|
376
|
+
new Error("Managed preparation step failed; the previous active bundle was preserved")
|
|
377
|
+
);
|
|
348
378
|
else resolve({ stdout: output });
|
|
349
379
|
});
|
|
350
380
|
});
|
|
@@ -352,7 +382,8 @@ function switchPointer(base, name, target) {
|
|
|
352
382
|
const current = path.join(base, name);
|
|
353
383
|
if (exists(current)) {
|
|
354
384
|
const stat = fs.lstatSync(current);
|
|
355
|
-
if (!stat.isSymbolicLink() || stat.uid !== uid())
|
|
385
|
+
if (!stat.isSymbolicLink() || stat.uid !== uid())
|
|
386
|
+
throw new Error("Managed active pointer must be an owned symlink");
|
|
356
387
|
}
|
|
357
388
|
const temporary = path.join(base, `.pointer-${randomUUID2()}`);
|
|
358
389
|
fs.symlinkSync(target, temporary);
|
|
@@ -389,19 +420,25 @@ async function prepareManagedToolchain(options = {}) {
|
|
|
389
420
|
let recovery = null;
|
|
390
421
|
const preserveInvalidSelection = () => {
|
|
391
422
|
const pointer = fs.lstatSync(active);
|
|
392
|
-
if (!pointer.isSymbolicLink() || pointer.uid !== uid())
|
|
423
|
+
if (!pointer.isSymbolicLink() || pointer.uid !== uid())
|
|
424
|
+
throw new Error("Repair refuses a foreign or non-symlink active pointer");
|
|
393
425
|
const target = path.resolve(base, fs.readlinkSync(active));
|
|
394
426
|
if (path.basename(target) !== "toolchain.json" || path.dirname(path.dirname(target)) !== base)
|
|
395
427
|
throw new Error("Repair refuses an active pointer outside the owned installation");
|
|
396
428
|
const root2 = path.dirname(target);
|
|
397
429
|
owned(root2, true, true);
|
|
398
|
-
if (fs.realpathSync(root2) !== root2)
|
|
430
|
+
if (fs.realpathSync(root2) !== root2)
|
|
431
|
+
throw new Error("Repair refuses a linked bundle directory");
|
|
399
432
|
let previousHash = null;
|
|
400
433
|
if (exists(target)) {
|
|
401
434
|
owned(target, false, true);
|
|
402
435
|
previousHash = sha(bytes(target));
|
|
403
436
|
}
|
|
404
|
-
return {
|
|
437
|
+
return {
|
|
438
|
+
priorManifestPath: target,
|
|
439
|
+
priorManifestSha256: previousHash,
|
|
440
|
+
priorSelection: "invalid_owned_bundle"
|
|
441
|
+
};
|
|
405
442
|
};
|
|
406
443
|
if (exists(active)) {
|
|
407
444
|
try {
|
|
@@ -417,13 +454,24 @@ async function prepareManagedToolchain(options = {}) {
|
|
|
417
454
|
for (const [name, component] of Object.entries(manifest.components)) {
|
|
418
455
|
const command = name === "companion" ? process.execPath : component.command;
|
|
419
456
|
const args = name === "companion" ? [component.command, "--version"] : ["--version"];
|
|
420
|
-
const observed = await runner({
|
|
421
|
-
|
|
457
|
+
const observed = await runner({
|
|
458
|
+
command,
|
|
459
|
+
args,
|
|
460
|
+
cwd: manifest.root,
|
|
461
|
+
env: cleanEnvironment(manifest.root),
|
|
462
|
+
timeoutMs: 15e3
|
|
463
|
+
});
|
|
464
|
+
if (!new RegExp(
|
|
465
|
+
`^(?:snipara-${name}[ ,]+)?${component.version.replaceAll(".", "\\.")}$`,
|
|
466
|
+
"i"
|
|
467
|
+
).test(observed.stdout.trim()))
|
|
422
468
|
throw new Error("Managed component version handshake did not match the pinned bundle");
|
|
423
469
|
}
|
|
424
470
|
}
|
|
425
471
|
const selectedPrior = prior;
|
|
426
|
-
if (selectedPrior && Object.entries(MANAGED_VERSIONS).every(
|
|
472
|
+
if (selectedPrior && Object.entries(MANAGED_VERSIONS).every(
|
|
473
|
+
([name, version]) => selectedPrior.components[name].version === version
|
|
474
|
+
)) {
|
|
427
475
|
try {
|
|
428
476
|
await handshake(selectedPrior);
|
|
429
477
|
readManagedManifest(active, options);
|
|
@@ -437,27 +485,64 @@ async function prepareManagedToolchain(options = {}) {
|
|
|
437
485
|
const bundleId = `bundle-${MANAGED_VERSIONS.companion}-${MANAGED_VERSIONS.orchestrator}-${MANAGED_VERSIONS.sandbox}-${randomUUID2()}`;
|
|
438
486
|
const root = path.join(base, bundleId);
|
|
439
487
|
fs.mkdirSync(root, { mode: 448 });
|
|
440
|
-
for (const directory of ["home", "tmp"])
|
|
488
|
+
for (const directory of ["home", "tmp"])
|
|
489
|
+
fs.mkdirSync(path.join(root, directory), { mode: 448 });
|
|
441
490
|
const env = cleanEnvironment(root);
|
|
442
491
|
const run = (command, args, timeoutMs = 3e5) => runner({ command, args, cwd: root, env, timeoutMs });
|
|
443
492
|
try {
|
|
444
|
-
if (recovery)
|
|
493
|
+
if (recovery)
|
|
494
|
+
writePrivate(path.join(root, "recovery.json"), {
|
|
495
|
+
schemaVersion: "snipara.toolchain_recovery.v1",
|
|
496
|
+
...recovery,
|
|
497
|
+
originalBundlePreserved: true
|
|
498
|
+
});
|
|
445
499
|
const python = options.python ?? program("python3"), npm = options.npm ?? program("npm");
|
|
446
|
-
if (![python, npm].every((value) => path.isAbsolute(value)))
|
|
500
|
+
if (![python, npm].every((value) => path.isAbsolute(value)))
|
|
501
|
+
throw new Error("Managed package managers need absolute executable paths");
|
|
447
502
|
const runtime = await run(python, ["--version"], 1e4);
|
|
448
503
|
assertManagedRuntimeVersions(process.versions.node, runtime.stdout);
|
|
449
504
|
const venv = path.join(root, "python"), prefix = path.join(root, "node");
|
|
450
505
|
await run(python, ["-I", "-m", "venv", venv], 6e4);
|
|
451
|
-
await run(path.join(venv, "bin/python"), [
|
|
452
|
-
|
|
506
|
+
await run(path.join(venv, "bin/python"), [
|
|
507
|
+
"-I",
|
|
508
|
+
"-m",
|
|
509
|
+
"pip",
|
|
510
|
+
"install",
|
|
511
|
+
"--no-input",
|
|
512
|
+
"--disable-pip-version-check",
|
|
513
|
+
"snipara-sandbox[validation,mcp]==" + MANAGED_VERSIONS.sandbox,
|
|
514
|
+
"snipara-orchestrator==" + MANAGED_VERSIONS.orchestrator
|
|
515
|
+
]);
|
|
516
|
+
await run(npm, [
|
|
517
|
+
"install",
|
|
518
|
+
"--prefix",
|
|
519
|
+
prefix,
|
|
520
|
+
"--ignore-scripts",
|
|
521
|
+
"--no-audit",
|
|
522
|
+
"--no-fund",
|
|
523
|
+
"--save-exact",
|
|
524
|
+
"snipara-companion@" + MANAGED_VERSIONS.companion
|
|
525
|
+
]);
|
|
453
526
|
const manifest = {
|
|
454
527
|
schemaVersion: "snipara.toolchain.v1",
|
|
455
528
|
bundleId,
|
|
456
529
|
root,
|
|
457
530
|
components: {
|
|
458
|
-
companion: {
|
|
459
|
-
|
|
460
|
-
|
|
531
|
+
companion: {
|
|
532
|
+
version: MANAGED_VERSIONS.companion,
|
|
533
|
+
command: fs.realpathSync(path.join(prefix, "node_modules/.bin/snipara-companion")),
|
|
534
|
+
sha256: ""
|
|
535
|
+
},
|
|
536
|
+
orchestrator: {
|
|
537
|
+
version: MANAGED_VERSIONS.orchestrator,
|
|
538
|
+
command: path.join(venv, "bin/snipara-orchestrator"),
|
|
539
|
+
sha256: ""
|
|
540
|
+
},
|
|
541
|
+
sandbox: {
|
|
542
|
+
version: MANAGED_VERSIONS.sandbox,
|
|
543
|
+
command: path.join(venv, "bin/snipara-sandbox"),
|
|
544
|
+
sha256: ""
|
|
545
|
+
}
|
|
461
546
|
},
|
|
462
547
|
contracts: { taskReference: 1, validation: 1 },
|
|
463
548
|
capabilities: ["validation", "coordination"]
|
|
@@ -470,12 +555,24 @@ async function prepareManagedToolchain(options = {}) {
|
|
|
470
555
|
writePrivate(manifestFile, parseManagedToolchainManifest(manifest));
|
|
471
556
|
await handshake(manifest);
|
|
472
557
|
readManagedManifest(manifestFile, options);
|
|
473
|
-
writePrivate(path.join(root, "prepared.json"), {
|
|
558
|
+
writePrivate(path.join(root, "prepared.json"), {
|
|
559
|
+
schemaVersion: "snipara.toolchain_preparation.v1",
|
|
560
|
+
status: "prepared",
|
|
561
|
+
manifestSha256: sha(bytes(manifestFile)),
|
|
562
|
+
observedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
563
|
+
activationObserved: false
|
|
564
|
+
});
|
|
474
565
|
if (prior) switchPointer(base, "previous.json", path.join(prior.root, "toolchain.json"));
|
|
475
566
|
switchPointer(base, "active.json", manifestFile);
|
|
476
567
|
return manifest;
|
|
477
568
|
} catch (error) {
|
|
478
|
-
writePrivate(path.join(root, "failed.json"), {
|
|
569
|
+
writePrivate(path.join(root, "failed.json"), {
|
|
570
|
+
schemaVersion: "snipara.toolchain_preparation.v1",
|
|
571
|
+
status: "failed",
|
|
572
|
+
observedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
573
|
+
reason: "preparation_or_identity_check_failed",
|
|
574
|
+
priorActivePreserved: true
|
|
575
|
+
});
|
|
479
576
|
throw error;
|
|
480
577
|
}
|
|
481
578
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-snipara",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.17",
|
|
4
4
|
"description": "Onboard Snipara Cloud or self-hosted MCP with an automatic project-grounded proof of value",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -60,7 +60,6 @@
|
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@eslint/js": "^9.39.3",
|
|
63
|
-
"@snipara/project-intelligence-contracts": "workspace:*",
|
|
64
63
|
"@types/node": "^20.17.12",
|
|
65
64
|
"@types/prompts": "^2.4.9",
|
|
66
65
|
"@typescript-eslint/eslint-plugin": "^8.56.0",
|