Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a983ece
refactor(cli): enforce utils leaf-layer dependency direction (#9146)
yiliang114 Aug 22, 2026
7735a3b
fix: use Qwen Team 2026 license header on new files (#9146)
yiliang114 Aug 22, 2026
204b3c3
chore: refresh stale utils/ path references after leaf-layer move (#9…
yiliang114 Aug 22, 2026
21d21a0
Merge remote-tracking branch 'origin/main' into codex/9146-utils-leaf…
yiliang114 Aug 22, 2026
a81cbe7
docs: reconcile no-utils-upward-import header with the allowed type-o…
yiliang114 Aug 22, 2026
beab2dc
fix(cli): allowlist sandbox process.env accesses after leaf-layer mov…
yiliang114 Aug 22, 2026
1e48458
chore(ci): re-record qwen-autofix.yml size baseline after #9677 (#9146)
yiliang114 Aug 22, 2026
0566edc
fix(review): drop the stale utils/findings.ts digest root after the l…
yiliang114 Aug 22, 2026
0dca7b0
fix(review): colocate seatbelt profiles with the sandbox module (#9146)
yiliang114 Aug 22, 2026
25670ab
fix(review): exempt inline type-only specifiers from the utils upward…
yiliang114 Aug 22, 2026
21cfacf
fix(review): report upward inline type-specifier imports under verbat…
yiliang114 Aug 22, 2026
6980025
test(review): pin mixed-specifier and zero-specifier upward imports i…
yiliang114 Aug 22, 2026
bf6b9ba
test(review): anchor the nested-checkout utils rule fixture on the la…
yiliang114 Aug 22, 2026
8071456
test(review): pin that the utils/findings.ts digest root stays remove…
yiliang114 Aug 22, 2026
256abb1
Merge remote-tracking branch 'origin/main' into codex/9146-utils-leaf…
yiliang114 Aug 23, 2026
1b870e2
fix(review): reword stale-bundle SCOPE header to the post-move helper…
yiliang114 Aug 23, 2026
ab039d6
test(review): drop the pre-move utils/findings.ts from the skill-pari…
yiliang114 Aug 23, 2026
25687c4
test(serve): derive the seatbelt colocation tripwire from BUILTIN_SEA…
yiliang114 Aug 23, 2026
764d603
fix(architecture): fail closed on computed dynamic imports in the uti…
yiliang114 Aug 23, 2026
98f0134
fix(cli): point settings.test.ts at the post-move settingsUtils path …
yiliang114 Aug 23, 2026
e81731f
fix(cli): close utils boundary review gaps
yiliang114 Aug 23, 2026
85320da
Merge remote-tracking branch 'origin/main' into codex/pr-9737-closeou…
yiliang114 Aug 23, 2026
1445a76
test(cli): cover utils boundary allow paths
yiliang114 Aug 23, 2026
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
2 changes: 1 addition & 1 deletion .github/workflows/.size-baseline
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
6495 pr-self-report-label.yml
9646 qwen-autofix-fork-bridge.yml
5942 qwen-autofix-fork-signal.yml
392111 qwen-autofix.yml
397656 qwen-autofix.yml
7061 qwen-ci-flaky-rerun.yml
151937 qwen-code-pr-review.yml
79041 qwen-fleet-shepherd.yml
Expand Down
117 changes: 117 additions & 0 deletions eslint-rules/no-utils-upward-import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* @license
* Copyright 2026 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/

import path from 'node:path';

/**
* `packages/cli/src/utils/` is the leaf layer that every other directory
* imports. It must not import back up into a domain directory (`config/`,
* `ui/`, `i18n/`, `nonInteractive/`, `commands/`, `serve/`,
* `acp-integration/`, ...): that is the dependency-direction invariant
* tracked in #9146.
*
* The only permitted "upward" references are type-only constructs:
* `import type`, `export type ... from`, and TS `import('...').T` type
* queries. All of them are erased at compile time, so they cannot create a
* runtime module cycle; everything else (value imports, value re-exports,
* literal/template dynamic `import()`) is reported. The two remaining
* instances (`Settings` in `modelConfigUtils.ts`, `CommandContext` in
* `sessionPaths.ts`) are this irreducible type-level coupling.
*/

const CLI_UTILS_MARKER = 'packages/cli/src/utils/';
const TEST_OR_FIXTURE_SEGMENTS = new Set(['__tests__', 'fixtures']);

function isCliUtilsProductionFile(filename) {
if (!filename || filename === '<input>' || filename === '<text>') {
return false;
}
const normalized = path.normalize(filename).replaceAll('\\', '/');
const start = normalized.lastIndexOf(CLI_UTILS_MARKER);
if (start < 0) {
return false;
}
const relativePath = normalized.slice(start + CLI_UTILS_MARKER.length);
if (/\.(test|spec)\.[cm]?[jt]sx?$/.test(relativePath)) {
return false;
}
return !relativePath.split('/').some((s) => TEST_OR_FIXTURE_SEGMENTS.has(s));
}

function escapesUtils(filename, importedPath) {
const normalized = path.normalize(filename).replaceAll('\\', '/');
const utilsRoot = normalized.slice(
0,
normalized.lastIndexOf(CLI_UTILS_MARKER) + CLI_UTILS_MARKER.length,
);
const resolved = path.resolve(path.dirname(filename), importedPath);
return path
.relative(utilsRoot, resolved)
.replaceAll('\\', '/')
.startsWith('..');
}

export default {
meta: {
type: 'problem',
docs: {
description:
'packages/cli/src/utils must not import outside utils/ (leaf-layer dependency direction).',
},
messages: {
noUtilsUpwardImport:
'packages/cli/src/utils must not import outside utils/. ' +
'Invert the dependency (pass the value in) or move the module to the ' +
'domain directory that owns it (#9146).',
},
},
create(context) {
const { filename } = context;
if (!isCliUtilsProductionFile(filename)) {
return {};
}

const reportIfEscaping = (sourceNode, importedPath) => {
if (
typeof importedPath === 'string' &&
importedPath.startsWith('.') &&
escapesUtils(filename, importedPath)
) {
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
context.report({ node: sourceNode, messageId: 'noUtilsUpwardImport' });
}
};

const checkStatic = (node) => {
// Type-only imports (`import type`, `export type ... from`) are erased at
// compile time and cannot create a runtime cycle.
if (node.importKind === 'type' || node.exportKind === 'type') {
return;
}
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
reportIfEscaping(node.source, node.source?.value);
};

const checkDynamic = (node) => {
const { source } = node;
if (source.type === 'Literal') {
reportIfEscaping(source, source.value);
} else if (
source.type === 'TemplateLiteral' &&
source.quasis.length === 1
) {
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
reportIfEscaping(source, source.quasis[0].value.cooked);
}
};

return {
ImportDeclaration: checkStatic,
ExportNamedDeclaration: checkStatic,
ExportAllDeclaration: checkStatic,
ImportExpression: checkDynamic,
// TSImportType (`import('../config/x').T`) is type-only by definition, so
// it is intentionally not reported.
};
},
};
29 changes: 13 additions & 16 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import globals from 'globals';
import storybook from 'eslint-plugin-storybook';
import checkFile from 'eslint-plugin-check-file';
import noCoreRootBarrelImport from './eslint-rules/no-core-root-barrel-import.js';
import noUtilsUpwardImport from './eslint-rules/no-utils-upward-import.js';
import { legacyFilenames } from './eslint.legacy-filenames.mjs';

// General syntax restrictions applied to every TS/TSX source file. Hoisted so
Expand Down Expand Up @@ -109,24 +110,20 @@ export default tseslint.config(
},
},
{
// `utils/` is the layer every other directory imports, so it must not
// import back into one. The daemon direction is clean and enforced here;
// the remaining `ui/`, `config/`, `i18n/` and `nonInteractive/` edges are
// tracked in #9146 and will be added to this group as they are resolved.
// `utils/` is the leaf layer that every other directory imports, so it
// must not import back up into a domain directory. Type-only imports are
// exempt: they are erased at compile time and cannot create a runtime
// cycle. See #9146.
files: ['packages/cli/src/utils/**/*.{ts,tsx}'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['**/serve/*', '**/serve/**'],
message:
'packages/cli/src/utils must not import serve/. Move lifecycle-free logic down into utils/ instead (#9146).',
},
],
plugins: {
architecture: {
rules: {
'no-utils-upward-import': noUtilsUpwardImport,
},
],
},
},
rules: {
'architecture/no-utils-upward-import': 'error',
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion packages/acp-bridge/src/workspacePaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const WINDOWS_ABSOLUTE_PATH_RE = /^([A-Za-z]):[\\/](.*)$/;
/**
* Maps a Windows-shaped absolute path to the container mount produced by the
* host-side sandbox launcher (`C:\work\proj` → `/c/work/proj`, mirroring
* `getContainerPath` in `cli/src/utils/sandbox.ts`).
* `getContainerPath` in `cli/src/serve/sandbox.ts`).
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
*
* A Windows host relaunching `qwen serve` into a Linux Docker/Podman sandbox
* translates the bind mount and `--workdir`, but path-valued CLI arguments
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/acp-integration/acpAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const { mockMcpPoolDrainAll } = vi.hoisted(() => ({
vi.mock('../utils/cleanup.js', () => ({
runExitCleanup: mockRunExitCleanup,
}));
vi.mock('../utils/housekeeping/scheduler.js', () => ({
vi.mock('../services/housekeeping/scheduler.js', () => ({
startNonInteractiveOpenAILogHousekeeping:
mockStartNonInteractiveOpenAILogHousekeeping,
}));
Expand Down Expand Up @@ -872,7 +872,7 @@ vi.mock('./session/Session.js', () => {
}),
};
});
vi.mock('../utils/languageUtils.js', () => ({
vi.mock('../i18n/languageUtils.js', () => ({
updateOutputLanguageFile: vi.fn(),
writeOutputLanguageAndRegisterPath: vi.fn(
(
Expand Down Expand Up @@ -994,7 +994,7 @@ import {
resolveOutputLanguageOrPreserveAuto,
updateOutputLanguageFile,
writeOutputLanguageAndRegisterPath,
} from '../utils/languageUtils.js';
} from '../i18n/languageUtils.js';
import { buildAuthMethods } from './authMethods.js';
import {
ACTIVE_WORK_HEARTBEAT_META_KEY,
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/acp-integration/acpAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ import {
ACP_EVENT_LOOP_STALL_RESTART_MS,
CHANNEL_PROMPT_META_KEY,
} from '@qwen-code/channel-base';
import { observeAcpToolResultWire } from '../utils/tool-result-boundary-diagnostics.js';
import { observeAcpToolResultWire } from '../nonInteractive/tool-result-boundary-diagnostics.js';
import { Readable, Writable } from 'node:stream';
import { normalizeDisabledToolList } from '../config/normalizeDisabledTools.js';
import { pipeline } from 'node:stream/promises';
Expand Down Expand Up @@ -278,11 +278,11 @@ import {
resolveOutputLanguageOrPreserveAuto,
getOutputLanguageFilePath,
writeOutputLanguageAndRegisterPath,
} from '../utils/languageUtils.js';
} from '../i18n/languageUtils.js';
import { runWithAcpRuntimeOutputDir } from './runtimeOutputDirContext.js';
import { ACP_ERROR_CODES } from './errorCodes.js';
import { runExitCleanup } from '../utils/cleanup.js';
import { startNonInteractiveOpenAILogHousekeeping } from '../utils/housekeeping/scheduler.js';
import { startNonInteractiveOpenAILogHousekeeping } from '../services/housekeeping/scheduler.js';
import { appEvents, AppEvent } from '../utils/events.js';
import {
setLanguageAsync,
Expand Down
8 changes: 3 additions & 5 deletions packages/cli/src/acp-integration/session/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,8 @@ import type {
AgentSideConnection,
} from '@agentclientprotocol/sdk';
import { SettingScope, type LoadedSettings } from '../../config/settings.js';
import {
insertAfterFunctionResponses,
normalizePartList,
} from '../../utils/nonInteractiveHelpers.js';
import { insertAfterFunctionResponses } from '../../nonInteractive/nonInteractiveHelpers.js';
import { normalizePartList } from '../../utils/normalize-part-list.js';
import { prefixMidTurnUserMessageParts } from '../../utils/midTurnUserMessage.js';
import {
handleSlashCommand,
Expand Down Expand Up @@ -320,7 +318,7 @@ import type {
} from './types.js';
import { HistoryReplayer } from './history-replayer.js';
import { projectAcpToolResultUpdate } from './acp-tool-result-text-projection.js';
import { observeAcpToolResultProjection } from '../../utils/tool-result-boundary-diagnostics.js';
import { observeAcpToolResultProjection } from '../../nonInteractive/tool-result-boundary-diagnostics.js';
import { ToolCallEmitter } from './emitters/tool-call-emitter.js';
import { ToolCallPreparationTracker } from './tool-call-preparation-tracker.js';
import { PlanEmitter } from './emitters/PlanEmitter.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
createTranscriptToolCallStartUpdate,
} from '@qwen-code/acp-bridge/transcriptReplay';
import { sanitizeTerminalText } from '../../../ui/utils/textUtils.js';
import { associateAcpToolResultArtifact } from '../../../utils/tool-result-boundary-diagnostics.js';
import { associateAcpToolResultArtifact } from '../../../nonInteractive/tool-result-boundary-diagnostics.js';

const KIND_MAP: Record<Kind, ToolKind> = {
[Kind.Read]: 'read',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import {

const observeAcpProjectionMock = vi.hoisted(() => vi.fn());
vi.mock(
'../../utils/tool-result-boundary-diagnostics.js',
'../../nonInteractive/tool-result-boundary-diagnostics.js',
async (original) => ({
...(await original<
typeof import('../../utils/tool-result-boundary-diagnostics.js')
typeof import('../../nonInteractive/tool-result-boundary-diagnostics.js')
>()),
observeAcpToolResultProjection: observeAcpProjectionMock,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { SessionUpdate } from '@agentclientprotocol/sdk';
import type { TranscriptReplayStateV1 } from '@qwen-code/acp-bridge/transcriptReplay';
import { Buffer } from 'node:buffer';
import { projectAcpToolResultUpdate } from './acp-tool-result-text-projection.js';
import { observeAcpToolResultProjection } from '../../utils/tool-result-boundary-diagnostics.js';
import { observeAcpToolResultProjection } from '../../nonInteractive/tool-result-boundary-diagnostics.js';
import { HistoryReplayer } from './history-replayer.js';
import type { PendingReplayToolCall } from './history-replayer.js';
import type { CumulativeUsage, SessionEmitterContext } from './types.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { Argv, CommandModule } from 'yargs';
import { parseArgsCommand } from './review/parse-args.js';
import { matchRemoteCommand } from './review/match-remote.js';
import { composeReviewCommand } from './review/compose-review.js';
import { findingsCommand } from '../utils/findings.js';
import { findingsCommand } from './review/findings.js';
import { recoverFindingsCommand } from './review/recover-findings.js';
import { fetchPrCommand } from './review/fetch-pr.js';
import { captureLocalCommand } from './review/capture-local.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/review/compose-review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
SOURCES,
type Severity,
type Source,
} from '../../utils/findings.js';
} from './findings.js';
import { BRIEFS } from './lib/agent-briefs.js';
import {
budgetStopDisclosure,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ import {
} from 'node:fs';
import type { Stats } from 'node:fs';
import { dirname, resolve, sep } from 'node:path';
import { writeStdoutLine, writeStderrLine } from './stdioHelpers.js';
import type { AnchorRequest } from '../commands/review/lib/anchors.js';
import { isSameFile } from '../commands/review/lib/same-file.js';
import { writeStdoutLine, writeStderrLine } from '../../utils/stdioHelpers.js';
import type { AnchorRequest } from './lib/anchors.js';
import { isSameFile } from './lib/same-file.js';

// These four lists have a second consumer: the Web Shell review renderer
// (packages/web-shell/client/components/artifacts/CodeReviewArtifactDetail.tsx)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/review/lib/certification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('openedBrief / readBrief', () => {
const arg = `{"absolute_path":${needle}}`;

it('does not credit a shell command that merely MENTIONS the brief', () => {
// The trap a prose matcher walks into: `utils/findings.ts` has a
// The trap a prose matcher walks into: `findings.ts` has a
// same-purpose-looking `namesPath` that matches on a name boundary, and
// it credits this arg. Deleting a brief is not opening it — so this atom
// matches the whole JSON string value instead, and keeps a different
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/review/lib/certification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function declaresOwnUncoverable(
* not one per half. This wrapper only spreads it over a record's call list;
* every path atom below routes through it.
*
* The name is deliberately not `namesPath`: `utils/findings.ts` has a
* The name is deliberately not `namesPath`: `findings.ts` has a
* module-private `namesPath` that matches a path named in PROSE on a name
* boundary — it credits `rm /plan/chunk-3.brief.md` for naming the brief.
* Unifying these two would make `openedBrief` credit an agent for deleting a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ vi.mock('../../../config/settings.js', async (importOriginal) => {
return { ...actual, loadSettings: loadSettingsMock };
});
import { operatorReviewSettings } from './review-settings.js';
import { getDialogSettingKeys } from '../../../utils/settingsUtils.js';
import { getDialogSettingKeys } from '../../../config/settingsUtils.js';

function setReview(review: unknown): void {
loadSettingsMock.mockReturnValue({ merged: { review } });
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/review/lib/shell-quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* plain `'…'` wrap traded that for breaking on the first embedded apostrophe
* (`~/Documents/John's Projects/…` is an ordinary macOS workspace). The
* `'\''` dance closes both: end the quote, emit a literal `'`, reopen.
* Same pattern as `shellQuoteForSh` in utils/standalone-update.ts.
* Same pattern as `shellQuoteForSh` in ui/standalone-update.ts.
*/
export function shellQuotePath(p: string): string {
return `'${p.replace(/'/g, "'\\''")}'`;
Expand Down
9 changes: 3 additions & 6 deletions packages/cli/src/commands/review/lib/stale-bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,12 +586,9 @@ describe('reviewSourceRoots', () => {
),
kind: 'code',
},
// The review helpers lifted out of `commands/review/`; the digest
// covered them there before the lift.
{
path: join('/w', 'packages', 'cli', 'src', 'utils', 'findings.ts'),
kind: 'code',
},
// The helpers of the findings validator live in `utils/`, outside the
// `review/` directory root; the validator itself lives back under
// `commands/review/` (#9146), which the directory root covers.
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
{
path: join('/w', 'packages', 'cli', 'src', 'utils', 'shell-args.ts'),
kind: 'code',
Expand Down
13 changes: 5 additions & 8 deletions packages/cli/src/commands/review/lib/stale-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,11 @@ export function reviewSourceRoots(repoRoot: string): ReviewSourceRoot[] {
),
kind: 'code',
},
// The findings validator and its two helpers were lifted out of
// `commands/review/` into `utils/`; the digest covered them there, and a
// root list that lost them would keep both digest copies equal while a
// skipped rebuild silently runs the bundle's old validator.
{
path: join(repoRoot, 'packages', 'cli', 'src', 'utils', 'findings.ts'),
kind: 'code',
},
// The two helpers of the findings validator live in `utils/`, outside
// the `review/` directory root; a root list that lost them would keep
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
// both digest copies equal while a skipped rebuild silently runs the
// bundle's old validator. The validator itself moved back into
// `commands/review/` (#9146), which the directory root covers.
{
path: join(repoRoot, 'packages', 'cli', 'src', 'utils', 'shell-args.ts'),
kind: 'code',
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/review/lib/transcripts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ describe('serializedArgsNamePath — the one needle both halves use', () => {

it('does not credit a shell command that merely mentions the path', () => {
// The divergence the review measured between this and the prose-boundary
// `namesPath` in `utils/findings.ts`, which returns true here. Both the
// `namesPath` in `findings.ts`, which returns true here. Both the
// diff-read half and the brief atoms route through THIS one, so the
// certification bar cannot credit `rm <file>` as opening it.
expect(
Expand Down
Loading
Loading