mirror of
https://github.com/anthropics/claude-code.git
synced 2026-10-02 05:25:05 +08:00
mods: revert two changes (agents-md truncated reads, diff forced colors) (#98018)
* Revert "agents-md: the truncated-read tests laid out as the formatter lays them" * Revert "fix(agents-md): retain instructions after truncated reads" * Revert "diff: the shared diff arguments' doc says what --no-color pins" * Revert "fix(diff): preserve hunks when Git forces colored output"
This commit is contained in:
@@ -223,14 +223,7 @@ export function register(on: On, options: PluginOptions): void {
|
||||
...Files.filesOf(claude),
|
||||
]).filter(file => !sent.has(file.path))
|
||||
const attached = fresh.filter(file => !Frames.isFileAt(file, read))
|
||||
const output = result.result
|
||||
const isPartialText =
|
||||
output?.type === 'text' &&
|
||||
(output.file.truncatedByTokenCap ||
|
||||
output.file.startLine !== 1 ||
|
||||
output.file.numLines < output.file.totalLines)
|
||||
const isWholeRead =
|
||||
e.offset === undefined && e.limit === undefined && !isPartialText
|
||||
const isWholeRead = e.offset === undefined && e.limit === undefined
|
||||
|
||||
for (const file of fresh) {
|
||||
const isSent =
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, mock, test, tier } from 'claude-code/testing'
|
||||
import { describe, expect, test, tier } from 'claude-code/testing'
|
||||
|
||||
import Hooks from '../hooks'
|
||||
import Fixtures from './fixtures'
|
||||
@@ -84,79 +84,6 @@ describe('register', () => {
|
||||
).toEqual({ blocks: BLOCKS, instructionFiles: [] })
|
||||
})
|
||||
|
||||
for (const [name, args, file, attaches] of [
|
||||
[
|
||||
'an auto-paginated read',
|
||||
{},
|
||||
{ content: '# head\nfollow', truncatedByTokenCap: true },
|
||||
true,
|
||||
],
|
||||
['an incomplete line range', {}, { content: '# head', numLines: 1 }, true],
|
||||
['a complete read', {}, {}, false],
|
||||
[
|
||||
'an explicit limit',
|
||||
{ limit: 1 },
|
||||
{ content: '# head', numLines: 1 },
|
||||
true,
|
||||
],
|
||||
[
|
||||
'an explicit offset',
|
||||
{ offset: 2 },
|
||||
{ content: 'follow the tail rule', numLines: 1, startLine: 2 },
|
||||
true,
|
||||
],
|
||||
['an unstructured result', {}, undefined, false],
|
||||
] as const) {
|
||||
test(`a nested AGENTS.md after ${name}`, async ($, on) => {
|
||||
const dir = `${Fixtures.SESSION.cwd}/nested`
|
||||
const path = `${dir}/AGENTS.md`
|
||||
const content = '# head\nfollow the tail rule'
|
||||
const started = Fixtures.projectOf(
|
||||
on,
|
||||
[Fixtures.ancestorOf(dir, 'AGENTS.md', content)],
|
||||
[],
|
||||
)
|
||||
|
||||
mock.env(on, {})
|
||||
on('session.cwd', () => ({ value: Fixtures.SESSION.cwd }))
|
||||
on('tool.call', ($, e) => ({
|
||||
result:
|
||||
e.tool === 'Read' && file !== undefined
|
||||
? {
|
||||
type: 'text',
|
||||
file: Object.assign(
|
||||
{
|
||||
filePath: e.file_path,
|
||||
content,
|
||||
numLines: 2,
|
||||
startLine: 1,
|
||||
totalLines: 2,
|
||||
},
|
||||
file,
|
||||
),
|
||||
}
|
||||
: 'read',
|
||||
}))
|
||||
|
||||
const direct = await $.tool.call({
|
||||
tool: 'Read',
|
||||
file_path: path,
|
||||
...args,
|
||||
})
|
||||
const source = { tool: 'Read', file_path: `${dir}/source.ts` } as const
|
||||
const after = await $.tool.call(source)
|
||||
const repeated = await $.tool.call(source)
|
||||
|
||||
expect(direct.context).toBeUndefined()
|
||||
expect(after.context).toEqual(
|
||||
attaches ? [`Contents of ${path}:\n\n${content}`] : undefined,
|
||||
)
|
||||
expect(repeated.context).toBeUndefined()
|
||||
|
||||
await started.clock.settle()
|
||||
})
|
||||
}
|
||||
|
||||
test(
|
||||
'the start sends the mode row alone: no walk, no toast',
|
||||
{ plugins: [Fixtures.RECORDING] },
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
*
|
||||
* Root-relative paths whatever `diff.relative` says, non-ASCII paths as
|
||||
* their own bytes, no optional locks, no child `git status` in a dirty
|
||||
* submodule, no external diff or textconv driver even on a stats pass, and
|
||||
* no color escapes whatever `color.ui` or `color.diff` says, so a hunk
|
||||
* header parses where either is set to `always`.
|
||||
* submodule, and no external diff or textconv driver even on a stats pass.
|
||||
*/
|
||||
export const DIFF_LEADING_ARGS = [
|
||||
'--no-optional-locks',
|
||||
@@ -15,7 +13,6 @@ export const DIFF_LEADING_ARGS = [
|
||||
'-c',
|
||||
'core.quotePath=false',
|
||||
'diff',
|
||||
'--no-color',
|
||||
'--no-ext-diff',
|
||||
'--no-textconv',
|
||||
'--ignore-submodules=dirty',
|
||||
|
||||
@@ -148,42 +148,6 @@ describe('fetch-diff', () => {
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
test("forced git colors do not hide a changed file's hunks", async () => {
|
||||
const deps = depsOf({
|
||||
'HEAD --shortstat': Fixtures.ok(
|
||||
' 1 file changed, 1 insertion(+), 1 deletion(-)',
|
||||
),
|
||||
'HEAD --numstat': Fixtures.ok('1\t1\ta.ts\0'),
|
||||
'ls-files': Fixtures.ok(),
|
||||
})
|
||||
|
||||
const git = Fixtures.scriptedGitOf({
|
||||
'--no-color': Fixtures.ok('@@ -1 +1 @@\n-old\n+new\n'),
|
||||
diff: Fixtures.ok(
|
||||
'\x1b[36m@@ -1 +1 @@\x1b[m\n\x1b[31m-old\x1b[m\n' +
|
||||
'\x1b[32m+\x1b[m\x1b[32mnew\x1b[m\n',
|
||||
),
|
||||
})
|
||||
|
||||
const outcome = await Git.fetchDiff(deps, 'uncommitted')
|
||||
const data = outcome.kind === 'data' ? outcome.data : null
|
||||
const [row] = data?.files ?? []
|
||||
|
||||
expect(data?.stats).toEqual({
|
||||
filesCount: 1,
|
||||
linesAdded: 1,
|
||||
linesRemoved: 1,
|
||||
})
|
||||
|
||||
expect(
|
||||
data && row ? await Git.fetchFileHunks(git.run, data, row) : null,
|
||||
).toEqual({
|
||||
hunks: [{ oldStart: 1, newStart: 1, lines: ['-old', '+new'] }],
|
||||
isTruncated: false,
|
||||
isLarge: false,
|
||||
})
|
||||
})
|
||||
|
||||
test('uncommitted mode drops pre-session untracked files', async () => {
|
||||
const outcome = await Git.fetchDiff(
|
||||
depsOf(
|
||||
|
||||
Reference in New Issue
Block a user