Skip to content

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.

fix(admission): retain callable inputs used as commands [C7,O5]

Corey Olsonb6a836249156
diff --git a/src/browser-launch-source.js b/src/browser-launch-source.js
index 7355bd82..2a1b1c61 100644
--- a/src/browser-launch-source.js
+++ b/src/browser-launch-source.js
@@ -58,7 +58,7 @@ function processNamespaces(source) {
}
/** Unknown command members stay bound without tainting unrelated calls in the same source. */
-function unresolvedCommandValue(expression, links) {
+function unresolvedCommandValue(expression, links, parameters) {
const compact = expression.replace(/^\s*await\s+/u, '').replace(/\s/gu, '');
// A conditional's predicate is not one of the executable values it returns.
let nested = 0;
@@ -76,8 +76,8 @@ function unresolvedCommandValue(expression, links) {
at = end;
} else if (compact[at] === '?' && !['?', '.'].includes(compact[at + 1]) && compact[at - 1] !== '?') nested += 1;
else if (compact[at] === ':' && nested-- === 0) {
- return unresolvedCommandValue(compact.slice(start, at), links)
- || unresolvedCommandValue(compact.slice(at + 1), links);
+ return unresolvedCommandValue(compact.slice(start, at), links, parameters)
+ || unresolvedCommandValue(compact.slice(at + 1), links, parameters);
}
}
return true;
@@ -86,6 +86,9 @@ function unresolvedCommandValue(expression, links) {
// Only returned values and bare aliases feed the command graph, never a conditional's predicate.
const linked = /^([$A-Z_a-z][$\w]*)(?=$|(?:\?\.)?\()/u.exec(compact);
if (linked && links) links.add(linked[1]);
+ // A returned input is not a proven non-browser executable. It affects only callers that
+ // actually supply a process command; unused callable parameters never taint literal launches.
+ if (parameters && [...compact.matchAll(WORD)].some(word => parameters.has(word[0]))) return true;
// Calls and object/template construction do not return the value of each member they read.
// In particular, a pid used to build a directory name is not an executable-valued alias.
let brackets = 0;
@@ -121,9 +124,15 @@ function expressionEnd(code, start, newlineEnds = true) {
return end;
}
+/** Keep parameter binding names while omitting defaults, which are executable expressions. */
+function parameterNames(source) {
+ return new Set([...source.replace(/=[^,]*/gu, '').matchAll(WORD)].map(word => word[0]));
+}
+
/** Read callable result spans without evaluating either a function body or its generated source. */
function callableReturns(code, start, end) {
let at = start + code.slice(start, end).search(/\S/u);
+ let names;
const declared = /^(?:async\s+)?function(?:\s+[$A-Z_a-z][$\w]*)?\s*\(/u.exec(code.slice(at, end));
if (declared) at += declared[0].length - 1;
else {
@@ -133,10 +142,12 @@ function callableReturns(code, start, end) {
if (code[at] === '(') {
const parameters = closing(code, at);
if (parameters === null) return [];
+ names = parameterNames(code.slice(at + 1, parameters));
at = parameters + 1;
} else {
const parameter = /^[$A-Z_a-z][$\w]*/u.exec(code.slice(at, end));
if (!parameter || declared) return [];
+ names = new Set([parameter[0]]);
at += parameter[0].length;
}
at += code.slice(at, end).search(/\S/u);
@@ -144,7 +155,7 @@ function callableReturns(code, start, end) {
if (code.slice(at, at + 2) !== '=>') return [];
at += 2;
at += code.slice(at, end).search(/\S/u);
- if (code[at] !== '{') return [[at, end]];
+ if (code[at] !== '{') return [[at, end, names]];
}
if (code[at] !== '{') return [];
const last = closing(code, at);
@@ -152,7 +163,7 @@ function callableReturns(code, start, end) {
return [...code.slice(at + 1, last).matchAll(/\breturn[ \t]+/gu)].flatMap(match => {
const first = at + 1 + match.index + match[0].length;
const final = expressionEnd(code, first);
- return final === null ? [] : [[first, final]];
+ return final === null ? [] : [[first, final, names]];
});
}
@@ -203,8 +214,8 @@ export function sourceLaunchesBrowser(source, reviewedExecutors = []) {
const prior = bindings.get(match[1]) ?? { browser: false, unresolved: false, aliases: new Set(), dependencies: new Set() };
prior.browser ||= browserIn(start, end);
prior.unresolved ||= unresolvedCommandValue(code.slice(start, end), prior.aliases);
- for (const [first, last] of callableReturns(code, start, end)) {
- prior.unresolved ||= unresolvedCommandValue(code.slice(first, last), prior.aliases);
+ for (const [first, last, parameters] of callableReturns(code, start, end)) {
+ prior.unresolved ||= unresolvedCommandValue(code.slice(first, last), prior.aliases, parameters);
}
for (const word of code.slice(start, end).matchAll(WORD)) prior.dependencies.add(word[0]);
bindings.set(match[1], prior);
@@ -219,12 +230,13 @@ export function sourceLaunchesBrowser(source, reviewedExecutors = []) {
const last = closing(code, body);
if (last === null) continue;
const value = bindings.get(match[1]) ?? { browser: false, unresolved: false, aliases: new Set(), dependencies: new Set() };
+ const names = parameterNames(code.slice(match.index + match[0].length, parameters));
for (const returned of code.slice(body + 1, last).matchAll(/\breturn\s+(?![\r\n])/gu)) {
const start = body + 1 + returned.index + returned[0].length;
const end = expressionEnd(code, start);
if (end === null) continue;
value.browser ||= browserIn(start, end);
- value.unresolved ||= unresolvedCommandValue(code.slice(start, end), value.aliases);
+ value.unresolved ||= unresolvedCommandValue(code.slice(start, end), value.aliases, names);
for (const word of code.slice(start, end).matchAll(WORD)) value.dependencies.add(word[0]);
}
bindings.set(match[1], value);