fix: route document asks to comment-first askClaude (plan T6 Step 4); machine-author guard + offer cleanup
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+25
-7
@@ -192,12 +192,17 @@ export class ThreadController implements vscode.Disposable {
|
||||
end: document.offsetAt(editor.selection.end),
|
||||
};
|
||||
const fp = buildFingerprint(document.getText(), offsets);
|
||||
const { threadId } = addThread(state.artifact, fp, { author: this.currentAuthor(), body: firstBody });
|
||||
const author = this.currentAuthor();
|
||||
const { threadId } = addThread(state.artifact, fp, { author, body: firstBody });
|
||||
this.persist(state);
|
||||
const vsThread = this.renderThread(document, state, threadId, offsets, false);
|
||||
// D10: the first message of a new thread is also "a comment on a coedited
|
||||
// doc" — run the same respond loop as a reply.
|
||||
void this.respondInThread(vsThread, state, threadId, firstBody);
|
||||
// doc" — run the same respond loop as a reply. Finding 2 guard: only for a
|
||||
// human-authored message (never re-trigger the loop off the machine's own
|
||||
// words — see reply() below for the matching guard).
|
||||
if (author.kind !== "agent") {
|
||||
void this.respondInThread(vsThread, state, threadId, firstBody);
|
||||
}
|
||||
return threadId;
|
||||
}
|
||||
|
||||
@@ -210,9 +215,10 @@ export class ThreadController implements vscode.Disposable {
|
||||
if (!document) return;
|
||||
const state = this.ensureState(document);
|
||||
if (this.guard.isReadOnly(state.docPath)) return;
|
||||
const author = this.currentAuthor();
|
||||
let threadId = this.threadIdOf(vsThread);
|
||||
if (threadId) {
|
||||
appendMessage(state.artifact, threadId, { author: this.currentAuthor(), body: r.text });
|
||||
appendMessage(state.artifact, threadId, { author, body: r.text });
|
||||
} else {
|
||||
// D10/D19: a brand-new thread created via the native "+"/comment-widget
|
||||
// gesture (not via createThreadOnSelection) — VS Code hands us a real,
|
||||
@@ -223,7 +229,7 @@ export class ThreadController implements vscode.Disposable {
|
||||
end: document.offsetAt(range.end),
|
||||
};
|
||||
const fp = buildFingerprint(document.getText(), offsets);
|
||||
const created = addThread(state.artifact, fp, { author: this.currentAuthor(), body: r.text });
|
||||
const created = addThread(state.artifact, fp, { author, body: r.text });
|
||||
threadId = created.threadId;
|
||||
state.vsThreads.set(threadId, vsThread);
|
||||
state.live.set(threadId, offsets);
|
||||
@@ -231,8 +237,14 @@ export class ThreadController implements vscode.Disposable {
|
||||
}
|
||||
this.persist(state);
|
||||
this.refreshComments(vsThread, state, threadId);
|
||||
// D10: every human comment on a coedited doc runs a turn.
|
||||
void this.respondInThread(vsThread, state, threadId, r.text);
|
||||
// D10: every HUMAN comment on a coedited doc runs a turn. Finding 2 guard:
|
||||
// `cowriting.reply` is the ingress for both a genuine human reply and (in
|
||||
// principle) a re-dispatched machine message — never loop the machine's own
|
||||
// reply back through respondInThread (it would double-turn on Claude's words
|
||||
// and re-flip an already-"offer" thread).
|
||||
if (author.kind !== "agent") {
|
||||
void this.respondInThread(vsThread, state, threadId, r.text);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -310,6 +322,12 @@ export class ThreadController implements vscode.Disposable {
|
||||
const target = this.targetOf(doc, vsThread);
|
||||
const ids = await this.editFlow.runEditAndPropose(doc, target, offer.ask);
|
||||
vsThread.contextValue = "offer-done";
|
||||
// Finding 3 (seam hygiene): drop the offer once it's spent — otherwise the
|
||||
// `makeThreadEdit(threadId, docPath)` test seam (or a stray second UI click,
|
||||
// now dead per contextValue but still a valid direct call) could re-run the
|
||||
// same edit a second time. A future offer on this thread is a fresh
|
||||
// respondInThread() call, which re-populates the WeakMap entry.
|
||||
this.offers.delete(vsThread);
|
||||
if (ids.length) {
|
||||
void vscode.window.showInformationMessage(
|
||||
`Cowriting: ${ids.length} pending change${ids.length === 1 ? "" : "s"} landed in the buffer — ✓ Keep / ✗ Reject there.`,
|
||||
|
||||
Reference in New Issue
Block a user