Elffuss BraidHub

kikocis/continue public

Merge pull request #7400 from continuedev/nate/unroll-assistant-list-blocks

feat: allow/blocklisted blocks in unrollAssistant
Changeset7dd3a742e7cdd8a2fcac36be13c503df82973da355e9c1ba92d8fc2554ebe9b2
AuthorNate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-08-25 16:16 -07:00
CommitterGitHub <noreply@github.com> · 2025-08-25 16:16 -07:00
Parentsd13968478db8, b4db4cbf8943

Browse the files at this changeset

2 files changed

modified packages/config-yaml/src/__tests__/index.test.ts +162 −0
@@ -330,5 +330,167 @@
330330 ).toBe(true);
331331 });
332332
333+ it("should throw when a block is blocklisted", async () => {
334+ const result = await unrollAssistant(
335+ {
336+ uriType: "slug",
337+ fullSlug: {
338+ ownerSlug: "test-org",
339+ packageSlug: "agent",
340+ versionSlug: "latest",
341+ },
342+ },
343+ registry,
344+ {
345+ renderSecrets: true,
346+ platformClient,
347+ orgScopeId: "test-org",
348+ currentUserSlug: "test-user",
349+ onPremProxyUrl: null,
350+ blocklistedBlocks: [
351+ {
352+ ownerSlug: "test-org",
353+ packageSlug: "gemini",
354+ },
355+ ],
356+ },
357+ );
358+
359+ // Should contain an error about the blocklisted block
360+ expect(result.errors).toBeDefined();
361+ expect(result.errors?.length).toBeGreaterThan(0);
362+ expect(
363+ result.errors?.some((error) =>
364+ error.message.includes(
365+ "test-org/gemini is block listed and can not be used.",
366+ ),
367+ ),
368+ ).toBe(true);
369+ });
370+
371+ it("should return an error when a block is not on the allowlist", async () => {
372+ const result = await unrollAssistant(
373+ {
374+ uriType: "slug",
375+ fullSlug: {
376+ ownerSlug: "test-org",
377+ packageSlug: "agent",
378+ versionSlug: "latest",
379+ },
380+ },
381+ registry,
382+ {
383+ renderSecrets: true,
384+ platformClient,
385+ orgScopeId: "test-org",
386+ currentUserSlug: "test-user",
387+ onPremProxyUrl: null,
388+ allowlistedBlocks: [
389+ {
390+ ownerSlug: "test-org",
391+ packageSlug: "docs",
392+ },
393+ {
394+ ownerSlug: "test-org",
395+ packageSlug: "rules",
396+ },
397+ {
398+ ownerSlug: "test-org",
399+ packageSlug: "claude35sonnet",
400+ },
401+ ],
402+ },
403+ );
404+
405+ // Should contain an error about the non-allowlisted block (gemini)
406+ expect(result.errors).toBeDefined();
407+ expect(result.errors?.length).toBeGreaterThan(0);
408+ expect(
409+ result.errors?.some((error) =>
410+ error.message.includes(
411+ "test-org/gemini is block listed and can not be used.",
412+ ),
413+ ),
414+ ).toBe(true);
415+ });
416+
417+ it("should allow blocks when they are on the allowlist", async () => {
418+ const result = await unrollAssistant(
419+ {
420+ uriType: "slug",
421+ fullSlug: {
422+ ownerSlug: "test-org",
423+ packageSlug: "agent",
424+ versionSlug: "latest",
425+ },
426+ },
427+ registry,
428+ {
429+ renderSecrets: true,
430+ platformClient,
431+ orgScopeId: "test-org",
432+ currentUserSlug: "test-user",
433+ onPremProxyUrl: null,
434+ allowlistedBlocks: [
435+ {
436+ ownerSlug: "test-org",
437+ packageSlug: "docs",
438+ },
439+ {
440+ ownerSlug: "test-org",
441+ packageSlug: "rules",
442+ },
443+ {
444+ ownerSlug: "test-org",
445+ packageSlug: "gemini",
446+ },
447+ {
448+ ownerSlug: "test-org",
449+ packageSlug: "claude35sonnet",
450+ },
451+ ],
452+ },
453+ );
454+
455+ // Should successfully unroll without errors for allowed blocks
456+ expect(result.config?.models?.length).toBe(4);
457+ expect(result.config?.rules?.length).toBe(2);
458+ expect(result.config?.docs?.length).toBe(1);
459+ });
460+
461+ it("should not affect file-based blocks with allow/blocklists", async () => {
462+ const result = await unrollAssistant(
463+ {
464+ uriType: "file",
465+ fileUri: "./src/__tests__/local-files/duplicate-test-agent.yaml",
466+ },
467+ registry,
468+ {
469+ renderSecrets: true,
470+ platformClient,
471+ orgScopeId: "test-org",
472+ currentUserSlug: "test-user",
473+ onPremProxyUrl: null,
474+ blocklistedBlocks: [
475+ {
476+ ownerSlug: "test-org",
477+ packageSlug: "docs",
478+ },
479+ ],
480+ injectBlocks: [
481+ {
482+ uriType: "file",
483+ fileUri: "./src/__tests__/local-files/rules.yaml",
484+ },
485+ ],
486+ },
487+ );
488+
489+ // File-based blocks should not be affected by blocklists
490+ expect(result.config?.models?.length).toBe(1);
491+ expect(result.config?.context?.length).toBe(1);
492+ expect(result.config?.rules?.length).toBeGreaterThan(0);
493+ });
494+
333495 it.skip("should prioritize org over user / package secrets", () => {});
334496 });
modified packages/config-yaml/src/load/unroll.ts +69 −2
@@ -6,8 +6,12 @@
66 decodeFQSN,
77 decodePackageIdentifier,
88 encodeFQSN,
9+ encodePackageIdentifier,
10+ encodePackageSlug,
911 FQSN,
1012 PackageIdentifier,
13+ PackageSlug,
14+ packageSlugsEqual,
1115 } from "../interfaces/slugs.js";
1216 import { markdownToRule } from "../markdown/index.js";
1317 import {
@@ -197,6 +201,8 @@
197201 export interface BaseUnrollAssistantOptions {
198202 renderSecrets: boolean;
199203 injectBlocks?: PackageIdentifier[];
204+ allowlistedBlocks?: PackageSlug[];
205+ blocklistedBlocks?: PackageSlug[];
200206 }
201207
202208 export interface DoNotRenderSecretsUnrollAssistantOptions
@@ -262,7 +268,13 @@
262268 config: unrolledAssistant,
263269 configLoadInterrupted,
264270 errors,
265- } = await unrollBlocks(parsedYaml, registry, options.injectBlocks);
271+ } = await unrollBlocks(
272+ parsedYaml,
273+ registry,
274+ options.injectBlocks,
275+ options.allowlistedBlocks,
276+ options.blocklistedBlocks,
277+ );
266278
267279 // Back to a string so we can fill in template variables
268280 const rawUnrolledYaml = YAML.stringify(unrolledAssistant);
@@ -300,10 +312,44 @@
300312 return { config: finalConfig, errors, configLoadInterrupted };
301313 }
302314
315+function isPackageAllowed(
316+ pkgId: PackageIdentifier,
317+ allowlistedBlocks?: PackageSlug[],
318+ blocklistedBlocks?: PackageSlug[],
319+): boolean {
320+ // Only "slug" type blocks can be allow/block listed
321+ if (pkgId.uriType !== "slug") {
322+ return true;
323+ }
324+
325+ const packageSlug = {
326+ ownerSlug: pkgId.fullSlug.ownerSlug,
327+ packageSlug: pkgId.fullSlug.packageSlug,
328+ };
329+
330+ if (
331+ allowlistedBlocks &&
332+ !allowlistedBlocks.some((block) => packageSlugsEqual(block, packageSlug))
333+ ) {
334+ return false;
335+ }
336+
337+ if (
338+ blocklistedBlocks &&
339+ blocklistedBlocks.some((block) => packageSlugsEqual(block, packageSlug))
340+ ) {
341+ return false;
342+ }
343+
344+ return true;
345+}
346+
303347 export async function unrollBlocks(
304348 assistant: ConfigYaml,
305349 registry: Registry,
306350 injectBlocks: PackageIdentifier[] | undefined,
351+ allowlistedBlocks?: PackageSlug[],
352+ blocklistedBlocks?: PackageSlug[],
307353 ): Promise<ConfigResult<AssistantUnrolled>> {
308354 const errors: ConfigValidationError[] = [];
309355
@@ -336,8 +382,29 @@
336382 // "uses/with" block
337383 if ("uses" in unrolledBlock) {
338384 try {
385+ const blockIdentifier = decodePackageIdentifier(unrolledBlock.uses);
386+
387+ if (
388+ !isPackageAllowed(
389+ blockIdentifier,
390+ allowlistedBlocks,
391+ blocklistedBlocks,
392+ )
393+ ) {
394+ throw new Error(
395+ `${
396+ blockIdentifier.uriType === "slug"
397+ ? encodePackageSlug({
398+ ownerSlug: blockIdentifier.fullSlug.ownerSlug,
399+ packageSlug: blockIdentifier.fullSlug.packageSlug,
400+ })
401+ : encodePackageIdentifier(blockIdentifier)
402+ } is block listed and can not be used.`,
403+ );
404+ }
405+
339406 const blockConfigYaml = await resolveBlock(
340- decodePackageIdentifier(unrolledBlock.uses),
407+ blockIdentifier,
341408 unrolledBlock.with,
342409 registry,
343410 );