Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (codex r2): stop passive lookahead at sentence boundaries

[._.]/ Adam Eivydfdc670ac4f8
diff --git a/server/lib/editorial/proseTics.js b/server/lib/editorial/proseTics.js
index 409826d28b..08a1344154 100644
--- a/server/lib/editorial/proseTics.js
+++ b/server/lib/editorial/proseTics.js
@@ -361,12 +361,21 @@ export function findPassiveVoice(text) {
const end = tokens[j].index + tokens[j].word.length;
const participle = tokens[j].lower;
// Small window just past the participle, where a "by <agent>" or an
- // atmospheric "with/in <…>" complement would sit.
- const after = tokens.slice(j + 1, j + 1 + PASSIVE_LOOKAHEAD);
+ // atmospheric "with/in <…>" complement would sit. Stop at a sentence/line
+ // boundary so the next sentence ("…exhausted. By morning…") can't leak a
+ // false agent in — tokenizeWords drops punctuation, so the boundary is
+ // detected from the raw text gap between adjacent tokens.
+ const after = [];
+ for (let k = j + 1; k < tokens.length && after.length < PASSIVE_LOOKAHEAD; k += 1) {
+ const prev = tokens[k - 1];
+ if (/[.!?\n]/.test(text.slice(prev.index + prev.word.length, tokens[k].index))) break;
+ after.push(tokens[k]);
+ }
// An explicit "by <agent>" (with an optional intervening adverb) is the
// unambiguous agentive passive — it wins over stative/mood classification.
+ // The agent token must be inside the same-sentence window.
const byPos = after.findIndex((t) => t.lower === 'by');
- const byAgent = byPos !== -1 && j + 1 + byPos + 1 < tokens.length;
+ const byAgent = byPos !== -1 && after.length > byPos + 1;
let classification = 'weak';
if (!byAgent) {
// A mood image needs BOTH a setting subject and an atmospheric complement
diff --git a/server/lib/editorial/proseTics.test.js b/server/lib/editorial/proseTics.test.js
index 48caae8443..bcf8bbd8fb 100644
--- a/server/lib/editorial/proseTics.test.js
+++ b/server/lib/editorial/proseTics.test.js
@@ -185,6 +185,14 @@ describe('findPassiveVoice', () => {
const [hit] = findPassiveVoice('The room was searched.');
expect(hit.classification).toBe('weak');
});
+
+ it('does not read a "by" from the next sentence as the agent', () => {
+ // "By morning" starts a new sentence — it must not flip the stative
+ // "was exhausted" into a weak by-agent passive.
+ const [hit] = findPassiveVoice('She was exhausted. By morning the fog had lifted.');
+ expect(hit.byAgent).toBe(false);
+ expect(hit.classification).toBe('stative');
+ });
});
describe('filterPassiveVoice', () => {