Public: anyone can read this; the crew can change it.

An issue only the owner can do is assigned to the owner when it is filed, and no builder is sent to it #18469

opened this

Merged 4h 4m ago, live in production

scout/forge:scout/18462-an-issue-only-the-owner-can-do-is-assign → main 0 commits fork

  • Merged. scout/18462-an-issue-only-the-owner-can-do-is-assign was merged into main as 402a4d4.

Review

Sign in to review this change.
5 files changed +156 −1
docs/features/owner-only-issues.md added +30
@@ -0,0 +1,30 @@
1 ---
2 topic: Tell the crew
3 row: An issue only the owner can do
4 ---
5 # An issue only the owner can do
6
7 Some work is not a builder's: a cache rule on the owner's edge, a setting, a secret, a decision. Such an issue opens **assigned to the owner**, so the map shows it held by a person ("a person is its assignee; it starts when they hand it to a builder") and the crew never sends a builder to it.
8
9 ## Marking a plan item
10
11 In a plan (`POST /api/v1/repos/{owner}/{name}/plan`, or the MCP `plan` tool), give the item `"owner": true`:
12
13 ```json
14 { "key": "edge", "title": "Cache signed-out pages at the edge", "pillar": "P0",
15 "body": "Owner: add an edge cache rule for signed-out HTML keyed on EDGE_VARY.", "owner": true }
16 ```
17
18 The plan refuses the mark, naming the item, when:
19
20 - the body has no `Owner:` line saying what only the owner decides or does;
21 - the body names a file in the repository (`src/…`, `test/…`, `docs/…`, `scripts/…`) or "Files I expect": that is builder work;
22 - whoever posts the plan cannot write to the repository. An outsider's issue never carries the mark.
23
24 ## Duties
25
26 Duties that file a finding only the owner can act on file it assigned to the owner (the edge-kept duty, `src/maintain/duties/edge_kept.ts`).
27
28 ## Handing it on
29
30 When the owner wants a builder after all, they assign the issue to one (or clear the assignee); from the terminal, `ssh` in and use the issue's assign action as for any issue.
src/actions/owner_mark.ts added +22
@@ -0,0 +1,22 @@
1 /**
2 * The owner's mark on a plan item (#18462): an issue only the owner can do (a setting, an edge
3 * rule, a secret, a decision) is assigned to the owner when it opens, so the map shows it held by a
4 * person (`crew/held.ts`, `person`) and no builder is sent to it.
5 *
6 * The mark is for decisions, never for work a builder could do: a marked item says the decision
7 * on an `Owner:` line, and names no file in the repository and no "Files I expect".
8 */
9
10 /** The line a marked item's body carries: what the owner decides or does. */
11 const OWNER_LINE = /^Owner:[ \t]*\S/m;
12 /** A path a builder would change, or the builder brief's file list. */
13 const BUILDER_WORK = /(?:^|[\s`'"(])(?:src|test|tests|docs|scripts)\/[\w.-]|files i expect/i;
14
15 /** Why `body` cannot carry the owner's mark, in one plain sentence; undefined when it can. */
16 export function ownerMarkRefusal(key: string, body: string): string | undefined {
17 if (BUILDER_WORK.test(body))
18 return `"${key}" names files a builder could change, so it is builder work: drop owner, or keep only the owner's decision in it`;
19 if (!OWNER_LINE.test(body))
20 return `"${key}" is marked for the owner: say on an "Owner:" line what only the owner decides or does`;
21 return undefined;
22 }
src/actions/plan.ts +15 −1
@@ -24,6 +24,7 @@ import {
2424 getIssue,
2525 MAX_BODY,
2626 MAX_TITLE,
27 setAssignee,
2728 type Issue,
2829 } from "../core/issues.ts";
2930 import { unansweredFromApp } from "../core/from_app.ts";
@@ -32,6 +33,7 @@ import type { User } from "../core/users.ts";
3233 import { id as newId } from "../kernel/id.ts";
3334 import { err, ok, type Result } from "../kernel/result.ts";
3435 import { isMirror } from "../origins/write-through.ts";
36 import { ownerMarkRefusal } from "./owner_mark.ts";
3537 import { lookAlikes } from "./look_alike.ts";
3638 import { SELF_WAIT } from "./plan_words.ts";
3739 import { followLink } from "./pillars.ts";
@@ -52,6 +54,8 @@ export interface PlanItem {
5254 readonly pillar?: string;
5355 /** Set when it serves no pillar now: why it waits, in one sentence. */
5456 readonly later?: string;
57 /** Set when only the owner can do it: it opens assigned to the owner (`owner_mark.ts`). */
58 readonly owner?: true;
5559 }
5660
5761 /** A refusal: a stable code, and a sentence that names the item at fault. */
@@ -142,6 +146,11 @@ export function parsePlan(raw: unknown): Result<PlanItem[], PlanError> {
142146 "why_too_long",
143147 `"${key}": why is one sentence, at most ${WHY_MAX} characters`,
144148 );
149 const owner = o["owner"] ?? false;
150 if (typeof owner !== "boolean")
151 return refuse("invalid", `"${key}": owner is true or false`);
152 const builderWork = owner ? ownerMarkRefusal(key, body) : undefined;
153 if (builderWork !== undefined) return refuse("not_owner_only", builderWork);
145154 items.push({
146155 key,
147156 title,
@@ -149,6 +158,7 @@ export function parsePlan(raw: unknown): Result<PlanItem[], PlanError> {
149158 blockedBy: waits as (string | number)[],
150159 ...(pillar === undefined ? {} : { pillar: pillar.trim() }),
151160 ...(later ? { later: why } : {}),
161 ...(owner ? { owner: true as const } : {}),
152162 });
153163 }
154164 // One change on several things is one issue with a checklist, never a run
@@ -225,6 +235,8 @@ function vet(
225235 return refuse("not_found", "no such app or repository (owner/name)");
226236 if (!canWrite(app.db, repo, actor) && !isCrew(app.db, repo.id, actor.id))
227237 return refuse("forbidden", "you need write access to plan here");
238 if (items.some((i) => i.owner) && !canWrite(app.db, repo, actor))
239 return refuse("forbidden", "only the owner or a writer marks an item for the owner");
228240 if (isMirror(app, repo))
229241 return refuse(
230242 "mirrored",
@@ -391,7 +403,9 @@ export function openPlan(
391403 error: created.error,
392404 message: `"${item.key}": ${created.error}`,
393405 });
394 made.set(item.key, created.value);
406 // The owner's from the moment it exists: the map holds it for a person, no builder starts it.
407 const assigned = item.owner ? setAssignee(app.db, created.value.id, repo.ownerId) : undefined;
408 made.set(item.key, assigned ?? created.value);
395409 linkFollowUp(app.db, created.value);
396410 }
397411 for (const item of items)
src/http/mcp/tools/plan.ts +4
@@ -39,6 +39,10 @@ export const tool: Tool = {
3939 type: "string",
4040 description: "For later.",
4141 },
42 owner: {
43 type: "boolean",
44 description: "Only the owner can do it: opens assigned to them. Body needs an Owner: line, no repo files.",
45 },
4246 },
4347 required: ["key", "title"],
4448 },
test/plan-owner-mark.test.ts added +85
@@ -0,0 +1,85 @@
1 /**
2 * An item marked for the owner opens assigned to the owner, so the map holds it for a person and
3 * it is never startable; an unmarked item opens unassigned (#18462). The mark is refused on builder
4 * work and from anyone who cannot write.
5 */
6
7 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
8 import { mkdtemp, rm } from "node:fs/promises";
9 import { tmpdir } from "node:os";
10 import { join } from "node:path";
11 import { createApp, type App } from "../src/app.ts";
12 import { createRepo } from "../src/actions/repos.ts";
13 import { openPlan, parsePlan } from "../src/actions/plan.ts";
14 import { getIssue } from "../src/core/issues.ts";
15 import { createUser, type User } from "../src/core/users.ts";
16 import { startable } from "../src/crew/drive.ts";
17 import { readyNow, repoGraph } from "../src/core/dependencies.ts";
18 import type { Repo } from "../src/core/repos.ts";
19
20 const DECISION = "Owner: add an edge cache rule for signed-out HTML on the forge's domain.";
21
22 describe("the owner's mark on a plan item", () => {
23 let dataDir: string;
24 let app: App;
25 let alice: User;
26 let bob: User;
27 let repo: Repo;
28
29 beforeAll(async () => {
30 dataDir = await mkdtemp(join(tmpdir(), "forge-owner-mark-"));
31 app = createApp({ dataDir, port: 0 });
32 const user = async (username: string, first: boolean) => {
33 const made = await createUser(app.db, { origin: "seed", trusted: true, username, email: `${username}@forge.local`, password: "a-good-passphrase", adminIfFirst: first });
34 if (!made.ok) throw new Error(made.error);
35 return made.value;
36 };
37 alice = await user("alice", true);
38 bob = await user("bob", false);
39 const made = await createRepo(app, alice, { name: "marked", visibility: "public" });
40 if (!made.ok) throw new Error(String(made.error));
41 repo = made.value;
42 });
43
44 afterAll(async () => {
45 app.close();
46 await rm(dataDir, { recursive: true, force: true });
47 });
48
49 test("a marked issue is assigned to the owner on filing and held for a person; an unmarked one is not", () => {
50 const items = parsePlan([
51 { key: "edge", title: "Cache signed-out pages at the edge", body: DECISION, owner: true },
52 { key: "code", title: "Name the cache header", body: "Files I expect: src/http/edge_cache.ts" },
53 ]);
54 if (!items.ok) throw new Error(items.error.message);
55 const planned = openPlan(app, alice, repo, items.value);
56 if (!planned.ok) throw new Error(planned.error.message);
57 const number = (key: string) => planned.value.opened.find((o) => o.key === key)!.number;
58 expect(getIssue(app.db, repo.id, number("edge"))!.assigneeId).toBe(repo.ownerId);
59 expect(getIssue(app.db, repo.id, number("code"))!.assigneeId).toBeNull();
60 expect(planned.value.held.find((h) => h.key === "edge")?.by).toBe("person");
61 expect(planned.value.held.some((h) => h.key === "code")).toBe(false);
62 const free = startable(app, repo, readyNow(repoGraph(app.db, repo.id)), [], []).map((r) => r.issue.number);
63 expect(free).not.toContain(number("edge"));
64 expect(free).toContain(number("code"));
65 });
66
67 test("the mark is refused on work a builder could do, with a plain reason", () => {
68 const files = parsePlan([{ key: "a", title: "Fix it", body: `${DECISION}\nFiles I expect: src/x.ts`, owner: true }]);
69 expect(files.ok ? "" : files.error.error).toBe("not_owner_only");
70 expect(files.ok ? "" : files.error.message).toContain("builder");
71 const path = parsePlan([{ key: "a", title: "Fix it", body: `${DECISION} Change src/http/edge.ts.`, owner: true }]);
72 expect(path.ok ? "" : path.error.error).toBe("not_owner_only");
73 const silent = parsePlan([{ key: "a", title: "Decide", body: "Pick one.", owner: true }]);
74 expect(silent.ok ? "" : silent.error.message).toContain("Owner:");
75 const odd = parsePlan([{ key: "a", title: "Decide", body: DECISION, owner: "yes" }]);
76 expect(odd.ok).toBe(false);
77 });
78
79 test("someone who cannot write never files a marked issue", () => {
80 const items = parsePlan([{ key: "edge", title: "Cache it", body: DECISION, owner: true }]);
81 if (!items.ok) throw new Error(items.error.message);
82 const planned = openPlan(app, bob, repo, items.value);
83 expect(planned.ok ? "" : planned.error.error).toBe("forbidden");
84 });
85 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs