feat(subagent): make Codex provider directly installable
This commit is contained in:
1 parent
21b93a4568
commit
b2178ade80
50 files changed
+571
-242
No files matched your search
@@ -4,7 +4,9 @@ import { tmpdir } from 'node:os'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
CLAUDE_AGENT_SDK_PACKAGE,
|
||||
CODEX_PACKAGE,
|
||||
claudeDistributionFromManifest,
|
||||
codexDistributionFromManifest,
|
||||
collectPythonDependencies,
|
||||
isOwnerAuthorizedRuntime,
|
||||
isPermissive,
|
||||
@@ -331,6 +333,53 @@ describe('official Claude distribution authorization', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('official Codex platform payloads', () => {
|
||||
it('derives versioned packages from the wrapper aliases', () => {
|
||||
expect(codexDistributionFromManifest({
|
||||
name: CODEX_PACKAGE,
|
||||
version: '9.8.7',
|
||||
optionalDependencies: {
|
||||
'@openai/codex-linux-x64': 'npm:@openai/[email protected]',
|
||||
'@openai/codex-darwin-arm64': 'npm:@openai/[email protected]',
|
||||
},
|
||||
})).toEqual({
|
||||
wrapperVersion: '9.8.7',
|
||||
payloads: [
|
||||
{ alias: '@openai/codex-darwin-arm64', version: '9.8.7-darwin-arm64' },
|
||||
{ alias: '@openai/codex-linux-x64', version: '9.8.7-linux-x64' },
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
it('rejects a wrong identity, missing payloads, and non-official aliases', () => {
|
||||
expect(() => codexDistributionFromManifest({
|
||||
name: '@openai/unrelated',
|
||||
version: '1.0.0',
|
||||
optionalDependencies: {
|
||||
'@openai/codex-linux-x64': 'npm:@openai/[email protected]',
|
||||
},
|
||||
})).toThrow(`expected ${CODEX_PACKAGE} manifest`)
|
||||
expect(() => codexDistributionFromManifest({
|
||||
name: CODEX_PACKAGE,
|
||||
version: '1.0.0',
|
||||
})).toThrow('declares no optional platform payloads')
|
||||
expect(() => codexDistributionFromManifest({
|
||||
name: CODEX_PACKAGE,
|
||||
version: '1.0.0',
|
||||
optionalDependencies: {
|
||||
'@openai/unrelated': 'npm:@openai/[email protected]',
|
||||
},
|
||||
})).toThrow('outside its platform alias namespace')
|
||||
expect(() => codexDistributionFromManifest({
|
||||
name: CODEX_PACKAGE,
|
||||
version: '1.0.0',
|
||||
optionalDependencies: {
|
||||
'@openai/codex-linux-x64': '1.0.0',
|
||||
},
|
||||
})).toThrow('does not alias an official versioned payload')
|
||||
})
|
||||
})
|
||||
|
||||
describe('manifestPatterns', () => {
|
||||
it('derives globs from the declared members, so a new member area is read', () => {
|
||||
expect(manifestPatterns(['packages/*/*', 'tools/*', 'native/landlock-run', 'native/landlock-run/packages/*'])).toEqual([
|
||||
|
||||
@@ -50,6 +50,9 @@ const FIRST_PARTY = new Set([
|
||||
export const CLAUDE_AGENT_SDK_PACKAGE = '@anthropic-ai/claude-agent-sdk'
|
||||
const CLAUDE_PLATFORM_PACKAGE_PREFIX = `${CLAUDE_AGENT_SDK_PACKAGE}-`
|
||||
const CLAUDE_PLATFORM_DECLARED_LICENSE = 'SEE LICENSE IN LICENSE.md'
|
||||
export const CODEX_PACKAGE = '@openai/codex'
|
||||
const CODEX_PLATFORM_ALIAS_PREFIX = `${CODEX_PACKAGE}-`
|
||||
const CODEX_DECLARED_LICENSE = 'Apache-2.0'
|
||||
|
||||
/**
|
||||
* Whether a non-permissive runtime declaration has an identity-scoped owner
|
||||
@@ -194,6 +197,18 @@ export interface ClaudeDistribution {
|
||||
readonly payloads: ClaudePlatformPayload[]
|
||||
}
|
||||
|
||||
/** One optional-dependency alias for an official Codex platform payload. */
|
||||
export interface CodexPlatformPayload {
|
||||
readonly alias: string
|
||||
readonly version: string
|
||||
}
|
||||
|
||||
/** Current Codex wrapper and platform payload facts from the official manifest. */
|
||||
export interface CodexDistribution {
|
||||
readonly wrapperVersion: string
|
||||
readonly payloads: CodexPlatformPayload[]
|
||||
}
|
||||
|
||||
function requiredManifestString(
|
||||
value: string | undefined,
|
||||
field: string,
|
||||
@@ -243,6 +258,40 @@ export function claudeDistributionFromManifest(
|
||||
return { sdkVersion, claudeCodeVersion, payloads }
|
||||
}
|
||||
|
||||
/** Derive official Codex platform aliases and published package versions. */
|
||||
export function codexDistributionFromManifest(
|
||||
manifest: VirtualManifest,
|
||||
): CodexDistribution {
|
||||
if (manifest.name !== CODEX_PACKAGE) {
|
||||
throw new Error(
|
||||
`gen-third-party-notices: expected ${CODEX_PACKAGE} manifest, got ${JSON.stringify(manifest.name)}.`,
|
||||
)
|
||||
}
|
||||
const wrapperVersion = manifest.version
|
||||
if (wrapperVersion === undefined || wrapperVersion.length === 0) {
|
||||
throw new Error(`gen-third-party-notices: ${CODEX_PACKAGE} has no version.`)
|
||||
}
|
||||
const entries = Object.entries(manifest.optionalDependencies ?? {})
|
||||
if (entries.length === 0) {
|
||||
throw new Error(`gen-third-party-notices: ${CODEX_PACKAGE} declares no optional platform payloads.`)
|
||||
}
|
||||
const payloads = entries.map(([alias, spec]) => {
|
||||
if (!alias.startsWith(CODEX_PLATFORM_ALIAS_PREFIX)) {
|
||||
throw new Error(
|
||||
`gen-third-party-notices: ${CODEX_PACKAGE} optional dependency ${alias} is outside its platform alias namespace.`,
|
||||
)
|
||||
}
|
||||
const prefix = `npm:${CODEX_PACKAGE}@`
|
||||
if (!spec.startsWith(prefix) || spec.length === prefix.length) {
|
||||
throw new Error(
|
||||
`gen-third-party-notices: ${CODEX_PACKAGE} optional dependency ${alias} does not alias an official versioned payload.`,
|
||||
)
|
||||
}
|
||||
return { alias, version: spec.slice(prefix.length) }
|
||||
}).sort((left, right) => left.alias.localeCompare(right.alias))
|
||||
return { wrapperVersion, payloads }
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve one package's manifest inside a pnpm virtual store. The prefix scan
|
||||
* matches ordinary `@scope+name@version` directory names; pnpm 11 truncates
|
||||
@@ -333,6 +382,54 @@ function collectClaudeDistribution(): ClaudeDistribution {
|
||||
return distribution
|
||||
}
|
||||
|
||||
/** Resolve an installed versioned Codex payload manifest from either pnpm store. */
|
||||
function installedCodexPayload(version: string): VirtualManifest | undefined {
|
||||
for (const store of ['node_modules', 'native/landlock-run/node_modules']) {
|
||||
const candidate = resolve(
|
||||
root,
|
||||
store,
|
||||
'.pnpm',
|
||||
`${CODEX_PACKAGE.replace('/', '+')}@${version}`,
|
||||
'node_modules',
|
||||
CODEX_PACKAGE,
|
||||
'package.json',
|
||||
)
|
||||
if (existsSync(candidate)) {
|
||||
return JSON.parse(readFileSync(candidate, 'utf8')) as VirtualManifest
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
function collectCodexDistribution(): CodexDistribution {
|
||||
const manifest = installedManifest(CODEX_PACKAGE)
|
||||
if (manifest === undefined) {
|
||||
throw new Error(`gen-third-party-notices: cannot resolve ${CODEX_PACKAGE}; run \`pnpm install\`.`)
|
||||
}
|
||||
const distribution = codexDistributionFromManifest(manifest)
|
||||
let installedPayloads = 0
|
||||
for (const payload of distribution.payloads) {
|
||||
const installed = installedCodexPayload(payload.version)
|
||||
if (installed === undefined) continue
|
||||
installedPayloads += 1
|
||||
if (
|
||||
installed.name !== CODEX_PACKAGE
|
||||
|| installed.version !== payload.version
|
||||
|| installed.license !== CODEX_DECLARED_LICENSE
|
||||
) {
|
||||
throw new Error(
|
||||
`gen-third-party-notices: installed ${payload.alias} does not match its official ${CODEX_PACKAGE}@${payload.version} payload and ${CODEX_DECLARED_LICENSE} license.`,
|
||||
)
|
||||
}
|
||||
}
|
||||
if (installedPayloads === 0) {
|
||||
throw new Error(
|
||||
'gen-third-party-notices: no Codex platform payload is installed; install optional dependencies before regenerating.',
|
||||
)
|
||||
}
|
||||
return distribution
|
||||
}
|
||||
|
||||
/** Normalize a manifest repository/homepage value to a browsable https URL. */
|
||||
function normalizeRepo(raw: string | undefined): string | undefined {
|
||||
if (raw === undefined || raw === '') return undefined
|
||||
@@ -656,6 +753,24 @@ ${rows.join('\n')}
|
||||
`
|
||||
}
|
||||
|
||||
function renderCodexDistribution(
|
||||
distribution: CodexDistribution | undefined,
|
||||
): string {
|
||||
if (distribution === undefined) return ''
|
||||
const rows = distribution.payloads.map(payload => (
|
||||
`| \`${payload.alias}\` | [\`${CODEX_PACKAGE}\`](https://www.npmjs.com/package/${CODEX_PACKAGE}/v/${payload.version}) | ${payload.version} | ${CODEX_DECLARED_LICENSE} |`
|
||||
))
|
||||
return `
|
||||
## Official Codex platform payloads
|
||||
|
||||
The installed \`${CODEX_PACKAGE}\` wrapper ${distribution.wrapperVersion} declares the following optional-dependency aliases. Every alias resolves to an official platform-specific \`${CODEX_PACKAGE}\` version that carries the native Codex CLI and its bundled resources; the declared license is verified against the payload installed for the current host.
|
||||
|
||||
| Optional dependency alias | Published package | Version | Declared license |
|
||||
| --- | --- | --- | --- |
|
||||
${rows.join('\n')}
|
||||
`
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the complete notices document.
|
||||
* @returns the exact bytes `THIRD_PARTY_NOTICES.md` must hold.
|
||||
@@ -673,6 +788,9 @@ export function render(): string {
|
||||
)
|
||||
? collectClaudeDistribution()
|
||||
: undefined
|
||||
const codexDistribution = runtimeDeps.some(dep => dep.name === CODEX_PACKAGE)
|
||||
? collectCodexDistribution()
|
||||
: undefined
|
||||
|
||||
const nonPermissiveDev = devDeps.filter(dep => !isPermissive(dep.license))
|
||||
// A copyleft license reaching a shipped surface is a distribution decision,
|
||||
@@ -693,7 +811,7 @@ export function render(): string {
|
||||
|
||||
DeepSeek Harness is licensed under [MIT](LICENSE). It depends on the third-party software listed below. Each project remains under its own license; nothing in this file changes those terms.
|
||||
|
||||
This file lists **direct** dependencies declared by the workspace and the explicitly disclosed official Claude platform payload closure. It is generated from the workspace manifests by \`scripts/gen-third-party-notices.ts\`: a pre-commit hook regenerates it whenever a staged file changes one of its inputs, and \`scripts/gen-third-party-notices.spec.ts\` asserts in the test lane that the committed bytes match. Deleting a manifest runs no hook, so that case is caught by the assertion instead. Run \`pnpm run verify-third-party-notices\` for the standalone check.
|
||||
This file lists **direct** dependencies declared by the workspace and the explicitly disclosed official Claude Code and Codex platform payload closures. It is generated from the workspace manifests by \`scripts/gen-third-party-notices.ts\`: a pre-commit hook regenerates it whenever a staged file changes one of its inputs, and \`scripts/gen-third-party-notices.spec.ts\` asserts in the test lane that the committed bytes match. Deleting a manifest runs no hook, so that case is caught by the assertion instead. Run \`pnpm run verify-third-party-notices\` for the standalone check.
|
||||
|
||||
The complete npm transitive closure, including the Landlock launcher workspace, is recorded with exact pinned versions in [\`pnpm-lock.yaml\`](pnpm-lock.yaml) — inspect it with \`pnpm licenses list\`. The Python closure is recorded separately in [\`python/sdk/uv.lock\`](python/sdk/uv.lock).
|
||||
|
||||
@@ -715,6 +833,7 @@ pnpm applies local patches to the following packages at install time, so shipped
|
||||
|
||||
${patchedLines.join('\n')}
|
||||
${renderClaudeDistribution(claudeDistribution)}
|
||||
${renderCodexDistribution(codexDistribution)}
|
||||
|
||||
## Development-only npm dependencies
|
||||
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
* metadata field must stay static, and a disabled expression must parse.
|
||||
*/
|
||||
|
||||
import { globSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
bundleManifestPaths,
|
||||
@@ -15,36 +14,6 @@ import {
|
||||
metadataExpressionErrors,
|
||||
} from './verify-cordis-config.ts'
|
||||
|
||||
interface WorkspaceManifest {
|
||||
name?: string
|
||||
dependencies?: Record<string, string>
|
||||
optionalDependencies?: Record<string, string>
|
||||
peerDependencies?: Record<string, string>
|
||||
}
|
||||
|
||||
const repoRoot = fileURLToPath(new URL('..', import.meta.url))
|
||||
|
||||
function productionClosure(entry: string): Set<string> {
|
||||
const manifests = new Map<string, WorkspaceManifest>()
|
||||
for (const path of globSync(['apps/*/package.json', 'packages/*/*/package.json'], { cwd: repoRoot })) {
|
||||
const manifest = JSON.parse(readFileSync(join(repoRoot, path), 'utf8')) as WorkspaceManifest
|
||||
if (manifest.name !== undefined) manifests.set(manifest.name, manifest)
|
||||
}
|
||||
const visited = new Set<string>()
|
||||
const pending = [entry]
|
||||
for (let name = pending.pop(); name !== undefined; name = pending.pop()) {
|
||||
if (visited.has(name)) continue
|
||||
visited.add(name)
|
||||
const manifest = manifests.get(name)
|
||||
pending.push(
|
||||
...Object.keys(manifest?.dependencies ?? {}),
|
||||
...Object.keys(manifest?.optionalDependencies ?? {}),
|
||||
...Object.keys(manifest?.peerDependencies ?? {}),
|
||||
)
|
||||
}
|
||||
return visited
|
||||
}
|
||||
|
||||
describe('verify-cordis-config metadata expressions', () => {
|
||||
it('accepts a disabled !!js expression', () => {
|
||||
const problems = metadataExpressionErrors(
|
||||
@@ -116,15 +85,4 @@ describe('workspace Bundle discovery and product dependency closures', () => {
|
||||
`${file}: @deepseek-ai/dsh-missing-plugin must be declared in ${manifestPath} dependencies`,
|
||||
])
|
||||
})
|
||||
|
||||
it('keeps the default and optional Claude Code closure independent', () => {
|
||||
const shipped = productionClosure('@deepseek-ai/dsh')
|
||||
expect(shipped).not.toContain('@deepseek-ai/dsh-subagent-codex')
|
||||
expect(shipped).not.toContain('@deepseek-ai/dsh-subagent-claude-code')
|
||||
expect(shipped).not.toContain('@anthropic-ai/claude-agent-sdk')
|
||||
|
||||
const claudeCode = productionClosure('@deepseek-ai/dsh-subagent-claude-code')
|
||||
expect(claudeCode).toContain('@anthropic-ai/claude-agent-sdk')
|
||||
expect(claudeCode).not.toContain('@deepseek-ai/dsh-subagent-codex')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user