@bakers-build/addon-forge 0.11.1-next.1 → 0.11.1-next.3

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.
@@ -29,6 +29,11 @@ export interface ForgeMerge {
29
29
  readonly subject: string;
30
30
  readonly body: string;
31
31
  }
32
+ export interface IssueLabel {
33
+ readonly name: string;
34
+ /** False for a label inherited from a group. */
35
+ readonly is_project_label: boolean;
36
+ }
32
37
  export interface ForgeBackend {
33
38
  readonly id: string;
34
39
  /** Every credential value; the tools redact them from all output. */
@@ -63,6 +68,21 @@ export interface ForgeBackend {
63
68
  isMerged(pr: ForgePr): Promise<boolean>;
64
69
  /** The [tail] of a job's log; refuses a job outside the repository. */
65
70
  jobLog(jobId: number, maxBytes: number): Promise<LogTail>;
71
+ /**
72
+ * The origin issue's operations, by its web URL; a backend refuses a URL
73
+ * outside its host before any request. Labels include inherited ones.
74
+ */
75
+ issueLabels(issueUrl: string): Promise<IssueLabel[]>;
76
+ /** One update; returns the issue's labels afterwards. */
77
+ updateIssueLabels(issueUrl: string, change: {
78
+ add?: string;
79
+ remove: readonly string[];
80
+ }): Promise<string[]>;
81
+ /** One write, never retried: a lost answer must not post twice. */
82
+ commentIssue(issueUrl: string, body: string): Promise<{
83
+ id: number;
84
+ url: string;
85
+ }>;
66
86
  }
67
87
  export interface LogTail {
68
88
  readonly text: string;
@@ -15,6 +15,9 @@ const METHODS = [
15
15
  'merge',
16
16
  'isMerged',
17
17
  'jobLog',
18
+ 'issueLabels',
19
+ 'updateIssueLabels',
20
+ 'commentIssue',
18
21
  ];
19
22
  /** Reject a factory result that is not a `ForgeBackend`. */
20
23
  export function assertForgeBackend(value, spec) {
@@ -1,5 +1,5 @@
1
- // The forge addon: six conductor tools a sandboxed run delivers through,
2
- // while the token stays with the conductor. Without a forge entry no tool is
1
+ // The forge addon: the conductor tools a sandboxed run delivers and updates
2
+ // its origin issue through, while the token stays with the conductor. Without a forge entry no tool is
3
3
  // served and runs deliver as before.
4
4
  import { FORGE_TOOL_DEFINITIONS } from './tool-definitions.js';
5
5
  // Configurable on either level; the machine entry's with wins.
@@ -74,6 +74,26 @@ export const FORGE_TOOL_DEFINITIONS = {
74
74
  required: ['job_id'],
75
75
  },
76
76
  },
77
+ forge_issue_update: {
78
+ description: "The run ticket's origin issue, with the conductor's credentials. operation list_labels: the origin project's labels, inherited group labels included, as {name, is_project_label}. update_labels: in one update add the label `add` and remove the labels `remove`; every name must be a listed label spelled exactly, none is created; returns the issue's labels. comment: post `body` (Markdown, sent unchanged) once, never retried; returns {id, url}. Refused without an origin, and on a backend without origin issues (GitHub): record the step in Manual review.",
79
+ input: {
80
+ type: 'object',
81
+ properties: {
82
+ operation: {
83
+ type: 'string',
84
+ enum: ['list_labels', 'update_labels', 'comment'],
85
+ },
86
+ add: { type: 'string', description: 'update_labels: label to set' },
87
+ remove: {
88
+ type: 'array',
89
+ items: { type: 'string' },
90
+ description: 'update_labels: labels to remove',
91
+ },
92
+ body: { type: 'string', description: 'comment: Markdown text' },
93
+ },
94
+ required: ['operation'],
95
+ },
96
+ },
77
97
  forge_merge: {
78
98
  description: "Merge the open PR/MR of an owned branch into its base, once it is conflict free and overall is success. Human approval is the workflow's merge gate, not this tool's.",
79
99
  input: { type: 'object', properties: { branch } },
@@ -1,6 +1,7 @@
1
1
  import type { ToolHandler } from '@bakers-build/conductor/contract';
2
2
  import type { ForgeBackend, ForgeCheck } from './backend.js';
3
3
  export declare const FORGE_NEEDS_RUN = "forge tools act only for an agent run: the call carries no ticket branch_name and base_branch (an operator delivers by hand)";
4
+ export declare const FORGE_NEEDS_ORIGIN = "forge_issue_update acts only on the run ticket's origin issue, and this ticket has none";
4
5
  export interface ForgeToolDeps {
5
6
  backend(): Promise<ForgeBackend>;
6
7
  /** The forge entry's `with` (merge rules). */
package/dist/src/tools.js CHANGED
@@ -6,6 +6,7 @@ import { FORGE_NEEDS_BACKEND, loadForgeBackend, mergeRule } from './config.js';
6
6
  import { fetchBranches, pushBranch, updateBranch } from './git.js';
7
7
  import { derivedBase, isConventionalTitle, isOwned, ownershipRefusal, redact, TITLE_REFUSAL, } from './rules.js';
8
8
  export const FORGE_NEEDS_RUN = 'forge tools act only for an agent run: the call carries no ticket branch_name and base_branch (an operator delivers by hand)';
9
+ export const FORGE_NEEDS_ORIGIN = "forge_issue_update acts only on the run ticket's origin issue, and this ticket has none";
9
10
  function runOf(req) {
10
11
  const t = req.ticket;
11
12
  if (!t?.branchName || !t.baseBranch)
@@ -36,6 +37,13 @@ async function currentBase(req, branch, run) {
36
37
  throw refuse('no target_branch or base_branch returned');
37
38
  return target;
38
39
  }
40
+ /** The ticket's origin as the server returns it now, else the run's copy. */
41
+ async function originOf(req) {
42
+ const t = req.currentTicket ? await req.currentTicket() : req.ticket;
43
+ if (!t?.issueUrl)
44
+ throw new Error(FORGE_NEEDS_ORIGIN);
45
+ return t.issueUrl;
46
+ }
39
47
  function ownedBranch(req, run) {
40
48
  const branch = req.args.branch ?? run.branchName;
41
49
  if (!isOwned(branch, run.branchName))
@@ -286,6 +294,40 @@ export function forgeTools(deps) {
286
294
  log: log.text,
287
295
  });
288
296
  },
297
+ forge_issue_update: async (req) => {
298
+ runOf(req);
299
+ const op = req.args.operation;
300
+ if (op === 'comment') {
301
+ const body = req.args.body;
302
+ if (typeof body !== 'string' || body.trim() === '')
303
+ throw new Error('comment needs a non-blank body');
304
+ const issueUrl = await originOf(req);
305
+ return json(await (await backend()).commentIssue(issueUrl, body));
306
+ }
307
+ if (op === 'list_labels') {
308
+ const issueUrl = await originOf(req);
309
+ const labels = await (await backend()).issueLabels(issueUrl);
310
+ return json({ issue_url: issueUrl, labels });
311
+ }
312
+ if (op !== 'update_labels')
313
+ throw new Error('operation must be list_labels, update_labels or comment');
314
+ const add = typeof req.args.add === 'string' ? req.args.add : '';
315
+ const remove = req.args.remove ?? [];
316
+ if (!add && remove.length === 0)
317
+ throw new Error('update_labels needs add or remove');
318
+ const issueUrl = await originOf(req);
319
+ const b = await backend();
320
+ // GitLab creates an unknown label it is sent: only listed names pass.
321
+ const known = new Set((await b.issueLabels(issueUrl)).map((l) => l.name));
322
+ const unknown = [add, ...remove].filter((n) => n && !known.has(n));
323
+ if (unknown.length > 0)
324
+ throw new Error(`update_labels sends only existing labels, spelled exactly; not found: ${unknown.join(', ')}; nothing was sent`);
325
+ const labels = await b.updateIssueLabels(issueUrl, {
326
+ ...(add ? { add } : {}),
327
+ remove,
328
+ });
329
+ return json({ issue_url: issueUrl, labels });
330
+ },
289
331
  };
290
332
  return Object.fromEntries(Object.entries(tools).map(([n, h]) => [n, guarded(h)]));
291
333
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-forge",
3
- "version": "0.11.1-next.1",
3
+ "version": "0.11.1-next.3",
4
4
  "description": "bakers.build forge tools: a sandboxed run fetches, pushes its own branches, opens its PR/MR, reads checks and merges through the conductor, which holds the token. Backends implement the ForgeBackend contract (./backend).",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -22,11 +22,11 @@
22
22
  "directory": "bakers-cli/addons/forge"
23
23
  },
24
24
  "peerDependencies": {
25
- "@bakers-build/conductor": "^0.11.1-next.1",
26
- "@bakers-build/core": "^0.11.1-next.1"
25
+ "@bakers-build/conductor": "^0.11.1-next.3",
26
+ "@bakers-build/core": "^0.11.1-next.3"
27
27
  },
28
28
  "bakersBuild": {
29
- "commit": "a32643ac726f468692c47ff7be1759da3f63fd87",
29
+ "commit": "0bd662a88dd41e11e79a7912bf83dc0ee48a733d",
30
30
  "channel": "next"
31
31
  }
32
32
  }