From 890386153994e228891ee9edaf641ad615798015 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 00:54:40 +0000 Subject: [PATCH 1/2] Updating a diff from its directory never starts a second diff An agent that named the diff's parent again on an update made the helper mint a new bit, so a creator iterating on a diff draft got a second diff (or, with Claude's auto mode, a blocked call and a stuck approval). Naming the same parent now updates the diff, every update carries the parent, bind accepts a draft that was never published, and publish_directory's fields say when to send them. Release 0.9.9. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Ur9VQtEaLwvb6HitGELh2q --- CHANGELOG.md | 11 +++++ directory/differ/.claude-plugin/plugin.json | 2 +- directory/differ/.codex-plugin/plugin.json | 4 +- directory/differ/plugin.json | 4 +- helper/client.mjs | 36 ++++++++++++++-- helper/main.mjs | 8 +++- package-lock.json | 4 +- package.json | 2 +- plugins/differ/.claude-plugin/plugin.json | 2 +- plugins/differ/.codex-plugin/plugin.json | 2 +- plugins/differ/plugin.json | 2 +- plugins/differ/scripts/differ.cjs | 41 ++++++++++++++---- test/fake-control.mjs | 12 +++++- test/publishing.test.mjs | 46 +++++++++++++++++++++ test/tools.test.mjs | 5 ++- 15 files changed, 153 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 745cced..a011d4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## 0.9.9 + +- Updating a diff from its directory no longer starts a second diff when the + agent names the same parent again; only another parent or `newBit` starts a + new bit. Every update carries the diff's parent, so its lineage is kept. +- `bind` (and the new `bind_directory` tool) points a directory at the + connected creator's draft that was never published, instead of refusing it + as not ready. The next upload replaces that draft. +- `publish_directory` describes `newBit`, `parentBitId` and `parentVersionId`, + and says how to update a bit or a diff. + ## 0.9.8 - Skills synced from Control: a bit can read its own post's comments and diff --git a/directory/differ/.claude-plugin/plugin.json b/directory/differ/.claude-plugin/plugin.json index 7ccc45d..d2c98d2 100644 --- a/directory/differ/.claude-plugin/plugin.json +++ b/directory/differ/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "differ", - "version": "0.9.8", + "version": "0.9.9", "description": "Make, publish and diff interactive bits on Differ.", "author": { "name": "Sky Valley", diff --git a/directory/differ/.codex-plugin/plugin.json b/directory/differ/.codex-plugin/plugin.json index f570c73..0dda387 100644 --- a/directory/differ/.codex-plugin/plugin.json +++ b/directory/differ/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "differ", - "version": "0.9.8", + "version": "0.9.9", "description": "Make, publish and diff interactive bits on Differ.", "author": { "name": "Sky Valley", @@ -95,7 +95,7 @@ "commerce_description": "Differ does not sell anything or take payments." }, "publication": { - "release_notes": "Differ 0.9.8: make, publish and diff bits; publish as a guest or connect a Differ account." + "release_notes": "Differ 0.9.9: make, publish and diff bits; publish as a guest or connect a Differ account." } } } diff --git a/directory/differ/plugin.json b/directory/differ/plugin.json index 0305fc2..9c9bba6 100644 --- a/directory/differ/plugin.json +++ b/directory/differ/plugin.json @@ -1,7 +1,7 @@ { "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json", "name": "differ", - "version": "0.9.8", + "version": "0.9.9", "description": "Make, publish and diff interactive bits on Differ.", "author": { "name": "Sky Valley", @@ -97,7 +97,7 @@ "commerce_description": "Differ does not sell anything or take payments." }, "publication": { - "release_notes": "Differ 0.9.8: make, publish and diff bits; publish as a guest or connect a Differ account." + "release_notes": "Differ 0.9.9: make, publish and diff bits; publish as a guest or connect a Differ account." } } } diff --git a/helper/client.mjs b/helper/client.mjs index e007dd1..da4ccaf 100644 --- a/helper/client.mjs +++ b/helper/client.mjs @@ -1,4 +1,4 @@ -import { lstatSync, readdirSync, readFileSync, writeFileSync, mkdirSync, existsSync, unlinkSync } from 'node:fs'; +import { lstatSync, readdirSync, readFileSync, writeFileSync, mkdirSync, existsSync, unlinkSync, rmSync } from 'node:fs'; import { join, resolve, dirname, relative } from 'node:path'; import { createServer } from 'node:http'; import { randomUUID, randomBytes } from 'node:crypto'; @@ -119,6 +119,10 @@ export async function bind(directory, bitId) { try { const state = stateFor(directory, config, true); if (state.pending) throw problem('pending_publication', 'Reconcile the pending publication first.', 'Run status.'); + const current = await publicState(config, bitId); + // A creator's draft that was never published has no public version to + // name: bind as its creator, and the next upload replaces that draft. + if (!current.bit && current.claimed) return bindDraft(directory, config, state, bitId); const bit = await getBit(bitId); if (state.bit && state.bit.id !== bit.id) { state.previous = [...(state.previous ?? []), { bit: state.bit, receipt: state.receipt, lastInput: state.lastInput }]; @@ -131,6 +135,22 @@ export async function bind(directory, bitId) { return { bound: true, bitId: bit.id, expectedVersionId: bit.currentVersionId, recovery: 'Local files were not changed. Publish only after deliberately reconciling this draft with the current bit.' }; } finally { unlock(); } } +async function bindDraft(directory, config, state, bitId) { + const me = await account(config); + if (!me) throw problem('connection_required', 'This bit is a draft that was never published; only its creator can update it.', 'Connect as its creator, then bind again. To make your own version instead, publish a diff of a published bit.'); + if (state.bit?.id !== bitId) { + if (state.bit) state.previous = [...(state.previous ?? []), { bit: state.bit, receipt: state.receipt, lastInput: state.lastInput }]; + // Control checks the upload is the creator's; the source stays the draft's own. + state.bit = { id: bitId, mode: 'connected', accountHandle: me.handle }; + } + state.receipt = { bitId, versionId: null }; + delete state.lastInput; + atomic(statePath(directory), state); + // differ-bit.json names a published version; a draft has none yet, so the + // next upload writes it. + rmSync(join(directory, bindingName), { force: true }); + return { bound: true, bitId, draft: true, expectedVersionId: null, recovery: 'Local files were not changed. The next publish replaces this draft; it stays unpublished until the creator publishes it in Differ.' }; +} // The bearer decides who a publication acts for: the connected creator for its // own drafts and for guest bits it has since claimed, otherwise the guest // upload pass. A claimed bit is the account's when Control names its handle. @@ -183,14 +203,21 @@ async function publishCreator(config, state, directory, artifact, caption, { new if (recovered.state === 'succeeded') return { ...recovered, recovered: true, recovery: 'Recovered the previous upload. Run publish again only if more edits were requested.' }; if (state.pending.artifactId !== artifact.artifactId || state.pending.caption !== caption || !!state.pending.publish !== now) throw problem('pending_changed', 'Pending publication belongs to different content.', 'Restore the pending content/caption and retry; never discard uncertain state.'); } - if (!state.pending && (newBit || parentBitId)) { + // A diff's directory keeps updating that diff: naming its own parent again + // is an update, and an update names the parent the diff was made from. + // Only --new or another parent starts another bit. + const saved = state.bit?.parent ?? (state.lastInput?.parentBitId ? { bitId: state.lastInput.parentBitId, versionId: state.lastInput.parentVersionId } : undefined); + const sameDiff = !!(parentBitId && saved && saved.bitId === parentBitId && saved.versionId === parentVersionId); + const fork = !state.pending && (newBit || (parentBitId && !sameDiff)); + if (fork) { state.previous = [...(state.previous ?? []), { bit: state.bit, receipt: state.receipt, lastInput: state.lastInput }]; delete state.bit; delete state.receipt; delete state.lastInput; } if (!state.bit) { if (state.receipt && !me) throw problem('ownership_required', 'A public bit binding does not grant editing rights.', 'Use the original private workspace or connect the owner. To make your own, create a diff.'); state.bit = { id: state.receipt?.bitId ?? randomUUID(), mode: me ? 'connected' : 'guest', - ...(me ? { accountHandle: me.handle } : { ownerProof: randomBytes(32).toString('hex') }) }; + ...(me ? { accountHandle: me.handle } : { ownerProof: randomBytes(32).toString('hex') }), + ...(parentBitId ? { parent: { bitId: parentBitId, versionId: parentVersionId } } : {}) }; atomic(statePath(directory), state); } if (state.bit.mode === 'guest' && !state.bit.uploadToken) { @@ -203,8 +230,9 @@ async function publishCreator(config, state, directory, artifact, caption, { new // that is now to be published. if (!state.pending && state.receipt?.artifactId === artifact.artifactId && state.lastInput?.caption === caption && !(now && state.receipt.draft)) return creatorStatus(config, state, directory, me); const bearer = await bearerFor(config, state, me); + const parent = parentBitId ? { bitId: parentBitId, versionId: parentVersionId } : state.bit.parent ?? (fork ? undefined : saved); const input = state.pending ?? { requestId: randomUUID(), artifactId: artifact.artifactId, caption, - expectedVersionId: state.receipt?.versionId ?? null, ...(parentBitId ? { parentBitId, parentVersionId } : {}), ...(now ? { publish: true } : {}) }; + expectedVersionId: state.receipt?.versionId ?? null, ...(parent ? { parentBitId: parent.bitId, parentVersionId: parent.versionId } : {}), ...(now ? { publish: true } : {}) }; state.pending = input; atomic(statePath(directory), state); let receipt; try { receipt = await request(config.url, `/v1/publishing/bits/${state.bit.id}/versions`, { bearer, body: draft(input, artifact.files) }); } diff --git a/helper/main.mjs b/helper/main.mjs index 6014e8f..5e8f773 100644 --- a/helper/main.mjs +++ b/helper/main.mjs @@ -27,10 +27,12 @@ async function mcp() { server.registerTool('publisher_status', { description: 'Check publishing service access, account, and limits. No publication.', inputSchema: {}, annotations }, wrap(doctor)); server.registerTool('check_content', { description: 'Validate local static files without uploading or publishing. Reports shared participation as unverified: read the participation reference and examples and rehearse with the real runtime. Does not test authorization, live updates or browser behavior.', inputSchema: { directory }, annotations }, wrap(({ directory }) => check(directory))); server.registerTool('publish_directory', { - description: 'Upload content when the human asks. Works as a guest without sign-in, or as the deliberately connected creator. A new directory creates a bit; its saved identity uploads a new version of that bit. Connected uploads are drafts: when the receipt has draft:true, say it is not published yet and show its url, where the maker previews it, confirms its caption and publishes it. For guests show the url, private claim link, expiry and unclaimed notice; never hide them or block publishing to demand sign-in.', + description: 'Upload content when the human asks. Works as a guest without sign-in, or as the deliberately connected creator. A new directory creates a bit; its saved identity uploads a new version of that bit, or replaces its draft, so to update a bit or a diff call it again with the same directory. To update a draft made from another directory, run bind with its bit id first. Connected uploads are drafts: when the receipt has draft:true, say it is not published yet and show its url, where the maker previews it, confirms its caption and publishes it. For guests show the url, private claim link, expiry and unclaimed notice; never hide them or block publishing to demand sign-in.', inputSchema: { directory, caption: z.string().optional().describe("The maker's own words shown over the bit: 1–200 characters, at most 3 line breaks, checked before upload. Suggest it and let the maker confirm it; they confirm it again in Differ before the bit goes public. Defaults to the caption differ-bit.json saved for this bit."), - newBit: z.boolean().optional(), parentBitId: z.string().uuid().optional(), parentVersionId: z.string().uuid().optional(), + newBit: z.boolean().optional().describe('true only when the human asked for a separate, unrelated bit from this directory. Omit it to update the bit this directory already published or drafted.'), + parentBitId: z.string().uuid().optional().describe("For a diff's first upload: the source bit's id, with parentVersionId. Later uploads from the same directory update that diff whether or not you name it again; another parent starts another diff."), + parentVersionId: z.string().uuid().optional().describe("For a diff's first upload: the source bit's exact version id."), publish: z.boolean().optional().describe('Connected creators only: true only when the human explicitly asked to publish now without previewing, with the caption they confirmed. Otherwise omit it, and the upload waits as a draft.') }, annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true }, }, wrap(({ directory, caption, ...options }) => publish(directory, caption, options))); @@ -46,6 +48,8 @@ async function mcp() { server.registerTool('connection_status', { description: 'Check the saved connection with Differ, or finish connecting after the human approves the connection link. Respect retryAfter; do not poll in a tight loop.', inputSchema: {}, annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false } }, wrap(connectionStatus)); server.registerTool('disconnect_account', { description: 'Only when the human requests it, revoke this agent connection and explicitly return future publishing to guest mode. Existing bits keep their ownership.', inputSchema: {}, annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: false } }, wrap(disconnect)); server.registerTool('publication_status', { description: 'Recover a pending publication or verify the saved receipt for a local directory.', inputSchema: { directory }, annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false } }, wrap(({ directory }) => status(directory))); + server.registerTool('bind_directory', { description: "Point a directory at an existing bit, or at the connected creator's draft that was never published, so the next publish_directory updates it. Only after the human asked to update that bit and you compared it; local files are not changed.", + inputSchema: { directory, bitId: z.string().uuid() }, annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false } }, wrap(({ directory, bitId }) => bind(directory, bitId))); server.registerTool('get_bit', { description: 'Inspect a remote bit and its versions before conflict recovery or diffing.', inputSchema: { bitId: z.string().uuid() }, annotations }, wrap(({ bitId }) => getBit(bitId))); server.registerTool('image_candidate', { description: 'Create a separate WebP candidate using installed cwebp. Never replaces source or adopts visual quality automatically.', inputSchema: { source: z.string(), output: z.string(), quality: z.number().min(0).max(100).optional() }, annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false } }, wrap(({ source, output, quality }) => imageCandidate(source, output, quality))); server.registerTool('inspect_video', { description: 'Read recording dimensions, codec, duration and encoded frame rate using installed ffprobe. Not proof of smooth motion or good composition.', inputSchema: { file: z.string() }, annotations }, wrap(({ file }) => inspectVideo(file))); diff --git a/package-lock.json b/package-lock.json index 2f8fefe..79b40c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "differ-plugin", - "version": "0.9.8", + "version": "0.9.9", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "differ-plugin", - "version": "0.9.8", + "version": "0.9.9", "license": "MIT", "dependencies": { "@modelcontextprotocol/sdk": "1.32.1", diff --git a/package.json b/package.json index 96661ac..0ad573b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "differ-plugin", - "version": "0.9.8", + "version": "0.9.9", "private": true, "type": "module", "engines": { diff --git a/plugins/differ/.claude-plugin/plugin.json b/plugins/differ/.claude-plugin/plugin.json index 7ccc45d..d2c98d2 100644 --- a/plugins/differ/.claude-plugin/plugin.json +++ b/plugins/differ/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "differ", - "version": "0.9.8", + "version": "0.9.9", "description": "Make, publish and diff interactive bits on Differ.", "author": { "name": "Sky Valley", diff --git a/plugins/differ/.codex-plugin/plugin.json b/plugins/differ/.codex-plugin/plugin.json index e9fc46d..5949e42 100644 --- a/plugins/differ/.codex-plugin/plugin.json +++ b/plugins/differ/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "differ", - "version": "0.9.8", + "version": "0.9.9", "description": "Make, publish and diff interactive bits on Differ.", "author": { "name": "Sky Valley", diff --git a/plugins/differ/plugin.json b/plugins/differ/plugin.json index 3f035ae..f3c245d 100644 --- a/plugins/differ/plugin.json +++ b/plugins/differ/plugin.json @@ -1,7 +1,7 @@ { "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json", "name": "differ", - "version": "0.9.8", + "version": "0.9.9", "description": "Make, publish and diff interactive bits on Differ.", "author": { "name": "Sky Valley", diff --git a/plugins/differ/scripts/differ.cjs b/plugins/differ/scripts/differ.cjs index b2fc327..de51ce5 100644 --- a/plugins/differ/scripts/differ.cjs +++ b/plugins/differ/scripts/differ.cjs @@ -39594,6 +39594,8 @@ async function bind(directory, bitId) { try { const state = stateFor(directory, config2, true); if (state.pending) throw problem("pending_publication", "Reconcile the pending publication first.", "Run status."); + const current = await publicState(config2, bitId); + if (!current.bit && current.claimed) return bindDraft(directory, config2, state, bitId); const bit = await getBit(bitId); if (state.bit && state.bit.id !== bit.id) { state.previous = [...state.previous ?? [], { bit: state.bit, receipt: state.receipt, lastInput: state.lastInput }]; @@ -39608,6 +39610,19 @@ async function bind(directory, bitId) { unlock(); } } +async function bindDraft(directory, config2, state, bitId) { + const me = await account(config2); + if (!me) throw problem("connection_required", "This bit is a draft that was never published; only its creator can update it.", "Connect as its creator, then bind again. To make your own version instead, publish a diff of a published bit."); + if (state.bit?.id !== bitId) { + if (state.bit) state.previous = [...state.previous ?? [], { bit: state.bit, receipt: state.receipt, lastInput: state.lastInput }]; + state.bit = { id: bitId, mode: "connected", accountHandle: me.handle }; + } + state.receipt = { bitId, versionId: null }; + delete state.lastInput; + atomic(statePath(directory), state); + (0, import_node_fs3.rmSync)((0, import_node_path4.join)(directory, bindingName), { force: true }); + return { bound: true, bitId, draft: true, expectedVersionId: null, recovery: "Local files were not changed. The next publish replaces this draft; it stays unpublished until the creator publishes it in Differ." }; +} async function bearerFor(config2, state, me) { const bit = state.bit; if (me === void 0) me = await account(config2); @@ -39654,7 +39669,10 @@ async function publishCreator(config2, state, directory, artifact, caption2, { n if (recovered.state === "succeeded") return { ...recovered, recovered: true, recovery: "Recovered the previous upload. Run publish again only if more edits were requested." }; if (state.pending.artifactId !== artifact.artifactId || state.pending.caption !== caption2 || !!state.pending.publish !== now) throw problem("pending_changed", "Pending publication belongs to different content.", "Restore the pending content/caption and retry; never discard uncertain state."); } - if (!state.pending && (newBit || parentBitId)) { + const saved2 = state.bit?.parent ?? (state.lastInput?.parentBitId ? { bitId: state.lastInput.parentBitId, versionId: state.lastInput.parentVersionId } : void 0); + const sameDiff = !!(parentBitId && saved2 && saved2.bitId === parentBitId && saved2.versionId === parentVersionId); + const fork = !state.pending && (newBit || parentBitId && !sameDiff); + if (fork) { state.previous = [...state.previous ?? [], { bit: state.bit, receipt: state.receipt, lastInput: state.lastInput }]; delete state.bit; delete state.receipt; @@ -39665,7 +39683,8 @@ async function publishCreator(config2, state, directory, artifact, caption2, { n state.bit = { id: state.receipt?.bitId ?? (0, import_node_crypto3.randomUUID)(), mode: me ? "connected" : "guest", - ...me ? { accountHandle: me.handle } : { ownerProof: (0, import_node_crypto3.randomBytes)(32).toString("hex") } + ...me ? { accountHandle: me.handle } : { ownerProof: (0, import_node_crypto3.randomBytes)(32).toString("hex") }, + ...parentBitId ? { parent: { bitId: parentBitId, versionId: parentVersionId } } : {} }; atomic(statePath(directory), state); } @@ -39677,12 +39696,13 @@ async function publishCreator(config2, state, directory, artifact, caption2, { n } if (!state.pending && state.receipt?.artifactId === artifact.artifactId && state.lastInput?.caption === caption2 && !(now && state.receipt.draft)) return creatorStatus(config2, state, directory, me); const bearer = await bearerFor(config2, state, me); + const parent = parentBitId ? { bitId: parentBitId, versionId: parentVersionId } : state.bit.parent ?? (fork ? void 0 : saved2); const input2 = state.pending ?? { requestId: (0, import_node_crypto3.randomUUID)(), artifactId: artifact.artifactId, caption: caption2, expectedVersionId: state.receipt?.versionId ?? null, - ...parentBitId ? { parentBitId, parentVersionId } : {}, + ...parent ? { parentBitId: parent.bitId, parentVersionId: parent.versionId } : {}, ...now ? { publish: true } : {} }; state.pending = input2; @@ -39769,7 +39789,7 @@ var import_node_child_process3 = require("node:child_process"); // package.json var package_default = { name: "differ-plugin", - version: "0.9.8", + version: "0.9.9", private: true, type: "module", engines: { @@ -41056,13 +41076,13 @@ async function mcp() { server.registerTool("publisher_status", { description: "Check publishing service access, account, and limits. No publication.", inputSchema: {}, annotations }, wrap(doctor)); server.registerTool("check_content", { description: "Validate local static files without uploading or publishing. Reports shared participation as unverified: read the participation reference and examples and rehearse with the real runtime. Does not test authorization, live updates or browser behavior.", inputSchema: { directory }, annotations }, wrap(({ directory: directory2 }) => check2(directory2))); server.registerTool("publish_directory", { - description: "Upload content when the human asks. Works as a guest without sign-in, or as the deliberately connected creator. A new directory creates a bit; its saved identity uploads a new version of that bit. Connected uploads are drafts: when the receipt has draft:true, say it is not published yet and show its url, where the maker previews it, confirms its caption and publishes it. For guests show the url, private claim link, expiry and unclaimed notice; never hide them or block publishing to demand sign-in.", + description: "Upload content when the human asks. Works as a guest without sign-in, or as the deliberately connected creator. A new directory creates a bit; its saved identity uploads a new version of that bit, or replaces its draft, so to update a bit or a diff call it again with the same directory. To update a draft made from another directory, run bind with its bit id first. Connected uploads are drafts: when the receipt has draft:true, say it is not published yet and show its url, where the maker previews it, confirms its caption and publishes it. For guests show the url, private claim link, expiry and unclaimed notice; never hide them or block publishing to demand sign-in.", inputSchema: { directory, caption: external_exports.string().optional().describe("The maker's own words shown over the bit: 1\u2013200 characters, at most 3 line breaks, checked before upload. Suggest it and let the maker confirm it; they confirm it again in Differ before the bit goes public. Defaults to the caption differ-bit.json saved for this bit."), - newBit: external_exports.boolean().optional(), - parentBitId: external_exports.string().uuid().optional(), - parentVersionId: external_exports.string().uuid().optional(), + newBit: external_exports.boolean().optional().describe("true only when the human asked for a separate, unrelated bit from this directory. Omit it to update the bit this directory already published or drafted."), + parentBitId: external_exports.string().uuid().optional().describe("For a diff's first upload: the source bit's id, with parentVersionId. Later uploads from the same directory update that diff whether or not you name it again; another parent starts another diff."), + parentVersionId: external_exports.string().uuid().optional().describe("For a diff's first upload: the source bit's exact version id."), publish: external_exports.boolean().optional().describe("Connected creators only: true only when the human explicitly asked to publish now without previewing, with the caption they confirmed. Otherwise omit it, and the upload waits as a draft.") }, annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true } @@ -41084,6 +41104,11 @@ async function mcp() { server.registerTool("connection_status", { description: "Check the saved connection with Differ, or finish connecting after the human approves the connection link. Respect retryAfter; do not poll in a tight loop.", inputSchema: {}, annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false } }, wrap(connectionStatus)); server.registerTool("disconnect_account", { description: "Only when the human requests it, revoke this agent connection and explicitly return future publishing to guest mode. Existing bits keep their ownership.", inputSchema: {}, annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: false } }, wrap(disconnect)); server.registerTool("publication_status", { description: "Recover a pending publication or verify the saved receipt for a local directory.", inputSchema: { directory }, annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false } }, wrap(({ directory: directory2 }) => status(directory2))); + server.registerTool("bind_directory", { + description: "Point a directory at an existing bit, or at the connected creator's draft that was never published, so the next publish_directory updates it. Only after the human asked to update that bit and you compared it; local files are not changed.", + inputSchema: { directory, bitId: external_exports.string().uuid() }, + annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false } + }, wrap(({ directory: directory2, bitId }) => bind(directory2, bitId))); server.registerTool("get_bit", { description: "Inspect a remote bit and its versions before conflict recovery or diffing.", inputSchema: { bitId: external_exports.string().uuid() }, annotations }, wrap(({ bitId }) => getBit(bitId))); server.registerTool("image_candidate", { description: "Create a separate WebP candidate using installed cwebp. Never replaces source or adopts visual quality automatically.", inputSchema: { source: external_exports.string(), output: external_exports.string(), quality: external_exports.number().min(0).max(100).optional() }, annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false } }, wrap(({ source, output: output3, quality }) => imageCandidate(source, output3, quality))); server.registerTool("inspect_video", { description: "Read recording dimensions, codec, duration and encoded frame rate using installed ffprobe. Not proof of smooth motion or good composition.", inputSchema: { file: external_exports.string() }, annotations }, wrap(({ file: file2 }) => inspectVideo(file2))); diff --git a/test/fake-control.mjs b/test/fake-control.mjs index b485374..0e7753b 100644 --- a/test/fake-control.mjs +++ b/test/fake-control.mjs @@ -112,14 +112,22 @@ export async function fakeControl() { return receiptView(bit, saved.receipt); } if (as.guest && bit.owner) reject(403, 'owner_conflict', 'This bit was claimed. Publish its changes as its owner.'); - if ((body.expectedVersionId ?? null) !== (bit?.draft?.id ?? bit?.versions.at(-1)?.id ?? null)) reject(409, 'version_conflict', 'The bit changed after this draft.'); + // Control's checkPublication: the expected version is the bit's current + // one, or, for its creator, the pending draft made from that current one. + const current = bit?.versions.at(-1)?.id ?? null, expected = body.expectedVersionId ?? null; + if (expected !== current && !(as.handle && bit?.draft && expected === bit.draft.id && bit.draft.basedOn === current)) reject(409, 'version_conflict', 'The bit changed after this draft.'); + const parent = body.parentBitId ? { bitId: body.parentBitId, versionId: body.parentVersionId } : undefined; + if (current && parent && (bit.parent?.bitId !== parent.bitId || bit.parent?.versionId !== parent.versionId)) reject(409, 'parent_conflict', 'A version cannot replace its original source.'); const target = bit ?? { id, owner: as.handle, versions: [], receipts: new Map() }; + // A bit not yet published takes the source an upload names and keeps its + // own when an upload names none. + if (!current && parent) target.parent = parent; bits.set(id, target); const versionId = randomUUID(); const version = { id: versionId, caption: body.caption ?? '', createdAt: new Date().toISOString() }; // A person's upload waits as the bit's draft unless it publishes now, // which replaces the draft. - if (as.handle && !now) target.draft = { ...version, expiresAt: new Date(Date.now() + 7 * 86_400_000).toISOString() }; + if (as.handle && !now) target.draft = { ...version, basedOn: current, expiresAt: new Date(Date.now() + 7 * 86_400_000).toISOString() }; else { target.versions.push(version); delete target.draft; } const receipt = { state: 'succeeded', requestId: body.requestId, bitId: id, versionId, artifactId: artifact, ...(as.handle && !now ? { draft: true } : {}) }; target.receipts.set(body.requestId, { fingerprint, receipt }); diff --git a/test/publishing.test.mjs b/test/publishing.test.mjs index d3c835d..fee4a1f 100644 --- a/test/publishing.test.mjs +++ b/test/publishing.test.mjs @@ -378,6 +378,52 @@ test('a caption is checked before upload; a new bit or a diff never inherits the assert.equal(diff.state, 'succeeded'); }); +test('a diff is updated from its directory whether or not its parent is named again; only another parent starts a new diff', async t => { + const h = await harness(t); + const source = await h.cli('publish', h.bit('source', { 'preview.html': preview, 'index.html': 'source' }), '--caption', 'Source'); + await h.connectAs('iris'); + const directory = h.bit('bouquet', { 'preview.html': preview, 'index.html': 'v1' }); + const parents = ['--parent-bit', source.bitId, '--parent-version', source.versionId]; + const first = await h.cli('publish', directory, ...parents); + assert.equal(first.draft, true); + + writeFileSync(join(directory, 'index.html'), 'v2 botanical'); + h.control.reset(); + const again = await h.cli('publish', directory, ...parents); + const repeated = h.control.calls().find(request => request.path.endsWith('/versions')); + assert.equal(again.bitId, first.bitId, 'naming the same parent again updates the diff, never starts a second one'); + assert.equal(repeated.body.expectedVersionId, first.versionId); + + writeFileSync(join(directory, 'index.html'), 'v3'); + h.control.reset(); + const plain = await h.cli('publish', directory); + const update = h.control.calls().find(request => request.path.endsWith('/versions')); + assert.equal(plain.bitId, first.bitId); + assert.deepEqual([update.body.parentBitId, update.body.parentVersionId], [source.bitId, source.versionId], 'an update carries the diff\'s parent'); + assert.deepEqual(h.control.bit(first.bitId).parent, { bitId: source.bitId, versionId: source.versionId }); + + writeFileSync(join(directory, 'index.html'), 'v4'); + const other = await h.cli('publish', directory, '--parent-bit', first.bitId, '--parent-version', first.versionId); + assert.notEqual(other.bitId, first.bitId, 'another parent is another diff'); +}); + +test('bind points another directory at a draft that was never published; the next upload replaces that draft', async t => { + const h = await harness(t); + await h.connectAs('iris'); + const first = await h.cli('publish', h.bit('first', { 'preview.html': preview, 'index.html': 'v1' })); + assert.equal(first.draft, true); + const copy = h.bit('copy', { 'preview.html': preview, 'index.html': 'v2' }); + const bound = await h.cli('bind', copy, '--bit', first.bitId); + assert.equal(bound.bound, true, JSON.stringify(bound)); + assert.equal(bound.draft, true); + h.control.reset(); + const update = await h.cli('publish', copy); + assert.equal(update.bitId, first.bitId, JSON.stringify(update)); + assert.equal(update.draft, true); + assert.equal(h.control.bit(first.bitId).draft.id, update.versionId); + assert.equal(h.control.bit(first.bitId).versions.length, 0); +}); + test('asked to publish now, a connected upload goes live with the confirmed caption; without one it stops before sending', async t => { const h = await harness(t); await h.connectAs('maker'); diff --git a/test/tools.test.mjs b/test/tools.test.mjs index e7bbca4..c3f9948 100644 --- a/test/tools.test.mjs +++ b/test/tools.test.mjs @@ -11,9 +11,12 @@ test('the local tools speak of bits, versions and captions', async () => { await client.connect(new StdioClientTransport({ command: process.execPath, args: [bundle, 'mcp'] })); try { const tools = Object.fromEntries((await client.listTools()).tools.map(tool => [tool.name, tool])); - assert.deepEqual(Object.keys(tools).sort(), ['check_content', 'connect_account', 'connection_status', 'disconnect_account', 'get_bit', 'image_candidate', 'inspect_video', 'publication_status', 'publish_directory', 'publish_place', 'publish_place_draft', 'publisher_status']); + assert.deepEqual(Object.keys(tools).sort(), ['bind_directory', 'check_content', 'connect_account', 'connection_status', 'disconnect_account', 'get_bit', 'image_candidate', 'inspect_video', 'publication_status', 'publish_directory', 'publish_place', 'publish_place_draft', 'publisher_status']); assert.deepEqual(Object.keys(tools.publish_directory.inputSchema.properties).sort(), ['caption', 'directory', 'newBit', 'parentBitId', 'parentVersionId', 'publish']); assert.deepEqual(tools.publish_directory.inputSchema.required, ['directory'], 'an upload\'s caption is a suggestion the maker confirms later'); + for (const [name, field] of Object.entries(tools.publish_directory.inputSchema.properties)) assert.ok(field.description, `publish_directory's ${name} tells the agent when to send it`); + assert.match(tools.publish_directory.inputSchema.properties.parentBitId.description, /Later uploads from the same directory update that diff/); + assert.deepEqual(Object.keys(tools.bind_directory.inputSchema.properties).sort(), ['bitId', 'directory']); assert.deepEqual(Object.keys(tools.get_bit.inputSchema.properties), ['bitId']); assert.deepEqual(Object.keys(tools.publish_place.inputSchema.properties).sort(), ['directory', 'publish']); for (const name of ['publish_place', 'publish_place_draft']) { From cdaf048ad72037909aceff046308c19f7a3728fd Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 04:02:26 +0000 Subject: [PATCH 2/2] Sync skills: a diff's later uploads update the same diff Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Ur9VQtEaLwvb6HitGELh2q --- CHANGELOG.md | 2 ++ directory/differ/skills.lock.json | 8 ++++---- .../differ/skills/publish-content/references/connector.md | 5 ++++- .../differ/skills/publish-content/references/helper.md | 8 +++++++- plugins/differ/skills.lock.json | 8 ++++---- .../differ/skills/publish-content/references/connector.md | 5 ++++- .../differ/skills/publish-content/references/helper.md | 8 +++++++- 7 files changed, 32 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a011d4d..b69b374 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ as not ready. The next upload replaces that draft. - `publish_directory` describes `newBit`, `parentBitId` and `parentVersionId`, and says how to update a bit or a diff. +- Skills synced from Control: the helper and connector references say a diff + names its parent in its first upload and later uploads update the same diff. ## 0.9.8 diff --git a/directory/differ/skills.lock.json b/directory/differ/skills.lock.json index 97a4928..837b8d2 100644 --- a/directory/differ/skills.lock.json +++ b/directory/differ/skills.lock.json @@ -32,13 +32,13 @@ }, { "uri": "skill://publish-content/references/connector.md", - "digest": "sha256:66278e88045fca08dcd72c4e19bd34a7e59e0e76d76fbaabbb1e9992ed1e9ff1", - "size": 4085 + "digest": "sha256:b4f12b6cf2ba086c7bfb24f241dfbe7c5870ffded6381a3879b6a17d446ba983", + "size": 4255 }, { "uri": "skill://publish-content/references/helper.md", - "digest": "sha256:b04642ea900279eecfb77a96ef2f8cbd2f7bdd6fd92a657106fe13cfff45c19a", - "size": 3777 + "digest": "sha256:6631806722986e0584ad22ed2e589c47bbea9111111c2843ef81474bdb152a42", + "size": 4132 }, { "uri": "skill://publish-content/references/participation.md", diff --git a/directory/differ/skills/publish-content/references/connector.md b/directory/differ/skills/publish-content/references/connector.md index fe2171c..7f9d532 100644 --- a/directory/differ/skills/publish-content/references/connector.md +++ b/directory/differ/skills/publish-content/references/connector.md @@ -70,4 +70,7 @@ it first; it then replaces their live place at once. `get_bit` reads a bit's public state and version identifiers; it grants no editing or claiming rights. For a diff, add `parentBitId` and -`parentVersionId` to the publishing request, with the maker's own caption. +`parentVersionId` to the first publishing request, with the maker's own +caption. Later uploads of that diff send its own bit `id` and the last +`versionId` you uploaded as `expectedVersionId`; the parent may be left out, +since the diff keeps it. diff --git a/directory/differ/skills/publish-content/references/helper.md b/directory/differ/skills/publish-content/references/helper.md index 0b1a2c2..7dc16bf 100644 --- a/directory/differ/skills/publish-content/references/helper.md +++ b/directory/differ/skills/publish-content/references/helper.md @@ -57,5 +57,11 @@ never in Git or uploaded assets. On uncertainty run `publication_status` / `status DIR`, then retry unchanged. Never delete pending state to retry. Conflicts require comparing the current bit (`get_bit` / `get-bit ID`); `bind DIR --bit ID` deliberately rebases after review. `--new` starts an -unrelated bit only when requested. A diff of someone's bit names its parent: +unrelated bit only when requested. A diff of someone's bit names its parent +in its first upload: `publish APP --caption CAPTION --parent-bit ID --parent-version ID`. +Every later upload from the same directory updates that diff, draft or live: +plain `publish APP` / `publish_directory` with only the directory (naming the +same parent again also updates it, never starts a second diff). To update a +draft from another directory, `bind DIR --bit ID` first; it works for a draft +that was never published. diff --git a/plugins/differ/skills.lock.json b/plugins/differ/skills.lock.json index 97a4928..837b8d2 100644 --- a/plugins/differ/skills.lock.json +++ b/plugins/differ/skills.lock.json @@ -32,13 +32,13 @@ }, { "uri": "skill://publish-content/references/connector.md", - "digest": "sha256:66278e88045fca08dcd72c4e19bd34a7e59e0e76d76fbaabbb1e9992ed1e9ff1", - "size": 4085 + "digest": "sha256:b4f12b6cf2ba086c7bfb24f241dfbe7c5870ffded6381a3879b6a17d446ba983", + "size": 4255 }, { "uri": "skill://publish-content/references/helper.md", - "digest": "sha256:b04642ea900279eecfb77a96ef2f8cbd2f7bdd6fd92a657106fe13cfff45c19a", - "size": 3777 + "digest": "sha256:6631806722986e0584ad22ed2e589c47bbea9111111c2843ef81474bdb152a42", + "size": 4132 }, { "uri": "skill://publish-content/references/participation.md", diff --git a/plugins/differ/skills/publish-content/references/connector.md b/plugins/differ/skills/publish-content/references/connector.md index fe2171c..7f9d532 100644 --- a/plugins/differ/skills/publish-content/references/connector.md +++ b/plugins/differ/skills/publish-content/references/connector.md @@ -70,4 +70,7 @@ it first; it then replaces their live place at once. `get_bit` reads a bit's public state and version identifiers; it grants no editing or claiming rights. For a diff, add `parentBitId` and -`parentVersionId` to the publishing request, with the maker's own caption. +`parentVersionId` to the first publishing request, with the maker's own +caption. Later uploads of that diff send its own bit `id` and the last +`versionId` you uploaded as `expectedVersionId`; the parent may be left out, +since the diff keeps it. diff --git a/plugins/differ/skills/publish-content/references/helper.md b/plugins/differ/skills/publish-content/references/helper.md index 0b1a2c2..7dc16bf 100644 --- a/plugins/differ/skills/publish-content/references/helper.md +++ b/plugins/differ/skills/publish-content/references/helper.md @@ -57,5 +57,11 @@ never in Git or uploaded assets. On uncertainty run `publication_status` / `status DIR`, then retry unchanged. Never delete pending state to retry. Conflicts require comparing the current bit (`get_bit` / `get-bit ID`); `bind DIR --bit ID` deliberately rebases after review. `--new` starts an -unrelated bit only when requested. A diff of someone's bit names its parent: +unrelated bit only when requested. A diff of someone's bit names its parent +in its first upload: `publish APP --caption CAPTION --parent-bit ID --parent-version ID`. +Every later upload from the same directory updates that diff, draft or live: +plain `publish APP` / `publish_directory` with only the directory (naming the +same parent again also updates it, never starts a second diff). To update a +draft from another directory, `bind DIR --bit ID` first; it works for a draft +that was never published.