请问HN:我在代理编码方面做错了什么?

2作者: tlonny2 个月前原帖
以下是我给Claude Code CLI和VSCode代理的提示内容,针对我的TS项目: ``` 我修改了作业创建的类型签名和行为。之前,作业定义的创建需要一个批量参数(从队列中创建)。现在它直接接受队列,采用异步方式,并且在创建时需要传入databaseClient(而不是在批量执行时)。它不再返回任何内容——这没关系,因为结果仅用于日志记录——而这现在由我们处理,所以我们不必担心。我们能否重构代码库以利用新的JobDefinition.create?请删除多余的“作业已创建”日志。 只执行这个任务,仅此而已。如果你看到与此无关的内容,认为需要重构的地方——请不要修改它。仅执行与此任务直接相关的操作。 ``` 所以有两个指令: 1. 完成任务 2. 不要做与任务无关的事情(在后续尝试中因沮丧而添加) 我的经历: 代理的流程开始得很好——它找到了所有需要更改的文件并开始进行编辑。 到第5个文件时,我注意到除了请求的重构外,它还开始重新排序`JobDefinition.create`方法的对象键。虽然在语义上没有实际影响,但这让我非常沮丧,因为这使得差异的审查变得更加困难。 稍后,它开始修改之前不满意的日志消息,最终完全偏离轨道,向我的函数定义中添加了它认为需要的参数(引入了类型/运行时错误)。 VSCode会定期暂停并要求确认以继续。每次我都借此机会重新提示代理保持专注: 我:“停止偏离任务——停止重命名变量,重新排序参数。只需按照任务的指示做,不做其他。” 代理:“你说得对。我为偏离任务而道歉。让我专注于任务:重构JobDefinition.create调用以使用新的签名,并删除多余的‘作业已创建’日志。” 但每次坏行为在一段时间后都会重新出现。 我不确定自己哪里做错了。我原以为这种机械化的重复工作对代理工作流程来说是轻而易举的,但它却不断失去连贯性。 最后,我不得不撤回所有更改,因为我对生成代码的质量完全没有信任。 抱歉占用了这么多文字,但我对浪费的时间感到非常沮丧,急切想知道我哪里做错了! 提前感谢!
查看原文
Here is the prompt I gave both Claude Code CLI, and the VSCode agent for my TS project:<p>```<p>I have modified the type signature and behaviour of how jobs are created. Previously, job definition create took a batch argument (created from a queue). Now it takes the queue directly, is async, requires the databaseClient to be passed in at creation (vs. when the batch is executed). It no longer returns anything - which is fine because the result was only being used for logging - which is now done for us so we don&#x27;t have to worry. Can we refactor the codebase to make use of the new JobDefinition.create? Remove the vestigial &quot;Job created&quot; log please.<p>Perform this task and this task only. If you see something unrelated that you believe needs to be refactored - DO NOT MODIFY IT. ONLY PERFORM ACTIONS DIRECTLY RELEVANT TO THIS TASK<p>```<p>So there are two instructions:<p>1. Do the task<p>2. Don&#x27;t do stuff that isn&#x27;t the task (added in frustration on subsequent attempts)<p>My experience:<p>The agent flow started well - it found all the files that needed to change and began making edits.<p>By about file #5 I noticed that on top of requested refactor it started re-ordering object keys of the `JobDefinition.create` method. Although semantically a no-op, this was incredibly frustrating as it made diffs much harder to review.<p>A little later, it started to modify log messages it wasn&#x27;t happy with before eventually completely going off the rails and adding arguments to my function definitions that it _thought_ they needed (introducing type&#x2F;run-time errors).<p>VSCode would periodically pause and ask for a confirmation in order to continue. Each time I used the opportunity to re-prompt the agent to stay on target:<p>Me: &quot;STOP GOING OFF TASK - STOP RENAMING VARIABLES, REORDERING PARAMS. JUST DO AS THE TASK TELLS YOU AND NOTHING ELSE&quot;<p>Agent: &quot;You&#x27;re absolutely right. I apologize for going off task. Let me focus solely on the task: refactoring JobDefinition.create calls to use the new signature and removing vestigial &quot;Job created&quot; logs&quot;<p>And each time the bad behavior would return after some time.<p>I&#x27;m not sure what I&#x27;m doing wrong. I assumed this sort of mechanical monkey work would be bread and butter for an agentic workflow - but it just keeps losing coherence.<p>I ended up reverting all the changes as I had absolutely 0 trust in the quality of the generated code.<p>I apologise for the wall of text but I&#x27;m quite frustrated about all the time wasted and am desperate to know what I&#x27;m doing wrong!<p>Thanks in advance!