UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

101 lines 2.98 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildProvenance = buildProvenance; const node_child_process_1 = require("node:child_process"); const node_os_1 = __importDefault(require("node:os")); function detectCi() { const env = process.env; if (env.GITHUB_ACTIONS) { return { provider: 'github' }; } if (env.GITLAB_CI) { return { provider: 'gitlab' }; } if (env.CIRCLECI) { return { provider: 'circle' }; } if (env.BUILDKITE) { return { provider: 'buildkite' }; } if (env.JENKINS_URL) { return { provider: 'jenkins' }; } if (env.TF_BUILD) { return { provider: 'azure-pipelines' }; } if (env.BITBUCKET_BUILD_NUMBER) { return { provider: 'bitbucket' }; } if (env.TRAVIS) { return { provider: 'travis' }; } if (env.CI === 'true' || env.CI === '1') { return {}; } return undefined; } function detectGit() { const opts = { timeout: 500, stdio: ['ignore', 'pipe', 'ignore'], encoding: 'utf8', windowsHide: true, }; let sha; try { sha = (0, node_child_process_1.execFileSync)('git', ['rev-parse', 'HEAD'], opts).trim() || undefined; } catch { // Not a git repo, git missing, or timed out — nothing useful to report. return undefined; } let branch; try { const raw = (0, node_child_process_1.execFileSync)('git', ['rev-parse', '--abbrev-ref', 'HEAD'], opts).trim(); branch = raw && raw !== 'HEAD' ? raw : undefined; } catch { /* leave undefined */ } let dirty; try { const status = (0, node_child_process_1.execFileSync)('git', ['status', '--porcelain'], opts); dirty = status.length > 0; } catch { /* leave undefined */ } return { sha, branch, dirty }; } function buildProvenance(source) { let user; let hostname; try { user = node_os_1.default.userInfo().username; } catch { // os.userInfo() can throw in containerised envs with no passwd entry. } try { hostname = node_os_1.default.hostname() || undefined; } catch { // Defensive: hostname() is documented to throw only on rare libuv errors. } // CI and git context only make sense for CODE-source entities — they // describe the user's project environment, not Studio's own runtime. Skip // both for DONOBU_STUDIO to avoid the `git` shell-outs on every create. const isCode = source === 'CODE'; return { source, user, os: process.platform, hostname, ci: isCode ? detectCi() : undefined, git: isCode ? detectGit() : undefined, }; } //# sourceMappingURL=buildProvenance.js.map