A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
improve heartbeat command guidance (#339)
kt2de63180d51a
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.mdindex c5b3be3d9d..0e8bd20acf 100644--- a/packages/coding-agent/CHANGELOG.md+++ b/packages/coding-agent/CHANGELOG.md@@ -2,6 +2,7 @@## [Unreleased]+- Fixed `/heartbeat` guidance to show `stop` and the `every <duration> <instruction>` interval syntax ([ENG-4484](https://linear.app/primeintellect/issue/ENG-4484/improve-heartbeat-command-syntax-guidance-in-ui)).- Fixed login dialogs in fullscreen so sign-in URLs can be selected natively ([ENG-4480](https://linear.app/primeintellect/issue/ENG-4480/new-fullscreen-tui-makes-it-impossible-to-copy-login-url)).- Fixed provider auth failures leaving stale credentials shown as connected in `/login` ([ENG-4491](https://linear.app/primeintellect/issue/ENG-4491/mark-provider-stale-after-repeated-401s)).diff --git a/packages/coding-agent/src/core/slash-commands.ts b/packages/coding-agent/src/core/slash-commands.tsindex 1f92252da8..fe24cdd749 100644--- a/packages/coding-agent/src/core/slash-commands.ts+++ b/packages/coding-agent/src/core/slash-commands.ts@@ -77,8 +77,9 @@ const CANONICAL_BUILTIN_SLASH_COMMANDS: ReadonlyArray<BuiltinSlashCommand> = [},{name: "heartbeat",- description: "Set or view a persistent heartbeat; supports pause, resume, and clear",- argumentHint: "[--every <interval>] <instruction>",+ description: "Set or view a persistent heartbeat; supports pause, resume, stop, and clear",+ argumentHint: "[status|pause|resume|stop|every <duration> <instruction>]",+ takesArgument: true,},{ name: "resume", description: "Resume a different session" },{ name: "reload", description: "Reload keybindings, extensions, skills, prompts, and themes" },diff --git a/packages/coding-agent/src/modes/interactive/interactive-mode.ts b/packages/coding-agent/src/modes/interactive/interactive-mode.tsindex 3da45d6b17..5802383bb8 100644--- a/packages/coding-agent/src/modes/interactive/interactive-mode.ts+++ b/packages/coding-agent/src/modes/interactive/interactive-mode.ts@@ -381,6 +381,14 @@ const THINKING_LEVEL_DESCRIPTIONS: Record<ThinkingLevel, string> = {max: "Maximum reasoning",};+const HEARTBEAT_ARGUMENT_COMPLETIONS: AutocompleteItem[] = [+ {+ value: "every ",+ label: "every <duration> <instruction>",+ description: "Set an interval, then add an instruction: /heartbeat every 10s Scan the logs",+ },+];+const DEAD_TERMINAL_ERROR_CODES = new Set(["EIO", "EPIPE", "ENOTCONN"]);// Cap on retained pasted-image bytes (base64). Images are resized below the@@ -866,6 +874,12 @@ export class InteractiveMode {}}+ const heartbeatCommand = slashCommands.find((command) => command.name === "heartbeat");+ if (heartbeatCommand) {+ heartbeatCommand.getArgumentCompletions = (prefix: string): AutocompleteItem[] | null =>+ this.getHeartbeatArgumentCompletions(prefix);+ }+const connectionCommands = this.connectionCommands;const templateCommands: SlashCommand[] = connectionCommands.filter((cmd) => cmd.source === "prompt")@@ -6300,6 +6314,16 @@ export class InteractiveMode {}));}+ private getHeartbeatArgumentCompletions(prefix: string): AutocompleteItem[] | null {+ const term = prefix.trim().toLowerCase();+ const filtered = term+ ? HEARTBEAT_ARGUMENT_COMPLETIONS.filter(+ (item) => item.value.toLowerCase().startsWith(term) || item.label.toLowerCase().startsWith(term),+ )+ : HEARTBEAT_ARGUMENT_COMPLETIONS;+ return filtered.length === 0 ? null : filtered;+ }+private handleEffortCommand(arg: string): void {const levels = this.getAvailableThinkingLevels();if (levels.length === 0) {diff --git a/packages/coding-agent/test/cron-jobs.test.ts b/packages/coding-agent/test/cron-jobs.test.tsindex fcb2d1b431..e60576abad 100644--- a/packages/coding-agent/test/cron-jobs.test.ts+++ b/packages/coding-agent/test/cron-jobs.test.ts@@ -63,6 +63,11 @@ describe("parseHeartbeatCommand", () => {schedule: "every 30s",instruction: "check on me",});+ expect(parseHeartbeatCommand("/heartbeat every 10m check status")).toEqual({+ type: "set",+ schedule: "every 10m",+ instruction: "check status",+ });expect(parseHeartbeatCommand("/heartbeat every 10m -- check status")).toEqual({type: "set",schedule: "every 10m",diff --git a/packages/coding-agent/test/interactive-mode-heartbeat-command.test.ts b/packages/coding-agent/test/interactive-mode-heartbeat-command.test.tsnew file mode 100644index 0000000000..48f5d0b542--- /dev/null+++ b/packages/coding-agent/test/interactive-mode-heartbeat-command.test.ts@@ -0,0 +1,36 @@+import type { AutocompleteItem } from "@earendil-works/pi-tui";+import { describe, expect, it } from "vitest";+import { InteractiveMode } from "../src/modes/interactive/interactive-mode.js";++type InteractiveModePrototype = {+ getHeartbeatArgumentCompletions(prefix: string): AutocompleteItem[] | null;+};++const interactiveModePrototype = InteractiveMode.prototype as unknown as InteractiveModePrototype;++describe("InteractiveMode /heartbeat", () => {+ describe("argument autocomplete", () => {+ it("lists the interval syntax starter for an empty prefix", () => {+ const items = interactiveModePrototype.getHeartbeatArgumentCompletions("");++ expect(items?.map((item) => item.label)).toEqual(["every <duration> <instruction>"]);+ const everyItem = items?.find((item) => item.label === "every <duration> <instruction>");+ expect(everyItem?.value).toBe("every ");+ expect(everyItem?.description).toBe(+ "Set an interval, then add an instruction: /heartbeat every 10s Scan the logs",+ );+ });++ it("does not autocomplete lifecycle commands over free-form instructions", () => {+ const items = interactiveModePrototype.getHeartbeatArgumentCompletions("st");++ expect(items).toBeNull();+ });++ it("filters interval syntax by keyword", () => {+ const items = interactiveModePrototype.getHeartbeatArgumentCompletions("every");++ expect(items?.map((item) => item.label)).toEqual(["every <duration> <instruction>"]);+ });+ });+});diff --git a/packages/coding-agent/test/slash-commands.test.ts b/packages/coding-agent/test/slash-commands.test.tsindex 87a8b2f852..0b40523d99 100644--- a/packages/coding-agent/test/slash-commands.test.ts+++ b/packages/coding-agent/test/slash-commands.test.ts@@ -16,6 +16,14 @@ describe("built-in slash commands", () => {expect(commandNames).not.toContain("cron");});+ test("exposes heartbeat syntax guidance", () => {+ expect(BUILTIN_SLASH_COMMANDS.find((command) => command.name === "heartbeat")).toMatchObject({+ description: "Set or view a persistent heartbeat; supports pause, resume, stop, and clear",+ argumentHint: "[status|pause|resume|stop|every <duration> <instruction>]",+ takesArgument: true,+ });+ });+test("exposes /effort for selecting the thinking level", () => {expect(BUILTIN_SLASH_COMMANDS.find((command) => command.name === "effort")).toMatchObject({description: "Set reasoning/thinking level",@@ -34,6 +42,7 @@ describe("built-in slash commands", () => {expect(builtinSlashCommandTakesArgument("goal")).toBe(true);expect(builtinSlashCommandTakesArgument("effort")).toBe(true);expect(builtinSlashCommandTakesArgument("thinking")).toBe(true);+ expect(builtinSlashCommandTakesArgument("heartbeat")).toBe(true);expect(builtinSlashCommandTakesArgument("new")).toBe(false);expect(builtinSlashCommandTakesArgument("clear")).toBe(false);});