mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +00:00
Extract subprocess execution and process contracts into @orca/process-host with explicit public entry points, independent checks, and one Node 18 compatible CommonJS runtime. Migrate application consumers and integrate package builds, dependency selection, import enforcement, and runtime resource staging. Preserve daemon startup ownership and profile isolation, and qualify development rebuild recovery and concurrent output publication. Remove unnecessary aliases, test forwarding exports, and a duplicate output scan. Validation: full typechecks, changed-code quality, package and artifact checks, native Windows builds/types plus 306 runtime tests, and independent native reviews. Matched full E2E controls on original main and unchanged reviewed head both pass all 17 applicable tests (nine skips). Earlier intermittent E2E failures are documented in the PR; no assertions were weakened. The final combined-tree audit preserves both branches with no import-boundary violations.
52 lines
1.8 KiB
TypeScript
52 lines
1.8 KiB
TypeScript
import { runProcess } from '@orca/process-host'
|
|
import {
|
|
CHEAP_PS_ARGS,
|
|
PS_MAX_BUFFER_BYTES,
|
|
ProcessTableCaptureError,
|
|
parseCheapProcessTableRows,
|
|
type CheapProcessTableRow
|
|
} from './process-table-snapshot'
|
|
import {
|
|
PS_TIMEOUT_MS,
|
|
createProcessTableSnapshotReader,
|
|
withEvidenceBudget
|
|
} from './process-table-snapshot-reader'
|
|
|
|
/**
|
|
* The cheap-tier sibling of the strict evidence reader: same coalescing and TTL, a
|
|
* column set without `tty=`/`command=`. Separate instance because the two column sets
|
|
* parse differently and a cheap capture must never be served to an evidence consumer.
|
|
*/
|
|
const cheapProcessTableReader = createProcessTableSnapshotReader<CheapProcessTableRow[]>({
|
|
runPs: async () => {
|
|
const result = await runProcess({
|
|
program: 'ps',
|
|
args: CHEAP_PS_ARGS,
|
|
timeoutMs: PS_TIMEOUT_MS,
|
|
maxOutputBytes: PS_MAX_BUFFER_BYTES
|
|
})
|
|
// A ceiling hit is truncation, not absence: name it in the domain vocabulary.
|
|
if (result.outputTruncated) {
|
|
throw new ProcessTableCaptureError('capture_truncated')
|
|
}
|
|
if (result.timedOut) {
|
|
throw new ProcessTableCaptureError('capture_timeout')
|
|
}
|
|
if (result.code !== 0) {
|
|
throw new ProcessTableCaptureError(`ps_exit_${result.code ?? result.signal ?? 'unknown'}`)
|
|
}
|
|
return parseCheapProcessTableRows(result.stdout)
|
|
},
|
|
now: () => Date.now()
|
|
})
|
|
|
|
/** Same wait bound as the evidence read: a stalled cheap capture must fall through to the full
|
|
* path's own handling rather than pin a polled tick. */
|
|
export async function getCheapProcessTableSnapshot(): Promise<CheapProcessTableRow[]> {
|
|
return withEvidenceBudget(cheapProcessTableReader.getSnapshot())
|
|
}
|
|
|
|
export function resetCheapProcessTableSnapshotForTests(): void {
|
|
cheapProcessTableReader.reset()
|
|
}
|