khala-cli 0.4.9 → 0.4.10

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 (45) hide show
  1. package/dist/THIRD_PARTY_NOTICES.txt +28 -0
  2. package/dist/{chunk-NIX5F4LT.mjs → chunk-2AMWQ7RB.mjs} +330 -66
  3. package/dist/{chunk-PAJ4JJPV.mjs → chunk-3E5DH3Y6.mjs} +43 -6
  4. package/dist/{chunk-NGSYOVQ4.mjs → chunk-4BP7V3OP.mjs} +2 -2
  5. package/dist/{chunk-TEFOQXBK.mjs → chunk-4BZQ4GVW.mjs} +3 -3
  6. package/dist/{chunk-ITFD3JZS.mjs → chunk-5JSGA6OB.mjs} +424 -78
  7. package/dist/{chunk-QKWEZXR3.mjs → chunk-6AQVW5W7.mjs} +12 -4
  8. package/dist/{chunk-UK5GJO4Y.mjs → chunk-6J2PUM7L.mjs} +6 -5
  9. package/dist/{chunk-P3YIN7G7.mjs → chunk-6SUV3EW6.mjs} +11 -10
  10. package/dist/{chunk-GSZADJMW.mjs → chunk-ARIDZOTI.mjs} +309 -81
  11. package/dist/chunk-C2WEDMAF.mjs +15 -0
  12. package/dist/{chunk-DJM23SIU.mjs → chunk-CHC4VZF5.mjs} +7 -8
  13. package/dist/{chunk-BLCRVRIK.mjs → chunk-CKLCR5G4.mjs} +456 -87
  14. package/dist/{chunk-7R3EIDGR.mjs → chunk-EVT2DWNZ.mjs} +1 -1
  15. package/dist/{chunk-KMLXOPBQ.mjs → chunk-FJVVSKZ3.mjs} +4 -2
  16. package/dist/{chunk-3KDOTR54.mjs → chunk-G3NMB4PY.mjs} +1 -1
  17. package/dist/{chunk-SSO5RFOX.mjs → chunk-HHEZVPRR.mjs} +1 -1
  18. package/dist/{chunk-BV45NK7K.mjs → chunk-JKOJQTFT.mjs} +100 -6
  19. package/dist/{chunk-T7IL7V7Q.mjs → chunk-NDMFD5IM.mjs} +13 -10
  20. package/dist/{chunk-TANCKTDK.mjs → chunk-OEV5DFLW.mjs} +70 -5
  21. package/dist/{chunk-BEO7WIIM.mjs → chunk-OIZ4R5H7.mjs} +28 -8
  22. package/dist/{chunk-FZEH2IXZ.mjs → chunk-PJKI7SRI.mjs} +176 -26
  23. package/dist/{chunk-NPSQNCOY.mjs → chunk-PN25BUQ4.mjs} +13 -4
  24. package/dist/{chunk-3R6HFSLL.mjs → chunk-QDPJ4VT2.mjs} +92 -38
  25. package/dist/{chunk-FO5GXCST.mjs → chunk-SRZTHCXP.mjs} +5 -5
  26. package/dist/{chunk-LBT47HLZ.mjs → chunk-TSK3HJEG.mjs} +10 -9
  27. package/dist/{chunk-6BO3JSUP.mjs → chunk-UX34IVN5.mjs} +2 -2
  28. package/dist/{chunk-V4F3SYKW.mjs → chunk-VAC3JTAV.mjs} +25 -17
  29. package/dist/{chunk-PDZ5Z5ZE.mjs → chunk-VDZK4LW3.mjs} +24 -9
  30. package/dist/chunk-W6HM6F2U.mjs +901 -0
  31. package/dist/{chunk-WDOHRV3D.mjs → chunk-WPNMWNCL.mjs} +14 -14
  32. package/dist/chunk-WUDXHF2Q.mjs +14 -0
  33. package/dist/{chunk-XBQDIKB5.mjs → chunk-WZJ6DQJV.mjs} +9 -8
  34. package/dist/{chunk-ANSR4IAW.mjs → chunk-XR625T3I.mjs} +2 -2
  35. package/dist/{chunk-K7V7X6WU.mjs → chunk-ZSKLNZWZ.mjs} +21 -4
  36. package/dist/iterm2_send.py +56 -0
  37. package/dist/khala.mjs +11 -11
  38. package/dist/web/assets/local-CSPuGnH2.css +1 -0
  39. package/dist/web/assets/local-Dtyxaacx.js +9 -0
  40. package/dist/web/index.html +2 -2
  41. package/package.json +1 -1
  42. package/dist/chunk-47XNLAJG.mjs +0 -38
  43. package/dist/chunk-XUCWSYVS.mjs +0 -148
  44. package/dist/web/assets/local-CFzRHZpB.js +0 -9
  45. package/dist/web/assets/local-ciypUFoK.css +0 -1
@@ -1,13 +1,13 @@
1
1
  import { createRequire as __khalaCreateRequire } from 'node:module'; const require = __khalaCreateRequire(import.meta.url);
2
2
  import {
3
3
  KHALA_AGENT_VERSION
4
- } from "./chunk-ANSR4IAW.mjs";
4
+ } from "./chunk-XR625T3I.mjs";
5
5
  import {
6
6
  bundle
7
- } from "./chunk-3KDOTR54.mjs";
7
+ } from "./chunk-G3NMB4PY.mjs";
8
8
  import {
9
9
  LISTENING_MODES
10
- } from "./chunk-NGSYOVQ4.mjs";
10
+ } from "./chunk-4BP7V3OP.mjs";
11
11
  import {
12
12
  HARNESS_REGISTRY,
13
13
  M1_LABEL_MAX_BYTES,
@@ -35,10 +35,10 @@ import {
35
35
  utcTimestamp,
36
36
  utf8Length,
37
37
  version
38
- } from "./chunk-NPSQNCOY.mjs";
38
+ } from "./chunk-PN25BUQ4.mjs";
39
39
  import {
40
40
  init_define_KHALA_BUNDLE
41
- } from "./chunk-7R3EIDGR.mjs";
41
+ } from "./chunk-EVT2DWNZ.mjs";
42
42
 
43
43
  // src/client.ts
44
44
  init_define_KHALA_BUNDLE();
@@ -3,15 +3,16 @@ import {
3
3
  resolveHarness,
4
4
  resolveSession,
5
5
  resolveSessionId
6
- } from "./chunk-6BO3JSUP.mjs";
7
- import "./chunk-ITFD3JZS.mjs";
8
- import "./chunk-QKWEZXR3.mjs";
9
- import "./chunk-NIX5F4LT.mjs";
10
- import "./chunk-NGSYOVQ4.mjs";
11
- import "./chunk-TANCKTDK.mjs";
12
- import "./chunk-NPSQNCOY.mjs";
13
- import "./chunk-K7V7X6WU.mjs";
14
- import "./chunk-7R3EIDGR.mjs";
6
+ } from "./chunk-UX34IVN5.mjs";
7
+ import "./chunk-5JSGA6OB.mjs";
8
+ import "./chunk-6AQVW5W7.mjs";
9
+ import "./chunk-2AMWQ7RB.mjs";
10
+ import "./chunk-4BP7V3OP.mjs";
11
+ import "./chunk-OEV5DFLW.mjs";
12
+ import "./chunk-JKOJQTFT.mjs";
13
+ import "./chunk-PN25BUQ4.mjs";
14
+ import "./chunk-ZSKLNZWZ.mjs";
15
+ import "./chunk-EVT2DWNZ.mjs";
15
16
  export {
16
17
  resolveHarness,
17
18
  resolveSession,
@@ -2,10 +2,10 @@ import { createRequire as __khalaCreateRequire } from 'node:module'; const requi
2
2
  import {
3
3
  adapterFor,
4
4
  resolveSources
5
- } from "./chunk-ITFD3JZS.mjs";
5
+ } from "./chunk-5JSGA6OB.mjs";
6
6
  import {
7
7
  init_define_KHALA_BUNDLE
8
- } from "./chunk-7R3EIDGR.mjs";
8
+ } from "./chunk-EVT2DWNZ.mjs";
9
9
 
10
10
  // src/mcp/session-id.ts
11
11
  init_define_KHALA_BUNDLE();
@@ -1,25 +1,30 @@
1
1
  import { createRequire as __khalaCreateRequire } from 'node:module'; const require = __khalaCreateRequire(import.meta.url);
2
2
  import {
3
3
  sessionStartWakeChannels
4
- } from "./chunk-TEFOQXBK.mjs";
4
+ } from "./chunk-4BZQ4GVW.mjs";
5
5
  import {
6
6
  adapterFor
7
- } from "./chunk-ITFD3JZS.mjs";
8
- import "./chunk-QKWEZXR3.mjs";
7
+ } from "./chunk-5JSGA6OB.mjs";
8
+ import "./chunk-6AQVW5W7.mjs";
9
9
  import {
10
- driverAllowed
11
- } from "./chunk-NIX5F4LT.mjs";
12
- import "./chunk-NGSYOVQ4.mjs";
13
- import "./chunk-TANCKTDK.mjs";
10
+ driverAllowed,
11
+ readListeningMode
12
+ } from "./chunk-2AMWQ7RB.mjs";
13
+ import "./chunk-4BP7V3OP.mjs";
14
+ import {
15
+ wakesAgent
16
+ } from "./chunk-OEV5DFLW.mjs";
17
+ import "./chunk-JKOJQTFT.mjs";
14
18
  import {
15
19
  filesForDir,
20
+ readJson,
16
21
  resolveStateDir,
17
22
  stateRoot
18
- } from "./chunk-NPSQNCOY.mjs";
19
- import "./chunk-K7V7X6WU.mjs";
23
+ } from "./chunk-PN25BUQ4.mjs";
24
+ import "./chunk-ZSKLNZWZ.mjs";
20
25
  import {
21
26
  init_define_KHALA_BUNDLE
22
- } from "./chunk-7R3EIDGR.mjs";
27
+ } from "./chunk-EVT2DWNZ.mjs";
23
28
 
24
29
  // hooks/claude-wake.ts
25
30
  init_define_KHALA_BUNDLE();
@@ -30,7 +35,7 @@ import { setTimeout as sleep } from "node:timers/promises";
30
35
  var NOTICE = "Khala: new channel messages. They arrive in the next hook context.\n";
31
36
  var DEADLINE_MS = 24 * 60 * 60 * 1e3;
32
37
  var POLL_MS = 500;
33
- async function readJson(file) {
38
+ async function readJson2(file) {
34
39
  try {
35
40
  return JSON.parse(await fs.readFile(file, "utf8"));
36
41
  } catch (error) {
@@ -39,7 +44,10 @@ async function readJson(file) {
39
44
  }
40
45
  }
41
46
  async function unreadChannelMessages(dir) {
42
- const cursor = await readJson(path.join(dir, "cursor.json"));
47
+ const files = filesForDir(dir);
48
+ const mode = await readListeningMode(files);
49
+ const you = (await readJson(files.status))?.displayName;
50
+ const cursor = await readJson2(path.join(dir, "cursor.json"));
43
51
  const delivered = cursor && (cursor.lastDeliveredEventId === null || typeof cursor.lastDeliveredEventId === "string") && Number.isSafeInteger(cursor.deliveredCount) && typeof cursor.deliveredCount === "number" && cursor.deliveredCount >= 0 ? cursor.deliveredCount : 0;
44
52
  let content;
45
53
  try {
@@ -57,7 +65,7 @@ async function unreadChannelMessages(dir) {
57
65
  continue;
58
66
  }
59
67
  if (!entry || !["eventId", "roomId", "ts", "sender", "senderLabel", "body"].every((key) => typeof entry[key] === "string") || !["human", "agent", "unknown"].includes(entry.senderKind) || !["message", "event"].includes(entry.kind)) continue;
60
- if (index++ >= delivered && entry.kind === "message") messages++;
68
+ if (index++ >= delivered && wakesAgent(entry, mode, you)) messages++;
61
69
  }
62
70
  return messages;
63
71
  }
@@ -72,7 +80,7 @@ async function unreadMessages(dir) {
72
80
  }
73
81
  let messages = 0;
74
82
  for (const directory of directories) {
75
- if ((await readJson(path.join(directory, "mode.json")))?.mode === "async") continue;
83
+ if ((await readJson2(path.join(directory, "mode.json")))?.mode === "async") continue;
76
84
  messages += await unreadChannelMessages(directory);
77
85
  }
78
86
  return messages;
@@ -128,16 +136,16 @@ async function watch(stdin, _argv, io = { stderr: process.stderr, env: process.e
128
136
  };
129
137
  const deadline = started.getTime() + testDuration(io.env.KHALA_WAKE_TEST_DEADLINE_MS, DEADLINE_MS);
130
138
  const poll = testDuration(io.env.KHALA_WAKE_TEST_POLL_MS, POLL_MS);
131
- const owns = async () => (await readJson(owner))?.nonce === nonce;
139
+ const owns = async () => (await readJson2(owner))?.nonce === nonce;
132
140
  const idle = async () => {
133
- const activity = await readJson(path.join(dir, "activity.json"));
141
+ const activity = await readJson2(path.join(dir, "activity.json"));
134
142
  return activity?.state === "idle" && typeof activity.updatedAt === "string" && Number.isFinite(Date.parse(activity.updatedAt));
135
143
  };
136
144
  const unread = async () => {
137
145
  if (input.hook_event_name !== "SessionStart") return unreadMessages(dir);
138
146
  let messages = 0;
139
147
  for (const channel of await sessionStartWakeChannels(filesForDir(dir), io.env)) {
140
- if (channel.connected && (await readJson(channel.files.mode))?.mode !== "async") messages += await unreadChannelMessages(channel.files.dir);
148
+ if (channel.connected && (await readJson2(channel.files.mode))?.mode !== "async") messages += await unreadChannelMessages(channel.files.dir);
141
149
  }
142
150
  return messages;
143
151
  };
@@ -4,7 +4,7 @@ import {
4
4
  checkName,
5
5
  isDefaultAgentName,
6
6
  restartHelper
7
- } from "./chunk-FO5GXCST.mjs";
7
+ } from "./chunk-SRZTHCXP.mjs";
8
8
  import {
9
9
  StateError,
10
10
  harnessInfo,
@@ -13,10 +13,10 @@ import {
13
13
  stateRoot,
14
14
  validateAgentName,
15
15
  writeJsonAtomic
16
- } from "./chunk-NPSQNCOY.mjs";
16
+ } from "./chunk-PN25BUQ4.mjs";
17
17
  import {
18
18
  init_define_KHALA_BUNDLE
19
- } from "./chunk-7R3EIDGR.mjs";
19
+ } from "./chunk-EVT2DWNZ.mjs";
20
20
 
21
21
  // src/local/identity.ts
22
22
  init_define_KHALA_BUNDLE();
@@ -288,12 +288,27 @@ async function pollUntilDeadline(input, options) {
288
288
  }
289
289
  }
290
290
  async function reportReady(input, deps = {}) {
291
- const response = await post(endpoint(input, "/api/agent/join/ready"), input.origin, {}, deps, input.pollSecret);
292
- if (response.status === 204) return;
293
- const code = serverCode(await json(response));
294
- if (response.status === 404) fail("ready_not_found");
295
- if (response.status === 409) fail("not_confirmed");
296
- gatewayError(response.status, code);
291
+ const now = deps.now ?? Date.now;
292
+ const deadline = now() + (deps.timeoutMs ?? 12e4);
293
+ for (let delay = 1e3; ; delay = Math.min(delay * 2, 15e3)) {
294
+ const response = await post(endpoint(input, "/api/agent/join/ready"), input.origin, {}, deps, input.pollSecret);
295
+ if (response.status === 204) return;
296
+ const code = serverCode(await json(response));
297
+ if ((response.status === 429 || response.status === 503 && code === "unavailable") && now() + delay <= deadline) {
298
+ try {
299
+ await (deps.sleep ?? sleep)(delay, deps.signal);
300
+ } catch {
301
+ fail("network");
302
+ }
303
+ continue;
304
+ }
305
+ readyError(response.status, code);
306
+ }
307
+ }
308
+ function readyError(status, code) {
309
+ if (status === 404) fail("ready_not_found");
310
+ if (status === 409) fail("not_confirmed");
311
+ gatewayError(status, code);
297
312
  fail("protocol");
298
313
  }
299
314