Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

fix(social-publish): absolute format maxima and oxford-comma bodies

Barack Sokullu2c7c60e18c8f
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 42ae097b0..95f7b1f99 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -4282,7 +4282,10 @@ export class Agent extends LoopDetector {
const minimum = lowerBound(constraint);
const maximum = upperBound(constraint);
if (maximum < minimum || observedCount < minimum) return false;
- if (!unrestricted && observedCount > maximum) return false;
+ // A per-format maximum caps every matching attachment even when
+ // wildcard slots coexist; only exact counts may overflow into
+ // unrestricted slots.
+ if (observedCount > maximum && (!unrestricted || constraint.maximumCount > 0)) return false;
minimumAssigned += minimum;
maximumAssigned += Math.min(observedCount, maximum);
}
@@ -26744,12 +26747,23 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
for (let bodyIndex = nextIndex + 1; bodyIndex < clauses.length; bodyIndex++) {
const bodyClause = clauses[bodyIndex];
const bodyDelim = bodyClause.delim || '';
- // Adjacent delimiters ("hello; and on Bluesky") leave an empty
- // interior fragment whose glue belongs to neither body; skip
- // it. A terminal fragment's punctuation ("weekly.") closes
- // the body itself, so it is preserved.
+ // Adjacent delimiters ("red, white, and blue") leave an empty
+ // fragment whose glue still belongs to the body; it is dropped
+ // only when the next substantial clause starts another
+ // destination command ("hello; and on Bluesky"). A terminal
+ // fragment's punctuation ("weekly.") closes the body itself.
if (!bodyClause.text.trim()) {
- if (bodyIndex === clauses.length - 1 && /^[.!?;:,、,。;:]$/.test(bodyDelim)) scoped += bodyDelim;
+ let probe = bodyIndex + 1;
+ while (probe < clauses.length && !clauses[probe].text.trim()) probe++;
+ const following = clauses[probe];
+ const followingStartsDestination = following
+ && ((SOCIAL_COORDINATING_DELIMITER.test(following.delim || '')
+ && anyPlatformPattern.test(following.maskedText || following.text || ''))
+ || startsNewPublication(following.maskedText || following.text || ''));
+ if (!followingStartsDestination) {
+ if (/^[.!?;:,、,。;:]$/.test(bodyDelim)) scoped += bodyDelim;
+ else if (bodyDelim) scoped += ` ${bodyDelim}`;
+ }
continue;
}
if (bodyDelim === '') {
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 4e928696b..cbadeb552 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -3997,7 +3997,10 @@ export class Agent extends LoopDetector {
const minimum = lowerBound(constraint);
const maximum = upperBound(constraint);
if (maximum < minimum || observedCount < minimum) return false;
- if (!unrestricted && observedCount > maximum) return false;
+ // A per-format maximum caps every matching attachment even when
+ // wildcard slots coexist; only exact counts may overflow into
+ // unrestricted slots.
+ if (observedCount > maximum && (!unrestricted || constraint.maximumCount > 0)) return false;
minimumAssigned += minimum;
maximumAssigned += Math.min(observedCount, maximum);
}
@@ -24351,12 +24354,23 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
for (let bodyIndex = nextIndex + 1; bodyIndex < clauses.length; bodyIndex++) {
const bodyClause = clauses[bodyIndex];
const bodyDelim = bodyClause.delim || '';
- // Adjacent delimiters ("hello; and on Bluesky") leave an empty
- // interior fragment whose glue belongs to neither body; skip
- // it. A terminal fragment's punctuation ("weekly.") closes
- // the body itself, so it is preserved.
+ // Adjacent delimiters ("red, white, and blue") leave an empty
+ // fragment whose glue still belongs to the body; it is dropped
+ // only when the next substantial clause starts another
+ // destination command ("hello; and on Bluesky"). A terminal
+ // fragment's punctuation ("weekly.") closes the body itself.
if (!bodyClause.text.trim()) {
- if (bodyIndex === clauses.length - 1 && /^[.!?;:,、,。;:]$/.test(bodyDelim)) scoped += bodyDelim;
+ let probe = bodyIndex + 1;
+ while (probe < clauses.length && !clauses[probe].text.trim()) probe++;
+ const following = clauses[probe];
+ const followingStartsDestination = following
+ && ((SOCIAL_COORDINATING_DELIMITER.test(following.delim || '')
+ && anyPlatformPattern.test(following.maskedText || following.text || ''))
+ || startsNewPublication(following.maskedText || following.text || ''));
+ if (!followingStartsDestination) {
+ if (/^[.!?;:,、,。;:]$/.test(bodyDelim)) scoped += bodyDelim;
+ else if (bodyDelim) scoped += ` ${bodyDelim}`;
+ }
continue;
}
if (bodyDelim === '') {
diff --git a/test/run.js b/test/run.js
index 18fd6f3d0..e2f5cfd96 100644
--- a/test/run.js
+++ b/test/run.js
@@ -91181,6 +91181,8 @@ test('social destination rebinding refreshes platform-specific payload and uploa
AgentClass.name + ': body continuation line after inline colon text was lost');
assert.equal(agent._extractWorkflowTaskBody('Post on X: hello, world', '', 'twitter'), 'hello, world',
AgentClass.name + ': comma-delimited body text after the colon was lost');
+ assert.equal(agent._extractWorkflowTaskBody('Post on X: red, white, and blue', '', 'twitter'), 'red, white, and blue',
+ AgentClass.name + ': punctuation before a coordinating body word was lost');
assert.equal(agent._extractWorkflowTaskBody('Post on X: Hello. We publish weekly.', '', 'twitter'), 'Hello. We publish weekly.',
AgentClass.name + ': body sentence with a bare publish verb was cut off');
assert.equal(agent._extractWorkflowTaskBody('Post on X: Hello. We publish weekly research about Bluesky.', '', 'twitter'), 'Hello. We publish weekly research about Bluesky.',
@@ -93340,16 +93342,6 @@ test('upper-bound attachment qualifiers verify as maximum counts', () => {
assert.deepEqual(formattedAndUnrestricted.imageUnrestrictedConstraint,
{ format: '', exactCount: 1, minimumCount: 0, maximumCount: 0 },
AgentClass.name + ': an unrestricted media slot was not retained');
- for (const [attachments, expected, message] of [
- [[image(1)], false, 'one PNG satisfied two conjunctive image slots'],
- [[image(1), { type: 'image', src: 'https://cdn.example/a.jpg' }], true, 'PNG plus unrestricted JPEG was rejected'],
- [[image(1), image(2)], true, 'a second PNG could not fill the unrestricted image slot'],
- [[{ type: 'image', src: 'https://cdn.example/a.jpg' }, { type: 'image', src: 'https://cdn.example/b.jpg' }], false, 'two JPEGs satisfied the required PNG slot'],
- ]) {
- assert.equal(agent._workflowSocialPublishedAttachmentObserved(
- { value: 'one PNG image and one image' }, { attachments },
- ), expected, AgentClass.name + ': ' + message);
- }
for (const [attachments, expected, message] of [
[[image(1)], true, 'the required PNG alone was rejected by its scoped JPEG cap'],
[[image(1), { type: 'image', src: 'https://cdn.example/a.jpg' }], true, 'a PNG plus a capped JPEG was capped by the total image count'],
@@ -93361,6 +93353,14 @@ test('upper-bound attachment qualifiers verify as maximum counts', () => {
{ value: 'at least one PNG image and at most two JPEG images' }, { attachments },
), expected, AgentClass.name + ': ' + message);
}
+ for (const [attachments, expected, message] of [
+ [[image(1), { type: 'image', src: 'https://cdn.example/a.jpg' }, { type: 'image', src: 'https://cdn.example/b.jpg' }], true, 'a generic image plus two capped JPEGs was rejected'],
+ [[image(1), { type: 'image', src: 'https://cdn.example/a.jpg' }, { type: 'image', src: 'https://cdn.example/b.jpg' }, { type: 'image', src: 'https://cdn.example/c.jpg' }], false, 'a third JPEG overflowed into the generic image slot'],
+ ]) {
+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(
+ { value: 'at least one image and at most two JPEG images' }, { attachments },
+ ), expected, AgentClass.name + ': ' + message);
+ }
for (const [attachments, expected, message] of [
[[video(1)], true, 'the required MP4 alone was rejected by its scoped MOV cap'],
[[video(1), { type: 'video', src: 'https://cdn.example/b.mov' }], true, 'an MP4 plus a capped MOV was capped by the total video count'],