fix: don't bleed top-level interval/prompt into heartbeat task parsing

This commit is contained in:
Rahul Pal
2026-04-11 01:37:01 +05:30
committed by Josh Lehman
parent ecf76bd97e
commit 2f9e87c8bb
2 changed files with 25 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
import {
DEFAULT_HEARTBEAT_ACK_MAX_CHARS,
isHeartbeatContentEffectivelyEmpty,
parseHeartbeatTasks,
stripHeartbeatToken,
} from "./heartbeat.js";
import { HEARTBEAT_TOKEN } from "./tokens.js";
@@ -25,6 +26,22 @@ describe("stripHeartbeatToken", () => {
});
});
it("does not bleed top-level interval/prompt fields into task parsing", () => {
const content = `
tasks:- name: email-check
interval: 30m
prompt: Check for urgent emails
interval: should-not-bleed
`;
expect(parseHeartbeatTasks(content)).toEqual([
{
name: "email-check",
interval: "30m",
prompt: "Check for urgent emails",
},
]);
});
it("drops heartbeats with small junk in heartbeat mode", () => {
expect(stripHeartbeatToken("HEARTBEAT_OK 🦞", { mode: "heartbeat" })).toEqual({
shouldSkip: true,

View File

@@ -249,12 +249,18 @@ export function parseHeartbeatTasks(content: string): HeartbeatTask[] {
}
// Check for task fields BEFORE checking for end of block
if (nextTrimmed.startsWith("interval:")) {
if (
nextTrimmed.startsWith("interval:") &&
(nextLine.startsWith(" ") || nextLine.startsWith("\t"))
) {
interval = nextTrimmed
.replace("interval:", "")
.trim()
.replace(/^["']|["']$/g, "");
} else if (nextTrimmed.startsWith("prompt:")) {
} else if (
nextTrimmed.startsWith("prompt:") &&
(nextLine.startsWith(" ") || nextLine.startsWith("\t"))
) {
prompt = nextTrimmed
.replace("prompt:", "")
.trim()