* Materialize workspace data into the VFS. * Uses shared service functions for all data access, then generates * WORKSPACE.md from the summaries returned by each materializer.
(workspaceId: string, userId: string)
| 511 | * WORKSPACE.md from the summaries returned by each materializer. |
| 512 | */ |
| 513 | async materialize(workspaceId: string, userId: string): Promise<void> { |
| 514 | const start = Date.now() |
| 515 | this.files = new Map() |
| 516 | this.lazy = new Map() |
| 517 | this.normalizedCache = new Map() |
| 518 | this.deploymentCache = new Map() |
| 519 | this._workspaceId = workspaceId |
| 520 | this._betaEnabled = await isFeatureEnabled('mothership-beta', { userId }) |
| 521 | |
| 522 | // Per-phase wall-clock, stamped on the span so a slow materialize in a |
| 523 | // trace names its bottleneck instead of showing up as unattributed dead |
| 524 | // time inside read/glob/grep (how the v0.7 lint.json regression hid). |
| 525 | const phaseMs: Record<string, number> = {} |
| 526 | const timed = <T>(phase: string, promise: Promise<T>): Promise<T> => { |
| 527 | const t0 = Date.now() |
| 528 | return promise.finally(() => { |
| 529 | phaseMs[phase] = Date.now() - t0 |
| 530 | }) |
| 531 | } |
| 532 | |
| 533 | await trace |
| 534 | .getTracer('sim-copilot-vfs', '1.0.0') |
| 535 | .startActiveSpan( |
| 536 | TraceSpan.CopilotVfsMaterialize, |
| 537 | { attributes: { [TraceAttr.WorkspaceId]: workspaceId } }, |
| 538 | async (span) => { |
| 539 | try { |
| 540 | const [ |
| 541 | wfSummary, |
| 542 | kbSummary, |
| 543 | tblSummary, |
| 544 | fileSummary, |
| 545 | envSummary, |
| 546 | toolsSummary, |
| 547 | mcpServersSummary, |
| 548 | skillsSummary, |
| 549 | taskSummary, |
| 550 | jobsSummary, |
| 551 | wsRow, |
| 552 | members, |
| 553 | ] = await Promise.all([ |
| 554 | timed('workflows', this.materializeWorkflows(workspaceId)), |
| 555 | timed('knowledge_bases', this.materializeKnowledgeBases(workspaceId, userId)), |
| 556 | timed('tables', this.materializeTables(workspaceId)), |
| 557 | timed('files', this.materializeFiles(workspaceId)), |
| 558 | timed('environment', this.materializeEnvironment(workspaceId, userId)), |
| 559 | timed('custom_tools', this.materializeCustomTools(workspaceId, userId)), |
| 560 | timed('mcp_servers', this.materializeMcpServers(workspaceId)), |
| 561 | timed('skills', this.materializeSkills(workspaceId)), |
| 562 | timed('tasks', this.materializeTasks(workspaceId, userId)), |
| 563 | timed('jobs', this.materializeJobs(workspaceId)), |
| 564 | timed('workspace_row', getWorkspaceWithOwner(workspaceId)), |
| 565 | timed('members', getUsersWithPermissions(workspaceId)), |
| 566 | ]) |
| 567 | |
| 568 | const workspaceMdData = { |
| 569 | workspace: wsRow, |
| 570 | members, |
no test coverage detected