# Code and working pages

The 10 tools for code and working pages. Before an agent first makes one, it reads guide topic code or pages.

## create_code

Put code in a space for people to read, edit together live and review: one or more files (a script, a module, a config, a small project). People see the files in a code editor, comment on lines, and see each version as a diff. Read guide topic "code" first. To make a web page or small app people can use, use create_page instead.

Parameters:
- `space_id` (string, required)
- `title` (string, required)
- `files` (object[], required)
- `message` (string): What this first version is, as a commit message.

## read_code

A code item's files as they are now, people's live edits included, and its version number. Pass paths to read only some; numbered: true puts line numbers in front of each line (what comments on lines refer to).

Parameters:
- `item_id` (string, required)
- `paths` (string[])
- `numbered` (boolean)

## edit_code

Change a code item's files while people may be editing them: everyone with it open sees the change at once, and it becomes a new version with your message (people see it as a diff in History). Read the files first (read_code). Prefer replace with the exact current text for small changes; write a whole file for new files or rewrites. All edits in one call are one version; if one can't apply, none do.

Parameters:
- `item_id` (string, required)
- `message` (string, required): What changed and why, as a commit message: "Validate the email before sending".
- `edits` (object[], required)

## code_history

The versions of a code item, a page or a report (its files), newest first: number, message, who made it (a person or an agent), when, and which files it changed. People's typing is grouped into one version per person until they pause for five minutes.

Parameters:
- `item_id` (string, required)

## code_diff

A unified diff (as git diff prints it) for a code item, a page or a report: what one version changed (version), or between two versions (from, to; to "now" for the files as they are this moment, people's typing included). Pass path for one file.

Parameters:
- `item_id` (string, required)
- `version` (integer): What this version changed, against the one before it.
- `from` (integer)
- `to` (integer | "now"): Default "now".
- `path` (string)

## code_restore

Put a code item's, a page's or a report's files back as they were in a version. It becomes a new version ("Restored version N"); nothing is lost — the versions after it stay in the history.

Parameters:
- `item_id` (string, required)
- `version` (integer, required)

## create_page

Make a working web page in a space: HTML, CSS and JavaScript that run when people open it — a calculator, a quiz, a tracker, an interactive chart, a game, a simulation, custom 3D, generative art. People use it live, see its code, comment on a part of it or a line, and see each version as a diff. Give index.html (where it starts); put CSS and JavaScript in it or in files beside it (style.css, app.js) that it links. It runs in a sandbox: no localStorage or cookies, and nothing from Artifacts; libraries load from a CDN by full URL. A prototype (a product or app people click through) or a website (a landing page, a site, pricing, docs, an article): before its first write, do the steps of guide topic "prototype" or "website" in order: a template's guide, its rules, one design system read whole, the template's example. It is never designed without them, however short or simple the request. Anything else: guide topic "pages", and page-design, page-games, page-3d, page-simulations or page-art for what it is. A prototype or a website is built one part at a time: give its head, the design system's whole :root block, its styles and first finished part; edit_page adds the rest, a part a call.  Run it with render_page and lint_page once it is whole.

Parameters:
- `space_id` (string, required)
- `title` (string, required)
- `kind` (string): When it is one: kept on the page, so whoever changes it later reads the right guide.
- `html` (string, required): index.html: a whole document. For a large page, its head, styles and first finished part; edit_page adds the rest.
- `files` (object[]): Files beside it: CSS, JavaScript, JSON, SVG.
- `message` (string)

## read_page

A working page's files (index.html and the files beside it) as they are now, people's live edits included, and its version number. numbered: true puts line numbers in front of each line.

Parameters:
- `item_id` (string, required)
- `paths` (string[])
- `numbered` (boolean)

## edit_page

Change a working page's files while people may be using or editing it (a prototype or a website, when it is still empty or is being redesigned: first the steps of guide topic "prototype" or "website", in order — a template's guide, its rules, one design system, the template's example — then one part a call): everyone with it open gets the new page at once, and it becomes a new version with your message. Same edits as edit_code (replace exact text, write a whole file, delete, rename); index.html stays. Run it with render_page after.

Parameters:
- `item_id` (string, required)
- `message` (string, required): What changed, as a commit message.
- `edits` (object[], required)

## render_page

Run a working page as people see it (scripts on) and check all of it in one call: JavaScript errors, console errors and failed requests; its layout at desktop and phone widths, in words (what sticks out of the frame, text cut off, images and fonts that did not load, small tap targets, leftover placeholders); and pictures of the whole page. For a prototype or a website it also gives the anti-slop findings and whether the page wears the space's brand or a design system: every must_fix is fixed before you hand over. Call it once the page is built, not after every edit. steps clicks and types through it in order — { click: "#add" }, { type: { selector: "#email", text: "a@b.co" } }, { press: "Enter" }, { scroll: 800 }, { wait: 1000 } — and shows it after them. Fix every JavaScript error before you hand a page over.

Parameters:
- `item_id` (string, required)
- `width` (integer): The width the pictures are taken at. Default 1280. The layout is checked at this width and at a phone's (390) either way.
- `height` (integer): Default 800.
- `from_y` (integer): Where the pictures start, in px from the top (default 0). A call shows the whole page, up to eight screens; a longer page says where to continue.
- `pictures` (boolean): false: errors and layout findings only, no pictures. For re-checking after a fix.
- `steps` (object[])
