Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions infra/pdk/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ import { defineConfig } from '@rslib/core';
export default defineConfig({
source: {
entry: {
index: ['src/**/*.ts', '!src/**/*.{test,bench}.ts'],
index: 'src/index.ts',
},
},
lib: [
{
format: 'cjs',
syntax: 'es2021',
bundle: false,
bundle: true,
autoExternal: {
dependencies: false, // Enable bundling to include tiny-conventional-commits-parser
optionalDependencies: true,
peerDependencies: true,
},
dts: true,
},
],
Expand Down
10 changes: 5 additions & 5 deletions infra/pdk/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* CLI entry point for PTK
*/
import { cac } from 'cac';
import { dev, release, patch, changelog, githubRelease } from './index';
import { dev, release, patch, changelog, githubRelease } from './commands';
import { logger } from './utils/logger';

/**
Expand Down Expand Up @@ -121,9 +121,9 @@ export function bootstrapCli() {
.option('--baseURL, --base-url <baseURL>', 'Custom base URL for LLM')
.option(
'--filter-scopes <scopes>',
'Comma-separated list of scopes to include in changelog',
'Comma-separated list of scopes to include in changelog (empty for all)',
{
default: 'tars,agent,tarko,o-agent,tars-stack,browser,infra,mcp,all',
default: '',
},
)
.option(
Expand Down Expand Up @@ -227,9 +227,9 @@ export function bootstrapCli() {
.option('--baseURL, --base-url <baseURL>', 'Custom base URL for LLM')
.option(
'--filter-scopes <scopes>',
'Comma-separated list of scopes to include in changelog',
'Comma-separated list of scopes to include in changelog (empty for all)',
{
default: 'tars,agent,tarko,o-agent,tars-stack,browser,infra,mcp,all',
default: '',
},
)
.option(
Expand Down
35 changes: 28 additions & 7 deletions infra/pdk/src/commands/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
generateReleaseNotes,
getRepositoryInfo,
} from '../utils/github';
import { AIChangelogGenerator } from '../utils/ai-changelog';
import type { ModelProviderName } from '@tarko/model-provider';

import type { ChangelogOptions } from '../types';

Expand Down Expand Up @@ -93,13 +95,32 @@ export async function changelog(options: ChangelogOptions = {}): Promise<void> {
`📝 Generating unified changelog from ${previousTag || 'repository start'} to ${tagName}`,
);

// Generate GitHub-style release notes
const releaseNotes = await generateReleaseNotes(
tagName,
previousTag,
cwd,
repoInfo || undefined,
);
let releaseNotes: string;

if (options.useAi) {
const aiGenerator = new AIChangelogGenerator(cwd, tagPrefix, {
id: options.model || 'gpt-4o',
provider: options.provider as ModelProviderName,
// secretlint-disable-next-line @secretlint/secretlint-rule-pattern
apiKey: options.apiKey,
baseURL: options.baseURL,
});

releaseNotes = await aiGenerator.generate(
version,
previousTag,
options.filterScopes,
);
} else {
// Use traditional GitHub-style release notes
releaseNotes = await generateReleaseNotes(
tagName,
previousTag,
cwd,
repoInfo || undefined,
options.filterScopes,
);
}

// Compose final changelog entry with version header
const versionHeader = tagName.startsWith('v') ? tagName : `v${tagName}`;
Expand Down
10 changes: 10 additions & 0 deletions infra/pdk/src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
* SPDX-License-Identifier: Apache-2.0
*/

export * from './dev';
export * from './release';
export * from './patch';
export * from './changelog';
export * from './github-release';
13 changes: 3 additions & 10 deletions infra/pdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
/*
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
* SPDX-License-Identifier: Apache-2.0
*/

/**
* Main entry point for the PNPM Toolkit (PDK)
* Exports all public APIs
*/
export * from './commands/dev';
export * from './commands/release';
export * from './commands/patch';
export * from './commands/changelog';
export * from './commands/github-release';

export * from './commands';
export * from './cli';
20 changes: 18 additions & 2 deletions infra/pdk/src/utils/ai-changelog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { existsSync, readFileSync, writeFileSync } from 'fs';
import { execa } from 'execa';
import { logger } from './logger';
import { shouldIncludeCommitByScope } from './commit';
import { AgentModel } from '@tarko/model-provider';

interface CommitEntry {
Expand Down Expand Up @@ -51,6 +52,7 @@ export class AIChangelogGenerator {
private async getCommitsBetweenTags(
fromTag?: string,
toTag = 'HEAD',
filterScopes?: string[],
): Promise<CommitEntry[]> {
try {
const range = fromTag ? `${fromTag}..${toTag}` : toTag;
Expand Down Expand Up @@ -81,7 +83,7 @@ export class AIChangelogGenerator {
return [];
}

return stdout
const commits = stdout
.split('\n')
.filter(Boolean)
.map((line) => {
Expand All @@ -99,6 +101,15 @@ export class AIChangelogGenerator {
prNumber,
};
});

// Apply scope filter if provided
if (filterScopes && filterScopes.length > 0) {
return commits.filter((commit) =>
shouldIncludeCommitByScope(commit.message, filterScopes),
);
}

return commits;
} catch (error) {
logger.error(`Failed to get commits: ${(error as Error).message}`);
return [];
Expand Down Expand Up @@ -239,6 +250,7 @@ export class AIChangelogGenerator {
public async generate(
version: string,
previousTag?: string,
filterScopes?: string[],
): Promise<string> {
const currentTag = `${this.tagPrefix}${version}`;

Expand All @@ -259,7 +271,11 @@ export class AIChangelogGenerator {
`Generating changelog from ${previousTag || 'initial commit'} to ${currentTag}`,
);

const commits = await this.getCommitsBetweenTags(previousTag, currentTag);
const commits = await this.getCommitsBetweenTags(
previousTag,
currentTag,
filterScopes,
);
const changelogData = await this.generateChangelogWithAI(
commits,
version,
Expand Down
43 changes: 43 additions & 0 deletions infra/pdk/src/utils/commit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { parseCommit } from 'tiny-conventional-commits-parser';

/**
* Git commit utilities
*/

/**
* Check if a commit should be included based on scope filters
* @param commitMessage - The commit message to check
* @param filterScopes - Array of scopes to include (empty array means include all)
* @returns True if the commit should be included
*/
export function shouldIncludeCommitByScope(
commitMessage: string,
filterScopes?: string[],
): boolean {
// If no filter provided, include all commits
if (!filterScopes || filterScopes.length === 0) {
return true;
}

// Parse the commit using tiny-conventional-commits-parser
const rawCommit = {
message: commitMessage,
body: '',
shortHash: '',
author: { name: '', email: '' },
data: '',
};

try {
const parsedCommit = parseCommit(rawCommit);
const scope = parsedCommit.scope;

// Include if no scope or scope matches filter
return (
!scope || filterScopes.includes(scope) || filterScopes.includes('all')
);
} catch {
// If parsing fails, include the commit
return true;
}
}
8 changes: 8 additions & 0 deletions infra/pdk/src/utils/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
import { execa } from 'execa';
import { logger } from './logger';
import { shouldIncludeCommitByScope } from './commit';

// Username mapping for commit authors to correct GitHub usernames
const USERNAME_MAP: Record<string, string> = {
Expand Down Expand Up @@ -100,6 +101,7 @@ export async function generateReleaseNotes(
previousTag: string | null,
cwd: string,
repoInfo?: { owner: string; repo: string },
filterScopes?: string[],
): Promise<string> {
try {
// Get commits between tags
Expand Down Expand Up @@ -138,6 +140,12 @@ export async function generateReleaseNotes(
const match = commit.subject.match(/^(\w+)(\([^)]+\))?:\s*(.+)$/);
if (match) {
const [, type] = match;

// Apply scope filter if provided
if (!shouldIncludeCommitByScope(commit.subject, filterScopes)) {
return; // Skip this commit
}

if (type in groups) {
groups[type as keyof typeof groups].push(commit);
} else {
Expand Down
14 changes: 7 additions & 7 deletions multimodal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"test:watch": "vitest",
"coverage": "vitest run --coverage",
"format": "pnpm prettier --write .",
"release": "pdk release --push-tag --build --ignore-scripts --auto-create-release-branch",
"release:dryrun": "pdk release --push-tag --build --ignore-scripts --auto-create-release-branch --dry-run",
"release:canary": "pdk release --canary --push-tag --build --ignore-scripts --auto-create-release-branch",
"release:full": "pdk release --push-tag --build --ignore-scripts --create-github-release",
"release:ai": "pdk release --push-tag --build --ignore-scripts --use-ai --provider=azure-openai --model=aws_sdk_claude37_sonnet --baseURL=AWS_CLAUDE_API_BASE_URL",
"release:ai:full": "pdk release --push-tag --build --ignore-scripts --use-ai --provider=azure-openai --model=aws_sdk_claude37_sonnet --baseURL=AWS_CLAUDE_API_BASE_URL --create-github-release",
"release:ai:dryrun": "pdk release --push-tag --build --ignore-scripts --use-ai --provider=azure-openai --model=aws_sdk_claude37_sonnet --baseURL=AWS_CLAUDE_API_BASE_URL --dry-run",
"release": "pdk release --push-tag --build --ignore-scripts --auto-create-release-branch --filter-scopes=tars,agent,tarko,o-agent,tars-stack,browser,infra,mcp,all",
"release:dryrun": "pdk release --push-tag --build --ignore-scripts --auto-create-release-branch --filter-scopes=tars,agent,tarko,o-agent,tars-stack,browser,infra,mcp,all --dry-run",
"release:canary": "pdk release --canary --push-tag --build --ignore-scripts --auto-create-release-branch --filter-scopes=tars,agent,tarko,o-agent,tars-stack,browser,infra,mcp,all",
"release:full": "pdk release --push-tag --build --ignore-scripts --create-github-release --filter-scopes=tars,agent,tarko,o-agent,tars-stack,browser,infra,mcp,all",
"release:ai": "pdk release --push-tag --build --ignore-scripts --use-ai --provider=azure-openai --model=aws_sdk_claude37_sonnet --baseURL=AWS_CLAUDE_API_BASE_URL --filter-scopes=tars,agent,tarko,o-agent,tars-stack,browser,infra,mcp,all",
"release:ai:full": "pdk release --push-tag --build --ignore-scripts --use-ai --provider=azure-openai --model=aws_sdk_claude37_sonnet --baseURL=AWS_CLAUDE_API_BASE_URL --create-github-release --filter-scopes=tars,agent,tarko,o-agent,tars-stack,browser,infra,mcp,all",
"release:ai:dryrun": "pdk release --push-tag --build --ignore-scripts --use-ai --provider=azure-openai --model=aws_sdk_claude37_sonnet --baseURL=AWS_CLAUDE_API_BASE_URL --filter-scopes=tars,agent,tarko,o-agent,tars-stack,browser,infra,mcp,all --dry-run",
"github-release": "pdk github-release",
"github-release:dryrun": "pdk github-release --dry-run",
"changelog": "pdk changelog",
Expand Down
Loading