-
Notifications
You must be signed in to change notification settings - Fork 10
feat(client): consume brand identity agents/services allowlists #479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
db03912
feat(schema): accept optional agents/services on the config build bundle
lucas77778 dfd090d
feat(desktop): render and surface the build-time agent/service allowlist
lucas77778 28eb599
feat(daemon): gate new agent adapters by the restricted-brand allowlist
lucas77778 46648dd
feat(desktop): exclude restricted agents' SDKs from packaged builds
lucas77778 bd62ef1
feat(mobile): thread the build-time agent allowlist into the config b…
lucas77778 ccac9af
feat(workbench,ui): filter the harness picker and add-account catalog…
lucas77778 8d577b9
fix(engine,daemon): fix CI ESM load, history-read regression, and rev…
lucas77778 068c291
fix(desktop): import agent-package-excludes with an explicit extension
lucas77778 5671d2a
fix(engine,daemon): close review gaps in the restricted-brand allowlist
lucas77778 baa0f7b
merge(client): resolve master conflicts for brand restrictions
lucas77778 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import type { AssetService } from '@linkcode/engine'; | ||
| import type { AgentRuntimes, InstalledAsset, ManagedAssetId } from '@linkcode/schema'; | ||
| import { noop } from 'foxts/noop'; | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import { filterAgentRuntimes, restrictedAssetService } from '../agent-restrictions'; | ||
|
|
||
| describe('filterAgentRuntimes', () => { | ||
| const runtimes: AgentRuntimes = { | ||
| 'claude-code': { status: 'available', source: 'detected', path: '/usr/bin/claude' }, | ||
| codex: { status: 'available', source: 'sdk' }, | ||
| pi: { status: 'missing' }, | ||
| }; | ||
|
|
||
| it('returns the runtimes unchanged when unrestricted', () => { | ||
| expect(filterAgentRuntimes(runtimes, null)).toBe(runtimes); | ||
| }); | ||
|
|
||
| it('reports a disallowed kind as missing regardless of how it was actually probed', () => { | ||
| const filtered = filterAgentRuntimes(runtimes, ['pi']); | ||
| expect(filtered['claude-code']).toEqual({ status: 'missing' }); | ||
| expect(filtered.codex).toEqual({ status: 'missing' }); | ||
| expect(filtered.pi).toEqual({ status: 'missing' }); | ||
| }); | ||
|
|
||
| it('leaves an allowed kind exactly as probed', () => { | ||
| const filtered = filterAgentRuntimes(runtimes, ['claude-code']); | ||
| expect(filtered['claude-code']).toBe(runtimes['claude-code']); | ||
| }); | ||
| }); | ||
|
|
||
| describe('restrictedAssetService', () => { | ||
| // Mocks kept as loose locals rather than read back off the typed `AssetService` — asserting via | ||
| // `assets.ensure` would reference an interface method (unbound-method lint) for no benefit here. | ||
| function fakeAssets(): { | ||
| assets: AssetService; | ||
| ensure: ReturnType<typeof vi.fn>; | ||
| statuses: ReturnType<typeof vi.fn>; | ||
| subscribe: ReturnType<typeof vi.fn>; | ||
| } { | ||
| const ensure = vi.fn( | ||
| (id: ManagedAssetId): Promise<InstalledAsset> => | ||
| Promise.resolve({ id, version: '1.0.0', path: '/tmp/asset' }), | ||
| ); | ||
| const statuses = vi.fn(() => []); | ||
| const subscribe = vi.fn(() => noop); | ||
| return { assets: { statuses, subscribe, ensure }, ensure, statuses, subscribe }; | ||
| } | ||
|
|
||
| it('returns the asset service unchanged when unrestricted', () => { | ||
| const { assets } = fakeAssets(); | ||
| expect(restrictedAssetService(assets, null)).toBe(assets); | ||
| }); | ||
|
|
||
| it('refuses to ensure a disallowed agent asset without touching the underlying store', async () => { | ||
| const { assets, ensure } = fakeAssets(); | ||
| const restricted = restrictedAssetService(assets, ['pi']); | ||
|
|
||
| const installed = await restricted.ensure({ kind: 'agent', name: 'codex' }); | ||
|
|
||
| expect(installed).toBeUndefined(); | ||
| expect(ensure).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('passes an allowed agent asset through to the underlying store', async () => { | ||
| const { assets, ensure } = fakeAssets(); | ||
| const restricted = restrictedAssetService(assets, ['pi']); | ||
|
|
||
| await restricted.ensure({ kind: 'agent', name: 'pi' }); | ||
|
|
||
| expect(ensure).toHaveBeenCalledWith({ kind: 'agent', name: 'pi' }); | ||
| }); | ||
|
|
||
| it('never agent-gates a tool asset', async () => { | ||
| const { assets, ensure } = fakeAssets(); | ||
| const restricted = restrictedAssetService(assets, ['pi']); | ||
|
|
||
| await restricted.ensure({ kind: 'tool', name: 'aigateway' }); | ||
|
|
||
| expect(ensure).toHaveBeenCalledWith({ kind: 'tool', name: 'aigateway' }); | ||
| }); | ||
|
|
||
| it('forwards statuses() and subscribe() untouched', () => { | ||
| const { assets, statuses, subscribe } = fakeAssets(); | ||
| const restricted = restrictedAssetService(assets, ['pi']); | ||
| const listener = vi.fn(); | ||
|
|
||
| restricted.statuses(); | ||
| restricted.subscribe(listener); | ||
|
|
||
| expect(statuses).toHaveBeenCalledTimes(1); | ||
| expect(subscribe).toHaveBeenCalledWith(listener); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import type { AssetService } from '@linkcode/engine'; | ||
| import type { AgentKind, AgentRuntimes, ManagedAssetId } from '@linkcode/schema'; | ||
|
|
||
| /** | ||
| * Restricted-brand runtime-probe filter (CODE-618): a disallowed agent must never read as | ||
| * `available` on a restricted build, however the boot probe actually found it (detected CLI, | ||
| * managed install, or SDK-resolved) — the settings page and onboarding cards read straight off | ||
| * this map. `null` (unrestricted, the default build) returns `runtimes` unchanged. | ||
| */ | ||
| export function filterAgentRuntimes( | ||
| runtimes: AgentRuntimes, | ||
| allowedAgents: readonly AgentKind[] | null, | ||
| ): AgentRuntimes { | ||
| if (allowedAgents === null) return runtimes; | ||
| const filtered: AgentRuntimes = { ...runtimes }; | ||
| for (const kind of Object.keys(filtered) as AgentKind[]) { | ||
| if (!allowedAgents.includes(kind)) filtered[kind] = { status: 'missing' }; | ||
| } | ||
| return filtered; | ||
| } | ||
|
|
||
| /** | ||
| * Restricted-brand managed-download gate (CODE-618): wraps the daemon's `AssetService` so a | ||
| * client's `asset.ensure` for an excluded agent kind gets the same "cannot be installed here" | ||
| * refusal `ManagedAssetService` already gives an unpinnable asset — no new failure path to learn. | ||
| * Tool assets (`kind: 'tool'`, e.g. aigateway) are never agent-gated. `null` (unrestricted) returns | ||
| * `assets` unchanged. | ||
| */ | ||
| export function restrictedAssetService( | ||
| assets: AssetService, | ||
| allowedAgents: readonly AgentKind[] | null, | ||
| ): AssetService { | ||
| if (allowedAgents === null) return assets; | ||
| return { | ||
| statuses: () => assets.statuses(), | ||
| subscribe: (listener) => assets.subscribe(listener), | ||
| ensure: (id: ManagedAssetId) => | ||
| id.kind === 'agent' && !allowedAgents.includes(id.name) | ||
| ? Promise.resolve(undefined) | ||
| : assets.ensure(id), | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.