@worca/ui 0.29.0 → 0.30.0

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/app/styles.css CHANGED
@@ -6473,3 +6473,43 @@ sl-dialog.markdown-dialog::part(body) {
6473
6473
  .conflict-icon {
6474
6474
  color: var(--status-blocked);
6475
6475
  }
6476
+
6477
+ /* Graphify cache location — selectable monospace path (W-053 cache relocation) */
6478
+ .graphify-codebox {
6479
+ display: block;
6480
+ margin: 0.25rem 0 0.75rem;
6481
+ padding: 0.4rem 0.6rem;
6482
+ background: var(--bg-secondary);
6483
+ border: 1px solid var(--border-subtle);
6484
+ border-radius: var(--radius);
6485
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
6486
+ font-size: 0.85rem;
6487
+ color: var(--fg);
6488
+ word-break: break-all;
6489
+ user-select: all;
6490
+ }
6491
+
6492
+ /* A monospace value/command box with a copy button pinned to the right. */
6493
+ .graphify-copy-row {
6494
+ display: flex;
6495
+ align-items: center;
6496
+ gap: 0.4rem;
6497
+ margin: 0.25rem 0 0.75rem;
6498
+ }
6499
+
6500
+ .graphify-copy-row .graphify-codebox {
6501
+ flex: 1;
6502
+ min-width: 0;
6503
+ margin: 0;
6504
+ }
6505
+
6506
+ /* Shown when the graphify CLI is missing/incompatible. */
6507
+ .graphify-not-installed {
6508
+ margin: 0 0 0.75rem;
6509
+ }
6510
+
6511
+ /* Caution color (action needed: install) on the message text only — not the
6512
+ install-command code box, which keeps normal monospace styling. */
6513
+ .graphify-not-installed .settings-tab-description {
6514
+ color: var(--status-paused);
6515
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worca/ui",
3
- "version": "0.29.0",
3
+ "version": "0.30.0",
4
4
  "description": "Pipeline monitoring UI for worca-cc",
5
5
  "license": "MIT",
6
6
  "author": "Sinisha Djukic",
package/server/app.js CHANGED
@@ -2,7 +2,13 @@
2
2
 
3
3
  import { execFile, execFileSync, spawn } from 'node:child_process';
4
4
  import { createHmac, randomUUID } from 'node:crypto';
5
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
5
+ import {
6
+ existsSync,
7
+ mkdirSync,
8
+ readFileSync,
9
+ rmSync,
10
+ writeFileSync,
11
+ } from 'node:fs';
6
12
  import { homedir } from 'node:os';
7
13
  import { basename, dirname, isAbsolute, join } from 'node:path';
8
14
  import { fileURLToPath } from 'node:url';
@@ -10,13 +16,19 @@ import express from 'express';
10
16
 
11
17
  import { dbExists, getIssue, listIssues } from './beads-reader.js';
12
18
  import { createFleetRouter } from './fleet-routes.js';
19
+ import {
20
+ _effectiveConfig,
21
+ clearRepoCache,
22
+ createGraphifyStatus,
23
+ snapshotDir,
24
+ } from './graphify-status.js';
13
25
  import { RAW_BODY } from './integrations/index.js';
14
26
  import { verify } from './integrations/verify.js';
15
27
  import { LaunchLock } from './launch-lock.js';
16
28
  import { fleetRunsDir, workspaceRunsDir, workspacesDir } from './paths.js';
17
29
  import { createPreferencesRouter } from './preferences-routes.js';
18
30
  import { ProcessManager } from './process-manager.js';
19
- import { scanDirectory } from './project-registry.js';
31
+ import { readProjects, scanDirectory } from './project-registry.js';
20
32
  import {
21
33
  createProjectRoutes,
22
34
  createProjectScopedRoutes,
@@ -994,6 +1006,154 @@ export function createApp(options = {}) {
994
1006
  res.json({ ok: true, path: configPath });
995
1007
  });
996
1008
 
1009
+ // ─── Graphify endpoints ──────────────────────────────────────────────
1010
+ if (!app.locals.graphifyStatus) {
1011
+ app.locals.graphifyStatus = createGraphifyStatus({});
1012
+ }
1013
+
1014
+ // Resolve the graphify settings for a request. In single-project mode the
1015
+ // server's own projectRoot/settingsPath are used. In global mode there is no
1016
+ // fixed project, so the selected project is passed as ?project=<id> and we
1017
+ // resolve its root + settings.json from the registry — otherwise the endpoint
1018
+ // would be blind to every project and only ever see global settings.
1019
+ function readGraphifySettings(projectId) {
1020
+ const readJson = (p) => {
1021
+ if (!p) return {};
1022
+ try {
1023
+ return JSON.parse(readFileSync(p, 'utf-8'));
1024
+ } catch {
1025
+ return {};
1026
+ }
1027
+ };
1028
+ const globalSettingsPath = prefsDir
1029
+ ? join(prefsDir, 'settings.json')
1030
+ : settingsPath;
1031
+
1032
+ let projectSettingsPath = settingsPath;
1033
+ let root = projectRoot || process.cwd();
1034
+ if (projectId && prefsDir) {
1035
+ const proj = readProjects(prefsDir).find((p) => p.name === projectId);
1036
+ if (proj) {
1037
+ projectSettingsPath =
1038
+ proj.settingsPath || join(proj.path, '.claude', 'settings.json');
1039
+ root = proj.path;
1040
+ }
1041
+ } else if (!projectSettingsPath && projectRoot) {
1042
+ projectSettingsPath = join(projectRoot, '.claude', 'settings.json');
1043
+ }
1044
+
1045
+ return {
1046
+ globalSettings: readJson(globalSettingsPath),
1047
+ projectSettings: readJson(projectSettingsPath),
1048
+ root,
1049
+ };
1050
+ }
1051
+
1052
+ async function graphifyStatusPayload(projectId) {
1053
+ const { globalSettings, projectSettings, root } =
1054
+ readGraphifySettings(projectId);
1055
+ const result = await app.locals.graphifyStatus.getStatus({
1056
+ globalSettings,
1057
+ projectSettings,
1058
+ projectRoot: root,
1059
+ });
1060
+ return { ...result, building: Boolean(app.locals.graphifyBuilding) };
1061
+ }
1062
+
1063
+ app.get('/api/graphify/status', async (req, res) => {
1064
+ try {
1065
+ res.json(await graphifyStatusPayload(req.query.project));
1066
+ } catch (err) {
1067
+ res.status(500).json({ ok: false, error: err.message });
1068
+ }
1069
+ });
1070
+
1071
+ app.post('/api/graphify/recheck', async (req, res) => {
1072
+ try {
1073
+ app.locals.graphifyStatus.invalidate();
1074
+ res.json(await graphifyStatusPayload(req.query.project));
1075
+ } catch (err) {
1076
+ res.status(500).json({ ok: false, error: err.message });
1077
+ }
1078
+ });
1079
+
1080
+ // Build/refresh the current HEAD's cache snapshot (async, long-running).
1081
+ // The lock + .complete publish discipline lives in run_graphify_preflight,
1082
+ // so we drive it via a detached Python process and track a `building` flag
1083
+ // the UI polls through /api/graphify/status.
1084
+ app.post('/api/graphify/build', async (req, res) => {
1085
+ try {
1086
+ const { globalSettings, projectSettings, root } = readGraphifySettings(
1087
+ req.query.project,
1088
+ );
1089
+ const effective = _effectiveConfig(globalSettings, projectSettings);
1090
+ if (!effective.enabled) {
1091
+ return res
1092
+ .status(400)
1093
+ .json({ ok: false, error: 'Graphify is not enabled' });
1094
+ }
1095
+ const detection = await app.locals.graphifyStatus.detect();
1096
+ if (!detection.installed || !detection.compatible) {
1097
+ return res.status(400).json({
1098
+ ok: false,
1099
+ error:
1100
+ detection.error || 'Graphify is not installed or not compatible',
1101
+ });
1102
+ }
1103
+ if (app.locals.graphifyBuilding) {
1104
+ return res.json({ ok: true, status: 'building' });
1105
+ }
1106
+ // Fresh build for the current HEAD: clear its snapshot first.
1107
+ const snap = snapshotDir(root);
1108
+ if (snap) {
1109
+ try {
1110
+ rmSync(snap, { recursive: true, force: true });
1111
+ } catch {}
1112
+ }
1113
+ app.locals.graphifyBuilding = true;
1114
+ const child = spawn(
1115
+ 'python3',
1116
+ [
1117
+ '-c',
1118
+ 'from worca.scripts.graphify_preflight import run_graphify_preflight as r; r()',
1119
+ ],
1120
+ { cwd: root, stdio: 'ignore' },
1121
+ );
1122
+ const done = () => {
1123
+ app.locals.graphifyBuilding = false;
1124
+ app.locals.graphifyStatus.invalidate();
1125
+ };
1126
+ child.on('exit', done);
1127
+ child.on('error', done);
1128
+ res.json({ ok: true, status: 'building' });
1129
+ } catch (err) {
1130
+ app.locals.graphifyBuilding = false;
1131
+ res.status(500).json({ ok: false, error: err.message });
1132
+ }
1133
+ });
1134
+
1135
+ // Clear ALL cached snapshots for this project's repo.
1136
+ app.post('/api/graphify/clear', async (req, res) => {
1137
+ try {
1138
+ const { root } = readGraphifySettings(req.query.project);
1139
+ const cleared = clearRepoCache(root);
1140
+ app.locals.graphifyStatus.invalidate();
1141
+ res.json({ ok: true, cleared });
1142
+ } catch (err) {
1143
+ res.status(500).json({ ok: false, error: err.message });
1144
+ }
1145
+ });
1146
+
1147
+ app.get('/api/graphify/graph.html', (req, res) => {
1148
+ const { root } = readGraphifySettings(req.query.project);
1149
+ const snap = snapshotDir(root);
1150
+ const htmlPath = snap ? join(snap, 'graphify', 'graph.html') : null;
1151
+ if (!htmlPath || !existsSync(htmlPath)) {
1152
+ return res.status(404).json({ ok: false, error: 'graph.html not found' });
1153
+ }
1154
+ res.sendFile(htmlPath);
1155
+ });
1156
+
997
1157
  // ─── Dynamic favicon ──────────────────────────────────────────────────
998
1158
  // Serve mode-specific favicon before express.static so it takes precedence.
999
1159
  app.get('/favicon.svg', (_req, res) => {
@@ -0,0 +1,234 @@
1
+ import { execFileSync, spawn } from 'node:child_process';
2
+ import { createHash } from 'node:crypto';
3
+ import { existsSync, realpathSync, rmSync, statSync } from 'node:fs';
4
+ import { homedir } from 'node:os';
5
+ import { isAbsolute, join } from 'node:path';
6
+
7
+ // Mirror of _GRAPHIFY_DEFAULTS in src/worca/utils/graphify.py — keep in sync.
8
+ const GRAPHIFY_DEFAULTS = {
9
+ enabled: false,
10
+ mode: 'structural',
11
+ backend: null,
12
+ model_profile: null,
13
+ out_dir: 'graphify-out',
14
+ update_on: { preflight: true, guardian_post_commit: true },
15
+ min_repo_files: 100,
16
+ version_range: '>=0.8.16,<1',
17
+ preflight_timeout_seconds: 300,
18
+ freshness: 'clean_only',
19
+ };
20
+
21
+ // Mirror of effective_graphify_config() in src/worca/utils/graphify.py.
22
+ // Enablement is project-level: the project opts in via graphify.enabled. Global
23
+ // graphify.enabled is purely a kill-switch — an EXPLICIT global `false` disables
24
+ // everywhere; `true`/unset defer to the project. These rules MUST match the
25
+ // Python implementation; the parity is guarded by graphify-status.test.js
26
+ // ("effective-config parity with Python"). Update both together.
27
+ export function _effectiveConfig(globalSettings, projectSettings) {
28
+ const gGraphify = globalSettings?.worca?.graphify ?? {};
29
+ const pGraphify = projectSettings?.worca?.graphify ?? {};
30
+
31
+ // Only an explicit global `enabled: false` disables; `true`/unset defer.
32
+ if (gGraphify.enabled === false) {
33
+ return { ...GRAPHIFY_DEFAULTS, enabled: false, reason: 'global-off' };
34
+ }
35
+
36
+ const projectEnabled = pGraphify.enabled ?? false;
37
+ if (!projectEnabled) {
38
+ return { ...GRAPHIFY_DEFAULTS, enabled: false, reason: 'project-off' };
39
+ }
40
+
41
+ const merged = { ...GRAPHIFY_DEFAULTS };
42
+ for (const [k, v] of Object.entries(gGraphify)) {
43
+ if (v != null || k === 'enabled') merged[k] = v;
44
+ }
45
+ for (const [k, v] of Object.entries(pGraphify)) {
46
+ if (v != null || k === 'enabled') merged[k] = v;
47
+ }
48
+
49
+ return {
50
+ enabled: true,
51
+ mode: merged.mode,
52
+ backend: merged.backend,
53
+ model_profile: merged.model_profile,
54
+ out_dir: merged.out_dir,
55
+ update_on: merged.update_on,
56
+ min_repo_files: merged.min_repo_files,
57
+ version_range: merged.version_range,
58
+ preflight_timeout_seconds: merged.preflight_timeout_seconds,
59
+ freshness: merged.freshness,
60
+ reason: null,
61
+ };
62
+ }
63
+
64
+ // ─── Per-commit cache resolution (mirrors utils/paths.py + utils/git.py) ────
65
+
66
+ export function cacheDir() {
67
+ if (process.env.WORCA_CACHE) return process.env.WORCA_CACHE;
68
+ const home = process.env.WORCA_HOME || join(homedir(), '.worca');
69
+ return join(home, 'cache');
70
+ }
71
+
72
+ export function repoId(projectRoot) {
73
+ try {
74
+ const common = execFileSync(
75
+ 'git',
76
+ ['-C', projectRoot, 'rev-parse', '--git-common-dir'],
77
+ { encoding: 'utf-8' },
78
+ ).trim();
79
+ if (!common) return null;
80
+ const abs = isAbsolute(common) ? common : join(projectRoot, common);
81
+ const real = realpathSync(abs);
82
+ return createHash('sha256').update(real).digest('hex').slice(0, 12);
83
+ } catch {
84
+ return null;
85
+ }
86
+ }
87
+
88
+ export function headSha(projectRoot) {
89
+ try {
90
+ return execFileSync('git', ['-C', projectRoot, 'rev-parse', 'HEAD'], {
91
+ encoding: 'utf-8',
92
+ }).trim();
93
+ } catch {
94
+ return null;
95
+ }
96
+ }
97
+
98
+ /** Absolute snapshot dir for the project's current HEAD, or null. */
99
+ export function snapshotDir(projectRoot) {
100
+ const rid = repoId(projectRoot);
101
+ const sha = headSha(projectRoot);
102
+ if (!rid || !sha) return null;
103
+ return join(cacheDir(), 'ast', rid, sha);
104
+ }
105
+
106
+ /** The per-project cache dir (<cache>/ast/<repo-id>/), or null if not a repo. */
107
+ export function repoCacheDir(projectRoot) {
108
+ const rid = repoId(projectRoot);
109
+ if (!rid) return null;
110
+ return join(cacheDir(), 'ast', rid);
111
+ }
112
+
113
+ /** Remove all cached snapshots for the project's repo. Returns the path or null. */
114
+ export function clearRepoCache(projectRoot) {
115
+ const repoCache = repoCacheDir(projectRoot);
116
+ if (!repoCache) return null;
117
+ rmSync(repoCache, { recursive: true, force: true });
118
+ return repoCache;
119
+ }
120
+
121
+ /** Stats for a per-commit snapshot dir, or null if not complete/present. */
122
+ export function _graphStats(snapDir) {
123
+ if (!snapDir || !existsSync(join(snapDir, '.complete'))) return null;
124
+ const reportPath = join(snapDir, 'graphify', 'GRAPH_REPORT.md');
125
+ if (!existsSync(reportPath)) return null;
126
+
127
+ const stat = statSync(reportPath);
128
+ const ageSeconds = Math.max(0, (Date.now() - stat.mtimeMs) / 1000);
129
+ const htmlPath = join(snapDir, 'graphify', 'graph.html');
130
+ const graphJsonPath = join(snapDir, 'graphify', 'graph.json');
131
+
132
+ return {
133
+ report_path: reportPath,
134
+ // The queryable dataset for humans: `graphify query … --graph <path>`.
135
+ // null when the snapshot lacks graph.json (older/partial builds).
136
+ graph_json_path: existsSync(graphJsonPath) ? graphJsonPath : null,
137
+ snapshot_dir: snapDir,
138
+ age_seconds: ageSeconds,
139
+ size_bytes: stat.size,
140
+ has_html: existsSync(htmlPath),
141
+ };
142
+ }
143
+
144
+ function defaultDetect() {
145
+ return new Promise((resolve) => {
146
+ const child = spawn(
147
+ 'python3',
148
+ [
149
+ '-c',
150
+ 'import json; from worca.utils.graphify import detect_graphify; d = detect_graphify(); print(json.dumps({"installed": d.installed, "version": d.version, "compatible": d.compatible, "backend_env_present": d.backend_env_present, "error": d.error}))',
151
+ ],
152
+ { stdio: ['ignore', 'pipe', 'pipe'] },
153
+ );
154
+
155
+ let stdout = '';
156
+ let stderr = '';
157
+ child.stdout.on('data', (chunk) => {
158
+ stdout += chunk.toString();
159
+ });
160
+ child.stderr.on('data', (chunk) => {
161
+ stderr += chunk.toString();
162
+ });
163
+ child.on('error', () => {
164
+ resolve({
165
+ installed: false,
166
+ version: null,
167
+ compatible: false,
168
+ backend_env_present: [],
169
+ error: 'python3 not available',
170
+ });
171
+ });
172
+ child.on('exit', (code) => {
173
+ if (code === 0 && stdout.trim()) {
174
+ try {
175
+ resolve(JSON.parse(stdout.trim()));
176
+ return;
177
+ } catch {
178
+ // fall through
179
+ }
180
+ }
181
+ resolve({
182
+ installed: false,
183
+ version: null,
184
+ compatible: false,
185
+ backend_env_present: [],
186
+ error: stderr.trim() || `detect exited ${code}`,
187
+ });
188
+ });
189
+ });
190
+ }
191
+
192
+ const DEFAULT_TTL_MS = 60_000;
193
+
194
+ export function createGraphifyStatus(opts = {}) {
195
+ const detectFn = opts.detectFn || defaultDetect;
196
+ const ttlMs = opts.ttlMs ?? DEFAULT_TTL_MS;
197
+
198
+ let cached = null;
199
+ let cachedAt = 0;
200
+
201
+ async function detect() {
202
+ const now = Date.now();
203
+ if (cached && now - cachedAt < ttlMs) return cached;
204
+ cached = await detectFn();
205
+ cachedAt = Date.now();
206
+ return cached;
207
+ }
208
+
209
+ function invalidate() {
210
+ cached = null;
211
+ cachedAt = 0;
212
+ }
213
+
214
+ async function getStatus({ globalSettings, projectSettings, projectRoot }) {
215
+ const effective = _effectiveConfig(globalSettings, projectSettings);
216
+ const detection = await detect();
217
+ const graphStats = effective.enabled
218
+ ? _graphStats(snapshotDir(projectRoot))
219
+ : null;
220
+ return {
221
+ ok: true,
222
+ effective,
223
+ detection,
224
+ graph_stats: graphStats,
225
+ // The cache path is a pure function of the repo location (it's null only
226
+ // when projectRoot isn't a git repo), so resolve it regardless of whether
227
+ // graphify is enabled. This lets the UI show the path immediately when
228
+ // the user toggles graphify on in-memory, before the setting is saved.
229
+ cache_path: repoCacheDir(projectRoot),
230
+ };
231
+ }
232
+
233
+ return { detect, invalidate, getStatus };
234
+ }