@townco/agent 0.1.137 → 0.1.139

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.
@@ -1,6 +1,8 @@
1
- import { existsSync, mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync, } from "node:fs";
1
+ import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { z } from "zod";
4
+ import { createLogger } from "../logger.js";
5
+ const logger = createLogger("session-storage");
4
6
  /**
5
7
  * Zod schema for validating session files
6
8
  */
@@ -273,12 +275,8 @@ export class SessionStorage {
273
275
  try {
274
276
  // Write to temp file
275
277
  writeFileSync(tempPath, JSON.stringify(session, null, 2), "utf-8");
276
- // Atomic rename
277
- if (existsSync(sessionPath)) {
278
- unlinkSync(sessionPath);
279
- }
280
- writeFileSync(sessionPath, readFileSync(tempPath, "utf-8"), "utf-8");
281
- unlinkSync(tempPath);
278
+ // Atomic rename - renameSync is atomic on POSIX systems
279
+ renameSync(tempPath, sessionPath);
282
280
  }
283
281
  catch (error) {
284
282
  // Clean up temp file on error
@@ -424,8 +422,12 @@ export class SessionStorage {
424
422
  sessions.push(entry);
425
423
  }
426
424
  }
427
- catch {
428
- // Skip invalid sessions
425
+ catch (error) {
426
+ // Log and skip invalid sessions so they don't break the session list
427
+ logger.warn("Failed to load session, skipping from list", {
428
+ sessionId,
429
+ error: error instanceof Error ? error.message : String(error),
430
+ });
429
431
  }
430
432
  }
431
433
  // Sort by updatedAt, most recent first
@@ -506,11 +508,8 @@ export class SessionStorage {
506
508
  const tempPath = `${sessionPath}.tmp`;
507
509
  try {
508
510
  writeFileSync(tempPath, JSON.stringify(updatedSession, null, 2), "utf-8");
509
- if (existsSync(sessionPath)) {
510
- unlinkSync(sessionPath);
511
- }
512
- writeFileSync(sessionPath, readFileSync(tempPath, "utf-8"), "utf-8");
513
- unlinkSync(tempPath);
511
+ // Atomic rename - renameSync is atomic on POSIX systems
512
+ renameSync(tempPath, sessionPath);
514
513
  }
515
514
  catch (error) {
516
515
  if (existsSync(tempPath)) {
@@ -30,6 +30,11 @@ export async function createModelFromString(modelString) {
30
30
  if (!shedAuth) {
31
31
  throw new Error("Not logged in. Run 'town login' or set SHED_API_KEY.");
32
32
  }
33
+ console.log("[model-factory] town- model, sending to shed:", {
34
+ shedUrl: shedAuth.shedUrl,
35
+ tokenPrefix: shedAuth.accessToken?.slice(0, 20),
36
+ tokenLength: shedAuth.accessToken?.length,
37
+ });
33
38
  return new ChatAnthropic({
34
39
  model: actualModel,
35
40
  anthropicApiUrl: `${shedAuth.shedUrl}/api/anthropic`,