drafted 1.19.18 → 1.19.19

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.
Files changed (2) hide show
  1. package/cli/drafted.mjs +14 -5
  2. package/package.json +1 -1
package/cli/drafted.mjs CHANGED
@@ -300,11 +300,20 @@ async function readApiGet(command, apiPath, org) {
300
300
  // A valid session now targets the server it was minted for (see getServerUrl),
301
301
  // so a 401/403 here means the credential is genuinely missing/expired — surface
302
302
  // an actionable next step instead of the bare server "Unauthenticated" string.
303
- if (res.status === 401 || res.status === 403) {
304
- // Name BOTH paths. `drafted login` is interactive, so an agent that reads
305
- // only this line hands its user a shell command instead of a link — which
306
- // is what happened. An agent should call the MCP auth tool and surface the
307
- // URL it returns; approval writes the shared auth file, fixing the CLI too.
303
+ // THE SERVER'S MESSAGE WINS. This used to replace every 401/403 with "your
304
+ // session is missing or expired — run `drafted login`", which is a guess. A
305
+ // valid, signed-in session that simply had not been NAMED yet returns 403
306
+ // {code:'session_unnamed'} with the exact remedy in the body and that got
307
+ // discarded and reported as an auth failure, sending readers off to re-run a
308
+ // device-code login that could never fix it. Only invent a message when the
309
+ // server sent none.
310
+ // A bare `{"error":"Unauthenticated"}` explains nothing, so the actionable
311
+ // auth message is genuinely better. A body with a `code` is the server
312
+ // naming a SPECIFIC condition (session_unnamed, and anything added later)
313
+ // and usually carrying its own remedy — replacing that is what sent the last
314
+ // reader off to re-run a login that could not have helped.
315
+ const serverNamedTheReason = typeof data?.code === 'string' && data.code && data.code !== 'unauthenticated';
316
+ if ((res.status === 401 || res.status === 403) && !serverNamedTheReason) {
308
317
  msg = `Not authenticated for ${serverUrl} — your Drafted session is missing or expired. `
309
318
  + `If you are a person at a terminal: run \`drafted login\`. `
310
319
  + `If you are an agent: call the Drafted MCP auth tool with action="get_link" and give the URL to your user — you cannot complete a sign-in yourself. `
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drafted",
3
- "version": "1.19.18",
3
+ "version": "1.19.19",
4
4
  "description": "Drafted — visual thinking surface for humans and AI agents. Renders HTML, markdown, images, and code as frames on a zoomable canvas, with MCP tools for AI agents and real-time sync for humans.",
5
5
  "type": "module",
6
6
  "files": [