An open-source, faster Devin alternative
TypeScript
computer: say what a mid-turn message waits behind; no foreground waits
Igor Zalutski via Computer7d7c866556e6
diff --git a/computer/src/runner/held-steer.test.ts b/computer/src/runner/held-steer.test.tsnew file mode 100644index 00000000..eff680f4--- /dev/null+++ b/computer/src/runner/held-steer.test.ts@@ -0,0 +1,49 @@+import { afterEach, describe, expect, it, vi } from 'vitest';+import { HELD_STEER_MS, HeldSteer } from './held-steer.js';++afterEach(() => vi.useRealTimers());++function held(running: { title: string; ms: number } | null = { title: 'Bash(gh run watch 1)', ms: 95_000 }) {+ vi.useFakeTimers();+ const said: string[] = [];+ return { h: new HeldSteer({ running: () => running ?? undefined, say: (t) => said.push(t) }), said };+}++describe('HeldSteer: a message waiting behind a slow step', () => {+ it('says what it waits on once the wait passes HELD_STEER_MS', () => {+ const { h, said } = held();+ h.arm();+ vi.advanceTimersByTime(HELD_STEER_MS - 1);+ expect(said).toEqual([]);+ vi.advanceTimersByTime(1);+ expect(said).toEqual(["Still in `Bash(gh run watch 1)` (1m35s). I'll read your message when it finishes; start a message with `!!` to stop it now."]);+ });++ it('one notice per wait, however many messages join it', () => {+ const { h, said } = held();+ h.arm();+ vi.advanceTimersByTime(HELD_STEER_MS);+ h.arm();+ vi.advanceTimersByTime(HELD_STEER_MS * 3);+ expect(said).toHaveLength(1);+ });++ it('nothing once a tool result carried the message', () => {+ const { h, said } = held();+ h.arm();+ vi.advanceTimersByTime(HELD_STEER_MS / 2);+ h.cancel();+ vi.advanceTimersByTime(HELD_STEER_MS);+ expect(said).toEqual([]);+ });++ it('nothing while no step runs, and it can arm again', () => {+ const { h, said } = held(null);+ h.arm();+ vi.advanceTimersByTime(HELD_STEER_MS);+ expect(said).toEqual([]);+ h.arm();+ vi.advanceTimersByTime(HELD_STEER_MS);+ expect(said).toEqual([]);+ });+});diff --git a/computer/src/runner/held-steer.ts b/computer/src/runner/held-steer.tsnew file mode 100644index 00000000..84270cfc--- /dev/null+++ b/computer/src/runner/held-steer.ts@@ -0,0 +1,38 @@+// A message sent mid-turn reaches the model only at the next tool boundary+// (session.ts). A tool that blocks for minutes, such as `gh run watch` or a+// sleep loop, held it unseen while the thread showed nothing but 👀. When a+// message is still waiting behind a running step after HELD_STEER_MS, the+// thread says what it waits on and how to break in.++import { fmtDuration } from './format.js';++export const HELD_STEER_MS = 8_000;++export interface HeldSteerDeps {+ /** The step running longest; undefined when nothing runs (the model is writing, and reads it soon). */+ running(): { title: string; ms: number } | undefined;+ say(text: string): unknown;+}++export class HeldSteer {+ private timer?: NodeJS.Timeout;++ constructor(private deps: HeldSteerDeps, private ms = HELD_STEER_MS) {}++ /** A message joined the running turn: one notice per wait, however many messages join it. */+ arm() {+ this.timer ??= setTimeout(() => this.fire(), this.ms);+ }++ /** A tool result went back (and every waiting message with it), or the turn ended. */+ cancel() {+ clearTimeout(this.timer);+ this.timer = undefined;+ }++ private fire() {+ const step = this.deps.running();+ if (!step) return void (this.timer = undefined);+ void this.deps.say(`Still in \`${step.title}\` (${fmtDuration(step.ms)}). I'll read your message when it finishes; start a message with \`!!\` to stop it now.`);+ }+}diff --git a/computer/src/runner/session.ts b/computer/src/runner/session.tsindex fdf6ed89..f426d7d4 100644--- a/computer/src/runner/session.ts+++ b/computer/src/runner/session.ts@@ -49,6 +49,7 @@ import type { TurnEvents } from './turn-events.js';import { Compaction } from './compaction.js';import { effortOf, speedOf, switchModel } from './model-switch.js';import { TurnCloser } from './turn-close.js';+import { HeldSteer } from './held-steer.js';export { SILENT, prompts };@@ -127,6 +128,7 @@ export class Session {(s) => this.hooks.secrets?.redact(s) ?? s,);private tools = new Map<string, { name: string; input: any }>();+ private heldSteer = new HeldSteer({ running: () => this.timeline.longestRunning(), say: (t) => this.say(t) });private thinking = new ThinkingCards(this.timeline, () => this.hooks.turns?.thinkingShown());readonly compaction = new Compaction(this.timeline, (f) => this.hooks.turns?.compacted(f), () => this.busy);readonly shadow: Compactor;@@ -225,7 +227,7 @@ export class Session {if (!stopping) this.hooks.api?.sent(text, userId, this.busy && !urgent, from);// Mid-turn messages land at the next tool boundary, like Claude Code's queue.Effect.runSync(h.send({ text, attachments: atts }, this.busy && !urgent ? 'steer' : 'queue'));- this.hooks.turns?.pushed(this.busy && !urgent);+ this.hooks.turns?.pushed(this.busy && !urgent), this.busy && !urgent && this.heldSteer.arm();if (!this.busy) this.addressed = mentioned === undefined || mentioned === true;// An addressed turn's message opens now, before the model answers (work 068); a steer's output follows its turn's.if (!this.busy && this.addressed) this.timeline.open();@@ -331,11 +333,7 @@ export class Session {private async pump(run: Running) {const record = (e: HarnessEvent) => {this.hooks.turns?.event(e), this.hooks.event?.(e), this.hooks.api?.event(e), this.compaction.observe(e);- try {- this.onEvent(e);- } catch (err) {- log.error('onEvent', err);- }+ try { this.onEvent(e); } catch (err) { log.error('onEvent', err); }};try {await Effect.runPromise(Stream.runForEach(run.harness.events, (e) => Effect.sync(() => record(e))));@@ -421,7 +419,7 @@ export class Session {case 'tool':return this.onTool(e);case 'tool_result':- return this.onToolResult(e);+ return this.heldSteer.cancel(), this.onToolResult(e);case 'task':return this.onTask(e);case 'turn_ended':@@ -517,7 +515,7 @@ export class Session {const silent = this.silent && !this.spoke && !failure;const reason = failure && (failure === 'error_during_execution' ? 'interrupted' : failure); // Claude Code's word for a stop (or a failure)this.hooks.turns?.ended(silent, failure), this.hooks.api?.ended(failure);- clearInterval(this.ticker);+ clearInterval(this.ticker), this.heldSteer.cancel();this.thinking.clear();this.timeline.endTurn(reason);this.history = this.held = undefined;diff --git a/computer/src/runner/system-prompt.ts b/computer/src/runner/system-prompt.tsindex 298816cb..8bfbc2dc 100644--- a/computer/src/runner/system-prompt.ts+++ b/computer/src/runner/system-prompt.ts@@ -18,7 +18,10 @@ You are being driven from Slack, not a terminal. The user watches your textstream live and sees each tool call as a timeline entry, so narrate brieflybetween steps; standard markdown renders. The user may send messages while youwork: treat them as steering from someone watching over your shoulder and-adjust immediately.+adjust immediately. Their messages reach you only between tool calls, so+never block in the foreground on something slow (\`gh run watch\`, sleep or+polling loops, \`--wait\` flags): run it in the background, say what you are+waiting on, and stay free to answer while it runs.Your readers are mostly engineers and other builders. A few principles shapehow you work with them:diff --git a/computer/src/runner/timeline.ts b/computer/src/runner/timeline.tsindex c21b2a2a..dfd47e5e 100644--- a/computer/src/runner/timeline.ts+++ b/computer/src/runner/timeline.ts@@ -270,6 +270,14 @@ export class Timeline {}}+ /** The step running longest and for how long: what a message sent mid-turn waits behind. */+ longestRunning() {+ for (const [id, t0] of this.started) {+ const t = this.tasks.get(id);+ if (t?.status === 'in_progress' && !t.waiting && !isThinking(t)) return { title: t.title, ms: Date.now() - t0 };+ }+ }+/** The turn is over: running steps show as interrupted, the run closes, the state clears. `failure`: why, for an unclaimed opening card. */endTurn(failure?: string) {if (this.opening) this.settleOpening(failure);