@zookanalytics/agent-env 0.9.0 → 0.9.1

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.
@@ -14,18 +14,29 @@ if [ ! -f "$GITCONFIG" ]; then
14
14
  touch "$GITCONFIG"
15
15
  fi
16
16
 
17
- # Stage only SSH public keys for container mount (never expose private keys)
17
+ # Stage only SSH public keys for container mount (never expose private keys).
18
+ # Non-fatal — SSH agent socket provides auth; pub keys are only for sshd authorized_keys.
18
19
  SSH_PUB_DIR="$HOME/.agent-env/ssh-pub-keys"
19
20
  mkdir -p "$SSH_PUB_DIR"
20
- rm -f "$SSH_PUB_DIR"/*.pub 2>/dev/null || true
21
21
  if ls "$HOME/.ssh/"*.pub &>/dev/null; then
22
- cp -p "$HOME/.ssh/"*.pub "$SSH_PUB_DIR/"
23
- echo "agent-env: Staged SSH public keys:"
24
- for f in "$SSH_PUB_DIR"/*.pub; do
25
- echo " - $(basename "$f")"
26
- done
22
+ # Atomic replace: copy to temp dir, then swap
23
+ STAGING_TMP="$SSH_PUB_DIR/.staging.$$"
24
+ mkdir -p "$STAGING_TMP"
25
+ if cp -p "$HOME/.ssh/"*.pub "$STAGING_TMP/" 2>/dev/null; then
26
+ rm -f "$SSH_PUB_DIR"/*.pub 2>/dev/null || true
27
+ mv "$STAGING_TMP"/*.pub "$SSH_PUB_DIR/" 2>/dev/null || true
28
+ echo "agent-env: Staged SSH public keys:"
29
+ for f in "$SSH_PUB_DIR"/*.pub; do
30
+ [ -f "$f" ] && echo " - $(basename "$f")"
31
+ done
32
+ else
33
+ rm -f "$SSH_PUB_DIR"/*.pub 2>/dev/null || true
34
+ echo "agent-env: Warning: Failed to stage SSH public keys — cleared stale keys (non-fatal)"
35
+ fi
36
+ rm -rf "$STAGING_TMP" 2>/dev/null || true
27
37
  else
28
- echo "agent-env: Warning: No SSH public keys found in ~/.ssh. SSH access will require manual setup."
38
+ rm -f "$SSH_PUB_DIR"/*.pub 2>/dev/null || true
39
+ echo "agent-env: Warning: No SSH public keys found in ~/.ssh — cleared stale keys. SSH access will require manual setup."
29
40
  fi
30
41
 
31
42
  # Stage PulseAudio cookie for audio passthrough (if setup-audio was run)
package/dist/cli.js CHANGED
@@ -56,7 +56,7 @@ import React3 from "react";
56
56
  // package.json
57
57
  var package_default = {
58
58
  name: "@zookanalytics/agent-env",
59
- version: "0.9.0",
59
+ version: "0.9.1",
60
60
  description: "CLI for creating isolated, AI-ready development environments",
61
61
  type: "module",
62
62
  bin: {
@@ -438,7 +438,7 @@ import { dirname as dirname2, join as join6 } from "path";
438
438
  // src/lib/devcontainer-merge.ts
439
439
  import { parse as parseJsonc2 } from "jsonc-parser";
440
440
  import { constants } from "fs";
441
- import { access as access2, readFile as readFile2, rename, writeFile as writeFile2 } from "fs/promises";
441
+ import { access as access2, lstat, readFile as readFile2, readlink, rename, writeFile as writeFile2 } from "fs/promises";
442
442
  import { createRequire } from "module";
443
443
  import { join as join2 } from "path";
444
444
 
@@ -614,7 +614,14 @@ function parseDockerfileImages(content, logger) {
614
614
  }
615
615
 
616
616
  // src/lib/devcontainer-merge.ts
617
- var defaultMergeDeps = { readFile: readFile2, writeFile: writeFile2, rename, access: access2 };
617
+ var defaultMergeDeps = {
618
+ readFile: readFile2,
619
+ writeFile: writeFile2,
620
+ rename,
621
+ access: access2,
622
+ lstat,
623
+ readlink
624
+ };
618
625
  var STATUS_BAR_JSON_FILENAME = "statusBar.json";
619
626
  var LABEL_LIFECYCLE_CMDS = {
620
627
  postCreateCommand: "/usr/local/bin/post-create.sh",
@@ -635,6 +642,21 @@ async function readRepoConfig(workspacePath, deps = defaultMergeDeps, logger) {
635
642
  join2(workspacePath, ".devcontainer.json")
636
643
  ];
637
644
  for (const candidate of candidates) {
645
+ if (deps.lstat && deps.readlink) {
646
+ try {
647
+ const linkStat = await deps.lstat(candidate);
648
+ if (linkStat.isSymbolicLink()) {
649
+ const target = await deps.readlink(candidate);
650
+ if (target.includes(AGENT_ENV_DIR)) {
651
+ logger?.warn(
652
+ `Skipping symlink to agent-env config at ${candidate} \u2014 not a repo config`
653
+ );
654
+ continue;
655
+ }
656
+ }
657
+ } catch {
658
+ }
659
+ }
638
660
  let content;
639
661
  try {
640
662
  await deps.access(candidate, constants.F_OK);
@@ -1941,11 +1963,11 @@ import { Command as Command2 } from "commander";
1941
1963
  // src/lib/code-instance.ts
1942
1964
  import {
1943
1965
  appendFile as appendFile5,
1944
- lstat,
1966
+ lstat as lstat2,
1945
1967
  mkdir as mkdir7,
1946
1968
  readdir as readdir6,
1947
1969
  readFile as readFile9,
1948
- readlink,
1970
+ readlink as readlink2,
1949
1971
  rename as rename6,
1950
1972
  stat as stat6,
1951
1973
  symlink,
@@ -1953,7 +1975,7 @@ import {
1953
1975
  writeFile as writeFile8
1954
1976
  } from "fs/promises";
1955
1977
  import { homedir as homedir5 } from "os";
1956
- import { join as join8, relative } from "path";
1978
+ import { join as join8 } from "path";
1957
1979
  function createCodeDefaultDeps() {
1958
1980
  const executor = createExecutor();
1959
1981
  return {
@@ -1961,14 +1983,13 @@ function createCodeDefaultDeps() {
1961
1983
  container: createContainerLifecycle(executor),
1962
1984
  workspaceFsDeps: { mkdir: mkdir7, readdir: readdir6, stat: stat6, homedir: homedir5 },
1963
1985
  stateFsDeps: { readFile: readFile9, writeFile: writeFile8, rename: rename6, mkdir: mkdir7, appendFile: appendFile5 },
1964
- codeFsDeps: { mkdir: mkdir7, lstat, symlink, readlink, unlink }
1986
+ codeFsDeps: { lstat: lstat2, symlink, readlink: readlink2, unlink }
1965
1987
  };
1966
1988
  }
1967
1989
  var DEVCONTAINER_OPEN_TIMEOUT = 3e4;
1968
- async function ensureDevcontainerSymlink(wsRoot, deps) {
1969
- const devcontainerDir = join8(wsRoot, ".devcontainer");
1970
- const symlinkPath = join8(devcontainerDir, "devcontainer.json");
1971
- const target = relative(devcontainerDir, join8(wsRoot, AGENT_ENV_DIR, "devcontainer.json"));
1990
+ async function ensureConfigSymlink(wsRoot, deps) {
1991
+ const symlinkPath = join8(wsRoot, ".devcontainer.json");
1992
+ const target = join8(AGENT_ENV_DIR, "devcontainer.json");
1972
1993
  try {
1973
1994
  const linkStat = await deps.lstat(symlinkPath);
1974
1995
  if (linkStat.isSymbolicLink()) {
@@ -1981,9 +2002,17 @@ async function ensureDevcontainerSymlink(wsRoot, deps) {
1981
2002
  } catch (err) {
1982
2003
  if (err.code !== "ENOENT") throw err;
1983
2004
  }
1984
- await deps.mkdir(devcontainerDir, { recursive: true });
1985
2005
  await deps.symlink(target, symlinkPath);
1986
2006
  }
2007
+ async function removeConfigSymlink(wsRoot, deps) {
2008
+ const symlinkPath = join8(wsRoot, ".devcontainer.json");
2009
+ try {
2010
+ const linkStat = await deps.lstat(symlinkPath);
2011
+ if (!linkStat.isSymbolicLink()) return;
2012
+ await deps.unlink(symlinkPath);
2013
+ } catch {
2014
+ }
2015
+ }
1987
2016
  async function codeInstance(instanceName, deps, onContainerStarting, onOpening, repoSlug) {
1988
2017
  const lookup = await resolveInstance(instanceName, repoSlug, {
1989
2018
  fsDeps: deps.workspaceFsDeps,
@@ -2034,9 +2063,10 @@ async function codeInstance(instanceName, deps, onContainerStarting, onOpening,
2034
2063
  };
2035
2064
  }
2036
2065
  }
2037
- if (!state.repoConfigDetected) {
2066
+ const needsSymlink = !state.repoConfigDetected;
2067
+ if (needsSymlink) {
2038
2068
  try {
2039
- await ensureDevcontainerSymlink(wsPath.root, deps.codeFsDeps);
2069
+ await ensureConfigSymlink(wsPath.root, deps.codeFsDeps);
2040
2070
  } catch (err) {
2041
2071
  const detail = err instanceof Error ? err.message : String(err);
2042
2072
  return {
@@ -2049,12 +2079,19 @@ async function codeInstance(instanceName, deps, onContainerStarting, onOpening,
2049
2079
  };
2050
2080
  }
2051
2081
  }
2052
- onOpening?.();
2053
- const openResult = await deps.executor(
2054
- "devcontainer",
2055
- ["open", wsPath.root, "--config", configPath],
2056
- { stdio: "inherit", timeout: DEVCONTAINER_OPEN_TIMEOUT }
2057
- );
2082
+ let openResult;
2083
+ try {
2084
+ onOpening?.();
2085
+ openResult = await deps.executor(
2086
+ "devcontainer",
2087
+ ["open", wsPath.root, "--config", configPath],
2088
+ { stdio: "inherit", timeout: DEVCONTAINER_OPEN_TIMEOUT }
2089
+ );
2090
+ } finally {
2091
+ if (needsSymlink) {
2092
+ await removeConfigSymlink(wsPath.root, deps.codeFsDeps);
2093
+ }
2094
+ }
2058
2095
  if (!openResult.ok) {
2059
2096
  return {
2060
2097
  ok: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zookanalytics/agent-env",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "CLI for creating isolated, AI-ready development environments",
5
5
  "type": "module",
6
6
  "bin": {