publish-workflow-spec.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/usr/bin/env node
  2. import fs from 'fs';
  3. import os from 'os';
  4. import path from 'path';
  5. import { DOCCENTER_API_URL } from '../src/data/doc-paths.js';
  6. const ROOT = '/Users/ivx/Documents/VLCode-Lite';
  7. const SPEC_PATH = path.join(ROOT, 'docs', 'vl-workflow-spec-3.18.md');
  8. const AUTH_PATH = path.join(os.homedir(), '.vl-code', 'auth.json');
  9. const APPLY = process.argv.includes('--apply');
  10. const cookie = process.env.DOCCENTER_COOKIE || (() => {
  11. try {
  12. return JSON.parse(fs.readFileSync(AUTH_PATH, 'utf-8')).cookie;
  13. } catch {
  14. return '';
  15. }
  16. })();
  17. if (!cookie) {
  18. console.error('Missing DocCenter cookie. Set DOCCENTER_COOKIE or login so ~/.vl-code/auth.json exists.');
  19. process.exit(1);
  20. }
  21. const headers = {
  22. 'Content-Type': 'application/json',
  23. Cookie: String(cookie).startsWith('ih5bearer=') ? String(cookie) : `ih5bearer=${cookie}`,
  24. };
  25. async function dcPost(endpoint, body) {
  26. const res = await fetch(`${DOCCENTER_API_URL}/${endpoint}`, {
  27. method: 'POST',
  28. headers,
  29. body: JSON.stringify(body),
  30. });
  31. const text = await res.text();
  32. try {
  33. return JSON.parse(text);
  34. } catch {
  35. throw new Error(`DocCenter returned non-JSON for ${endpoint}: ${text.slice(0, 300)}`);
  36. }
  37. }
  38. async function loadDocByPath(docPath) {
  39. const list = await dcPost('SERVICE_DocCenter_GetDocList', {
  40. keyword: 'Workflow Spec',
  41. tagId: 0,
  42. page: 1,
  43. pageSize: 100,
  44. });
  45. return (list?.data || []).find(doc => String(doc.path) === String(docPath)) || null;
  46. }
  47. async function main() {
  48. const currentContent = fs.readFileSync(SPEC_PATH, 'utf-8');
  49. const existing = await loadDocByPath(3);
  50. if (!existing) {
  51. throw new Error('DocCenter Path 3 was not found');
  52. }
  53. const docId = existing._id || existing.id;
  54. const remote = await dcPost('SERVICE_DocCenter_GetDocById', { docId });
  55. const remoteContent = remote?.data?.currentContent || '';
  56. if (remoteContent === currentContent) {
  57. console.log(`unchanged path 3 VL Workflow Spec 3.18 (docId ${docId})`);
  58. return;
  59. }
  60. if (!APPLY) {
  61. console.log(`publish path 3 VL Workflow Spec 3.18 (docId ${docId})`);
  62. return;
  63. }
  64. const result = await dcPost('SERVICE_DocCenter_SaveAsVersion', {
  65. path: '3',
  66. name: 'VL Workflow Spec 3.18',
  67. description: 'Canonical workflow specification with Doc ID resolution priority, Tool_* extension profiles, tool events, clientRunToken, and checkpoint rerun semantics.',
  68. currentContent,
  69. changeNote: 'v3.18 — document Doc ID priority, locked core spec slots, Tool_* runtime semantics, and workflow-of-workflows compatibility',
  70. });
  71. console.log(JSON.stringify({
  72. success: result?.success ?? null,
  73. message: result?.message ?? null,
  74. data: result?.data ?? null,
  75. }, null, 2));
  76. }
  77. main().catch(err => {
  78. console.error(err.message);
  79. process.exit(1);
  80. });