Public: anyone can read this; the crew can change it.
Vision upkeep: a thought that changes the vision becomes a small pull to docs/VISION.md, and the direction follows #5761
scout/forge:scout/655-vision-upkeep-a-thought-that-changes-the → main 3 commits fork 7 threads · 7 unresolved
README.md +17
| @@ -1659,6 +1659,23 @@ takes back (`supersedes`). `/asked` shows "said again, first on …", "takes bac | ||
| 1659 | 1659 | …" and "superseded by …" under each thought, and the MCP `thought` tool returns |
| 1660 | 1660 | `repeats`, `supersedes`, `repeatedBy` and `supersededBy` thought ids. |
| 1661 | 1661 | |
| 1662 | **Vision upkeep.** A thought read as a `vision` opens a small pull (branch | |
| 1663 | `vision/…`) adding one dated line under "Changes of direction" in | |
| 1664 | `docs/VISION.md`, with the thought quoted in the description; the reply under | |
| 1665 | the thought links the pull, and the MCP `thought` tool returns it as | |
| 1666 | `placed[].pull`. A person lands it. When it lands, the repository's direction | |
| 1667 | has one block rewritten from the vision (purpose, order of work, rules), | |
| 1668 | the part between `<!-- from docs/VISION.md -->` and `<!-- end -->`, through | |
| 1669 | the settings path, with a `repo.settings_updated` event naming | |
| 1670 | `autonomyDirection`. The block is appended when the markers are missing; | |
| 1671 | everything outside it is the owner's and kept word for word, and when both | |
| 1672 | would pass 2,000 characters the generated part is cut. The pull's description | |
| 1673 | shows the direction as it will read if it lands. Only an admin's merge writes | |
| 1674 | it; otherwise the pull gets a note from the forge. Without a | |
| 1675 | `docs/VISION.md` the thought stays a note on the direction issue. The edit is a | |
| 1676 | plain appended line, not a rewrite of the prose: the owner edits the pull if | |
| 1677 | the wording should change. | |
| 1678 | ||
| 1662 | 1679 | ## Link-preview cards |
| 1663 | 1680 | |
| 1664 | 1681 | `/og/repo/owner~name.svg`, `/og/app/slug.svg`, `/og/issue/owner~name~N.svg`, |
src/actions/pulls.ts +3
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | * issues — a pull is an issue with a diff. |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | import { followVision } from "../crew/vision.ts"; | |
| 7 | 8 | import { resolveOpen } from "../core/decisions.ts"; |
| 8 | 9 | import type { App } from "../app.ts"; |
| 9 | 10 | import { isCrew } from "../core/agents.ts"; |
| @@ -435,6 +436,8 @@ export async function mergePull( | ||
| 435 | 436 | mergeOid: merged.value.mergeOid, |
| 436 | 437 | }, |
| 437 | 438 | }); |
| 439 | // A landed vision edit: the direction follows the document (#655). | |
| 440 | await followVision(app, repo, pull, writer.value); | |
High: when this runs, it overwrites the whole |
||
| 438 | 441 | // What the pull said it closes, closes: the issue is done when the change |
| 439 | 442 | // lands, as the person who landed it — which is what frees the map. Not |
| 440 | 443 | // the plan's own issues: no change finishes an umbrella or opens the |
src/actions/repos.ts +1
| @@ -384,6 +384,7 @@ export async function updateRepoSettings( | ||
| 384 | 384 | "crewOutsiders", |
| 385 | 385 | "decisionsBy", |
| 386 | 386 | "plansNeedNod", |
| 387 | "autonomyDirection", | |
| 387 | 388 | ] as const |
| 388 | 389 | ).filter((k) => settings[k] !== undefined && settings[k] !== repo[k]); |
| 389 | 390 | if (moved) changed.push("archived"); |
src/core/placements.ts +16 −1
| @@ -9,7 +9,7 @@ import type { Database } from "bun:sqlite"; | ||
| 9 | 9 | export const KINDS = ["work", "amendment", "vision", "decision", "reversal"] as const; |
| 10 | 10 | export type Kind = (typeof KINDS)[number]; |
| 11 | 11 | |
| 12 | export type Action = "opened" | "amended" | "deferred" | "superseded" | "linked"; | |
| 12 | export type Action = "opened" | "amended" | "deferred" | "superseded" | "linked" | "proposed"; | |
| 13 | 13 | |
| 14 | 14 | /** One thing done on the map: an issue of `repo` (owner/name), and the pillar it serves. */ |
| 15 | 15 | export interface Placed { |
| @@ -17,6 +17,8 @@ export interface Placed { | ||
| 17 | 17 | repo: string; |
| 18 | 18 | number: number; |
| 19 | 19 | pillar?: string; |
| 20 | /** For `proposed`: the pull that carries the edit; `number` is still the direction issue. */ | |
| 21 | pull?: number; | |
| 20 | 22 | } |
| 21 | 23 | |
| 22 | 24 | export interface Placement { |
| @@ -107,3 +109,16 @@ export function authorsWithUnplaced(db: Database, since: string): string[] { | ||
| 107 | 109 | export function thoughtAuthor(db: Database, thoughtId: string): string | undefined { |
| 108 | 110 | return db.query<{ author: string }, [string]>("SELECT author FROM thought WHERE id = ?1").get(thoughtId)?.author; |
| 109 | 111 | } |
| 112 | ||
| 113 | /** True when the planner opened this pull of `repo` (owner/name) for a vision thought. */ | |
| 114 | export function isProposedPull(db: Database, repo: string, pull: number): boolean { | |
| 115 | return ( | |
| 116 | db | |
| 117 | .query<{ one: number }, [string, number]>( | |
| 118 | `SELECT 1 AS one FROM placement p, json_each(p.placed) j | |
| 119 | WHERE p.kind = 'vision' AND json_extract(j.value, '$.action') = 'proposed' | |
| 120 | AND json_extract(j.value, '$.repo') = ?1 AND json_extract(j.value, '$.pull') = ?2 LIMIT 1`, | |
| 121 | ) | |
| 122 | .get(repo, pull) !== null | |
| 123 | ); | |
| 124 | } |
src/crew/triage.ts +6
| @@ -34,6 +34,7 @@ import { createLog } from "../kernel/log.ts"; | ||
| 34 | 34 | import { autonomyStatus, ensureDirectionIssue } from "./autonomy.ts"; |
| 35 | 35 | import { certain, decideOr, type Answers, type Questions } from "./decide.ts"; |
| 36 | 36 | import { linkThoughts, raiseIssue } from "../core/thought_links.ts"; |
| 37 | import { proposeVision } from "./vision.ts"; | |
| 37 | 38 | import { crewOffInPreview } from "./preview.ts"; |
| 38 | 39 | |
| 39 | 40 | const log = createLog("triage"); |
| @@ -296,6 +297,8 @@ export async function placeThought( | ||
| 296 | 297 | question = kind === "reversal" ? "Which issue does this take back?" : "Is this an amendment to an open issue? Which one?"; |
| 297 | 298 | kind = kind === "reversal" ? "decision" : "work"; |
| 298 | 299 | } |
| 300 | // A vision becomes a small pull to docs/VISION.md; without one it stays a note on the direction. | |
| 301 | const proposed = kind === "vision" && direction ? await proposeVision(app, by, repo, thought, now) : undefined; | |
| 299 | 302 | if (kind === "work") { |
| 300 | 303 | const first = text.trim().split("\n")[0] ?? ""; |
| 301 | 304 | const opened = openPlan(app, by, repo, [ |
| @@ -341,6 +344,9 @@ export async function placeThought( | ||
| 341 | 344 | const when = taken[0] ? ` (you said it on ${taken[0].receivedAt.slice(0, 10)})` : ""; |
| 342 | 345 | say.push(deferred ? `Superseded #${issue.number}${when} and put it behind the Later gate.` : `Marked #${issue.number}${when} superseded.`); |
| 343 | 346 | } |
| 347 | } else if (proposed !== undefined) { | |
| 348 | placed.push({ action: "proposed", repo: slug, number: direction!.number, pull: proposed }); | |
| 349 | say.push(`Opened pull #${proposed} editing docs/VISION.md; ship it and the direction follows.`); | |
| 344 | 350 | } else if (direction) { |
| 345 | 351 | comment(direction, kind === "vision" ? "The direction changes:" : "A decision:"); |
| 346 | 352 | placed.push({ action: "amended", repo: slug, number: direction.number }); |
src/crew/vision.ts added +172
| @@ -0,0 +1,172 @@ | ||
| 1 | /** | |
| 2 | * Vision upkeep (#655). A thought read as `vision` becomes a small pull to | |
| 3 | * docs/VISION.md: one dated line under "Changes of direction" with the | |
| 4 | * thought's words, and the thought quoted in the description. A person | |
| 5 | * lands it (rule 10). When it lands, the repository's direction text is | |
| 6 | * regenerated from the vision itself (its purpose, order of work and rules) | |
| 7 | * inside a fenced block of the direction and written through the settings | |
| 8 | * path. Everything outside the fence is the owner's and is kept word for word; | |
| 9 | * the whole stays under `DIRECTION_MAX` characters. | |
| 10 | */ | |
| 11 | ||
| 12 | import type { App } from "../app.ts"; | |
| 13 | import { addComment } from "../actions/issues.ts"; | |
| 14 | import { getIssue } from "../core/issues.ts"; | |
| 15 | import { isProposedPull } from "../core/placements.ts"; | |
| 16 | import { editFiles } from "../actions/contents.ts"; | |
| 17 | import { updateRepoSettings } from "../actions/repos.ts"; | |
| 18 | import type { Pull } from "../core/pulls.ts"; | |
| 19 | import { canAdmin, getRepoById, type Repo } from "../core/repos.ts"; | |
| 20 | import { getUserById, type User } from "../core/users.ts"; | |
| 21 | import { blobForRender } from "../git/read.ts"; | |
| 22 | import { repoDir } from "../git/repos.ts"; | |
| 23 | import { createLog } from "../kernel/log.ts"; | |
| 24 | ||
| 25 | const log = createLog("vision"); | |
| 26 | ||
| 27 | export const VISION_PATH = "docs/VISION.md"; | |
| 28 | /** The same bound the settings page puts on the direction. */ | |
| 29 | export const DIRECTION_MAX = 2_000; | |
| 30 | /** The branch prefix the planner gives a vision edit (a name only; the placement is what identifies one). */ | |
| 31 | export const VISION_BRANCH = "vision/"; | |
| 32 | const SECTION = "## Changes of direction"; | |
| 33 | const LINE_MAX = 600; | |
| 34 | const READ_MAX = 256 * 1024; | |
| 35 | ||
| 36 | const flat = (text: string): string => text.replace(/\s+/g, " ").trim(); | |
| 37 | const clip = (text: string, max: number): string => (text.length > max ? `${text.slice(0, max - 1).trimEnd()}…` : text); | |
| 38 | ||
| 39 | async function readVision(app: App, repo: Repo): Promise<string | undefined> { | |
| 40 | const blob = await blobForRender(repoDir(app.reposRoot, repo.ownerName, repo.name), repo.defaultBranch, VISION_PATH, READ_MAX); | |
| 41 | return blob.kind === "text" ? new TextDecoder().decode(blob.body) : undefined; | |
| 42 | } | |
| 43 | ||
| 44 | /** The vision with one line added under "Changes of direction", the section made if absent. */ | |
| 45 | export function withChange(vision: string, text: string, date: string): string { | |
| 46 | const line = `- ${date}: ${clip(flat(text), LINE_MAX)}`; | |
| 47 | const body = vision.replace(/\s+$/, ""); | |
| 48 | const at = body.indexOf(`\n${SECTION}`); | |
| 49 | if (at === -1) return `${body}\n\n${SECTION}\n${line}\n`; | |
| 50 | const after = body.indexOf("\n## ", at + 1); | |
| 51 | const end = after === -1 ? body.length : after; | |
| 52 | return `${body.slice(0, end).replace(/\s+$/, "")}\n${line}\n${after === -1 ? "" : `\n${body.slice(end + 1)}\n`}`; | |
| 53 | } | |
| 54 | ||
| 55 | /** Direction text from a vision document: purpose, order of work, rules; never over the bound. */ | |
| 56 | export function directionFrom(vision: string, max = DIRECTION_MAX): string { | |
| 57 | const lines = vision.split("\n"); | |
| 58 | const purpose = flat(lines.slice(1).join("\n").split(/\n\s*\n|\n##/)[0] ?? ""); | |
| 59 | const firstSentence = (s: string): string => clip((s.match(/^.*?[.!?](?=\s|$)/)?.[0] ?? s).replace(/\*\*/g, ""), 140); | |
| 60 | const order: string[] = []; | |
| 61 | const rules: string[] = []; | |
| 62 | let into: string[] | undefined; | |
| 63 | for (const raw of lines) { | |
| 64 | if (/^##\s+order of work/i.test(raw)) into = order; | |
| 65 | else if (/^##\s+how we build/i.test(raw)) into = rules; | |
| 66 | else if (/^#{1,2}\s/.test(raw)) into = undefined; | |
| 67 | else if (into && /^(\d+\.|-)\s+/.test(raw)) into.push(firstSentence(flat(raw.replace(/^(\d+\.|-)\s+/, "")))); | |
| 68 | } | |
| 69 | const parts = [`From ${VISION_PATH}; change it there.`, clip(purpose, 400)]; | |
| 70 | if (order.length) parts.push("Order of work:", ...order.map((l, i) => `${i}. ${l}`)); | |
| 71 | if (rules.length) parts.push("Rules:", ...rules.map((l) => `- ${l}`)); | |
| 72 | const kept: string[] = []; | |
| 73 | let used = 0; | |
| 74 | for (const part of parts) { | |
| 75 | if (used + part.length + 1 > max) break; | |
| 76 | kept.push(part); | |
| 77 | used += part.length + 1; | |
| 78 | } | |
| 79 | return kept.join("\n"); | |
| 80 | } | |
| 81 | ||
| 82 | export const BLOCK_START = "<!-- from docs/VISION.md -->"; | |
| 83 | export const BLOCK_END = "<!-- end -->"; | |
| 84 | ||
| 85 | /** | |
| 86 | * The direction with its fenced block regenerated from the vision: the block is | |
| 87 | * replaced where it stands, or appended when the markers are missing; text | |
| 88 | * outside it is kept exactly. When both would pass the bound, the generated | |
| 89 | * part is cut, never the owner's text. | |
| 90 | */ | |
| 91 | export function withVisionBlock(current: string, vision: string): string { | |
| 92 | const from = current.indexOf(BLOCK_START); | |
| 93 | const to = from === -1 ? -1 : current.indexOf(BLOCK_END, from + BLOCK_START.length); | |
| 94 | const head = from === -1 || to === -1 ? current.replace(/\s+$/, "") : current.slice(0, from); | |
| 95 | const tail = from === -1 || to === -1 ? "" : current.slice(to + BLOCK_END.length); | |
Low: when |
||
| 96 | const lead = head === "" ? "" : head.endsWith("\n") ? head : `${head}\n\n`; | |
| 97 | const room = DIRECTION_MAX - lead.length - tail.length - BLOCK_START.length - BLOCK_END.length - 2; | |
| 98 | if (room < 80) return current; | |
| 99 | return `${lead}${BLOCK_START}\n${directionFrom(vision, room)}\n${BLOCK_END}${tail}`; | |
| 100 | } | |
| 101 | ||
| 102 | /** | |
| 103 | * Open the pull for a vision thought. Undefined when there is nothing to edit | |
| 104 | * (no vision document, or the pull could not open): the caller keeps the words | |
| 105 | * on the direction issue, as before. | |
| 106 | */ | |
| 107 | export async function proposeVision( | |
| 108 | app: App, | |
| 109 | by: User, | |
| 110 | repo: Repo, | |
| 111 | thought: { id: string; text: string }, | |
| 112 | now = new Date(), | |
outdated
A branch prefix is something the client chooses. Identify the vision pull by the placement that opened it ( |
||
| 113 | ): Promise<number | undefined> { | |
| 114 | try { | |
| 115 | return await propose(app, by, repo, thought, now); | |
| 116 | } catch (error) { | |
| 117 | log.error("vision pull not opened", { thought: thought.id, error: String(error) }); | |
| 118 | return undefined; | |
| 119 | } | |
outdated
High. When the merger is not an admin, this acts as |
||
| 120 | } | |
| 121 | ||
| 122 | async function propose(app: App, by: User, repo: Repo, thought: { id: string; text: string }, now: Date): Promise<number | undefined> { | |
| 123 | const vision = await readVision(app, repo); | |
| 124 | if (vision === undefined) return undefined; | |
| 125 | const first = flat(thought.text.split("\n")[0] ?? ""); | |
| 126 | const quote = thought.text.split("\n").map((l) => `> ${l}`).join("\n"); | |
| 127 | const changed = withChange(vision, thought.text, now.toISOString().slice(0, 10)); | |
| 128 | const next = withVisionBlock(repo.autonomyDirection, changed); | |
| 129 | const made = await editFiles(app, by, repo, { | |
| 130 | newBranch: `${VISION_BRANCH}${thought.id.toLowerCase().replace(/[^a-z0-9]+/g, "-").slice(0, 40)}`, | |
| 131 | message: `Vision: ${clip(first, 60)}`, | |
| 132 | files: [{ path: VISION_PATH, content: changed }], | |
| 133 | openPull: { | |
| 134 | title: `Vision: ${clip(first, 80) || "a change of direction"}`, | |
| 135 | body: `A thought that changes the vision, as one line in ${VISION_PATH}. Land it and the block of the repository's direction between \`${BLOCK_START}\` and \`${BLOCK_END}\` follows the vision; the rest of the direction stays as it is.\n\nFrom thought \`${thought.id}\`:\n\n${quote}\n\nThe direction as it will read if this lands now:\n\n\`\`\`\n${next.replace(/\`\`\`/g, "'''")}\n\`\`\``, | |
| 136 | }, | |
| 137 | }); | |
| 138 | if (!made.ok || !made.value.pull) { | |
| 139 | log.warn("vision pull not opened", { thought: thought.id, error: made.ok ? "no pull" : JSON.stringify(made.error) }); | |
| 140 | return undefined; | |
| 141 | } | |
| 142 | return made.value.pull.number; | |
| 143 | } | |
| 144 | ||
| 145 | /** | |
| 146 | * A landed vision pull: write the direction from the vision as it now stands. | |
| 147 | * Only for a pull the planner opened for a vision thought (its placement says | |
| 148 | * so), and only when the person who landed it may administer the repository: | |
| 149 | * the direction is the crew's instruction, an admin's setting. Otherwise it is | |
| 150 | * left alone and the pull says so. True when it changed. | |
| 151 | */ | |
| 152 | export async function followVision(app: App, repo: Repo, pull: Pull, actor: User): Promise<boolean> { | |
| 153 | if (pull.baseBranch !== repo.defaultBranch || !isProposedPull(app.db, `${repo.ownerName}/${repo.name}`, pull.number)) return false; | |
| 154 | try { | |
| 155 | if (!canAdmin(app.db, repo, actor)) { | |
| 156 | const issue = getIssue(app.db, repo.id, pull.number); | |
| 157 | // Said under the pull's author, never under the merger's name: it is the forge's note, not theirs. | |
| 158 | if (issue) addComment(app, getUserById(app.db, pull.authorId) ?? actor, repo, issue, "Note from the forge: the direction was not updated, because only an admin of this repository changes it. An admin can save the vision's direction from Settings."); | |
Medium: this comment is posted as the pull's author, who is the thought's author. They didn't write it, and in an org they may not be the person who merged. The words "Note from the forge" don't change whose name the feed, notifications and the audit log show. Attributing words to a user who didn't say them is the integrity problem the earlier round tried to avoid. Fix: post it as the merger, framed as their own action ("Merged without updating the direction: only an admin changes it."). Or post no comment and log a |
||
| 159 | return false; | |
| 160 | } | |
| 161 | const vision = await readVision(app, repo); | |
| 162 | if (vision === undefined) return false; | |
| 163 | const direction = withVisionBlock(repo.autonomyDirection, vision); | |
| 164 | if (direction === repo.autonomyDirection) return false; | |
| 165 | const done = await updateRepoSettings(app, actor, getRepoById(app.db, repo.id) ?? repo, { autonomyDirection: direction }); | |
| 166 | if (!done.ok) log.warn("direction not updated", { repo: repo.id, error: String(done.error) }); | |
| 167 | return done.ok; | |
| 168 | } catch (error) { | |
| 169 | log.error("direction not updated", { repo: repo.id, error: String(error) }); | |
| 170 | return false; | |
| 171 | } | |
| 172 | } |
src/web/studio/asked_page.ts +2
| @@ -65,6 +65,8 @@ function placedLinks(t: StreamThought): Html { | ||
| 65 | 65 | ? html`${x.action} in a repository you cannot read` |
| 66 | 66 | : x.title === null |
| 67 | 67 | ? html`${x.action} ${x.repo} #${x.number}` |
| 68 | : x.pull !== undefined | |
| 69 | ? html`${x.action} <a href="/${x.repo}/pulls/${x.pull}">${x.repo} pull #${x.pull}</a>` | |
| 68 | 70 | : html`${x.action} <a href="/${x.repo}/issues/${x.number}">${x.repo} #${x.number}</a>`, |
| 69 | 71 | ); |
| 70 | 72 | return links.length === 0 |
src/web/studio/feed.ts +7 −1
| @@ -126,7 +126,13 @@ export function thoughtCard(thought: Thought, who: string, placement?: Placement | ||
| 126 | 126 | /** The planner's answer under a thought: one or two lines, `#N` linking to the issue it names. */ |
| 127 | 127 | export function replyUnder(placement: Placement): Html { |
| 128 | 128 | const where = new Map(placement.placed.map((p) => [p.number, p.repo])); |
| 129 | const parts = placement.reply.split(/(#\d+)/).map((part) => { | |
| 129 | const pulls = new Map(placement.placed.flatMap((p) => (p.pull === undefined ? [] : [[p.pull, p.repo] as const]))); | |
| 130 | const parts = placement.reply.split(/(pull #\d+|#\d+)/).map((part) => { | |
| 131 | const pull = /^pull #(\d+)$/.exec(part); | |
| 132 | if (pull) { | |
| 133 | const at = pulls.get(Number(pull[1])); | |
| 134 | return at === undefined ? part : html`<a href="/${at}/pulls/${pull[1]}">${part}</a>`; | |
| 135 | } | |
| 130 | 136 | const repo = /^#(\d+)$/.test(part) ? where.get(Number(part.slice(1))) : undefined; |
| 131 | 137 | return repo === undefined ? part : html`<a href="/${repo}/issues/${part.slice(1)}">${part}</a>`; |
| 132 | 138 | }); |
test/triage.test.ts +146 −2
| @@ -9,17 +9,22 @@ import { tmpdir } from "node:os"; | ||
| 9 | 9 | import { join } from "node:path"; |
| 10 | 10 | import { createApp, type App } from "../src/app.ts"; |
| 11 | 11 | import { openIssue } from "../src/actions/issues.ts"; |
| 12 | import { createRepo, updateRepoSettings } from "../src/actions/repos.ts"; | |
| 12 | import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts"; | |
| 13 | 13 | import { keepThought } from "../src/actions/thought.ts"; |
| 14 | 14 | import { listComments, getIssue, getIssueById } from "../src/core/issues.ts"; |
| 15 | 15 | import { readyNow, repoGraph } from "../src/core/dependencies.ts"; |
| 16 | 16 | import { linksFrom } from "../src/core/thought_links.ts"; |
| 17 | 17 | import { thoughtStream } from "../src/core/thought_stream.ts"; |
| 18 | import { placementOf } from "../src/core/placements.ts"; | |
| 18 | import { placementJson, placementOf } from "../src/core/placements.ts"; | |
| 19 | 19 | import { getRepoById, type Repo } from "../src/core/repos.ts"; |
| 20 | 20 | import { createUser, type User } from "../src/core/users.ts"; |
| 21 | 21 | import { BATCH_MS, placeThought, ruleKind, triageTick } from "../src/crew/triage.ts"; |
| 22 | 22 | import type { Decider } from "../src/crew/decide.ts"; |
| 23 | import { addTeamMember, createOrg, createTeam } from "../src/actions/orgs.ts"; | |
| 24 | import { getOrg } from "../src/core/orgs.ts"; | |
| 25 | import { mergePull, openPull } from "../src/actions/pulls.ts"; | |
| 26 | import { getPull } from "../src/core/pulls.ts"; | |
| 27 | import { directionFrom, withChange, withVisionBlock } from "../src/crew/vision.ts"; | |
| 23 | 28 | import { replyUnder } from "../src/web/studio/feed.ts"; |
| 24 | 29 | import { thoughtRow } from "../src/web/studio/asked_page.ts"; |
| 25 | 30 | |
| @@ -317,3 +322,142 @@ describe("triage", () => { | ||
| 317 | 322 | expect(html).not.toContain("<b>"); |
| 318 | 323 | }); |
| 319 | 324 | }); |
| 325 | ||
| 326 | describe("vision upkeep (#655)", () => { | |
| 327 | let dataDir: string; | |
| 328 | let app: App; | |
| 329 | let alice: User; | |
| 330 | let repo: Repo; | |
| 331 | const fresh = () => getRepoById(app.db, repo.id)!; | |
| 332 | ||
| 333 | beforeAll(async () => { | |
| 334 | dataDir = await mkdtemp(join(tmpdir(), "forge-vision-")); | |
| 335 | app = createApp({ dataDir, port: 0 }); | |
| 336 | const made = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 337 | if (!made.ok) throw new Error(String(made.error)); | |
| 338 | alice = made.value; | |
| 339 | const r = await createRepo(app, alice, { name: "forge", visibility: "private" }); | |
| 340 | if (!r.ok) throw new Error(String(r.error)); | |
| 341 | repo = r.value; | |
| 342 | await updateRepoSettings(app, alice, repo, { autonomy: "autonomous", autonomyDirection: "Hand written.", autonomyCeilingUsd: 10, autonomySlots: 1, autonomyBy: alice.id }); | |
| 343 | const seeded = await commitToBranch(app, alice, fresh(), { | |
| 344 | message: "Vision", | |
| 345 | files: [{ path: "docs/VISION.md", content: "# What it is for\nA place for building. More words.\n\n## Order of work\n0. **Trust.** Agents are contained.\n1. **Feed.** One front door.\n\n## How we build\n- Done means reachable: a page and a tool.\n" }], | |
| 346 | }); | |
| 347 | if (!seeded.ok) throw new Error(JSON.stringify(seeded.error)); | |
| 348 | }); | |
| 349 | afterAll(async () => { | |
| 350 | app.close(); | |
| 351 | await rm(dataDir, { recursive: true, force: true }); | |
| 352 | }); | |
| 353 | ||
| 354 | test("a vision thought opens a pull quoting it; landing it rewrites the direction under the bound", async () => { | |
| 355 | app.config.decider = stub({ vision: ["vision", 0.9] }); | |
| 356 | const kept = keepThought(app, alice, "vision: every fork follows its upstream", "api"); | |
| 357 | if (!kept.ok) throw new Error(kept.error); | |
| 358 | const p = await placeThought(app, fresh(), alice, { id: kept.value.id, text: "vision: every fork follows its upstream" }); | |
| 359 | expect(p.kind).toBe("vision"); | |
| 360 | const at = p.placed[0]!; | |
| 361 | expect(at.action).toBe("proposed"); | |
| 362 | expect(p.reply).toContain(`pull #${at.pull}`); | |
| 363 | const pull = getPull(app.db, repo.id, at.pull!)!; | |
| 364 | expect(pull.body).toContain("> vision: every fork follows its upstream"); | |
| 365 | expect(pull.body).toContain(kept.value.id); | |
| 366 | expect(fresh().autonomyDirection).toBe("Hand written."); | |
| 367 | expect(replyUnder(p).toString()).toContain(`/${at.repo}/pulls/${at.pull}`); | |
| 368 | expect(placementJson(placementOf(app.db, kept.value.id))).toMatchObject({ placed: [{ pull: at.pull }] }); | |
| 369 | ||
| 370 | const merged = await mergePull(app, alice, fresh(), pull, "squash"); | |
| 371 | expect(merged.ok).toBe(true); | |
| 372 | const direction = fresh().autonomyDirection; | |
| 373 | expect(direction.startsWith("Hand written.")).toBe(true); | |
| 374 | expect(direction).toContain("<!-- from docs/VISION.md -->"); | |
| 375 | expect(pull.body).toContain("Hand written."); | |
| 376 | expect(direction).toContain("Order of work:"); | |
| 377 | expect(direction).toContain("0. Trust."); | |
| 378 | expect(direction).toContain("Done means reachable"); | |
| 379 | expect(direction.length).toBeLessThanOrEqual(2000); | |
outdated
The name promises the no-VISION.md fallback, but the body only tests |
||
| 380 | expect( | |
| 381 | app.db.query<{ payload: string }, []>("SELECT payload FROM event WHERE kind = 'repo.settings_updated' ORDER BY rowid DESC LIMIT 1").get()!.payload, | |
| 382 | ).toContain("autonomyDirection"); | |
| 383 | }); | |
| 384 | ||
| 385 | test("a vision in a repository without VISION.md stays a note on the direction issue", async () => { | |
| 386 | const r = await createRepo(app, alice, { name: "plain", visibility: "private" }); | |
| 387 | if (!r.ok) throw new Error(String(r.error)); | |
| 388 | await updateRepoSettings(app, alice, r.value, { autonomy: "autonomous", autonomyDirection: "x", autonomyCeilingUsd: 10, autonomySlots: 1, autonomyBy: alice.id }); | |
| 389 | const plain = getRepoById(app.db, r.value.id)!; | |
| 390 | await commitToBranch(app, alice, plain, { message: "Start", files: [{ path: "README.md", content: "# plain\n" }] }); | |
| 391 | app.config.decider = stub({ vision: ["vision", 0.9] }); | |
| 392 | const kept = keepThought(app, alice, "vision: small is the point", "api"); | |
| 393 | if (!kept.ok) throw new Error(kept.error); | |
| 394 | const p = await placeThought(app, plain, alice, { id: kept.value.id, text: "vision: small is the point" }); | |
| 395 | expect(p.placed[0]!.action).toBe("amended"); | |
| 396 | expect(p.placed[0]!.pull).toBeUndefined(); | |
| 397 | const direction = getIssue(app.db, plain.id, p.placed[0]!.number)!; | |
| 398 | expect(listComments(app.db, direction.id).some((c) => c.body.includes(kept.value.id))).toBe(true); | |
| 399 | }); | |
| 400 | ||
| 401 | test("an empty repository falls back to the note instead of failing the placement", async () => { | |
| 402 | const r = await createRepo(app, alice, { name: "empty", visibility: "private" }); | |
| 403 | if (!r.ok) throw new Error(String(r.error)); | |
| 404 | await updateRepoSettings(app, alice, r.value, { autonomy: "autonomous", autonomyDirection: "x", autonomyCeilingUsd: 10, autonomySlots: 1, autonomyBy: alice.id }); | |
| 405 | const kept = keepThought(app, alice, "vision: nothing here yet", "api"); | |
| 406 | if (!kept.ok) throw new Error(kept.error); | |
| 407 | const p = await placeThought(app, getRepoById(app.db, r.value.id)!, alice, { id: kept.value.id, text: "vision: nothing here yet" }); | |
| 408 | expect(p.placed[0]!.action).toBe("amended"); | |
| 409 | }); | |
| 410 | ||
| 411 | test("a writer who is not an admin merging a vision pull leaves the direction alone; so does a pull nobody placed", async () => { | |
| 412 | const bobMade = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase" }); | |
| 413 | if (!bobMade.ok) throw new Error(String(bobMade.error)); | |
| 414 | const bob = bobMade.value; | |
| 415 | expect(createOrg(app, alice, "acme").ok).toBe(true); | |
| 416 | const acme = getOrg(app.db, "acme")!; | |
| 417 | const devs = createTeam(app, alice, acme, "devs", "write"); | |
| 418 | if (!devs.ok) throw new Error(String(devs.error)); | |
| 419 | expect(addTeamMember(app, alice, acme, devs.value, "bob").ok).toBe(true); | |
| 420 | const r = await createRepo(app, alice, { owner: "acme", name: "shared", visibility: "private" }); | |
| 421 | if (!r.ok) throw new Error(String(r.error)); | |
| 422 | await updateRepoSettings(app, alice, r.value, { autonomy: "autonomous", autonomyDirection: "Mine.", autonomyCeilingUsd: 10, autonomySlots: 1, autonomyBy: alice.id, protectDefault: false }); | |
| 423 | const shared = getRepoById(app.db, r.value.id)!; | |
| 424 | await commitToBranch(app, alice, shared, { message: "Vision", files: [{ path: "docs/VISION.md", content: "# V\nPurpose here.\n\n## Order of work\n0. **Trust.** Safe.\n" }] }); | |
| 425 | app.config.decider = stub({ vision: ["vision", 0.9] }); | |
| 426 | const kept = keepThought(app, alice, "vision: go wide", "api"); | |
| 427 | if (!kept.ok) throw new Error(kept.error); | |
| 428 | const p = await placeThought(app, shared, alice, { id: kept.value.id, text: "vision: go wide" }); | |
| 429 | const planned = getPull(app.db, shared.id, p.placed[0]!.pull!)!; | |
| 430 | expect((await mergePull(app, bob, getRepoById(app.db, shared.id)!, planned, "squash")).ok).toBe(true); | |
| 431 | expect(getRepoById(app.db, shared.id)!.autonomyDirection).toBe("Mine."); | |
| 432 | const note = listComments(app.db, planned.id).find((c) => c.body.includes("only an admin")); | |
| 433 | expect(note).toBeDefined(); | |
| 434 | expect(note!.authorId).not.toBe(bob.id); | |
| 435 | ||
| 436 | // A branch anyone can name is not a vision pull. | |
| 437 | const named = await commitToBranch(app, alice, getRepoById(app.db, shared.id)!, { branch: "vision/x", message: "x", files: [{ path: "docs/VISION.md", content: "# V\nChanged.\n\n## Order of work\n0. **Other.** Thing.\n" }] }); | |
| 438 | expect(named.ok).toBe(true); | |
| 439 | const opened = await openPull(app, alice, getRepoById(app.db, shared.id)!, { title: "Sneaky", baseBranch: "main", headBranch: "vision/x" }); | |
| 440 | if (!opened.ok) throw new Error(JSON.stringify(opened.error)); | |
| 441 | await mergePull(app, alice, getRepoById(app.db, shared.id)!, opened.value, "squash"); | |
| 442 | expect(getRepoById(app.db, shared.id)!.autonomyDirection).toBe("Mine."); | |
| 443 | }); | |
| 444 | ||
| 445 | test("withChange adds to the section; a huge vision still fits", async () => { | |
| 446 | expect(withChange("# V\n\n## Changes of direction\n- a\n\n## Other\nx\n", "new", "2026-01-01")).toBe( | |
| 447 | "# V\n\n## Changes of direction\n- a\n- 2026-01-01: new\n\n## Other\nx\n", | |
| 448 | ); | |
| 449 | const big = `# V\nPurpose.\n\n## Order of work\n${Array.from({ length: 200 }, (_, i) => `${i}. **T${i}.** ${"word ".repeat(60)}`).join("\n")}\n`; | |
| 450 | expect(directionFrom(big).length).toBeLessThanOrEqual(2000); | |
| 451 | const owner = "NOW: ship #5735 first.\nSmall single-purpose pulls."; | |
| 452 | const once = withVisionBlock(owner, big); | |
| 453 | expect(once.startsWith(`${owner}\n\n<!-- from docs/VISION.md -->`)).toBe(true); | |
| 454 | expect(once.length).toBeLessThanOrEqual(2000); | |
| 455 | const twice = withVisionBlock(once.replace("NOW: ship", "NOW: then ship") + "\nAfter.", "# V\nNew purpose.\n"); | |
| 456 | expect(twice.startsWith("NOW: then ship #5735 first.")).toBe(true); | |
| 457 | expect(twice.endsWith("<!-- end -->\nAfter.")).toBe(true); | |
| 458 | expect(twice).toContain("New purpose."); | |
| 459 | expect(twice).not.toContain("Order of work"); | |
| 460 | const full = "x".repeat(1990); | |
| 461 | expect(withVisionBlock(full, big)).toBe(full); | |
| 462 | }); | |
| 463 | }); |
"This removes hand-edited direction drift" also removes hand-edited direction. Once the fenced-block fix is in, say here which part of the direction follows the vision and which part stays the owner's.