typeclaw 0.46.1 → 0.46.2

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.
@@ -43,11 +43,9 @@ export type ExportClaudeCredentialsFileOptions = {
43
43
 
44
44
  // Writes typeclaw's anthropic OAuth credential to
45
45
  // $CLAUDE_CONFIG_DIR/.credentials.json (or $HOME/.claude/.credentials.json
46
- // by default) when it's safe to do so. The Dockerfile entrypoint shim
47
- // symlinks the same resolved credentials path to
48
- // /agent/.typeclaw/home/.claude/.credentials.json on every boot, so the
49
- // write follows the symlink and lands on the persistent host-side path —
50
- // same contract as exportCodexAuthFile.
46
+ // by default) when it's safe to do so. Container HOME is /home/agent and
47
+ // ephemeral; this boot-time export reconstructs the CLI file from secrets.json
48
+ // after provider OAuth refresh has updated the canonical credential.
51
49
  //
52
50
  // Three guards, cheapest first. The first two return without ever touching
53
51
  // the filesystem, which keeps the 90% case (users who don't enable
@@ -192,16 +190,11 @@ function resolveClaudeConfigDir(configDir: string | undefined): string | null {
192
190
  // rename is belt-and-suspenders: writeFileSync's `mode` is applied at
193
191
  // create time, but umask can mask it down on some filesystems.
194
192
  //
195
- // Symlink preservation: the entrypoint shim will install
196
- // $HOME/.claude/.credentials.json as a symlink to
197
- // /agent/.typeclaw/home/.claude/.credentials.json. POSIX rename(2)
198
- // replaces the directory entry at the destination atomically and does
199
- // NOT follow symlinks, so a naive renameSync against the symlink path
200
- // would replace the symlink with a regular file, leaving the persistent
201
- // path empty and Claude Code's in-place token refresh silently lost on
202
- // every restart. Resolve the symlink target with readlinkSync and rename
203
- // against the real path so the symlink itself is preserved. The temp
204
- // file MUST live alongside the real target (same filesystem) because
193
+ // Symlink preservation remains a safety property even though TypeClaw no longer
194
+ // plants one here. An operator or external tool may preconfigure the credentials
195
+ // path as a symlink; POSIX rename(2) replaces that directory entry instead of
196
+ // following it. Resolve the target and rename there so the caller's symlink
197
+ // survives. The temp file MUST live alongside the real target because
205
198
  // renameSync across filesystems fails with EXDEV.
206
199
  function writeAtomic(targetPath: string, contents: string): void {
207
200
  const realTarget = resolveSymlinkTarget(targetPath)
@@ -227,13 +220,11 @@ function writeAtomic(targetPath: string, contents: string): void {
227
220
  }
228
221
  }
229
222
 
230
- // Returns the absolute path renameSync should target. When `path` is a
231
- // symlink (production: $HOME/.claude/.credentials.json -> /agent/...),
232
- // returns the resolved absolute target so we write through the link
233
- // instead of replacing it. Otherwise (tests, or first boot before the
234
- // shim installs the symlink), returns the path unchanged. readlinkSync
235
- // throws EINVAL when the path exists but isn't a symlink and ENOENT
236
- // when nothing is there — both cases fall through to the original path.
223
+ // Returns the absolute path renameSync should target. When `path` is a symlink,
224
+ // returns the resolved absolute target so we write through the link instead of
225
+ // replacing it. Otherwise returns the path unchanged. readlinkSync throws EINVAL
226
+ // when the path exists but isn't a symlink and ENOENT when nothing is there —
227
+ // both cases fall through to the original path.
237
228
  function resolveSymlinkTarget(path: string): string {
238
229
  let link: string
239
230
  try {
@@ -38,12 +38,9 @@ export type ExportCodexAuthFileOptions = {
38
38
  }
39
39
 
40
40
  // Writes typeclaw's openai-codex OAuth credential to $HOME/.codex/auth.json
41
- // when it's safe to do so. The Dockerfile entrypoint shim symlinks
42
- // $HOME/.codex/auth.json to /agent/.typeclaw/home/.codex/auth.json on every
43
- // boot, so the write follows the symlink and lands on the persistent
44
- // host-side path — that's the stable contract from src/init/dockerfile.ts
45
- // "link_persistent_home_files" and we MUST use it instead of writing to
46
- // /agent/.typeclaw/home/ directly.
41
+ // when it's safe to do so. Container HOME is /home/agent and ephemeral; this
42
+ // boot-time export reconstructs the CLI file from secrets.json after provider
43
+ // OAuth refresh has had a chance to update the canonical credential.
47
44
  //
48
45
  // Three guards, cheapest first. The first two return without ever touching
49
46
  // the filesystem, which keeps the 90% case (users who don't enable Codex
@@ -170,22 +167,12 @@ function readCredentialExpiry(credential: { expires?: unknown; access?: unknown
170
167
  // belt-and-suspenders: writeFileSync's `mode` is applied at create time,
171
168
  // but umask can mask it down on some filesystems.
172
169
  //
173
- // Symlink preservation: the entrypoint shim
174
- // (src/init/dockerfile.ts link_persistent_home_files) installs
175
- // $HOME/.codex/auth.json as a symlink to
176
- // /agent/.typeclaw/home/.codex/auth.json on every boot. POSIX rename(2)
177
- // replaces the directory entry at the destination atomically — it does
178
- // NOT follow symlinks — so a naive `renameSync(tmp, $HOME/.codex/auth.json)`
179
- // would replace the symlink with a regular file, leaving the persistent
180
- // path empty. Next boot the shim recreates the symlink (force-removing
181
- // our file), the persistent path is still empty, and Codex's in-place
182
- // token refresh is silently lost on every restart.
183
- //
184
- // Fix: resolve the symlink target with readlinkSync and rename against
185
- // the real path so the symlink itself is preserved. The temp file MUST
186
- // live alongside the real target (same filesystem) because renameSync
187
- // across filesystems fails with EXDEV — $HOME is the container's
188
- // overlayfs, but the symlink target is a bind-mounted host path.
170
+ // Symlink preservation is still a safety property even though TypeClaw no
171
+ // longer plants one here. An operator or external tool may preconfigure
172
+ // $HOME/.codex/auth.json as a symlink; POSIX rename(2) replaces that directory
173
+ // entry instead of following it. Resolve the target and rename there so the
174
+ // caller's symlink survives. The temp file MUST live alongside the real target
175
+ // because renameSync across filesystems fails with EXDEV.
189
176
  function writeAtomic(targetPath: string, contents: string): void {
190
177
  const realTarget = resolveSymlinkTarget(targetPath)
191
178
  const dir = dirname(realTarget)
@@ -213,12 +200,9 @@ function writeAtomic(targetPath: string, contents: string): void {
213
200
  }
214
201
  }
215
202
 
216
- // Returns the absolute path renameSync should target. When `path` is a
217
- // symlink (production: $HOME/.codex/auth.json -> /agent/.typeclaw/home/...),
218
- // returns the resolved absolute target so we write through the link
219
- // instead of replacing it. Otherwise (tests, or first boot before the
220
- // shim installs the symlink — though the shim runs before the agent in
221
- // production), returns the path unchanged.
203
+ // Returns the absolute path renameSync should target. When `path` is a symlink,
204
+ // returns the resolved absolute target so we write through the link instead of
205
+ // replacing it. Otherwise returns the path unchanged.
222
206
  //
223
207
  // readlinkSync throws EINVAL when the path exists but isn't a symlink,
224
208
  // and ENOENT when nothing is there. Either case → write to the original