@tekmidian/pai 0.29.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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  // src/hooks/ts/stop/stop-hook.ts
4
4
  import { readFileSync as readFileSync6, writeFileSync as writeFileSync4, mkdirSync as mkdirSync5, existsSync as existsSync7, unlinkSync } from "fs";
5
- import { join as join7, basename as basename3, dirname } from "path";
5
+ import { join as join7, basename as basename4, dirname } from "path";
6
6
  import { connect } from "net";
7
7
  import { randomUUID } from "crypto";
8
8
 
@@ -388,7 +388,7 @@ ${summary || "Session completed."}`
388
388
 
389
389
  // src/hooks/ts/lib/project-utils/todo.ts
390
390
  import { existsSync as existsSync6, mkdirSync as mkdirSync4, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
391
- import { join as join6 } from "path";
391
+ import { join as join6, basename as basename3 } from "path";
392
392
 
393
393
  // src/session/checkpoint-block.ts
394
394
  import {
@@ -767,7 +767,12 @@ function ensureTodoMd(cwd) {
767
767
  }
768
768
  return todoPath;
769
769
  }
770
- function updateTodoContinue(cwd, noteFilename, state, tokenDisplay) {
770
+ function sessionIdFromTranscript(transcriptPath) {
771
+ if (!transcriptPath) return void 0;
772
+ const base = basename3(transcriptPath).replace(/\.jsonl$/, "");
773
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(base) ? base : void 0;
774
+ }
775
+ function updateTodoContinue(cwd, noteFilename, state, tokenDisplay, sessionId) {
771
776
  ensureTodoMd(cwd);
772
777
  const result = applyContinue({
773
778
  rootPath: cwd,
@@ -778,6 +783,9 @@ function updateTodoContinue(cwd, noteFilename, state, tokenDisplay) {
778
783
  // is the key that decides whether an authored checkpoint belongs to the
779
784
  // current session and must be preserved.
780
785
  sessionLine: noteFilename.replace(/\.md$/, ""),
786
+ // The UUID is authoritative when present; the line above is the fallback
787
+ // for callers that cannot supply one, and it is mutable by design.
788
+ sessionId,
781
789
  cwd,
782
790
  body: state?.trim() || void 0
783
791
  });
@@ -1279,7 +1287,7 @@ async function executeDirectly(lines, transcriptPath, cwd, message, lastUserQuer
1279
1287
  }
1280
1288
  const summary = message || "Session completed.";
1281
1289
  finalizeSessionNote(currentNotePath, summary);
1282
- console.error(`Session note finalized: ${basename3(currentNotePath)}`);
1290
+ console.error(`Session note finalized: ${basename4(currentNotePath)}`);
1283
1291
  if (workItems.length === 0 && !message) {
1284
1292
  console.error("Nothing to hand over \u2014 leaving TODO.md ## Continue intact");
1285
1293
  } else {
@@ -1295,7 +1303,16 @@ async function executeDirectly(lines, transcriptPath, cwd, message, lastUserQuer
1295
1303
  if (message) {
1296
1304
  stateLines.push("", `Last completed: ${message}`);
1297
1305
  }
1298
- updateTodoContinue(cwd, basename3(currentNotePath), stateLines.join("\n"), "session-end");
1306
+ updateTodoContinue(
1307
+ cwd,
1308
+ basename4(currentNotePath),
1309
+ stateLines.join("\n"),
1310
+ "session-end",
1311
+ // Identity, not the note title. The note is renamed as the session
1312
+ // ends, so the title-based comparison stops recognising this very
1313
+ // session moments after it writes.
1314
+ sessionIdFromTranscript(transcriptPath)
1315
+ );
1299
1316
  } catch (todoError) {
1300
1317
  console.error(`Could not update TODO.md: ${todoError}`);
1301
1318
  }
@@ -1348,7 +1365,7 @@ STOP-HOOK TRIGGERED AT ${timestamp}`);
1348
1365
  transcriptPath = parsed.transcript_path;
1349
1366
  cwd = parsed.cwd || process.cwd();
1350
1367
  stopHookActive = parsed.stop_hook_active === true;
1351
- sessionId = parsed.session_id ?? basename3(transcriptPath ?? "").replace(/\.jsonl$/, "");
1368
+ sessionId = parsed.session_id ?? basename4(transcriptPath ?? "").replace(/\.jsonl$/, "");
1352
1369
  debug(`Transcript path: ${transcriptPath}`);
1353
1370
  debug(`Working directory: ${cwd}`);
1354
1371
  debug(`stop_hook_active: ${stopHookActive}`);