MCPcopy Index your code
hub / github.com/coder/mux / getTaskDepthFromConfig

Function getTaskDepthFromConfig

src/node/services/taskUtils.ts:78–106  ·  view source on GitHub ↗
(
  config: ReturnType<Config["loadConfigOrDefault"]>,
  workspaceId: string
)

Source from the content-addressed store, hash-verified

76 * Detects cycles (max 32 hops).
77 */
78export function getTaskDepthFromConfig(
79 config: ReturnType<Config["loadConfigOrDefault"]>,
80 workspaceId: string
81): number {
82 const parentById = new Map<string, string | undefined>();
83 for (const project of config.projects.values()) {
84 for (const workspace of project.workspaces) {
85 if (!workspace.id) continue;
86 parentById.set(workspace.id, workspace.parentWorkspaceId);
87 }
88 }
89
90 let depth = 0;
91 let current = workspaceId;
92 for (let i = 0; i < 32; i++) {
93 const parent = parentById.get(current);
94 if (!parent) break;
95 depth += 1;
96 current = parent;
97 }
98
99 if (depth >= 32) {
100 throw new Error(
101 `getTaskDepthFromConfig: possible parentWorkspaceId cycle starting at ${workspaceId}`
102 );
103 }
104
105 return depth;
106}

Callers 1

resolveAgentForStreamFunction · 0.90

Calls 2

setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected