Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

Merge branch 'feat/p2-ci-lint-termux' into release/1.3.1-p2

Salman Qureshi7d8bcac19780
diff --cc .github/workflows/ci.yml
index fc557cc7,7115fbd8..20abb740
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@@ -33,6 -37,27 +37,30 @@@ jobs
- run: npm ci
- run: npm run typecheck
+ lint:
+ name: Lint (tsc + ESLint ratchet)
++ # Provisional baseline (grep estimate): non-blocking until the first real
++ # run refreshes .lint-baseline.json with `npm run lint:ratchet -- --update`.
++ continue-on-error: true
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 22
+ cache: npm
+ - run: npm ci
+ - run: npm run lint
+ # ESLint is pinned here rather than in package.json/package-lock.json so
+ # `npm ci` in every other job is untouched. Move these into
+ # devDependencies (and regenerate the lockfile) once the baseline is real.
+ - name: Install ESLint (pinned, not saved)
+ run: npm install --no-save --no-audit --no-fund [email protected] @eslint/[email protected] [email protected]
+ # Ratchet: per-rule counts may only go down relative to .lint-baseline.json.
+ # Refresh the baseline with `npm run lint:ratchet -- --update` after a
+ # deliberate clean-up (or on the first run, when the baseline is provisional).
+ - run: npm run lint:ratchet
+
test:
name: Test (Node ${{ matrix.node }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
@@@ -58,21 -85,24 +88,39 @@@
- run: npm run build
- run: npm test
+ eval:
+ # Replay-based eval harness (ROADMAP P2.3): drives the real agent loop
+ # with scripted providers and recorded tool outputs. No network, no keys.
+ name: Eval harness (Node 22, ubuntu)
+ runs-on: ubuntu-latest
+ timeout-minutes: 5
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 22
+ cache: npm
+ - run: npm ci
+ - run: npm run eval
+
+ linux-arm64:
+ name: Typecheck & Test (Node 22, linux-arm64)
+ # GitHub-hosted arm64 runners (`ubuntu-24.04-arm`) are free for public
+ # repos but not enabled in every org. Until a green run proves they are
+ # available here, a missing runner must not block the pipeline.
+ runs-on: ubuntu-24.04-arm
+ continue-on-error: true
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 22
+ cache: npm
+ - run: npm ci
+ - run: npm run typecheck
+ - run: npm run build
+ - run: npm test
+
pack-verify:
name: Pack & Verify (Node ${{ matrix.node }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
@@@ -98,9 -128,213 +146,216 @@@
- name: Verify package integrity
run: node scripts/verify-package.cjs
+ - name: Verify vendor/ink is stock ink 5.2.1 + the patch set (ADR-017)
+ run: node scripts/vendor-ink.cjs --check
+
+ binary-smoke:
+ name: Binary smoke (${{ matrix.os }})
+ runs-on: ${{ matrix.os }}
+ timeout-minutes: 12
+ strategy:
+ fail-fast: false
+ matrix:
+ os: [ubuntu-latest, macos-latest, windows-latest]
+ env:
+ # Keep the smoke binary's state out of the runner's real home.
+ MERCURY_HOME: ${{ github.workspace }}/.smoke-home
+ # chalk forces colour on GitHub Actions; the greps below want plain text.
+ FORCE_COLOR: '0'
+ NO_COLOR: '1'
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 22
+ cache: npm
+ - uses: oven-sh/setup-bun@v2
+ with:
+ bun-version: latest
+ - run: npm ci
+ - run: npm run build
+
+ - name: Build host binary (release/smoke, never published)
+ run: node scripts/build-bin.cjs --host-only
+
+ - name: Locate binary
+ id: bin
+ shell: bash
+ run: |
+ set -euo pipefail
+ bin=$(find release/smoke -maxdepth 2 -type f -name 'mercury-*' ! -name '*.tar.gz' | head -n 1)
+ test -n "$bin" || { echo "::error::no host binary found under release/smoke"; ls -R release; exit 1; }
+ ls -l "$bin"
+ echo "path=$bin" >> "$GITHUB_OUTPUT"
+
+ - name: Smoke --version
+ shell: bash
+ run: |
+ set -euo pipefail
+ expected=$(node -p "require('./package.json').version")
+ out=$("${{ steps.bin.outputs.path }}" --version)
+ echo "--version → $out"
+ [ "$out" = "$expected" ] || { echo "::error::--version printed '$out', expected '$expected'"; exit 1; }
+
+ - name: Smoke --help
+ shell: bash
+ run: |
+ set -euo pipefail
+ "${{ steps.bin.outputs.path }}" --help | tee smoke-help.txt
+ grep -q 'Usage:' smoke-help.txt
+
+ - name: Smoke doctor --platform
+ shell: bash
+ run: |
+ set -euo pipefail
+ "${{ steps.bin.outputs.path }}" doctor --platform | tee smoke-platform.txt
+ grep -q 'Mercury Platform Doctor' smoke-platform.txt
+
+ - name: Smoke doctor --storage (bun:sqlite must be active)
+ shell: bash
+ run: |
+ set -euo pipefail
+ "${{ steps.bin.outputs.path }}" doctor --storage | sed 's/\x1b\[[0-9;]*m//g' | tee smoke-storage.txt
+ # The standalone binary ships Bun's embedded SQLite. A JSON-only
+ # report here means the driver fell through every backend.
+ if grep -Eq 'SQLite backend: +bun:sqlite' smoke-storage.txt; then
+ echo "bun:sqlite active"
+ else
+ echo "::error::doctor --storage did not report bun:sqlite as the active backend"
+ exit 1
+ fi
+ if grep -q 'JSON-only' smoke-storage.txt; then
+ echo "::error::doctor --storage reports JSON-only storage"
+ exit 1
+ fi
+
+ - name: Upload smoke logs
+ if: always()
+ uses: actions/upload-artifact@v4
+ with:
+ name: binary-smoke-${{ matrix.os }}
+ path: smoke-*.txt
+ retention-days: 1
+ if-no-files-found: ignore
+
+ script-lint:
+ name: Scripts (shellcheck + PSScriptAnalyzer)
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: shellcheck
+ run: |
+ set -euo pipefail
+ shellcheck --version
+ shellcheck scripts/install.sh scripts/install-dev.sh scripts/publish*.sh
+
+ - name: Install PSScriptAnalyzer
+ shell: pwsh
+ run: |
+ Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
+ Install-Module -Name PSScriptAnalyzer -Scope CurrentUser -Force -ErrorAction Stop
+ Import-Module PSScriptAnalyzer
+ (Get-Module PSScriptAnalyzer).Version
+
+ - name: Invoke-ScriptAnalyzer scripts/*.ps1
+ shell: pwsh
+ run: |
+ $results = @(Get-ChildItem scripts -Filter *.ps1 | ForEach-Object {
+ Invoke-ScriptAnalyzer -Path $_.FullName -Severity Error,Warning
+ })
+ foreach ($r in $results) {
+ $level = if ($r.Severity -eq 'Error') { 'error' } else { 'warning' }
+ Write-Output "::$level file=$($r.ScriptPath),line=$($r.Line)::[$($r.RuleName)] $($r.Message)"
+ }
+ $errors = @($results | Where-Object Severity -eq 'Error')
+ Write-Output "PSScriptAnalyzer: $($results.Count) finding(s), $($errors.Count) error(s)"
+ # Warnings (Write-Host, Invoke-Expression, ShouldProcess) are expected
+ # in a curl|iex-style installer and are surfaced as annotations only.
+ if ($errors.Count -gt 0) { exit 1 }
+
+ installer-smoke:
+ name: Installer dry run (install.sh against a local release dir)
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Build a fake release directory
+ run: |
+ set -euo pipefail
+ version=9.9.9
+ rel="$RUNNER_TEMP/fake-release/v$version"
+ mkdir -p "$rel/web"
+ # A tiny stub "binary": enough to pass the installer's --version smoke.
+ cat > "$rel/mercury-linux-x64" <<'STUB'
+ #!/bin/sh
+ if [ "${1:-}" = "--version" ]; then echo "9.9.9"; exit 0; fi
+ echo "mercury stub: $*"
+ STUB
+ chmod +x "$rel/mercury-linux-x64"
+ echo '<!doctype html><title>stub dashboard</title>' > "$rel/web/index.html"
+ tar -C "$rel" -czf "$rel/web.tar.gz" web
+ (cd "$rel" && sha256sum mercury-linux-x64 web.tar.gz > checksums.txt)
+ cat "$rel/checksums.txt"
+ echo "REL_ROOT=$RUNNER_TEMP/fake-release" >> "$GITHUB_ENV"
+
+ - name: Serve it over HTTP
+ run: |
+ set -euo pipefail
+ (cd "$REL_ROOT" && python3 -m http.server 8765 --bind 127.0.0.1 > "$RUNNER_TEMP/http.log" 2>&1 &)
+ for _ in $(seq 1 30); do
+ curl -fsS http://127.0.0.1:8765/v9.9.9/checksums.txt > /dev/null && break
+ sleep 0.5
+ done
+ curl -fsS http://127.0.0.1:8765/v9.9.9/checksums.txt
+
+ - name: Run install.sh against the local release dir
+ env:
+ MERCURY_VERSION: 9.9.9
+ MERCURY_DOWNLOAD_BASE: http://127.0.0.1:8765
+ MERCURY_INSTALL: ${{ runner.temp }}/mercury-prefix
+ MERCURY_NO_PATH: '1'
+ run: |
+ set -euo pipefail
+ sh scripts/install.sh 2>&1 | tee "$RUNNER_TEMP/install.log"
+ grep -q 'Checksums verified' "$RUNNER_TEMP/install.log"
+ grep -q 'Smoke test passed' "$RUNNER_TEMP/install.log"
+ test -x "$MERCURY_INSTALL/bin/mercury"
+ test -f "$MERCURY_INSTALL/bin/web/index.html"
+ [ "$("$MERCURY_INSTALL/bin/mercury" --version)" = "9.9.9" ]
+
+ - name: install-dev.sh delegates to install.sh (dev channel, local release dir)
+ env:
+ MERCURY_DOWNLOAD_BASE: http://127.0.0.1:8765
+ MERCURY_INSTALL: ${{ runner.temp }}/mercury-dev-prefix
+ MERCURY_NO_PATH: '1'
+ run: |
+ set -euo pipefail
+ # The dev channel resolves <base>/mercury-dev-latest/…; alias the fake
+ # release under that tag.
+ ln -s v9.9.9 "$REL_ROOT/mercury-dev-latest"
+ sh scripts/install-dev.sh 2>&1 | tee "$RUNNER_TEMP/install-dev.log"
+ grep -q 'Smoke test passed' "$RUNNER_TEMP/install-dev.log"
+ test -x "$MERCURY_INSTALL/bin/mercury-dev"
+ [ "$("$MERCURY_INSTALL/bin/mercury-dev" --version)" = "9.9.9" ]
+
+ - name: A tampered checksum must abort the install
+ env:
+ MERCURY_VERSION: 9.9.9
+ MERCURY_DOWNLOAD_BASE: http://127.0.0.1:8765
+ MERCURY_INSTALL: ${{ runner.temp }}/mercury-tampered
+ MERCURY_NO_PATH: '1'
+ run: |
+ set -euo pipefail
+ sed -i 's/^[0-9a-f]\{8\}/00000000/' "$REL_ROOT/v9.9.9/checksums.txt"
+ if sh scripts/install.sh > "$RUNNER_TEMP/tampered.log" 2>&1; then
+ echo "::error::install.sh succeeded with a tampered checksums.txt"
+ cat "$RUNNER_TEMP/tampered.log"
+ exit 1
+ fi
+ grep -q 'Checksum mismatch' "$RUNNER_TEMP/tampered.log"
+ test ! -e "$MERCURY_INSTALL/bin/mercury"
+
termux:
name: Termux (Android, x86_64)
runs-on: ubuntu-latest
diff --cc src/cli/service.test.ts
index 23a483dc,55acd559..2ab21abc
--- a/src/cli/service.test.ts
+++ b/src/cli/service.test.ts
@@@ -10,10 -10,19 +10,21 @@@ import
buildSchtasksCreateCommand,
buildSystemdUnit,
buildWindowsCommandLine,
+ buildTermuxBootScript,
buildWindowsTaskXml,
encodeWindowsTaskXml,
+ pinnedServicePath,
+ serviceFileOptions,
+ installService,
+ isServiceInstalled,
+ isServiceRunning,
+ removeTermuxBootScript,
+ showServiceStatus,
+ stopService,
+ teardownService,
+ termuxBootScriptPath,
+ uninstallService,
+ writeTermuxBootScript,
quoteWindowsArg,
resolveDistPath,
runKeyLaunchArgs,
@@@ -172,44 -181,123 +183,165 @@@ describe('resolveDistPath', () =>
});
});
+describe('service PATH pinning (ROADMAP P2.2, #103)', () => {
+ const nodeDir = '/Users/jane/.nvm/versions/node/v20.11.0/bin';
+
+ it('pins a fixed PATH of system dirs plus the node directory (darwin, linux)', () => {
+ expect(pinnedServicePath('darwin', nodeDir)).toBe(`/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/homebrew/bin:${nodeDir}`);
+ expect(pinnedServicePath('linux', '/usr/bin')).toBe('/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin');
+ // A relative node dir is never written.
+ expect(pinnedServicePath('linux', 'node_modules/.bin')).toBe('/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin');
+ });
+
+ it('pins Windows to System32, Git and the node directory', () => {
+ const p = pinnedServicePath('win32', 'C:\\Program Files\\nodejs', { SystemRoot: 'C:\\Windows', ProgramFiles: 'C:\\Program Files' });
+ expect(p.split(';')).toEqual([
+ 'C:\\Windows\\System32',
+ 'C:\\Windows',
+ 'C:\\Windows\\System32\\Wbem',
+ 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0',
+ 'C:\\Program Files\\Git\\cmd',
+ 'C:\\Program Files\\nodejs',
+ ]);
+ });
+
+ it('generated plist and systemd unit carry the pinned PATH, not the installing shell PATH', () => {
+ const original = process.env.PATH;
+ process.env.PATH = `/tmp/evil-bin:./node_modules/.bin:${original}`;
+ try {
+ const opts = serviceFileOptions();
+ expect(opts.pathEnv).not.toContain('/tmp/evil-bin');
+ expect(opts.pathEnv).not.toContain('node_modules');
+ const args = ['/usr/local/bin/node', '/opt/mercury/dist/index.js', 'start', '--daemon'];
+ const plist = buildLaunchAgentPlist(args, opts);
+ expect(plist).toContain(`<key>PATH</key>\n <string>${opts.pathEnv}</string>`);
+ expect(plist).not.toContain('/tmp/evil-bin');
+ const unit = buildSystemdUnit(args, opts);
+ expect(unit).toContain(`Environment=PATH=${opts.pathEnv}`);
+ expect(unit).not.toContain('/tmp/evil-bin');
+ } finally {
+ process.env.PATH = original;
+ }
+ });
+});
++
+ describe('Termux:Boot script (P2.8)', () => {
+ const opts = { prefix: '/data/data/com.termux/files/usr', mercuryHome: '/data/data/com.termux/files/home/.mercury' };
+
+ it('uses the Termux shell, takes a wake lock before `mercury up`, and logs boot output', () => {
+ const script = buildTermuxBootScript(['/data/data/com.termux/files/usr/bin/node', '/data/x/dist/index.js', 'up'], opts);
+ const lines = script.split('\n');
+ expect(lines[0]).toBe('#!/data/data/com.termux/files/usr/bin/sh');
+ const wake = lines.indexOf('termux-wake-lock');
+ const up = lines.findIndex((l) => l.startsWith('/data/data/com.termux/files/usr/bin/node /data/x/dist/index.js up'));
+ expect(wake).toBeGreaterThan(0);
+ expect(up).toBeGreaterThan(wake);
+ expect(lines[up]).toContain('>> /data/data/com.termux/files/home/.mercury/boot.log 2>&1');
+ expect(script).toContain('export PATH="/data/data/com.termux/files/usr/bin:$PATH"');
+ expect(script.endsWith('\n')).toBe(true);
+ });
+
+ it('single-quotes argv words that the boot shell would split or expand', () => {
+ const script = buildTermuxBootScript(["/home/my dir/it's/node", '$HOME/x', 'up'], opts);
+ expect(script).toContain(String.raw`'/home/my dir/it'\''s/node' '$HOME/x' up >>`);
+ });
+
+ it('falls back to the default Termux prefix', () => {
+ expect(buildTermuxBootScript(['mercury', 'up'], { mercuryHome: '/m' }).split('\n')[0])
+ .toBe('#!/data/data/com.termux/files/usr/bin/sh');
+ });
+
+ it('writes ~/.termux/boot/mercury.sh executable under a fake HOME and removes it', () => {
+ const home = mkdtempSync(join(tmpdir(), 'mercury-termux-'));
+ try {
+ const path = writeTermuxBootScript(['mercury', 'up'], { ...opts, home });
+ expect(path).toBe(termuxBootScriptPath(home));
+ expect(path.replace(/\\/g, '/').endsWith('/.termux/boot/mercury.sh')).toBe(true);
+ expect(readFileSync(path, 'utf8')).toContain('termux-wake-lock');
+ if (process.platform !== 'win32') expect(statSync(path).mode & 0o777).toBe(0o755);
+ // Re-install over an existing (non-executable) file restores the mode.
+ if (process.platform !== 'win32') {
+ writeFileSync(path, 'old', { mode: 0o644 });
+ writeTermuxBootScript(['mercury', 'up'], { ...opts, home });
+ expect(statSync(path).mode & 0o777).toBe(0o755);
+ }
+ expect(removeTermuxBootScript(path)).toBe(true);
+ expect(existsSync(path)).toBe(false);
+ // Removing an absent script is still "gone".
+ expect(removeTermuxBootScript(path)).toBe(true);
+ } finally {
+ rmSync(home, { recursive: true, force: true });
+ }
+ });
+ });
+
+ describe('service install/uninstall/status on Termux (fake HOME, platform android)', () => {
+ let home: string;
+ const realPlatform = process.platform;
+ let logs: string[];
+
+ beforeEach(() => {
+ home = mkdtempSync(join(tmpdir(), 'mercury-termux-home-'));
+ vi.stubEnv('HOME', home);
+ vi.stubEnv('USERPROFILE', home);
+ vi.stubEnv('MERCURY_HOME', join(home, '.mercury'));
+ vi.stubEnv('TERMUX_VERSION', '0.118.0');
+ vi.stubEnv('PREFIX', '/data/data/com.termux/files/usr');
+ Object.defineProperty(process, 'platform', { value: 'android', configurable: true });
+ logs = [];
+ vi.spyOn(console, 'log').mockImplementation((...args: unknown[]) => { logs.push(args.join(' ')); });
+ });
+
+ afterEach(() => {
+ Object.defineProperty(process, 'platform', { value: realPlatform, configurable: true });
+ vi.restoreAllMocks();
+ vi.unstubAllEnvs();
+ rmSync(home, { recursive: true, force: true });
+ });
+
+ it('install writes the boot script and reports it; status and uninstall recognise it', () => {
+ const bootPath = termuxBootScriptPath(home);
+ expect(isServiceInstalled()).toBe(false);
+
+ expect(installService()).toBe(true);
+ expect(existsSync(bootPath)).toBe(true);
+ const script = readFileSync(bootPath, 'utf8');
+ expect(script.split('\n')[0]).toBe('#!/data/data/com.termux/files/usr/bin/sh');
+ expect(script).toMatch(/termux-wake-lock\n.* up >> /);
+ expect(script).not.toContain('--daemon');
+ expect(logs.join('\n')).toContain('Termux:Boot');
+ expect(logs.join('\n')).toContain(bootPath);
+
+ expect(isServiceInstalled()).toBe(true);
+ // Nothing supervises the daemon: no service process to stop or query.
+ expect(isServiceRunning()).toBe(false);
+ expect(stopService()).toBe(true);
+
+ logs.length = 0;
+ showServiceStatus();
+ expect(logs.join('\n')).toContain('Autostart: Termux:Boot script');
+ expect(logs.join('\n')).toContain(bootPath);
+
+ logs.length = 0;
+ expect(uninstallService()).toBe(true);
+ expect(existsSync(bootPath)).toBe(false);
+ expect(logs.join('\n')).toContain('boot script removed');
+ expect(isServiceInstalled()).toBe(false);
+
+ logs.length = 0;
+ showServiceStatus();
+ expect(logs.join('\n')).toMatch(/not installed/);
+ });
+
+ it('uninstall without a boot script reports it and does not exit', () => {
+ expect(uninstallService()).toBe(false);
+ expect(logs.join('\n')).toMatch(/not installed/);
+ });
+
+ it('teardownService (mercury uninstall) removes the boot script', () => {
+ expect(teardownService()).toEqual({ removed: false });
+ installService();
+ expect(teardownService()).toEqual({ removed: true, path: termuxBootScriptPath(home) });
+ expect(existsSync(termuxBootScriptPath(home))).toBe(false);
+ });
+ });
diff --cc src/cli/service.ts
index 618565b2,10d41a34..df6dcfd6
--- a/src/cli/service.ts
+++ b/src/cli/service.ts
@@@ -1,5 -1,5 +1,5 @@@
- import { existsSync, mkdirSync, writeFileSync, unlinkSync, realpathSync } from 'node:fs';
+ import { chmodSync, existsSync, mkdirSync, writeFileSync, unlinkSync, realpathSync } from 'node:fs';
-import { join, posix } from 'node:path';
+import { dirname, join, posix, win32 } from 'node:path';
import { fileURLToPath } from 'node:url';
import { homedir } from 'node:os';
import chalk from 'chalk';