@intentius/chant 0.124.57 → 0.124.59
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/dist/ci-product-words.d.ts +47 -2
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +59 -1
- package/dist/ci-product.d.ts +26 -2
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +25 -2
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +1 -1
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +5 -1
- package/dist/cli/handlers/init.d.ts.map +1 -1
- package/dist/cli/handlers/init.js +16 -0
- package/dist/cli/handlers/lifecycle-drift.d.ts +2 -1
- package/dist/cli/handlers/lifecycle-drift.d.ts.map +1 -1
- package/dist/cli/handlers/lifecycle-drift.js +4 -2
- package/dist/cli/handlers/lock.d.ts.map +1 -1
- package/dist/cli/handlers/lock.js +45 -2
- package/dist/cli/handlers/serve.d.ts.map +1 -1
- package/dist/cli/handlers/serve.js +9 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +11 -3
- package/dist/cli/mcp/product-tools.d.ts +40 -7
- package/dist/cli/mcp/product-tools.d.ts.map +1 -1
- package/dist/cli/mcp/product-tools.js +58 -15
- package/dist/cli/mcp/read-only.d.ts +2 -1
- package/dist/cli/mcp/read-only.d.ts.map +1 -1
- package/dist/cli/mcp/read-only.js +2 -1
- package/dist/cli/mcp/server.d.ts +11 -0
- package/dist/cli/mcp/server.d.ts.map +1 -1
- package/dist/cli/mcp/server.js +15 -3
- package/dist/cli/mcp-config.d.ts +4 -1
- package/dist/cli/mcp-config.d.ts.map +1 -1
- package/dist/cli/mcp-config.js +6 -2
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +27 -0
- package/dist/cli/registry.d.ts +14 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/pr-pipeline.d.ts +56 -0
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +55 -2
- package/dist/components/product-pipeline.d.ts +18 -1
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +8 -2
- package/dist/drift-record.d.ts +5 -0
- package/dist/drift-record.d.ts.map +1 -1
- package/dist/e2e-harness/driver.d.ts.map +1 -1
- package/dist/e2e-harness/driver.js +97 -0
- package/dist/e2e-harness/forgejo.d.ts +5 -1
- package/dist/e2e-harness/forgejo.d.ts.map +1 -1
- package/dist/e2e-harness/forgejo.js +35 -0
- package/dist/e2e-harness/index.d.ts +7 -0
- package/dist/e2e-harness/index.d.ts.map +1 -1
- package/dist/e2e-harness/index.js +10 -1
- package/dist/e2e-harness/ports.d.ts +31 -0
- package/dist/e2e-harness/ports.d.ts.map +1 -1
- package/dist/e2e-harness/scenario.d.ts.map +1 -1
- package/dist/e2e-harness/scenario.js +9 -5
- package/dist/e2e-harness/schemas/e2e-scenario.schema.json +43 -3
- package/dist/e2e-harness/schemas/index.d.ts +22 -1
- package/dist/e2e-harness/schemas/index.d.ts.map +1 -1
- package/dist/e2e-harness/schemas/index.js +1 -1
- package/dist/e2e-harness/steps.d.ts.map +1 -1
- package/dist/e2e-harness/steps.js +4 -0
- package/dist/lifecycle/lock-beat.d.ts +27 -0
- package/dist/lifecycle/lock-beat.d.ts.map +1 -0
- package/dist/lifecycle/lock-beat.js +84 -0
- package/dist/lifecycle/resource-lock.d.ts +54 -1
- package/dist/lifecycle/resource-lock.d.ts.map +1 -1
- package/dist/lifecycle/resource-lock.js +128 -7
- package/dist/mcp/types.d.ts +9 -0
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/op/activities/activity-contracts.d.ts +4 -4
- package/dist/op/index.d.ts +1 -1
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +1 -1
- package/dist/op/op-waves-notify.d.ts.map +1 -1
- package/dist/op/op-waves-notify.js +11 -0
- package/dist/op/op-waves-run.d.ts +28 -1
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +92 -7
- package/dist/op/op-waves.d.ts +12 -1
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +9 -2
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/template-request/index.d.ts +9 -0
- package/dist/template-request/index.d.ts.map +1 -0
- package/dist/template-request/index.js +8 -0
- package/dist/template-request/request-body.d.ts +21 -0
- package/dist/template-request/request-body.d.ts.map +1 -0
- package/dist/template-request/request-body.js +86 -0
- package/dist/template-request/template-request.d.ts +100 -0
- package/dist/template-request/template-request.d.ts.map +1 -0
- package/dist/template-request/template-request.js +149 -0
- package/dist/template-request/template-request.schema.json +100 -0
- package/dist/template-request/template-spec.d.ts +83 -0
- package/dist/template-request/template-spec.d.ts.map +1 -0
- package/dist/template-request/template-spec.js +146 -0
- package/dist/template-request/template.schema.json +114 -0
- package/dist/template-request/validate.d.ts +4 -0
- package/dist/template-request/validate.d.ts.map +1 -0
- package/dist/template-request/validate.js +21 -0
- package/dist/wave-runtime.mjs +298 -298
- package/dist/workspace/drift-cli.d.ts +13 -1
- package/dist/workspace/drift-cli.d.ts.map +1 -1
- package/dist/workspace/drift-cli.js +19 -3
- package/package.json +8 -1
- package/src/ci-product-words.test.ts +23 -0
- package/src/ci-product-words.ts +68 -3
- package/src/ci-product.ts +31 -1
- package/src/cli/commands/init.ts +3 -1
- package/src/cli/handlers/build.ts +5 -1
- package/src/cli/handlers/init.ts +18 -0
- package/src/cli/handlers/lifecycle-drift.test.ts +52 -0
- package/src/cli/handlers/lifecycle-drift.ts +4 -2
- package/src/cli/handlers/lock.ts +41 -2
- package/src/cli/handlers/serve.ts +9 -0
- package/src/cli/main.ts +11 -3
- package/src/cli/mcp/product-tools.test.ts +56 -1
- package/src/cli/mcp/product-tools.ts +66 -15
- package/src/cli/mcp/read-only.ts +2 -1
- package/src/cli/mcp/server.ts +20 -5
- package/src/cli/mcp-config.test.ts +52 -2
- package/src/cli/mcp-config.ts +6 -3
- package/src/cli/parse-args.ts +19 -0
- package/src/cli/registry.ts +14 -0
- package/src/components/pr-pipeline.ts +87 -2
- package/src/components/product-actions.test.ts +76 -0
- package/src/components/product-pipeline.ts +21 -2
- package/src/drift-record.ts +5 -0
- package/src/e2e-harness/driver.test.ts +163 -0
- package/src/e2e-harness/driver.ts +86 -1
- package/src/e2e-harness/forgejo.ts +42 -1
- package/src/e2e-harness/index.ts +11 -1
- package/src/e2e-harness/ports.ts +33 -0
- package/src/e2e-harness/scenario.ts +8 -6
- package/src/e2e-harness/schemas/README.md +11 -2
- package/src/e2e-harness/schemas/e2e-scenario.schema.json +43 -3
- package/src/e2e-harness/schemas/index.ts +5 -1
- package/src/e2e-harness/schemas.test.ts +44 -1
- package/src/e2e-harness/steps.ts +4 -0
- package/src/lifecycle/lock-beat.ts +99 -0
- package/src/lifecycle/resource-lock-liveness.test.ts +289 -0
- package/src/lifecycle/resource-lock.ts +143 -8
- package/src/mcp/types.ts +9 -0
- package/src/op/index.ts +1 -0
- package/src/op/op-waves-notify.ts +11 -0
- package/src/op/op-waves-preview.test.ts +167 -0
- package/src/op/op-waves-run.ts +116 -8
- package/src/op/op-waves.ts +20 -3
- package/src/release-floors.ts +1 -1
- package/src/template-request/__fixtures__/request-body.md +41 -0
- package/src/template-request/index.ts +8 -0
- package/src/template-request/request-body.ts +91 -0
- package/src/template-request/template-request.schema.json +100 -0
- package/src/template-request/template-request.test.ts +315 -0
- package/src/template-request/template-request.ts +234 -0
- package/src/template-request/template-spec.ts +176 -0
- package/src/template-request/template.schema.json +114 -0
- package/src/template-request/validate.ts +28 -0
- package/src/workspace/drift-cli.test.ts +35 -1
- package/src/workspace/drift-cli.ts +21 -3
|
@@ -10,7 +10,10 @@ import { join } from "node:path";
|
|
|
10
10
|
import { tmpdir } from "node:os";
|
|
11
11
|
import { pathToFileURL } from "node:url";
|
|
12
12
|
import { McpServer } from "./server";
|
|
13
|
-
import { productToolWriteWord, ProductToolRefusedError, type ProductMcpHook } from "./product-tools";
|
|
13
|
+
import { PRODUCT_MCP_PROPOSE_FLOOR, productToolWriteWord, ProductToolRefusedError, type ProductMcpHook } from "./product-tools";
|
|
14
|
+
import { PROPOSE_INSTRUCTIONS } from "./server";
|
|
15
|
+
import { READ_ONLY_CORE_TOOLS } from "./read-only";
|
|
16
|
+
import * as ciProduct from "../../ci-product";
|
|
14
17
|
import { reportReader, reportToolKey, safeReportKey } from "./report-tools";
|
|
15
18
|
import type { ToolDefinition } from "./types";
|
|
16
19
|
import type { McpToolContribution } from "../../mcp/types";
|
|
@@ -105,6 +108,58 @@ describe("the product tool hook (#4555)", () => {
|
|
|
105
108
|
});
|
|
106
109
|
});
|
|
107
110
|
|
|
111
|
+
describe("the --propose tier (#4655)", () => {
|
|
112
|
+
const forge = (name: string, handler: McpToolContribution["handler"] = async () => ({ opened: name })): McpToolContribution => ({ ...tool(name, undefined, handler), forgeWrite: true });
|
|
113
|
+
const hook = (tools: McpToolContribution[], extra: Partial<ProductMcpHook> = {}): ProductMcpHook => ({ product: "terragucci", tools: () => tools, ...extra });
|
|
114
|
+
|
|
115
|
+
test("serves the read tools, the readOnly product tools and the forgeWrite ones, and no op, signal, apply or approve tool", async () => {
|
|
116
|
+
const server = new McpServer([], { readOnly: true, propose: true, product: hook([forge("request_from_template"), tool("templates", true), tool("drift_scan")]) });
|
|
117
|
+
expect(server.readOnly).toBe(true);
|
|
118
|
+
expect(server.propose).toBe(true);
|
|
119
|
+
const names = await listed(server);
|
|
120
|
+
expect(names.filter((n) => n.startsWith("terragucci:")).sort()).toEqual(["terragucci:request_from_template", "terragucci:templates"]);
|
|
121
|
+
expect(names.filter((n) => !n.startsWith("terragucci:")).every((n) => READ_ONLY_CORE_TOOLS.has(n))).toBe(true);
|
|
122
|
+
for (const name of ["op-run", "op-signal", "op-approve", "apply", "lifecycle-snapshot"]) expect(names, name).not.toContain(name);
|
|
123
|
+
expect(JSON.parse((await call(server, "terragucci:request_from_template")).text)).toEqual({ opened: "request_from_template" });
|
|
124
|
+
const res = await server.handleRequest({ jsonrpc: "2.0", id: 1, method: "initialize", params: {} });
|
|
125
|
+
const instructions = (res.result as { instructions: string }).instructions;
|
|
126
|
+
expect(instructions).toContain(PROPOSE_INSTRUCTIONS);
|
|
127
|
+
expect(instructions).toMatch(/open pull requests and comments only/);
|
|
128
|
+
expect(instructions).toMatch(/belong to a person/);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("the read-only server without propose refuses to start, naming the forgeWrite tool", () => {
|
|
132
|
+
const tools = [forge("request_from_template"), tool("templates", true)];
|
|
133
|
+
expect(() => new McpServer([], { readOnly: true, product: hook(tools) })).toThrow(ProductToolRefusedError);
|
|
134
|
+
expect(() => new McpServer([], { readOnly: true, product: hook(tools) })).toThrow(/terragucci:request_from_template|request_from_template/);
|
|
135
|
+
expect(() => new McpServer([], { product: hook(tools) })).toThrow(/request_from_template.*--propose/);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("a forgeWrite tool named with a strong word refuses the start, naming the word", () => {
|
|
139
|
+
for (const [name, word] of [["approve_request", "approve"], ["merge_request", "merge"], ["request_override", "override"], ["apply_template", "apply"], ["create_request", "create"]] as const) {
|
|
140
|
+
const start = () => new McpServer([], { readOnly: true, propose: true, product: hook([forge(name)]) });
|
|
141
|
+
expect(start, name).toThrow(ProductToolRefusedError);
|
|
142
|
+
expect(start, name).toThrow(new RegExp(`${name} would ${word}`));
|
|
143
|
+
}
|
|
144
|
+
expect(productToolWriteWord("propose_change", ["request", "propose"])).toBeUndefined();
|
|
145
|
+
expect(productToolWriteWord("request_from_template", ["request", "propose"])).toBeUndefined();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("propose on the hook turns the tier on, and an ordinary server refuses it", async () => {
|
|
149
|
+
const tools = [forge("request_from_template"), tool("templates", true)];
|
|
150
|
+
expect(await listed(new McpServer([], { product: hook(tools, { propose: true }) }))).toContain("terragucci:request_from_template");
|
|
151
|
+
expect(() => new McpServer([], { product: hook(tools, { readOnly: false, propose: true }) })).toThrow(/--read-only --propose/);
|
|
152
|
+
// The ordinary server serves a forgeWrite tool as any other.
|
|
153
|
+
expect(await listed(new McpServer([], { product: hook(tools, { readOnly: false }) }))).toContain("terragucci:request_from_template");
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test("the tier's floor is on @intentius/chant/ci-product for a product to feature-detect", () => {
|
|
157
|
+
expect(PRODUCT_MCP_PROPOSE_FLOOR).toBe("0.124.58");
|
|
158
|
+
expect(ciProduct.PRODUCT_MCP_PROPOSE_FLOOR).toBe(PRODUCT_MCP_PROPOSE_FLOOR);
|
|
159
|
+
expect(ciProduct.PRODUCT_TOOL_PROPOSE_WORDS).toEqual(["request", "propose"]);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
108
163
|
describe("the report tool's keys (#4555)", () => {
|
|
109
164
|
test("take a pull request, a commit, an optional member and one of the stage files", () => {
|
|
110
165
|
expect(reportToolKey({ pr: "12", commit: "a".repeat(40), file: "change-set.json" })).toBe(`12/${"a".repeat(40)}/change-set.json`);
|
|
@@ -20,10 +20,19 @@
|
|
|
20
20
|
* the server's own credentials, never from a tool's arguments.
|
|
21
21
|
*
|
|
22
22
|
* Tools are registered as `<product>:<name>`, as a lexicon's are.
|
|
23
|
+
*
|
|
24
|
+
* chant#4655 adds a tier between read-only and ordinary for a product tool
|
|
25
|
+
* that opens a pull request (`request_from_template`): `chant serve mcp
|
|
26
|
+
* --read-only --propose`, or `propose: true` on the hook. It serves what the
|
|
27
|
+
* read-only server serves, plus the product tools that declare `forgeWrite:
|
|
28
|
+
* true`, and never chant's op, approve or snapshot tools. The read-only
|
|
29
|
+
* server without `--propose` refuses to start with a `forgeWrite` tool. On
|
|
30
|
+
* the tier a `forgeWrite` tool's name is exempt from the write-word check for
|
|
31
|
+
* `request` and `propose` only: `approve_request` still refuses the start.
|
|
32
|
+
* A product feature-detects the tier on {@link PRODUCT_MCP_PROPOSE_FLOOR}.
|
|
23
33
|
*/
|
|
24
34
|
|
|
25
35
|
import type { McpToolContribution } from "../../mcp/types";
|
|
26
|
-
import { servesContributedTool } from "./read-only";
|
|
27
36
|
import { reportReader, reportUrlFor, type ReportReader } from "./report-tools";
|
|
28
37
|
|
|
29
38
|
/** What a product's tools are handed. */
|
|
@@ -32,6 +41,8 @@ export interface ProductMcpContext {
|
|
|
32
41
|
cwd: string;
|
|
33
42
|
/** Whether the server is read-only. */
|
|
34
43
|
readOnly: boolean;
|
|
44
|
+
/** Whether the read-only server also serves the product's `forgeWrite` tools (`--propose`, chant#4655). */
|
|
45
|
+
propose: boolean;
|
|
35
46
|
/**
|
|
36
47
|
* The report store, read-only: the hook's `reportUrl`, else the declared
|
|
37
48
|
* `ci.reportUrl`. Resolves undefined when neither names one.
|
|
@@ -49,10 +60,27 @@ export interface ProductMcpHook {
|
|
|
49
60
|
reportUrl?: string;
|
|
50
61
|
/** `false` starts an ordinary server through the hook. Default: read-only. */
|
|
51
62
|
readOnly?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* `true` serves the product's `forgeWrite` tools on the read-only server,
|
|
65
|
+
* as `--propose` does (chant#4655). It needs the server read-only: with
|
|
66
|
+
* `readOnly: false` the server refuses to start.
|
|
67
|
+
*/
|
|
68
|
+
propose?: boolean;
|
|
52
69
|
/** Text added to the server's `initialize` instructions. */
|
|
53
70
|
instructions?: string;
|
|
54
71
|
}
|
|
55
72
|
|
|
73
|
+
/**
|
|
74
|
+
* The first chant whose `chant serve mcp` has the `--propose` tier and serves
|
|
75
|
+
* `forgeWrite` product tools on it (chant#4655). A product checks this before
|
|
76
|
+
* it passes `--propose` or `propose: true`, and refuses naming this release
|
|
77
|
+
* when its chant is older.
|
|
78
|
+
*/
|
|
79
|
+
export const PRODUCT_MCP_PROPOSE_FLOOR = "0.124.58";
|
|
80
|
+
|
|
81
|
+
/** The words a `forgeWrite` tool's name may hold on the `--propose` tier, which the write-word check passes over (chant#4655). */
|
|
82
|
+
export const PRODUCT_TOOL_PROPOSE_WORDS = ["request", "propose"] as const;
|
|
83
|
+
|
|
56
84
|
/** Words that say a tool would change something; a read-only server will not serve a tool named with one. terragucci's list. */
|
|
57
85
|
export const PRODUCT_TOOL_WRITE_WORDS = ["approve", "apply", "override", "revoke", "unlock", "lock", "merge", "resume", "migrate", "write", "put", "delete", "push", "commit", "publish", "reconcile", "rollout", "init", "generate", "respond", "relay", "notify", "update", "create", "exec"] as const;
|
|
58
86
|
|
|
@@ -65,16 +93,26 @@ export const PRODUCT_TOOL_STRONG_WORDS = ["approve", "override", "revoke", "unlo
|
|
|
65
93
|
* strong one anywhere: `last_apply` reads, `apply_wave` and `wave_approve`
|
|
66
94
|
* do not.
|
|
67
95
|
*/
|
|
68
|
-
export function productToolWriteWord(name: string): string | undefined {
|
|
96
|
+
export function productToolWriteWord(name: string, exempt: readonly string[] = []): string | undefined {
|
|
69
97
|
const parts = name.toLowerCase().split(/[^a-z]+/).filter(Boolean);
|
|
70
98
|
const first = parts[0] ?? "";
|
|
71
|
-
|
|
99
|
+
const words = (list: readonly string[]) => list.filter((w) => !exempt.includes(w));
|
|
100
|
+
return words(PRODUCT_TOOL_WRITE_WORDS).find((w) => first.startsWith(w)) ?? words(PRODUCT_TOOL_STRONG_WORDS).find((w) => parts.some((p) => p.startsWith(w)));
|
|
72
101
|
}
|
|
73
102
|
|
|
74
|
-
/**
|
|
103
|
+
/**
|
|
104
|
+
* A read-only server refused a product tool: one named as a write, or a
|
|
105
|
+
* `forgeWrite` tool on a server started without `--propose` (chant#4655).
|
|
106
|
+
*/
|
|
75
107
|
export class ProductToolRefusedError extends Error {
|
|
76
|
-
constructor(product: string, name: string, word: string) {
|
|
77
|
-
super(
|
|
108
|
+
constructor(product: string, name: string, word: string, tier: "read-only" | "propose" | "forge-write" = "read-only") {
|
|
109
|
+
super(
|
|
110
|
+
tier === "forge-write"
|
|
111
|
+
? `chant serve mcp is read-only for ${product}, and the tool ${name} opens pull requests (forgeWrite); the server does not start with it. Start it with --read-only --propose to serve it`
|
|
112
|
+
: tier === "propose"
|
|
113
|
+
? `chant serve mcp --propose serves ${product}'s tools that read or open pull requests and comments, and the tool ${name} would ${word}; the server does not start with it`
|
|
114
|
+
: `chant serve mcp is read-only for ${product}, and the tool ${name} would ${word}; the server does not start with it`,
|
|
115
|
+
);
|
|
78
116
|
this.name = "ProductToolRefusedError";
|
|
79
117
|
}
|
|
80
118
|
}
|
|
@@ -82,28 +120,41 @@ export class ProductToolRefusedError extends Error {
|
|
|
82
120
|
const PRODUCT = /^[a-z0-9][a-z0-9-]*$/;
|
|
83
121
|
|
|
84
122
|
/**
|
|
85
|
-
* The product tools a server serves
|
|
86
|
-
* declare `readOnly: true`,
|
|
87
|
-
*
|
|
123
|
+
* The product tools a server serves. On an ordinary server every tool. On a
|
|
124
|
+
* read-only server those that declare `readOnly: true`, none named as a
|
|
125
|
+
* write, and no `forgeWrite` tool (each a throw, so the server does not
|
|
126
|
+
* start). On the `--propose` tier the `readOnly: true` tools under the same
|
|
127
|
+
* check, plus the `forgeWrite` tools, whose names may hold `request` or
|
|
128
|
+
* `propose` but no other write word (chant#4655).
|
|
88
129
|
*/
|
|
89
130
|
export function productToolsServed(hook: ProductMcpHook, ctx: ProductMcpContext): McpToolContribution[] {
|
|
90
131
|
if (!PRODUCT.test(hook.product)) throw new Error(`the product tool hook's product ${JSON.stringify(hook.product)} is not a product name ([a-z0-9-])`);
|
|
91
|
-
const
|
|
92
|
-
if (ctx.readOnly)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
132
|
+
const tools = hook.tools(ctx);
|
|
133
|
+
if (!ctx.readOnly) return tools;
|
|
134
|
+
const served: McpToolContribution[] = [];
|
|
135
|
+
for (const t of tools) {
|
|
136
|
+
const short = t.name.startsWith(`${hook.product}:`) ? t.name.slice(hook.product.length + 1) : t.name;
|
|
137
|
+
if (t.forgeWrite === true) {
|
|
138
|
+
if (!ctx.propose) throw new ProductToolRefusedError(hook.product, t.name, "open a pull request", "forge-write");
|
|
139
|
+
const word = productToolWriteWord(short, PRODUCT_TOOL_PROPOSE_WORDS);
|
|
140
|
+
if (word) throw new ProductToolRefusedError(hook.product, t.name, word, "propose");
|
|
141
|
+
served.push(t);
|
|
142
|
+
} else if (t.readOnly === true) {
|
|
143
|
+
const word = productToolWriteWord(short);
|
|
144
|
+
if (word) throw new ProductToolRefusedError(hook.product, t.name, word, ctx.propose ? "propose" : "read-only");
|
|
145
|
+
served.push(t);
|
|
96
146
|
}
|
|
97
147
|
}
|
|
98
148
|
return served;
|
|
99
149
|
}
|
|
100
150
|
|
|
101
151
|
/** The context a hook's tools get on a server at `cwd`. The store is opened on first read. */
|
|
102
|
-
export function productMcpContext(hook: ProductMcpHook, cwd: string, readOnly: boolean): ProductMcpContext {
|
|
152
|
+
export function productMcpContext(hook: ProductMcpHook, cwd: string, readOnly: boolean, propose = false): ProductMcpContext {
|
|
103
153
|
let opened: Promise<ReportReader | undefined> | undefined;
|
|
104
154
|
return {
|
|
105
155
|
cwd,
|
|
106
156
|
readOnly,
|
|
157
|
+
propose,
|
|
107
158
|
reports: () =>
|
|
108
159
|
(opened ??= reportUrlFor(hook.reportUrl, cwd).then((url) => (url ? reportReader(url) : undefined))),
|
|
109
160
|
};
|
package/src/cli/mcp/read-only.ts
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
*
|
|
11
11
|
* Contributed tools (a lexicon's `mcpTools()`, and a product's tools through
|
|
12
12
|
* the hook chant#4555 adds, ./product-tools.ts) are served only when they
|
|
13
|
-
* declare `readOnly: true`.
|
|
13
|
+
* declare `readOnly: true`. The `--propose` tier (chant#4655) keeps these
|
|
14
|
+
* lists and adds only a product's `forgeWrite` tools (./product-tools.ts).
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
17
|
import { workspaceReadTools, workspaceWriteTools } from "./workspace-tools";
|
package/src/cli/mcp/server.ts
CHANGED
|
@@ -102,6 +102,10 @@ export function namespacedResourceUri(lexicon: string, uri: string): string {
|
|
|
102
102
|
export const READ_ONLY_INSTRUCTIONS =
|
|
103
103
|
"This chant server is read-only: it serves the ledger, the workspace graph, runs, gates and snapshots, and no tool here runs an Op, resolves a gate or writes anything.";
|
|
104
104
|
|
|
105
|
+
/** The `initialize` instructions of the `--propose` tier (chant#4655), in place of {@link READ_ONLY_INSTRUCTIONS}. */
|
|
106
|
+
export const PROPOSE_INSTRUCTIONS =
|
|
107
|
+
"This chant server is read-only apart from its forge tools: it serves the ledger, the workspace graph, runs, gates and snapshots, and no tool here runs an Op, resolves a gate or applies anything. The product's forge tools open pull requests and comments only. Approving, merging and applying a change belong to a person.";
|
|
108
|
+
|
|
105
109
|
/** The `lint` a read-only server serves: the same tool with no `fix` (chant#4543). */
|
|
106
110
|
const readOnlyLintTool: ToolDefinition = {
|
|
107
111
|
...lintTool,
|
|
@@ -127,6 +131,8 @@ export class McpServer {
|
|
|
127
131
|
private clientInfo: McpClientInfo | undefined;
|
|
128
132
|
/** `chant serve mcp --read-only` (chant#4543): only tools that change nothing are registered. */
|
|
129
133
|
readonly readOnly: boolean;
|
|
134
|
+
/** `chant serve mcp --read-only --propose` (chant#4655): the read-only server plus the product's `forgeWrite` tools. */
|
|
135
|
+
readonly propose: boolean;
|
|
130
136
|
|
|
131
137
|
/**
|
|
132
138
|
* `options.instructions` is sent as the `initialize` result's
|
|
@@ -149,14 +155,21 @@ export class McpServer {
|
|
|
149
155
|
* under the same read-only rule as a plugin's, and a read-only server
|
|
150
156
|
* refuses to start with one named as a write. With a hook and no
|
|
151
157
|
* `readOnly`, the server is read-only unless the hook says otherwise.
|
|
158
|
+
*
|
|
159
|
+
* `options.propose` (`--propose`, chant#4655), or `propose: true` on the
|
|
160
|
+
* hook, is a tier of the read-only server: the same core and plugin tools,
|
|
161
|
+
* plus the product tools that declare `forgeWrite: true`. It needs
|
|
162
|
+
* `readOnly`; an ordinary server with it refuses to start.
|
|
152
163
|
*/
|
|
153
|
-
constructor(plugins?: LexiconPlugin[], options: { instructions?: string; workspace?: WorkspaceToolsOptions; readOnly?: boolean; product?: ProductMcpHook } = {}) {
|
|
164
|
+
constructor(plugins?: LexiconPlugin[], options: { instructions?: string; workspace?: WorkspaceToolsOptions; readOnly?: boolean; propose?: boolean; product?: ProductMcpHook } = {}) {
|
|
154
165
|
this.plugins = plugins ?? [];
|
|
155
166
|
const product = options.product;
|
|
156
167
|
this.readOnly = options.readOnly ?? (product ? product.readOnly !== false : false);
|
|
168
|
+
this.propose = options.propose === true || product?.propose === true;
|
|
169
|
+
if (this.propose && !this.readOnly) throw new Error("chant serve mcp --propose is a tier of the read-only server: start it with --read-only --propose");
|
|
157
170
|
const said = [options.instructions, product?.instructions].filter((s): s is string => s !== undefined);
|
|
158
171
|
this.instructions = this.readOnly
|
|
159
|
-
? [...said, READ_ONLY_INSTRUCTIONS].join("\n\n")
|
|
172
|
+
? [...said, this.propose ? PROPOSE_INSTRUCTIONS : READ_ONLY_INSTRUCTIONS].join("\n\n")
|
|
160
173
|
: said.length > 0 ? said.join("\n\n") : undefined;
|
|
161
174
|
const cwd = options.workspace?.cwd ?? process.cwd();
|
|
162
175
|
// Register core tools
|
|
@@ -203,9 +216,10 @@ export class McpServer {
|
|
|
203
216
|
}
|
|
204
217
|
}
|
|
205
218
|
|
|
206
|
-
// A CI product's tools (chant#4555), read-only by default as chant#4543 rules for contributed tools
|
|
219
|
+
// A CI product's tools (chant#4555), read-only by default as chant#4543 rules for contributed tools,
|
|
220
|
+
// and its forgeWrite tools on the --propose tier (chant#4655).
|
|
207
221
|
if (product) {
|
|
208
|
-
for (const tool of productToolsServed(product, productMcpContext(product, cwd, this.readOnly))) {
|
|
222
|
+
for (const tool of productToolsServed(product, productMcpContext(product, cwd, this.readOnly, this.propose))) {
|
|
209
223
|
this.registerTool({ name: namespacedToolName(product.product, tool.name), description: tool.description, inputSchema: tool.inputSchema }, tool.handler);
|
|
210
224
|
}
|
|
211
225
|
}
|
|
@@ -459,7 +473,7 @@ export class McpServer {
|
|
|
459
473
|
/**
|
|
460
474
|
* Start MCP server, loading plugins from the project
|
|
461
475
|
*/
|
|
462
|
-
export async function startMcpServer(options: { readOnly?: boolean } = {}): Promise<void> {
|
|
476
|
+
export async function startMcpServer(options: { readOnly?: boolean; propose?: boolean } = {}): Promise<void> {
|
|
463
477
|
let plugins: LexiconPlugin[] = [];
|
|
464
478
|
try {
|
|
465
479
|
const { resolveProjectLexicons, loadPlugins } = await import("../plugins");
|
|
@@ -473,6 +487,7 @@ export async function startMcpServer(options: { readOnly?: boolean } = {}): Prom
|
|
|
473
487
|
const server = new McpServer(plugins, {
|
|
474
488
|
workspace: { cwd: process.cwd() },
|
|
475
489
|
...(options.readOnly ? { readOnly: true } : {}),
|
|
490
|
+
...(options.propose ? { propose: true } : {}),
|
|
476
491
|
...(product ? { product } : {}),
|
|
477
492
|
});
|
|
478
493
|
server.start();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, test, expect } from "vitest";
|
|
1
|
+
import { describe, test, expect, vi } from "vitest";
|
|
2
2
|
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
|
|
3
3
|
import { join } from "path";
|
|
4
4
|
import { homedir } from "os";
|
|
@@ -7,7 +7,10 @@ import { initCommand } from "./commands/init";
|
|
|
7
7
|
import { doctorCommand } from "./commands/doctor";
|
|
8
8
|
import { updateCommand } from "./commands/update";
|
|
9
9
|
import { parseArgs, commandRegistry } from "./main";
|
|
10
|
-
import { MCP_CONFIG_FILENAME, MCP_SETUP_COMMAND, mcpConfigPath } from "./mcp-config";
|
|
10
|
+
import { generateMcpConfig, MCP_CONFIG_FILENAME, MCP_SETUP_COMMAND, mcpConfigPath } from "./mcp-config";
|
|
11
|
+
import { runServeMcp } from "./handlers/serve";
|
|
12
|
+
import { runInit } from "./handlers/init";
|
|
13
|
+
import type { CommandContext } from "./registry";
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
16
|
* chant #2383. `chant init` used to write `mcp.json` into the user's home
|
|
@@ -166,3 +169,50 @@ describe("MCP config: one location, three agreeing sites (#2383)", () => {
|
|
|
166
169
|
}
|
|
167
170
|
});
|
|
168
171
|
});
|
|
172
|
+
|
|
173
|
+
describe("the --propose tier on the command line (#4655)", () => {
|
|
174
|
+
const ctx = (argv: string[]): CommandContext => ({ args: parseArgs(argv), plugins: [], serializers: [] });
|
|
175
|
+
|
|
176
|
+
async function captured(run: () => Promise<number>): Promise<{ code: number; out: string; err: string }> {
|
|
177
|
+
const out: string[] = [];
|
|
178
|
+
const err: string[] = [];
|
|
179
|
+
const log = vi.spyOn(console, "log").mockImplementation((...a: unknown[]) => void out.push(a.join(" ")));
|
|
180
|
+
const error = vi.spyOn(console, "error").mockImplementation((...a: unknown[]) => void err.push(a.join(" ")));
|
|
181
|
+
try {
|
|
182
|
+
return { code: await run(), out: out.join("\n"), err: err.join("\n") };
|
|
183
|
+
} finally {
|
|
184
|
+
log.mockRestore();
|
|
185
|
+
error.mockRestore();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
test("chant serve mcp --propose without --read-only exits 1 with a usage message", async () => {
|
|
190
|
+
const args = parseArgs(["serve", "mcp", "--propose"]);
|
|
191
|
+
expect(args.propose).toBe(true);
|
|
192
|
+
const got = await captured(() => runServeMcp(ctx(["serve", "mcp", "--propose"])));
|
|
193
|
+
expect(got.code).toBe(1);
|
|
194
|
+
expect(got.err).toMatch(/--propose needs --read-only/);
|
|
195
|
+
expect(got.err).toMatch(/Usage: chant serve mcp --read-only --propose/);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test("chant init --mcp-read-only --propose --dry-run prints the .mcp.json it would write, and writes nothing", async () => {
|
|
199
|
+
await withTestDir(async (dir) => {
|
|
200
|
+
const got = await captured(() => runInit(ctx(["init", dir, "--mcp-read-only", "--propose", "--dry-run"])));
|
|
201
|
+
expect(got.code).toBe(0);
|
|
202
|
+
expect(JSON.parse(got.out).mcpServers.chant.args).toEqual(["chant", "serve", "mcp", "--read-only", "--propose"]);
|
|
203
|
+
expect(existsSync(mcpConfigPath(dir))).toBe(false);
|
|
204
|
+
});
|
|
205
|
+
const refused = await captured(() => runInit(ctx(["init", "--propose", "--dry-run"])));
|
|
206
|
+
expect(refused.code).toBe(1);
|
|
207
|
+
expect(refused.err).toMatch(/--propose needs --mcp-read-only/);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test("init --mcp-read-only --propose registers the tier, and propose alone is refused", async () => {
|
|
211
|
+
await withTestDir(async (testDir) => {
|
|
212
|
+
await initCommand({ path: testDir, lexicon: "aws", skipInstall: true, mcpReadOnly: true, mcpPropose: true });
|
|
213
|
+
const config = JSON.parse(readFileSync(mcpConfigPath(testDir), "utf-8"));
|
|
214
|
+
expect(config.mcpServers.chant.args).toEqual(["chant", "serve", "mcp", "--read-only", "--propose"]);
|
|
215
|
+
});
|
|
216
|
+
expect(() => generateMcpConfig("npm", { propose: true })).toThrow(/--mcp-read-only --propose/);
|
|
217
|
+
});
|
|
218
|
+
});
|
package/src/cli/mcp-config.ts
CHANGED
|
@@ -53,14 +53,17 @@ export function detectPackageManager(dir?: string): "bun" | "npm" {
|
|
|
53
53
|
* The MCP registration chant writes: one stdio server named `chant`. With
|
|
54
54
|
* `readOnly` (`chant init --mcp-read-only`, chant#4543) it registers
|
|
55
55
|
* `chant serve mcp --read-only`, which serves only the tools that change
|
|
56
|
-
* nothing.
|
|
56
|
+
* nothing. With `readOnly` and `propose` (`chant init --mcp-read-only
|
|
57
|
+
* --propose`, chant#4655) it registers `chant serve mcp --read-only
|
|
58
|
+
* --propose`; `propose` without `readOnly` is refused.
|
|
57
59
|
*/
|
|
58
|
-
export function generateMcpConfig(pm: "bun" | "npm", options: { readOnly?: boolean } = {}): string {
|
|
60
|
+
export function generateMcpConfig(pm: "bun" | "npm", options: { readOnly?: boolean; propose?: boolean } = {}): string {
|
|
61
|
+
if (options.propose && !options.readOnly) throw new Error("--propose is a tier of the read-only server: use --mcp-read-only --propose");
|
|
59
62
|
const config = {
|
|
60
63
|
mcpServers: {
|
|
61
64
|
chant: {
|
|
62
65
|
command: pm === "bun" ? "bunx" : "npx",
|
|
63
|
-
args: ["chant", "serve", "mcp", ...(options.readOnly ? ["--read-only"] : [])],
|
|
66
|
+
args: ["chant", "serve", "mcp", ...(options.readOnly ? ["--read-only"] : []), ...(options.readOnly && options.propose ? ["--propose"] : [])],
|
|
64
67
|
},
|
|
65
68
|
},
|
|
66
69
|
};
|
package/src/cli/parse-args.ts
CHANGED
|
@@ -87,6 +87,7 @@ const BOOLEAN_FLAGS = new Set([
|
|
|
87
87
|
"--skip-mcp",
|
|
88
88
|
"--read-only",
|
|
89
89
|
"--mcp-read-only",
|
|
90
|
+
"--propose",
|
|
90
91
|
"--current",
|
|
91
92
|
"--uncommitted",
|
|
92
93
|
"--allow-code",
|
|
@@ -146,6 +147,7 @@ export function parseArgs(args: string[]): ParsedArgs {
|
|
|
146
147
|
skipMcp: undefined,
|
|
147
148
|
readOnly: undefined,
|
|
148
149
|
mcpReadOnly: undefined,
|
|
150
|
+
propose: undefined,
|
|
149
151
|
src: undefined,
|
|
150
152
|
env: undefined,
|
|
151
153
|
};
|
|
@@ -341,6 +343,8 @@ export function parseArgs(args: string[]): ParsedArgs {
|
|
|
341
343
|
result.readOnly = true;
|
|
342
344
|
} else if (arg === "--mcp-read-only") {
|
|
343
345
|
result.mcpReadOnly = true;
|
|
346
|
+
} else if (arg === "--propose") {
|
|
347
|
+
result.propose = true;
|
|
344
348
|
} else if (arg === "--src") {
|
|
345
349
|
result.src = args[++i];
|
|
346
350
|
} else if (arg === "--env") {
|
|
@@ -527,6 +531,18 @@ export function parseArgs(args: string[]): ParsedArgs {
|
|
|
527
531
|
// `chant lock --alive <run>` (#4552): print whether a run holding rows or the repo lock tag still runs.
|
|
528
532
|
result.aliveRun = args[++i];
|
|
529
533
|
if (!result.aliveRun || result.aliveRun.startsWith("-")) throw new Error("--alive needs a run id: --alive <run>");
|
|
534
|
+
} else if (arg === "--beat") {
|
|
535
|
+
// `chant lock --beat <run> --parent <pid>` (#4660): the heartbeat side process of a row hold.
|
|
536
|
+
result.beatRun = args[++i];
|
|
537
|
+
if (!result.beatRun || result.beatRun.startsWith("-")) throw new Error("--beat needs a run id: --beat <run> --parent <pid>");
|
|
538
|
+
} else if (arg === "--parent") {
|
|
539
|
+
const pid = Number(args[++i]);
|
|
540
|
+
if (!Number.isInteger(pid) || pid < 1) throw new Error("--parent needs a process id: --parent <pid>");
|
|
541
|
+
result.parentPid = pid;
|
|
542
|
+
} else if (arg === "--run") {
|
|
543
|
+
// `chant unlock --run <id>` (#4660): free the rows a run holds or waits for.
|
|
544
|
+
result.unlockRun = args[++i];
|
|
545
|
+
if (!result.unlockRun || result.unlockRun.startsWith("-")) throw new Error("--run needs a run id: --run <id>");
|
|
530
546
|
} else if (arg === "--from-report") {
|
|
531
547
|
// `chant lock --from-report <pr-plan.json>` (#4293): lock the components a pull-request report lists.
|
|
532
548
|
result.fromReport = args[++i];
|
|
@@ -594,6 +610,9 @@ export function parseArgs(args: string[]): ParsedArgs {
|
|
|
594
610
|
} else if (arg === "--apply-on-merge") {
|
|
595
611
|
// `chant build --pr-loop --apply-on-merge` and `chant ci serve --apply-on-merge` (#4168): opt into applying on merge.
|
|
596
612
|
result.applyOnMerge = true;
|
|
613
|
+
} else if (arg === "--action-job") {
|
|
614
|
+
// `chant build --pr-loop --action-job` (#4654): the job that answers the action comment and the action dispatch.
|
|
615
|
+
result.actionJob = true;
|
|
597
616
|
} else if (arg === "--preview-comment") {
|
|
598
617
|
// `chant build --pr-loop --preview-comment` (#4620): the job that answers `/<product> <plan word>` with a preview.
|
|
599
618
|
result.previewComment = true;
|
package/src/cli/registry.ts
CHANGED
|
@@ -137,6 +137,12 @@ export interface ParsedArgs {
|
|
|
137
137
|
readOnly?: boolean;
|
|
138
138
|
/** `chant init --mcp-read-only` (chant#4543): write `.mcp.json` registering `chant serve mcp --read-only`. */
|
|
139
139
|
mcpReadOnly?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* `chant serve mcp --read-only --propose` and `chant init --mcp-read-only
|
|
142
|
+
* --propose` (chant#4655): the read-only server plus a product's tools that
|
|
143
|
+
* open pull requests (`forgeWrite`).
|
|
144
|
+
*/
|
|
145
|
+
propose?: boolean;
|
|
140
146
|
/** `chant import --type <ResourceType>` selector */
|
|
141
147
|
selectType?: string;
|
|
142
148
|
/** `chant import --name <name>` selector */
|
|
@@ -361,6 +367,12 @@ export interface ParsedArgs {
|
|
|
361
367
|
fromReport?: string;
|
|
362
368
|
/** `chant lock --alive <run>` (#4552): print `alive` or `dead` for a run that holds rows or the repo lock tag. */
|
|
363
369
|
aliveRun?: string;
|
|
370
|
+
/** `chant lock --beat <run>` (#4660): the heartbeat side process of the rows a run holds. Not for people. */
|
|
371
|
+
beatRun?: string;
|
|
372
|
+
/** `chant lock --beat <run> --parent <pid>`: the process whose end ends the beat. */
|
|
373
|
+
parentPid?: number;
|
|
374
|
+
/** `chant unlock --run <id>` (#4660): free the rows a run holds or waits for, whatever the forge says of it. */
|
|
375
|
+
unlockRun?: string;
|
|
364
376
|
/** Every `--pr <n>`, in order: `chant release compose` (#4168 4.3) takes several. */
|
|
365
377
|
prs?: number[];
|
|
366
378
|
/** `chant release cut --channel <tag>` (#4168 4.3): the tag a publish of the release moves in place of `latest`. */
|
|
@@ -441,6 +453,8 @@ export interface ParsedArgs {
|
|
|
441
453
|
applyBeforeMerge?: boolean;
|
|
442
454
|
/** `chant build --pr-loop --preview-comment` (#4620): a job answers `/<product> <plan word>` by previewing the pull request's head again. */
|
|
443
455
|
previewComment?: boolean;
|
|
456
|
+
/** `chant build --pr-loop --action-job` (#4654): a job answers `/<product> <action word> <member> <action>` and a dispatch with the two inputs by running the product's action verb. */
|
|
457
|
+
actionJob?: boolean;
|
|
444
458
|
/** `chant build --pr-loop --pr-build` (#4088) — build and lint before pr-plan and pr-apply. */
|
|
445
459
|
prBuild?: boolean;
|
|
446
460
|
/** `chant build --pr-loop --pr-runner <stage>=<label>[,<label>...]` (#4625), repeatable: a stage's runner, plan, apply or default. */
|
|
@@ -97,7 +97,8 @@ import { layerWaves } from "../gated-waves";
|
|
|
97
97
|
import type { DriverComponent } from "./driver";
|
|
98
98
|
import type { GatedWavePipelineOptions } from "./gated-wave-pipeline";
|
|
99
99
|
import type { CloudTradeSpec, PipelineCloudIdentity } from "../ci-identity";
|
|
100
|
-
import { commentLine, resolveProductWords, type CiProductWords, type CiProductWordsInput } from "../ci-product-words";
|
|
100
|
+
import { commandWord, commentLine, PRODUCT_ACTION_ENV, PRODUCT_ACTION_EVENT_FLAG, resolveProductWords, type CiProductWords, type CiProductWordsInput } from "../ci-product-words";
|
|
101
|
+
import { CHANT_EXIT } from "../exit-codes";
|
|
101
102
|
import type { ControlTarget } from "../control/dispatch";
|
|
102
103
|
import { CI_RESPOND_ENV, respondList, type CiResponses } from "../ci-respond";
|
|
103
104
|
|
|
@@ -306,6 +307,15 @@ export interface PrLoopPipelineOptions {
|
|
|
306
307
|
* Default false.
|
|
307
308
|
*/
|
|
308
309
|
previewComment?: boolean;
|
|
310
|
+
/**
|
|
311
|
+
* The action job (#4654): `/<product> <action word> <member> <action>` on
|
|
312
|
+
* an issue or pull request, or a dispatch of the workflow with the two
|
|
313
|
+
* inputs ({@link prActionJob}), runs the product's action verb at the
|
|
314
|
+
* target branch's commit under its gated request. GitHub and Forgejo only.
|
|
315
|
+
* The words must name an `action` command and a `bin`. Set from
|
|
316
|
+
* `--action-job` beside `--pr-loop`. Default off.
|
|
317
|
+
*/
|
|
318
|
+
actionJob?: boolean | PrActionJobOptions;
|
|
309
319
|
/**
|
|
310
320
|
* Where the pull request loop's jobs run (#4625), by stage: `plan` for the
|
|
311
321
|
* plan and the comment preview, `apply` for the apply jobs, the record
|
|
@@ -409,7 +419,7 @@ export function prLoopRunner(options: Pick<PrLoopPipelineOptions, "runners">, st
|
|
|
409
419
|
export function prLoopJobStage(name: string, member?: string): PrLoopRunnerStage {
|
|
410
420
|
const bare = member && name.startsWith(`${member}-`) ? name.slice(member.length + 1) : name;
|
|
411
421
|
if (bare === "plan" || bare === PR_COMMENT_PREVIEW_JOB) return "plan";
|
|
412
|
-
if (bare === "apply" || bare === "record" || /^apply-wave-\d+$/.test(bare) || bare === "env-up" || bare === "env-down" || bare === "env-sweep") return "apply";
|
|
422
|
+
if (bare === "apply" || bare === "record" || bare === PR_ACTION_JOB || /^apply-wave-\d+$/.test(bare) || bare === "env-up" || bare === "env-down" || bare === "env-sweep") return "apply";
|
|
413
423
|
return "default";
|
|
414
424
|
}
|
|
415
425
|
|
|
@@ -516,6 +526,81 @@ export function prCommentLockJobs(forge: ForgeKind, options: Pick<PrLoopPipeline
|
|
|
516
526
|
return out;
|
|
517
527
|
}
|
|
518
528
|
|
|
529
|
+
/** The job answering the action comment and the action dispatch (#4654). */
|
|
530
|
+
export const PR_ACTION_JOB = "action";
|
|
531
|
+
|
|
532
|
+
/** The action job's settings (#4654). */
|
|
533
|
+
export interface PrActionJobOptions {
|
|
534
|
+
/** The dispatch inputs' names. Default the words' member noun (`stack`, `root`) and `action`. */
|
|
535
|
+
inputs?: { member?: string; action?: string };
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/** The action job (#4654): what starts it, what it runs, and the values it reads. */
|
|
539
|
+
export interface PrActionJob {
|
|
540
|
+
jobName: typeof PR_ACTION_JOB;
|
|
541
|
+
/** The comment it answers, `/<product> <action word>`, followed by a member and an action. */
|
|
542
|
+
comment: string;
|
|
543
|
+
/** The dispatch inputs, by role: the member's input name and the action's. */
|
|
544
|
+
inputs: { member: string; action: string };
|
|
545
|
+
/**
|
|
546
|
+
* The command line: the product's action verb with
|
|
547
|
+
* {@link PRODUCT_ACTION_EVENT_FLAG}, which reads the comment or the inputs
|
|
548
|
+
* from {@link PRODUCT_ACTION_ENV}. A run that waits for an approval exits
|
|
549
|
+
* with chant's `waiting` code; {@link script} turns that into a green job.
|
|
550
|
+
*/
|
|
551
|
+
command: string;
|
|
552
|
+
/** The step's script: the command, with chant's `waiting` exit taken as success, since a pending approval is the expected first answer. */
|
|
553
|
+
script: string;
|
|
554
|
+
/** The values it reads, as the forge spells them. */
|
|
555
|
+
env: Record<string, string>;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
const INPUT_NAME = /^[A-Za-z_][A-Za-z0-9_-]{0,63}$/;
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* The action job (#4654), with `actionJob`: one job that answers the
|
|
562
|
+
* product's action comment and a dispatch of the workflow with a member and
|
|
563
|
+
* an action. It runs at the target branch's commit (an `issue_comment` run's
|
|
564
|
+
* checkout) or the dispatched ref, never a pull request's head, and runs the
|
|
565
|
+
* product's own action verb, which asks for the gated request and runs the
|
|
566
|
+
* action once an approval counts. The comment and the inputs reach the verb
|
|
567
|
+
* as variables ({@link PRODUCT_ACTION_ENV}), never as shell text.
|
|
568
|
+
*
|
|
569
|
+
* Undefined without `actionJob`. Throws on GitLab, which starts no pipeline
|
|
570
|
+
* on a note; for words that name no `action` command or no `bin`, since
|
|
571
|
+
* chant has no action verb of its own; and for input names that are not
|
|
572
|
+
* plain names or are the same.
|
|
573
|
+
*/
|
|
574
|
+
export function prActionJob(forge: ForgeKind, options: Pick<PrLoopPipelineOptions, "actionJob" | "words"> = {}): PrActionJob | undefined {
|
|
575
|
+
if (!options.actionJob) return undefined;
|
|
576
|
+
if (forge === "gitlab") throw new Error("the action job runs on GitHub and Forgejo, whose workflows start on a comment and on a dispatch with inputs; on GitLab, run the product's action verb from a pipeline of its own");
|
|
577
|
+
const words = resolveProductWords(options.words);
|
|
578
|
+
const typed = commandWord(words, "action");
|
|
579
|
+
if (typed === undefined) throw new Error(`--action-job answers /${words.product} <action command>, and the words name no action command; name one in the words' commands, or drop --action-job`);
|
|
580
|
+
if (!words.bin) throw new Error("--action-job runs the product's action verb, and the words name no bin; chant has no action verb of its own");
|
|
581
|
+
const given = options.actionJob === true ? {} : options.actionJob.inputs ?? {};
|
|
582
|
+
const inputs = { member: given.member ?? words.noun[0], action: given.action ?? "action" };
|
|
583
|
+
for (const [role, name] of Object.entries(inputs)) {
|
|
584
|
+
if (!INPUT_NAME.test(name)) throw new Error(`the action job's ${role} input is a plain name, not ${JSON.stringify(name)}`);
|
|
585
|
+
}
|
|
586
|
+
if (inputs.member === inputs.action) throw new Error(`the action job's two inputs need two names, and both are ${inputs.action}`);
|
|
587
|
+
const command = withProductBin(["chant", typed, PRODUCT_ACTION_EVENT_FLAG].join(" "), words.bin);
|
|
588
|
+
return {
|
|
589
|
+
jobName: PR_ACTION_JOB,
|
|
590
|
+
comment: `/${words.product} ${typed}`,
|
|
591
|
+
inputs,
|
|
592
|
+
command,
|
|
593
|
+
script: ["set +e", command, 'code="$?"', `if [ "$code" -eq ${CHANT_EXIT.waiting} ]; then echo "The action waits for an approval."; exit 0; fi`, 'exit "$code"'].join("\n"),
|
|
594
|
+
env: {
|
|
595
|
+
[PRODUCT_ACTION_ENV.comment]: "${{ github.event.comment.body }}",
|
|
596
|
+
[PRODUCT_ACTION_ENV.member]: `\${{ github.event.inputs.${inputs.member} }}`,
|
|
597
|
+
[PRODUCT_ACTION_ENV.action]: `\${{ github.event.inputs.${inputs.action} }}`,
|
|
598
|
+
PR_NUMBER: "${{ github.event.issue.number }}",
|
|
599
|
+
GITHUB_TOKEN: GITHUB_JOB_TOKEN,
|
|
600
|
+
},
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
|
|
519
604
|
/** The job answering `/<product> <plan word>` (#4620). */
|
|
520
605
|
export const PR_COMMENT_PREVIEW_JOB = "comment-preview";
|
|
521
606
|
/** The job that posts the comment preview's note and status (#4620). */
|