khala-cli 0.4.13 → 0.4.14

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/{chunk-QPYXV4BQ.mjs → chunk-2ZT7TFV5.mjs} +10 -10
  2. package/dist/{chunk-SDBMJPIA.mjs → chunk-4THILKJ5.mjs} +6 -6
  3. package/dist/{chunk-O4QJ3ZT6.mjs → chunk-4YHVAWZF.mjs} +3 -3
  4. package/dist/chunk-6CDTY2EG.mjs +20 -0
  5. package/dist/{chunk-QZUBLJW7.mjs → chunk-BSB77FJG.mjs} +2 -2
  6. package/dist/{chunk-ZWWTVM6R.mjs → chunk-FOCBFFH5.mjs} +2 -2
  7. package/dist/{chunk-SUUEWCY5.mjs → chunk-G2TAYBYB.mjs} +1 -1
  8. package/dist/{chunk-3JA3Q5MK.mjs → chunk-H3XIRV2S.mjs} +1 -1
  9. package/dist/{chunk-JZZNVQKH.mjs → chunk-HPZY6LHL.mjs} +2 -2
  10. package/dist/{chunk-6P4PKPJW.mjs → chunk-KZO6BSPQ.mjs} +5 -5
  11. package/dist/{chunk-NHW62KEB.mjs → chunk-N7B2VPDU.mjs} +1 -1
  12. package/dist/{chunk-2AIADANH.mjs → chunk-O2NDYSYF.mjs} +6 -6
  13. package/dist/{chunk-JLENHMKE.mjs → chunk-OPBOWFBB.mjs} +33 -32
  14. package/dist/{chunk-SUT7AKNZ.mjs → chunk-P2S3OAZ5.mjs} +6 -6
  15. package/dist/{chunk-XI5FPUNN.mjs → chunk-PFWYYXR5.mjs} +2 -2
  16. package/dist/{chunk-SKJ6YV3G.mjs → chunk-PISWOM3Q.mjs} +14 -13
  17. package/dist/{chunk-P3XZEYZF.mjs → chunk-PIYD4WCN.mjs} +1 -1
  18. package/dist/{chunk-KMDLTHDW.mjs → chunk-PYVAMHAG.mjs} +2 -2
  19. package/dist/{chunk-BWVC3EKG.mjs → chunk-QEIYPWN4.mjs} +13 -13
  20. package/dist/{chunk-3GUVMXTM.mjs → chunk-QH5WZEIG.mjs} +23 -17
  21. package/dist/{chunk-OIYAR2ND.mjs → chunk-RHAAMCRD.mjs} +7 -7
  22. package/dist/{chunk-72W7IC2O.mjs → chunk-RXM47OGD.mjs} +26 -5
  23. package/dist/{chunk-RUQDE5DI.mjs → chunk-T3BRQFVF.mjs} +1 -1
  24. package/dist/chunk-TMOAMJMV.mjs +19 -0
  25. package/dist/{chunk-BJVJ5WJS.mjs → chunk-TVWBZD24.mjs} +32 -29
  26. package/dist/{chunk-32SGUUP5.mjs → chunk-U2OUPWUW.mjs} +2 -2
  27. package/dist/{chunk-6DE4V756.mjs → chunk-UBDI4XFO.mjs} +32 -12
  28. package/dist/chunk-UQJHB4AH.mjs +27 -0
  29. package/dist/{chunk-XR3JSUPF.mjs → chunk-VQDIOGV7.mjs} +24 -14
  30. package/dist/chunk-VXHWS7JD.mjs +47 -0
  31. package/dist/{chunk-XRV5GUSI.mjs → chunk-W3LLNKEB.mjs} +3 -3
  32. package/dist/{chunk-ICTAFDO6.mjs → chunk-WMZ7YE6H.mjs} +3 -3
  33. package/dist/{chunk-ONAZVGVO.mjs → chunk-YXMJJAMH.mjs} +9 -9
  34. package/dist/{chunk-MRSZOWFU.mjs → chunk-ZWDINIQJ.mjs} +1 -1
  35. package/dist/khala.mjs +11 -11
  36. package/dist/web/assets/{local-mElTRGcH.js → local-EzltpNwn.js} +4 -4
  37. package/dist/web/index.html +1 -1
  38. package/package.json +1 -1
  39. package/dist/chunk-2BNIPJVW.mjs +0 -27
  40. package/dist/chunk-I4POSYHZ.mjs +0 -132
  41. package/dist/chunk-TVQ5NHFX.mjs +0 -20
  42. package/dist/chunk-WZD4JAG6.mjs +0 -19
@@ -2,18 +2,20 @@ import { createRequire as __khalaCreateRequire } from 'node:module'; const requi
2
2
  import {
3
3
  DEFAULT_LISTENING_MODE,
4
4
  decodeListeningMode
5
- } from "./chunk-I4POSYHZ.mjs";
5
+ } from "./chunk-VXHWS7JD.mjs";
6
6
  import {
7
7
  advanceCursor,
8
8
  isWakeEntry,
9
9
  listChannels,
10
+ markNudged,
10
11
  mentions,
11
12
  readActivity,
12
13
  readCursor,
13
14
  readEntries,
14
15
  unread,
16
+ wakeStart,
15
17
  wakesAgent
16
- } from "./chunk-72W7IC2O.mjs";
18
+ } from "./chunk-RXM47OGD.mjs";
17
19
  import {
18
20
  SESSION_ID_PATTERN,
19
21
  StateError,
@@ -23,7 +25,7 @@ import {
23
25
  sessionFiles,
24
26
  stateRoot,
25
27
  writeJsonAtomic
26
- } from "./chunk-NHW62KEB.mjs";
28
+ } from "./chunk-N7B2VPDU.mjs";
27
29
  import {
28
30
  cancelAttempt,
29
31
  confirmWakeText,
@@ -32,10 +34,10 @@ import {
32
34
  settleAttempts,
33
35
  wakeLine,
34
36
  withWakeLock
35
- } from "./chunk-SUUEWCY5.mjs";
37
+ } from "./chunk-G2TAYBYB.mjs";
36
38
  import {
37
39
  init_define_KHALA_BUNDLE
38
- } from "./chunk-3JA3Q5MK.mjs";
40
+ } from "./chunk-H3XIRV2S.mjs";
39
41
 
40
42
  // src/watch.ts
41
43
  init_define_KHALA_BUNDLE();
@@ -93,14 +95,20 @@ async function isDelegated(files) {
93
95
  }
94
96
  async function readListeningMode(files) {
95
97
  const state = await readModeState(files);
96
- return state.archived || await isDelegated(files) ? "async" : state.mode;
98
+ return state.archived || await isDelegated(files) ? "mute" : state.mode;
97
99
  }
98
100
  async function applyArchived(files, archived) {
99
101
  const content = await readJson(files.mode);
100
102
  if (content?.archived === true === archived) return;
101
- if (!archived && (await readModeState(files)).mode !== "async") await skipBacklog(files);
103
+ const stored = (await readModeState(files)).mode;
104
+ if (!archived && !QUIET.has(stored)) await skipBacklog(files);
105
+ if (!archived && stored === "async") await skipPings(files);
102
106
  await writeJsonAtomic(files.mode, { ...content ?? {}, archived });
103
107
  }
108
+ async function skipPings(files) {
109
+ const cursor = await readCursor(files);
110
+ await markNudged(files, cursor, (await readEntries(files)).length);
111
+ }
104
112
  async function skipBacklog(files) {
105
113
  for (let attempt = 0; attempt < 2; attempt++) {
106
114
  const { cursor, entries } = await unread(files);
@@ -108,11 +116,13 @@ async function skipBacklog(files) {
108
116
  }
109
117
  throw new StateError("storage_failed");
110
118
  }
111
- var ATTENTION = { async: 0, sync: 1, steer: 2 };
119
+ var ATTENTION = { mute: 0, async: 1, sync: 2, steer: 3 };
120
+ var QUIET = /* @__PURE__ */ new Set(["async", "mute"]);
112
121
  async function applyListeningMode(files, next, meta, now = () => /* @__PURE__ */ new Date()) {
113
122
  const { keepBacklog, ...record } = meta;
114
123
  const { mode: previous, archived } = await readModeState(files);
115
- if (previous === "async" && next !== "async" && !keepBacklog) await skipBacklog(files);
124
+ if (QUIET.has(previous) && !QUIET.has(next) && !keepBacklog) await skipBacklog(files);
125
+ if (previous === "mute" && next === "async") await skipPings(files);
116
126
  await writeJsonAtomic(files.mode, { mode: next, ...archived ? { archived } : {}, ...record, updatedAt: now().toISOString() });
117
127
  return { previous, next };
118
128
  }
@@ -982,7 +992,7 @@ async function watchSession(files, io) {
982
992
  if (!await wakeAllowed()) return;
983
993
  if (latestSession?.userId !== session.userId || latestSession?.roomId !== session.roomId || !["connected", "send_failed"].includes(latestStatus?.state ?? "")) continue;
984
994
  const messages = fresh.filter((entry) => isWakeEntry(entry) && entry.sender !== session.userId && entry.roomId === session.roomId);
985
- if (io.harness !== "muse" && !done && mode !== "async" && latestMode !== "async" && messages.some((entry) => wakesAgent(entry, latestMode, latestStatus?.displayName))) {
995
+ if (io.harness !== "muse" && !done && mode !== "mute" && latestMode !== "mute" && messages.some((entry) => wakesAgent(entry, latestMode, latestStatus?.displayName))) {
986
996
  const count = messages.filter((entry) => mentions(entry, latestStatus?.displayName)).length;
987
997
  io.write(`khala: ${messages.length} new message${messages.length === 1 ? "" : "s"} in #${channelLabel(latestStatus?.channelName ?? channel.channelName ?? "channel")} (${count} mentions you)
988
998
  `);
@@ -1013,12 +1023,12 @@ async function watchSession(files, io) {
1013
1023
  let eligible = false;
1014
1024
  for (const channel of channels) {
1015
1025
  const channelMode = await readListeningMode(channel.files);
1016
- if (channelMode === "async") continue;
1026
+ if (channelMode === "mute") continue;
1017
1027
  const session = await readJson(channel.files.session);
1018
1028
  const status2 = await readWatcherStatus(channel.files);
1019
1029
  if (!["connected", "send_failed"].includes(status2?.state ?? "")) continue;
1020
1030
  const cursor = await readCursor(channel.files);
1021
- eligible ||= (await readEntries(channel.files)).slice(cursor.deliveredCount).some((entry) => entry.sender !== session?.userId && wakesAgent(entry, channelMode, status2?.displayName));
1031
+ eligible ||= (await readEntries(channel.files)).slice(wakeStart(cursor)).some((entry) => entry.sender !== session?.userId && wakesAgent(entry, channelMode, status2?.displayName));
1022
1032
  }
1023
1033
  const activity = await readActivity(files);
1024
1034
  if (eligible && await ownsSession() && activity.state === "idle") {
@@ -1087,8 +1097,8 @@ ${WATCH_USAGE}`);
1087
1097
  return 1;
1088
1098
  };
1089
1099
  if (argv.length !== 0 && !(argv.length === 2 && ["--session", "--harness"].includes(argv[0])) && !(argv.length === 4 && argv[0] === "--harness" && argv[2] === "--session")) return invalid("invalid_arguments");
1090
- const { resolveHarness, resolveSessionId } = await import("./chunk-TVQ5NHFX.mjs");
1091
- const { adapterFor } = await import("./chunk-WZD4JAG6.mjs");
1100
+ const { resolveHarness, resolveSessionId } = await import("./chunk-6CDTY2EG.mjs");
1101
+ const { adapterFor } = await import("./chunk-TMOAMJMV.mjs");
1092
1102
  const harness = resolveHarness(argv, process.env);
1093
1103
  if (harness === "invalid" || !adapterFor(harness)?.codec) return invalid("invalid_harness");
1094
1104
  const index = argv.indexOf("--session");
@@ -0,0 +1,47 @@
1
+ import { createRequire as __khalaCreateRequire } from 'node:module'; const require = __khalaCreateRequire(import.meta.url);
2
+ import {
3
+ decodeWith,
4
+ literal,
5
+ object,
6
+ readMatrixUserId,
7
+ version
8
+ } from "./chunk-N7B2VPDU.mjs";
9
+ import {
10
+ init_define_KHALA_BUNDLE
11
+ } from "./chunk-H3XIRV2S.mjs";
12
+
13
+ // ../contracts/src/m1/listening-mode.ts
14
+ init_define_KHALA_BUNDLE();
15
+ var LISTENING_MODES = ["steer", "sync", "async", "mute"];
16
+ function decodeListeningMode(input) {
17
+ return decodeWith(() => literal(input, "", LISTENING_MODES));
18
+ }
19
+ var LISTENING_MODE_COMMAND_TYPE = "com.khala.listening_mode.v1";
20
+ var LISTENING_MODE_MEMBER_KEY = "com.khala.listening_mode";
21
+ var DEFAULT_LISTENING_MODE = "sync";
22
+ function decodeListeningModeCommand(input) {
23
+ return decodeWith(() => {
24
+ const r = object(input, "", ["v", "agent", "mode"]);
25
+ return {
26
+ v: version(r.field("v"), r.at("v")),
27
+ agent: readMatrixUserId(r.field("agent"), r.at("agent")),
28
+ mode: literal(r.field("mode"), r.at("mode"), LISTENING_MODES)
29
+ };
30
+ });
31
+ }
32
+ function memberListeningMode(content) {
33
+ const value = typeof content === "object" && content !== null ? content[LISTENING_MODE_MEMBER_KEY] : void 0;
34
+ if (value === void 0) return DEFAULT_LISTENING_MODE;
35
+ const decoded = decodeListeningMode(value);
36
+ return decoded.ok ? decoded.value : "async";
37
+ }
38
+
39
+ export {
40
+ LISTENING_MODES,
41
+ decodeListeningMode,
42
+ LISTENING_MODE_COMMAND_TYPE,
43
+ LISTENING_MODE_MEMBER_KEY,
44
+ DEFAULT_LISTENING_MODE,
45
+ decodeListeningModeCommand,
46
+ memberListeningMode
47
+ };
@@ -1,18 +1,18 @@
1
1
  import { createRequire as __khalaCreateRequire } from 'node:module'; const require = __khalaCreateRequire(import.meta.url);
2
2
  import {
3
3
  retryUnexpired
4
- } from "./chunk-MRSZOWFU.mjs";
4
+ } from "./chunk-ZWDINIQJ.mjs";
5
5
  import {
6
6
  StateError,
7
7
  ensureStateDir,
8
8
  writeJsonAtomic
9
- } from "./chunk-NHW62KEB.mjs";
9
+ } from "./chunk-N7B2VPDU.mjs";
10
10
  import {
11
11
  __commonJS,
12
12
  __export,
13
13
  __toESM,
14
14
  init_define_KHALA_BUNDLE
15
- } from "./chunk-3JA3Q5MK.mjs";
15
+ } from "./chunk-H3XIRV2S.mjs";
16
16
 
17
17
  // ../../node_modules/.pnpm/immediate@3.3.0/node_modules/immediate/lib/nextTick.js
18
18
  var require_nextTick = __commonJS({
@@ -1,17 +1,17 @@
1
1
  import { createRequire as __khalaCreateRequire } from 'node:module'; const require = __khalaCreateRequire(import.meta.url);
2
2
  import {
3
3
  listChannels
4
- } from "./chunk-72W7IC2O.mjs";
4
+ } from "./chunk-RXM47OGD.mjs";
5
5
  import {
6
6
  TERMINAL_SESSION_DETAILS,
7
7
  cachedProcessReader,
8
8
  readStateFile,
9
9
  readStatus,
10
10
  validAgentRejoinSecret
11
- } from "./chunk-NHW62KEB.mjs";
11
+ } from "./chunk-N7B2VPDU.mjs";
12
12
  import {
13
13
  init_define_KHALA_BUNDLE
14
- } from "./chunk-3JA3Q5MK.mjs";
14
+ } from "./chunk-H3XIRV2S.mjs";
15
15
 
16
16
  // src/session-start-wake.ts
17
17
  init_define_KHALA_BUNDLE();
@@ -1,27 +1,27 @@
1
1
  import { createRequire as __khalaCreateRequire } from 'node:module'; const require = __khalaCreateRequire(import.meta.url);
2
2
  import {
3
3
  retryUnexpired
4
- } from "./chunk-MRSZOWFU.mjs";
4
+ } from "./chunk-ZWDINIQJ.mjs";
5
5
  import {
6
6
  RESTORE_HISTORY_MAX_PAGES
7
- } from "./chunk-JZZNVQKH.mjs";
8
- import "./chunk-P3XZEYZF.mjs";
7
+ } from "./chunk-HPZY6LHL.mjs";
8
+ import "./chunk-PIYD4WCN.mjs";
9
9
  import {
10
10
  LISTENING_MODE_COMMAND_TYPE,
11
11
  LISTENING_MODE_MEMBER_KEY,
12
12
  memberListeningMode
13
- } from "./chunk-I4POSYHZ.mjs";
13
+ } from "./chunk-VXHWS7JD.mjs";
14
14
  import {
15
15
  CHANNEL_EVENT_TYPE,
16
16
  encodeChannelEvent,
17
17
  memberRenameContent
18
- } from "./chunk-XI5FPUNN.mjs";
18
+ } from "./chunk-PFWYYXR5.mjs";
19
19
  import {
20
20
  StateError
21
- } from "./chunk-NHW62KEB.mjs";
21
+ } from "./chunk-N7B2VPDU.mjs";
22
22
  import {
23
23
  init_define_KHALA_BUNDLE
24
- } from "./chunk-3JA3Q5MK.mjs";
24
+ } from "./chunk-H3XIRV2S.mjs";
25
25
 
26
26
  // src/matrix/session.ts
27
27
  init_define_KHALA_BUNDLE();
@@ -59,7 +59,7 @@ async function createAgentMatrixSession(creds, opts) {
59
59
  const started = Date.now();
60
60
  const rejoinTxnId = `khala.rejoin.${randomUUID()}`;
61
61
  const log = (line) => opts?.log?.(line);
62
- const persistent = opts?.cryptoStore ? await (await import("./chunk-XRV5GUSI.mjs")).openCryptoStore(opts.cryptoStore.dir, opts.cryptoStore.root, creds) : void 0;
62
+ const persistent = opts?.cryptoStore ? await (await import("./chunk-W3LLNKEB.mjs")).openCryptoStore(opts.cryptoStore.dir, opts.cryptoStore.root, creds) : void 0;
63
63
  const client = createClient({ ...persistent ? { store: persistent.sync } : {}, baseUrl: creds.homeserver, userId: creds.userId, accessToken: creds.accessToken, deviceId: creds.deviceId });
64
64
  const handlers = /* @__PURE__ */ new Set();
65
65
  const ended = /* @__PURE__ */ new Set();
@@ -315,7 +315,7 @@ async function createAgentMatrixSession(creds, opts) {
315
315
  await client.initRustCrypto(persistent ? { useIndexedDB: true, cryptoDatabasePrefix: persistent.prefix } : { useIndexedDB: false });
316
316
  } catch (error) {
317
317
  if (!persistent?.restored || error instanceof StateError && error.code === "unsafe_state_dir") throw error;
318
- throw new (await import("./chunk-XRV5GUSI.mjs")).CryptoStoreCorruptError();
318
+ throw new (await import("./chunk-W3LLNKEB.mjs")).CryptoStoreCorruptError();
319
319
  }
320
320
  const crypto = client.getCrypto();
321
321
  if (!crypto) throw new Error("crypto_unavailable");
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __khalaCreateRequire } from 'node:module'; const require = __khalaCreateRequire(import.meta.url);
2
2
  import {
3
3
  init_define_KHALA_BUNDLE
4
- } from "./chunk-3JA3Q5MK.mjs";
4
+ } from "./chunk-H3XIRV2S.mjs";
5
5
 
6
6
  // src/matrix/decryption-retry.ts
7
7
  init_define_KHALA_BUNDLE();
package/dist/khala.mjs CHANGED
@@ -2,11 +2,11 @@
2
2
  import { createRequire as __khalaCreateRequire } from 'node:module'; const require = __khalaCreateRequire(import.meta.url);
3
3
  import {
4
4
  KHALA_AGENT_VERSION
5
- } from "./chunk-32SGUUP5.mjs";
6
- import "./chunk-RUQDE5DI.mjs";
5
+ } from "./chunk-U2OUPWUW.mjs";
6
+ import "./chunk-T3BRQFVF.mjs";
7
7
  import {
8
8
  init_define_KHALA_BUNDLE
9
- } from "./chunk-3JA3Q5MK.mjs";
9
+ } from "./chunk-H3XIRV2S.mjs";
10
10
 
11
11
  // src/cli-bundle.ts
12
12
  init_define_KHALA_BUNDLE();
@@ -84,15 +84,15 @@ async function runCli(argv, modules) {
84
84
 
85
85
  // src/cli-bundle.ts
86
86
  var hooks = {
87
- "session-start": () => import("./chunk-SUT7AKNZ.mjs"),
88
- deliver: () => import("./chunk-6DE4V756.mjs"),
89
- "claude-wake": () => import("./chunk-SKJ6YV3G.mjs")
87
+ "session-start": () => import("./chunk-P2S3OAZ5.mjs"),
88
+ deliver: () => import("./chunk-UBDI4XFO.mjs"),
89
+ "claude-wake": () => import("./chunk-PISWOM3Q.mjs")
90
90
  };
91
91
  process.exitCode = await runCli(process.argv.slice(2), {
92
- mcp: () => () => import("./chunk-JLENHMKE.mjs"),
93
- watch: () => () => import("./chunk-OIYAR2ND.mjs"),
94
- local: () => () => import("./chunk-3GUVMXTM.mjs"),
95
- install: () => () => import("./chunk-BWVC3EKG.mjs"),
96
- wake: () => () => import("./chunk-2BNIPJVW.mjs"),
92
+ mcp: () => () => import("./chunk-OPBOWFBB.mjs"),
93
+ watch: () => () => import("./chunk-RHAAMCRD.mjs"),
94
+ local: () => () => import("./chunk-QH5WZEIG.mjs"),
95
+ install: () => () => import("./chunk-QEIYPWN4.mjs"),
96
+ wake: () => () => import("./chunk-UQJHB4AH.mjs"),
97
97
  hook: (name) => Object.hasOwn(hooks, name) ? hooks[name] : void 0
98
98
  });