Skip to content

Commit faa4e56

Browse files
committed
fix(sim-cli): keep a linked root AGENTS.md, list plan errors and metadata changes in summaries
1 parent c7049f7 commit faa4e56

6 files changed

Lines changed: 87 additions & 6 deletions

File tree

‎packages/sim-cli/src/commands/protocol/source-status.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ import { printLine } from '../../output/io'
2525
import { styles } from '../../output/presentation'
2626
import { bytes, printDocument, sanitize } from '../../output/render'
2727
import { CliUsageError, LocalRefusal } from './local-errors'
28-
import { codeSpan, type Diagnostic, findingsOutput, markdownCell, summaryMarker } from './source-ui'
28+
import {
29+
codeSpan,
30+
type Diagnostic,
31+
errorBullets,
32+
findingsOutput,
33+
markdownCell,
34+
summaryMarker,
35+
} from './source-ui'
2936

3037
/** One change of a workspace apply's plan. */
3138
type WorkspacePlanChange = ApplyWorkspaceSourceResponse['data']['plan'][number]
@@ -142,12 +149,13 @@ const SERVER_WORDS = {
142149
/**
143150
* A status as the Markdown a step summary or `--summary-file` holds: the local changes, what
144151
* changed on the server (the drift a scheduled job opens an issue for), the plan's one line and
145-
* the next command.
152+
* the next command; the plan's error findings follow it, as an apply's summary lists them.
146153
*/
147154
function statusMarkdown<Plan>(
148155
heading: string,
149156
report: StatusReport<Plan>,
150-
planLine: (plan: Plan) => string
157+
planLine: (plan: Plan) => string,
158+
findings: readonly Diagnostic[]
151159
): string {
152160
const lines = [`### Sim status: ${markdownCell(heading)}`, '']
153161
if (report.local.length === 0) lines.push('No local changes.')
@@ -187,6 +195,8 @@ function statusMarkdown<Plan>(
187195
lines.push(`Server not checked${report.note ? `: ${markdownCell(report.note)}` : '.'}`)
188196
}
189197
if (report.plan) lines.push('', markdownCell(planLine(report.plan)))
198+
const errors = findings.filter((finding) => finding.severity === 'error')
199+
if (errors.length > 0) lines.push('', '**Errors**', '', ...errorBullets(errors))
190200
if (report.next) lines.push('', `Next: ${codeSpan(report.next.command)}`)
191201
return lines.join('\n')
192202
}
@@ -205,7 +215,7 @@ export function printStatusReport<Plan>(
205215
findings: readonly Diagnostic[],
206216
summaryFile?: string
207217
): void {
208-
publishSummary(() => statusMarkdown(heading, report, planLine), {
218+
publishSummary(() => statusMarkdown(heading, report, planLine, findings), {
209219
file: summaryFile,
210220
marker: summaryMarker(report.dir),
211221
})

‎packages/sim-cli/src/commands/protocol/source-tree.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ import { AGENTS_POINTER_MARKER, agentsPointer, type PrimerKind, primerFor } from
5959
const TSCONFIG_FILE = 'tsconfig.json'
6060
/** Where agents look first: the nearest `AGENTS.md` above the file they edit. */
6161
const ROOT_AGENTS_FILE = 'AGENTS.md'
62+
/**
63+
* A file the user may own, read so a symbolic link they point at their own guide counts as theirs
64+
* (empty text, which is never replaced) instead of refusing the whole refresh.
65+
*/
66+
async function readUserOwnedText(dir: string, path: string): Promise<string | null> {
67+
try {
68+
return await readSourceText(dir, path)
69+
} catch (error) {
70+
if (error instanceof SourceDirError && error.code === 'SOURCE_SYMLINK') return ''
71+
throw error
72+
}
73+
}
74+
6275
/** Type-checks the source against every current block, for a block the default one leaves out. */
6376
export const TSCONFIG_FULL_FILE = 'tsconfig.full.json'
6477
/** The SDK file whose first line names the catalog the declarations were generated from. */
@@ -802,7 +815,7 @@ export async function sourceTreeChange(
802815
readSourceText(dir, TSCONFIG_FILE),
803816
readSourceText(dir, TSCONFIG_FULL_FILE),
804817
sdkCacheIndex(catalog),
805-
readSourceText(dir, ROOT_AGENTS_FILE),
818+
readUserOwnedText(dir, ROOT_AGENTS_FILE),
806819
])
807820
if (rootAgents === null || rootAgents.startsWith(AGENTS_POINTER_MARKER)) {
808821
write.push([ROOT_AGENTS_FILE, agentsPointer(profile.kind)])

‎packages/sim-cli/src/commands/protocol/workflow-source-apply.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,20 @@ describe('sim workflows source apply', () => {
232232
expect(readFileSync(file, 'utf8')).toContain('Variables: added limit; modified region')
233233
})
234234

235+
it('names a name or description change in --summary-file, which no count shows', async () => {
236+
setTerminal(false)
237+
const answer = outcome({ dryRun: true })
238+
answer.data.diff.blocks.added = []
239+
answer.data.diff.edges = { added: 0, removed: 0 }
240+
Object.assign(answer.data.diff, { meta: ['name', 'description'] })
241+
request.mockResolvedValue(answer)
242+
const file = join(dir, 'plan.md')
243+
244+
await apply(WORKFLOW_ID, '--dir', dir, '--dry-run', '--summary-file', file)
245+
246+
expect(readFileSync(file, 'utf8')).toContain('Metadata: name, description')
247+
})
248+
235249
it('prints the whole next command in a table, never clipping the flag it names', async () => {
236250
setTerminal(false)
237251
contextMockState.output = 'table'

‎packages/sim-cli/src/commands/protocol/workflow-source-apply.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ function planMarkdown(data: SourceApplyData, creating: boolean, deployment: Depl
288288
...(variableChanges.length > 0
289289
? ['', `Variables: ${variableChanges.map(markdownCell).join('; ')}`]
290290
: []),
291+
...(data.diff.meta?.length ? ['', `Metadata: ${data.diff.meta.join(', ')}`] : []),
291292
...(changes.length > 0
292293
? [
293294
'',

‎packages/sim-cli/src/commands/protocol/workflow-source-get.test.ts‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { execFileSync } from 'node:child_process'
2-
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
2+
import {
3+
existsSync,
4+
mkdirSync,
5+
mkdtempSync,
6+
readFileSync,
7+
rmSync,
8+
symlinkSync,
9+
writeFileSync,
10+
} from 'node:fs'
311
import { tmpdir } from 'node:os'
412
import { dirname, join } from 'node:path'
513
import { COOKBOOK_EXAMPLES } from '@sim/workflow-sdk/codegen'
@@ -205,6 +213,20 @@ describe('sim workflows source get --dir', () => {
205213
expect(readFileSync(join(outDir, 'AGENTS.md'), 'utf8')).toBe('# My own rules\n')
206214
})
207215

216+
it("leaves a root AGENTS.md that links to the user's own guide untouched, and still refreshes", async () => {
217+
serve({ [SOURCE_PATH]: () => source() })
218+
await get('--dir', outDir)
219+
const guide = join(outDir, '..', 'my-guide.md')
220+
writeFileSync(guide, '# Mine\n')
221+
rmSync(join(outDir, 'AGENTS.md'))
222+
symlinkSync(guide, join(outDir, 'AGENTS.md'))
223+
224+
await get('--dir', outDir, '--force')
225+
226+
expect(readFileSync(guide, 'utf8')).toBe('# Mine\n')
227+
expect(existsSync(join(outDir, '.sim/AGENTS.md'))).toBe(true)
228+
})
229+
208230
it.each(['workflow', 'workspace'] as const)(
209231
'names in the %s primer only commands and flags this CLI has',
210232
(kind) => {

‎packages/sim-cli/src/commands/protocol/workflow-source-status.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,27 @@ describe('workflows source status', () => {
288288
expect(readFileSync(file, 'utf8')).toContain('applying never sends it: functions/notes.js')
289289
})
290290

291+
it('lists the plan errors in --summary-file, not only their count', async () => {
292+
mockRequest.mockResolvedValue(
293+
dryRun([
294+
{
295+
code: 'E_UNRESOLVED_BLOCK',
296+
severity: 'error',
297+
message: 'No block named score.',
298+
file: 'workflow.ts',
299+
line: 4,
300+
},
301+
])
302+
)
303+
const file = join(root, 'status.md')
304+
305+
await run(root, 'status', '--summary-file', file)
306+
307+
expect(readFileSync(file, 'utf8')).toContain(
308+
'`E_UNRESOLVED_BLOCK` workflow.ts:4: No block named score.'
309+
)
310+
})
311+
291312
it('does not report a recorded function file as deleted once no codeFile() names it but it is still on disk', async () => {
292313
write(
293314
root,

0 commit comments

Comments
 (0)