Skip to content

Commit ef7e96c

Browse files
Sync public snapshot from freebuff-private
Source: CodebuffAI/freebuff-private@85f19d16a054404e9381063c28eb0f8f302cd643
1 parent 26a5b47 commit ef7e96c

21 files changed

Lines changed: 1738 additions & 35 deletions

‎cli/src/utils/sponsored-cli-capability.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import {
55
type SponsoredCapabilityReason,
66
} from '@codebuff/common/ads/sponsored-capability'
77
import { repoFullNameFromRemote } from '@codebuff/common/ads/sponsored-proposal-target'
8-
import type { SponsoredLocalContainment } from '@codebuff/common/ads/sponsored-local-execution'
8+
import {
9+
sponsoredLocalContainmentIsFloor,
10+
type SponsoredLocalContainment,
11+
} from '@codebuff/common/ads/sponsored-local-execution'
912
import { existsSync, readFileSync } from 'fs'
1013
import { release } from 'node:os'
1114
import { join } from 'path'
@@ -112,6 +115,11 @@ function execution(
112115
if (platform !== 'darwin' && platform !== 'linux')
113116
return 'unsupported_platform'
114117
const contained = containment(platform)
118+
// The Windows floor (COD-642) is Desktop's arm, answered only for win32,
119+
// which returned above. A probe that claims it here is not believed, and
120+
// the CLI never offers the floor at all.
121+
if (sponsoredLocalContainmentIsFloor(contained))
122+
return 'containment_probe_failed'
115123
if (!contained.available)
116124
return contained.reason === 'bubblewrap-missing'
117125
? 'bubblewrap_missing'

‎common/src/ads/sponsored-capability.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, expect, test } from 'bun:test'
22
import {
33
sponsoredCapabilitySchema,
4+
sponsoredDesktopExecutionSurfaceForPlatform,
45
SUPABASE_FOUNDATION_MODES,
56
SUPABASE_FOUNDATION_RUNNABLE_FRAMEWORKS,
67
supabaseFoundationCapabilityEligible,
@@ -186,3 +187,18 @@ describe('foundation execution admission', () => {
186187
}
187188
})
188189
})
190+
191+
describe('the Desktop surface a process reports (COD-642)', () => {
192+
test('each OS names its own surface, and no other', () => {
193+
expect(sponsoredDesktopExecutionSurfaceForPlatform('darwin')).toBe(
194+
'desktop_macos',
195+
)
196+
expect(sponsoredDesktopExecutionSurfaceForPlatform('linux')).toBe(
197+
'desktop_linux',
198+
)
199+
expect(sponsoredDesktopExecutionSurfaceForPlatform('win32')).toBe(
200+
'desktop_windows',
201+
)
202+
expect(sponsoredDesktopExecutionSurfaceForPlatform('freebsd')).toBeNull()
203+
})
204+
})

‎common/src/ads/sponsored-capability.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export const sponsoredCapabilityReasonSchema = z.enum([
1515
'unreadable_package_manifest',
1616
'no_consent_bridge',
1717
'containment_probe_failed',
18+
// COD-642: the sponsored file tools cannot hold this project's volume.
19+
'file_layer_unavailable',
1820
])
1921
export const capabilityInspectionSchema = z.discriminatedUnion('status', [
2022
z.object({ status: z.literal('available') }).strict(),
@@ -67,6 +69,20 @@ export const SPONSORED_DESKTOP_EXECUTION_SURFACES = [
6769
] as const satisfies readonly SponsoredExecutionSurface[]
6870
export type SponsoredDesktopExecutionSurface =
6971
(typeof SPONSORED_DESKTOP_EXECUTION_SURFACES)[number]
72+
73+
/**
74+
* The Desktop execution surface of the OS a Desktop process runs on, or null
75+
* for an OS Desktop does not run sponsored work on. What the client reports,
76+
* never what it is granted: the server decides whether that surface is served.
77+
*/
78+
export function sponsoredDesktopExecutionSurfaceForPlatform(
79+
platform: string,
80+
): SponsoredDesktopExecutionSurface | null {
81+
if (platform === 'darwin') return 'desktop_macos'
82+
if (platform === 'linux') return 'desktop_linux'
83+
if (platform === 'win32') return 'desktop_windows'
84+
return null
85+
}
7086
export const sponsoredCapabilitySchema = z
7187
.object({
7288
schemaVersion: z.literal(2),

‎common/src/ads/sponsored-compute-contract.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, expect, test } from 'bun:test'
22
import {
33
SPONSORED_ACCEPT_EXECUTION_SURFACE_PARAM,
4+
acceptClientSurfacePairsWithRow,
45
readSponsoredComputePolicy,
56
sponsoredAcceptSurfaceMatchesRow,
67
sponsoredComputeAdmitsCampaign,
@@ -163,4 +164,34 @@ describe('the funded Accept request pairs the client with the row (COD-642)', ()
163164
// A client that cannot name its own surface matches nothing recorded.
164165
expect(sponsoredAcceptSurfaceMatchesRow(null, 'desktop_macos')).toBe(false)
165166
})
167+
168+
test('the Accept pairing: Windows only ever takes a Windows row, and a Windows row only a Windows client', () => {
169+
// One rule, applied by the server route and by Desktop before consent.
170+
expect(
171+
acceptClientSurfacePairsWithRow('desktop_windows', 'desktop_windows'),
172+
).toBe(true)
173+
// Stricter than the plain match: an unrecorded row is never Windows.
174+
expect(acceptClientSurfacePairsWithRow('desktop_windows', undefined)).toBe(
175+
false,
176+
)
177+
expect(acceptClientSurfacePairsWithRow('desktop_windows', null)).toBe(false)
178+
expect(
179+
acceptClientSurfacePairsWithRow('desktop_windows', 'desktop_macos'),
180+
).toBe(false)
181+
// A client that sends nothing (older builds, the CLI) keeps its old rows
182+
// and never reaches a Windows one.
183+
expect(acceptClientSurfacePairsWithRow(undefined, 'desktop_macos')).toBe(
184+
true,
185+
)
186+
expect(acceptClientSurfacePairsWithRow(undefined, undefined)).toBe(true)
187+
expect(acceptClientSurfacePairsWithRow(undefined, 'desktop_windows')).toBe(
188+
false,
189+
)
190+
expect(acceptClientSurfacePairsWithRow('desktop_macos', undefined)).toBe(
191+
true,
192+
)
193+
expect(
194+
acceptClientSurfacePairsWithRow('desktop_macos', 'desktop_windows'),
195+
).toBe(false)
196+
})
166197
})

‎common/src/ads/sponsored-compute-contract.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,35 @@ export function sponsoredAcceptSurfaceMatchesRow(
5353
return clientSurface === rowSurface
5454
}
5555

56+
/**
57+
* The pairing the funded Accept applies, on the server and on Desktop alike
58+
* (COD-642). The row's `execution_surface` says which machine the offer was
59+
* minted for; `clientExecutionSurface` says which machine is about to run it.
60+
*
61+
* - Absent (a client older than the field, and the CLI, which never sends
62+
* it): any row it could accept before COD-642, and NEVER a
63+
* `desktop_windows` row, whose only legitimate client sends it.
64+
* - `desktop_windows`: only a `desktop_windows` row. An unrecorded row is
65+
* never one, so it is refused too.
66+
* - Anything else: exactly the row's own surface when the row recorded one
67+
* ({@link sponsoredAcceptSurfaceMatchesRow}).
68+
*
69+
* Linux (COD-655) needs no arm of its own: it follows macOS. `desktop_linux`
70+
* pairs only with a `desktop_linux` row, a macOS or Windows client is refused
71+
* on one, and an absent field is admitted exactly as it is on a macOS row,
72+
* since released Linux builds already run sponsored work under bubblewrap.
73+
*/
74+
export function acceptClientSurfacePairsWithRow(
75+
clientSurface: SponsoredExecutionSurface | null | undefined,
76+
rowSurface: string | null | undefined,
77+
): boolean {
78+
const windows = 'desktop_windows' satisfies SponsoredExecutionSurface
79+
if (clientSurface === undefined || clientSurface === null)
80+
return rowSurface !== windows
81+
if (clientSurface === windows && rowSurface !== windows) return false
82+
return sponsoredAcceptSurfaceMatchesRow(clientSurface, rowSurface)
83+
}
84+
5685
/** Public response shape. The bearer belongs in host memory, never a thread. */
5786
export type SponsoredComputeGrant = Readonly<{
5887
token: string

‎common/src/ads/sponsored-consent.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
SPONSORED_CONSENT_MAX_NAME_CHARS,
77
SPONSORED_CONSENT_NO_NAME,
88
SPONSORED_CONSENT_SENTENCE,
9+
SPONSORED_CONSENT_WINDOWS_FLOOR_SENTENCE,
910
sponsoredConsentName,
1011
sponsoredConsentSentence,
1112
} from './sponsored-consent'
@@ -57,6 +58,23 @@ describe('every surface asks the same question', () => {
5758
expect(read(rel)).toContain(SPONSORED_CONSENT_SENTENCE.trim())
5859
})
5960

61+
test.each([
62+
['freebuff-desktop/electron/mcp-consent-bridge.cjs'],
63+
['freebuff-desktop/electron/consent-window.html'],
64+
])('%s carries the same Windows no-sandbox sentence, verbatim (COD-642)', (rel) => {
65+
expect(read(rel)).toContain(SPONSORED_CONSENT_WINDOWS_FLOOR_SENTENCE)
66+
})
67+
68+
test('the Windows sentence says the three things, in plain words', () => {
69+
expect(SPONSORED_CONSENT_WINDOWS_FLOOR_SENTENCE).toContain('no sandbox')
70+
expect(SPONSORED_CONSENT_WINDOWS_FLOOR_SENTENCE).toContain(
71+
'your own Windows permissions',
72+
)
73+
expect(SPONSORED_CONSENT_WINDOWS_FLOOR_SENTENCE).toContain(
74+
'hidden from it but not locked away',
75+
)
76+
})
77+
6078
test('the desktop window says the same thing when it cannot name who is asking', () => {
6179
expect(read('freebuff-desktop/electron/consent-window.html')).toContain(
6280
SPONSORED_CONSENT_NO_NAME,

‎common/src/ads/sponsored-consent.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
export const SPONSORED_CONSENT_SENTENCE =
2525
' wants to integrate itself into this project, on its own branch. Nothing is pushed until you review it.'
2626

27+
/**
28+
* The second sentence, shown ONLY where the run has no OS sandbox: Windows (COD-642). Plain words
29+
* for the three things a user is agreeing to there -- their own permissions, no sandbox, and
30+
* credentials that are kept out of the run's way rather than locked away. Product-owned and fixed:
31+
* a surface decides from its own platform whether to show it, never from anything it was sent.
32+
*/
33+
export const SPONSORED_CONSENT_WINDOWS_FLOOR_SENTENCE =
34+
'On Windows there is no sandbox. This task runs with your own Windows permissions, and your credentials are hidden from it but not locked away.'
35+
2736
/**
2837
* What a surface shows when it cannot name who is asking. Blank is not a legal render: a sentence
2938
* about nobody asks a human to consent to nothing, so the surfaces refuse instead of asking.

0 commit comments

Comments
 (0)