-
Notifications
You must be signed in to change notification settings - Fork 0
feat(config): support output.distPath for the artifact build root #296
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "agent-bundle": minor | ||
| --- | ||
|
|
||
| Agent Bundle config now supports `output.distPath` to relocate the build | ||
| artifact root (the default `dist` is unchanged); CLI `--output` still takes | ||
| precedence. Invalid values report `AB4707`–`AB4709`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { createHash } from 'node:crypto'; | ||
| import { existsSync, statSync } from 'node:fs'; | ||
| import { readFile, readdir, stat } from 'node:fs/promises'; | ||
| import { basename, dirname, extname, posix, relative, resolve, sep } from 'node:path'; | ||
| import { basename, dirname, extname, posix, relative, resolve, sep, win32 } from 'node:path'; | ||
|
|
||
| import { digest } from '../core/digest.ts'; | ||
| import { deepFreeze } from '../core/freeze.ts'; | ||
|
|
@@ -177,6 +177,51 @@ const safePackageOutputName = (name: string): boolean => | |
| */ | ||
| export const packageBuildOutputDir = 'dist'; | ||
|
|
||
| /** The default artifact output directory of `agent-bundle build`, relative to the project root. */ | ||
| export const defaultArtifactDistPath = 'dist'; | ||
|
|
||
| export type ArtifactDistPathIssue = 'path' | 'reserved' | 'shape'; | ||
|
|
||
| const reservedArtifactDistPathSegments = new Set([ | ||
| '.agent-bundle', | ||
| '.git', | ||
| 'node_modules', | ||
| 'src', | ||
| ]); | ||
|
|
||
| export const isArtifactOutputConfig = ( | ||
| value: unknown, | ||
| ): value is Readonly<Record<string, unknown>> => { | ||
| if (!isRecord(value)) return false; | ||
| const prototype = Object.getPrototypeOf(value); | ||
| return prototype === null || prototype === Object.prototype; | ||
| }; | ||
|
|
||
| /** Classifies one configured artifact output path without consulting the filesystem. */ | ||
| export const artifactDistPathIssue = (value: unknown): ArtifactDistPathIssue | undefined => { | ||
| if (typeof value !== 'string' || value.length === 0) return 'shape'; | ||
| if (posix.isAbsolute(value) || win32.isAbsolute(value) || value.includes('\\')) return 'path'; | ||
| const segments = value.split('/'); | ||
| if (segments.some((segment) => segment.length === 0 || segment === '.' || segment === '..')) { | ||
| return 'path'; | ||
| } | ||
| return reservedArtifactDistPathSegments.has(segments[0]!) ? 'reserved' : undefined; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On case-insensitive filesystems, including Windows and typical macOS installations, values such as Useful? React with 👍 / 👎.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in a45992e: |
||
| }; | ||
|
|
||
| /** Returns the validated config path, falling back so downstream path resolution cannot throw on malformed input. */ | ||
| export const configuredArtifactDistPath = (config: AgentBundleConfig): string => { | ||
| try { | ||
| const output = config.output as unknown; | ||
| if (!isArtifactOutputConfig(output)) return defaultArtifactDistPath; | ||
| const distPath = output.distPath; | ||
| return artifactDistPathIssue(distPath) === undefined | ||
| ? distPath as string | ||
| : defaultArtifactDistPath; | ||
| } catch { | ||
| return defaultArtifactDistPath; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * The framework-generated routed-CLI bin (#102 stage 2): a generated-mode | ||
| * `src/cli/**` surface with at least one compiled command becomes one | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a user follows this new guidance and passes an absolute path outside the project,
build()includes that path inProjectService.outputRoots, whoseresolveOutputRootsrejects anything outside the project root and returnsAB7002before the artifact build runs. Therefore the CLI cannot currently serve as the documented escape hatch for absolute output locations; either allow external CLI output roots during preparation or remove this promise (which also appears inAgentBundleOutputConfig).Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in
3c2240169. The framework docs andAgentBundleOutputConfigTSDoc now state that--outputonly overrides the relative artifact root and remains subject to project-root containment; rejection behavior is unchanged.