@adhdev/daemon-core 0.8.4 → 0.8.6

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.mjs CHANGED
@@ -6833,6 +6833,37 @@ function resolveSafePath(requestedPath) {
6833
6833
  }
6834
6834
  return resolved;
6835
6835
  }
6836
+ function listDirectoryEntriesSafe(dirPath) {
6837
+ const entries = fs4.readdirSync(dirPath, { withFileTypes: true });
6838
+ const files = [];
6839
+ for (const entry of entries) {
6840
+ const entryPath = path6.join(dirPath, entry.name);
6841
+ try {
6842
+ if (entry.isDirectory()) {
6843
+ files.push({ name: entry.name, type: "directory" });
6844
+ continue;
6845
+ }
6846
+ if (entry.isFile()) {
6847
+ let size;
6848
+ try {
6849
+ size = fs4.statSync(entryPath).size;
6850
+ } catch {
6851
+ size = void 0;
6852
+ }
6853
+ files.push({ name: entry.name, type: "file", size });
6854
+ continue;
6855
+ }
6856
+ const stat = fs4.statSync(entryPath);
6857
+ files.push({
6858
+ name: entry.name,
6859
+ type: stat.isDirectory() ? "directory" : "file",
6860
+ size: stat.isFile() ? stat.size : void 0
6861
+ });
6862
+ } catch {
6863
+ }
6864
+ }
6865
+ return files;
6866
+ }
6836
6867
  async function handleFileRead(h, args) {
6837
6868
  try {
6838
6869
  const filePath = resolveSafePath(args?.path);
@@ -6855,19 +6886,20 @@ async function handleFileWrite(h, args) {
6855
6886
  async function handleFileList(h, args) {
6856
6887
  try {
6857
6888
  const dirPath = resolveSafePath(args?.path || ".");
6858
- const entries = fs4.readdirSync(dirPath, { withFileTypes: true });
6859
- const files = entries.map((e) => ({
6860
- name: e.name,
6861
- type: e.isDirectory() ? "directory" : "file",
6862
- size: e.isFile() ? fs4.statSync(path6.join(dirPath, e.name)).size : void 0
6863
- }));
6889
+ const files = listDirectoryEntriesSafe(dirPath);
6864
6890
  return { success: true, files, path: dirPath };
6865
6891
  } catch (e) {
6866
6892
  return { success: false, error: e.message };
6867
6893
  }
6868
6894
  }
6869
6895
  async function handleFileListBrowse(h, args) {
6870
- return handleFileList(h, args);
6896
+ try {
6897
+ const dirPath = resolveSafePath(args?.path || ".");
6898
+ const files = listDirectoryEntriesSafe(dirPath).filter((entry) => entry.type === "directory").sort((a, b) => a.name.localeCompare(b.name));
6899
+ return { success: true, files, path: dirPath };
6900
+ } catch (e) {
6901
+ return { success: false, error: e.message };
6902
+ }
6871
6903
  }
6872
6904
 
6873
6905
  // src/commands/stream-commands.ts
@@ -15787,6 +15819,8 @@ async function handleAutoImplement(ctx, type, req, res) {
15787
15819
  let approvalBuffer = "";
15788
15820
  let lastApprovalTime = 0;
15789
15821
  let completionSignalSeen = false;
15822
+ let autoStopTimer = null;
15823
+ let autoStopIssued = false;
15790
15824
  try {
15791
15825
  const { normalizeCliProviderForRuntime: normalizeCliProviderForRuntime2 } = await Promise.resolve().then(() => (init_provider_cli_adapter(), provider_cli_adapter_exports));
15792
15826
  const normalized = normalizeCliProviderForRuntime2(agentProvider);
@@ -15824,8 +15858,37 @@ async function handleAutoImplement(ctx, type, req, res) {
15824
15858
  lastApprovalTime = Date.now();
15825
15859
  }
15826
15860
  };
15861
+ const clearAutoStopTimer = () => {
15862
+ if (autoStopTimer) {
15863
+ clearTimeout(autoStopTimer);
15864
+ autoStopTimer = null;
15865
+ }
15866
+ };
15867
+ const scheduleAutoStopForVerification = () => {
15868
+ if (!verification || command !== "codex" || completionSignalSeen || autoStopIssued) return;
15869
+ const elapsed = Date.now() - spawnedAt;
15870
+ if (elapsed < 3e4) return;
15871
+ clearAutoStopTimer();
15872
+ autoStopTimer = setTimeout(() => {
15873
+ if (!ctx.autoImplProcess || completionSignalSeen || autoStopIssued) return;
15874
+ autoStopIssued = true;
15875
+ ctx.log(`Auto-implement output quiet for 30s after ${Math.round((Date.now() - spawnedAt) / 1e3)}s. Interrupting agent and switching to daemon verification.`);
15876
+ sendAutoImplSSE(ctx, {
15877
+ event: "output",
15878
+ data: {
15879
+ chunk: "\n[\u{1F916} ADHDev Pipeline] Agent output quiet. Interrupting and running daemon verification...\n",
15880
+ stream: "stdout"
15881
+ }
15882
+ });
15883
+ try {
15884
+ ctx.autoImplProcess.kill("SIGINT");
15885
+ } catch {
15886
+ }
15887
+ }, 3e4);
15888
+ };
15827
15889
  const finalizeCliAutoImpl = async (code) => {
15828
15890
  ctx.autoImplProcess = null;
15891
+ clearAutoStopTimer();
15829
15892
  let success = completionSignalSeen || code === 0;
15830
15893
  let message = success ? completionSignalSeen && code !== 0 ? "\u2705 Auto-implement complete (completion signal)" : "\u2705 Auto-implement complete" : `\u274C Agent exited (code: ${code})`;
15831
15894
  let verificationSummary = null;
@@ -15876,12 +15939,14 @@ async function handleAutoImplement(ctx, type, req, res) {
15876
15939
  if (isPty) {
15877
15940
  child.onData((data) => {
15878
15941
  stdout += data;
15942
+ clearAutoStopTimer();
15879
15943
  if (data.includes("\x1B[6n")) {
15880
15944
  child.write("\x1B[12;1R");
15881
15945
  ctx.log("Terminal CPR request (\\x1b[6n) intercepted in PTY, responding with dummy coordinates [12;1R]");
15882
15946
  }
15883
15947
  checkAutoApproval(data, (s) => child.write(s));
15884
15948
  sendAutoImplSSE(ctx, { event: "output", data: { chunk: data, stream: "stdout" } });
15949
+ scheduleAutoStopForVerification();
15885
15950
  });
15886
15951
  child.onExit(({ exitCode: code }) => {
15887
15952
  void finalizeCliAutoImpl(code);
@@ -15890,15 +15955,19 @@ async function handleAutoImplement(ctx, type, req, res) {
15890
15955
  child.stdout?.on("data", (d) => {
15891
15956
  const chunk = d.toString();
15892
15957
  stdout += chunk;
15958
+ clearAutoStopTimer();
15893
15959
  if (chunk.includes("\x1B[6n")) child.stdin?.write("\x1B[1;1R");
15894
15960
  checkAutoApproval(chunk, (s) => child.stdin?.write(s));
15895
15961
  sendAutoImplSSE(ctx, { event: "output", data: { chunk, stream: "stdout" } });
15962
+ scheduleAutoStopForVerification();
15896
15963
  });
15897
15964
  child.stderr?.on("data", (d) => {
15898
15965
  const chunk = d.toString();
15899
15966
  stderr += chunk;
15967
+ clearAutoStopTimer();
15900
15968
  checkAutoApproval(chunk, (s) => child.stdin?.write(s));
15901
15969
  sendAutoImplSSE(ctx, { event: "output", data: { chunk, stream: "stderr" } });
15970
+ scheduleAutoStopForVerification();
15902
15971
  });
15903
15972
  child.on("exit", (code) => {
15904
15973
  void finalizeCliAutoImpl(code);