drafted 1.19.43 → 1.19.44

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/mcp/server.mjs +93 -0
  2. package/package.json +1 -1
package/mcp/server.mjs CHANGED
@@ -4348,6 +4348,99 @@ tool('repo', 'Registered git repos — the org index of .agents/ skills + identi
4348
4348
  }
4349
4349
  return err(new Error(`unknown repo action: ${action}`));
4350
4350
  });
4351
+
4352
+ tool('drive', 'The org\'s Google Drive mirror: its state, and the conflicts a human would otherwise clear by hand one button at a time. Org-wide (org members only) — dispatch by `action`:\n- `status` — connection mode (`dwd` = domain-wide delegation, `oauth` = per-user), root folder, sync/pull job state, and OPEN CONFLICT COUNTS BY TYPE. Start here.\n- `conflicts` — the open conflicts (paginated, `compact` mode). Each carries `conflictType`, the Drive error, the frame label and its ids, so you can decide per file instead of guessing.\n- `resolve` — decide ONE conflict: `keep_drafted` (re-push Drafted content to Drive), `keep_drive` (pull Drive content into the frame, with a version snapshot), `duplicate_both`, `retry` (re-check on the next sync, content untouched), `ignore_once`, `archive_mirror` (stop mirroring this file).\n- `retry_all` — close EVERY open `inaccessible_file` conflict as `retry` and queue a sync. This is the right move for a pile of access failures: a broken credential files one conflict per frame, and re-checking is not a decision anyone should make hundreds of times. Files that are genuinely gone come back as fresh, accurate conflicts.\n- `sync` — queue the org push, then re-read `status`.\n\nTRIAGE ORDER that avoids wasted decisions: `status` → if `inaccessible_file` dominates, `retry_all` → `sync` → `conflicts` again, and only then decide the survivors one by one. `archive_mirror` on a stale access failure deactivates a HEALTHY mirror — prefer `retry` unless the file is really gone.', {
4353
+ action: z.enum(['status', 'conflicts', 'resolve', 'retry_all', 'sync']).describe('status: connection + conflict counts; conflicts: list them; resolve: decide one; retry_all: bulk-retry access failures; sync: queue the org push.'),
4354
+ conflictId: z.string().optional().describe('[resolve] the conflict id from `conflicts`.'),
4355
+ resolution: z.enum(['keep_drafted', 'keep_drive', 'duplicate_both', 'retry', 'ignore_once', 'archive_mirror']).optional().describe('[resolve] what to do with it.'),
4356
+ conflictType: z.string().optional().describe('[conflicts] filter to one type, e.g. inaccessible_file, content_conflict, drive_deleted, drafted_deleted.'),
4357
+ limit: z.number().int().min(1).max(100).optional().describe('page size (default 25, max 100).'),
4358
+ offset: z.number().int().min(0).optional().describe('page offset (default 0).'),
4359
+ compact: z.boolean().optional().describe('[conflicts] return only {id,conflictType,label} (default false).'),
4360
+ org: z.string().optional().describe('Org (id or name) to scope this call; defaults to the session\'s working org.'),
4361
+ }, async (args) => {
4362
+ const { action, conflictId, resolution, conflictType, limit, offset, compact, org } = args;
4363
+ const orgHeader = org ? { 'X-Drafted-Org': org } : {};
4364
+ const cap = Math.min(Math.max(1, Math.floor(Number(limit) || 25)), 100);
4365
+ const start = Math.max(0, Math.floor(Number(offset) || 0));
4366
+
4367
+ const listConflicts = async () => {
4368
+ const data = await api('GET', '/api/google/drive/conflicts', undefined, orgHeader);
4369
+ const rows = Array.isArray(data?.conflicts) ? data.conflicts : [];
4370
+ return conflictType ? rows.filter((c) => c.conflictType === conflictType) : rows;
4371
+ };
4372
+ // The counts are the whole point of `status`: 744 open conflicts that are three
4373
+ // causes reads as 744 decisions, which is why nobody clears them.
4374
+ const countByType = (rows) => rows.reduce((acc, c) => {
4375
+ const k = c.conflictType || 'unknown';
4376
+ acc[k] = (acc[k] || 0) + 1;
4377
+ return acc;
4378
+ }, {});
4379
+
4380
+ if (action === 'status') {
4381
+ const [conn, sync, pull, rows] = await Promise.all([
4382
+ api('GET', '/api/google/status', undefined, orgHeader).catch(() => null),
4383
+ api('GET', '/api/google/drive/sync-status', undefined, orgHeader).catch(() => null),
4384
+ api('GET', '/api/google/drive/pull-status', undefined, orgHeader).catch(() => null),
4385
+ listConflicts().catch(() => []),
4386
+ ]);
4387
+ return ok({
4388
+ connected: !!conn?.connected,
4389
+ connectionMode: conn?.connectionMode || null,
4390
+ googleEmail: conn?.googleEmail || null,
4391
+ driveRootFolderName: conn?.driveRootFolderName || null,
4392
+ syncEnabled: conn?.syncEnabled ?? null,
4393
+ openConflicts: rows.length,
4394
+ openConflictsByType: countByType(rows),
4395
+ lastSync: sync ? { status: sync.status, finishedAt: sync.finishedAt, error: sync.error } : null,
4396
+ lastPull: pull ? { status: pull.status, finishedAt: pull.finishedAt, error: pull.error } : null,
4397
+ });
4398
+ }
4399
+
4400
+ if (action === 'conflicts') {
4401
+ const rows = await listConflicts();
4402
+ const page = rows.slice(start, start + cap);
4403
+ return ok({
4404
+ totalAvailable: rows.length, offset: start, returned: page.length, truncated: start + page.length < rows.length,
4405
+ byType: countByType(rows),
4406
+ conflicts: page.map(compact ? (c => ({ id: c.id, conflictType: c.conflictType, label: c.details?.label || null })) : (c => ({
4407
+ id: c.id,
4408
+ conflictType: c.conflictType,
4409
+ label: c.details?.label || null,
4410
+ error: c.details?.error || null,
4411
+ frameId: c.frameId,
4412
+ projectId: c.projectId,
4413
+ driveFileId: c.driveFileId,
4414
+ createdAt: c.createdAt,
4415
+ }))),
4416
+ });
4417
+ }
4418
+
4419
+ if (action === 'resolve') {
4420
+ if (!conflictId) return err(new Error('resolve requires conflictId (get it from action="conflicts")'));
4421
+ if (!resolution) return err(new Error('resolve requires resolution: keep_drafted | keep_drive | duplicate_both | retry | ignore_once | archive_mirror'));
4422
+ const data = await api('POST', `/api/google/drive/conflicts/${encodeURIComponent(conflictId)}/resolve`, { action: resolution }, orgHeader);
4423
+ return ok({ resolved: 1, conflictId, resolution, conflict: data?.conflict || null });
4424
+ }
4425
+
4426
+ if (action === 'retry_all') {
4427
+ const data = await api('POST', '/api/google/drive/conflicts/retry-all', undefined, orgHeader);
4428
+ return ok({
4429
+ retried: data?.retried || 0,
4430
+ note: data?.retried
4431
+ ? 'A sync was queued. Re-read action="status" once it finishes: anything still broken comes back as a fresh conflict with an accurate reason.'
4432
+ : 'Nothing to retry — no open inaccessible_file conflicts.',
4433
+ });
4434
+ }
4435
+
4436
+ if (action === 'sync') {
4437
+ const job = await api('POST', '/api/google/drive/sync', undefined, orgHeader);
4438
+ return ok({ queued: true, jobId: job?.id || null, status: job?.status || null });
4439
+ }
4440
+
4441
+ return err(new Error(`unknown drive action: ${action}`));
4442
+ });
4443
+
4351
4444
  function normalizeMcpUpdatePolicy(policy) {
4352
4445
  const severity = policy?.policy?.severity || 'unknown';
4353
4446
  const updateAvailable = !!policy?.policy?.updateAvailable;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drafted",
3
- "version": "1.19.43",
3
+ "version": "1.19.44",
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": [