Files
captoys/good-fences/src/mower.ts
T
dckcandClaude Opus 5.5 8c110098ff feat(good-fences): a Think agent mows with a codemode mower connector
Neighbor is a Project Think agent on gpt-oss-120b. Its execute tool
runs model-written code in a dynamic worker; MowerConnector puts the
mower there as the `mower.*` namespace (start/push/turn/stop, each
taking an args object). makeMower is the Logo-turtle mower on a
wrapping yard; for now it lives inside the agent's DO.

Getting to green, one symptom at a time:
- chatted instead of acting: say it acts by running code
- reply cut mid-sentence: maxOutputTokens 4096 via beforeTurn
- execute failed creating codemode's runtime facet ("Incorrect type
  for the 'class' field"): declare CodemodeRuntime as a DO class
- looked for the mower in the workspace filesystem: activeTools
  ["execute"], and name the namespace in the prompt
- found the mower, then asked for lawn dimensions: "don't ask me
  questions: put it to use"

Green: 36 mower calls, a 30-cell rectangle.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-09 00:35:56 -05:00

51 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** @file The mower: Logo-turtle moves on a yard of cells. */
/** what a model is told about a mower: its type, with the moves explained */
export const aboutMower = {
ts: `interface Mower {
/** put the mower down, facing north, and cut the cell under it */
start(): Promise<void>;
/** move forward one cell (10 yards), cutting the cell it enters */
push(): Promise<void>;
/** turn right 90 degrees, in place */
turn(): Promise<void>;
/** park the mower */
stop(): Promise<void>;
}`,
};
const headings = [
[0, -1], // north
[1, 0], // east
[0, 1], // south
[-1, 0], // west
] as const;
/** a mower on a `width` × `height` yard, starting at `at`; pushing past an
* edge wraps to the other side (6d) */
export const makeMower = ({ width, height, at }: { width: number; height: number; at: { x: number; y: number } }) => {
let { x, y } = at;
let heading = 0;
const cut = new Set<string>();
const cutHere = () => cut.add(`${x},${y}`);
return {
start() {
heading = 0;
cutHere();
},
push() {
const [dx, dy] = headings[heading];
x = (x + dx + width) % width;
y = (y + dy + height) % height;
cutHere();
},
turn() {
heading = (heading + 1) % headings.length;
},
stop() {},
cutCells: () => [...cut],
};
};
export type Mower = ReturnType<typeof makeMower>;