@intentius/chant 0.124.57 → 0.124.58
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 +26 -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/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 +6 -2
- 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 +59 -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 +9 -0
- package/dist/cli/registry.d.ts +8 -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/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 +11 -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/mcp/types.d.ts +9 -0
- package/dist/mcp/types.d.ts.map +1 -1
- 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 +150 -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 +4 -4
- 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 +32 -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/serve.ts +9 -0
- package/src/cli/main.ts +6 -2
- package/src/cli/mcp/product-tools.test.ts +57 -1
- package/src/cli/mcp/product-tools.ts +67 -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 +7 -0
- package/src/cli/registry.ts +8 -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/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 +12 -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/mcp/types.ts +9 -0
- 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 +316 -0
- package/src/template-request/template-request.ts +235 -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intentius/chant",
|
|
3
|
-
"version": "0.124.
|
|
3
|
+
"version": "0.124.58",
|
|
4
4
|
"description": "Declarative infrastructure-as-code toolkit — TypeScript on Node.js",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://intentius.io/chant",
|
|
@@ -93,6 +93,13 @@
|
|
|
93
93
|
"import": "./dist/op/activities/index.js",
|
|
94
94
|
"default": "./src/op/activities/index.ts"
|
|
95
95
|
},
|
|
96
|
+
"./template-request": {
|
|
97
|
+
"development": "./src/template-request/index.ts",
|
|
98
|
+
"types": "./dist/template-request/index.d.ts",
|
|
99
|
+
"import": "./dist/template-request/index.js",
|
|
100
|
+
"default": "./src/template-request/index.ts"
|
|
101
|
+
},
|
|
102
|
+
"./template-request/*.schema.json": "./src/template-request/*.schema.json",
|
|
96
103
|
"./components": {
|
|
97
104
|
"development": "./src/components/index.ts",
|
|
98
105
|
"types": "./dist/components/index.d.ts",
|
|
@@ -92,6 +92,29 @@ describe("the comment grammar (moved from terragucci's comment.ts)", () => {
|
|
|
92
92
|
expect(parseProductComment(pw, "/plywood lock everything")).toMatchObject({ kind: "refused" });
|
|
93
93
|
});
|
|
94
94
|
|
|
95
|
+
test("an action command names one member and one action, and nothing else (#4653)", () => {
|
|
96
|
+
const words = assertProductWords({ ...TERRAGUCCI, commands: { ...TERRAGUCCI.commands, action: "action" as const } });
|
|
97
|
+
expect(parseProductComment(words, "/terragucci action apps/orders action.aws_lambda_invoke.rotate")).toEqual({ kind: "action", member: "apps/orders", address: "action.aws_lambda_invoke.rotate" });
|
|
98
|
+
expect(parseProductComment(words, "/terragucci action apps/orders module.app.action.aws_lambda_invoke.rotate")).toEqual({ kind: "action", member: "apps/orders", address: "module.app.action.aws_lambda_invoke.rotate" });
|
|
99
|
+
expect(parseProductComment(words, '/terragucci action apps/orders module.app["blue"].action.t.l[0]')).toEqual({ kind: "action", member: "apps/orders", address: 'module.app["blue"].action.t.l[0]' });
|
|
100
|
+
for (const bad of [
|
|
101
|
+
"/terragucci action",
|
|
102
|
+
"/terragucci action apps/orders",
|
|
103
|
+
"/terragucci action apps/orders action.t.l extra",
|
|
104
|
+
"/terragucci action ../etc action.t.l",
|
|
105
|
+
"/terragucci action apps/orders -target=x",
|
|
106
|
+
"/terragucci action apps/orders action.t.l;id",
|
|
107
|
+
"/terragucci action apps/orders $(id)",
|
|
108
|
+
"/terragucci action apps/orders action.t.l\nrm",
|
|
109
|
+
]) {
|
|
110
|
+
expect(parseProductComment(words, bad.replace("\\n", "\n"))).toMatchObject({ kind: "refused" });
|
|
111
|
+
}
|
|
112
|
+
// A product without the word does not read it.
|
|
113
|
+
expect(parseProductComment(tg, "/terragucci action apps/orders action.t.l")).toMatchObject({ kind: "refused", reason: expect.stringMatching(/the commands are/) });
|
|
114
|
+
expect(commentLine(words, "action")).toBe("/terragucci action");
|
|
115
|
+
expect(productWordsProblems(words, { jobs: ["plan", "apply", "lock", "unlock", "agent"] })).toContain("commands.action needs a action job, and the pipeline has none");
|
|
116
|
+
});
|
|
117
|
+
|
|
95
118
|
test("an alias reads only where its variable turns it on", () => {
|
|
96
119
|
expect(parseProductComment(tg, "atlantis plan -d envs/dev/orders")).toBeUndefined();
|
|
97
120
|
expect(parseProductComment(tg, "atlantis plan -d ./envs/dev/orders/", { TG_ATLANTIS_COMMENTS: "1" })).toEqual({ kind: "plan", member: "envs/dev/orders" });
|
package/src/ci-product-words.ts
CHANGED
|
@@ -29,10 +29,14 @@ export type CiProductStage = "plan" | "apply" | "record" | "check" | "drift" | "
|
|
|
29
29
|
/** Every stage slot, in the order {@link assertProductWords} reports them. */
|
|
30
30
|
export const CI_PRODUCT_STAGES: readonly CiProductStage[] = ["plan", "apply", "record", "check", "drift", "lock", "approval", "control"];
|
|
31
31
|
|
|
32
|
-
/**
|
|
33
|
-
|
|
32
|
+
/**
|
|
33
|
+
* The commands a comment may name. Each one needs a job in the pipeline that
|
|
34
|
+
* answers it. `action` (#4653) asks for a day-2 action on one member, which
|
|
35
|
+
* runs under a gated request.
|
|
36
|
+
*/
|
|
37
|
+
export type CiProductCommand = "plan" | "apply" | "lock" | "unlock" | "agent" | "action";
|
|
34
38
|
|
|
35
|
-
export const CI_PRODUCT_COMMANDS: readonly CiProductCommand[] = ["plan", "apply", "lock", "unlock", "agent"];
|
|
39
|
+
export const CI_PRODUCT_COMMANDS: readonly CiProductCommand[] = ["plan", "apply", "lock", "unlock", "agent", "action"];
|
|
36
40
|
|
|
37
41
|
/**
|
|
38
42
|
* What an approval of a product's waves binds to (ruling B, 2026-10-27).
|
|
@@ -454,6 +458,12 @@ export type ParsedProductComment =
|
|
|
454
458
|
| { kind: "unlock" }
|
|
455
459
|
/** An ask for the agent: data, never split or run. */
|
|
456
460
|
| { kind: "agent"; ask: string }
|
|
461
|
+
/**
|
|
462
|
+
* A day-2 action (#4653): `<member> <action>`, such as `apps/orders
|
|
463
|
+
* module.app.action.aws_lambda_invoke.rotate` or a stack's action name.
|
|
464
|
+
* The engine's lexicon checks the action against the member's plan.
|
|
465
|
+
*/
|
|
466
|
+
| { kind: "action"; member: string; address: string }
|
|
457
467
|
| { kind: "refused"; reason: string };
|
|
458
468
|
|
|
459
469
|
/** A member as a comment may name it: path segments, no leading dash, no shell or glob syntax. */
|
|
@@ -465,6 +475,12 @@ const MEMBER = /^[A-Za-z0-9_][A-Za-z0-9_.\/-]{0,199}$/;
|
|
|
465
475
|
* It never reaches a shell: the job reads the comment from a variable.
|
|
466
476
|
*/
|
|
467
477
|
const TARGET = /^[A-Za-z0-9_][A-Za-z0-9_.:\/\[\]"*@=+$,-]{0,499}$/;
|
|
478
|
+
/**
|
|
479
|
+
* An action as a comment may name it (#4653): a Terraform action address,
|
|
480
|
+
* module steps and instance keys included, or a configured action's name.
|
|
481
|
+
* No leading dash, no spaces, no shell or glob syntax.
|
|
482
|
+
*/
|
|
483
|
+
const ACTION = /^[A-Za-z_][A-Za-z0-9_.\[\]"-]{0,299}$/;
|
|
468
484
|
/** The longest ask an agent comment may carry. */
|
|
469
485
|
export const PRODUCT_COMMENT_ASK_MAX = 2000;
|
|
470
486
|
/** Commands a comment never runs, named in the reply so nobody waits on them. */
|
|
@@ -530,6 +546,15 @@ export function parseProductComment(words: CiProductWords, body: unknown, env: R
|
|
|
530
546
|
if (/[\u0000-\u0008\u000b-\u001f\u007f]/.test(ask)) return { kind: "refused", reason: "an ask is plain text, with no control characters" };
|
|
531
547
|
return { kind: "agent", ask };
|
|
532
548
|
}
|
|
549
|
+
case "action": {
|
|
550
|
+
const usage = `${line} takes a ${words.noun[0]} and an action: \`${prefix} ${typed} <${words.noun[0]}> <action>\``;
|
|
551
|
+
if (parts.length !== 4) return { kind: "refused", reason: usage };
|
|
552
|
+
const member = parts[2]!;
|
|
553
|
+
const address = parts[3]!;
|
|
554
|
+
if (!MEMBER.test(member) || member.split("/").some((s) => s === "" || s === "." || s === "..")) return { kind: "refused", reason: `the ${words.noun[0]} is a name or a path from the repository root` };
|
|
555
|
+
if (!ACTION.test(address)) return { kind: "refused", reason: "an action is an action address or name, with no spaces or shell characters" };
|
|
556
|
+
return { kind: "action", member, address };
|
|
557
|
+
}
|
|
533
558
|
case "apply": {
|
|
534
559
|
if (parts.length === 2) return { kind: "apply" };
|
|
535
560
|
const m = parts.length === 3 ? /^wave-([1-9][0-9]{0,3})$/.exec(parts[2]!) : null;
|
|
@@ -563,3 +588,43 @@ export function parseProductComment(words: CiProductWords, body: unknown, env: R
|
|
|
563
588
|
}
|
|
564
589
|
}
|
|
565
590
|
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* The variables the generated action job (#4654) hands the product's action
|
|
594
|
+
* verb: the comment that started it, on a comment, and the dispatch's two
|
|
595
|
+
* inputs, on a dispatch. The values reach the job as variables and never as
|
|
596
|
+
* shell text; {@link productActionFromEnv} reads them.
|
|
597
|
+
*/
|
|
598
|
+
export const PRODUCT_ACTION_ENV = { comment: "CHANT_ACTION_COMMENT", member: "CHANT_ACTION_MEMBER", action: "CHANT_ACTION" } as const;
|
|
599
|
+
|
|
600
|
+
/** The flag the generated action job passes the product's action verb, so it reads {@link PRODUCT_ACTION_ENV} (#4654). */
|
|
601
|
+
export const PRODUCT_ACTION_EVENT_FLAG = "--from-event";
|
|
602
|
+
|
|
603
|
+
/** What an action job was asked for (#4654): a member and an action, from a comment or a dispatch. */
|
|
604
|
+
export type ProductActionRequest = { kind: "action"; member: string; address: string; from: "comment" | "dispatch" } | { kind: "refused"; reason: string };
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* The action an action job was started for (#4654), read from
|
|
608
|
+
* {@link PRODUCT_ACTION_ENV}: a comment, parsed as {@link parseProductComment}
|
|
609
|
+
* parses it, else the dispatch's member and action, checked by the same
|
|
610
|
+
* rules. A product's action verb calls this under
|
|
611
|
+
* {@link PRODUCT_ACTION_EVENT_FLAG}.
|
|
612
|
+
*/
|
|
613
|
+
export function productActionFromEnv(words: CiProductWords, env: Record<string, string | undefined>): ProductActionRequest {
|
|
614
|
+
const typed = commandWord(words, "action");
|
|
615
|
+
if (typed === undefined) return { kind: "refused", reason: `${words.product} names no action command, so no job answers one` };
|
|
616
|
+
const comment = env[PRODUCT_ACTION_ENV.comment]?.trim();
|
|
617
|
+
if (comment) {
|
|
618
|
+
const parsed = parseProductComment(words, comment, env);
|
|
619
|
+
if (parsed?.kind === "action") return { ...parsed, from: "comment" };
|
|
620
|
+
if (parsed?.kind === "refused") return parsed;
|
|
621
|
+
return { kind: "refused", reason: `the comment is not \`/${words.product} ${typed} <${words.noun[0]}> <action>\`` };
|
|
622
|
+
}
|
|
623
|
+
const member = env[PRODUCT_ACTION_ENV.member]?.trim() ?? "";
|
|
624
|
+
const action = env[PRODUCT_ACTION_ENV.action]?.trim() ?? "";
|
|
625
|
+
if (member === "" || action === "") return { kind: "refused", reason: `a dispatched action names a ${words.noun[0]} and an action` };
|
|
626
|
+
if (/\s/.test(member) || /\s/.test(action)) return { kind: "refused", reason: `a ${words.noun[0]} and an action are one word each` };
|
|
627
|
+
const parsed = parseProductComment(words, `/${words.product} ${typed} ${member} ${action}`, {});
|
|
628
|
+
if (parsed?.kind === "action") return { ...parsed, from: "dispatch" };
|
|
629
|
+
return parsed?.kind === "refused" ? parsed : { kind: "refused", reason: `a dispatched action names a ${words.noun[0]} and an action` };
|
|
630
|
+
}
|
package/src/ci-product.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type { CiProductWords, CiProductWordsInput } from "./ci-product-words";
|
|
|
13
13
|
import type { ProductMcpHook } from "./cli/mcp/product-tools";
|
|
14
14
|
import type { ProductWaveHook } from "./op/op-waves-after-plan";
|
|
15
15
|
import { OTLP_EXPORTER_FLOOR } from "./otlp";
|
|
16
|
+
import { NEXT_RELEASE } from "./release-floors";
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* The first chant with the product pipeline (#4550): the words, the
|
|
@@ -40,6 +41,9 @@ export {
|
|
|
40
41
|
notifyWaveLabel,
|
|
41
42
|
overrideLine,
|
|
42
43
|
parseProductComment,
|
|
44
|
+
productActionFromEnv,
|
|
45
|
+
PRODUCT_ACTION_ENV,
|
|
46
|
+
PRODUCT_ACTION_EVENT_FLAG,
|
|
43
47
|
productContext,
|
|
44
48
|
productStatusContext,
|
|
45
49
|
productWaveGate,
|
|
@@ -59,6 +63,7 @@ export {
|
|
|
59
63
|
type CiProductWordsInput,
|
|
60
64
|
type OverrideLineInput,
|
|
61
65
|
type ParsedProductComment,
|
|
66
|
+
type ProductActionRequest,
|
|
62
67
|
} from "./ci-product-words";
|
|
63
68
|
export { driftNotifyFields, productNotifySource, productNotifyWords, productSendOptions, type DriftNotifyInput } from "./notify-product";
|
|
64
69
|
|
|
@@ -110,7 +115,19 @@ export {
|
|
|
110
115
|
type ProductPipelineJobs,
|
|
111
116
|
type ProductPipelineOptions,
|
|
112
117
|
} from "./components/product-pipeline";
|
|
113
|
-
export { prApplyComment, prCommentLockJobs, prCommentPreviewJob, prLoopSetup, engineSetupLines, withProductBin, type PrCommentLockJob, type PrCommentPreviewJob } from "./components/pr-pipeline";
|
|
118
|
+
export { prActionJob, PR_ACTION_JOB, prApplyComment, prCommentLockJobs, prCommentPreviewJob, prLoopSetup, engineSetupLines, withProductBin, type PrActionJob, type PrActionJobOptions, type PrCommentLockJob, type PrCommentPreviewJob } from "./components/pr-pipeline";
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Day-2 actions in the product pipeline (#4654): the `action` comment
|
|
122
|
+
* command counted as answered by the product's own workflow
|
|
123
|
+
* (`productPipelineJobs(forge, env, { words, actions: true })`), or the
|
|
124
|
+
* pipeline's own action job (`actionJob`, `build --pr-loop --action-job`),
|
|
125
|
+
* which answers the comment and a dispatch with a member and an action
|
|
126
|
+
* input, and runs the product's action verb with `--from-event`. The verb
|
|
127
|
+
* reads what was asked with `productActionFromEnv`. A product
|
|
128
|
+
* feature-detects on this floor.
|
|
129
|
+
*/
|
|
130
|
+
export const PRODUCT_ACTIONS_FLOOR = NEXT_RELEASE;
|
|
114
131
|
export { CI_SERVICES_FLOOR, engineServices, githubServices, gitlabServices, serviceWaitLine, servicesJobEnv, type CiService } from "./components/ci-services";
|
|
115
132
|
export { renderPrNote, prStatusContext, prApproveCommand, prApproveCommands, prApproveTargets, prMergeSentence, type PrMemberDetail } from "./pr-loop";
|
|
116
133
|
export { upsertPlanNote } from "./pr-post";
|
|
@@ -214,6 +231,20 @@ export { parseRequiresList, PR_APPLY_REQUIRES, type PrApplyRequire } from "./pr-
|
|
|
214
231
|
*/
|
|
215
232
|
export const PRODUCT_MCP_HOOK_FLOOR = OTLP_EXPORTER_FLOOR;
|
|
216
233
|
export type { ProductMcpContext, ProductMcpHook } from "./cli/mcp/product-tools";
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* The `--propose` tier (chant#4655): `runChantInProcess(["serve", "mcp",
|
|
237
|
+
* "--read-only", "--propose"], words, { mcp: hook })`, or `propose: true` on
|
|
238
|
+
* the hook, serves the read-only server's tools plus the product tools that
|
|
239
|
+
* declare `forgeWrite: true` on their `McpToolContribution`, tools that open
|
|
240
|
+
* a pull request or a comment and do nothing else. A product's own tool and
|
|
241
|
+
* hook types widen from `readOnly: true` to `readOnly: true` or `forgeWrite:
|
|
242
|
+
* true` for these, and its hook gains `propose?: boolean`. Feature-detect on
|
|
243
|
+
* `PRODUCT_MCP_PROPOSE_FLOOR`: on an older chant the read-only server drops a
|
|
244
|
+
* `forgeWrite` tool, and `--propose` is not a flag it parses.
|
|
245
|
+
*/
|
|
246
|
+
export { PRODUCT_MCP_PROPOSE_FLOOR, PRODUCT_TOOL_PROPOSE_WORDS } from "./cli/mcp/product-tools";
|
|
247
|
+
export type { McpToolContribution } from "./mcp/types";
|
|
217
248
|
export {
|
|
218
249
|
activeOtlp,
|
|
219
250
|
configureOtlp,
|
package/src/cli/commands/init.ts
CHANGED
|
@@ -34,6 +34,8 @@ export interface InitOptions {
|
|
|
34
34
|
skipMcp?: boolean;
|
|
35
35
|
/** Register `chant serve mcp --read-only` in `.mcp.json` (`--mcp-read-only`, chant#4543) */
|
|
36
36
|
mcpReadOnly?: boolean;
|
|
37
|
+
/** With `mcpReadOnly`, register `chant serve mcp --read-only --propose` (`--propose`, chant#4655) */
|
|
38
|
+
mcpPropose?: boolean;
|
|
37
39
|
/** Skip interactive install prompt */
|
|
38
40
|
skipInstall?: boolean;
|
|
39
41
|
/**
|
|
@@ -439,7 +441,7 @@ export async function initCommand(options: InitOptions): Promise<InitResult> {
|
|
|
439
441
|
if (!options.skipMcp) {
|
|
440
442
|
writeIfNotExists(
|
|
441
443
|
mcpConfigPath(targetDir),
|
|
442
|
-
generateMcpConfig(detectPackageManager(targetDir), { readOnly: options.mcpReadOnly }),
|
|
444
|
+
generateMcpConfig(detectPackageManager(targetDir), { readOnly: options.mcpReadOnly, propose: options.mcpPropose }),
|
|
443
445
|
MCP_CONFIG_FILENAME,
|
|
444
446
|
createdFiles,
|
|
445
447
|
warnings,
|
|
@@ -54,7 +54,9 @@ async function engineSetupFor(path: string): Promise<string[]> {
|
|
|
54
54
|
* `--apply-before-merge` (#4301) writes the apply job that applies an open
|
|
55
55
|
* pull request before it merges, beside the record job.
|
|
56
56
|
* `--preview-comment` (#4620) writes the jobs that answer the product's plan
|
|
57
|
-
* comment with a preview of the pull request's head.
|
|
57
|
+
* comment with a preview of the pull request's head. `--action-job` (#4654)
|
|
58
|
+
* writes the job that answers the product's action comment and a dispatch
|
|
59
|
+
* with a member and an action.
|
|
58
60
|
* `--pr-runner`, `--pr-variable`, `--pr-secret` and `--parallelism` (#4625)
|
|
59
61
|
* set each stage's runner, the plan and apply jobs' variables and passed
|
|
60
62
|
* secrets, and how many members the plan plans at once.
|
|
@@ -82,6 +84,8 @@ function prLoopOption(args: CommandContext["args"], reportUrl: string | undefine
|
|
|
82
84
|
...(args.prEnv ? { prEnvironment: true } : {}),
|
|
83
85
|
...(args.applyBeforeMerge ? { applyBeforeMerge: true } : {}),
|
|
84
86
|
...(args.previewComment ? { previewComment: true } : {}),
|
|
87
|
+
// #4654: the job that answers the action comment and the action dispatch.
|
|
88
|
+
...(args.actionJob ? { actionJob: true } : {}),
|
|
85
89
|
// #4628: the note carries its target commit, and a push marks the open notes stale.
|
|
86
90
|
...(args.staleNotes ? { staleNotes: true } : {}),
|
|
87
91
|
...(args.requires ? { applyRequires: args.requires } : {}),
|
package/src/cli/handlers/init.ts
CHANGED
|
@@ -6,6 +6,23 @@ export async function runInit(ctx: CommandContext): Promise<number> {
|
|
|
6
6
|
|
|
7
7
|
if (args.migrateFrom !== undefined) return runInitFrom(ctx);
|
|
8
8
|
|
|
9
|
+
// chant#4655 — --propose registers the read-only server's propose tier, so it needs --mcp-read-only.
|
|
10
|
+
if (args.propose === true && args.mcpReadOnly !== true) {
|
|
11
|
+
console.error(formatError({
|
|
12
|
+
message: "chant init --propose needs --mcp-read-only",
|
|
13
|
+
hint: "Usage: chant init --mcp-read-only --propose (registers chant serve mcp --read-only --propose in .mcp.json)",
|
|
14
|
+
}));
|
|
15
|
+
return 1;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// chant#4655 — --dry-run prints the .mcp.json init would register and writes nothing.
|
|
19
|
+
if (args.dryRun === true) {
|
|
20
|
+
const { detectPackageManager, generateMcpConfig } = await import("../mcp-config");
|
|
21
|
+
const target = args.path === "." || args.path === undefined ? process.cwd() : args.path;
|
|
22
|
+
console.log(generateMcpConfig(detectPackageManager(target), { readOnly: args.mcpReadOnly, propose: args.propose }));
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
9
26
|
if (!args.lexicon) {
|
|
10
27
|
console.error(formatError({
|
|
11
28
|
message: "Missing --lexicon flag",
|
|
@@ -23,6 +40,7 @@ export async function runInit(ctx: CommandContext): Promise<number> {
|
|
|
23
40
|
force: args.force,
|
|
24
41
|
skipMcp: args.skipMcp,
|
|
25
42
|
mcpReadOnly: args.mcpReadOnly,
|
|
43
|
+
mcpPropose: args.propose,
|
|
26
44
|
skipInstall: true,
|
|
27
45
|
});
|
|
28
46
|
await printInitResult(result, { skipInstall: false, cwd: args.path });
|
|
@@ -10,6 +10,14 @@ export async function runServeLsp(ctx: CommandContext): Promise<number> {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export async function runServeMcp(ctx: CommandContext): Promise<number> {
|
|
13
|
+
// chant#4655 — --propose is a tier of the read-only server, never of the ordinary one.
|
|
14
|
+
if (ctx.args.propose === true && ctx.args.readOnly !== true) {
|
|
15
|
+
console.error(formatError({
|
|
16
|
+
message: "chant serve mcp --propose needs --read-only",
|
|
17
|
+
hint: "Usage: chant serve mcp --read-only --propose (serves the read tools and a product's tools that open pull requests)",
|
|
18
|
+
}));
|
|
19
|
+
return 1;
|
|
20
|
+
}
|
|
13
21
|
const { McpServer } = await import("../mcp/server");
|
|
14
22
|
// #2700 — main() hands over no plugins only at a workspace root with no
|
|
15
23
|
// lexicon of its own (anywhere else it refuses first). There the lexicons
|
|
@@ -29,6 +37,7 @@ export async function runServeMcp(ctx: CommandContext): Promise<number> {
|
|
|
29
37
|
instructions,
|
|
30
38
|
workspace: { cwd: process.cwd() },
|
|
31
39
|
...(ctx.args.readOnly === true ? { readOnly: true } : {}),
|
|
40
|
+
...(ctx.args.propose === true ? { propose: true } : {}),
|
|
32
41
|
...(product ? { product } : {}),
|
|
33
42
|
});
|
|
34
43
|
await server.start();
|
package/src/cli/main.ts
CHANGED
|
@@ -1362,7 +1362,9 @@ Local:
|
|
|
1362
1362
|
Servers:
|
|
1363
1363
|
serve lsp Start the LSP server (stdio)
|
|
1364
1364
|
serve mcp Start the MCP server (stdio); --read-only serves only
|
|
1365
|
-
the tools that read (ledger, graph, runs) and run nothing
|
|
1365
|
+
the tools that read (ledger, graph, runs) and run nothing;
|
|
1366
|
+
--read-only --propose also serves a product's tools that
|
|
1367
|
+
open pull requests and comments, and nothing that approves
|
|
1366
1368
|
|
|
1367
1369
|
Project:
|
|
1368
1370
|
update (alias: sync) Sync lexicon types into .chant/types/ (does not install
|
|
@@ -1389,7 +1391,9 @@ Options:
|
|
|
1389
1391
|
records its lineage in .chant/workspace.lock.json
|
|
1390
1392
|
--skill <name> Init: install only this skill from the lexicon
|
|
1391
1393
|
--skip-mcp Init: scaffold without writing the project's .mcp.json
|
|
1392
|
-
--mcp-read-only Init: register \`chant serve mcp --read-only\` in .mcp.json
|
|
1394
|
+
--mcp-read-only Init: register \`chant serve mcp --read-only\` in .mcp.json;
|
|
1395
|
+
with --propose, \`chant serve mcp --read-only --propose\`.
|
|
1396
|
+
Init --dry-run prints that .mcp.json and writes nothing
|
|
1393
1397
|
--fix Auto-fix fixable issues (lint command)
|
|
1394
1398
|
--force Force overwrite existing files (import command)
|
|
1395
1399
|
-w, --watch Watch for changes and rebuild/re-lint (build, lint)
|
|
@@ -10,7 +10,11 @@ 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 { NEXT_RELEASE } from "../../release-floors";
|
|
17
|
+
import * as ciProduct from "../../ci-product";
|
|
14
18
|
import { reportReader, reportToolKey, safeReportKey } from "./report-tools";
|
|
15
19
|
import type { ToolDefinition } from "./types";
|
|
16
20
|
import type { McpToolContribution } from "../../mcp/types";
|
|
@@ -105,6 +109,58 @@ describe("the product tool hook (#4555)", () => {
|
|
|
105
109
|
});
|
|
106
110
|
});
|
|
107
111
|
|
|
112
|
+
describe("the --propose tier (#4655)", () => {
|
|
113
|
+
const forge = (name: string, handler: McpToolContribution["handler"] = async () => ({ opened: name })): McpToolContribution => ({ ...tool(name, undefined, handler), forgeWrite: true });
|
|
114
|
+
const hook = (tools: McpToolContribution[], extra: Partial<ProductMcpHook> = {}): ProductMcpHook => ({ product: "terragucci", tools: () => tools, ...extra });
|
|
115
|
+
|
|
116
|
+
test("serves the read tools, the readOnly product tools and the forgeWrite ones, and no op, signal, apply or approve tool", async () => {
|
|
117
|
+
const server = new McpServer([], { readOnly: true, propose: true, product: hook([forge("request_from_template"), tool("templates", true), tool("drift_scan")]) });
|
|
118
|
+
expect(server.readOnly).toBe(true);
|
|
119
|
+
expect(server.propose).toBe(true);
|
|
120
|
+
const names = await listed(server);
|
|
121
|
+
expect(names.filter((n) => n.startsWith("terragucci:")).sort()).toEqual(["terragucci:request_from_template", "terragucci:templates"]);
|
|
122
|
+
expect(names.filter((n) => !n.startsWith("terragucci:")).every((n) => READ_ONLY_CORE_TOOLS.has(n))).toBe(true);
|
|
123
|
+
for (const name of ["op-run", "op-signal", "op-approve", "apply", "lifecycle-snapshot"]) expect(names, name).not.toContain(name);
|
|
124
|
+
expect(JSON.parse((await call(server, "terragucci:request_from_template")).text)).toEqual({ opened: "request_from_template" });
|
|
125
|
+
const res = await server.handleRequest({ jsonrpc: "2.0", id: 1, method: "initialize", params: {} });
|
|
126
|
+
const instructions = (res.result as { instructions: string }).instructions;
|
|
127
|
+
expect(instructions).toContain(PROPOSE_INSTRUCTIONS);
|
|
128
|
+
expect(instructions).toMatch(/open pull requests and comments only/);
|
|
129
|
+
expect(instructions).toMatch(/belong to a person/);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("the read-only server without propose refuses to start, naming the forgeWrite tool", () => {
|
|
133
|
+
const tools = [forge("request_from_template"), tool("templates", true)];
|
|
134
|
+
expect(() => new McpServer([], { readOnly: true, product: hook(tools) })).toThrow(ProductToolRefusedError);
|
|
135
|
+
expect(() => new McpServer([], { readOnly: true, product: hook(tools) })).toThrow(/terragucci:request_from_template|request_from_template/);
|
|
136
|
+
expect(() => new McpServer([], { product: hook(tools) })).toThrow(/request_from_template.*--propose/);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("a forgeWrite tool named with a strong word refuses the start, naming the word", () => {
|
|
140
|
+
for (const [name, word] of [["approve_request", "approve"], ["merge_request", "merge"], ["request_override", "override"], ["apply_template", "apply"], ["create_request", "create"]] as const) {
|
|
141
|
+
const start = () => new McpServer([], { readOnly: true, propose: true, product: hook([forge(name)]) });
|
|
142
|
+
expect(start, name).toThrow(ProductToolRefusedError);
|
|
143
|
+
expect(start, name).toThrow(new RegExp(`${name} would ${word}`));
|
|
144
|
+
}
|
|
145
|
+
expect(productToolWriteWord("propose_change", ["request", "propose"])).toBeUndefined();
|
|
146
|
+
expect(productToolWriteWord("request_from_template", ["request", "propose"])).toBeUndefined();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("propose on the hook turns the tier on, and an ordinary server refuses it", async () => {
|
|
150
|
+
const tools = [forge("request_from_template"), tool("templates", true)];
|
|
151
|
+
expect(await listed(new McpServer([], { product: hook(tools, { propose: true }) }))).toContain("terragucci:request_from_template");
|
|
152
|
+
expect(() => new McpServer([], { product: hook(tools, { readOnly: false, propose: true }) })).toThrow(/--read-only --propose/);
|
|
153
|
+
// The ordinary server serves a forgeWrite tool as any other.
|
|
154
|
+
expect(await listed(new McpServer([], { product: hook(tools, { readOnly: false }) }))).toContain("terragucci:request_from_template");
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test("the tier's floor is on @intentius/chant/ci-product for a product to feature-detect", () => {
|
|
158
|
+
expect(PRODUCT_MCP_PROPOSE_FLOOR).toBe(NEXT_RELEASE);
|
|
159
|
+
expect(ciProduct.PRODUCT_MCP_PROPOSE_FLOOR).toBe(PRODUCT_MCP_PROPOSE_FLOOR);
|
|
160
|
+
expect(ciProduct.PRODUCT_TOOL_PROPOSE_WORDS).toEqual(["request", "propose"]);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
108
164
|
describe("the report tool's keys (#4555)", () => {
|
|
109
165
|
test("take a pull request, a commit, an optional member and one of the stage files", () => {
|
|
110
166
|
expect(reportToolKey({ pr: "12", commit: "a".repeat(40), file: "change-set.json" })).toBe(`12/${"a".repeat(40)}/change-set.json`);
|
|
@@ -20,10 +20,20 @@
|
|
|
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 {
|
|
36
|
+
import { NEXT_RELEASE } from "../../release-floors";
|
|
27
37
|
import { reportReader, reportUrlFor, type ReportReader } from "./report-tools";
|
|
28
38
|
|
|
29
39
|
/** What a product's tools are handed. */
|
|
@@ -32,6 +42,8 @@ export interface ProductMcpContext {
|
|
|
32
42
|
cwd: string;
|
|
33
43
|
/** Whether the server is read-only. */
|
|
34
44
|
readOnly: boolean;
|
|
45
|
+
/** Whether the read-only server also serves the product's `forgeWrite` tools (`--propose`, chant#4655). */
|
|
46
|
+
propose: boolean;
|
|
35
47
|
/**
|
|
36
48
|
* The report store, read-only: the hook's `reportUrl`, else the declared
|
|
37
49
|
* `ci.reportUrl`. Resolves undefined when neither names one.
|
|
@@ -49,10 +61,27 @@ export interface ProductMcpHook {
|
|
|
49
61
|
reportUrl?: string;
|
|
50
62
|
/** `false` starts an ordinary server through the hook. Default: read-only. */
|
|
51
63
|
readOnly?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* `true` serves the product's `forgeWrite` tools on the read-only server,
|
|
66
|
+
* as `--propose` does (chant#4655). It needs the server read-only: with
|
|
67
|
+
* `readOnly: false` the server refuses to start.
|
|
68
|
+
*/
|
|
69
|
+
propose?: boolean;
|
|
52
70
|
/** Text added to the server's `initialize` instructions. */
|
|
53
71
|
instructions?: string;
|
|
54
72
|
}
|
|
55
73
|
|
|
74
|
+
/**
|
|
75
|
+
* The first chant whose `chant serve mcp` has the `--propose` tier and serves
|
|
76
|
+
* `forgeWrite` product tools on it (chant#4655). A product checks this before
|
|
77
|
+
* it passes `--propose` or `propose: true`, and refuses naming this release
|
|
78
|
+
* when its chant is older.
|
|
79
|
+
*/
|
|
80
|
+
export const PRODUCT_MCP_PROPOSE_FLOOR = NEXT_RELEASE;
|
|
81
|
+
|
|
82
|
+
/** The words a `forgeWrite` tool's name may hold on the `--propose` tier, which the write-word check passes over (chant#4655). */
|
|
83
|
+
export const PRODUCT_TOOL_PROPOSE_WORDS = ["request", "propose"] as const;
|
|
84
|
+
|
|
56
85
|
/** Words that say a tool would change something; a read-only server will not serve a tool named with one. terragucci's list. */
|
|
57
86
|
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
87
|
|
|
@@ -65,16 +94,26 @@ export const PRODUCT_TOOL_STRONG_WORDS = ["approve", "override", "revoke", "unlo
|
|
|
65
94
|
* strong one anywhere: `last_apply` reads, `apply_wave` and `wave_approve`
|
|
66
95
|
* do not.
|
|
67
96
|
*/
|
|
68
|
-
export function productToolWriteWord(name: string): string | undefined {
|
|
97
|
+
export function productToolWriteWord(name: string, exempt: readonly string[] = []): string | undefined {
|
|
69
98
|
const parts = name.toLowerCase().split(/[^a-z]+/).filter(Boolean);
|
|
70
99
|
const first = parts[0] ?? "";
|
|
71
|
-
|
|
100
|
+
const words = (list: readonly string[]) => list.filter((w) => !exempt.includes(w));
|
|
101
|
+
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
102
|
}
|
|
73
103
|
|
|
74
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* A read-only server refused a product tool: one named as a write, or a
|
|
106
|
+
* `forgeWrite` tool on a server started without `--propose` (chant#4655).
|
|
107
|
+
*/
|
|
75
108
|
export class ProductToolRefusedError extends Error {
|
|
76
|
-
constructor(product: string, name: string, word: string) {
|
|
77
|
-
super(
|
|
109
|
+
constructor(product: string, name: string, word: string, tier: "read-only" | "propose" | "forge-write" = "read-only") {
|
|
110
|
+
super(
|
|
111
|
+
tier === "forge-write"
|
|
112
|
+
? `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`
|
|
113
|
+
: tier === "propose"
|
|
114
|
+
? `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`
|
|
115
|
+
: `chant serve mcp is read-only for ${product}, and the tool ${name} would ${word}; the server does not start with it`,
|
|
116
|
+
);
|
|
78
117
|
this.name = "ProductToolRefusedError";
|
|
79
118
|
}
|
|
80
119
|
}
|
|
@@ -82,28 +121,41 @@ export class ProductToolRefusedError extends Error {
|
|
|
82
121
|
const PRODUCT = /^[a-z0-9][a-z0-9-]*$/;
|
|
83
122
|
|
|
84
123
|
/**
|
|
85
|
-
* The product tools a server serves
|
|
86
|
-
* declare `readOnly: true`,
|
|
87
|
-
*
|
|
124
|
+
* The product tools a server serves. On an ordinary server every tool. On a
|
|
125
|
+
* read-only server those that declare `readOnly: true`, none named as a
|
|
126
|
+
* write, and no `forgeWrite` tool (each a throw, so the server does not
|
|
127
|
+
* start). On the `--propose` tier the `readOnly: true` tools under the same
|
|
128
|
+
* check, plus the `forgeWrite` tools, whose names may hold `request` or
|
|
129
|
+
* `propose` but no other write word (chant#4655).
|
|
88
130
|
*/
|
|
89
131
|
export function productToolsServed(hook: ProductMcpHook, ctx: ProductMcpContext): McpToolContribution[] {
|
|
90
132
|
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
|
-
|
|
133
|
+
const tools = hook.tools(ctx);
|
|
134
|
+
if (!ctx.readOnly) return tools;
|
|
135
|
+
const served: McpToolContribution[] = [];
|
|
136
|
+
for (const t of tools) {
|
|
137
|
+
const short = t.name.startsWith(`${hook.product}:`) ? t.name.slice(hook.product.length + 1) : t.name;
|
|
138
|
+
if (t.forgeWrite === true) {
|
|
139
|
+
if (!ctx.propose) throw new ProductToolRefusedError(hook.product, t.name, "open a pull request", "forge-write");
|
|
140
|
+
const word = productToolWriteWord(short, PRODUCT_TOOL_PROPOSE_WORDS);
|
|
141
|
+
if (word) throw new ProductToolRefusedError(hook.product, t.name, word, "propose");
|
|
142
|
+
served.push(t);
|
|
143
|
+
} else if (t.readOnly === true) {
|
|
144
|
+
const word = productToolWriteWord(short);
|
|
145
|
+
if (word) throw new ProductToolRefusedError(hook.product, t.name, word, ctx.propose ? "propose" : "read-only");
|
|
146
|
+
served.push(t);
|
|
96
147
|
}
|
|
97
148
|
}
|
|
98
149
|
return served;
|
|
99
150
|
}
|
|
100
151
|
|
|
101
152
|
/** 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 {
|
|
153
|
+
export function productMcpContext(hook: ProductMcpHook, cwd: string, readOnly: boolean, propose = false): ProductMcpContext {
|
|
103
154
|
let opened: Promise<ReportReader | undefined> | undefined;
|
|
104
155
|
return {
|
|
105
156
|
cwd,
|
|
106
157
|
readOnly,
|
|
158
|
+
propose,
|
|
107
159
|
reports: () =>
|
|
108
160
|
(opened ??= reportUrlFor(hook.reportUrl, cwd).then((url) => (url ? reportReader(url) : undefined))),
|
|
109
161
|
};
|
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();
|