@developerz.ai/ui-debugger-mcp 1.0.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.
Files changed (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +295 -0
  3. package/dist/adapters/android/adb.d.ts +38 -0
  4. package/dist/adapters/android/adb.js +72 -0
  5. package/dist/adapters/android/adb.js.map +1 -0
  6. package/dist/adapters/android/android-adapter.d.ts +63 -0
  7. package/dist/adapters/android/android-adapter.js +306 -0
  8. package/dist/adapters/android/android-adapter.js.map +1 -0
  9. package/dist/adapters/android/commands.d.ts +59 -0
  10. package/dist/adapters/android/commands.js +178 -0
  11. package/dist/adapters/android/commands.js.map +1 -0
  12. package/dist/adapters/android/uiautomator.d.ts +81 -0
  13. package/dist/adapters/android/uiautomator.js +296 -0
  14. package/dist/adapters/android/uiautomator.js.map +1 -0
  15. package/dist/adapters/browser/browser-adapter.d.ts +72 -0
  16. package/dist/adapters/browser/browser-adapter.js +434 -0
  17. package/dist/adapters/browser/browser-adapter.js.map +1 -0
  18. package/dist/adapters/browser/cdp.d.ts +83 -0
  19. package/dist/adapters/browser/cdp.js +308 -0
  20. package/dist/adapters/browser/cdp.js.map +1 -0
  21. package/dist/adapters/browser/query.d.ts +25 -0
  22. package/dist/adapters/browser/query.js +85 -0
  23. package/dist/adapters/browser/query.js.map +1 -0
  24. package/dist/adapters/contract.d.ts +159 -0
  25. package/dist/adapters/contract.js +22 -0
  26. package/dist/adapters/contract.js.map +1 -0
  27. package/dist/adapters/desktop/atspi.d.ts +95 -0
  28. package/dist/adapters/desktop/atspi.js +359 -0
  29. package/dist/adapters/desktop/atspi.js.map +1 -0
  30. package/dist/adapters/desktop/capture.d.ts +35 -0
  31. package/dist/adapters/desktop/capture.js +67 -0
  32. package/dist/adapters/desktop/capture.js.map +1 -0
  33. package/dist/adapters/desktop/desktop-adapter.d.ts +60 -0
  34. package/dist/adapters/desktop/desktop-adapter.js +215 -0
  35. package/dist/adapters/desktop/desktop-adapter.js.map +1 -0
  36. package/dist/adapters/desktop/input.d.ts +67 -0
  37. package/dist/adapters/desktop/input.js +191 -0
  38. package/dist/adapters/desktop/input.js.map +1 -0
  39. package/dist/adapters/desktop/proc.d.ts +23 -0
  40. package/dist/adapters/desktop/proc.js +38 -0
  41. package/dist/adapters/desktop/proc.js.map +1 -0
  42. package/dist/adapters/factory.d.ts +23 -0
  43. package/dist/adapters/factory.js +45 -0
  44. package/dist/adapters/factory.js.map +1 -0
  45. package/dist/agent/belt/act.d.ts +100 -0
  46. package/dist/agent/belt/act.js +166 -0
  47. package/dist/agent/belt/act.js.map +1 -0
  48. package/dist/agent/belt/look.d.ts +98 -0
  49. package/dist/agent/belt/look.js +160 -0
  50. package/dist/agent/belt/look.js.map +1 -0
  51. package/dist/agent/belt/observe.d.ts +102 -0
  52. package/dist/agent/belt/observe.js +185 -0
  53. package/dist/agent/belt/observe.js.map +1 -0
  54. package/dist/agent/belt/report.d.ts +133 -0
  55. package/dist/agent/belt/report.js +112 -0
  56. package/dist/agent/belt/report.js.map +1 -0
  57. package/dist/agent/loop.d.ts +136 -0
  58. package/dist/agent/loop.js +173 -0
  59. package/dist/agent/loop.js.map +1 -0
  60. package/dist/agent/models.d.ts +26 -0
  61. package/dist/agent/models.js +22 -0
  62. package/dist/agent/models.js.map +1 -0
  63. package/dist/agent/prompts/android-addendum.d.ts +12 -0
  64. package/dist/agent/prompts/android-addendum.js +76 -0
  65. package/dist/agent/prompts/android-addendum.js.map +1 -0
  66. package/dist/agent/prompts/compose.d.ts +30 -0
  67. package/dist/agent/prompts/compose.js +52 -0
  68. package/dist/agent/prompts/compose.js.map +1 -0
  69. package/dist/agent/prompts/debug-agent.d.ts +9 -0
  70. package/dist/agent/prompts/debug-agent.js +102 -0
  71. package/dist/agent/prompts/debug-agent.js.map +1 -0
  72. package/dist/agent/prompts/desktop-addendum.d.ts +10 -0
  73. package/dist/agent/prompts/desktop-addendum.js +66 -0
  74. package/dist/agent/prompts/desktop-addendum.js.map +1 -0
  75. package/dist/agent/prompts/web-addendum.d.ts +9 -0
  76. package/dist/agent/prompts/web-addendum.js +70 -0
  77. package/dist/agent/prompts/web-addendum.js.map +1 -0
  78. package/dist/agent/provider.d.ts +17 -0
  79. package/dist/agent/provider.js +29 -0
  80. package/dist/agent/provider.js.map +1 -0
  81. package/dist/cli/control.d.ts +19 -0
  82. package/dist/cli/control.js +152 -0
  83. package/dist/cli/control.js.map +1 -0
  84. package/dist/cli/help.d.ts +9 -0
  85. package/dist/cli/help.js +41 -0
  86. package/dist/cli/help.js.map +1 -0
  87. package/dist/cli/init.d.ts +20 -0
  88. package/dist/cli/init.js +119 -0
  89. package/dist/cli/init.js.map +1 -0
  90. package/dist/config/load.d.ts +64 -0
  91. package/dist/config/load.js +105 -0
  92. package/dist/config/load.js.map +1 -0
  93. package/dist/config/schema.d.ts +105 -0
  94. package/dist/config/schema.js +62 -0
  95. package/dist/config/schema.js.map +1 -0
  96. package/dist/errors.d.ts +41 -0
  97. package/dist/errors.js +90 -0
  98. package/dist/errors.js.map +1 -0
  99. package/dist/findings/schema.d.ts +64 -0
  100. package/dist/findings/schema.js +27 -0
  101. package/dist/findings/schema.js.map +1 -0
  102. package/dist/index.d.ts +2 -0
  103. package/dist/index.js +4 -0
  104. package/dist/index.js.map +1 -0
  105. package/dist/main.d.ts +2 -0
  106. package/dist/main.js +95 -0
  107. package/dist/main.js.map +1 -0
  108. package/dist/mcp/server.d.ts +25 -0
  109. package/dist/mcp/server.js +31 -0
  110. package/dist/mcp/server.js.map +1 -0
  111. package/dist/mcp/tools/describe.d.ts +12 -0
  112. package/dist/mcp/tools/describe.js +32 -0
  113. package/dist/mcp/tools/describe.js.map +1 -0
  114. package/dist/mcp/tools/end-session.d.ts +11 -0
  115. package/dist/mcp/tools/end-session.js +27 -0
  116. package/dist/mcp/tools/end-session.js.map +1 -0
  117. package/dist/mcp/tools/get-findings.d.ts +12 -0
  118. package/dist/mcp/tools/get-findings.js +42 -0
  119. package/dist/mcp/tools/get-findings.js.map +1 -0
  120. package/dist/mcp/tools/index.d.ts +17 -0
  121. package/dist/mcp/tools/index.js +24 -0
  122. package/dist/mcp/tools/index.js.map +1 -0
  123. package/dist/mcp/tools/result.d.ts +10 -0
  124. package/dist/mcp/tools/result.js +20 -0
  125. package/dist/mcp/tools/result.js.map +1 -0
  126. package/dist/mcp/tools/send-message.d.ts +11 -0
  127. package/dist/mcp/tools/send-message.js +31 -0
  128. package/dist/mcp/tools/send-message.js.map +1 -0
  129. package/dist/mcp/tools/start-debug.d.ts +12 -0
  130. package/dist/mcp/tools/start-debug.js +50 -0
  131. package/dist/mcp/tools/start-debug.js.map +1 -0
  132. package/dist/services/debug-service.d.ts +133 -0
  133. package/dist/services/debug-service.js +163 -0
  134. package/dist/services/debug-service.js.map +1 -0
  135. package/dist/services/replay.d.ts +102 -0
  136. package/dist/services/replay.js +184 -0
  137. package/dist/services/replay.js.map +1 -0
  138. package/dist/services/session-builder.d.ts +65 -0
  139. package/dist/services/session-builder.js +198 -0
  140. package/dist/services/session-builder.js.map +1 -0
  141. package/dist/services/summarize.d.ts +59 -0
  142. package/dist/services/summarize.js +93 -0
  143. package/dist/services/summarize.js.map +1 -0
  144. package/dist/session/findings-store.d.ts +52 -0
  145. package/dist/session/findings-store.js +176 -0
  146. package/dist/session/findings-store.js.map +1 -0
  147. package/dist/session/manager.d.ts +47 -0
  148. package/dist/session/manager.js +66 -0
  149. package/dist/session/manager.js.map +1 -0
  150. package/dist/session/process-identity.d.ts +45 -0
  151. package/dist/session/process-identity.js +81 -0
  152. package/dist/session/process-identity.js.map +1 -0
  153. package/dist/session/session.d.ts +156 -0
  154. package/dist/session/session.js +309 -0
  155. package/dist/session/session.js.map +1 -0
  156. package/dist/session/state-file.d.ts +72 -0
  157. package/dist/session/state-file.js +104 -0
  158. package/dist/session/state-file.js.map +1 -0
  159. package/dist/session/workspace.d.ts +60 -0
  160. package/dist/session/workspace.js +75 -0
  161. package/dist/session/workspace.js.map +1 -0
  162. package/package.json +53 -0
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Web-target addendum for the debug agent system prompt.
3
+ *
4
+ * Teaches CDP reach: which domains to use, why, and the DOM-first rule.
5
+ * Appended to the base prompt by `compose.ts` when target is "web".
6
+ *
7
+ * Provider-agnostic — no vendor tricks; any competent model drives the same loop.
8
+ */
9
+ export declare const WEB_ADDENDUM_PROMPT = "## Web target \u2014 CDP reach\n\nYour browser connection uses the Chrome DevTools Protocol (CDP).\nOne connection reaches everything: the current page, every iframe (including\nout-of-process), all tabs and windows, workers \u2014 plus DOM, console, network,\ninput, and screenshots. Use it deliberately.\n\n### CDP domains and when to reach for each\n\n| Domain | What it gives you | Use via |\n|-------------|-------------------|---------|\n| `Target` | enumerate/switch tabs and frames | `observe({kind:\"tree\"})` with `within` to scope to a frame |\n| `Page` | navigate, wait for load, capture screenshot | `act({action:\"navigate\"})`, `observe({kind:\"screenshot\"})` |\n| `DOM` | read/query the element tree, attributes, text | `observe({kind:\"tree\"})` |\n| `Runtime` | evaluate JS in a context (e.g. read a value not in the DOM) | `observe({kind:\"tree\", query:\"Runtime.evaluate:...\"})` |\n| `Network` | request/response status, failed requests, timing | `observe({kind:\"network\"})` |\n| `Log` | browser console messages, JS errors | `observe({kind:\"console\"})` |\n\n### DOM-first rule\n\nAlways try the structured path before asking for vision:\n1. `observe({kind:\"tree\"})` \u2014 read element roles, names, bounds, enabled state.\n2. If an element is not visible in the tree, try scrolling or waiting, then re-observe.\n3. Use `observe({kind:\"console\"})` and `observe({kind:\"network\"})` proactively after\n each meaningful action \u2014 errors land there before they surface visually.\n4. Only after the tree gives you no answer: call `look` for pixels.\n\n### Multi-frame / tab navigation\n\nIf the goal involves an iframe or a new tab:\n- Enumerate frames via the Target domain (use `observe` with appropriate scope).\n- Switch context to the target frame/tab before acting inside it.\n- After navigation, wait for the page to settle before reading state.\n\n### Login bypass\n\nIf the target has `?debug-ai=true` support (the app's captcha bypass gate),\nappend it to the login URL before navigating. This skips captcha only \u2014 not auth.\nThe app must have `ALLOW_AI_DEBUG_LOGIN=true` set in its environment.\n\n### Selectors \u2014 use the node's `target`, don't invent one\n\nMost actionable nodes from `observe({kind:\"tree\"})` carry a ready-to-use `target`\nstring (e.g. `role=button[name=\"Add to cart\" i]`, with `>> nth=N` when names repeat).\nWhen a node has a `target`, COPY it verbatim into `act({action, target})`.\nDo NOT hand-craft a selector \u2014 guessed CSS like `button[name=\"...\"]` will not resolve.\n\nIf a node has no `target` (unnamed/non-semantic, or a scoped `within`/`filters`\nread), you may pass its visible text as `target` (plain text resolves), or\n`role \"name\"`. Avoid XPath and positional CSS.\n\n### Console + network \u2014 watch always\n\nAfter every `act`, immediately:\n1. Check `observe({kind:\"console\"})` for JS errors or warnings.\n2. Check `observe({kind:\"network\"})` for failed requests (4xx/5xx).\n\nRecord any errors as `console` or `network` bugs with the request URL / error\nmessage as `detail` and the screenshot path as `evidence` when relevant.\n";
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Web-target addendum for the debug agent system prompt.
3
+ *
4
+ * Teaches CDP reach: which domains to use, why, and the DOM-first rule.
5
+ * Appended to the base prompt by `compose.ts` when target is "web".
6
+ *
7
+ * Provider-agnostic — no vendor tricks; any competent model drives the same loop.
8
+ */
9
+ export const WEB_ADDENDUM_PROMPT = `\
10
+ ## Web target — CDP reach
11
+
12
+ Your browser connection uses the Chrome DevTools Protocol (CDP).
13
+ One connection reaches everything: the current page, every iframe (including
14
+ out-of-process), all tabs and windows, workers — plus DOM, console, network,
15
+ input, and screenshots. Use it deliberately.
16
+
17
+ ### CDP domains and when to reach for each
18
+
19
+ | Domain | What it gives you | Use via |
20
+ |-------------|-------------------|---------|
21
+ | \`Target\` | enumerate/switch tabs and frames | \`observe({kind:"tree"})\` with \`within\` to scope to a frame |
22
+ | \`Page\` | navigate, wait for load, capture screenshot | \`act({action:"navigate"})\`, \`observe({kind:"screenshot"})\` |
23
+ | \`DOM\` | read/query the element tree, attributes, text | \`observe({kind:"tree"})\` |
24
+ | \`Runtime\` | evaluate JS in a context (e.g. read a value not in the DOM) | \`observe({kind:"tree", query:"Runtime.evaluate:..."})\` |
25
+ | \`Network\` | request/response status, failed requests, timing | \`observe({kind:"network"})\` |
26
+ | \`Log\` | browser console messages, JS errors | \`observe({kind:"console"})\` |
27
+
28
+ ### DOM-first rule
29
+
30
+ Always try the structured path before asking for vision:
31
+ 1. \`observe({kind:"tree"})\` — read element roles, names, bounds, enabled state.
32
+ 2. If an element is not visible in the tree, try scrolling or waiting, then re-observe.
33
+ 3. Use \`observe({kind:"console"})\` and \`observe({kind:"network"})\` proactively after
34
+ each meaningful action — errors land there before they surface visually.
35
+ 4. Only after the tree gives you no answer: call \`look\` for pixels.
36
+
37
+ ### Multi-frame / tab navigation
38
+
39
+ If the goal involves an iframe or a new tab:
40
+ - Enumerate frames via the Target domain (use \`observe\` with appropriate scope).
41
+ - Switch context to the target frame/tab before acting inside it.
42
+ - After navigation, wait for the page to settle before reading state.
43
+
44
+ ### Login bypass
45
+
46
+ If the target has \`?debug-ai=true\` support (the app's captcha bypass gate),
47
+ append it to the login URL before navigating. This skips captcha only — not auth.
48
+ The app must have \`ALLOW_AI_DEBUG_LOGIN=true\` set in its environment.
49
+
50
+ ### Selectors — use the node's \`target\`, don't invent one
51
+
52
+ Most actionable nodes from \`observe({kind:"tree"})\` carry a ready-to-use \`target\`
53
+ string (e.g. \`role=button[name="Add to cart" i]\`, with \`>> nth=N\` when names repeat).
54
+ When a node has a \`target\`, COPY it verbatim into \`act({action, target})\`.
55
+ Do NOT hand-craft a selector — guessed CSS like \`button[name="..."]\` will not resolve.
56
+
57
+ If a node has no \`target\` (unnamed/non-semantic, or a scoped \`within\`/\`filters\`
58
+ read), you may pass its visible text as \`target\` (plain text resolves), or
59
+ \`role "name"\`. Avoid XPath and positional CSS.
60
+
61
+ ### Console + network — watch always
62
+
63
+ After every \`act\`, immediately:
64
+ 1. Check \`observe({kind:"console"})\` for JS errors or warnings.
65
+ 2. Check \`observe({kind:"network"})\` for failed requests (4xx/5xx).
66
+
67
+ Record any errors as \`console\` or \`network\` bugs with the request URL / error
68
+ message as \`detail\` and the screenshot path as \`evidence\` when relevant.
69
+ `;
70
+ //# sourceMappingURL=web-addendum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-addendum.js","sourceRoot":"","sources":["../../../src/agent/prompts/web-addendum.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4DlC,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * OpenAI-compatible provider (OpenRouter default) for the debug agent.
3
+ * Resolves API key and base URL with fallbacks from environment variables.
4
+ */
5
+ import { type OpenRouterProvider } from '@openrouter/ai-sdk-provider';
6
+ export interface ProviderOptions {
7
+ apiKey?: string;
8
+ baseURL?: string;
9
+ }
10
+ /**
11
+ * Create an OpenRouter provider with fallback resolution.
12
+ * Resolves apiKey from: provided value → OPENAI_API_KEY → OPENROUTER_API_KEY
13
+ * Resolves baseURL from: provided value → OPENAI_BASE_URL → DEFAULT_BASE_URL
14
+ * Throws ProviderError if no API key is found or if it's empty.
15
+ */
16
+ export declare function createOpenRouterProvider(options?: ProviderOptions): OpenRouterProvider;
17
+ export type { OpenRouterProvider };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * OpenAI-compatible provider (OpenRouter default) for the debug agent.
3
+ * Resolves API key and base URL with fallbacks from environment variables.
4
+ */
5
+ import { createOpenRouter } from '@openrouter/ai-sdk-provider';
6
+ import { ProviderError } from '../errors.js';
7
+ const DEFAULT_BASE_URL = 'https://openrouter.ai/api/v1';
8
+ /**
9
+ * Create an OpenRouter provider with fallback resolution.
10
+ * Resolves apiKey from: provided value → OPENAI_API_KEY → OPENROUTER_API_KEY
11
+ * Resolves baseURL from: provided value → OPENAI_BASE_URL → DEFAULT_BASE_URL
12
+ * Throws ProviderError if no API key is found or if it's empty.
13
+ */
14
+ export function createOpenRouterProvider(options = {}) {
15
+ // Resolve API key with fallback chain
16
+ const apiKey = options.apiKey || process.env.OPENAI_API_KEY || process.env.OPENROUTER_API_KEY || '';
17
+ // Validate API key
18
+ if (!apiKey || apiKey.trim() === '') {
19
+ throw new ProviderError('No API key found. Set OPENAI_API_KEY or OPENROUTER_API_KEY in the environment, or provide apiKey in options.');
20
+ }
21
+ // Resolve base URL with fallback
22
+ const baseURL = options.baseURL || process.env.OPENAI_BASE_URL || DEFAULT_BASE_URL;
23
+ // Create and return the provider
24
+ return createOpenRouter({
25
+ apiKey,
26
+ ...(baseURL ? { baseURL } : {}),
27
+ });
28
+ }
29
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/agent/provider.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAA2B,MAAM,6BAA6B,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,gBAAgB,GAAG,8BAA8B,CAAC;AAOxD;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,UAA2B,EAAE;IACpE,sCAAsC;IACtC,MAAM,MAAM,GACV,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,EAAE,CAAC;IAEvF,mBAAmB;IACnB,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACpC,MAAM,IAAI,aAAa,CACrB,8GAA8G,CAC/G,CAAC;IACJ,CAAC;IAED,iCAAiC;IACjC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,gBAAgB,CAAC;IAEnF,iCAAiC;IACjC,OAAO,gBAAgB,CAAC;QACtB,MAAM;QACN,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * `ui-debugger-mcp status` / `stop` — quick out-of-band run control.
3
+ *
4
+ * The live run lives in the server process's memory; these subcommands run in a
5
+ * *separate* process, so they work off the `state.json` breadcrumb the server
6
+ * drops (see {@link FileStatePort}) plus the session's `findings.json`:
7
+ *
8
+ * - `status` — print which run is active, whether the server is still alive, the
9
+ * current verdict, and finding counts. Read-only.
10
+ * - `stop` — signal the recorded server pid (SIGTERM) for a graceful teardown
11
+ * (the server ends the run, frees the profile, exits) and mark the state
12
+ * `stopped`. No live server → just mark it stopped.
13
+ *
14
+ * Neither needs the model API key — they resolve only the workspace dir.
15
+ */
16
+ /** `ui-debugger-mcp status` — print the active run's state + findings summary. */
17
+ export declare function runStatus(cwd?: string): Promise<void>;
18
+ /** `ui-debugger-mcp stop` — signal the server to tear the run down, mark state stopped. */
19
+ export declare function runStop(cwd?: string): Promise<void>;
@@ -0,0 +1,152 @@
1
+ /**
2
+ * `ui-debugger-mcp status` / `stop` — quick out-of-band run control.
3
+ *
4
+ * The live run lives in the server process's memory; these subcommands run in a
5
+ * *separate* process, so they work off the `state.json` breadcrumb the server
6
+ * drops (see {@link FileStatePort}) plus the session's `findings.json`:
7
+ *
8
+ * - `status` — print which run is active, whether the server is still alive, the
9
+ * current verdict, and finding counts. Read-only.
10
+ * - `stop` — signal the recorded server pid (SIGTERM) for a graceful teardown
11
+ * (the server ends the run, frees the profile, exits) and mark the state
12
+ * `stopped`. No live server → just mark it stopped.
13
+ *
14
+ * Neither needs the model API key — they resolve only the workspace dir.
15
+ */
16
+ import { readFile } from 'node:fs/promises';
17
+ import { isAbsolute, join } from 'node:path';
18
+ import { loadWorkspaceDir } from '../config/load.js';
19
+ import { FindingsSchema } from '../findings/schema.js';
20
+ import { verifyIdentity } from '../session/process-identity.js';
21
+ import { markStatus, readState } from '../session/state-file.js';
22
+ import { resolveProject, workspacePaths } from '../session/workspace.js';
23
+ /** Whether `pid` is a live process this user can see (`kill(pid, 0)`). */
24
+ function isAlive(pid) {
25
+ try {
26
+ process.kill(pid, 0);
27
+ return true;
28
+ }
29
+ catch (err) {
30
+ // EPERM = the process exists but is owned by another user — still "alive".
31
+ return err.code === 'EPERM';
32
+ }
33
+ }
34
+ /**
35
+ * Is the recorded server *genuinely* still alive — not an unrelated process that
36
+ * inherited a recycled PID? A verified `match` is alive; a `stale` PID (recycled)
37
+ * or a `gone` PID is dead. When the identity can't be verified (non-Linux), fall
38
+ * back to a bare liveness probe — best effort, same as before this guard existed.
39
+ */
40
+ function serverAlive(pid, check) {
41
+ if (check === 'match')
42
+ return true;
43
+ if (check === 'stale' || check === 'gone')
44
+ return false;
45
+ return isAlive(pid);
46
+ }
47
+ /** Resolve the recorded run's liveness, guarding against PID reuse. */
48
+ function checkServer(pid, identity) {
49
+ const check = verifyIdentity(pid, identity);
50
+ return { check, alive: serverAlive(pid, check) };
51
+ }
52
+ /** Read + validate a session's `findings.json`; `null` when absent/malformed. */
53
+ async function readFindings(sessionDir) {
54
+ try {
55
+ const raw = await readFile(join(sessionDir, 'findings.json'), 'utf8');
56
+ const parsed = FindingsSchema.safeParse(JSON.parse(raw));
57
+ return parsed.success ? parsed.data : null;
58
+ }
59
+ catch {
60
+ return null;
61
+ }
62
+ }
63
+ /** Resolve `state.json` for the current project (no API key needed). */
64
+ function stateJsonPath(cwd = process.cwd()) {
65
+ // A relative workspace is anchored at the project root (cwd), matching the server.
66
+ const base = loadWorkspaceDir(cwd);
67
+ const workspace = workspacePaths(cwd, isAbsolute(base) ? base : join(cwd, base));
68
+ return { project: resolveProject(cwd), stateJson: workspace.stateJson };
69
+ }
70
+ /** `ui-debugger-mcp status` — print the active run's state + findings summary. */
71
+ export async function runStatus(cwd = process.cwd()) {
72
+ const { project, stateJson } = stateJsonPath(cwd);
73
+ const state = await readState(stateJson);
74
+ if (!state) {
75
+ console.log(`ui-debugger-mcp: no debug run recorded for '${project}'.`);
76
+ return;
77
+ }
78
+ const { check, alive } = checkServer(state.pid, state.identity);
79
+ const findings = await readFindings(state.sessionDir);
80
+ // Server up + nothing settled yet → trust findings' live status; else the recorded terminal.
81
+ const verdict = alive && state.status === 'running' ? (findings?.status ?? 'running') : state.status;
82
+ const counts = findings
83
+ ? `${findings.bugs.length} bugs, ${findings.visual.length} visual, ${findings.steps.length} steps`
84
+ : 'no findings yet';
85
+ // A recycled PID owns a different process now — say so rather than imply our server lives.
86
+ const serverState = check === 'stale' ? 'not running (PID reused)' : alive ? 'running' : 'not running';
87
+ console.log(`ui-debugger-mcp — ${project}`);
88
+ console.log(` run: ${state.sessionId}`);
89
+ console.log(` target: ${state.target}`);
90
+ console.log(` goal: ${truncate(state.goal, 72)}`);
91
+ console.log(` server: pid ${state.pid} — ${serverState}`);
92
+ console.log(` status: ${verdict}`);
93
+ console.log(` findings: ${counts}`);
94
+ console.log(` started: ${state.startedAt}`);
95
+ console.log(` session: ${state.sessionDir}`);
96
+ }
97
+ /** `ui-debugger-mcp stop` — signal the server to tear the run down, mark state stopped. */
98
+ export async function runStop(cwd = process.cwd()) {
99
+ const { project, stateJson } = stateJsonPath(cwd);
100
+ const state = await readState(stateJson);
101
+ if (!state) {
102
+ console.log(`ui-debugger-mcp: no active debug run to stop for '${project}'.`);
103
+ return;
104
+ }
105
+ const { check, alive } = checkServer(state.pid, state.identity);
106
+ // The recorded PID is alive but now owns an *unrelated* process (it was recycled
107
+ // after our server died). Signaling it would kill an innocent process — don't.
108
+ // Our server is provably gone, so mark the run stopped without ever signaling.
109
+ if (check === 'stale') {
110
+ await markStatus(stateJson, 'stopped');
111
+ console.log(`ui-debugger-mcp: server (pid ${state.pid}) is gone — its PID was reused by an unrelated process; marked run '${state.sessionId}' stopped without signaling.`);
112
+ return;
113
+ }
114
+ if (alive) {
115
+ const signaled = signalStop(state.pid);
116
+ if (!signaled.ok) {
117
+ // The signal failed for a reason other than the process already being gone
118
+ // (e.g. EPERM). Teardown did NOT happen — don't lie by marking it stopped.
119
+ console.error(`ui-debugger-mcp: failed to signal server (pid ${state.pid}): ${signaled.reason}. Run '${state.sessionId}' left as-is.`);
120
+ process.exitCode = 1;
121
+ return;
122
+ }
123
+ await markStatus(stateJson, 'stopped');
124
+ const how = signaled.gone ? `pid ${state.pid} already exited` : `SIGTERM → pid ${state.pid}`;
125
+ console.log(`ui-debugger-mcp: stopping run '${state.sessionId}' (${how}).`);
126
+ return;
127
+ }
128
+ await markStatus(stateJson, 'stopped');
129
+ console.log(`ui-debugger-mcp: server (pid ${state.pid}) is not running; marked run '${state.sessionId}' stopped.`);
130
+ }
131
+ /**
132
+ * SIGTERM the recorded server pid. Only the `ESRCH` race (the pid vanished between
133
+ * the liveness check and here — teardown already happened) is treated as benign
134
+ * (`gone`); any other failure surfaces so the caller never reports a false stop.
135
+ */
136
+ function signalStop(pid) {
137
+ try {
138
+ process.kill(pid, 'SIGTERM');
139
+ return { ok: true, gone: false };
140
+ }
141
+ catch (err) {
142
+ const code = err.code;
143
+ if (code === 'ESRCH')
144
+ return { ok: true, gone: true };
145
+ return { ok: false, reason: code ?? (err instanceof Error ? err.message : String(err)) };
146
+ }
147
+ }
148
+ /** Clamp a string to `max` chars with an ellipsis. */
149
+ function truncate(s, max) {
150
+ return s.length <= max ? s : `${s.slice(0, max - 1)}…`;
151
+ }
152
+ //# sourceMappingURL=control.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control.js","sourceRoot":"","sources":["../../src/cli/control.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAA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kCAAkC,KAAK,CAAC,SAAS,MAAM,GAAG,IAAI,CAAC,CAAC;QAC5E,OAAO;IACT,CAAC;IAED,MAAM,UAAU,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IACvC,OAAO,CAAC,GAAG,CACT,gCAAgC,KAAK,CAAC,GAAG,iCAAiC,KAAK,CAAC,SAAS,YAAY,CACtG,CAAC;AACJ,CAAC;AAKD;;;;GAIG;AACH,SAAS,UAAU,CAAC,GAAW;IAC7B,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAC7B,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACnC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,GAAI,GAA6B,CAAC,IAAI,CAAC;QACjD,IAAI,IAAI,KAAK,OAAO;YAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QACtD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,IAAI,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;IAC3F,CAAC;AACH,CAAC;AAED,sDAAsD;AACtD,SAAS,QAAQ,CAAC,CAAS,EAAE,GAAW;IACtC,OAAO,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC;AACzD,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `ui-debugger-mcp --help` / `--version` — usage and version info.
3
+ *
4
+ * No project config needed. Print and exit(0).
5
+ */
6
+ /** Print usage and exit. */
7
+ export declare function runHelp(): void;
8
+ /** Print version and exit. */
9
+ export declare function runVersion(): void;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * `ui-debugger-mcp --help` / `--version` — usage and version info.
3
+ *
4
+ * No project config needed. Print and exit(0).
5
+ */
6
+ import { NAME, VERSION } from '../index.js';
7
+ const USAGE = `${NAME} — autonomous UI debugger (MCP server)
8
+
9
+ USAGE:
10
+ ${NAME} [subcommand] [options]
11
+
12
+ SUBCOMMANDS:
13
+ init Scaffold a new project (.ui-debugger-mcp.json, workspace)
14
+ status Print the active debug run's state + findings summary
15
+ stop Signal the server to tear down the active run gracefully
16
+ (no subcommand) Boot the stdio MCP server (default, for Claude use)
17
+
18
+ OPTIONS:
19
+ --help, -h Show this message and exit
20
+ --version, -v Show version and exit
21
+
22
+ EXAMPLES:
23
+ ui-debugger-mcp init Set up a new project
24
+ ui-debugger-mcp status Check the current run
25
+ ui-debugger-mcp stop Stop the active run
26
+ ui-debugger-mcp Boot the server (via .mcp.json)
27
+
28
+ DOCS:
29
+ https://github.com/developerz-ai/ui-debugger-mcp
30
+ `;
31
+ /** Print usage and exit. */
32
+ export function runHelp() {
33
+ console.log(USAGE);
34
+ process.exit(0);
35
+ }
36
+ /** Print version and exit. */
37
+ export function runVersion() {
38
+ console.log(`${NAME} v${VERSION}`);
39
+ process.exit(0);
40
+ }
41
+ //# sourceMappingURL=help.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"help.js","sourceRoot":"","sources":["../../src/cli/help.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,KAAK,GAAG,GAAG,IAAI;;;IAGjB,IAAI;;;;;;;;;;;;;;;;;;;;CAoBP,CAAC;AAEF,4BAA4B;AAC5B,MAAM,UAAU,OAAO;IACrB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,8BAA8B;AAC9B,MAAM,UAAU,UAAU;IACxB,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;IACnC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * `ui-debugger-mcp init` — scaffold a project for use with this server.
3
+ *
4
+ * Idempotent: never clobbers existing files. Runs in `process.cwd()`.
5
+ *
6
+ * Steps:
7
+ * 1. mkdir ./tmp/ui-debugger-mcp/
8
+ * 2. write .ui-debugger-mcp.json (only if absent)
9
+ * 3. add `tmp/` to .gitignore (only if the line is missing)
10
+ * 4. print .mcp.json snippet (never writes the API key)
11
+ */
12
+ import { UiDebuggerError } from '../errors.js';
13
+ export declare class InitError extends UiDebuggerError {
14
+ constructor(message: string);
15
+ }
16
+ /**
17
+ * Run the init scaffold in `cwd`.
18
+ * Throws `InitError` on filesystem failures.
19
+ */
20
+ export declare function runInit(cwd?: string): void;
@@ -0,0 +1,119 @@
1
+ /**
2
+ * `ui-debugger-mcp init` — scaffold a project for use with this server.
3
+ *
4
+ * Idempotent: never clobbers existing files. Runs in `process.cwd()`.
5
+ *
6
+ * Steps:
7
+ * 1. mkdir ./tmp/ui-debugger-mcp/
8
+ * 2. write .ui-debugger-mcp.json (only if absent)
9
+ * 3. add `tmp/` to .gitignore (only if the line is missing)
10
+ * 4. print .mcp.json snippet (never writes the API key)
11
+ */
12
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
13
+ import { join } from 'node:path';
14
+ import { DEFAULT_MODELS, DEFAULT_WORKSPACE } from '../config/load.js';
15
+ import { UiDebuggerError } from '../errors.js';
16
+ export class InitError extends UiDebuggerError {
17
+ constructor(message) {
18
+ super(message);
19
+ this.name = 'InitError';
20
+ Object.setPrototypeOf(this, InitError.prototype);
21
+ }
22
+ }
23
+ /** Starter project config written on `init` (only if absent). */
24
+ const STARTER_CONFIG = JSON.stringify({
25
+ models: {
26
+ driver: DEFAULT_MODELS.driver,
27
+ vision: DEFAULT_MODELS.vision,
28
+ summary: DEFAULT_MODELS.summary,
29
+ },
30
+ workspace: DEFAULT_WORKSPACE,
31
+ targets: {
32
+ web: {
33
+ adapter: 'browser',
34
+ url: 'http://localhost:3000',
35
+ headless: true,
36
+ },
37
+ },
38
+ }, null, 2);
39
+ /** `.mcp.json` snippet printed to stdout (API key placeholder — never written). */
40
+ const MCP_JSON_SNIPPET = `{
41
+ "mcpServers": {
42
+ "ui-debugger": {
43
+ "command": "npx",
44
+ "args": ["-y", "@developerz.ai/ui-debugger-mcp"],
45
+ "env": {
46
+ "OPENAI_API_KEY": "<your-key-here>",
47
+ "OPENAI_BASE_URL": "https://openrouter.ai/api/v1"
48
+ }
49
+ }
50
+ }
51
+ }`;
52
+ /**
53
+ * Run the init scaffold in `cwd`.
54
+ * Throws `InitError` on filesystem failures.
55
+ */
56
+ export function runInit(cwd = process.cwd()) {
57
+ // 1. mkdir workspace
58
+ const workspaceDir = join(cwd, 'tmp', 'ui-debugger-mcp');
59
+ try {
60
+ mkdirSync(workspaceDir, { recursive: true });
61
+ }
62
+ catch (e) {
63
+ throw new InitError(`Failed to create workspace dir: ${e instanceof Error ? e.message : String(e)}`);
64
+ }
65
+ console.log(`✓ workspace ${workspaceDir}`);
66
+ // 2. write .ui-debugger-mcp.json (only if absent)
67
+ const configPath = join(cwd, '.ui-debugger-mcp.json');
68
+ if (existsSync(configPath)) {
69
+ console.log(` (skip) .ui-debugger-mcp.json already exists`);
70
+ }
71
+ else {
72
+ try {
73
+ writeFileSync(configPath, `${STARTER_CONFIG}\n`, 'utf8');
74
+ }
75
+ catch (e) {
76
+ throw new InitError(`Failed to write .ui-debugger-mcp.json: ${e instanceof Error ? e.message : String(e)}`);
77
+ }
78
+ console.log(`✓ created .ui-debugger-mcp.json`);
79
+ }
80
+ // 3. add `tmp/` to .gitignore (only if line absent)
81
+ const gitignorePath = join(cwd, '.gitignore');
82
+ ensureGitignoreLine(gitignorePath, 'tmp/');
83
+ // 4. print .mcp.json snippet
84
+ console.log(`
85
+ Paste into your .mcp.json (do NOT commit your API key):
86
+
87
+ ${MCP_JSON_SNIPPET}
88
+ `);
89
+ }
90
+ /**
91
+ * Ensure `line` appears in `.gitignore`. Creates the file if absent.
92
+ * Appends only; never rewrites existing content.
93
+ */
94
+ function ensureGitignoreLine(path, line) {
95
+ let existing = '';
96
+ if (existsSync(path)) {
97
+ try {
98
+ existing = readFileSync(path, 'utf8');
99
+ }
100
+ catch (e) {
101
+ throw new InitError(`Failed to read .gitignore: ${e instanceof Error ? e.message : String(e)}`);
102
+ }
103
+ }
104
+ const lines = existing.split('\n');
105
+ const already = lines.some((l) => l.trim() === line.trim());
106
+ if (already) {
107
+ console.log(` (skip) .gitignore already contains \`${line}\``);
108
+ return;
109
+ }
110
+ const append = `${(existing.endsWith('\n') || existing === '' ? '' : '\n') + line}\n`;
111
+ try {
112
+ writeFileSync(path, existing + append, 'utf8');
113
+ }
114
+ catch (e) {
115
+ throw new InitError(`Failed to update .gitignore: ${e instanceof Error ? e.message : String(e)}`);
116
+ }
117
+ console.log(`✓ .gitignore added \`${line}\``);
118
+ }
119
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/cli/init.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,OAAO,SAAU,SAAQ,eAAe;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,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AE,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAE5D,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,CAAC,8CAA8C,IAAI,IAAI,CAAC,CAAC;QACpE,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,QAAQ,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC;IACtF,IAAI,CAAC;QACH,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,SAAS,CACjB,gCAAgC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAC7E,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,IAAI,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Config loader + resolution order.
3
+ *
4
+ * Reads `./.ui-debugger-mcp.json` (cwd), Zod-validates it, and resolves a fully
5
+ * defaulted `ResolvedConfig`. Layering follows `idea/config.md`:
6
+ *
7
+ * built-in defaults < project file < env
8
+ *
9
+ * The layers govern disjoint fields, so the order is unambiguous:
10
+ * - models / workspace / targets → project file over defaults
11
+ * - provider creds (key, base url) → env over the OpenRouter default base url
12
+ * The per-session smart-agent overrides (top of the documented order) are a
13
+ * runtime concern, not the file loader's — out of scope here.
14
+ *
15
+ * Bad config fails fast and loud via `ConfigError` — never a silent fallback.
16
+ */
17
+ import type { Target } from './schema.js';
18
+ /** Committed, per-project debug config filename, resolved against the cwd. */
19
+ export declare const CONFIG_FILENAME = ".ui-debugger-mcp.json";
20
+ /** Default base url — OpenRouter. Override with env `OPENAI_BASE_URL`. */
21
+ export declare const OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1";
22
+ /** Default workspace dir (per-project sessions, profiles, logs). */
23
+ export declare const DEFAULT_WORKSPACE = "./tmp/ui-debugger-mcp";
24
+ /** Per-role model defaults — deepseek for text, glm for image. See `idea/models.md`. */
25
+ export declare const DEFAULT_MODELS: ResolvedModels;
26
+ /** Fully resolved per-role models — every role present after defaulting. */
27
+ export interface ResolvedModels {
28
+ driver: string;
29
+ vision: string;
30
+ summary: string;
31
+ }
32
+ /** OpenAI-compatible router credentials, resolved from env + the OpenRouter default. */
33
+ export interface ProviderConfig {
34
+ apiKey: string;
35
+ baseUrl: string;
36
+ }
37
+ /** Resolved config: project values with defaults filled and env-sourced creds. */
38
+ export interface ResolvedConfig {
39
+ models: ResolvedModels;
40
+ workspace: string;
41
+ targets: Record<string, Target>;
42
+ provider: ProviderConfig;
43
+ }
44
+ export interface LoadOptions {
45
+ /** Project root holding the config file. Defaults to `process.cwd()`. */
46
+ cwd?: string;
47
+ /** Environment source for provider creds. Defaults to `process.env`. */
48
+ env?: Record<string, string | undefined>;
49
+ }
50
+ /**
51
+ * Load, validate, and resolve the project config. Throws `ConfigError` if the
52
+ * file is missing, not JSON, fails the schema, or `OPENAI_API_KEY` is unset.
53
+ */
54
+ export declare function loadConfig(opts?: LoadOptions): ResolvedConfig;
55
+ /**
56
+ * Resolve just the workspace dir for a project — no provider creds required.
57
+ * Backs the `status` / `stop` CLI, which read `state.json` but need no API key.
58
+ *
59
+ * Falls back to {@link DEFAULT_WORKSPACE} only when the config file is ABSENT. A
60
+ * present-but-invalid config surfaces its `ConfigError` (fail loud, no silent
61
+ * fallback) — otherwise a typo anywhere in the file would silently point `status`/
62
+ * `stop` at the default workspace and report "no run" for a custom-workspace run.
63
+ */
64
+ export declare function loadWorkspaceDir(cwd?: string): string;