-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(agent-core-v2): enable tower through experimental flag, with registration wiring guard #3050
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d0631b6
feat(agent-core-v2): enable tower through experimental flag
sailist 5d6ee41
test(agent-core-v2): guard experimental flag registration wiring
bj456736 c6356cb
chore(changesets): add changeset for the tower experimental flag
bj456736 2868bfa
test(agent-core-v2): drop forbidden comments and treat type-only spec…
bj456736 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,5 @@ | ||
| --- | ||
| "@moonshot-ai/kimi-code": patch | ||
| --- | ||
|
|
||
| Gate Tower multi-agent orchestration behind an experimental flag: it is off by default, opt in with `KIMI_CODE_EXPERIMENTAL_TOWER=1` or by setting `tower = true` in the `[experimental]` config section. |
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,16 @@ | ||
| import { type FlagDefinitionInput, registerFlagDefinition } from '#/app/flag/flagRegistry'; | ||
|
|
||
| import { TOWER_FLAG_ID } from './tower'; | ||
|
|
||
| export const TOWER_FLAG_ENV = 'KIMI_CODE_EXPERIMENTAL_TOWER'; | ||
|
|
||
| export const towerFlag: FlagDefinitionInput = { | ||
| id: TOWER_FLAG_ID, | ||
| title: 'Tower multi-agent orchestration', | ||
| description: 'Coordinate parallel worker agents through Tower tools and the tower mode.', | ||
| env: TOWER_FLAG_ENV, | ||
| default: false, | ||
| surface: 'core', | ||
| }; | ||
|
|
||
| registerFlagDefinition(towerFlag); |
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
114 changes: 114 additions & 0 deletions
114
packages/agent-core-v2/test/app/flag/flagWiring.test.ts
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,114 @@ | ||
| import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'; | ||
| import { dirname, join, relative, resolve } from 'node:path'; | ||
|
|
||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| const sourceRoot = join(import.meta.dirname, '../../../src'); | ||
| const packageEntry = join(sourceRoot, 'index.ts'); | ||
| const flagRegistryModule = join(sourceRoot, 'app/flag/flagRegistry.ts'); | ||
|
|
||
| const RUNTIME_EDGE = | ||
| /(?:^|\n)\s*(?:import\s+(?!type[\s{])[^'"]*?from\s+|import\s+|export\s+(?!type[\s{])[^'"]*?from\s+)['"]([^'"]+)['"]/g; | ||
| const REGISTRATION_CALL = /\bregisterFlagDefinition\s*\(/; | ||
| const FLAG_ID_CONSTANT = /export\s+const\s+([A-Z0-9_]+_FLAG_ID)\s*=\s*['"]([^'"]+)['"]/g; | ||
|
|
||
| function keepsRuntimeSideEffects(statement: string): boolean { | ||
| const open = statement.indexOf('{'); | ||
| if (open === -1) return true; | ||
| const inner = statement.slice(open + 1, statement.lastIndexOf('}')); | ||
| return inner | ||
| .split(',') | ||
| .map((part) => part.trim()) | ||
| .filter(Boolean) | ||
| .some((part) => !part.startsWith('type ')); | ||
| } | ||
|
|
||
| function listTypeScriptFiles(root: string): string[] { | ||
| const result: string[] = []; | ||
| const visit = (directory: string): void => { | ||
| for (const entry of readdirSync(directory, { withFileTypes: true })) { | ||
| const absolute = join(directory, entry.name); | ||
| if (entry.isDirectory()) visit(absolute); | ||
| else if (entry.name.endsWith('.ts')) result.push(absolute); | ||
| } | ||
| }; | ||
| visit(root); | ||
| return result; | ||
| } | ||
|
|
||
| function resolveSpecifier(fromFile: string, specifier: string): string | undefined { | ||
| let base: string; | ||
| if (specifier.startsWith('#/')) base = join(sourceRoot, specifier.slice(2)); | ||
| else if (specifier.startsWith('.')) base = resolve(dirname(fromFile), specifier); | ||
| else return undefined; | ||
| const candidates = specifier.endsWith('.js') | ||
| ? [base.replace(/\.js$/, '.ts'), base.replace(/\.js$/, '.tsx')] | ||
| : [base, `${base}.ts`, `${base}.tsx`, join(base, 'index.ts'), join(base, 'index.tsx')]; | ||
| for (const candidate of candidates) { | ||
| if (existsSync(candidate) && statSync(candidate).isFile()) return candidate; | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| function collectModulesReachableFromEntry(): Set<string> { | ||
| const reachable = new Set<string>(); | ||
| const queue = [packageEntry]; | ||
| while (queue.length > 0) { | ||
| const file = queue.pop()!; | ||
| if (reachable.has(file)) continue; | ||
| reachable.add(file); | ||
| const content = readFileSync(file, 'utf8').replaceAll(/\/\*[\s\S]*?\*\//g, ' '); | ||
| for (const match of content.matchAll(RUNTIME_EDGE)) { | ||
| if (!keepsRuntimeSideEffects(match[0])) continue; | ||
| const resolved = resolveSpecifier(file, match[1]!); | ||
| if (resolved && !reachable.has(resolved)) queue.push(resolved); | ||
| } | ||
| } | ||
| return reachable; | ||
| } | ||
|
|
||
| function findRegistrationModules(): string[] { | ||
| return listTypeScriptFiles(sourceRoot) | ||
| .filter((file) => file !== flagRegistryModule) | ||
| .filter((file) => REGISTRATION_CALL.test(readFileSync(file, 'utf8'))); | ||
| } | ||
|
|
||
| describe('experimental flag wiring', () => { | ||
| it('loads every module that registers a flag definition from the package entry', () => { | ||
| const reachable = collectModulesReachableFromEntry(); | ||
| const unwired = findRegistrationModules() | ||
| .filter((file) => !reachable.has(file)) | ||
| .map((file) => relative(sourceRoot, file)); | ||
| expect( | ||
| unwired, | ||
| 'these modules call registerFlagDefinition but are not reachable from src/index.ts, ' + | ||
| 'so their flags never get registered and every gate on them silently stays off. ' + | ||
| "Import each module for its side effects from the package entry (see how src/index.ts imports '#/…/flag').", | ||
| ).toEqual([]); | ||
| }); | ||
|
|
||
| it('registers every exported *_FLAG_ID constant', () => { | ||
| const registrationModules = findRegistrationModules(); | ||
| const registrationSource = registrationModules | ||
| .map((file) => readFileSync(file, 'utf8')) | ||
| .join('\n'); | ||
| const unregistered: string[] = []; | ||
| for (const file of listTypeScriptFiles(sourceRoot)) { | ||
| if (registrationModules.includes(file)) continue; | ||
| const content = readFileSync(file, 'utf8'); | ||
| for (const match of content.matchAll(FLAG_ID_CONSTANT)) { | ||
| const name = match[1]!; | ||
| const id = match[2]!; | ||
| if (!new RegExp(`\\b${name}\\b`).test(registrationSource)) { | ||
| unregistered.push(`${name} ('${id}') in ${relative(sourceRoot, file)}`); | ||
| } | ||
| } | ||
| } | ||
| expect( | ||
| unregistered, | ||
| 'these exported flag id constants are never referenced by a module calling registerFlagDefinition, ' + | ||
| 'so gates evaluating them silently stay off. ' + | ||
| 'Register each flag in a flag module wired into the package entry (see src/features/tower/flag.ts).', | ||
| ).toEqual([]); | ||
| }); | ||
| }); | ||
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.
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.