Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(view): name the listener program behind a thread label [N26,I1]
Corey Olson7e9c50fd08fa
diff --git a/src/view-session.js b/src/view-session.jsindex 409c47fa..c2fe54eb 100644--- a/src/view-session.js+++ b/src/view-session.js@@ -1,7 +1,7 @@/** Private runtime records that let an unattended CLI hand off its live view link. */import { spawnSync } from 'node:child_process';import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';-import { dirname, join } from 'node:path';+import { basename, dirname, join } from 'node:path';import { LOOPBACK, lastPort } from './serve.js';import { registryFile } from './projects.js';import { fetchLocal } from './local-fetch.js';@@ -80,6 +80,23 @@ export async function runningView(port = 0, expectedScopeCommonDir = null) {}}+/** Resolve a thread label to its program without exposing script paths or command arguments. */+function listenerProgram(pid, listedName) {+ if (!/^(?:node-)?MainThread$/u.test(listedName)) return listedName;+ try {+ let command;+ if (process.platform === 'linux') {+ command = readFileSync(`/proc/${pid}/cmdline`).toString('utf8').split('\0', 1)[0];+ } else {+ // macOS comm is the executable path, so spaces in that path are not mistaken for arguments.+ const result = spawnSync('/bin/ps', ['-p', String(pid), '-o', 'comm='], { encoding: 'utf8', timeout: 2_000 });+ if (result.status !== 0) return 'a program';+ command = result.stdout;+ }+ return basename(String(command).trim()).replace(/[\u0000-\u001f\u007f]/gu, '').trim() || 'a program';+ } catch { return 'a program'; }+}+/*** Name the process listening on a loopback port, when this machine can tell. Only the system's* listener table (lsof) can say who owns a port: a recorded view pid that is still alive may be a@@ -99,5 +116,6 @@ export function portHolder(port) {if (listed.status !== 0 || pids.length !== 1 || !Number.isInteger(pids[0]) || pids[0] < 1) return null;const pid = pids[0];if (readSession(port)?.pid === pid) return { pid, name: 'pullboard view' };- return { pid, name: /^c(.+)$/mu.exec(listed.stdout)?.[1]?.trim() || 'a program' };+ const listedName = /^c(.+)$/mu.exec(listed.stdout)?.[1]?.trim() || 'a program';+ return { pid, name: listenerProgram(pid, listedName) };}diff --git a/test/view-port.test.js b/test/view-port.test.jsindex a663571b..530ea77d 100644--- a/test/view-port.test.js+++ b/test/view-port.test.js@@ -17,6 +17,60 @@ import { fetchPrintedViewLink } from './view-link-fixture.js';const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');+test('a busy port names the program, not its thread [N26,I1]', (t) => {+ const dir = mkdtempSync(join(tmpdir(), 'pullboard-port-program-'));+ t.after(() => rmSync(dir, { recursive: true, force: true }));+ const script = String.raw`+import fs from 'node:fs';+import childProcess from 'node:child_process';+import { syncBuiltinESMExports } from 'node:module';+const original = { exists: fs.existsSync, read: fs.readFileSync, spawn: childProcess.spawnSync,+ platform: Object.getOwnPropertyDescriptor(process, 'platform') };+let listedName = 'MainThread';+let program = '/opt/Runtime Folder/bin/node';+fs.existsSync = path => ['/usr/sbin/lsof', '/usr/bin/lsof'].includes(path) || original.exists(path);+fs.readFileSync = (path, ...args) => path === '/proc/43210/cmdline'+ ? Buffer.from([program, '/private/DO_NOT_LEAK.js', '--token=DO_NOT_LEAK', ''].join(String.fromCharCode(0)))+ : original.read(path, ...args);+childProcess.spawnSync = (command, args, options) => {+ if (command.endsWith('/lsof')) return { status: 0, stdout: 'p43210\nc' + listedName + '\n' };+ if (command.endsWith('/ps')) return { status: 0, stdout: program + '\n' };+ throw new Error('unexpected fixture process: ' + command);+};+syncBuiltinESMExports();+try {+ const { portHolder } = await import(process.argv[1]);+ const threaded = [];+ for (program of ['/opt/Runtime Folder/bin/node', '/opt/Runtime Folder/bin/fixture-server']) {+ for (const platform of ['linux', 'darwin']) {+ Object.defineProperty(process, 'platform', { value: platform, configurable: true });+ threaded.push(portHolder(31337));+ }+ }+ listedName = 'python3';+ const ordinary = portHolder(31337);+ process.stdout.write(JSON.stringify({ threaded, ordinary }));+} finally {+ fs.existsSync = original.exists; fs.readFileSync = original.read; childProcess.spawnSync = original.spawn;+ Object.defineProperty(process, 'platform', original.platform);+ syncBuiltinESMExports();+}+`;+ const result = runFixtureChild(process.execPath, ['--input-type=module', '-e', script,+ pathToFileURL(resolve(import.meta.dirname, '../src/view-session.js')).href], {+ cwd: dir, encoding: 'utf8',+ env: { ...process.env, HOME: join(dir, 'home'), PULLBOARD_HOME: join(dir, 'home', '.pullboard'),+ PULLBOARD_MACHINE_HOME: join(dir, 'machine-home') },+ });+ assert.equal(result.status, 0, result.failure ?? result.stderr);+ const named = JSON.parse(result.stdout);+ assert.deepEqual(named.threaded, [{ pid: 43210, name: 'node' }, { pid: 43210, name: 'node' },+ { pid: 43210, name: 'fixture-server' }, { pid: 43210, name: 'fixture-server' }],+ 'Linux and macOS name the program behind a MainThread listener');+ assert.deepEqual(named.ordinary, { pid: 43210, name: 'python3' }, 'an ordinary program name stays unchanged');+ assert.doesNotMatch(result.stdout, /DO_NOT_LEAK/u, 'a script path and command arguments never become the program label');+});+test('the shipped view port stays fixed and malformed environment overrides are refused [N26]', () => {assert.equal(DEFAULT_VIEW_PORT, 4890);assert.equal(defaultViewPort({}), DEFAULT_VIEW_PORT);