@tekmidian/pai 0.42.6 → 0.43.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.
Files changed (42) hide show
  1. package/dist/{chain-BbcfP77K.mjs → chain-CEC1a5mX.mjs} +2 -2
  2. package/dist/{chain-BbcfP77K.mjs.map → chain-CEC1a5mX.mjs.map} +1 -1
  3. package/dist/cli/index.mjs +5 -5
  4. package/dist/cli/program.mjs +5 -5
  5. package/dist/daemon/index.mjs +4 -4
  6. package/dist/{daemon-BppziPi6.mjs → daemon-BhldpFvO.mjs} +6 -6
  7. package/dist/{daemon-BppziPi6.mjs.map → daemon-BhldpFvO.mjs.map} +1 -1
  8. package/dist/{daemon-BNjbVsQU.mjs → daemon-QIvCXB5f.mjs} +4 -4
  9. package/dist/daemon-mcp/index.mjs +3 -3
  10. package/dist/{fallback-Cwt4hmh5.mjs → fallback-BQJ8PbCK.mjs} +6 -4
  11. package/dist/fallback-BQJ8PbCK.mjs.map +1 -0
  12. package/dist/hooks/load-project-context.mjs +51 -48
  13. package/dist/hooks/load-project-context.mjs.map +4 -4
  14. package/dist/hooks/whisper-reinject.mjs +8 -0
  15. package/dist/hooks/whisper-reinject.mjs.map +3 -3
  16. package/dist/hooks/worker-status-line.mjs +108 -41
  17. package/dist/hooks/worker-status-line.mjs.map +3 -3
  18. package/dist/{planner-pXRc-8yt.mjs → planner-BlKGgpWI.mjs} +3 -3
  19. package/dist/{planner-pXRc-8yt.mjs.map → planner-BlKGgpWI.mjs.map} +1 -1
  20. package/dist/{program-LLNPpxlj.mjs → program-C5jRQ1kg.mjs} +749 -25
  21. package/dist/program-C5jRQ1kg.mjs.map +1 -0
  22. package/dist/{run-DDdT9teG.mjs → run-ByBKowN5.mjs} +472 -59
  23. package/dist/run-ByBKowN5.mjs.map +1 -0
  24. package/dist/{tools-BradfQk7.mjs → tools-CAG2sUjf.mjs} +2 -2
  25. package/dist/{tools-UrSHIe29.mjs → tools-DiRC5glA.mjs} +2 -2
  26. package/dist/{tools-UrSHIe29.mjs.map → tools-DiRC5glA.mjs.map} +1 -1
  27. package/dist/{wakeup-TnGjJY3I.mjs → wakeup-BfElduEU.mjs} +21 -8
  28. package/dist/wakeup-BfElduEU.mjs.map +1 -0
  29. package/docs/commands/README.md +3 -1
  30. package/docs/commands/audit.md +27 -2
  31. package/docs/commands/worker.md +2 -0
  32. package/package.json +1 -1
  33. package/scripts/build-hooks.mjs +2 -0
  34. package/src/hooks/ts/post-tool-use/whisper-reinject.test.ts +55 -0
  35. package/src/hooks/ts/post-tool-use/whisper-reinject.ts +3 -0
  36. package/src/hooks/ztk-auto.sh +28 -0
  37. package/src/hooks/ztk-auto.test.ts +72 -0
  38. package/src/hooks/ztk-passthrough.mjs +71 -0
  39. package/dist/fallback-Cwt4hmh5.mjs.map +0 -1
  40. package/dist/program-LLNPpxlj.mjs.map +0 -1
  41. package/dist/run-DDdT9teG.mjs.map +0 -1
  42. package/dist/wakeup-TnGjJY3I.mjs.map +0 -1
@@ -15,9 +15,39 @@ import { homedir as homedir5 } from "os";
15
15
  import { execSync } from "child_process";
16
16
 
17
17
  // src/memory/wakeup.ts
18
- import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
19
- import { join, basename } from "node:path";
18
+ import { existsSync as existsSync2, readdirSync as readdirSync2, readFileSync as readFileSync2, statSync as statSync2 } from "node:fs";
19
+ import { join as join2, basename } from "node:path";
20
+ import { homedir as homedir2 } from "node:os";
21
+
22
+ // src/config/pai-home.ts
23
+ import { existsSync, mkdirSync, readFileSync, copyFileSync, renameSync, readdirSync, statSync } from "node:fs";
20
24
  import { homedir } from "node:os";
25
+ import { join, dirname } from "node:path";
26
+ function paiHomeDir() {
27
+ return process.env.PAI_HOME || join(homedir(), ".claude", "pai");
28
+ }
29
+ function paiHomePath(...segments) {
30
+ return join(paiHomeDir(), ...segments);
31
+ }
32
+ var noticesPrinted = /* @__PURE__ */ new Set();
33
+ function resolvePaiFile(newPath, oldCandidates, migrateHint) {
34
+ if (existsSync(newPath)) return newPath;
35
+ for (const old of oldCandidates) {
36
+ if (existsSync(old)) {
37
+ if (!noticesPrinted.has(newPath)) {
38
+ noticesPrinted.add(newPath);
39
+ process.stderr.write(
40
+ `pai: ${old} is at an old location \u2014 run \`${migrateHint}\` to move it to ${newPath}
41
+ `
42
+ );
43
+ }
44
+ return old;
45
+ }
46
+ }
47
+ return newPath;
48
+ }
49
+
50
+ // src/memory/wakeup.ts
21
51
  var L1_TOKEN_BUDGET = 300;
22
52
  var L1_CHAR_BUDGET = L1_TOKEN_BUDGET * 4;
23
53
  var L1_MAX_NOTES = 3;
@@ -27,47 +57,50 @@ var EXTRACT_SECTIONS = [
27
57
  "Next Steps",
28
58
  "Checkpoint"
29
59
  ];
30
- var IDENTITY_FILE = join(homedir(), ".pai", "identity.txt");
31
- function loadL0Identity() {
32
- if (!existsSync(IDENTITY_FILE)) return "";
60
+ var IDENTITY_FILE = join2(homedir2(), ".pai", "identity.txt");
61
+ function loadL0Identity(opts = {}) {
62
+ const newPath = opts.newPath ?? paiHomePath("identity.txt");
63
+ const legacyPath = opts.legacyPath ?? IDENTITY_FILE;
64
+ const path = existsSync2(newPath) ? newPath : legacyPath;
65
+ if (!existsSync2(path)) return "";
33
66
  try {
34
- return readFileSync(IDENTITY_FILE, "utf-8").trim();
67
+ return readFileSync2(path, "utf-8").trim();
35
68
  } catch {
36
69
  return "";
37
70
  }
38
71
  }
39
72
  function findNotesDirForProject(rootPath) {
40
73
  const localCandidates = [
41
- join(rootPath, "Notes"),
42
- join(rootPath, "notes"),
43
- join(rootPath, ".claude", "Notes")
74
+ join2(rootPath, "Notes"),
75
+ join2(rootPath, "notes"),
76
+ join2(rootPath, ".claude", "Notes")
44
77
  ];
45
78
  for (const p of localCandidates) {
46
- if (existsSync(p)) return p;
79
+ if (existsSync2(p)) return p;
47
80
  }
48
81
  const encoded = rootPath.replace(/\//g, "-").replace(/\./g, "-").replace(/ /g, "-");
49
- const centralNotes = join(
50
- homedir(),
82
+ const centralNotes = join2(
83
+ homedir2(),
51
84
  ".claude",
52
85
  "projects",
53
86
  encoded,
54
87
  "Notes"
55
88
  );
56
- if (existsSync(centralNotes)) return centralNotes;
89
+ if (existsSync2(centralNotes)) return centralNotes;
57
90
  return null;
58
91
  }
59
92
  function findSessionNotes(notesDir) {
60
93
  const result = [];
61
94
  const scanDir = (dir) => {
62
- if (!existsSync(dir)) return;
95
+ if (!existsSync2(dir)) return;
63
96
  let entries;
64
97
  try {
65
- entries = readdirSync(dir, { withFileTypes: true }).map((e) => ({ name: e.name, isDir: e.isDirectory() }));
98
+ entries = readdirSync2(dir, { withFileTypes: true }).map((e) => ({ name: e.name, isDir: e.isDirectory() }));
66
99
  } catch {
67
100
  return;
68
101
  }
69
102
  for (const entry of entries) {
70
- const fullPath = join(dir, entry.name);
103
+ const fullPath = join2(dir, entry.name);
71
104
  if (entry.isDir) {
72
105
  scanDir(fullPath);
73
106
  } else if (entry.name.match(/^\d{3,4}[\s_-].*\.md$/)) {
@@ -80,7 +113,7 @@ function findSessionNotes(notesDir) {
80
113
  const numberOf = (p) => parseInt(basename(p).match(/^(\d+)/)?.[1] ?? "0", 10);
81
114
  const mtimeOf = (p) => {
82
115
  try {
83
- return statSync(p).mtimeMs;
116
+ return statSync2(p).mtimeMs;
84
117
  } catch {
85
118
  return 0;
86
119
  }
@@ -155,7 +188,7 @@ function buildL1EssentialStory(rootPath, tokenBudget = L1_TOKEN_BUDGET) {
155
188
  if (remaining <= 50) break;
156
189
  let content;
157
190
  try {
158
- content = readFileSync(noteFile, "utf-8");
191
+ content = readFileSync2(noteFile, "utf-8");
159
192
  } catch {
160
193
  continue;
161
194
  }
@@ -332,36 +365,6 @@ var AUTHORED_GRACE_MS = 60 * 60 * 1e3;
332
365
  import { homedir as homedir3 } from "os";
333
366
  import { resolve, join as join3 } from "path";
334
367
  import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
335
-
336
- // src/config/pai-home.ts
337
- import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, copyFileSync, renameSync, readdirSync as readdirSync2, statSync as statSync2 } from "node:fs";
338
- import { homedir as homedir2 } from "node:os";
339
- import { join as join2, dirname } from "node:path";
340
- function paiHomeDir() {
341
- return process.env.PAI_HOME || join2(homedir2(), ".claude", "pai");
342
- }
343
- function paiHomePath(...segments) {
344
- return join2(paiHomeDir(), ...segments);
345
- }
346
- var noticesPrinted = /* @__PURE__ */ new Set();
347
- function resolvePaiFile(newPath, oldCandidates, migrateHint) {
348
- if (existsSync2(newPath)) return newPath;
349
- for (const old of oldCandidates) {
350
- if (existsSync2(old)) {
351
- if (!noticesPrinted.has(newPath)) {
352
- noticesPrinted.add(newPath);
353
- process.stderr.write(
354
- `pai: ${old} is at an old location \u2014 run \`${migrateHint}\` to move it to ${newPath}
355
- `
356
- );
357
- }
358
- return old;
359
- }
360
- }
361
- return newPath;
362
- }
363
-
364
- // src/hooks/ts/lib/pai-paths.ts
365
368
  function loadEnvFile() {
366
369
  const possiblePaths = [
367
370
  resolve(process.env.ADAPTER_DIR || process.env.PAI_DIR || "", ".env"),