@slock-ai/daemon 0.29.1-alpha.0 → 0.30.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 (2) hide show
  1. package/dist/index.js +0 -210
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6,7 +6,6 @@ import os2 from "os";
6
6
  import { createRequire } from "module";
7
7
  import { execSync as execSync2 } from "child_process";
8
8
  import { accessSync } from "fs";
9
- import { readFile as readFile2, readdir as readdir2, stat as stat2, mkdir as mkdir2, appendFile } from "fs/promises";
10
9
  import { fileURLToPath } from "url";
11
10
 
12
11
  // src/connection.ts
@@ -1330,9 +1329,6 @@ Note: While you are busy, you may receive [System notification: ...] messages ab
1330
1329
  getRunningAgentIds() {
1331
1330
  return [...this.agents.keys()];
1332
1331
  }
1333
- getDataDir() {
1334
- return this.dataDir;
1335
- }
1336
1332
  getAgentSessionId(agentId) {
1337
1333
  return this.agents.get(agentId)?.sessionId ?? null;
1338
1334
  }
@@ -1587,11 +1583,6 @@ Note: While you are busy, you may receive [System notification: ...] messages ab
1587
1583
  case "session_init":
1588
1584
  if (ap) ap.sessionId = event.sessionId;
1589
1585
  this.sendToServer({ type: "agent:session", agentId, sessionId: event.sessionId });
1590
- writeFile(
1591
- path3.join(this.dataDir, agentId, "session-meta.json"),
1592
- JSON.stringify({ sessionId: event.sessionId, updatedAt: (/* @__PURE__ */ new Date()).toISOString() })
1593
- ).catch(() => {
1594
- });
1595
1586
  break;
1596
1587
  case "thinking": {
1597
1588
  const text = event.text.length > MAX_TRAJECTORY_TEXT ? event.text.slice(0, MAX_TRAJECTORY_TEXT) + "\u2026" : event.text;
@@ -1628,11 +1619,6 @@ Note: While you are busy, you may receive [System notification: ...] messages ab
1628
1619
  }
1629
1620
  if (event.sessionId) {
1630
1621
  this.sendToServer({ type: "agent:session", agentId, sessionId: event.sessionId });
1631
- writeFile(
1632
- path3.join(this.dataDir, agentId, "session-meta.json"),
1633
- JSON.stringify({ sessionId: event.sessionId, updatedAt: (/* @__PURE__ */ new Date()).toISOString() })
1634
- ).catch(() => {
1635
- });
1636
1622
  }
1637
1623
  break;
1638
1624
  case "error": {
@@ -1767,47 +1753,6 @@ var RUNTIMES = [
1767
1753
  // src/index.ts
1768
1754
  var require2 = createRequire(import.meta.url);
1769
1755
  var DAEMON_VERSION = require2("../package.json").version;
1770
- var LOG_DIR = path4.join(os2.homedir(), ".slock", "logs");
1771
- var LOG_FILE = path4.join(LOG_DIR, "daemon.log");
1772
- var MAX_LOG_BYTES = 5 * 1024 * 1024;
1773
- async function initLogFile() {
1774
- try {
1775
- await mkdir2(LOG_DIR, { recursive: true });
1776
- try {
1777
- const s = await stat2(LOG_FILE);
1778
- if (s.size > MAX_LOG_BYTES) {
1779
- const content = await readFile2(LOG_FILE, "utf-8");
1780
- const trimmed = content.slice(Math.floor(content.length / 2));
1781
- await appendFile(LOG_FILE, "");
1782
- const { writeFile: writeFile2 } = await import("fs/promises");
1783
- await writeFile2(LOG_FILE, trimmed);
1784
- }
1785
- } catch {
1786
- }
1787
- } catch {
1788
- }
1789
- }
1790
- function logLine(level, ...args2) {
1791
- const line = `${(/* @__PURE__ */ new Date()).toISOString()} [${level}] ${args2.map(String).join(" ")}
1792
- `;
1793
- appendFile(LOG_FILE, line).catch(() => {
1794
- });
1795
- }
1796
- var _origLog = console.log.bind(console);
1797
- var _origErr = console.error.bind(console);
1798
- var _origWarn = console.warn.bind(console);
1799
- console.log = (...args2) => {
1800
- _origLog(...args2);
1801
- logLine("INFO", ...args2);
1802
- };
1803
- console.error = (...args2) => {
1804
- _origErr(...args2);
1805
- logLine("ERROR", ...args2);
1806
- };
1807
- console.warn = (...args2) => {
1808
- _origWarn(...args2);
1809
- logLine("WARN", ...args2);
1810
- };
1811
1756
  function formatChannelTarget(msg) {
1812
1757
  return msg.message.channel_type === "dm" ? `dm:@${msg.message.channel_name}` : `#${msg.message.channel_name}`;
1813
1758
  }
@@ -1829,8 +1774,6 @@ function summarizeIncomingMessage(msg) {
1829
1774
  return `(agent=${msg.agentId}, runtime=${msg.runtime || "auto"})`;
1830
1775
  case "machine:workspace:delete":
1831
1776
  return `(directory=${msg.directoryName})`;
1832
- case "machine:feedback:collect":
1833
- return `(reportId=${msg.reportId}, agents=${msg.agents.length})`;
1834
1777
  default:
1835
1778
  return "";
1836
1779
  }
@@ -1866,126 +1809,6 @@ try {
1866
1809
  chatBridgePath = path4.resolve(__dirname, "chat-bridge.ts");
1867
1810
  }
1868
1811
  var connection;
1869
- async function collectAndUploadAgent(opts) {
1870
- const { agentId, reportAgentId, uploadUrl, authToken, timeRangeHours, includeSessionFiles, includeDaemonLogs, includeWorkspaceSnapshot, dataDir } = opts;
1871
- const sinceMs = Date.now() - timeRangeHours * 60 * 60 * 1e3;
1872
- let bytesUploaded = 0;
1873
- let anyUploadFailed = false;
1874
- try {
1875
- const agentDir = path4.join(dataDir, agentId);
1876
- let sessionId = opts.sessionId;
1877
- try {
1878
- const meta = JSON.parse(await readFile2(path4.join(agentDir, "session-meta.json"), "utf-8"));
1879
- if (meta.sessionId) sessionId = meta.sessionId;
1880
- } catch {
1881
- }
1882
- const filesToUpload = [];
1883
- if (includeSessionFiles && sessionId) {
1884
- const claudeProjectsDir = path4.join(os2.homedir(), ".claude", "projects");
1885
- try {
1886
- const projectDirs = await readdir2(claudeProjectsDir, { withFileTypes: true });
1887
- for (const pd of projectDirs) {
1888
- if (!pd.isDirectory()) continue;
1889
- const pdPath = path4.join(claudeProjectsDir, pd.name);
1890
- const files = await readdir2(pdPath, { withFileTypes: true });
1891
- for (const f of files) {
1892
- if (!f.isFile() || !f.name.endsWith(".jsonl")) continue;
1893
- if (!f.name.startsWith(sessionId)) continue;
1894
- const filePath = path4.join(pdPath, f.name);
1895
- const raw = await readFile2(filePath, "utf-8");
1896
- const filteredLines = raw.split("\n").filter((line) => {
1897
- if (!line.trim()) return false;
1898
- try {
1899
- const obj = JSON.parse(line);
1900
- if (!obj.timestamp) return true;
1901
- return new Date(obj.timestamp).getTime() >= sinceMs;
1902
- } catch {
1903
- return false;
1904
- }
1905
- }).join("\n");
1906
- if (!filteredLines.trim()) continue;
1907
- filesToUpload.push({ filename: f.name, data: Buffer.from(filteredLines), kind: "session_jsonl" });
1908
- }
1909
- }
1910
- } catch {
1911
- }
1912
- }
1913
- if (includeDaemonLogs) {
1914
- try {
1915
- const raw = await readFile2(LOG_FILE, "utf-8");
1916
- const filtered = raw.split("\n").filter((line) => {
1917
- if (!line.trim()) return false;
1918
- const ts = line.slice(0, 24);
1919
- return new Date(ts).getTime() >= sinceMs;
1920
- }).join("\n");
1921
- if (filtered.trim()) {
1922
- filesToUpload.push({ filename: "daemon.log", data: Buffer.from(filtered), kind: "daemon_log" });
1923
- }
1924
- } catch {
1925
- }
1926
- }
1927
- if (includeWorkspaceSnapshot) {
1928
- try {
1929
- const agentStat = await stat2(agentDir);
1930
- if (agentStat.isDirectory()) {
1931
- const files = await readdir2(agentDir, { withFileTypes: true });
1932
- for (const f of files) {
1933
- if (!f.isFile()) continue;
1934
- if (f.name === "session-meta.json") continue;
1935
- const filePath = path4.join(agentDir, f.name);
1936
- const s = await stat2(filePath);
1937
- if (s.size > 1024 * 1024) continue;
1938
- const data = await readFile2(filePath);
1939
- filesToUpload.push({ filename: f.name, data, kind: "runtime_log" });
1940
- }
1941
- }
1942
- } catch {
1943
- }
1944
- }
1945
- const manifest = {
1946
- reportAgentId,
1947
- agentId,
1948
- sessionId,
1949
- runtime: opts.runtime,
1950
- daemonVersion: DAEMON_VERSION,
1951
- hostname: os2.hostname(),
1952
- os: `${os2.platform()} ${os2.arch()}`,
1953
- collectedAt: (/* @__PURE__ */ new Date()).toISOString(),
1954
- timeRangeHours,
1955
- includeSessionFiles,
1956
- includeDaemonLogs,
1957
- includeWorkspaceSnapshot,
1958
- artifactCount: filesToUpload.length
1959
- };
1960
- filesToUpload.unshift({ filename: "manifest.json", data: Buffer.from(JSON.stringify(manifest, null, 2)), kind: "manifest" });
1961
- for (const file of filesToUpload) {
1962
- const formData = new FormData();
1963
- formData.append("reportAgentId", reportAgentId);
1964
- formData.append("kind", file.kind);
1965
- formData.append("filename", file.filename);
1966
- formData.append("file", new Blob([new Uint8Array(file.data)]), file.filename);
1967
- const resp = await fetch(uploadUrl, {
1968
- method: "POST",
1969
- headers: { Authorization: `Bearer ${authToken}` },
1970
- body: formData
1971
- });
1972
- if (resp.ok) {
1973
- bytesUploaded += file.data.length;
1974
- } else {
1975
- console.warn(`[Feedback] Upload failed for ${file.filename}: ${resp.status}`);
1976
- anyUploadFailed = true;
1977
- }
1978
- }
1979
- if (anyUploadFailed) {
1980
- return { reportAgentId, status: "error", daemonVersion: DAEMON_VERSION, error: "One or more files failed to upload", bytesUploaded };
1981
- }
1982
- return { reportAgentId, status: "collected", daemonVersion: DAEMON_VERSION, bytesUploaded };
1983
- } catch (err) {
1984
- const error = err instanceof Error ? err.message : String(err);
1985
- console.error(`[Feedback] Collection failed for agent ${agentId}:`, error);
1986
- return { reportAgentId, status: "error", daemonVersion: DAEMON_VERSION, error };
1987
- }
1988
- }
1989
1812
  var agentManager = new AgentProcessManager(chatBridgePath, (msg) => {
1990
1813
  connection.send(msg);
1991
1814
  }, apiKey);
@@ -2065,37 +1888,6 @@ connection = new DaemonConnection({
2065
1888
  case "ping":
2066
1889
  connection.send({ type: "pong" });
2067
1890
  break;
2068
- case "machine:feedback:collect": {
2069
- const { reportId, agents, timeRangeHours, includeSessionFiles, includeDaemonLogs, includeWorkspaceSnapshot, uploadUrl, authToken } = msg;
2070
- console.log(`[Daemon] Collecting feedback for report ${reportId} (${agents.length} agents)`);
2071
- const dataDir = agentManager.getDataDir();
2072
- Promise.all(agents.map(
2073
- (agent) => collectAndUploadAgent({
2074
- agentId: agent.agentId,
2075
- reportAgentId: agent.reportAgentId,
2076
- runtime: agent.runtime,
2077
- sessionId: agent.sessionId,
2078
- uploadUrl,
2079
- authToken,
2080
- timeRangeHours,
2081
- includeSessionFiles,
2082
- includeDaemonLogs,
2083
- includeWorkspaceSnapshot: includeWorkspaceSnapshot ?? false,
2084
- dataDir
2085
- })
2086
- )).then((agentResults) => {
2087
- connection.send({ type: "machine:feedback:result", reportId, agentResults });
2088
- }).catch((err) => {
2089
- console.error(`[Daemon] Feedback collection failed for report ${reportId}:`, err);
2090
- const agentResults = agents.map((a) => ({
2091
- reportAgentId: a.reportAgentId,
2092
- status: "error",
2093
- error: err instanceof Error ? err.message : String(err)
2094
- }));
2095
- connection.send({ type: "machine:feedback:result", reportId, agentResults });
2096
- });
2097
- break;
2098
- }
2099
1891
  }
2100
1892
  },
2101
1893
  onConnect: () => {
@@ -2124,8 +1916,6 @@ connection = new DaemonConnection({
2124
1916
  console.log("[Daemon] Lost connection \u2014 agents continue running locally");
2125
1917
  }
2126
1918
  });
2127
- initLogFile().catch(() => {
2128
- });
2129
1919
  console.log("[Slock Daemon] Starting...");
2130
1920
  connection.connect();
2131
1921
  var shutdown = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slock-ai/daemon",
3
- "version": "0.29.1-alpha.0",
3
+ "version": "0.30.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "slock-daemon": "dist/index.js"