rovecode 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +662 -0
- package/README.md +737 -0
- package/THIRD_PARTY_NOTICES.md +268 -0
- package/bin/rovecode.ts +21 -0
- package/package.json +56 -0
- package/src/acp/server.ts +374 -0
- package/src/cli/auth-login.ts +122 -0
- package/src/cli/connect.ts +244 -0
- package/src/cli/context-cmd.ts +199 -0
- package/src/cli/dispatch.ts +82 -0
- package/src/cli/doctor.ts +362 -0
- package/src/cli/export.ts +276 -0
- package/src/cli/help.ts +293 -0
- package/src/cli/is-tui-invocation.ts +8 -0
- package/src/cli/main.ts +583 -0
- package/src/cli/market-cmd.ts +658 -0
- package/src/cli/mcp-login.ts +141 -0
- package/src/cli/mcp-market-cmd.ts +302 -0
- package/src/cli/output.ts +382 -0
- package/src/cli/repl.ts +250 -0
- package/src/cli/repomap-root.ts +14 -0
- package/src/cli/resume.ts +57 -0
- package/src/cli/run-flags.ts +43 -0
- package/src/cli/run-limits.ts +78 -0
- package/src/cli/runtime.ts +931 -0
- package/src/cli/session-arg.ts +30 -0
- package/src/cli/sessions-cmd.ts +145 -0
- package/src/cli/setup.ts +153 -0
- package/src/cli/skills-cmd.ts +194 -0
- package/src/cli/start-chat.ts +65 -0
- package/src/cli/trust-cmd.ts +52 -0
- package/src/coding/bash.ts +148 -0
- package/src/coding/checkpoints.ts +327 -0
- package/src/coding/diff.ts +138 -0
- package/src/coding/files.ts +341 -0
- package/src/coding/hashline.ts +274 -0
- package/src/coding/lsp-gate.ts +254 -0
- package/src/coding/lsp-servers.ts +147 -0
- package/src/coding/lsp.ts +283 -0
- package/src/coding/repomap-cache.ts +99 -0
- package/src/coding/repomap-files.ts +192 -0
- package/src/coding/repomap.ts +481 -0
- package/src/core/agents.ts +255 -0
- package/src/core/compaction.ts +259 -0
- package/src/core/config.ts +289 -0
- package/src/core/context-report.ts +228 -0
- package/src/core/context.ts +60 -0
- package/src/core/count-remote.ts +107 -0
- package/src/core/execpolicy-rules.ts +196 -0
- package/src/core/execpolicy.ts +385 -0
- package/src/core/executor.ts +454 -0
- package/src/core/guardrails.ts +400 -0
- package/src/core/hooks.ts +411 -0
- package/src/core/images.ts +230 -0
- package/src/core/intro.ts +266 -0
- package/src/core/loop.ts +567 -0
- package/src/core/modes.ts +372 -0
- package/src/core/orchestrator.ts +245 -0
- package/src/core/proc-group.ts +48 -0
- package/src/core/project-trust.ts +98 -0
- package/src/core/reflection.ts +165 -0
- package/src/core/sandbox-config.ts +186 -0
- package/src/core/session-id.ts +24 -0
- package/src/core/session-images.ts +73 -0
- package/src/core/session-ops.ts +183 -0
- package/src/core/session-text.ts +29 -0
- package/src/core/session.ts +469 -0
- package/src/core/settings.ts +170 -0
- package/src/core/tasks.ts +646 -0
- package/src/core/token-scale.ts +108 -0
- package/src/core/tools.ts +309 -0
- package/src/core/trust.ts +104 -0
- package/src/core/types.ts +330 -0
- package/src/core/update-check.ts +171 -0
- package/src/core/usage.ts +204 -0
- package/src/core/validate.ts +121 -0
- package/src/core/verify-gate.ts +159 -0
- package/src/core/verify.ts +236 -0
- package/src/core/voice.ts +158 -0
- package/src/core/win-job.ts +183 -0
- package/src/core/workspace.ts +184 -0
- package/src/design/audit.ts +797 -0
- package/src/design/direction.ts +190 -0
- package/src/design/rules.ts +157 -0
- package/src/eval/bench.ts +150 -0
- package/src/eval/gauntlet-runner.ts +215 -0
- package/src/eval/gauntlet-support.ts +84 -0
- package/src/eval/gauntlet-wave3.ts +269 -0
- package/src/eval/gauntlet-wave4.ts +217 -0
- package/src/eval/gauntlet.ts +253 -0
- package/src/index.ts +17 -0
- package/src/lanes/agy.ts +95 -0
- package/src/lanes/approval.ts +24 -0
- package/src/lanes/claude.ts +129 -0
- package/src/lanes/codex.ts +127 -0
- package/src/lanes/events.ts +130 -0
- package/src/lanes/job.ts +142 -0
- package/src/lanes/opencode.ts +122 -0
- package/src/lanes/process.ts +184 -0
- package/src/lanes/progress.ts +183 -0
- package/src/lanes/registry.ts +178 -0
- package/src/lanes/runner.ts +124 -0
- package/src/lanes/types.ts +112 -0
- package/src/market/catalogs/mcp-docs.json +111 -0
- package/src/market/catalogs/plugins.json +111 -0
- package/src/market/catalogs/skills.json +478 -0
- package/src/market/clone.ts +72 -0
- package/src/market/context-cost.ts +121 -0
- package/src/market/digest.ts +106 -0
- package/src/market/index.ts +22 -0
- package/src/market/install.ts +578 -0
- package/src/market/manifest.ts +187 -0
- package/src/market/prereq.ts +145 -0
- package/src/market/registry.ts +363 -0
- package/src/market/resolve.ts +111 -0
- package/src/market/types.ts +236 -0
- package/src/market/validate.ts +227 -0
- package/src/mcp/client.ts +449 -0
- package/src/mcp/config.ts +252 -0
- package/src/mcp/local-package.ts +211 -0
- package/src/mcp/market-catalog.ts +84 -0
- package/src/mcp/market-install.ts +289 -0
- package/src/mcp/market.ts +362 -0
- package/src/mcp/oauth.ts +251 -0
- package/src/mcp/prompts-resources.ts +249 -0
- package/src/mcp/shared.ts +149 -0
- package/src/mcp/status.ts +67 -0
- package/src/mcp/tools.ts +275 -0
- package/src/mcp/transport.ts +122 -0
- package/src/mcp/trust.ts +25 -0
- package/src/memory/blocks.ts +278 -0
- package/src/memory/recall.ts +355 -0
- package/src/memory/scope.ts +182 -0
- package/src/memory/store.ts +105 -0
- package/src/memory/tools.ts +99 -0
- package/src/plugins/cli.ts +119 -0
- package/src/plugins/discover.ts +108 -0
- package/src/plugins/index.ts +50 -0
- package/src/plugins/install.ts +184 -0
- package/src/plugins/load.ts +124 -0
- package/src/plugins/manifest.ts +92 -0
- package/src/plugins/state.ts +83 -0
- package/src/providers/auth.ts +408 -0
- package/src/providers/cache.ts +223 -0
- package/src/providers/catalog-local.ts +160 -0
- package/src/providers/catalog.ts +421 -0
- package/src/providers/middleware-context.ts +86 -0
- package/src/providers/middleware.ts +373 -0
- package/src/providers/model-list.ts +23 -0
- package/src/providers/models-index.json +1 -0
- package/src/providers/oauth/common.ts +105 -0
- package/src/providers/oauth/device-code.ts +107 -0
- package/src/providers/oauth/github-copilot.ts +146 -0
- package/src/providers/oauth/loopback.ts +158 -0
- package/src/providers/oauth/openai.ts +163 -0
- package/src/providers/oauth/openrouter.ts +89 -0
- package/src/providers/oauth/pkce.ts +45 -0
- package/src/providers/oauth/registry.ts +39 -0
- package/src/providers/oauth/seam.ts +89 -0
- package/src/providers/profile-glm53.ts +111 -0
- package/src/providers/profile-sonnet5-persona.ts +65 -0
- package/src/providers/profile-sonnet5-voice.ts +23 -0
- package/src/providers/profiles.ts +156 -0
- package/src/providers/provider-config.ts +311 -0
- package/src/providers/registry.ts +333 -0
- package/src/providers/responses.ts +209 -0
- package/src/providers/retry.ts +234 -0
- package/src/providers/router.ts +294 -0
- package/src/providers/sse.ts +26 -0
- package/src/providers/stream-errors.ts +117 -0
- package/src/providers/stream.ts +566 -0
- package/src/providers/thinking.ts +189 -0
- package/src/providers/wire-messages.ts +129 -0
- package/src/providers/wire-responses.ts +79 -0
- package/src/providers/wire-select.ts +53 -0
- package/src/server/http.ts +291 -0
- package/src/server/openapi.ts +246 -0
- package/src/sextant/card-hits.ts +102 -0
- package/src/sextant/card-keys.ts +55 -0
- package/src/sextant/context-source.ts +157 -0
- package/src/sextant/crew-cards.ts +350 -0
- package/src/sextant/draw-agents.ts +273 -0
- package/src/sextant/draw-code.ts +388 -0
- package/src/sextant/draw-context.ts +222 -0
- package/src/sextant/draw-frame.ts +164 -0
- package/src/sextant/draw-market.ts +573 -0
- package/src/sextant/draw-messages.ts +386 -0
- package/src/sextant/draw-pet.ts +230 -0
- package/src/sextant/draw-plan.ts +187 -0
- package/src/sextant/draw-tabs.ts +85 -0
- package/src/sextant/draw-util.ts +65 -0
- package/src/sextant/draw-wizard.ts +378 -0
- package/src/sextant/engine.ts +230 -0
- package/src/sextant/frame-hits.ts +25 -0
- package/src/sextant/frame.ts +101 -0
- package/src/sextant/git-status.ts +197 -0
- package/src/sextant/grid.ts +59 -0
- package/src/sextant/input.ts +119 -0
- package/src/sextant/keys.ts +521 -0
- package/src/sextant/layout.ts +86 -0
- package/src/sextant/local-commands.ts +169 -0
- package/src/sextant/market-source.ts +287 -0
- package/src/sextant/mentions.ts +200 -0
- package/src/sextant/message-hits.ts +26 -0
- package/src/sextant/model.ts +387 -0
- package/src/sextant/overlays.ts +456 -0
- package/src/sextant/panel-hits.ts +38 -0
- package/src/sextant/pet.ts +399 -0
- package/src/sextant/screen.ts +324 -0
- package/src/sextant/scroll-hits.ts +66 -0
- package/src/sextant/scrollbar.ts +82 -0
- package/src/sextant/sextant-bridge.ts +174 -0
- package/src/sextant/sextant-cards.ts +142 -0
- package/src/sextant/sextant-diff-base.ts +63 -0
- package/src/sextant/sextant-files.ts +154 -0
- package/src/sextant/sextant-frame-loop.ts +335 -0
- package/src/sextant/sextant-renderer.ts +574 -0
- package/src/sextant/sextant-repo.ts +140 -0
- package/src/sextant/theme.ts +66 -0
- package/src/sextant/tool-rows.ts +189 -0
- package/src/sextant/types.ts +493 -0
- package/src/skills/index.ts +387 -0
- package/src/skills/pack.ts +220 -0
- package/src/skills/spec.ts +162 -0
- package/src/skills/tools.ts +69 -0
- package/src/skills/versioned.ts +227 -0
- package/src/telemetry/otel-export.ts +122 -0
- package/src/telemetry/otel-lanes.ts +89 -0
- package/src/telemetry/otel-logs.ts +131 -0
- package/src/telemetry/otel-metrics.ts +136 -0
- package/src/telemetry/otel.ts +397 -0
- package/src/telemetry/otlp.ts +76 -0
- package/src/tools/ask-user.ts +156 -0
- package/src/tools/bash-bg.ts +94 -0
- package/src/tools/bash-jobs.ts +237 -0
- package/src/tools/design.ts +151 -0
- package/src/tools/evalcell.ts +338 -0
- package/src/tools/html-text.ts +139 -0
- package/src/tools/provider.ts +149 -0
- package/src/tools/task.ts +250 -0
- package/src/tools/todo.ts +320 -0
- package/src/tools/webfetch.ts +332 -0
- package/src/tools/websearch.ts +359 -0
- package/src/tui/agents-cmd.ts +41 -0
- package/src/tui/app.ts +749 -0
- package/src/tui/attach.ts +127 -0
- package/src/tui/boot-notes.ts +41 -0
- package/src/tui/builtin-prompts.ts +59 -0
- package/src/tui/checkpoints-cmd.ts +70 -0
- package/src/tui/clipboard-image.ts +81 -0
- package/src/tui/clipboard.ts +78 -0
- package/src/tui/commands.ts +283 -0
- package/src/tui/config-view.ts +53 -0
- package/src/tui/context-cmds.ts +282 -0
- package/src/tui/cost.ts +108 -0
- package/src/tui/crash-guard.ts +173 -0
- package/src/tui/focus-terminal.ts +34 -0
- package/src/tui/git-cmds.ts +273 -0
- package/src/tui/git-plain.ts +58 -0
- package/src/tui/info-cmd.ts +150 -0
- package/src/tui/input-plain.ts +76 -0
- package/src/tui/mcp-cmd.ts +128 -0
- package/src/tui/memory-note.ts +77 -0
- package/src/tui/modes-cmd.ts +45 -0
- package/src/tui/notify-seq.ts +100 -0
- package/src/tui/notify.ts +318 -0
- package/src/tui/overlays.ts +97 -0
- package/src/tui/pi-renderer.ts +428 -0
- package/src/tui/providers-cmd.ts +377 -0
- package/src/tui/reasoning-view.ts +56 -0
- package/src/tui/renderer.ts +128 -0
- package/src/tui/replay-marker.ts +29 -0
- package/src/tui/session-cmd.ts +148 -0
- package/src/tui/session-manage.ts +95 -0
- package/src/tui/sextant-attach.ts +102 -0
- package/src/tui/sextant-io.ts +202 -0
- package/src/tui/sextant-smoke.ts +110 -0
- package/src/tui/shell-cmd.ts +158 -0
- package/src/tui/smoke.ts +72 -0
- package/src/tui/staged-terminal.ts +50 -0
- package/src/tui/startup.ts +12 -0
- package/src/tui/theme.ts +59 -0
- package/src/tui/todo-label.ts +7 -0
- package/src/tui/trust-card.ts +107 -0
- package/src/tui/tui-commands.ts +87 -0
- package/tsconfig.json +30 -0
- package/vendor/pi-tui/LICENSE +21 -0
- package/vendor/pi-tui/PATCHES.md +12 -0
- package/vendor/pi-tui/PROVENANCE.md +12 -0
- package/vendor/pi-tui/README.upstream.md +854 -0
- package/vendor/pi-tui/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
- package/vendor/pi-tui/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
- package/vendor/pi-tui/src/alt-screen-search.ts +158 -0
- package/vendor/pi-tui/src/autocomplete.ts +827 -0
- package/vendor/pi-tui/src/components/alt-screen-flash.ts +52 -0
- package/vendor/pi-tui/src/components/box.ts +138 -0
- package/vendor/pi-tui/src/components/cancellable-loader.ts +41 -0
- package/vendor/pi-tui/src/components/editor.ts +2364 -0
- package/vendor/pi-tui/src/components/h-stack.ts +45 -0
- package/vendor/pi-tui/src/components/image.ts +128 -0
- package/vendor/pi-tui/src/components/input.ts +448 -0
- package/vendor/pi-tui/src/components/loader.ts +93 -0
- package/vendor/pi-tui/src/components/markdown.ts +1016 -0
- package/vendor/pi-tui/src/components/scroll-view.ts +217 -0
- package/vendor/pi-tui/src/components/select-list.ts +230 -0
- package/vendor/pi-tui/src/components/settings-list.ts +277 -0
- package/vendor/pi-tui/src/components/spacer.ts +29 -0
- package/vendor/pi-tui/src/components/stack.ts +155 -0
- package/vendor/pi-tui/src/components/text.ts +108 -0
- package/vendor/pi-tui/src/components/truncated-text.ts +66 -0
- package/vendor/pi-tui/src/components/v-stack.ts +34 -0
- package/vendor/pi-tui/src/editor-component.ts +75 -0
- package/vendor/pi-tui/src/fuzzy.ts +138 -0
- package/vendor/pi-tui/src/index.ts +149 -0
- package/vendor/pi-tui/src/keybindings.ts +321 -0
- package/vendor/pi-tui/src/keys.ts +1402 -0
- package/vendor/pi-tui/src/kill-ring.ts +47 -0
- package/vendor/pi-tui/src/latex.ts +1381 -0
- package/vendor/pi-tui/src/layout-node.ts +52 -0
- package/vendor/pi-tui/src/layout.ts +411 -0
- package/vendor/pi-tui/src/native-modifiers.ts +60 -0
- package/vendor/pi-tui/src/native-module-path.ts +32 -0
- package/vendor/pi-tui/src/stdin-buffer.ts +445 -0
- package/vendor/pi-tui/src/terminal-colors.ts +74 -0
- package/vendor/pi-tui/src/terminal-image.ts +701 -0
- package/vendor/pi-tui/src/terminal.ts +554 -0
- package/vendor/pi-tui/src/tui-alt-screen.ts +1379 -0
- package/vendor/pi-tui/src/tui-main-screen.ts +655 -0
- package/vendor/pi-tui/src/tui.ts +1264 -0
- package/vendor/pi-tui/src/undo-stack.ts +29 -0
- package/vendor/pi-tui/src/utils.ts +1327 -0
- package/vendor/pi-tui/src/word-navigation.ts +118 -0
- package/vendor/pi-tui/test/test-themes.ts +39 -0
- package/vendor/pi-tui/test/virtual-terminal.ts +219 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/** The project's chosen design direction, recorded once and then honoured.
|
|
2
|
+
*
|
|
3
|
+
* Berkay's standing rule is "Tasarimda varsayilan yok" — no carried-over palette, no safe font,
|
|
4
|
+
* no direction picked by the tool. So rovecode ships NO default look. What it ships is a protocol:
|
|
5
|
+
* before the first UI is written, the agent proposes distinct directions, the HUMAN picks one, and
|
|
6
|
+
* the choice is written here. Every later piece of UI in the project is measured against it.
|
|
7
|
+
*
|
|
8
|
+
* Why persist it at all: without a record the second screen drifts from the first, and "consistent"
|
|
9
|
+
* degrades into "whatever the model remembered". With it, design_audit can report DEVIATION (a font
|
|
10
|
+
* that is not the chosen font) rather than only taste, which is the part a machine can actually judge.
|
|
11
|
+
*
|
|
12
|
+
* The file is <cwd>/.rovecode/design.json. It is deliberately per-project and never global: a global
|
|
13
|
+
* design file would be exactly the "carried over from the last job" default the rule forbids. */
|
|
14
|
+
|
|
15
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
16
|
+
import { dirname, join } from "node:path";
|
|
17
|
+
|
|
18
|
+
export const DESIGN_FILE = "design.json";
|
|
19
|
+
|
|
20
|
+
/** How corners read. Recorded because "no radius anywhere" is a finding UNLESS it was the choice. */
|
|
21
|
+
export type Corners = "sharp" | "soft" | "round";
|
|
22
|
+
/** How the page is composed. Recorded because centred-everything is a finding UNLESS it was the choice. */
|
|
23
|
+
export type Layout = "centered" | "left" | "asymmetric" | "grid";
|
|
24
|
+
/** How tightly the page is packed. Recorded because "airy" and "tight" want opposite spacing scales,
|
|
25
|
+
* and a model with no record of which regresses to the mode on every screen. */
|
|
26
|
+
export type Density = "tight" | "regular" | "airy";
|
|
27
|
+
|
|
28
|
+
export interface DesignDirection {
|
|
29
|
+
/** short name of the direction, as it was presented to the human ("lacivert band + beyaz govde") */
|
|
30
|
+
name: string;
|
|
31
|
+
/** one line: why this direction suits this product */
|
|
32
|
+
rationale?: string;
|
|
33
|
+
/** the palette as chosen — free-form keys so a direction is not forced into a fixed slot set */
|
|
34
|
+
palette?: Record<string, string>;
|
|
35
|
+
/** typefaces as chosen, by ROLE: `display`, `text`, and any role the direction needs (`label`,
|
|
36
|
+
* `mono`, …). Free-form keys on purpose: a chart-style direction has condensed map labels as a
|
|
37
|
+
* first-class role, and every face named here is exempt from the cliché-font check. */
|
|
38
|
+
typeface?: Record<string, string>;
|
|
39
|
+
corners?: Corners;
|
|
40
|
+
layout?: Layout;
|
|
41
|
+
|
|
42
|
+
/* The axes below were added on docs/design-slop-research.md §6.3. The argument for them is not that
|
|
43
|
+
* the auditor needs more fields: it is that an unspecified requirement is inferred correctly only
|
|
44
|
+
* 41.1% of the time and underspecified prompts are twice as likely to fail when conditions change
|
|
45
|
+
* (Yang et al., arXiv:2505.13360). Every axis this file leaves blank regresses to the training mode
|
|
46
|
+
* on EVERY call, which is where a second screen drifts from the first. All optional: a direction that
|
|
47
|
+
* says nothing about motion is a direction that has not decided about motion, not an invalid one. */
|
|
48
|
+
|
|
49
|
+
/** the page's blocks in order, as the human chose them ("hero, proof, problems, pricing, faq") */
|
|
50
|
+
sectionOrder?: string[];
|
|
51
|
+
/** the hero pattern by name, so "is this the hero we chose" becomes answerable */
|
|
52
|
+
heroPattern?: string;
|
|
53
|
+
/** the type scale as chosen, in px or rem steps — the count and the gaps, not a ratio */
|
|
54
|
+
typeScale?: number[];
|
|
55
|
+
/** how tightly the page is packed */
|
|
56
|
+
density?: Density;
|
|
57
|
+
/** the motion rule in the human's words ("one entrance per section, no loops") */
|
|
58
|
+
motion?: string;
|
|
59
|
+
/** the copy register ("technical, names and numbers, no marketing verbs") */
|
|
60
|
+
copyRegister?: string;
|
|
61
|
+
|
|
62
|
+
/** anything the audit cannot infer: imagery, what to avoid in THIS project */
|
|
63
|
+
notes?: string;
|
|
64
|
+
/** ISO date the human chose it */
|
|
65
|
+
chosenAt?: string;
|
|
66
|
+
|
|
67
|
+
/* Headless runs. `ask_user` needs a human on the other end; in a one-shot `rovecode run` there is
|
|
68
|
+
* none, so an agent that must ship a page either stalls or — measured, 2026-09-04 — picks a
|
|
69
|
+
* direction itself and records it as though a human had chosen. The second is worse than the first:
|
|
70
|
+
* it launders the agent's taste into the one file whose whole job is to hold the HUMAN's choice, and
|
|
71
|
+
* every later screen is then measured against a default nobody picked. So the record carries who
|
|
72
|
+
* chose. A provisional direction is honoured exactly like a chosen one while it stands — the point
|
|
73
|
+
* is not to weaken it, only to stop it from silently becoming permanent. */
|
|
74
|
+
|
|
75
|
+
/** true when no human could answer and the agent built to one direction to get unblocked */
|
|
76
|
+
provisional?: boolean;
|
|
77
|
+
/** who chose it. Absent means a human did (every record written before this field existed). */
|
|
78
|
+
chosenBy?: "human" | "agent";
|
|
79
|
+
/** the directions NOT built, by name — what the next interactive session offers instead */
|
|
80
|
+
alternatives?: string[];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function designPath(cwd: string): string {
|
|
84
|
+
return join(cwd, ".rovecode", DESIGN_FILE);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const str = (v: unknown): string | undefined => (typeof v === "string" && v.trim().length > 0 ? v.trim() : undefined);
|
|
88
|
+
|
|
89
|
+
const CORNERS: readonly string[] = ["sharp", "soft", "round"];
|
|
90
|
+
const LAYOUTS: readonly string[] = ["centered", "left", "asymmetric", "grid"];
|
|
91
|
+
const DENSITIES: readonly string[] = ["tight", "regular", "airy"];
|
|
92
|
+
|
|
93
|
+
/** Parse a raw record into a direction, dropping anything malformed rather than throwing: a
|
|
94
|
+
* hand-edited design.json with one bad field must not take the whole run down. Returns null when
|
|
95
|
+
* there is no usable direction at all (no name). */
|
|
96
|
+
export function parseDirection(raw: unknown): DesignDirection | null {
|
|
97
|
+
if (typeof raw !== "object" || raw === null) return null;
|
|
98
|
+
const r = raw as Record<string, unknown>;
|
|
99
|
+
const name = str(r["name"]);
|
|
100
|
+
if (name === undefined) return null;
|
|
101
|
+
const out: DesignDirection = { name };
|
|
102
|
+
const rationale = str(r["rationale"]); if (rationale !== undefined) out.rationale = rationale;
|
|
103
|
+
const notes = str(r["notes"]); if (notes !== undefined) out.notes = notes;
|
|
104
|
+
const chosenAt = str(r["chosenAt"]); if (chosenAt !== undefined) out.chosenAt = chosenAt;
|
|
105
|
+
const corners = str(r["corners"])?.toLowerCase();
|
|
106
|
+
if (corners !== undefined && CORNERS.includes(corners)) out.corners = corners as Corners;
|
|
107
|
+
const layout = str(r["layout"])?.toLowerCase();
|
|
108
|
+
if (layout !== undefined && LAYOUTS.includes(layout)) out.layout = layout as Layout;
|
|
109
|
+
if (typeof r["palette"] === "object" && r["palette"] !== null) {
|
|
110
|
+
const pal: Record<string, string> = {};
|
|
111
|
+
for (const [k, v] of Object.entries(r["palette"] as Record<string, unknown>)) {
|
|
112
|
+
const s = str(v); if (s !== undefined) pal[k] = s;
|
|
113
|
+
}
|
|
114
|
+
if (Object.keys(pal).length > 0) out.palette = pal;
|
|
115
|
+
}
|
|
116
|
+
if (typeof r["typeface"] === "object" && r["typeface"] !== null) {
|
|
117
|
+
const tf: Record<string, string> = {};
|
|
118
|
+
for (const [k, v] of Object.entries(r["typeface"] as Record<string, unknown>)) {
|
|
119
|
+
const s = str(v); if (s !== undefined) tf[k] = s;
|
|
120
|
+
}
|
|
121
|
+
if (Object.keys(tf).length > 0) out.typeface = tf;
|
|
122
|
+
}
|
|
123
|
+
// the §6.3 axes. Same discipline as everything above: a malformed field is dropped, never thrown on,
|
|
124
|
+
// so one bad hand-edit costs that axis and not the run.
|
|
125
|
+
if (r["provisional"] === true) out.provisional = true;
|
|
126
|
+
const chosenBy = str(r["chosenBy"])?.toLowerCase();
|
|
127
|
+
if (chosenBy === "human" || chosenBy === "agent") out.chosenBy = chosenBy;
|
|
128
|
+
if (Array.isArray(r["alternatives"])) {
|
|
129
|
+
const alts = r["alternatives"].map(str).filter((x): x is string => x !== undefined);
|
|
130
|
+
if (alts.length > 0) out.alternatives = alts;
|
|
131
|
+
}
|
|
132
|
+
const heroPattern = str(r["heroPattern"]); if (heroPattern !== undefined) out.heroPattern = heroPattern;
|
|
133
|
+
const motion = str(r["motion"]); if (motion !== undefined) out.motion = motion;
|
|
134
|
+
const copyRegister = str(r["copyRegister"]); if (copyRegister !== undefined) out.copyRegister = copyRegister;
|
|
135
|
+
const density = str(r["density"])?.toLowerCase();
|
|
136
|
+
if (density !== undefined && DENSITIES.includes(density)) out.density = density as Density;
|
|
137
|
+
if (Array.isArray(r["sectionOrder"])) {
|
|
138
|
+
const secs = r["sectionOrder"].map(str).filter((s): s is string => s !== undefined);
|
|
139
|
+
if (secs.length > 0) out.sectionOrder = secs;
|
|
140
|
+
}
|
|
141
|
+
if (Array.isArray(r["typeScale"])) {
|
|
142
|
+
const steps = r["typeScale"].filter((n): n is number => typeof n === "number" && Number.isFinite(n) && n > 0);
|
|
143
|
+
if (steps.length > 0) out.typeScale = steps;
|
|
144
|
+
}
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** The recorded direction, or null when this project has not chosen one yet. Never throws. */
|
|
149
|
+
export function loadDirection(cwd: string): DesignDirection | null {
|
|
150
|
+
const p = designPath(cwd);
|
|
151
|
+
if (!existsSync(p)) return null;
|
|
152
|
+
try { return parseDirection(JSON.parse(readFileSync(p, "utf8"))); } catch { return null; }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Write the direction the human chose. Returns the path written. */
|
|
156
|
+
export function saveDirection(cwd: string, d: DesignDirection): string {
|
|
157
|
+
const p = designPath(cwd);
|
|
158
|
+
mkdirSync(dirname(p), { recursive: true });
|
|
159
|
+
const body: DesignDirection = { ...d, chosenAt: d.chosenAt ?? new Date().toISOString().slice(0, 10) };
|
|
160
|
+
writeFileSync(p, JSON.stringify(body, null, 2) + "\n");
|
|
161
|
+
return p;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** The direction as prompt text — what the agent must stay faithful to. Empty string when none. */
|
|
165
|
+
export function renderDirection(d: DesignDirection | null): string {
|
|
166
|
+
if (d === null) return "";
|
|
167
|
+
const lines: string[] = d.provisional === true
|
|
168
|
+
? [`PROVISIONAL direction: ${d.name}${d.chosenAt ? ` (recorded ${d.chosenAt})` : ""} — chosen by the agent, no human was available.`,
|
|
169
|
+
"Build to it, but ask the human once before the next screen: this is the one decision that is theirs."]
|
|
170
|
+
: [`Chosen direction: ${d.name}${d.chosenAt ? ` (chosen ${d.chosenAt})` : ""}`];
|
|
171
|
+
if (d.rationale !== undefined) lines.push(`Why: ${d.rationale}`);
|
|
172
|
+
if (d.palette !== undefined) lines.push(`Palette: ${Object.entries(d.palette).map(([k, v]) => `${k} ${v}`).join(", ")}`);
|
|
173
|
+
if (d.typeface !== undefined) {
|
|
174
|
+
const roles = Object.entries(d.typeface);
|
|
175
|
+
const faces = new Set(roles.map(([, f]) => f));
|
|
176
|
+
// one face everywhere reads as one name; otherwise each role names its face
|
|
177
|
+
lines.push(`Typefaces: ${faces.size === 1 ? roles[0]![1] : roles.map(([role, f]) => `${f} for ${role}`).join(", ")}`);
|
|
178
|
+
}
|
|
179
|
+
if (d.corners !== undefined) lines.push(`Corners: ${d.corners}`);
|
|
180
|
+
if (d.layout !== undefined) lines.push(`Composition: ${d.layout}`);
|
|
181
|
+
if (d.density !== undefined) lines.push(`Density: ${d.density}`);
|
|
182
|
+
if (d.sectionOrder !== undefined) lines.push(`Section order: ${d.sectionOrder.join(" -> ")}`);
|
|
183
|
+
if (d.heroPattern !== undefined) lines.push(`Hero: ${d.heroPattern}`);
|
|
184
|
+
if (d.typeScale !== undefined) lines.push(`Type scale: ${d.typeScale.join(", ")}`);
|
|
185
|
+
if (d.motion !== undefined) lines.push(`Motion: ${d.motion}`);
|
|
186
|
+
if (d.copyRegister !== undefined) lines.push(`Copy register: ${d.copyRegister}`);
|
|
187
|
+
if (d.notes !== undefined) lines.push(`Notes: ${d.notes}`);
|
|
188
|
+
if (d.alternatives !== undefined) lines.push(`Not built: ${d.alternatives.join(", ")}`);
|
|
189
|
+
return lines.join("\n");
|
|
190
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/** The design section of the system prompt (cli/runtime.ts buildDef appends it after the base prompt
|
|
2
|
+
* and any model profile).
|
|
3
|
+
*
|
|
4
|
+
* What this section deliberately does NOT contain: a palette, a typeface, a layout, or any other
|
|
5
|
+
* "good default". Berkay's standing rule is "Tasarimda varsayilan yok" — every project decides colour,
|
|
6
|
+
* type and layout again, nothing carries over from the last job. A built-in default look would be the
|
|
7
|
+
* exact failure being complained about: it would make every rovecode site resemble every other one.
|
|
8
|
+
*
|
|
9
|
+
* So the section carries two things a default cannot give you:
|
|
10
|
+
* 1. A PROTOCOL. Before the first interface in a project, propose distinct directions and let the
|
|
11
|
+
* human choose; record the choice; hold to it afterwards. Asked once per project, not per task
|
|
12
|
+
* (the record in .rovecode/design.json is what makes "once" possible).
|
|
13
|
+
* 2. A BAN LIST, drawn from what Berkay actually pointed at: amber accents, the reflex hero,
|
|
14
|
+
* unrelated typefaces, hairlines everywhere, everything square, everything centred.
|
|
15
|
+
*
|
|
16
|
+
* The ban list is phrased as "these are the defaults you fall into", not as "these are forbidden
|
|
17
|
+
* forever" — a project that deliberately chooses sharp corners records that, and design_audit stops
|
|
18
|
+
* reporting it. A rule with no escape hatch gets ignored wholesale.
|
|
19
|
+
*
|
|
20
|
+
* Pinned by test/unit/design-rules.test.ts: no palette or font is prescribed, every complaint is
|
|
21
|
+
* covered, and the text names the two tools. */
|
|
22
|
+
|
|
23
|
+
import { loadDirection, renderDirection } from "./direction.ts";
|
|
24
|
+
|
|
25
|
+
/** The always-on part: the protocol and the ban list. Contains no colour, font or layout choice. */
|
|
26
|
+
export const DESIGN_RULES: string = [
|
|
27
|
+
"# Interface design",
|
|
28
|
+
"",
|
|
29
|
+
"This applies whenever you build or change a user interface — a page, a screen, a component, a theme.",
|
|
30
|
+
"",
|
|
31
|
+
"## Decide the direction with the human, once per project",
|
|
32
|
+
"",
|
|
33
|
+
"There is no default look. Colour, typeface and layout are decided per project and nothing carries",
|
|
34
|
+
"over from another project.",
|
|
35
|
+
"",
|
|
36
|
+
"This question is about NEW work: a page, screen or component that is not on the screen yet. A change",
|
|
37
|
+
"to something that already exists is not this question. \"Make the background black\", \"add a shadow to",
|
|
38
|
+
"the text\", \"make this bigger\", a new state on an existing screen, a colour swapped on an existing",
|
|
39
|
+
"button: do it, now, in the direction the existing code already shows, and do not stop at a proposal,",
|
|
40
|
+
"whether or not this project has a recorded direction. The test is simple: if the person could point at",
|
|
41
|
+
"the thing on the screen, it exists and you change it; if they could not, it is new and the direction is",
|
|
42
|
+
"decided first. When the change would contradict a recorded direction, make the change and say so in one",
|
|
43
|
+
"line, so the human can decide whether the direction moves.",
|
|
44
|
+
"",
|
|
45
|
+
"- If this project has no recorded direction and you are about to write NEW UI, stop and propose THREE",
|
|
46
|
+
" directions first. For each: the palette (as hex), the typefaces, how it composes the page, and the",
|
|
47
|
+
" specific fact about THIS product that justifies it.",
|
|
48
|
+
"- Three directions are distinct only if they disagree on ALL FOUR of these axes; if two agree on the",
|
|
49
|
+
" second or third they will converge however different their prose sounds, because those two decide",
|
|
50
|
+
" the structure:",
|
|
51
|
+
" 1. what the first screen is MADE OF (real output? prose? an instrument? an image?)",
|
|
52
|
+
" 2. what carries HIERARCHY (type scale? density? monospace rhythm? boxes? colour?)",
|
|
53
|
+
" 3. what COLOUR is FOR (functional only? near-absent with one accent? state semantics? mood?)",
|
|
54
|
+
" 4. what counts as PROOF (real runs? tables and footnotes? live numbers? testimony?)",
|
|
55
|
+
" Asking yourself once for three ideas tends to return one idea three times; derive each direction",
|
|
56
|
+
" from a different source of form instead, then check the four axes.",
|
|
57
|
+
"- Worked example for a developer tool, as an example and not a menu — the right sources of form for a",
|
|
58
|
+
" payments product or a magazine are different, and if you cannot name the product fact that justifies",
|
|
59
|
+
" an anchor, it is the wrong anchor for this project:",
|
|
60
|
+
" A. ITS OWN OUTPUT — the page is made of what the tool produces: a real transcript or diff as the",
|
|
61
|
+
" first screen, hierarchy from monospace rhythm, colour functional only (add/remove, exit status),",
|
|
62
|
+
" proof = actual runs. Forbids itself stock illustration and invented copy. Even here the first",
|
|
63
|
+
" screen still SAYS what the product is, in one visible line above or beside the output — a",
|
|
64
|
+
" caption, not a hero. A transcript a stranger cannot name is a demo, not a page, and an",
|
|
65
|
+
" sr-only h1 is not that line: it has to be visible.",
|
|
66
|
+
" B. THE MANUAL — a technical document that happens to be a web page: a stated claim in a long",
|
|
67
|
+
" measure plus a spec table, hierarchy from type scale and space alone, colour nearly absent",
|
|
68
|
+
" with one accent, proof = tables and versioned facts. Forbids itself cards, the headline-plus-",
|
|
69
|
+
" two-buttons pair, the three-column feature grid.",
|
|
70
|
+
" C. THE INSTRUMENT — a dense panel a professional reads at a glance: a live status surface first,",
|
|
71
|
+
" hierarchy from density contrast and a visible grid, colour carrying state (ok/warn/fail),",
|
|
72
|
+
" proof = numbers in place. Forbids itself marketing whitespace and decorative motion.",
|
|
73
|
+
"- The anchor fixes the organising idea and the structure, NOT the palette or the mode: the seed colour",
|
|
74
|
+
" and light/dark are chosen independently of it. \"Terminal\" is not a licence for dark-plus-green;",
|
|
75
|
+
" that would be a default smuggled in through the back door.",
|
|
76
|
+
"- Let the human choose. Do not build while the question is open, and do not pick for them.",
|
|
77
|
+
"- Keep each option LABEL to 60 characters or less — a letter and the direction's name (\"A. Its own",
|
|
78
|
+
" output\"). The four axes, the palette and the rationale go in the question body, not the label:",
|
|
79
|
+
" ask_user truncates a long option and the human then chooses between three cut-off phrases.",
|
|
80
|
+
"- WHEN NOTHING CAN ASK A HUMAN (a headless `rovecode run`, no terminal): do not stall, and do not",
|
|
81
|
+
" quietly promote your own pick to a decision. Build ONE direction and record it as provisional —",
|
|
82
|
+
" `design_direction set` with `provisional: true` and the other two names in `alternatives`. Then say",
|
|
83
|
+
" so in your final summary: which one you built, which two you did not, and that the choice is still",
|
|
84
|
+
" theirs. The next interactive session asks the question once before writing more UI.",
|
|
85
|
+
"- Once they choose, record it with the `design_direction` tool. That is what makes this a",
|
|
86
|
+
" once-per-project question instead of a once-per-task one.",
|
|
87
|
+
"- When a direction is already recorded, do NOT re-ask. Build to it. Propose a change only if the",
|
|
88
|
+
" work genuinely cannot be done within it, and say why. The one exception: a direction recorded as",
|
|
89
|
+
" PROVISIONAL was chosen by an agent, not a human — ask once, in the first interactive session that",
|
|
90
|
+
" touches UI, before building more; then record the answer with `provisional` dropped.",
|
|
91
|
+
"",
|
|
92
|
+
"## The defaults to climb out of",
|
|
93
|
+
"",
|
|
94
|
+
"These are what generated interfaces look like when nobody decided anything. Recognise them in your",
|
|
95
|
+
"own output:",
|
|
96
|
+
"",
|
|
97
|
+
"- Amber, orange and gold as the accent. It is the reflex accent; choose one that belongs to the product.",
|
|
98
|
+
"- A full-viewport hero with a big headline and two buttons, on a page that had no reason for one.",
|
|
99
|
+
" A hero costs the reader an entire screen — spend it only on an image or an idea that earns it.",
|
|
100
|
+
"- Typefaces with no relationship to the product: Inter, Roboto, Poppins, Montserrat and the rest of",
|
|
101
|
+
" the set that arrives when no one picked. What matters is the face you LOAD — an import, an",
|
|
102
|
+
" @font-face, a fonts URL — because that is where the decision is; a system stack sitting behind your",
|
|
103
|
+
" chosen face is a fallback, not a choice, and neither is a face merely named in prose. Pick the face",
|
|
104
|
+
" you load for a reason you can state. And if you name a face in CSS, LOAD it — a link, an @import,",
|
|
105
|
+
" an @font-face or a framework font import — or drop the name: a named-but-unloaded face renders as",
|
|
106
|
+
" its fallback, so the page does not look the way the code says it does. That is no decision at all,",
|
|
107
|
+
" and `design_audit` reports it as `font-named-not-loaded`.",
|
|
108
|
+
"- Hairlines everywhere: a border around every card, a rule between every row. Separation reads better",
|
|
109
|
+
" from spacing, weight, size and background than from drawn lines.",
|
|
110
|
+
"- Everything square. Corner treatment is a decision; make it once, deliberately, either way.",
|
|
111
|
+
"- Everything centred. Centring every block removes the alignment edge the eye follows down the page",
|
|
112
|
+
" and flattens the hierarchy — most content wants an edge to sit against.",
|
|
113
|
+
"- Every fact at the same size in one long column. Decide what is most important and let the layout",
|
|
114
|
+
" say so; a page where everything shouts says nothing.",
|
|
115
|
+
"- The purple-to-blue gradient, and the generic three-column feature grid under a centred heading.",
|
|
116
|
+
"",
|
|
117
|
+
"## Check yourself",
|
|
118
|
+
"",
|
|
119
|
+
"After writing UI, or changing how an existing screen looks (the black background, the shadow, the",
|
|
120
|
+
"bigger heading included), run `design_audit` on the source you touched — the PAGE",
|
|
121
|
+
"file together with the components it imports, not one component alone. Hairline density and centring",
|
|
122
|
+
"are properties of a page, and \"no rounded corner anywhere\" is a property of a project, so a",
|
|
123
|
+
"single-component run cannot see them. Run it on source, never on a fetched page: a built page measures",
|
|
124
|
+
"the framework's output.",
|
|
125
|
+
"",
|
|
126
|
+
"It separates two things. A SLOP finding means nothing here records a decision — it disappears the",
|
|
127
|
+
"moment the human chooses and you record it, and it is not a claim that the pattern is ugly. A",
|
|
128
|
+
"DEVIATION means the code contradicts what this project already chose, which is the half worth acting",
|
|
129
|
+
"on. Fix what it finds, or say plainly why a finding is wrong for this project: it reports evidence,",
|
|
130
|
+
"not verdicts, and it can be overruled.",
|
|
131
|
+
"",
|
|
132
|
+
"The audit measures patterns, not promises, so it cannot check the half of the direction that is",
|
|
133
|
+
"prose. Do that part yourself: re-read the `notes` and `rationale` recorded in design.json and take",
|
|
134
|
+
"each claim to the page one at a time. \"No stock imagery\", \"numbers in place, no adjectives\",",
|
|
135
|
+
"\"one entrance per section\" — either the page does it or it does not, and a clean audit says",
|
|
136
|
+
"nothing about any of them.",
|
|
137
|
+
].join("\n");
|
|
138
|
+
|
|
139
|
+
/** The prompt section for a project: the rules, plus either the recorded direction or the instruction
|
|
140
|
+
* to establish one. Read at buildDef (once per run start), like the model profile, so the system
|
|
141
|
+
* prefix stays byte-stable within a run for the prompt cache. */
|
|
142
|
+
export function designPromptSection(cwd: string): string {
|
|
143
|
+
const direction = loadDirection(cwd);
|
|
144
|
+
if (direction === null) {
|
|
145
|
+
return `${DESIGN_RULES}\n\n## This project\n\nNo design direction is recorded yet (.rovecode/design.json). The next interface work in this project starts with the proposal above.`;
|
|
146
|
+
}
|
|
147
|
+
// A provisional direction is built to exactly like a chosen one, but the heading must not tell the
|
|
148
|
+
// model "do not re-ask" about the one question that is still open. renderDirection carries the rest.
|
|
149
|
+
const heading = direction.provisional === true
|
|
150
|
+
? "## This project's direction — PROVISIONAL: build to this, and ask once before more UI"
|
|
151
|
+
: "## This project's direction — build to this, do not re-ask";
|
|
152
|
+
return `${DESIGN_RULES}
|
|
153
|
+
|
|
154
|
+
${heading}
|
|
155
|
+
|
|
156
|
+
${renderDirection(direction)}`;
|
|
157
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/** Cross-harness benchmark: runs equivalent micro-workloads through Rovecode and
|
|
2
|
+
* comparable harness primitives, measuring wall time, tool calls, success.
|
|
3
|
+
* Deterministic (scripted providers / direct API use) — no API keys needed. */
|
|
4
|
+
|
|
5
|
+
import { agentLoop, SteeringQueue } from "../core/loop.ts";
|
|
6
|
+
import { ToolRegistry } from "../core/tools.ts";
|
|
7
|
+
import { SessionStore } from "../core/session.ts";
|
|
8
|
+
import { readTool, editTool, writeTool } from "../coding/hashline.ts";
|
|
9
|
+
import { mockStream, textTurn, toolTurn } from "../providers/stream.ts";
|
|
10
|
+
import type { AgentDefinition, RunConfig, StreamFn, AssistantTurn, Message } from "../core/types.ts";
|
|
11
|
+
import { mkdtempSync, writeFileSync, readFileSync, rmSync } from "node:fs";
|
|
12
|
+
import { tmpdir } from "node:os";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { randomUUID } from "node:crypto";
|
|
15
|
+
|
|
16
|
+
export interface BenchResult {
|
|
17
|
+
harness: string;
|
|
18
|
+
task: string;
|
|
19
|
+
pass: boolean;
|
|
20
|
+
durationMs: number;
|
|
21
|
+
toolCalls: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const cfg: RunConfig = {
|
|
25
|
+
maxTurns: 10, contextBudgetTokens: 400_000, compactionThreshold: 0.8,
|
|
26
|
+
parallelTools: true,
|
|
27
|
+
permissionRules: [{ action: "*", resource: "*", effect: "allow" }],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const def: AgentDefinition = { name: "bench", systemPrompt: "bench", tools: ["*"] };
|
|
31
|
+
|
|
32
|
+
/** Workload: edit N lines across M files using anchored edits. */
|
|
33
|
+
async function benchEditsRovecode(nFiles: number, nEdits: number): Promise<{ pass: boolean; ms: number; calls: number }> {
|
|
34
|
+
const ws = mkdtempSync(join(tmpdir(), "rovecode-bench-"));
|
|
35
|
+
for (let i = 0; i < nFiles; i++) {
|
|
36
|
+
writeFileSync(join(ws, `f${i}.txt`), Array.from({ length: 50 }, (_, j) => `line-${i}-${j}`).join("\n") + "\n");
|
|
37
|
+
}
|
|
38
|
+
const store = new SessionStore(mkdtempSync(join(tmpdir(), "rovecode-bench-s-")), randomUUID());
|
|
39
|
+
const reg = new ToolRegistry();
|
|
40
|
+
reg.register(readTool, editTool, writeTool);
|
|
41
|
+
const t0 = Date.now();
|
|
42
|
+
let calls = 0;
|
|
43
|
+
// scripted: read each file, then batch edits
|
|
44
|
+
let fileIdx = 0; let phase: "read" | "edit" | "done" = "read";
|
|
45
|
+
const stream = mockStreamLike(async () => {
|
|
46
|
+
if (phase === "read" && fileIdx < nFiles) {
|
|
47
|
+
const p = join(ws, `f${fileIdx}.txt`);
|
|
48
|
+
fileIdx++;
|
|
49
|
+
if (fileIdx >= nFiles) phase = "edit";
|
|
50
|
+
return toolTurn([{ id: "r" + fileIdx, tool: "read", args: { path: p } }]);
|
|
51
|
+
}
|
|
52
|
+
if (phase === "edit") {
|
|
53
|
+
phase = "done";
|
|
54
|
+
const edits: { tag: string; anchorLine: number; anchorHash: string; newLines: string[] }[] = [];
|
|
55
|
+
for (let f = 0; f < nFiles; f++) {
|
|
56
|
+
const p = join(ws, `f${f}.txt`);
|
|
57
|
+
const content = readFileSync(p, "utf8");
|
|
58
|
+
const tag = hashTag(content);
|
|
59
|
+
const lines = content.split("\n");
|
|
60
|
+
for (let e = 0; e < nEdits; e++) {
|
|
61
|
+
const ln = 1 + e * 2; // spread edits
|
|
62
|
+
if (ln <= lines.length) edits.push({ tag, anchorLine: ln, anchorHash: fnv(lines[ln - 1]!), newLines: [`EDITED-${f}-${e}`] });
|
|
63
|
+
}
|
|
64
|
+
return toolTurn(edits.map((ed, i) => ({ id: "e" + i, tool: "edit", args: { path: p, edits: [ed] } })));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return textTurn("bench complete");
|
|
68
|
+
});
|
|
69
|
+
for await (const ev of agentLoop(def, "bench edits", {}, cfg, { stream, registry: reg, store }, new SteeringQueue())) {
|
|
70
|
+
if (ev.type === "tool_execution_start") calls++;
|
|
71
|
+
}
|
|
72
|
+
const ms = Date.now() - t0;
|
|
73
|
+
const pass = readFileSync(join(ws, "f0.txt"), "utf8").includes("EDITED-0-0");
|
|
74
|
+
rmSync(ws, { recursive: true, force: true });
|
|
75
|
+
return { pass, ms, calls };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function mockStreamLike(next: () => Promise<AssistantTurn>): StreamFn {
|
|
79
|
+
return async function* () {
|
|
80
|
+
yield { type: "turn" as const, turn: await next() };
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function fnv(line: string): string {
|
|
85
|
+
const s = line.replace(/\s/g, "");
|
|
86
|
+
let h = 0x811c9dc5;
|
|
87
|
+
for (let i = 0; i < s.length; i++) { h ^= s.charCodeAt(i); h = Math.imul(h, 0x01000193) >>> 0; }
|
|
88
|
+
return h.toString(36).padStart(3, "0").slice(-3);
|
|
89
|
+
}
|
|
90
|
+
function hashTag(content: string): string {
|
|
91
|
+
return Bun.CryptoHasher ? new Bun.CryptoHasher("sha1").update(content).digest("hex").slice(0, 4) : "0000";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Baseline: raw fs operations (no agent) for reference cost. */
|
|
95
|
+
function benchRawFs(nFiles: number, nEdits: number): { pass: boolean; ms: number } {
|
|
96
|
+
const ws = mkdtempSync(join(tmpdir(), "raw-bench-"));
|
|
97
|
+
const t0 = Date.now();
|
|
98
|
+
for (let i = 0; i < nFiles; i++) {
|
|
99
|
+
writeFileSync(join(ws, `f${i}.txt`), Array.from({ length: 50 }, (_, j) => `line-${i}-${j}`).join("\n") + "\n");
|
|
100
|
+
}
|
|
101
|
+
for (let f = 0; f < nFiles; f++) {
|
|
102
|
+
const p = join(ws, `f${f}.txt`);
|
|
103
|
+
const lines = readFileSync(p, "utf8").split("\n");
|
|
104
|
+
for (let e = 0; e < nEdits; e++) {
|
|
105
|
+
const ln = 1 + e * 2;
|
|
106
|
+
if (ln <= lines.length) lines[ln - 1] = `EDITED-${f}-${e}`;
|
|
107
|
+
}
|
|
108
|
+
writeFileSync(p, lines.join("\n"));
|
|
109
|
+
}
|
|
110
|
+
const ms = Date.now() - t0;
|
|
111
|
+
const pass = readFileSync(join(ws, "f0.txt"), "utf8").includes("EDITED-0-0");
|
|
112
|
+
rmSync(ws, { recursive: true, force: true });
|
|
113
|
+
return { pass, ms };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Session durability benchmark: append + replay N messages. */
|
|
117
|
+
function benchSessions(n: number): { pass: boolean; ms: number } {
|
|
118
|
+
const dir = mkdtempSync(join(tmpdir(), "rovecode-sess-bench-"));
|
|
119
|
+
const t0 = Date.now();
|
|
120
|
+
const s = new SessionStore(dir, randomUUID());
|
|
121
|
+
let prev: string | null = null;
|
|
122
|
+
for (let i = 0; i < n; i++) {
|
|
123
|
+
const m: Message = { id: randomUUID(), role: "user", parts: [{ kind: "text", text: `msg ${i}` }], parentId: prev, createdAt: Date.now() };
|
|
124
|
+
s.append(m);
|
|
125
|
+
prev = m.id;
|
|
126
|
+
}
|
|
127
|
+
const count = s.messages().length;
|
|
128
|
+
const ms = Date.now() - t0;
|
|
129
|
+
rmSync(dir, { recursive: true, force: true });
|
|
130
|
+
return { pass: count === n, ms };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export async function runBenchmarks(): Promise<BenchResult[]> {
|
|
134
|
+
const results: BenchResult[] = [];
|
|
135
|
+
const edits = await benchEditsRovecode(3, 5);
|
|
136
|
+
results.push({ harness: "rovecode", task: "edits-3files-5edits", ...edits, durationMs: edits.ms, toolCalls: edits.calls } as unknown as BenchResult);
|
|
137
|
+
const raw = benchRawFs(3, 5);
|
|
138
|
+
results.push({ harness: "raw-fs", task: "edits-3files-5edits", pass: raw.pass, durationMs: raw.ms, toolCalls: 0 });
|
|
139
|
+
const sess = benchSessions(500);
|
|
140
|
+
results.push({ harness: "rovecode", task: "session-append-replay-500", pass: sess.pass, durationMs: sess.ms, toolCalls: 0 });
|
|
141
|
+
return results;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function main(): Promise<void> {
|
|
145
|
+
const results = await runBenchmarks();
|
|
146
|
+
for (const r of results) {
|
|
147
|
+
console.log(`${r.harness.padEnd(8)} ${r.task.padEnd(28)} ${r.pass ? "PASS" : "FAIL"} ${r.durationMs}ms ${r.toolCalls} calls`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (import.meta.main) void main();
|