@anureo/refactor 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/anureo-refactor.ts +5 -0
- package/package.json +21 -23
- package/src/agent-work.ts +184 -0
- package/src/checks.ts +82 -0
- package/src/cli.ts +214 -0
- package/src/client.ts +93 -0
- package/src/errors.ts +70 -0
- package/src/git-path.ts +47 -0
- package/src/git-tree.ts +55 -0
- package/src/git.ts +55 -0
- package/src/graph-artifacts.ts +73 -0
- package/src/graph.ts +145 -0
- package/src/index.ts +40 -0
- package/src/options.ts +65 -0
- package/src/plan-validation.ts +38 -0
- package/src/{process.d.ts → process.ts} +4 -2
- package/src/{prompts.js → prompts.ts} +145 -67
- package/src/refactor.ts +191 -0
- package/src/{report-store.js → report-store.ts} +10 -8
- package/src/report.ts +60 -0
- package/src/results.ts +83 -0
- package/src/run-lifecycle.ts +117 -0
- package/src/{schema.d.ts → schema.ts} +29 -23
- package/src/source-inventory.ts +17 -0
- package/src/source-policy.ts +50 -0
- package/src/worktree.ts +322 -0
- package/tests/agent-contract.test.ts +180 -0
- package/tests/cli.test.ts +378 -0
- package/tests/fixtures/acp.mjs +38 -0
- package/tests/fixtures/ahp.mjs +50 -0
- package/tests/fixtures/answer.mjs +15 -0
- package/tests/fixtures/codex.mjs +44 -0
- package/tests/fixtures/repograph.ts +24 -0
- package/tests/graph.integration.test.ts +110 -0
- package/tests/helpers.ts +109 -0
- package/tests/refactor.test.ts +536 -0
- package/tests/run-lifecycle.test.ts +136 -0
- package/tests/tree.test.ts +210 -0
- package/tsconfig.json +12 -0
- package/LICENSE +0 -201
- package/bin/anureo-refactor.d.ts +0 -2
- package/bin/anureo-refactor.js +0 -4
- package/src/agent-work.d.ts +0 -41
- package/src/agent-work.js +0 -131
- package/src/checks.d.ts +0 -26
- package/src/checks.js +0 -66
- package/src/cli.d.ts +0 -27
- package/src/cli.js +0 -189
- package/src/client.d.ts +0 -26
- package/src/client.js +0 -73
- package/src/errors.d.ts +0 -9
- package/src/errors.js +0 -22
- package/src/git-path.d.ts +0 -15
- package/src/git-path.js +0 -46
- package/src/git-tree.d.ts +0 -18
- package/src/git-tree.js +0 -56
- package/src/git.d.ts +0 -23
- package/src/git.js +0 -40
- package/src/graph-artifacts.d.ts +0 -19
- package/src/graph-artifacts.js +0 -58
- package/src/graph.d.ts +0 -47
- package/src/graph.js +0 -71
- package/src/index.d.ts +0 -11
- package/src/index.js +0 -4
- package/src/options.d.ts +0 -55
- package/src/options.js +0 -15
- package/src/plan-validation.d.ts +0 -10
- package/src/plan-validation.js +0 -38
- package/src/process.js +0 -10
- package/src/prompts.d.ts +0 -47
- package/src/refactor.d.ts +0 -17
- package/src/refactor.js +0 -168
- package/src/report-store.d.ts +0 -9
- package/src/report.d.ts +0 -6
- package/src/report.js +0 -52
- package/src/results.d.ts +0 -80
- package/src/results.js +0 -0
- package/src/run-lifecycle.d.ts +0 -18
- package/src/run-lifecycle.js +0 -100
- package/src/schema.js +0 -31
- package/src/source-inventory.d.ts +0 -9
- package/src/source-inventory.js +0 -17
- package/src/source-policy.d.ts +0 -11
- package/src/source-policy.js +0 -56
- package/src/worktree.d.ts +0 -57
- package/src/worktree.js +0 -195
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { expect, test } from 'bun:test'
|
|
2
|
+
import { mkdir, readFile, realpath, rm, stat, writeFile } from 'node:fs/promises'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { git } from '../src/git'
|
|
5
|
+
import { saveReport } from '../src/report-store'
|
|
6
|
+
import { formatReport } from '../src/report'
|
|
7
|
+
import type { RefactorReport } from '../src/results'
|
|
8
|
+
import { withRun } from '../src/run-lifecycle'
|
|
9
|
+
import { fixture } from './helpers'
|
|
10
|
+
|
|
11
|
+
test('lifecycle holds the lock through body execution and records synchronous observer failures in order', async () => {
|
|
12
|
+
const context = await fixture()
|
|
13
|
+
const child = join(context.cwd, 'child')
|
|
14
|
+
await mkdir(child)
|
|
15
|
+
const events: string[] = []
|
|
16
|
+
let competingBodyRan = false
|
|
17
|
+
const report = await withRun({
|
|
18
|
+
...context,
|
|
19
|
+
onProgress: event => {
|
|
20
|
+
events.push(event)
|
|
21
|
+
if (events.length === 1) throw Object.create(null)
|
|
22
|
+
throw new Error(`Observer ${events.length}`)
|
|
23
|
+
},
|
|
24
|
+
}, async (report, progress) => {
|
|
25
|
+
expect(report.status).toBe('incomplete')
|
|
26
|
+
expect(events).toEqual([`run: ${report.directory}`])
|
|
27
|
+
for (const cwd of [context.cwd, child]) {
|
|
28
|
+
await expect(withRun({ ...context, cwd }, async () => { competingBodyRan = true })).rejects.toThrow('Cannot acquire refactor lock')
|
|
29
|
+
}
|
|
30
|
+
expect((await stat(join(context.cwd, '.anureo/refactor/writer.lock'))).isFile()).toBe(true)
|
|
31
|
+
progress('body: finished')
|
|
32
|
+
})
|
|
33
|
+
expect(competingBodyRan).toBe(false)
|
|
34
|
+
expect(events).toEqual([`run: ${report.directory}`, 'body: finished'])
|
|
35
|
+
expect(report.status).toBe('completed')
|
|
36
|
+
expect(report.progressErrors).toEqual(['Error details could not be displayed', 'Observer 2'])
|
|
37
|
+
await expectFinalizedRun(report)
|
|
38
|
+
|
|
39
|
+
const nested = await withRun({ ...context, cwd: child }, async () => {})
|
|
40
|
+
expect(nested.directory).toBe(join(child, '.anureo/refactor', nested.runId))
|
|
41
|
+
await expectFinalizedRun(nested, context.cwd)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('lifecycle publishes classified body failures before releasing the lock', async () => {
|
|
45
|
+
const context = await fixture()
|
|
46
|
+
const report = await withRun(context, async () => {
|
|
47
|
+
throw Object.assign(new Error('Body unavailable'), {
|
|
48
|
+
code: 'RECEIPT_LOST', outcomeUnknown: true, retryable: true,
|
|
49
|
+
details: { cleanupErrors: ['Release unavailable'], issues: [
|
|
50
|
+
{ path: '/summary', code: 'type', message: 'Omit this detail' },
|
|
51
|
+
{ path: ['modules', 0], code: 'invalid_type' },
|
|
52
|
+
{ path: [-1], code: 'ignored' },
|
|
53
|
+
] },
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
expect(report.status).toBe('incomplete')
|
|
57
|
+
expect(report.errors).toEqual(['Body unavailable'])
|
|
58
|
+
expect(report.failure).toEqual({
|
|
59
|
+
code: 'RECEIPT_LOST', outcomeUnknown: true, cleanupFailed: true, retryable: true,
|
|
60
|
+
issues: [{ path: '/summary', code: 'type' }, { path: ['modules', 0], code: 'invalid_type' }],
|
|
61
|
+
})
|
|
62
|
+
expect(formatReport(report)).toContain('Agent execution outcome is unknown')
|
|
63
|
+
expect(formatReport(report)).toContain('Validation issue: /summary [type]')
|
|
64
|
+
expect(formatReport(report)).toContain('Validation issue: ["modules",0] [invalid_type]')
|
|
65
|
+
await expectFinalizedRun(report)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('run artifacts are ignored without a repository ignore rule', async () => {
|
|
69
|
+
const context = await fixture()
|
|
70
|
+
await rm(join(context.cwd, '.gitignore'))
|
|
71
|
+
const report = await withRun(context, async () => {})
|
|
72
|
+
await expectFinalizedRun(report)
|
|
73
|
+
expect(await git(context.cwd, 'ls-files', '--others', '--exclude-standard')).toBe('')
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test('storage setup failures retain their filesystem diagnostic and release the checkout lock', async () => {
|
|
77
|
+
const context = await fixture()
|
|
78
|
+
const child = join(context.cwd, 'child')
|
|
79
|
+
const obstruction = join(child, '.anureo')
|
|
80
|
+
await mkdir(child)
|
|
81
|
+
await writeFile(obstruction, '')
|
|
82
|
+
let bodyRan = false
|
|
83
|
+
await expect(withRun({ ...context, cwd: child }, async () => { bodyRan = true }))
|
|
84
|
+
.rejects.toMatchObject({ path: join(obstruction, 'refactor') })
|
|
85
|
+
expect(bodyRan).toBe(false)
|
|
86
|
+
await expect(stat(join(context.cwd, '.anureo/refactor/writer.lock'))).rejects.toMatchObject({ code: 'ENOENT' })
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
// Obstruct real paths to exercise finalization diagnostics without replacing filesystem calls.
|
|
90
|
+
test.each([
|
|
91
|
+
{ publicationFails: true, removalFails: false },
|
|
92
|
+
{ publicationFails: false, removalFails: true },
|
|
93
|
+
{ publicationFails: true, removalFails: true },
|
|
94
|
+
])('finalization handles publication failure $publicationFails and removal failure $removalFails', async ({ publicationFails, removalFails }) => {
|
|
95
|
+
const context = await fixture()
|
|
96
|
+
const lockPath = join(await realpath(context.cwd), '.anureo/refactor/writer.lock')
|
|
97
|
+
let directory = ''
|
|
98
|
+
let checkpoint = ''
|
|
99
|
+
const run = withRun(context, async report => {
|
|
100
|
+
directory = report.directory
|
|
101
|
+
await saveReport(report)
|
|
102
|
+
checkpoint = await readFile(join(directory, 'report.json'), 'utf8')
|
|
103
|
+
if (publicationFails) await mkdir(join(directory, 'report.json.tmp'))
|
|
104
|
+
if (removalFails) {
|
|
105
|
+
await rm(lockPath)
|
|
106
|
+
await mkdir(lockPath)
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
const error = await run.then(() => null, cause => cause)
|
|
110
|
+
const temporaryReport = join(directory, 'report.json.tmp')
|
|
111
|
+
if (publicationFails && removalFails) {
|
|
112
|
+
expect(error).toBeInstanceOf(AggregateError)
|
|
113
|
+
expect(error.errors).toEqual([
|
|
114
|
+
expect.objectContaining({ path: temporaryReport }),
|
|
115
|
+
expect.objectContaining({ path: lockPath }),
|
|
116
|
+
])
|
|
117
|
+
expect(error.message).toContain(temporaryReport)
|
|
118
|
+
expect(error.message).toContain(lockPath)
|
|
119
|
+
} else {
|
|
120
|
+
expect(error).toMatchObject({ path: removalFails ? lockPath : temporaryReport })
|
|
121
|
+
}
|
|
122
|
+
const saved = await readFile(join(directory, 'report.json'), 'utf8')
|
|
123
|
+
if (publicationFails) expect(saved).toBe(checkpoint)
|
|
124
|
+
else expect(JSON.parse(saved).status).toBe('completed')
|
|
125
|
+
if (removalFails) expect((await stat(lockPath)).isDirectory()).toBe(true)
|
|
126
|
+
else await expect(stat(lockPath)).rejects.toMatchObject({ code: 'ENOENT' })
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
/** Assert the returned record was fully published and writer ownership was released. */
|
|
130
|
+
async function expectFinalizedRun(report: RefactorReport, checkout = report.cwd): Promise<void> {
|
|
131
|
+
const saved = await readFile(join(report.directory, 'report.json'), 'utf8')
|
|
132
|
+
expect(JSON.parse(saved)).toEqual(report)
|
|
133
|
+
expect(saved.endsWith('\n')).toBe(true)
|
|
134
|
+
await expect(stat(join(report.directory, 'report.json.tmp'))).rejects.toMatchObject({ code: 'ENOENT' })
|
|
135
|
+
await expect(stat(join(checkout, '.anureo/refactor/writer.lock'))).rejects.toMatchObject({ code: 'ENOENT' })
|
|
136
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// Verifies Git snapshots and source eligibility against real filesystem entries.
|
|
2
|
+
import { expect, spyOn, test } from 'bun:test'
|
|
3
|
+
import * as fs from 'node:fs/promises'
|
|
4
|
+
import { chmod, lstat, mkdir, readFile, rm, symlink, writeFile } from 'node:fs/promises'
|
|
5
|
+
import { join, resolve } from 'node:path'
|
|
6
|
+
import { runChecks, validateChecks } from '../src/checks'
|
|
7
|
+
import { captureTree, changes, treeVersion } from '../src/git-tree'
|
|
8
|
+
import { git, gitFiles } from '../src/git'
|
|
9
|
+
import { exec } from '../src/process'
|
|
10
|
+
import { isSource, isTextSource } from '../src/source-policy'
|
|
11
|
+
import { createAgentWorktree, mergeWorktree, prepareCheckDependencies, removeAgentWorktree, withWorktreeBaseline } from '../src/worktree'
|
|
12
|
+
import { fixture, temporary } from './helpers'
|
|
13
|
+
|
|
14
|
+
/** Exercise Git visibility separately from snapshot exclusions, including force-added run storage. */
|
|
15
|
+
test('snapshots sort visible files, omit deleted entries and metadata, and retain non-source files', async () => {
|
|
16
|
+
const { cwd } = await fixture()
|
|
17
|
+
await writeFile(join(cwd, '.gitignore'), '.anureo/\nignored.ts\n')
|
|
18
|
+
await writeFile(join(cwd, 'ignored.ts'), 'ignored')
|
|
19
|
+
await writeFile(join(cwd, 'notes.txt'), 'untracked text')
|
|
20
|
+
await mkdir(join(cwd, '.anureo'))
|
|
21
|
+
await writeFile(join(cwd, '.anureo', 'report.ts'), 'run output')
|
|
22
|
+
await exec('git', ['-C', cwd, 'add', '--force', '.anureo/report.ts'])
|
|
23
|
+
await rm(join(cwd, 'b.ts'))
|
|
24
|
+
|
|
25
|
+
expect(await gitFiles(cwd)).toEqual(['.anureo/report.ts', '.gitignore', 'a.ts', 'b.ts', 'notes.txt'])
|
|
26
|
+
const tree = await captureTree(cwd)
|
|
27
|
+
expect([...tree.keys()]).toEqual(['.gitignore', 'a.ts', 'notes.txt'])
|
|
28
|
+
const version = treeVersion(tree)
|
|
29
|
+
await writeFile(join(cwd, '.anureo', 'report.ts'), 'changed run output')
|
|
30
|
+
expect(treeVersion(await captureTree(cwd))).toBe(version)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('Git file discovery preserves an initial BOM and rejects invalid filename bytes', async () => {
|
|
34
|
+
const { cwd } = await fixture()
|
|
35
|
+
await writeFile(join(cwd, '\uFEFFfile.ts'), 'text')
|
|
36
|
+
expect(await gitFiles(cwd)).toContain('\uFEFFfile.ts')
|
|
37
|
+
|
|
38
|
+
const blob = (await git(cwd, 'rev-parse', ':a.ts')).trim()
|
|
39
|
+
const stdin = Buffer.concat([Buffer.from(`100644 ${blob}\t`), Buffer.from([0xff, 0])])
|
|
40
|
+
const child = Bun.spawn(['git', '-C', cwd, 'update-index', '-z', '--index-info'], { stdin })
|
|
41
|
+
expect(await child.exited).toBe(0)
|
|
42
|
+
await expect(gitFiles(cwd)).rejects.toThrow('filename that is not valid UTF-8')
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('detached worktrees restore the frozen split index and discover its paths', async () => {
|
|
46
|
+
const { cwd } = await fixture()
|
|
47
|
+
await git(cwd, 'update-index', '--split-index')
|
|
48
|
+
const before = await captureTree(cwd)
|
|
49
|
+
await withWorktreeBaseline(cwd, async baseline => {
|
|
50
|
+
const worktree = await createAgentWorktree(baseline)
|
|
51
|
+
try {
|
|
52
|
+
expect(await captureTree(worktree.root)).toEqual(before)
|
|
53
|
+
} finally {
|
|
54
|
+
await removeAgentWorktree(baseline, worktree)
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('validation copies ignored in-repository dependency targets and rebases workspace links', async () => {
|
|
60
|
+
const { cwd } = await fixture()
|
|
61
|
+
const installed = join(cwd, '.deps', 'node_modules')
|
|
62
|
+
await mkdir(installed, { recursive: true })
|
|
63
|
+
await writeFile(join(installed, 'installed.txt'), 'dependency content')
|
|
64
|
+
await symlink(cwd, join(installed, 'workspace'), 'junction')
|
|
65
|
+
await symlink(installed, join(cwd, 'node_modules'), 'junction')
|
|
66
|
+
await writeFile(join(cwd, '.gitignore'), '.anureo/\n.deps/\n')
|
|
67
|
+
await withWorktreeBaseline(cwd, async baseline => {
|
|
68
|
+
const worktree = await createAgentWorktree(baseline)
|
|
69
|
+
try {
|
|
70
|
+
await writeFile(join(worktree.cwd, 'a.ts'), 'candidate content')
|
|
71
|
+
await prepareCheckDependencies(baseline, worktree)
|
|
72
|
+
expect(await readFile(join(worktree.cwd, 'node_modules', 'installed.txt'), 'utf8')).toBe('dependency content')
|
|
73
|
+
expect(await readFile(join(worktree.cwd, 'node_modules', 'workspace', 'a.ts'), 'utf8')).toBe('candidate content')
|
|
74
|
+
} finally {
|
|
75
|
+
await removeAgentWorktree(baseline, worktree)
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test('shell and argv validation commands use their checkout despite inherited Git selectors', async () => {
|
|
81
|
+
const { cwd } = await fixture()
|
|
82
|
+
await withWorktreeBaseline(cwd, async baseline => {
|
|
83
|
+
const worktree = await createAgentWorktree(baseline)
|
|
84
|
+
const previous = { GIT_DIR: process.env.GIT_DIR, GIT_WORK_TREE: process.env.GIT_WORK_TREE }
|
|
85
|
+
try {
|
|
86
|
+
await writeFile(join(worktree.cwd, 'a.ts'), 'candidate content')
|
|
87
|
+
process.env.GIT_DIR = join(cwd, '.git')
|
|
88
|
+
process.env.GIT_WORK_TREE = cwd
|
|
89
|
+
for (const command of ['git diff --exit-code -- a.ts', { executable: 'git', args: ['diff', '--exit-code', '--', 'a.ts'] }]) {
|
|
90
|
+
const results: Parameters<typeof runChecks>[2] = []
|
|
91
|
+
await expect(runChecks(worktree.cwd, [command], results)).rejects.toThrow('Validation failed')
|
|
92
|
+
expect(results).toMatchObject([{ status: 'failed', output: expect.stringContaining('+candidate content') }])
|
|
93
|
+
}
|
|
94
|
+
} finally {
|
|
95
|
+
for (const [key, value] of Object.entries(previous)) {
|
|
96
|
+
if (value === undefined) delete process.env[key]
|
|
97
|
+
else process.env[key] = value
|
|
98
|
+
}
|
|
99
|
+
await removeAgentWorktree(baseline, worktree)
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('validation preflight reports every invalid command and argument position', () => {
|
|
105
|
+
expect(() => validateChecks([' ', { executable: 'git\0', args: ['diff', 'a\0', 'b\0'] }])).toThrow(
|
|
106
|
+
'check commands must be nonempty\ncheck #1 is blank\ncheck #2 contains NUL\ncheck #2 argument #2 contains NUL\ncheck #2 argument #3 contains NUL',
|
|
107
|
+
)
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
test('merge rolls back a late target edit from its target-relative recovery path', async () => {
|
|
111
|
+
const { cwd } = await fixture()
|
|
112
|
+
const file = 'nested/edit.ts'
|
|
113
|
+
const target = join(cwd, file)
|
|
114
|
+
await mkdir(join(cwd, 'nested'))
|
|
115
|
+
await mkdir(join(cwd, '.anureo', 'refactor'), { recursive: true })
|
|
116
|
+
await writeFile(target, 'baseline content')
|
|
117
|
+
await withWorktreeBaseline(cwd, async baseline => {
|
|
118
|
+
const worktree = await createAgentWorktree(baseline)
|
|
119
|
+
const mergeTarget = resolve(baseline.root, baseline.scope, file)
|
|
120
|
+
const rename = fs.rename
|
|
121
|
+
const moves: string[] = []
|
|
122
|
+
const mock = spyOn(fs, 'rename').mockImplementation(async (from, to) => {
|
|
123
|
+
if (from === mergeTarget) {
|
|
124
|
+
moves.push(String(to))
|
|
125
|
+
await writeFile(from, 'late editor save')
|
|
126
|
+
}
|
|
127
|
+
await rename(from, to)
|
|
128
|
+
})
|
|
129
|
+
try {
|
|
130
|
+
await writeFile(join(worktree.cwd, file), 'candidate content')
|
|
131
|
+
await expect(mergeWorktree(baseline, worktree, [file])).rejects.toThrow(`Source changed during refactor: ${file}`)
|
|
132
|
+
expect(moves).toEqual([expect.stringContaining(join('backups', file))])
|
|
133
|
+
expect(await readFile(target, 'utf8')).toBe('late editor save')
|
|
134
|
+
} finally {
|
|
135
|
+
mock.mockRestore()
|
|
136
|
+
await removeAgentWorktree(baseline, worktree)
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
/** Compare real file/link edits so content, mode and link text remain independently observable. */
|
|
142
|
+
test.skipIf(process.platform === 'win32')('snapshot changes track content and modes, and hash symlink text without reading its destination', async () => {
|
|
143
|
+
const { cwd } = await fixture()
|
|
144
|
+
const outside = await temporary()
|
|
145
|
+
const destination = join(outside, 'destination.ts')
|
|
146
|
+
await writeFile(destination, 'external content')
|
|
147
|
+
await symlink(destination, join(cwd, 'linked.ts'))
|
|
148
|
+
const before = await captureTree(cwd)
|
|
149
|
+
|
|
150
|
+
await writeFile(destination, 'changed external content')
|
|
151
|
+
expect(changes(before, await captureTree(cwd))).toEqual([])
|
|
152
|
+
await writeFile(join(cwd, 'a.ts'), 'changed content')
|
|
153
|
+
const mode = (await lstat(join(cwd, 'b.ts'))).mode
|
|
154
|
+
await chmod(join(cwd, 'b.ts'), mode ^ 0o100)
|
|
155
|
+
await rm(join(cwd, 'linked.ts'))
|
|
156
|
+
await symlink(join(outside, 'missing.ts'), join(cwd, 'linked.ts'))
|
|
157
|
+
await writeFile(join(cwd, 'new.ts'), 'new content')
|
|
158
|
+
|
|
159
|
+
const after = await captureTree(cwd)
|
|
160
|
+
expect(changes(before, after)).toEqual(['a.ts', 'b.ts', 'linked.ts', 'new.ts'])
|
|
161
|
+
expect(treeVersion(after)).not.toBe(treeVersion(before))
|
|
162
|
+
expect(treeVersion(new Map([...after].reverse()))).not.toBe(treeVersion(after))
|
|
163
|
+
await rm(join(cwd, 'a.ts'))
|
|
164
|
+
expect(changes(after, await captureTree(cwd))).toEqual(['a.ts'])
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
/** Exercise scope precedence, path inspection and text detection independently. */
|
|
168
|
+
test('source inventory accepts unfamiliar names and rejects unsafe paths, binary and non-file targets', async () => {
|
|
169
|
+
const { cwd } = await fixture()
|
|
170
|
+
const outside = await temporary()
|
|
171
|
+
expect(isSource('src/main.ts')).toBe(true)
|
|
172
|
+
expect(isSource('types.d.mts')).toBe(true)
|
|
173
|
+
expect(isSource('bin/outil')).toBe(true)
|
|
174
|
+
for (const file of ['docs/main.ts', 'node_modules/main.ts', 'README.md']) {
|
|
175
|
+
expect(isSource(file)).toBe(false)
|
|
176
|
+
}
|
|
177
|
+
expect(isSource('README.md', ['README.md'])).toBe(true)
|
|
178
|
+
expect(isSource('README.md', ['README.md'], ['*.md'])).toBe(false)
|
|
179
|
+
expect(isSource('docs/main.ts', ['docs/main.ts'])).toBe(false)
|
|
180
|
+
for (const file of ['/absolute.ts', '../escape.ts', './a.ts', 'src//a.ts', 'src/../a.ts', 'src\\a.ts', 'docs/main.ts']) {
|
|
181
|
+
await expect(isTextSource(cwd, file)).rejects.toThrow(`Invalid source path: ${file}`)
|
|
182
|
+
}
|
|
183
|
+
await expect(isTextSource(cwd, 'a.ts')).resolves.toBe(true)
|
|
184
|
+
await expect(isTextSource(cwd, 'missing/new.ts')).resolves.toBe(false)
|
|
185
|
+
expect(await lstat(join(cwd, 'missing')).catch(() => null)).toBeNull()
|
|
186
|
+
|
|
187
|
+
await symlink(outside, join(cwd, 'linked'), 'junction')
|
|
188
|
+
await expect(isTextSource(cwd, 'linked/new.ts')).rejects.toThrow('Symlink source paths are unsupported: linked/new.ts')
|
|
189
|
+
await mkdir(join(cwd, 'directory.ts'))
|
|
190
|
+
await expect(isTextSource(cwd, 'directory.ts')).resolves.toBe(false)
|
|
191
|
+
await writeFile(join(cwd, 'archive.dsl'), Buffer.from([0xff, 0, 0x80]))
|
|
192
|
+
await expect(isTextSource(cwd, 'archive.dsl')).resolves.toBe(false)
|
|
193
|
+
await writeFile(join(cwd, '构建'), Buffer.from('\uFEFFrun job\r\n', 'utf16le'))
|
|
194
|
+
await expect(isTextSource(cwd, '构建')).resolves.toBe(true)
|
|
195
|
+
await writeFile(join(cwd, '构建'), Buffer.from([0xfe, 0xff, 0x00, 0x61]))
|
|
196
|
+
await expect(isTextSource(cwd, '构建')).resolves.toBe(true)
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
/** Ensure a replaced ancestor is an actual failure rather than an apparently missing tracked file. */
|
|
200
|
+
test.skipIf(process.platform === 'win32')('snapshot and source validation propagate non-ENOENT filesystem failures', async () => {
|
|
201
|
+
const { cwd } = await fixture()
|
|
202
|
+
await mkdir(join(cwd, 'parent'))
|
|
203
|
+
await writeFile(join(cwd, 'parent', 'child.ts'), 'tracked content')
|
|
204
|
+
await exec('git', ['-C', cwd, 'add', 'parent/child.ts'])
|
|
205
|
+
await rm(join(cwd, 'parent'), { recursive: true })
|
|
206
|
+
await writeFile(join(cwd, 'parent'), 'replaced ancestor')
|
|
207
|
+
|
|
208
|
+
await expect(isTextSource(cwd, 'parent/child.ts')).rejects.toMatchObject({ code: 'ENOTDIR' })
|
|
209
|
+
await expect(captureTree(cwd)).rejects.toMatchObject({ code: 'ENOTDIR' })
|
|
210
|
+
})
|
package/tsconfig.json
ADDED
package/LICENSE
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright 2026 Yoichi
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
package/bin/anureo-refactor.d.ts
DELETED
package/bin/anureo-refactor.js
DELETED
package/src/agent-work.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { type CheckCommand } from "./checks.js";
|
|
2
|
-
import type { RefactorOptions } from "./options.js";
|
|
3
|
-
import type { StepResult } from "./results.js";
|
|
4
|
-
import { type AgentWorktree, type WorktreeBaseline } from "./worktree.js";
|
|
5
|
-
/** Run one callback in a fresh checkout of the supplied baseline. The callback must await all
|
|
6
|
-
* work that uses the checkout. Removal is awaited before returning its result or propagating its
|
|
7
|
-
* error. Creation and removal failures propagate, and a removal failure takes precedence over
|
|
8
|
-
* a callback failure. The caller owns the baseline. */
|
|
9
|
-
export declare function inAgentWorktree<T>(baseline: WorktreeBaseline, use: (worktree: AgentWorktree) => Promise<T>): Promise<T>;
|
|
10
|
-
/** Run a design or module session and return observed edits after checkout cleanup.
|
|
11
|
-
* runDesign and runModules use the returned step to decide what can be integrated. Session,
|
|
12
|
-
* capture, policy and checkout failures are recorded on the step. Capture still runs after a
|
|
13
|
-
* session failure so any patch can be recovered. Review-only work and out-of-target edits
|
|
14
|
-
* stop before writing a patch. The caller supplies the patch destination and owns the baseline
|
|
15
|
-
* and client. A step with a patch still requires a separate integration decision. */
|
|
16
|
-
export declare function runAgentWork(input: AgentWorkInput): Promise<StepResult>;
|
|
17
|
-
/** Apply an available patch and record validation in the target checkout. Design can apply a failed
|
|
18
|
-
* step's patch without running checks. Module integration skips failed steps with their patches
|
|
19
|
-
* intact. Apply and check failures are recorded on the step without rolling back applied edits.
|
|
20
|
-
* Callers serialize integration and publish the mutated step after this settles. */
|
|
21
|
-
export declare function integrateAgentWork(input: {
|
|
22
|
-
phase: 'design' | 'module';
|
|
23
|
-
baseline: WorktreeBaseline;
|
|
24
|
-
cwd: string;
|
|
25
|
-
step: StepResult;
|
|
26
|
-
checks: readonly CheckCommand[];
|
|
27
|
-
}): Promise<void>;
|
|
28
|
-
/** Mark a step failed in place. Later errors append diagnostics and can record a cleanup
|
|
29
|
-
* failure while preserving the first error's code and outcome uncertainty. recordSessionResult,
|
|
30
|
-
* runAgentWork and integrateAgentWork record caught errors here. integrateModules uses it when
|
|
31
|
-
* an earlier failure blocks a patch. Error conversion itself can throw for custom error objects. */
|
|
32
|
-
export declare function markFailed(step: StepResult, cause: unknown): void;
|
|
33
|
-
interface AgentWorkInput {
|
|
34
|
-
baseline: WorktreeBaseline;
|
|
35
|
-
options: RefactorOptions;
|
|
36
|
-
prompt: string;
|
|
37
|
-
patchPath: string;
|
|
38
|
-
/** Paths already assigned to this module. Omission skips module assignment validation. */
|
|
39
|
-
assignedFiles?: readonly string[];
|
|
40
|
-
}
|
|
41
|
-
export {};
|