@adhdev/daemon-core 0.6.11 → 0.6.13

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/dist/index.js CHANGED
@@ -6525,9 +6525,9 @@ var DaemonCommandRouter = class {
6525
6525
  const pkgName = isStandalone ? "@adhdev/daemon-standalone" : "adhdev";
6526
6526
  const latest = execSync7(`npm view ${pkgName} version`, { encoding: "utf-8", timeout: 1e4 }).trim();
6527
6527
  LOG.info("Upgrade", `Latest ${pkgName}: v${latest}`);
6528
- execSync7(`npm install -g ${pkgName}@latest`, {
6528
+ execSync7(`npm install -g ${pkgName}@latest --force`, {
6529
6529
  encoding: "utf-8",
6530
- timeout: 6e4,
6530
+ timeout: 12e4,
6531
6531
  stdio: ["pipe", "pipe", "pipe"]
6532
6532
  });
6533
6533
  LOG.info("Upgrade", `\u2705 Upgraded to v${latest}`);
@@ -9816,8 +9816,10 @@ function generateFiles(type, name, category, opts = {}) {
9816
9816
  if (cli) meta.cli = cli;
9817
9817
  if (cdpPorts) meta.cdpPorts = cdpPorts;
9818
9818
  else if (!isExtension) meta.cdpPorts = [9222, 9223];
9819
- if (processName) meta.processNames = { darwin: processName };
9820
- if (installPath) meta.paths = { darwin: [installPath] };
9819
+ if (opts.processNames) meta.processNames = opts.processNames;
9820
+ else if (processName) meta.processNames = { darwin: processName };
9821
+ if (opts.osPaths) meta.paths = opts.osPaths;
9822
+ else if (installPath) meta.paths = { darwin: [installPath] };
9821
9823
  if (isExtension) {
9822
9824
  meta.extensionId = extensionId || `publisher.${type}`;
9823
9825
  meta.extensionIdPattern = `${extensionId || type}`;
@@ -11085,7 +11087,9 @@ var DevServer = class _DevServer {
11085
11087
  installPath,
11086
11088
  binary,
11087
11089
  extensionId,
11088
- version
11090
+ version,
11091
+ osPaths,
11092
+ processNames
11089
11093
  } = body;
11090
11094
  if (!type || !name) {
11091
11095
  this.json(res, 400, { error: "type and name required" });
@@ -11104,7 +11108,7 @@ var DevServer = class _DevServer {
11104
11108
  return;
11105
11109
  }
11106
11110
  try {
11107
- const result = generateFiles(type, name, category, { cdpPorts, cli, processName, installPath, binary, extensionId, version });
11111
+ const result = generateFiles(type, name, category, { cdpPorts, cli, processName, installPath, binary, extensionId, version, osPaths, processNames });
11108
11112
  fs9.mkdirSync(targetDir, { recursive: true });
11109
11113
  fs9.writeFileSync(jsonPath, result["provider.json"], "utf-8");
11110
11114
  const createdFiles = ["provider.json"];
@@ -11901,50 +11905,8 @@ var DevServer = class _DevServer {
11901
11905
  return;
11902
11906
  }
11903
11907
  try {
11904
- this.sendAutoImplSSE({ event: "progress", data: { function: "_init", status: "analyzing", message: "DOM \uAD6C\uC870 \uC218\uC9D1 \uC911..." } });
11905
- let domContext = null;
11906
- const cdp = this.getCdp(type);
11907
- if (cdp) {
11908
- try {
11909
- const domScript = `(() => {
11910
- function fp(el) {
11911
- if (!el || el === document.body) return 'body';
11912
- const parts = [];
11913
- let c = el;
11914
- while (c && c !== document.documentElement) {
11915
- let s = c.tagName.toLowerCase();
11916
- if (c.id) s = '#' + c.id;
11917
- else if (c.className && typeof c.className === 'string') {
11918
- const cls = c.className.trim().split(/\\s+/).filter(x => x && !x.startsWith('_')).slice(0, 2);
11919
- if (cls.length) s += '.' + cls.join('.');
11920
- }
11921
- parts.unshift(s);
11922
- c = c.parentElement;
11923
- }
11924
- return parts.join(' > ');
11925
- }
11926
- const r = {};
11927
- // Content editables
11928
- r.editables = [...document.querySelectorAll('[contenteditable], textarea, input')].filter(e => e.offsetWidth > 0).slice(0, 10).map(e => ({
11929
- selector: fp(e), tag: e.tagName.toLowerCase(), ce: e.getAttribute('contenteditable'), role: e.getAttribute('role'), ph: e.getAttribute('placeholder')
11930
- }));
11931
- // Scroll containers
11932
- r.scrollContainers = [...document.querySelectorAll('div, section')].filter(e => {
11933
- const s = getComputedStyle(e); const b = e.getBoundingClientRect();
11934
- return (s.overflowY === 'auto' || s.overflowY === 'scroll') && b.height > 200 && e.children.length > 2;
11935
- }).slice(0, 5).map(e => ({ selector: fp(e), children: e.children.length, h: Math.round(e.getBoundingClientRect().height) }));
11936
- // Buttons
11937
- r.buttons = [...document.querySelectorAll('button, [role="button"]')].filter(e => e.offsetWidth > 0).slice(0, 20).map(e => ({
11938
- text: (e.textContent||'').trim().substring(0, 60), selector: fp(e), label: e.getAttribute('aria-label')
11939
- }));
11940
- return JSON.stringify(r);
11941
- })()`;
11942
- const raw = await cdp.evaluate(domScript, 1e4);
11943
- domContext = typeof raw === "string" ? JSON.parse(raw) : raw;
11944
- } catch (e) {
11945
- this.log(`DOM context collection failed (non-fatal): ${e.message}`);
11946
- }
11947
- }
11908
+ this.sendAutoImplSSE({ event: "progress", data: { function: "_init", status: "analyzing", message: "\uC5D0\uC774\uC804\uD2B8 \uCD08\uAE30\uD654 (DOM \uD0D0\uC0C9 \uAD8C\uD55C \uBD80\uC5EC)..." } });
11909
+ const domContext = null;
11948
11910
  this.sendAutoImplSSE({ event: "progress", data: { function: "_init", status: "loading_reference", message: `\uB808\uD37C\uB7F0\uC2A4 \uC2A4\uD06C\uB9BD\uD2B8 \uB85C\uB4DC \uC911 (${reference})...` } });
11949
11911
  let referenceScripts = {};
11950
11912
  const builtinDir = this.providerLoader.builtinDir || path12.resolve(__dirname, "../providers/_builtin");
@@ -12139,22 +12101,11 @@ var DevServer = class _DevServer {
12139
12101
  } else {
12140
12102
  args = [...baseArgs];
12141
12103
  }
12142
- const { execSync: execSync7 } = await import("child_process");
12143
- try {
12144
- execSync7(`which ${command}`, { stdio: "pipe" });
12145
- } catch {
12146
- try {
12147
- fs9.unlinkSync(promptFile);
12148
- } catch {
12149
- }
12150
- this.json(res, 400, { error: `Agent binary '${command}' not found on PATH. Install it first: ${agentProvider?.install || "check provider docs"}` });
12151
- return;
12152
- }
12153
12104
  this.sendAutoImplSSE({ event: "progress", data: { function: "_init", status: "spawning", message: `\uC5D0\uC774\uC804\uD2B8 \uC2E4\uD589 \uC911: ${command} ${args.join(" ")} (prompt: ${prompt.length} chars)` } });
12154
12105
  this.autoImplStatus = { running: true, type, progress: [] };
12155
12106
  const { spawn: spawnFn } = await import("child_process");
12156
12107
  const escapedArgs = args.map((a) => `'${a.replace(/'/g, "'\\''")}'`).join(" ");
12157
- const shellCmd = `cat '${promptFile}' | ${command} ${escapedArgs}`;
12108
+ const shellCmd = `${command} ${escapedArgs} -p "$(cat '${promptFile}')"`;
12158
12109
  this.log(`Auto-implement spawn: ${shellCmd}`);
12159
12110
  const child = spawnFn("sh", ["-c", shellCmd], {
12160
12111
  cwd: providerDir,
@@ -12313,6 +12264,7 @@ var DevServer = class _DevServer {
12313
12264
  lines.push("4. Always wrap in try-catch, return `JSON.stringify(result)`");
12314
12265
  lines.push("5. Do NOT modify `scripts.js` router \u2014 only edit individual `*.js` files");
12315
12266
  lines.push("6. All scripts run in the browser (CDP evaluate) \u2014 use DOM APIs only");
12267
+ lines.push('7. **Cross-Platform Compatibility**: If you use ARIA labels that contain keyboard shortcuts (e.g., `Cascade (\u2318L)`), you MUST use substring matches (`aria-label*="Cascade"`) or handle both macOS (`\u2318`, `Cmd`) and Windows (`Ctrl`) so the script does not break on other operating systems.');
12316
12268
  lines.push("");
12317
12269
  lines.push("## Required Return Format");
12318
12270
  lines.push("| Function | Return JSON |");
@@ -12335,42 +12287,40 @@ var DevServer = class _DevServer {
12335
12287
  lines.push("2. After editing, TEST each function using the DevConsole API (see below)");
12336
12288
  lines.push("3. If a test fails, fix the implementation and re-test");
12337
12289
  lines.push("");
12338
- lines.push("## DevConsole API (for testing)");
12339
- lines.push(`The DevConsole is running at \`http://127.0.0.1:${DEV_SERVER_PORT}\`. Use these HTTP APIs to test your implementations.`);
12290
+ lines.push("## YOU MUST EXPLORE THE DOM YOURSELF!");
12291
+ lines.push("I have NOT provided you with the DOM snapshot. You MUST use your command-line tools to discover the IDE structure dynamically!");
12340
12292
  lines.push("");
12341
- lines.push("### Run a script against the live IDE");
12293
+ lines.push("### 1. Evaluate JS to explore IDE DOM");
12294
+ lines.push("Use cURL to run JavaScript inside the IDE:");
12342
12295
  lines.push("```bash");
12343
- lines.push(`curl -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/providers/${type}/scripts/run \\`);
12296
+ lines.push(`curl -sS -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/cdp/evaluate \\`);
12344
12297
  lines.push(` -H "Content-Type: application/json" \\`);
12345
- lines.push(` -d '{"script": "readChat"}'`);
12346
- lines.push("```");
12347
- lines.push('Replace `"readChat"` with any function name. For functions with params:');
12348
- lines.push("```bash");
12349
- lines.push(`curl -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/providers/${type}/scripts/run \\`);
12350
- lines.push(` -H "Content-Type: application/json" \\`);
12351
- lines.push(` -d '{"script": "sendMessage", "params": {"text": "hello"}}'`);
12298
+ lines.push(` -d '{"expression": "document.body.innerHTML.substring(0, 1000)", "ideType": "${type}"}'`);
12352
12299
  lines.push("```");
12353
12300
  lines.push("");
12354
- lines.push("### Evaluate raw JS in the IDE (CDP)");
12355
- lines.push("```bash");
12356
- lines.push(`curl -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/cdp/evaluate \\`);
12357
- lines.push(` -H "Content-Type: application/json" \\`);
12358
- lines.push(` -d '{"expression": "document.title", "ideType": "${type}"}'`);
12359
- lines.push("```");
12360
- lines.push("");
12361
- lines.push("### Reload provider (after editing files)");
12301
+ lines.push("### 2. Test your generated function");
12302
+ lines.push("Once you save the file, test it by running:");
12362
12303
  lines.push("```bash");
12363
12304
  lines.push(`curl -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/providers/reload`);
12305
+ lines.push(`curl -sS -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/providers/${type}/scripts/run -H "Content-Type: application/json" -d '{"script": "readChat"}'`);
12364
12306
  lines.push("```");
12365
- lines.push("**IMPORTANT**: After editing script files, you MUST call reload before running scripts.");
12366
12307
  lines.push("");
12367
- lines.push("### Workflow: Edit \u2192 Reload \u2192 Test \u2192 Fix");
12368
- lines.push("1. Edit the `.js` file");
12369
- lines.push("2. `curl POST /api/providers/reload`");
12370
- lines.push(`3. \`curl POST /api/providers/${type}/scripts/run -d '{"script":"readChat"}'\``);
12371
- lines.push("4. Check the response \u2014 if error, fix and repeat from step 1");
12308
+ lines.push("### Task Workflow");
12309
+ lines.push("1. Write bash scripts to `curl` the CDP evaluate API above to find exactly where `.chat-message`, etc., are located.");
12310
+ lines.push("2. Iteratively explore until you are confident in your selectors.");
12311
+ lines.push("3. Edit the `.js` files using the selectors you discovered.");
12312
+ lines.push("4. Reload providers and TEST your script via the API.");
12313
+ lines.push("");
12314
+ lines.push("### \u{1F525} Advanced UI Parsing (CRUCIAL for `readChat`)");
12315
+ lines.push("Your `readChat` must flawlessly parse complex UI elements (tables, code blocks, tool calls, and AI thoughts). The quality must match the `antigravity` reference.");
12316
+ lines.push("To achieve this, you MUST generate a live test scenario:");
12317
+ lines.push("1. Early in your process, send a rich prompt to the IDE using the API:");
12318
+ lines.push(' `curl -sS -X POST http://127.0.0.1:${DEV_SERVER_PORT}/api/providers/${type}/scripts/run -H "Content-Type: application/json" -d \'{"script": "sendMessage", "params": {"text": "Write a python script, draw a markdown table, use a tool, and show your reasoning/thought process"}}\'`');
12319
+ lines.push("2. Wait a few seconds for the IDE AI to generate these elements in the UI.");
12320
+ lines.push("3. Use CDP evaluate to deeply inspect the DOM structure of the newly generated tables, code blocks, thought blocks, and tool calls.");
12321
+ lines.push("4. Ensure `readChat` extracts `content` with precise markdown formatting (especially for tables/code) and assigns correct `kind` tags (`thought`, `tool`, `terminal`).");
12372
12322
  lines.push("");
12373
- lines.push("Start NOW. Edit files, then test each one.");
12323
+ lines.push("Start NOW. Do not ask for permission. Explore the DOM -> Code -> Test.");
12374
12324
  return lines.join("\n");
12375
12325
  }
12376
12326
  handleAutoImplSSE(type, req, res) {
@@ -12900,20 +12850,21 @@ async function initDaemonComponents(config) {
12900
12850
  }
12901
12851
  providerLoader.loadAll();
12902
12852
  providerLoader.registerToDetector();
12903
- LOG.info("Init", "Detecting provider versions...");
12904
12853
  const versionArchive = new VersionArchive();
12905
12854
  providerLoader.setVersionArchive(versionArchive);
12906
- const versionResults = await detectAllVersions(providerLoader, versionArchive);
12907
- const installedProviders = versionResults.filter((v) => v.installed);
12908
- const withVersion = installedProviders.filter((v) => v.version);
12909
- LOG.info("Init", `Provider versions: ${installedProviders.length} installed, ${withVersion.length} versioned`);
12910
- for (const v of withVersion) {
12911
- LOG.info("Init", ` ${v.type} (${v.category}): v${v.version}${v.warning ? " \u26A0 " + v.warning : ""}`);
12912
- }
12913
- const noVersion = installedProviders.filter((v) => !v.version);
12914
- if (noVersion.length > 0) {
12915
- LOG.warn("Init", ` ${noVersion.length} installed but version unknown: ${noVersion.map((v) => v.type).join(", ")}`);
12916
- }
12855
+ detectAllVersions(providerLoader, versionArchive).then((versionResults) => {
12856
+ const installedProviders = versionResults.filter((v) => v.installed);
12857
+ const withVersion = installedProviders.filter((v) => v.version);
12858
+ LOG.info("Init", `Provider versions: ${installedProviders.length} installed, ${withVersion.length} versioned`);
12859
+ for (const v of withVersion) {
12860
+ LOG.info("Init", ` ${v.type} (${v.category}): v${v.version}${v.warning ? " \u26A0 " + v.warning : ""}`);
12861
+ }
12862
+ const noVersion = installedProviders.filter((v) => !v.version);
12863
+ if (noVersion.length > 0) {
12864
+ LOG.warn("Init", ` ${noVersion.length} installed but version unknown: ${noVersion.map((v) => v.type).join(", ")}`);
12865
+ }
12866
+ }).catch(() => {
12867
+ });
12917
12868
  const instanceManager = new ProviderInstanceManager();
12918
12869
  const cdpManagers = /* @__PURE__ */ new Map();
12919
12870
  const instanceIdMap = /* @__PURE__ */ new Map();