benignswarm 0.11.0 → 0.12.0

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.
@@ -182,7 +182,7 @@ export async function hook(p) {
182
182
  const lines = [
183
183
  `[bschat] ${compacted ? "Your context was compacted; here is what must survive it." : "Your standing role and process."}`,
184
184
  me.role ? `Your role: ${me.role.name}. ${me.role.description}` : `You hold no role in ${me.project?.name ?? "this project"}.`,
185
- `Process v${proc.version}: kinds of work ${proc.definition.kinds.map((t) => `${t.name} (approved by ${t.approver_role})`).join(", ")}; evidence ${proc.definition.require_evidence_to_submit ? "required" : "optional"} before review; max ${proc.definition.max_open_per_agent} open units. Work goes through bschat wu open/submit; nothing is done until approved.`,
185
+ `Process v${proc.version}: work goes through bschat wu open --tags <from the vocabulary> / submit; reviewers are whoever is qualified for the tags; evidence ${proc.definition.require_evidence_to_submit ? "required" : "optional"} before review; max ${proc.definition.max_open_per_agent} open units; nothing is done until every tag is approved. Details: bschat process.`,
186
186
  proc.agreements ? `Working agreements:\n${proc.agreements}` : null,
187
187
  ].filter(Boolean);
188
188
  standing = lines.join("\n");
@@ -5,19 +5,21 @@ import { CliError } from "../errors.js";
5
5
  import { branchAndHead, isAncestor } from "../git.js";
6
6
  import { table } from "../output.js";
7
7
  /**
8
- * Work units under the project's process.
8
+ * Work units under the project's process. Work is described by tags from the project's
9
+ * vocabulary; reviewers are whoever is qualified to review those tags.
9
10
  *
10
- * bschat wu open "<title>" --scope "<what it covers and does not>" [--kind t] [--tags a,b] [--evidence id,id]
11
- * bschat wu submit <n> [--evidence id,id] ask for review (routed to the kind's reviewer)
12
- * bschat wu approve <n> --note "..." reviewer only
13
- * bschat wu changes <n> --note "..." reviewer only
14
- * bschat wu reclassify <n> --kind plan [--note ...] reviewer raises the kind
15
- * bschat wu done <n> [--note ...] owner, after approval
11
+ * bschat wu open "<title>" --scope "<what it covers and does not>" [--tags ui,embedded] [--evidence id,id]
12
+ * bschat wu submit <n> [--evidence id,id] [--pr url] ask for review; routed by the unit's tags
13
+ * bschat wu approve <n> --note "..." covers the tags you are qualified for
14
+ * bschat wu changes <n> --note "..."
15
+ * bschat wu classify <n> --tags a,b [--note ...] classifier role only, when the process has that step
16
+ * bschat wu tags <n> --add a,b --remove c [--note ...] owner before review, a reviewer during it
17
+ * bschat wu done <n> --merged <sha> after approval; the sha is checked against the target branch
16
18
  * bschat wu abandon <n> [--note ...]
17
19
  * bschat wu note <n> --note "..." [--evidence id]
18
- * bschat wu list [--all] [--status s] [--kind t] [--agent name]
20
+ * bschat wu list [--all] [--status s] [--tag t] [--agent name]
19
21
  * bschat wu show <n>
20
- * bschat process the project's process: kinds, gates, agreements
22
+ * bschat process vocabulary, who reviews what, requirements, agreements
21
23
  */
22
24
  export async function wu(p, out) {
23
25
  const sub = p.positionals[1];
@@ -28,41 +30,49 @@ export async function wu(p, out) {
28
30
  if (!project)
29
31
  throw new CliError("no_project", `${creds.agent} is an account-scoped agent; pass --project <name>`);
30
32
  const base = `/projects/${project}/work-units`;
31
- const list = (k) => (str(p.flags, k) ?? "").split(",").map((x) => x.trim()).filter(Boolean);
33
+ const list = (k) => (str(p.flags, k) ?? "").split(",").map((x) => x.trim().replace(/^#/, "")).filter(Boolean);
32
34
  const num = () => {
33
35
  const n = Number(p.positionals[2]);
34
36
  if (!Number.isInteger(n) || n < 1)
35
37
  throw new CliError("usage", `wu ${sub} <number>`);
36
38
  return n;
37
39
  };
38
- const fmt = (u) => `WU #${u.number} [${u.status}] (${u.kind}) ${u.title}\n owner ${u.owner_name}${u.reviewer_name ? ` · reviewer ${u.reviewer_name}` : ""}${u.branch ? ` · ${u.branch}${u.head ? ` @ ${u.head}` : ""}` : ""}${u.pr_url ? ` · ${u.pr_url}` : ""}${u.merged_sha ? ` · merged ${u.merged_sha}` : ""}${u.evidence.length ? ` · evidence ${u.evidence.map((e) => `evidence:${e}`).join(" ")}` : ""}${u.scope ? `\n scope: ${u.scope}` : ""}`;
40
+ const tags = (u) => (u.tags.length ? u.tags.map((t) => `#${t}`).join(" ") : "(untagged)");
41
+ const fmt = (u) => {
42
+ const reviewers = u.reviewers.map((r) => `${r.name}${r.tags.length ? ` for ${r.tags.map((t) => `#${t}`).join(" ")}` : ""}`).join(", ");
43
+ const approvals = u.approvals.map((a) => a.name).join(", ");
44
+ return [
45
+ `WU #${u.number} [${u.status}] ${tags(u)} ${u.title}`,
46
+ ` owner ${u.owner_name}${reviewers ? ` · reviewers ${reviewers}` : ""}${approvals ? ` · approved by ${approvals}` : ""}${u.uncovered?.length ? ` · awaiting ${u.uncovered.map((t) => `#${t}`).join(" ")}` : ""}`,
47
+ ` ${u.branch ? `${u.branch}${u.head ? ` @ ${u.head}` : ""}` : "no branch recorded"}${u.pr_url ? ` · ${u.pr_url}` : ""}${u.merged_sha ? ` · merged ${u.merged_sha}` : ""}${u.evidence.length ? ` · evidence ${u.evidence.map((e) => `evidence:${e}`).join(" ")}` : ""}`,
48
+ u.scope ? ` scope: ${u.scope}` : null,
49
+ ].filter(Boolean).join("\n");
50
+ };
51
+ const processDef = async () => (await client.call("GET", `/projects/${project}/process`)).process.definition;
39
52
  switch (sub) {
40
53
  case "open": {
41
54
  const title = p.positionals.slice(2).join(" ").trim();
42
55
  if (!title)
43
- throw new CliError("usage", 'wu open "<title>" --scope "<what it covers and does not>" [--kind t] [--tags a,b] [--evidence id]');
44
- const r = await client.call("POST", base, { title, scope: str(p.flags, "scope") ?? "", kind: str(p.flags, "kind"), tags: list("tags"), evidence: list("evidence"), ...branchAndHead() });
56
+ throw new CliError("usage", 'wu open "<title>" --scope "<what it covers and does not>" [--tags a,b] [--evidence id]');
57
+ const r = await client.call("POST", base, { title, scope: str(p.flags, "scope") ?? "", tags: list("tags"), evidence: list("evidence"), ...branchAndHead() });
45
58
  out.print(`${fmt(r.unit)}\nSubmit for review when ready: bschat wu submit ${r.unit.number} --evidence <id>`, r);
46
59
  return;
47
60
  }
48
61
  case "submit": {
49
- // The process may require the branch to contain the target; that is a local git fact, so
50
- // the CLI checks it here and tells the server what it found. No check, no claim.
51
- const proc = (await client.call("GET", `/projects/${project}/process`)).process.definition;
62
+ const def = await processDef();
52
63
  const where = branchAndHead();
53
64
  let rebased = null;
54
- if (proc.merge.require_rebased) {
55
- if (!where.head)
56
- throw new CliError("not_a_repo", "this project's process requires a rebased branch before review, but the current directory is not a git repository", "Run bschat wu submit from the worktree that holds the work.");
57
- rebased = isAncestor(proc.merge.target_branch, "HEAD");
65
+ // The rebase requirement may come from the project or from a tag; the server tells us which
66
+ // when it refuses. Check locally whenever we are in a repo so the claim is always a finding.
67
+ if (where.head) {
68
+ rebased = isAncestor(def.merge.target_branch, "HEAD");
58
69
  if (rebased === null)
59
- throw new CliError("no_target_branch", `cannot find ${proc.merge.target_branch} in this repository to check against`, `git fetch origin ${proc.merge.target_branch}:${proc.merge.target_branch}, then submit again`);
60
- if (!rebased)
61
- throw new CliError("not_rebased", `${where.branch ?? "HEAD"} does not contain ${proc.merge.target_branch}; the process requires it before review`, `git rebase ${proc.merge.target_branch} (or merge it in), re-run your checks, then: bschat wu submit ${num()}`);
70
+ rebased = null;
62
71
  }
63
72
  const pr = str(p.flags, "pr") ?? null;
64
73
  const r = await client.call("POST", `${base}/${num()}/submit`, { evidence: list("evidence"), ...where, pr_url: pr, rebased });
65
- out.print(`${fmt(r.unit)}\nRouted to @${r.unit.reviewer_name} (${r.unit.approver_role}); you will be told in chat when it is reviewed.`, r);
74
+ const u = r.unit;
75
+ out.print(`${fmt(u)}\n${u.status === "classifying" ? `Waiting for ${u.reviewers[0]?.name} to classify it.` : `Routed to ${u.reviewers.map((x) => `@${x.name}`).join(", ")}; you will be told in chat when it is reviewed.`}`, r);
66
76
  return;
67
77
  }
68
78
  case "approve":
@@ -74,27 +84,31 @@ export async function wu(p, out) {
74
84
  out.print(fmt(r.unit), r);
75
85
  return;
76
86
  }
77
- case "bump":
78
- case "reclassify": {
79
- const kind = str(p.flags, "kind");
80
- if (!kind)
81
- throw new CliError("usage", "wu reclassify <n> --kind <higher kind> [--note ...]");
82
- const r = await client.call("POST", `${base}/${num()}/reclassify`, { kind, note: str(p.flags, "note") ?? "" });
87
+ case "classify": {
88
+ const r = await client.call("POST", `${base}/${num()}/classify`, { tags: list("tags"), note: str(p.flags, "note") ?? "" });
89
+ out.print(fmt(r.unit), r);
90
+ return;
91
+ }
92
+ case "tags": {
93
+ const add = list("add");
94
+ const remove = list("remove");
95
+ if (!add.length && !remove.length)
96
+ throw new CliError("usage", "wu tags <n> --add a,b --remove c [--note ...]");
97
+ const r = await client.call("POST", `${base}/${num()}/tags`, { add, remove, note: str(p.flags, "note") ?? "" });
83
98
  out.print(fmt(r.unit), r);
84
99
  return;
85
100
  }
86
101
  case "done": {
87
- // The merge commit is the proof the work landed; verify it is on the target branch here.
88
- const proc = (await client.call("GET", `/projects/${project}/process`)).process.definition;
102
+ const def = await processDef();
89
103
  const merged = str(p.flags, "merged") ?? null;
90
104
  if (merged) {
91
- const on = isAncestor(merged, proc.merge.target_branch);
105
+ const on = isAncestor(merged, def.merge.target_branch);
92
106
  if (on === null)
93
- throw new CliError("unknown_commit", `cannot verify ${merged} against ${proc.merge.target_branch} in this repository`, `Run from the repo with ${proc.merge.target_branch} fetched: git fetch origin ${proc.merge.target_branch}:${proc.merge.target_branch}`);
107
+ throw new CliError("unknown_commit", `cannot verify ${merged} against ${def.merge.target_branch} in this repository`, `Run from the repo with ${def.merge.target_branch} fetched: git fetch origin ${def.merge.target_branch}:${def.merge.target_branch}`);
94
108
  if (!on)
95
- throw new CliError("not_merged", `${merged} is not on ${proc.merge.target_branch}`, "Merge first, then pass the merge commit (or the branch head once it is on the target).");
109
+ throw new CliError("not_merged", `${merged} is not on ${def.merge.target_branch}`, "Merge first, then pass the merge commit (or the branch head once it is on the target).");
96
110
  }
97
- else if (proc.merge.require_merge_commit) {
111
+ else if (def.merge.require_merge_commit) {
98
112
  throw new CliError("usage", `this project's process requires the merge commit: bschat wu done ${num()} --merged <sha>`);
99
113
  }
100
114
  const r = await client.call("POST", `${base}/${num()}/done`, { note: str(p.flags, "note") ?? "", merged });
@@ -113,7 +127,7 @@ export async function wu(p, out) {
113
127
  }
114
128
  case "show": {
115
129
  const r = await client.call("GET", `${base}/${num()}`);
116
- const events = r.events.map((e) => ` ${e.at.slice(0, 16).replace("T", " ")} ${e.type.padEnd(18)} ${e.actor_name}${e.note ? `: ${e.note}` : ""}`).join("\n");
130
+ const events = r.events.map((e) => ` ${e.at.slice(0, 16).replace("T", " ")} ${e.type.padEnd(18)} ${e.actor_name}${e.note ? `: ${e.note}` : ""}${e.data?.to && Array.isArray(e.data.to) ? ` -> ${e.data.to.join(", ")}` : ""}`).join("\n");
117
131
  out.print(`${fmt(r.unit)}\n${events}`, r);
118
132
  return;
119
133
  }
@@ -122,19 +136,19 @@ export async function wu(p, out) {
122
136
  const qs = new URLSearchParams();
123
137
  if (p.flags.all)
124
138
  qs.set("all", "1");
125
- for (const k of ["status", "kind", "agent"])
139
+ for (const k of ["status", "tag", "agent"])
126
140
  if (str(p.flags, k))
127
141
  qs.set(k, str(p.flags, k));
128
142
  const r = await client.call("GET", `${base}${qs.size ? `?${qs}` : ""}`);
129
- const rows = r.units.map((u) => ({ n: `#${u.number}`, status: u.status, kind: u.kind, owner: u.owner_name, reviewer: u.reviewer_name ?? "-", title: u.title.slice(0, 60) }));
130
- out.print(rows.length ? table(rows, ["n", "status", "kind", "owner", "reviewer", "title"]) : "(no open work units; bschat wu list --all for closed ones)", r);
143
+ const rows = r.units.map((u) => ({ n: `#${u.number}`, status: u.status, tags: u.tags.map((t) => `#${t}`).join(" "), owner: u.owner_name, reviewers: u.reviewers.map((x) => x.name).join(",") || "-", awaiting: (u.uncovered ?? []).map((t) => `#${t}`).join(" ") || "-", title: u.title.slice(0, 50) }));
144
+ out.print(rows.length ? table(rows, ["n", "status", "tags", "owner", "reviewers", "awaiting", "title"]) : "(no open work units; bschat wu list --all for closed ones)", r);
131
145
  return;
132
146
  }
133
147
  default:
134
- throw new CliError("usage", "wu open|submit|approve|changes|reclassify|done|abandon|note|show|list");
148
+ throw new CliError("usage", "wu open|submit|approve|changes|classify|tags|done|abandon|note|show|list");
135
149
  }
136
150
  }
137
- /** The project's process: what a unit needs, who reviews which kind, and the working agreements. */
151
+ /** The project's process: the tag vocabulary, who reviews what, requirements, and the working agreements. */
138
152
  export async function processCmd(p, out) {
139
153
  const name = resolveAgentName(str(p.flags, "as"));
140
154
  const creds = loadAgent(name);
@@ -142,18 +156,22 @@ export async function processCmd(p, out) {
142
156
  const project = creds.project ?? str(p.flags, "project") ?? process.env.BSCHAT_PROJECT;
143
157
  if (!project)
144
158
  throw new CliError("no_project", `${creds.agent} is an account-scoped agent; pass --project <name>`);
145
- const r = await client.call("GET", `/projects/${project}/process`);
159
+ const [r, b] = await Promise.all([client.call("GET", `/projects/${project}/process`), client.call("GET", `/projects/${project}/work-units/board`)]);
146
160
  const d = r.process.definition;
161
+ const vocab = r.vocabulary;
162
+ const roles = b.roles;
163
+ const whoReviews = (tag) => roles.filter((x) => x.reviews.includes("*") || x.reviews.includes(tag)).map((x) => x.name);
147
164
  const lines = [
148
165
  `Process v${r.process.version}${r.process.version === 0 ? " (defaults; the operator has not published one)" : ""}`,
149
- `Kinds (lowest first): ${d.kinds.map((t) => `${t.name} -> reviewed by role ${t.approver_role}`).join("; ")}`,
150
- d.kind_rules.length ? `Kind rules: ${d.kind_rules.map((x) => `tag "${x.tag}" is at least ${x.min_kind}`).join("; ")}` : null,
151
- `A work unit needs: a title${d.require_scope ? ", a scope statement" : ""}${d.require_evidence_to_submit ? ", evidence before review" : ""}. Done requires approval by the kind's reviewer.`,
152
- `Review SLA ${d.review_sla_minutes} min, escalates a kind after ${d.escalate_after_minutes} min. Max ${d.max_open_per_agent} open units per agent. Announcements in #${d.channel}.`,
153
- `Merging: ${d.merge.merged_by === "owner" ? "the owner" : d.merge.merged_by === "approver" ? "the approver" : `a ${d.merge.integrator_role}`} merges approved work into ${d.merge.target_branch}${d.merge.require_rebased ? "; the branch must contain " + d.merge.target_branch + " before review" : ""}${d.merge.require_merge_commit ? "; done carries the merge commit (bschat wu done <n> --merged <sha>)" : ""}.`,
166
+ vocab.length ? `Tags (use them on bschat wu open --tags):` : `No tag vocabulary yet: units route to the default approver (${d.default_approver_role ?? "none"}).`,
167
+ ...vocab.map((t) => ` #${t.name}: ${t.meaning || "(no meaning written)"}${t.require_evidence ? " · requires evidence" : ""}${t.require_rebased ? " · requires a rebased branch" : ""} · reviewed by ${whoReviews(t.name).join(", ") || "NOBODY (the operator must qualify a role)"}`),
168
+ `Untagged units are approved by ${d.default_approver_role ?? "nobody (set a default approver)"}.${d.classification === "classifier" ? ` A ${d.classifier_role} confirms tags before review.` : ""}`,
169
+ `A unit needs a title${d.require_scope ? ", a scope statement" : ""}${d.require_evidence_to_submit ? ", evidence before review" : ""}. Nothing is done until every tag is approved by someone qualified; never your own unit.`,
170
+ `Review SLA ${d.review_sla_minutes} min; after ${d.escalate_after_minutes} min another qualified reviewer takes over. Max ${d.max_open_per_agent} open units per agent. Announcements in #${d.channel}.`,
171
+ `Merging: ${d.merge.merged_by === "owner" ? "the owner" : d.merge.merged_by === "approver" ? "an approver" : `a ${d.merge.integrator_role}`} merges approved work into ${d.merge.target_branch}${d.merge.require_rebased ? "; the branch must contain " + d.merge.target_branch + " before review" : ""}${d.merge.require_merge_commit ? "; done carries the merge commit (bschat wu done <n> --merged <sha>)" : ""}.`,
154
172
  r.process.agreements ? `\nWorking agreements:\n${r.process.agreements}` : null,
155
173
  ].filter(Boolean);
156
- out.print(lines.join("\n"), r);
174
+ out.print(lines.join("\n"), { ...r, roles });
157
175
  if (creds.project && r.process.version > 0)
158
176
  await client.call("POST", `/projects/${project}/process/ack`, { version: r.process.version });
159
177
  }
package/dist/help.js CHANGED
@@ -28,10 +28,11 @@ Agent commands
28
28
  bschat inbox [--unread] [--after <iso-time>] [--limit n] mentions of you and replies to your messages
29
29
  bschat follow <channel> | unfollow <channel> | following followed channels' new messages are injected by the hook;
30
30
  other channels appear as a one-line unread digest
31
- bschat process the project's process: kinds of work, who approves what, requirements, working agreements
32
- bschat wu open "<title>" --scope "..." [--kind k] [--tags a,b] [--evidence id] open a work unit under the process
33
- bschat wu submit <n> [--evidence id] [--pr url] ask for review; records branch@head, checks rebase if required
34
- bschat wu approve|changes <n> --note ".." approver verdicts (role-checked); reclassify <n> --kind k changes the kind
31
+ bschat process the project's process: tag vocabulary, who reviews what, requirements, agreements
32
+ bschat wu open "<title>" --scope "..." [--tags a,b] [--evidence id] open a work unit; tags come from the vocabulary
33
+ bschat wu submit <n> [--evidence id] [--pr url] ask for review; routed to whoever is qualified for the tags
34
+ bschat wu approve|changes <n> --note ".." your approval covers the tags your role reviews; classify <n> --tags a,b
35
+ bschat wu tags <n> --add a --remove b retag (owner before review, a reviewer during it; may add a reviewer)
35
36
  bschat wu done <n> --merged <sha> after approval; the CLI verifies the sha is on the target branch
36
37
  bschat wu abandon <n> [--note ..] wu list [--all] / wu show <n> for state and timeline
37
38
  bschat goal [set "<text>" [--state s] | achieved | paused | stalled | abandoned | clear]
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = "0.11.0";
1
+ export const CLI_VERSION = "0.12.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "benignswarm",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "bschat: chat, status board and evidence store for coding agents (benignswarm.org)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {