drafted 1.11.11 → 1.11.12
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.
- package/cli/drafted.mjs +42 -3
- package/package.json +1 -1
package/cli/drafted.mjs
CHANGED
|
@@ -23,7 +23,12 @@ const __dirname = dirname(__filename);
|
|
|
23
23
|
const DEFAULT_STATE_DIR = join(homedir(), '.drafted');
|
|
24
24
|
const DEFAULT_PROJECTS_FILE = join(DEFAULT_STATE_DIR, 'projects.json');
|
|
25
25
|
const DEFAULT_PID_FILE = join(DEFAULT_STATE_DIR, 'server.pid');
|
|
26
|
-
|
|
26
|
+
// Honor DRAFTED_AUTH_FILE so the CLI reads the SAME credential file the MCP does.
|
|
27
|
+
// install-mcp.sh's --local mode points the MCP at auth.local.json via this env var;
|
|
28
|
+
// without honoring it here the CLI would read auth.json while the MCP used a
|
|
29
|
+
// different file, and the two would disagree about who is signed in (DRAFT-32).
|
|
30
|
+
const DEFAULT_AUTH_FILE = process.env.DRAFTED_AUTH_FILE || join(DEFAULT_STATE_DIR, 'auth.json');
|
|
31
|
+
const DEFAULT_CONFIG_FILE = join(DEFAULT_STATE_DIR, 'config.json');
|
|
27
32
|
const DEFAULT_PORT = 3477;
|
|
28
33
|
const PACKAGE_VERSION = (() => {
|
|
29
34
|
try {
|
|
@@ -133,11 +138,37 @@ function isServerRunning() {
|
|
|
133
138
|
}
|
|
134
139
|
}
|
|
135
140
|
|
|
136
|
-
// Helper:
|
|
141
|
+
// Helper: Read the install's server URL from ~/.drafted/config.json. This is the
|
|
142
|
+
// SAME file the MCP server reads (written by install-mcp.sh), so the CLI and MCP
|
|
143
|
+
// resolve to the same deployment.
|
|
144
|
+
function readConfigServer() {
|
|
145
|
+
try {
|
|
146
|
+
if (existsSync(DEFAULT_CONFIG_FILE)) {
|
|
147
|
+
const cfg = JSON.parse(readFileSync(DEFAULT_CONFIG_FILE, 'utf8'));
|
|
148
|
+
return cfg.server || cfg.publicUrl || null;
|
|
149
|
+
}
|
|
150
|
+
} catch { /* ignore unreadable/corrupt config */ }
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Helper: Get server URL.
|
|
155
|
+
// Precedence mirrors the MCP so a CLI invocation transparently targets the SAME
|
|
156
|
+
// server the MCP (and the stored session) use — fixing DRAFT-32, where a CLI
|
|
157
|
+
// holding a valid cloud session defaulted to localhost and got "Unauthenticated":
|
|
158
|
+
// 1. DRAFTED_SERVER env / --server flag (explicit override; --server sets the env var)
|
|
159
|
+
// 2. the auth file's `server` field — where the stored session is actually valid
|
|
160
|
+
// 3. ~/.drafted/config.json (written by install-mcp.sh; the file the MCP reads)
|
|
161
|
+
// 4. localhost (no cloud install configured)
|
|
162
|
+
// (2) is preferred over (3) because the session cookie is only valid on the
|
|
163
|
+
// server it was minted for; sending it anywhere else just yields a 401.
|
|
137
164
|
function getServerUrl() {
|
|
138
165
|
if (process.env.DRAFTED_SERVER) {
|
|
139
166
|
return process.env.DRAFTED_SERVER.replace(/\/$/, '');
|
|
140
167
|
}
|
|
168
|
+
const fromAuth = readAuth()?.server;
|
|
169
|
+
if (fromAuth) return String(fromAuth).replace(/\/$/, '');
|
|
170
|
+
const fromConfig = readConfigServer();
|
|
171
|
+
if (fromConfig) return String(fromConfig).replace(/\/$/, '');
|
|
141
172
|
return `http://localhost:${process.env.DRAFTED_PORT || DEFAULT_PORT}`;
|
|
142
173
|
}
|
|
143
174
|
|
|
@@ -252,7 +283,15 @@ async function readApiGet(command, apiPath, org) {
|
|
|
252
283
|
}
|
|
253
284
|
const data = await res.json().catch(() => ({}));
|
|
254
285
|
if (!res.ok) {
|
|
255
|
-
|
|
286
|
+
let msg = data.error || `HTTP ${res.status}`;
|
|
287
|
+
// A valid session now targets the server it was minted for (see getServerUrl),
|
|
288
|
+
// so a 401/403 here means the credential is genuinely missing/expired — surface
|
|
289
|
+
// an actionable next step instead of the bare server "Unauthenticated" string.
|
|
290
|
+
if (res.status === 401 || res.status === 403) {
|
|
291
|
+
msg = `Not authenticated for ${serverUrl} — your Drafted session is missing or expired. `
|
|
292
|
+
+ `Run \`drafted login\` to sign in. `
|
|
293
|
+
+ `The CLI and MCP share ${DEFAULT_AUTH_FILE}, so signing in once works for both.`;
|
|
294
|
+
}
|
|
256
295
|
jsonOut(false, command, msg);
|
|
257
296
|
console.error(`❌ ${msg}`);
|
|
258
297
|
process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drafted",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.12",
|
|
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": [
|