@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.js CHANGED
@@ -6915,6 +6915,37 @@ function resolveSafePath(requestedPath) {
6915
6915
  }
6916
6916
  return resolved;
6917
6917
  }
6918
+ function listDirectoryEntriesSafe(dirPath) {
6919
+ const entries = fs4.readdirSync(dirPath, { withFileTypes: true });
6920
+ const files = [];
6921
+ for (const entry of entries) {
6922
+ const entryPath = path6.join(dirPath, entry.name);
6923
+ try {
6924
+ if (entry.isDirectory()) {
6925
+ files.push({ name: entry.name, type: "directory" });
6926
+ continue;
6927
+ }
6928
+ if (entry.isFile()) {
6929
+ let size;
6930
+ try {
6931
+ size = fs4.statSync(entryPath).size;
6932
+ } catch {
6933
+ size = void 0;
6934
+ }
6935
+ files.push({ name: entry.name, type: "file", size });
6936
+ continue;
6937
+ }
6938
+ const stat = fs4.statSync(entryPath);
6939
+ files.push({
6940
+ name: entry.name,
6941
+ type: stat.isDirectory() ? "directory" : "file",
6942
+ size: stat.isFile() ? stat.size : void 0
6943
+ });
6944
+ } catch {
6945
+ }
6946
+ }
6947
+ return files;
6948
+ }
6918
6949
  async function handleFileRead(h, args) {
6919
6950
  try {
6920
6951
  const filePath = resolveSafePath(args?.path);
@@ -6937,19 +6968,20 @@ async function handleFileWrite(h, args) {
6937
6968
  async function handleFileList(h, args) {
6938
6969
  try {
6939
6970
  const dirPath = resolveSafePath(args?.path || ".");
6940
- const entries = fs4.readdirSync(dirPath, { withFileTypes: true });
6941
- const files = entries.map((e) => ({
6942
- name: e.name,
6943
- type: e.isDirectory() ? "directory" : "file",
6944
- size: e.isFile() ? fs4.statSync(path6.join(dirPath, e.name)).size : void 0
6945
- }));
6971
+ const files = listDirectoryEntriesSafe(dirPath);
6946
6972
  return { success: true, files, path: dirPath };
6947
6973
  } catch (e) {
6948
6974
  return { success: false, error: e.message };
6949
6975
  }
6950
6976
  }
6951
6977
  async function handleFileListBrowse(h, args) {
6952
- return handleFileList(h, args);
6978
+ try {
6979
+ const dirPath = resolveSafePath(args?.path || ".");
6980
+ const files = listDirectoryEntriesSafe(dirPath).filter((entry) => entry.type === "directory").sort((a, b) => a.name.localeCompare(b.name));
6981
+ return { success: true, files, path: dirPath };
6982
+ } catch (e) {
6983
+ return { success: false, error: e.message };
6984
+ }
6953
6985
  }
6954
6986
 
6955
6987
  // src/commands/stream-commands.ts
@@ -15864,6 +15896,8 @@ async function handleAutoImplement(ctx, type, req, res) {
15864
15896
  let approvalBuffer = "";
15865
15897
  let lastApprovalTime = 0;
15866
15898
  let completionSignalSeen = false;
15899
+ let autoStopTimer = null;
15900
+ let autoStopIssued = false;
15867
15901
  try {
15868
15902
  const { normalizeCliProviderForRuntime: normalizeCliProviderForRuntime2 } = await Promise.resolve().then(() => (init_provider_cli_adapter(), provider_cli_adapter_exports));
15869
15903
  const normalized = normalizeCliProviderForRuntime2(agentProvider);
@@ -15901,8 +15935,37 @@ async function handleAutoImplement(ctx, type, req, res) {
15901
15935
  lastApprovalTime = Date.now();
15902
15936
  }
15903
15937
  };
15938
+ const clearAutoStopTimer = () => {
15939
+ if (autoStopTimer) {
15940
+ clearTimeout(autoStopTimer);
15941
+ autoStopTimer = null;
15942
+ }
15943
+ };
15944
+ const scheduleAutoStopForVerification = () => {
15945
+ if (!verification || command !== "codex" || completionSignalSeen || autoStopIssued) return;
15946
+ const elapsed = Date.now() - spawnedAt;
15947
+ if (elapsed < 3e4) return;
15948
+ clearAutoStopTimer();
15949
+ autoStopTimer = setTimeout(() => {
15950
+ if (!ctx.autoImplProcess || completionSignalSeen || autoStopIssued) return;
15951
+ autoStopIssued = true;
15952
+ ctx.log(`Auto-implement output quiet for 30s after ${Math.round((Date.now() - spawnedAt) / 1e3)}s. Interrupting agent and switching to daemon verification.`);
15953
+ sendAutoImplSSE(ctx, {
15954
+ event: "output",
15955
+ data: {
15956
+ chunk: "\n[\u{1F916} ADHDev Pipeline] Agent output quiet. Interrupting and running daemon verification...\n",
15957
+ stream: "stdout"
15958
+ }
15959
+ });
15960
+ try {
15961
+ ctx.autoImplProcess.kill("SIGINT");
15962
+ } catch {
15963
+ }
15964
+ }, 3e4);
15965
+ };
15904
15966
  const finalizeCliAutoImpl = async (code) => {
15905
15967
  ctx.autoImplProcess = null;
15968
+ clearAutoStopTimer();
15906
15969
  let success = completionSignalSeen || code === 0;
15907
15970
  let message = success ? completionSignalSeen && code !== 0 ? "\u2705 Auto-implement complete (completion signal)" : "\u2705 Auto-implement complete" : `\u274C Agent exited (code: ${code})`;
15908
15971
  let verificationSummary = null;
@@ -15953,12 +16016,14 @@ async function handleAutoImplement(ctx, type, req, res) {
15953
16016
  if (isPty) {
15954
16017
  child.onData((data) => {
15955
16018
  stdout += data;
16019
+ clearAutoStopTimer();
15956
16020
  if (data.includes("\x1B[6n")) {
15957
16021
  child.write("\x1B[12;1R");
15958
16022
  ctx.log("Terminal CPR request (\\x1b[6n) intercepted in PTY, responding with dummy coordinates [12;1R]");
15959
16023
  }
15960
16024
  checkAutoApproval(data, (s) => child.write(s));
15961
16025
  sendAutoImplSSE(ctx, { event: "output", data: { chunk: data, stream: "stdout" } });
16026
+ scheduleAutoStopForVerification();
15962
16027
  });
15963
16028
  child.onExit(({ exitCode: code }) => {
15964
16029
  void finalizeCliAutoImpl(code);
@@ -15967,15 +16032,19 @@ async function handleAutoImplement(ctx, type, req, res) {
15967
16032
  child.stdout?.on("data", (d) => {
15968
16033
  const chunk = d.toString();
15969
16034
  stdout += chunk;
16035
+ clearAutoStopTimer();
15970
16036
  if (chunk.includes("\x1B[6n")) child.stdin?.write("\x1B[1;1R");
15971
16037
  checkAutoApproval(chunk, (s) => child.stdin?.write(s));
15972
16038
  sendAutoImplSSE(ctx, { event: "output", data: { chunk, stream: "stdout" } });
16039
+ scheduleAutoStopForVerification();
15973
16040
  });
15974
16041
  child.stderr?.on("data", (d) => {
15975
16042
  const chunk = d.toString();
15976
16043
  stderr += chunk;
16044
+ clearAutoStopTimer();
15977
16045
  checkAutoApproval(chunk, (s) => child.stdin?.write(s));
15978
16046
  sendAutoImplSSE(ctx, { event: "output", data: { chunk, stream: "stderr" } });
16047
+ scheduleAutoStopForVerification();
15979
16048
  });
15980
16049
  child.on("exit", (code) => {
15981
16050
  void finalizeCliAutoImpl(code);