devworkspace 0.4.2 → 0.4.4

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 (50) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +299 -27
  3. package/dist/cli/args.d.ts +9 -0
  4. package/dist/cli/args.js +3 -0
  5. package/dist/cli/args.js.map +1 -1
  6. package/dist/cli/help.js +8 -4
  7. package/dist/cli/help.js.map +1 -1
  8. package/dist/cli/render.js +53 -4
  9. package/dist/cli/render.js.map +1 -1
  10. package/dist/cli/run.js +42 -17
  11. package/dist/cli/run.js.map +1 -1
  12. package/dist/core/artifacts.d.ts +32 -0
  13. package/dist/core/artifacts.js +46 -0
  14. package/dist/core/artifacts.js.map +1 -0
  15. package/dist/core/version.js +3 -0
  16. package/dist/core/version.js.map +1 -1
  17. package/dist/core/workspace.js +1 -0
  18. package/dist/core/workspace.js.map +1 -1
  19. package/dist/integrations/adapters/graphify.js +2 -1
  20. package/dist/integrations/adapters/graphify.js.map +1 -1
  21. package/dist/mcp/setup.d.ts +97 -2
  22. package/dist/mcp/setup.js +280 -67
  23. package/dist/mcp/setup.js.map +1 -1
  24. package/dist/mcp/tools.d.ts +6 -0
  25. package/dist/mcp/tools.js +140 -18
  26. package/dist/mcp/tools.js.map +1 -1
  27. package/dist/mcp/verify.d.ts +41 -0
  28. package/dist/mcp/verify.js +229 -0
  29. package/dist/mcp/verify.js.map +1 -0
  30. package/dist/services/doctor.js +139 -0
  31. package/dist/services/doctor.js.map +1 -1
  32. package/dist/services/graph.d.ts +77 -3
  33. package/dist/services/graph.js +336 -185
  34. package/dist/services/graph.js.map +1 -1
  35. package/dist/services/init.js +5 -1
  36. package/dist/services/init.js.map +1 -1
  37. package/dist/services/setup.js +4 -0
  38. package/dist/services/setup.js.map +1 -1
  39. package/dist/services/taskContext.d.ts +24 -2
  40. package/dist/services/taskContext.js +72 -26
  41. package/dist/services/taskContext.js.map +1 -1
  42. package/dist/tasks/routing.js +4 -1
  43. package/dist/tasks/routing.js.map +1 -1
  44. package/docs/agents.md +18 -4
  45. package/docs/claude.md +13 -0
  46. package/docs/getting-started.md +40 -1
  47. package/docs/integrations.md +16 -1
  48. package/docs/mcp.md +46 -14
  49. package/docs/troubleshooting.md +5 -0
  50. package/package.json +1 -1
package/dist/mcp/tools.js CHANGED
@@ -1,20 +1,51 @@
1
1
  import { promises as fs } from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { requireWorkspace, loadProject } from '../core/workspace.js';
4
+ import { readVersioned } from '../core/versioned.js';
5
+ import { SCHEMA_VERSION, validateCommands } from '../config/schemas.js';
6
+ import { packageDirs } from '../verification/scope.js';
4
7
  import { loadFacts, evaluateStaleness, authorityRank } from '../knowledge/facts.js';
5
8
  import { getStatus } from '../services/status.js';
6
- import { getTaskContext, isContextRole, words, expandQueryTerms, matchesQuery, } from '../services/taskContext.js';
9
+ import { getTaskContext, isContextRole, words, expandQueryTerms, matchesQuery, STOP, WEAK_TERMS, PATH_STRUCTURAL_TERMS, } from '../services/taskContext.js';
7
10
  import { loadFeatures } from '../services/features.js';
8
11
  import { listDecisions } from '../decisions/decision.js';
9
12
  import { packageVersion } from '../core/version.js';
10
13
  import { MCP_SECTION_START, MCP_SECTION_END } from './setup.js';
11
14
  import { IgnoreMatcher } from '../discovery/ignore.js';
12
- import { ALWAYS_SKIP_DIRS } from '../discovery/scan.js';
13
- import { traceGraphService } from '../services/graph.js';
15
+ import { ALWAYS_SKIP_DIRS, scanProject } from '../discovery/scan.js';
16
+ import { traceGraphService, loadGraphData } from '../services/graph.js';
14
17
  import { isSensitiveFile, safeReadText } from '../security/files.js';
15
18
  import { redact } from '../security/redact.js';
16
19
  import { assertNoSymlinkEscape, isInside, looksAbsolute, resolveInside, toPosix, validateRelativePath, } from '../utils/paths.js';
17
20
  import { pathExists, readJsonFile, readTextBounded } from '../utils/fs.js';
21
+ /**
22
+ * When a root-level file (e.g. package.json) is missing in a multi-package repo, list the same-named files that
23
+ * actually exist inside the known package directories. Every suggestion is confirmed on disk first.
24
+ */
25
+ export async function suggestPackageManifests(ws, posixRel) {
26
+ if (posixRel.includes('/'))
27
+ return [];
28
+ let dirs;
29
+ try {
30
+ dirs = packageDirs((await readVersioned(ws.commands, 'commands', SCHEMA_VERSION, validateCommands)).data.checks);
31
+ }
32
+ catch {
33
+ return [];
34
+ }
35
+ const found = [];
36
+ for (const d of [...new Set(dirs)].sort()) {
37
+ const cand = `${d.replace(/\\/g, '/')}/${posixRel}`;
38
+ try {
39
+ const full = resolveInside(ws.root, cand);
40
+ if ((await pathExists(full)) && (await fs.lstat(full)).isFile())
41
+ found.push(cand);
42
+ }
43
+ catch {
44
+ /* unsafe or unreadable candidate: never suggest it */
45
+ }
46
+ }
47
+ return found;
48
+ }
18
49
  export const TOOL_PROJECT_OVERVIEW = {
19
50
  name: 'get_project_overview',
20
51
  description: 'Retrieve the architectural summary, detected stack, health status, context freshness, and context capabilities of the current DevWorkspace project.',
@@ -240,7 +271,7 @@ function scoreFact(f, terms) {
240
271
  score += valMatches * 15;
241
272
  return score;
242
273
  }
243
- function formatTaskContextText(r, task, maxChars, extraFeatures) {
274
+ function formatTaskContextText(r, task, maxChars, extraFeatures, knownFiles, graphNotice) {
244
275
  const parts = [];
245
276
  const kw = words(task);
246
277
  const terms = expandQueryTerms(kw);
@@ -269,11 +300,53 @@ function formatTaskContextText(r, task, maxChars, extraFeatures) {
269
300
  return;
270
301
  if (looksAbsolute(posixPath))
271
302
  return;
303
+ // Reject non-path descriptions, labels, and detector summaries
304
+ if (posixPath.includes(',') || /^(?:package scripts|package manifests|workspace detector|unknown)/i.test(posixPath)) {
305
+ return;
306
+ }
307
+ // If knownFiles is provided, strictly enforce workspace containment
308
+ if (knownFiles && knownFiles.size > 0 && !knownFiles.has(posixPath)) {
309
+ return;
310
+ }
311
+ // If knownFiles is not provided, ensure it resembles a valid path without spaces
312
+ if (posixPath.includes(' ') || (!posixPath.includes('/') && !posixPath.includes('.'))) {
313
+ return;
314
+ }
272
315
  const existing = fileCandidates.get(posixPath);
273
316
  if (!existing || score > existing.score) {
274
317
  fileCandidates.set(posixPath, { path: posixPath, reason, score });
275
318
  }
276
319
  };
320
+ // 1. Path-based candidate discovery from workspace files (works even without features/graph)
321
+ if (knownFiles && knownFiles.size > 0) {
322
+ const DOMAIN_TERMS = terms.filter((t) => !STOP.has(t) && !WEAK_TERMS.has(t) && !PATH_STRUCTURAL_TERMS.has(t) && t.length >= 3);
323
+ const activeTerms = DOMAIN_TERMS.length > 0 ? DOMAIN_TERMS : terms.filter((t) => t.length >= 3 && !STOP.has(t));
324
+ const targetPkg = r.packages.length > 0 ? r.packages[0] : null;
325
+ for (const filePath of knownFiles) {
326
+ if (filePath.startsWith('.devworkspace/') || isSensitiveFile(filePath))
327
+ continue;
328
+ const baseName = filePath.split('/').pop() ?? filePath;
329
+ const nameWithoutExt = baseName.replace(/\.[^.]+$/, '').toLowerCase();
330
+ const segments = filePath.toLowerCase().split('/');
331
+ const dirSegments = segments.slice(0, -1);
332
+ const subTokens = nameWithoutExt.split(/[^a-z0-9]+/).concat(nameWithoutExt.replace(/([a-z])([A-Z])/g, '$1 $2').toLowerCase().split(/\s+/));
333
+ const pkgBoost = targetPkg && filePath.startsWith(`${targetPkg}/`) ? 5 : 0;
334
+ for (const t of activeTerms) {
335
+ if (nameWithoutExt === t) {
336
+ addCandidate(filePath, `path matches "${t}"`, 65 + pkgBoost);
337
+ break;
338
+ }
339
+ else if (subTokens.includes(t) || nameWithoutExt.startsWith(`${t}-`) || nameWithoutExt.startsWith(`${t}.`)) {
340
+ addCandidate(filePath, `path matches "${t}"`, 60 + pkgBoost);
341
+ break;
342
+ }
343
+ else if (dirSegments.some((seg) => seg === t || seg.split(/[^a-z0-9]+/).includes(t))) {
344
+ addCandidate(filePath, `path matches "${t}"`, 50 + pkgBoost);
345
+ break;
346
+ }
347
+ }
348
+ }
349
+ }
277
350
  const allFeatures = r.roleFindings?.features ?? extraFeatures;
278
351
  if (allFeatures) {
279
352
  for (const feat of allFeatures) {
@@ -300,7 +373,7 @@ function formatTaskContextText(r, task, maxChars, extraFeatures) {
300
373
  if (r.roleFindings?.graphNodes) {
301
374
  for (const node of r.roleFindings.graphNodes) {
302
375
  if (node.path) {
303
- addCandidate(node.path, `graph symbol node "${node.symbol ?? node.id}" (${node.status})`, 45);
376
+ addCandidate(node.path, `graph symbol node "${node.symbol ?? node.id}" (${node.status}${node.weak ? ', weak match' : ''})`, 45);
304
377
  }
305
378
  }
306
379
  }
@@ -338,9 +411,22 @@ function formatTaskContextText(r, task, maxChars, extraFeatures) {
338
411
  if (rf.graphNodes && rf.graphNodes.length > 0) {
339
412
  parts.push('\n### Graph Nodes');
340
413
  for (const node of rf.graphNodes.slice(0, 10)) {
341
- parts.push(`- ${node.id} (${node.status})${node.path ? `: \`${node.path}\`` : ''}`);
414
+ const loc = node.path ? `: \`${node.path}${node.line ? `:${node.line}` : ''}\`` : '';
415
+ const weak = node.weak ? ' - weak match, confirm relevance' : '';
416
+ parts.push(`- ${node.id} [${node.nodeType}] (${node.status} in source${weak})${loc}`);
417
+ }
418
+ const rels = rf.graphRelationships ?? [];
419
+ if (rels.length > 0) {
420
+ parts.push('\n### Graph Relationships');
421
+ for (const e of rels.slice(0, 8)) {
422
+ const tag = e.confidence === 'EXTRACTED' ? 'EXTRACTED (AST)' : e.confidence === 'INFERRED' ? 'INFERRED (graph inference, not source-confirmed)' : 'confidence unavailable';
423
+ parts.push(`- \`${e.source}\` --[${e.relation}]--> \`${e.target}\` [${tag}]`);
424
+ }
342
425
  }
343
426
  }
427
+ else if (rf.graphNotice) {
428
+ parts.push(`\n### Graphify Knowledge Graph\n- ${rf.graphNotice}`);
429
+ }
344
430
  if (rf.testFrameworks && rf.testFrameworks.length > 0) {
345
431
  parts.push(`\n### Test Frameworks: ${rf.testFrameworks.join(', ')}`);
346
432
  }
@@ -354,6 +440,9 @@ function formatTaskContextText(r, task, maxChars, extraFeatures) {
354
440
  parts.push(`\n### Review Notice: ${rf.diffNotice}`);
355
441
  }
356
442
  }
443
+ else if (graphNotice) {
444
+ parts.push(`\n### Graphify Knowledge Graph\n- ${graphNotice}`);
445
+ }
357
446
  // Display features if available
358
447
  if (allFeatures && allFeatures.length > 0) {
359
448
  parts.push('\n### Relevant Features');
@@ -540,7 +629,27 @@ export async function handleTaskContext(workspaceRoot, rawArgs) {
540
629
  // Fallback gracefully
541
630
  }
542
631
  }
543
- const formatted = formatTaskContextText(result, task, maxChars, extraFeatures);
632
+ let knownFiles;
633
+ try {
634
+ const scan = await scanProject(ws.root, { maxFiles: 5000, maxDepth: 10 });
635
+ knownFiles = scan.files;
636
+ }
637
+ catch {
638
+ // Degrade gracefully if scanning fails
639
+ }
640
+ let graphNotice = result.roleFindings?.graphNotice;
641
+ if (!graphNotice && !result.roleFindings?.graphNodes) {
642
+ try {
643
+ const graph = await loadGraphData(ws.root);
644
+ if (!graph.exists) {
645
+ graphNotice = 'No Graphify knowledge graph found at graphify-out/graph.json. Run "graphify update ." or "/graphify ." in Claude Code to map symbol dependencies.';
646
+ }
647
+ }
648
+ catch (err) {
649
+ graphNotice = `Graphify knowledge graph unavailable (${err.message}). Retrieval continuing without graph symbol data.`;
650
+ }
651
+ }
652
+ const formatted = formatTaskContextText(result, task, maxChars, extraFeatures, knownFiles, graphNotice);
544
653
  return {
545
654
  content: [{ type: 'text', text: formatted }],
546
655
  isError: false,
@@ -703,6 +812,16 @@ export async function handleFileContext(workspaceRoot, rawArgs) {
703
812
  };
704
813
  }
705
814
  if (!(await pathExists(fullPath))) {
815
+ const alts = await suggestPackageManifests(ws, posixRel);
816
+ if (alts.length > 0) {
817
+ return {
818
+ content: [{
819
+ type: 'text',
820
+ text: `File not found: "${rawPath}" does not exist at the workspace root. This looks like a multi-package workspace; confirmed existing alternatives: ${alts.map((a) => `"${a}"`).join(', ')}.`,
821
+ }],
822
+ isError: true,
823
+ };
824
+ }
706
825
  return {
707
826
  content: [{ type: 'text', text: `File not found: "${rawPath}" does not exist in the workspace.` }],
708
827
  isError: true,
@@ -1369,29 +1488,32 @@ export async function handleTraceSymbolDependencies(workspaceRoot, rawArgs) {
1369
1488
  lines.push(`- **${m.name}** (${m.type})`);
1370
1489
  lines.push(` • Path: \`${m.path ?? 'none'}\``);
1371
1490
  lines.push(` • Status: [${m.status.toUpperCase()}]${m.reason ? ` (${m.reason})` : ''}`);
1372
- lines.push(` • Traversal Depth: ${depth} (inspected ${trace.totalNodes} node(s): ${trace.verifiedNodes} verified, ${trace.hypothesisNodes} hypothesis)`);
1491
+ lines.push(` • Source location: ${m.line ? `line ${m.line}` : (m.sourceLocation ?? 'unavailable')}`);
1492
+ lines.push(` • Traversal Depth: ${depth} (inspected ${trace.totalNodes} of max ${trace.maxNodes} node(s): ${trace.verifiedNodes} verified, ${trace.hypothesisNodes} hypothesis)`);
1493
+ for (const w of trace.warnings)
1494
+ lines.push(` • Note: ${w}`);
1373
1495
  if (trace.nodes.length > 1) {
1374
1496
  lines.push('\n### Connected Dependency Nodes');
1375
- const otherNodes = trace.nodes
1376
- .filter((n) => n.id !== m.id)
1377
- .sort((a, b) => a.depth - b.depth || a.name.localeCompare(b.name));
1497
+ const otherNodes = trace.nodes.filter((n) => n.id !== m.id); // already ordered by depth, then path
1378
1498
  for (const n of otherNodes.slice(0, 45)) {
1379
- const pathStr = n.path ? ` in \`${n.path}\`` : '';
1499
+ const pathStr = n.path ? ` in \`${n.path}${n.line ? `:${n.line}` : ''}\`` : '';
1380
1500
  const unverified = n.status === 'hypothesis' ? ` ⚠️ [HYPOTHESIS: ${n.reason ?? 'unverified'}]` : ' [VERIFIED]';
1381
1501
  lines.push(`- [depth ${n.depth}] **${n.name}** (${n.type})${pathStr}${unverified}`);
1382
1502
  }
1383
1503
  if (otherNodes.length > 45) {
1384
- lines.push(`- ... and ${otherNodes.length - 45} more nodes (bounded to 50 nodes max)`);
1504
+ lines.push(`- ... ${otherNodes.length - 45} more node(s) not shown (showing 45 of ${otherNodes.length} returned)`);
1385
1505
  }
1386
1506
  }
1387
1507
  if (trace.edges.length > 0) {
1388
1508
  lines.push('\n### Dependency Relationships');
1389
- const sortedEdges = [...trace.edges].sort((a, b) => a.source.localeCompare(b.source) || a.target.localeCompare(b.target) || a.relation.localeCompare(b.relation));
1390
- for (const e of sortedEdges.slice(0, 40)) {
1391
- lines.push(`- \`${e.source}\` --[${e.relation}]--> \`${e.target}\` [${e.status}]`);
1509
+ lines.push('Evidence: EXTRACTED = AST-derived by Graphify; INFERRED = Graphify inference (not source-confirmed); UNKNOWN = older graph without confidence.');
1510
+ // Already ordered: shallower depth, stronger evidence, then deterministic id order.
1511
+ for (const e of trace.edges.slice(0, 40)) {
1512
+ const ev = e.provenance === 'extracted' ? 'EXTRACTED' : e.provenance === 'inferred' ? 'INFERRED' : 'UNKNOWN';
1513
+ lines.push(`- \`${e.source}\` --[${e.relation}]--> \`${e.target}\` [${ev}, ${e.status}]`);
1392
1514
  }
1393
- if (sortedEdges.length > 40) {
1394
- lines.push(`- ... and ${sortedEdges.length - 40} more relationships`);
1515
+ if (trace.edges.length > 40) {
1516
+ lines.push(`- ... ${trace.edges.length - 40} more relationship(s) not shown (showing 40 of ${trace.edges.length})`);
1395
1517
  }
1396
1518
  }
1397
1519
  lines.push(UNTRUSTED_FOOTER);