Skip to content

Commit f45fa92

Browse files
committed
style(skills): keep signal parser within ratchets
1 parent 288b7cb commit f45fa92

2 files changed

Lines changed: 15 additions & 40 deletions

File tree

‎src/skills/research/signals.test.ts‎

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -374,36 +374,16 @@ describe("durable instruction signals", () => {
374374
},
375375
);
376376

377-
it("preserves command casing", () => {
378-
const proposal = expectDefined(
379-
proposals([user("From now on, git fetch before rebasing.")])[0],
380-
"command rule",
381-
);
382-
expect(proposal.content).toContain("- git fetch before rebasing.");
383-
});
384-
385-
it("preserves a lowercase shell command with an assignment argument", () => {
386-
const proposal = expectDefined(
387-
proposals([user("From now on, export FOO=bar.")])[0],
388-
"assignment command",
389-
);
390-
expect(proposal.content).toContain("- export FOO=bar.");
391-
});
392-
393-
it("preserves a literal trailing-dot command argument", () => {
394-
const proposal = expectDefined(
395-
proposals([user("Remember to run git add .")])[0],
396-
"literal dot argument",
397-
);
398-
expect(proposal.content).toContain("- Run git add .");
399-
});
400-
401-
it("accepts an explicitly marked directive outside the action vocabulary", () => {
402-
const proposal = expectDefined(
403-
proposals([user("Remember to call the release webhook before publishing.")])[0],
404-
"explicit directive",
405-
);
406-
expect(proposal.content).toContain("- Call the release webhook before publishing.");
377+
it.each([
378+
["From now on, git fetch before rebasing.", "- git fetch before rebasing."],
379+
["From now on, export FOO=bar.", "- export FOO=bar."],
380+
["Remember to run git add .", "- Run git add ."],
381+
[
382+
"Remember to call the release webhook before publishing.",
383+
"- Call the release webhook before publishing.",
384+
],
385+
])("preserves explicit directive syntax: %s", (content, expected) => {
386+
expect(proposals([user(content)])[0]?.content).toContain(expected);
407387
});
408388

409389
it("rejects an ambiguous noun phrase after never", () => {

‎src/skills/research/signals.ts‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const RULE_SHORTHAND =
3636
const UNMARKED_FIX = /^(?!i\b|it\b|th\w+\b|we\b|you\b)[a-z][\w-]*\s+\S+/i;
3737
const COMMAND_SHAPED =
3838
/^(?:git|gh|node|npm|openclaw|pnpm)\s+|^[a-z][\w-]*\s+(?:-|\.?\/|https?:\/\/|[A-Z_][A-Z0-9_]*=)/;
39+
const EXPLICIT_ACTION_MARKER =
40+
/\b(?:remember to|make sure to)\b|^(?:(?:can|could|would|will) you\s+|please\s+)?always\b|[,;:—–-]\s+always\b/i;
3941

4042
const MATCH_STOPWORDS = new Set(
4143
"and are as before but for from have into not should that the them then they this was were what when with you your".split(
@@ -195,9 +197,7 @@ function normalizeRule(value: string, explicit = false): string | undefined {
195197
.replace(/^(?:(?:also|always|make sure to|please|just|remember to)\s+)+/i, "")
196198
.trim();
197199
const literalDotArgument = /^run\s+\S+.*\s\.$/i.test(rule);
198-
if (!literalDotArgument) {
199-
rule = rule.replace(/[.!?]+$/, "");
200-
}
200+
rule = literalDotArgument ? rule : rule.replace(/[.!?]+$/, "");
201201
if (
202202
!rule ||
203203
(compact.endsWith("?") && !request && !IMPERATIVE_RULE.test(rule)) ||
@@ -240,8 +240,7 @@ function normalizeRule(value: string, explicit = false): string | undefined {
240240
} else if (/\bin parentheses$/i.test(rule) && !IMPERATIVE_RULE.test(rule)) {
241241
rule = `Include ${rule}`;
242242
}
243-
const normalized = commandShaped ? rule : rule.charAt(0).toUpperCase() + rule.slice(1);
244-
return literalDotArgument ? normalized : `${normalized}.`;
243+
return `${commandShaped ? rule : rule.charAt(0).toUpperCase() + rule.slice(1)}${literalDotArgument ? "" : "."}`;
245244
}
246245

247246
function normalizeRuleList(value: string, splitList: boolean, explicit = false): string[] {
@@ -269,10 +268,6 @@ function normalizeRuleList(value: string, splitList: boolean, explicit = false):
269268

270269
function parseInstruction(instruction: string) {
271270
const compactInstruction = compactWhitespace(instruction.split("\uE000", 1)[0] ?? instruction);
272-
const explicitActionMarker =
273-
/\b(?:remember to|make sure to)\b|^(?:(?:can|could|would|will) you\s+|please\s+)?always\b|[,;:—–-]\s+always\b/i.test(
274-
compactInstruction,
275-
);
276271
const isolatedInstruction = stripSignalMarkers(compactInstruction);
277272
const actorEvent = isolatedInstruction.match(
278273
new RegExp(
@@ -508,7 +503,7 @@ function parseInstruction(instruction: string) {
508503
? { rules: normalizeRuleList(explicitFix, false) }
509504
: undefined;
510505
}
511-
const rules = normalizeRuleList(text, false, explicitActionMarker);
506+
const rules = normalizeRuleList(text, false, EXPLICIT_ACTION_MARKER.test(compactInstruction));
512507
return rules.length > 0 ? { rules } : undefined;
513508
}
514509

0 commit comments

Comments
 (0)