@versot/vaguspi 0.1.4 → 0.1.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/bin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // apps/cli/src/bin.ts
4
- import { readFileSync as readFileSync7 } from "node:fs";
4
+ import { existsSync as existsSync9, readFileSync as readFileSync7 } from "node:fs";
5
5
  import { parseArgs } from "node:util";
6
6
 
7
7
  // apps/cli/src/commands/daemon.ts
@@ -870,7 +870,7 @@ var ExtensionUiBridge = class {
870
870
  };
871
871
 
872
872
  // packages/host/engine/dist/vagus-engine.js
873
- var VagusEngine = class {
873
+ var VagusEngine = class _VagusEngine {
874
874
  options;
875
875
  sessions = /* @__PURE__ */ new Map();
876
876
  /**
@@ -1064,8 +1064,29 @@ var VagusEngine = class {
1064
1064
  if (entry.type !== "message" || !entry.message)
1065
1065
  continue;
1066
1066
  const role = String(entry.message.role);
1067
- if (role === "toolResult")
1067
+ if (role === "toolResult") {
1068
+ const m = entry.message;
1069
+ if (typeof m.toolCallId === "string") {
1070
+ const tid = m.toolCallId;
1071
+ const res = resultsById.get(tid);
1072
+ views.push({
1073
+ role: "tool",
1074
+ text: "",
1075
+ toolCalls: [{
1076
+ id: tid,
1077
+ name: typeof m.toolName === "string" ? m.toolName : "tool",
1078
+ args: "",
1079
+ ...res ? {
1080
+ result: truncateDisplay(res.result, 2e4),
1081
+ isError: res.isError,
1082
+ ...res.diff !== void 0 ? { diff: res.diff } : {},
1083
+ ...res.patch !== void 0 ? { patch: res.patch } : {}
1084
+ } : {}
1085
+ }]
1086
+ });
1087
+ }
1068
1088
  continue;
1089
+ }
1069
1090
  const entryTs = new Date(entry.timestamp).getTime();
1070
1091
  if (role === "user")
1071
1092
  closeTurn();
@@ -1698,8 +1719,6 @@ var VagusEngine = class {
1698
1719
  closeSessionForCwd(cwd) {
1699
1720
  for (const [sid, session] of this.sessions) {
1700
1721
  if (session.sessionManager?.getCwd() === cwd) {
1701
- process.stderr.write(`vagus: disposing session ${sid} (cwd=${cwd})
1702
- `);
1703
1722
  try {
1704
1723
  session.dispose();
1705
1724
  } catch (err) {
@@ -1769,10 +1788,9 @@ var VagusEngine = class {
1769
1788
  return void 0;
1770
1789
  }
1771
1790
  }
1772
- /** Restores an archived project: moves its session files back under `sessions/`. */
1773
1791
  /** Restores an archived project by its encoded dir name (unique identity). */
1774
1792
  async unarchiveProjectByDir(dirKey) {
1775
- if (!dirKey || dirKey.includes("/") || dirKey.includes("\\") || dirKey.includes(".."))
1793
+ if (!_VagusEngine.isSafeDirKey(dirKey))
1776
1794
  return;
1777
1795
  const agentDir = this.agentDirPath();
1778
1796
  const src = join5(agentDir, "archived", dirKey);
@@ -1824,12 +1842,10 @@ var VagusEngine = class {
1824
1842
  /** Permanently deletes an archived project dir by its encoded dir name.
1825
1843
  * dirKey (not cwd) is the identity — cwds can repeat across archive dirs. */
1826
1844
  async deleteArchivedProjectByDir(dirKey) {
1827
- if (!dirKey || dirKey.includes("/") || dirKey.includes("\\") || dirKey.includes(".."))
1845
+ if (!_VagusEngine.isSafeDirKey(dirKey))
1828
1846
  return;
1829
1847
  const agentDir = this.agentDirPath();
1830
1848
  const dir = join5(agentDir, "archived", dirKey);
1831
- process.stderr.write(`vagus: deleteArchivedProjectByDir dirKey=${dirKey}
1832
- `);
1833
1849
  const prefix = dir + sep;
1834
1850
  for (const [sid, session] of this.sessions) {
1835
1851
  const file = session.sessionManager?.getSessionFile();
@@ -1843,24 +1859,18 @@ var VagusEngine = class {
1843
1859
  });
1844
1860
  }
1845
1861
  }
1846
- process.stderr.write(`vagus: sessions closed, removing dir...
1847
- `);
1848
1862
  this.rmDirSafe(dir);
1849
- process.stderr.write(`vagus: archived dir removed OK
1850
- `);
1851
1863
  }
1852
1864
  /** Permanently deletes an archived project's session dir (JSONL). */
1853
1865
  async deleteArchivedProject(cwd) {
1854
1866
  const agentDir = this.agentDirPath();
1855
1867
  const dir = join5(agentDir, "archived", this.encodeCwd(cwd));
1856
- process.stderr.write(`vagus: deleteArchivedProject cwd=${cwd} dir=${dir}
1857
- `);
1858
1868
  this.closeSessionForCwd(cwd);
1859
- process.stderr.write(`vagus: sessions closed, removing dir...
1860
- `);
1861
1869
  this.rmDirSafe(dir);
1862
- process.stderr.write(`vagus: archived dir removed OK
1863
- `);
1870
+ }
1871
+ /** Safe archive-dir name: a plain single path segment, never traversal. */
1872
+ static isSafeDirKey(dirKey) {
1873
+ return dirKey.length > 0 && dirKey !== "." && dirKey !== ".." && !dirKey.includes("/") && !dirKey.includes("\\") && !dirKey.includes("..");
1864
1874
  }
1865
1875
  /**
1866
1876
  * rmSync(recursive) has crashed the daemon natively (0xC0000409 fastfail)
@@ -2026,17 +2036,20 @@ var VagusEngine = class {
2026
2036
  if (!existsSync3(sourceFile))
2027
2037
  throw new Error(`source session file not found: ${sourceFile}`);
2028
2038
  const raw = readFileSync4(sourceFile, "utf8");
2029
- const lines = raw.split("\n").filter((l) => l.trim().length > 0);
2030
- const entries = lines.map((l) => JSON.parse(l));
2039
+ const entries = raw.split("\n").filter((l) => l.trim().length > 0).flatMap((l) => {
2040
+ try {
2041
+ return [JSON.parse(l)];
2042
+ } catch {
2043
+ return [];
2044
+ }
2045
+ });
2031
2046
  const header = entries[0];
2032
2047
  if (!header || header.type !== "session")
2033
2048
  throw new Error("source session has no header");
2034
2049
  const targetIdx = entries.findIndex((e) => e.id === entryId);
2035
2050
  if (targetIdx < 0)
2036
2051
  throw new Error(`entry ${entryId} not found in source session`);
2037
- let endIdx = targetIdx - 1;
2038
- if (endIdx < 1)
2039
- endIdx = 1;
2052
+ const endIdx = targetIdx - 1;
2040
2053
  const cwd = session.sessionManager.getCwd() || this.options.cwd;
2041
2054
  const sessionDir = dirname3(sourceFile);
2042
2055
  mkdirSync4(sessionDir, { recursive: true });
@@ -7092,8 +7105,9 @@ function applyHttpProxy() {
7092
7105
  const normalized = /^https?:\/\//.test(proxy) ? proxy : `http://${proxy}`;
7093
7106
  process.env.HTTPS_PROXY = normalized;
7094
7107
  process.env.HTTP_PROXY = normalized;
7108
+ process.env.NO_PROXY ??= "localhost,127.0.0.1";
7095
7109
  setGlobalDispatcher(new EnvHttpProxyAgent());
7096
- process.stderr.write(`vagus: http proxy enabled \u2192 ${normalized}
7110
+ process.stderr.write(`vagus: http proxy enabled \u2192 ${normalized.replace(/\/\/([^@/]*)@/, "//***@")}
7097
7111
  `);
7098
7112
  }
7099
7113
  } catch (err) {
@@ -7674,10 +7688,10 @@ async function runDaemon() {
7674
7688
  });
7675
7689
  server = new JsonRpcServer({ send: (frame) => transport.send(frame) });
7676
7690
  registerMethods(server);
7677
- const wsPort = Number(process.env.VAGUS_WS_PORT ?? "19707");
7691
+ const requestedPort = Number(process.env.VAGUS_WS_PORT ?? "19707");
7678
7692
  const wsHost = new WsServerHost();
7679
- wsHost.listen({
7680
- port: wsPort,
7693
+ await wsHost.listen({
7694
+ port: requestedPort,
7681
7695
  registerMethods,
7682
7696
  staticDir: process.env.VAGUS_GUI_DIR
7683
7697
  });
@@ -7690,7 +7704,6 @@ async function runDaemon() {
7690
7704
  if (shuttingDown) return;
7691
7705
  shuttingDown = true;
7692
7706
  process.stderr.write(`vagus: daemon shutting down (${signal})
7693
- ${new Error("shutdown trace").stack}
7694
7707
  `);
7695
7708
  void (async () => {
7696
7709
  try {
@@ -7704,14 +7717,6 @@ ${new Error("shutdown trace").stack}
7704
7717
  };
7705
7718
  process.on("SIGINT", () => shutdown("SIGINT"));
7706
7719
  process.on("SIGTERM", () => shutdown("SIGTERM"));
7707
- process.on("beforeExit", (code) => {
7708
- process.stderr.write(`vagus: daemon beforeExit (event loop empty), code=${code}
7709
- `);
7710
- });
7711
- process.on("exit", (code) => {
7712
- process.stderr.write(`vagus: daemon exit, code=${code}
7713
- `);
7714
- });
7715
7720
  transport.start();
7716
7721
  process.stderr.write(`pi-web daemon ready (state: ${stateDir})
7717
7722
  `);
@@ -7734,8 +7739,7 @@ import { join as join9 } from "node:path";
7734
7739
  import { fileURLToPath as fileURLToPath3 } from "node:url";
7735
7740
 
7736
7741
  // apps/cli/src/daemon.ts
7737
- import { spawn } from "node:child_process";
7738
- import { execSync } from "node:child_process";
7742
+ import { execSync, spawn } from "node:child_process";
7739
7743
  import { existsSync as existsSync7 } from "node:fs";
7740
7744
  import { fileURLToPath as fileURLToPath2 } from "node:url";
7741
7745
  function detectSystemProxy() {
@@ -7772,6 +7776,9 @@ function daemonEntryPath() {
7772
7776
  const source = `${base}.ts`;
7773
7777
  return existsSync7(source) ? source : `${base}.js`;
7774
7778
  }
7779
+ function defaultWsPort() {
7780
+ return daemonEntryPath().endsWith(".ts") ? 19708 : 19707;
7781
+ }
7775
7782
  function spawnDaemon(options = {}) {
7776
7783
  const entry = daemonEntryPath();
7777
7784
  const args = entry.endsWith(".ts") ? ["--import", "tsx", entry, "daemon"] : [entry, "daemon"];
@@ -7783,7 +7790,8 @@ function spawnDaemon(options = {}) {
7783
7790
  injected.HTTPS_PROXY = sysProxy;
7784
7791
  injected.HTTP_PROXY = sysProxy;
7785
7792
  injected.NO_PROXY = process.env.NO_PROXY ?? "localhost,127.0.0.1";
7786
- process.stderr.write(`vagus: following system proxy \u2192 ${sysProxy}
7793
+ const redacted = sysProxy.replace(/\/\/([^@/]*)@/, "//***@");
7794
+ process.stderr.write(`vagus: following system proxy \u2192 ${redacted}
7787
7795
  `);
7788
7796
  } else {
7789
7797
  process.stderr.write(`vagus: no system proxy detected (direct connections)
@@ -7800,7 +7808,7 @@ function spawnDaemon(options = {}) {
7800
7808
  }
7801
7809
 
7802
7810
  // apps/cli/src/commands/web.ts
7803
- var DEFAULT_WS_PORT = 19707;
7811
+ var DEFAULT_WS_PORT = defaultWsPort();
7804
7812
  function guiDistPath() {
7805
7813
  const prod = fileURLToPath3(new URL("../gui", import.meta.url));
7806
7814
  if (existsSync8(join9(prod, "index.html"))) return prod;
@@ -7865,6 +7873,9 @@ async function runWeb() {
7865
7873
  }
7866
7874
 
7867
7875
  // apps/cli/src/bin.ts
7876
+ if (!process.env.VAGUS_WS_PORT && existsSync9(new URL("./commands/daemon.ts", import.meta.url))) {
7877
+ process.env.VAGUS_WS_PORT = "19708";
7878
+ }
7868
7879
  var VERSION = JSON.parse(
7869
7880
  readFileSync7(new URL("../package.json", import.meta.url), "utf8")
7870
7881
  ).version;