@holon-run/agentinbox 0.6.0 → 1.0.0-beta.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 (34) hide show
  1. package/README.md +32 -7
  2. package/dist/src/adapters.js +61 -6
  3. package/dist/src/backend.js +4 -16
  4. package/dist/src/cli.js +307 -53
  5. package/dist/src/client.js +2 -2
  6. package/dist/src/daemon.js +36 -2
  7. package/dist/src/http.js +467 -45
  8. package/dist/src/logging.js +112 -0
  9. package/dist/src/paths.js +1 -0
  10. package/dist/src/runtime_gate.js +394 -63
  11. package/dist/src/service.js +856 -154
  12. package/dist/src/source_hosts.js +75 -0
  13. package/dist/src/source_resolution.js +20 -20
  14. package/dist/src/source_schema.js +2 -2
  15. package/dist/src/sources/feishu.js +66 -28
  16. package/dist/src/sources/github.js +188 -24
  17. package/dist/src/sources/remote.js +44 -24
  18. package/dist/src/sources/{remote_profiles.js → remote_modules.js} +143 -58
  19. package/dist/src/store.js +861 -106
  20. package/dist/src/terminal.js +33 -7
  21. package/dist/src/util.js +46 -1
  22. package/drizzle/migrations/{0000_initial.sql → 0000_v1_initial.sql} +182 -6
  23. package/drizzle/schema.ts +93 -1
  24. package/package.json +2 -1
  25. package/scripts/iterm2_cursor_probe.py +8 -3
  26. package/scripts/release_smoke.sh +123 -0
  27. package/drizzle/migrations/0001_inbox_items_source_occurred_at_idx.sql +0 -3
  28. package/drizzle/migrations/0002_subscription_cleanup_policy.sql +0 -45
  29. package/drizzle/migrations/0003_subscription_lifecycle_retirements.sql +0 -14
  30. package/drizzle/migrations/0004_source_idle_states.sql +0 -10
  31. package/drizzle/migrations/0005_timers.sql +0 -22
  32. package/drizzle/migrations/0006_terminal_runtime_pid.sql +0 -1
  33. package/drizzle/migrations/0007_activation_dispatch_last_notified_fingerprint.sql +0 -2
  34. package/drizzle/migrations/0008_inbox_item_sequence.sql +0 -21
package/dist/src/cli.js CHANGED
@@ -12,6 +12,7 @@ const control_server_1 = require("./control_server");
12
12
  const current_agent_1 = require("./current_agent");
13
13
  const daemon_1 = require("./daemon");
14
14
  const http_1 = require("./http");
15
+ const logging_1 = require("./logging");
15
16
  const paths_1 = require("./paths");
16
17
  const service_1 = require("./service");
17
18
  const store_1 = require("./store");
@@ -50,14 +51,167 @@ async function main() {
50
51
  return;
51
52
  }
52
53
  const client = await createClient(normalized);
54
+ if (command === "host" && normalized[1] === "add") {
55
+ const [hostType, hostKey] = normalized.slice(2, 4);
56
+ if (!hostType || !hostKey) {
57
+ throw new Error("usage: agentinbox host add <hostType> <hostKey> [--config-json JSON] [--config-ref REF]");
58
+ }
59
+ await printRemote(client, "/hosts", {
60
+ hostType,
61
+ hostKey,
62
+ configRef: takeFlagValue(normalized, "--config-ref") ?? undefined,
63
+ config: (0, util_1.parseJsonArg)(takeFlagValue(normalized, "--config-json")),
64
+ });
65
+ return;
66
+ }
67
+ if (command === "host" && normalized[1] === "list") {
68
+ await printRemote(client, "/hosts", undefined, "GET");
69
+ return;
70
+ }
71
+ if (command === "host" && normalized[1] === "show") {
72
+ const hostId = normalized[2];
73
+ if (!hostId) {
74
+ throw new Error("usage: agentinbox host show <hostId>");
75
+ }
76
+ await printRemote(client, `/hosts/${encodeURIComponent(hostId)}`, undefined, "GET");
77
+ return;
78
+ }
79
+ if (command === "host" && normalized[1] === "schema") {
80
+ const hostId = normalized[2];
81
+ if (!hostId) {
82
+ throw new Error("usage: agentinbox host schema <hostId>");
83
+ }
84
+ await printRemote(client, `/hosts/${encodeURIComponent(hostId)}/schema`, undefined, "GET");
85
+ return;
86
+ }
87
+ if (command === "stream" && normalized[1] === "add") {
88
+ const [hostId, streamKind, streamKey] = normalized.slice(2, 5);
89
+ if (!hostId || !streamKind || !streamKey) {
90
+ throw new Error("usage: agentinbox stream add <hostId> <streamKind> <streamKey> [--config-json JSON] [--config-ref REF]");
91
+ }
92
+ await printRemote(client, "/streams", {
93
+ hostId,
94
+ streamKind,
95
+ streamKey,
96
+ configRef: takeFlagValue(normalized, "--config-ref") ?? undefined,
97
+ config: (0, util_1.parseJsonArg)(takeFlagValue(normalized, "--config-json")),
98
+ });
99
+ return;
100
+ }
101
+ if (command === "stream" && normalized[1] === "list") {
102
+ await printRemote(client, "/streams", undefined, "GET");
103
+ return;
104
+ }
105
+ if (command === "stream" && normalized[1] === "show") {
106
+ const streamId = normalized[2];
107
+ if (!streamId) {
108
+ throw new Error("usage: agentinbox stream show <streamId>");
109
+ }
110
+ await printRemote(client, `/streams/${encodeURIComponent(streamId)}`, undefined, "GET");
111
+ return;
112
+ }
113
+ if (command === "stream" && normalized[1] === "remove") {
114
+ const removeArgs = normalized.slice(2);
115
+ const positionals = positionalArgs(removeArgs, ["--with-subscriptions"]);
116
+ const streamId = positionals[0];
117
+ if (!streamId || positionals[1]) {
118
+ throw new Error("usage: agentinbox stream remove <streamId> [--with-subscriptions]");
119
+ }
120
+ const query = buildQuery({
121
+ with_subscriptions: hasFlag(normalized, "--with-subscriptions") ? "true" : undefined,
122
+ });
123
+ await printRemote(client, `/streams/${encodeURIComponent(streamId)}${query}`, undefined, "DELETE");
124
+ return;
125
+ }
126
+ if (command === "stream" && normalized[1] === "update") {
127
+ const streamId = normalized[2];
128
+ if (!streamId) {
129
+ throw new Error("usage: agentinbox stream update <streamId> [--config-json JSON] [--config-ref REF | --clear-config-ref]");
130
+ }
131
+ const configRef = takeFlagValue(normalized, "--config-ref");
132
+ const clearConfigRef = hasFlag(normalized, "--clear-config-ref");
133
+ const configJson = takeFlagValue(normalized, "--config-json");
134
+ if (configRef != null && clearConfigRef) {
135
+ throw new Error("stream update accepts only one of --config-ref or --clear-config-ref");
136
+ }
137
+ if (!clearConfigRef && configRef == null && configJson == null) {
138
+ throw new Error("usage: agentinbox stream update <streamId> [--config-json JSON] [--config-ref REF | --clear-config-ref]");
139
+ }
140
+ await printRemote(client, `/streams/${encodeURIComponent(streamId)}`, {
141
+ ...(clearConfigRef ? { configRef: null } : (configRef != null ? { configRef } : {})),
142
+ config: configJson != null ? (0, util_1.parseJsonArg)(configJson, "--config-json") : undefined,
143
+ }, "PATCH");
144
+ return;
145
+ }
146
+ if (command === "stream" && normalized[1] === "pause") {
147
+ const streamId = normalized[2];
148
+ if (!streamId) {
149
+ throw new Error("usage: agentinbox stream pause <streamId>");
150
+ }
151
+ await printRemote(client, `/streams/${encodeURIComponent(streamId)}/pause`, {});
152
+ return;
153
+ }
154
+ if (command === "stream" && normalized[1] === "resume") {
155
+ const streamId = normalized[2];
156
+ if (!streamId) {
157
+ throw new Error("usage: agentinbox stream resume <streamId>");
158
+ }
159
+ await printRemote(client, `/streams/${encodeURIComponent(streamId)}/resume`, {});
160
+ return;
161
+ }
162
+ if (command === "stream" && normalized[1] === "schema") {
163
+ if (normalized[2] === "preview") {
164
+ const sourceRef = normalized[3];
165
+ if (!sourceRef) {
166
+ throw new Error("usage: agentinbox stream schema preview <sourceKind|sourceType> [--config-json JSON] [--config-ref REF]");
167
+ }
168
+ await printRemote(client, "/streams/schema-preview", {
169
+ sourceRef,
170
+ configRef: takeFlagValue(normalized, "--config-ref") ?? undefined,
171
+ config: (0, util_1.parseJsonArg)(takeFlagValue(normalized, "--config-json")),
172
+ });
173
+ return;
174
+ }
175
+ const streamRef = normalized[2];
176
+ if (!streamRef) {
177
+ throw new Error("usage: agentinbox stream schema <streamId>");
178
+ }
179
+ await printRemote(client, `/streams/${encodeURIComponent(streamRef)}/schema`, undefined, "GET");
180
+ return;
181
+ }
182
+ if (command === "stream" && normalized[1] === "poll") {
183
+ const streamId = normalized[2];
184
+ if (!streamId) {
185
+ throw new Error("usage: agentinbox stream poll <streamId>");
186
+ }
187
+ await printRemote(client, `/streams/${encodeURIComponent(streamId)}/poll`, {});
188
+ return;
189
+ }
190
+ if (command === "stream" && normalized[1] === "event") {
191
+ const streamId = normalized[2];
192
+ const sourceNativeId = takeFlagValue(normalized, "--native-id");
193
+ const eventVariant = takeFlagValue(normalized, "--event");
194
+ if (!streamId || !sourceNativeId || !eventVariant) {
195
+ throw new Error("usage: agentinbox stream event <streamId> --native-id ID --event EVENT [--occurred-at ISO8601] [--metadata-json JSON] [--payload-json JSON]");
196
+ }
197
+ await printRemote(client, `/streams/${encodeURIComponent(streamId)}/events`, {
198
+ sourceNativeId,
199
+ eventVariant,
200
+ occurredAt: takeFlagValue(normalized, "--occurred-at") ?? undefined,
201
+ metadata: (0, util_1.parseJsonArg)(takeFlagValue(normalized, "--metadata-json")),
202
+ rawPayload: (0, util_1.parseJsonArg)(takeFlagValue(normalized, "--payload-json")),
203
+ });
204
+ return;
205
+ }
53
206
  if (command === "source" && normalized[1] === "add") {
54
- const [type, sourceKey] = normalized.slice(2, 4);
55
- if (!type || !sourceKey) {
56
- throw new Error("usage: agentinbox source add <type> <sourceKey> [--config-json JSON] [--config-ref REF]");
207
+ const [hostId, streamKind, streamKey] = normalized.slice(2, 5);
208
+ if (!hostId || !streamKind || !streamKey) {
209
+ throw new Error("usage: agentinbox source add <hostId> <streamKind> <streamKey> [--config-json JSON] [--config-ref REF]");
57
210
  }
58
211
  await printRemote(client, "/sources", {
59
- sourceType: type,
60
- sourceKey,
212
+ hostId,
213
+ streamKind,
214
+ streamKey,
61
215
  configRef: takeFlagValue(normalized, "--config-ref") ?? undefined,
62
216
  config: (0, util_1.parseJsonArg)(takeFlagValue(normalized, "--config-json")),
63
217
  });
@@ -125,27 +279,11 @@ async function main() {
125
279
  return;
126
280
  }
127
281
  if (command === "source" && normalized[1] === "schema") {
128
- if (normalized[2] === "preview") {
129
- const sourceRef = normalized[3];
130
- if (!sourceRef) {
131
- throw new Error("usage: agentinbox source schema preview <sourceKind|sourceType> [--config-json JSON] [--config-ref REF]");
132
- }
133
- await printRemote(client, "/sources/schema-preview", {
134
- sourceRef,
135
- configRef: takeFlagValue(normalized, "--config-ref") ?? undefined,
136
- config: (0, util_1.parseJsonArg)(takeFlagValue(normalized, "--config-json")),
137
- });
138
- return;
139
- }
140
282
  const sourceRef = normalized[2];
141
283
  if (!sourceRef) {
142
- throw new Error("usage: agentinbox source schema <sourceId|sourceType>");
143
- }
144
- if (sourceRef.startsWith("src_")) {
145
- await printRemote(client, `/sources/${encodeURIComponent(sourceRef)}/schema`, undefined, "GET");
146
- return;
284
+ throw new Error("usage: agentinbox source schema <sourceId>");
147
285
  }
148
- await printRemote(client, `/source-types/${encodeURIComponent(sourceRef)}/schema`, undefined, "GET");
286
+ await printRemote(client, `/sources/${encodeURIComponent(sourceRef)}/schema`, undefined, "GET");
149
287
  return;
150
288
  }
151
289
  if (command === "source" && normalized[1] === "poll") {
@@ -186,6 +324,7 @@ async function main() {
186
324
  termProgram: detected.termProgram ?? undefined,
187
325
  itermSessionId: detected.itermSessionId ?? undefined,
188
326
  notifyLeaseMs: parseOptionalNumber(takeFlagValue(normalized, "--notify-lease-ms")) ?? undefined,
327
+ minUnackedItems: parseOptionalNumber(takeFlagValue(normalized, "--min-unacked-items")) ?? undefined,
189
328
  });
190
329
  return;
191
330
  }
@@ -225,13 +364,14 @@ async function main() {
225
364
  const agentId = normalized[4];
226
365
  const url = takeFlagValue(normalized, "--url");
227
366
  if (!agentId || !url) {
228
- throw new Error("usage: agentinbox agent target add webhook <agentId> --url URL [--activation-mode MODE] [--notify-lease-ms N]");
367
+ throw new Error("usage: agentinbox agent target add webhook <agentId> --url URL [--activation-mode MODE] [--notify-lease-ms N] [--min-unacked-items N]");
229
368
  }
230
369
  await printRemote(client, `/agents/${encodeURIComponent(agentId)}/targets`, {
231
370
  kind: "webhook",
232
371
  url,
233
372
  activationMode: takeFlagValue(normalized, "--activation-mode") ?? undefined,
234
373
  notifyLeaseMs: parseOptionalNumber(takeFlagValue(normalized, "--notify-lease-ms")) ?? undefined,
374
+ minUnackedItems: parseOptionalNumber(takeFlagValue(normalized, "--min-unacked-items")) ?? undefined,
235
375
  });
236
376
  return;
237
377
  }
@@ -431,19 +571,19 @@ async function main() {
431
571
  }
432
572
  if (command === "inbox" && normalized[1] === "read") {
433
573
  const args = normalized.slice(2);
434
- const allowedFlags = ["--agent-id", "--after-item", "--include-acked"];
435
- if (positionalArgs(args, ["--agent-id", "--after-item"]).length > 0 || unexpectedFlags(args, allowedFlags).length > 0) {
436
- throw new Error("usage: agentinbox inbox read [--agent-id ID] [--after-item ID] [--include-acked]");
574
+ const allowedFlags = ["--agent-id", "--after-entry", "--include-acked"];
575
+ if (positionalArgs(args, ["--agent-id", "--after-entry"]).length > 0 || unexpectedFlags(args, allowedFlags).length > 0) {
576
+ throw new Error("usage: agentinbox inbox read [--agent-id ID] [--after-entry ID] [--include-acked]");
437
577
  }
438
578
  const selection = await selectAgentForCommand(client, {
439
579
  explicitAgentId: takeFlagValue(normalized, "--agent-id"),
440
580
  autoRegister: true,
441
581
  });
442
582
  const query = buildQuery({
443
- after_item_id: takeFlagValue(normalized, "--after-item"),
583
+ after_entry_id: takeFlagValue(normalized, "--after-entry"),
444
584
  include_acked: hasFlag(normalized, "--include-acked") ? "true" : undefined,
445
585
  });
446
- const response = await requestRemote(client, `/agents/${encodeURIComponent(selection.agentId)}/inbox/items${query}`, undefined, "GET");
586
+ const response = await requestRemote(client, `/agents/${encodeURIComponent(selection.agentId)}/inbox/entries${query}`, undefined, "GET");
447
587
  console.log((0, util_1.jsonResponse)(withCommandMetadata(response.data, selection)));
448
588
  return;
449
589
  }
@@ -466,8 +606,8 @@ async function main() {
466
606
  }
467
607
  if (command === "inbox" && normalized[1] === "watch") {
468
608
  const args = normalized.slice(2);
469
- if (positionalArgs(args, ["--agent-id", "--after-item", "--heartbeat-ms"]).length > 0) {
470
- throw new Error("usage: agentinbox inbox watch [--agent-id ID] [--after-item ID] [--include-acked] [--heartbeat-ms N]");
609
+ if (positionalArgs(args, ["--agent-id", "--after-entry", "--heartbeat-ms"]).length > 0) {
610
+ throw new Error("usage: agentinbox inbox watch [--agent-id ID] [--after-entry ID] [--include-acked] [--heartbeat-ms N]");
471
611
  }
472
612
  const selection = await selectAgentForCommand(client, {
473
613
  explicitAgentId: takeFlagValue(normalized, "--agent-id"),
@@ -480,7 +620,7 @@ async function main() {
480
620
  console.log((0, util_1.jsonResponse)(metadata));
481
621
  }
482
622
  for await (const event of client.watchInbox(selection.agentId, {
483
- afterItemId: takeFlagValue(normalized, "--after-item"),
623
+ afterEntryId: takeFlagValue(normalized, "--after-entry"),
484
624
  includeAcked: hasFlag(normalized, "--include-acked"),
485
625
  heartbeatMs: parseOptionalNumber(takeFlagValue(normalized, "--heartbeat-ms")),
486
626
  })) {
@@ -493,18 +633,41 @@ async function main() {
493
633
  }
494
634
  if (command === "inbox" && normalized[1] === "ack") {
495
635
  const args = normalized.slice(2);
496
- const itemId = takeFlagValue(normalized, "--item");
497
- const throughItemId = takeFlagValue(normalized, "--through");
636
+ const itemId = takeFlagValue(normalized, "--entry");
637
+ const throughEntryId = takeFlagValue(normalized, "--through");
498
638
  const ackAll = hasFlag(normalized, "--all");
499
- const modeCount = Number(Boolean(itemId)) + Number(Boolean(throughItemId)) + Number(ackAll);
500
- if (positionalArgs(args, ["--agent-id", "--item", "--through"]).length > 0 || modeCount !== 1) {
501
- throw new Error("usage: agentinbox inbox ack [--agent-id ID] (--through <itemId> | --item <itemId> | --all)");
639
+ const modeCount = Number(Boolean(itemId)) + Number(Boolean(throughEntryId)) + Number(ackAll);
640
+ if (positionalArgs(args, ["--agent-id", "--entry", "--through"]).length > 0 || modeCount !== 1) {
641
+ throw new Error("usage: agentinbox inbox ack [--agent-id ID] (--through <entryId> | --entry <entryId> | --all)");
502
642
  }
503
643
  const selection = await selectAgentForCommand(client, {
504
644
  explicitAgentId: takeFlagValue(normalized, "--agent-id"),
505
645
  autoRegister: true,
506
646
  });
507
- const response = await requestRemote(client, `/agents/${encodeURIComponent(selection.agentId)}/inbox/ack`, ackAll ? { all: true } : (throughItemId ? { throughItemId } : { itemIds: [itemId] }));
647
+ const response = await requestRemote(client, `/agents/${encodeURIComponent(selection.agentId)}/inbox/ack`, ackAll ? { all: true } : (throughEntryId ? { throughEntryId } : { entryIds: [itemId] }));
648
+ console.log((0, util_1.jsonResponse)(withCommandMetadata(response.data, selection)));
649
+ return;
650
+ }
651
+ if (command === "inbox" && normalized[1] === "policy" && normalized[2] === "show") {
652
+ const selection = await selectAgentForCommand(client, {
653
+ explicitAgentId: takeFlagValue(normalized, "--agent-id"),
654
+ autoRegister: true,
655
+ });
656
+ const response = await requestRemote(client, `/agents/${encodeURIComponent(selection.agentId)}/inbox/policy`, undefined, "GET");
657
+ console.log((0, util_1.jsonResponse)(withCommandMetadata(response.data, selection)));
658
+ return;
659
+ }
660
+ if (command === "inbox" && normalized[1] === "policy" && normalized[2] === "set") {
661
+ const selection = await selectAgentForCommand(client, {
662
+ explicitAgentId: takeFlagValue(normalized, "--agent-id"),
663
+ autoRegister: true,
664
+ });
665
+ const response = await requestRemote(client, `/agents/${encodeURIComponent(selection.agentId)}/inbox/policy`, {
666
+ enabled: hasFlag(normalized, "--enabled") ? true : (hasFlag(normalized, "--disabled") ? false : undefined),
667
+ windowMs: parseOptionalNumber(takeFlagValue(normalized, "--window-ms")),
668
+ maxItems: parseOptionalNumber(takeFlagValue(normalized, "--max-items")),
669
+ maxThreadAgeMs: parseOptionalNumber(takeFlagValue(normalized, "--max-thread-age-ms")),
670
+ });
508
671
  console.log((0, util_1.jsonResponse)(withCommandMetadata(response.data, selection)));
509
672
  return;
510
673
  }
@@ -526,9 +689,10 @@ async function main() {
526
689
  const targetRef = takeFlagValue(normalized, "--target");
527
690
  const kind = takeFlagValue(normalized, "--kind") ?? "reply";
528
691
  if (!provider || !surface || !targetRef) {
529
- throw new Error("usage: agentinbox deliver send --provider PROVIDER --surface SURFACE --target TARGET [--kind KIND] [--payload-json JSON]");
692
+ throw new Error("usage: agentinbox deliver send --provider PROVIDER --surface SURFACE --target TARGET [--source-id SOURCE_ID] [--kind KIND] [--payload-json JSON]");
530
693
  }
531
694
  await printRemote(client, "/deliveries/send", {
695
+ sourceId: takeFlagValue(normalized, "--source-id") ?? undefined,
532
696
  provider,
533
697
  surface,
534
698
  targetRef,
@@ -539,6 +703,58 @@ async function main() {
539
703
  });
540
704
  return;
541
705
  }
706
+ if (command === "deliver" && normalized[1] === "actions") {
707
+ const provider = takeFlagValue(normalized, "--provider");
708
+ const surface = takeFlagValue(normalized, "--surface");
709
+ const targetRef = takeFlagValue(normalized, "--target");
710
+ const handleJson = takeFlagValue(normalized, "--handle-json");
711
+ if (!handleJson && (!provider || !surface || !targetRef)) {
712
+ throw new Error("usage: agentinbox deliver actions (--handle-json JSON | --provider PROVIDER --surface SURFACE --target TARGET) [--source-id SOURCE_ID]");
713
+ }
714
+ await printRemote(client, "/deliveries/actions", handleJson
715
+ ? {
716
+ sourceId: takeFlagValue(normalized, "--source-id") ?? undefined,
717
+ deliveryHandle: (0, util_1.parseJsonArg)(handleJson),
718
+ }
719
+ : {
720
+ sourceId: takeFlagValue(normalized, "--source-id") ?? undefined,
721
+ provider,
722
+ surface,
723
+ targetRef,
724
+ threadRef: takeFlagValue(normalized, "--thread") ?? undefined,
725
+ replyMode: takeFlagValue(normalized, "--reply-mode") ?? undefined,
726
+ });
727
+ return;
728
+ }
729
+ if (command === "deliver" && normalized[1] === "invoke") {
730
+ const provider = takeFlagValue(normalized, "--provider");
731
+ const surface = takeFlagValue(normalized, "--surface");
732
+ const targetRef = takeFlagValue(normalized, "--target");
733
+ const handleJson = takeFlagValue(normalized, "--handle-json");
734
+ const operation = takeFlagValue(normalized, "--operation");
735
+ const inputJson = takeFlagValue(normalized, "--input-json");
736
+ if (!operation || !inputJson || (!handleJson && (!provider || !surface || !targetRef))) {
737
+ throw new Error("usage: agentinbox deliver invoke (--handle-json JSON | --provider PROVIDER --surface SURFACE --target TARGET) --operation NAME --input-json JSON [--source-id SOURCE_ID]");
738
+ }
739
+ await printRemote(client, "/deliveries/invoke", handleJson
740
+ ? {
741
+ sourceId: takeFlagValue(normalized, "--source-id") ?? undefined,
742
+ deliveryHandle: (0, util_1.parseJsonArg)(handleJson),
743
+ operation,
744
+ input: (0, util_1.parseJsonArg)(inputJson, "--input-json"),
745
+ }
746
+ : {
747
+ sourceId: takeFlagValue(normalized, "--source-id") ?? undefined,
748
+ provider,
749
+ surface,
750
+ targetRef,
751
+ threadRef: takeFlagValue(normalized, "--thread") ?? undefined,
752
+ replyMode: takeFlagValue(normalized, "--reply-mode") ?? undefined,
753
+ operation,
754
+ input: (0, util_1.parseJsonArg)(inputJson, "--input-json"),
755
+ });
756
+ return;
757
+ }
542
758
  if (command === "status") {
543
759
  await printRemote(client, "/status", undefined, "GET");
544
760
  return;
@@ -555,27 +771,37 @@ async function main() {
555
771
  }
556
772
  async function runServe(args) {
557
773
  const port = parseOptionalNumber(takeFlagValue(args, "--port"));
774
+ const homeOverride = takeFlagValue(args, "--home");
558
775
  const serveConfig = (0, paths_1.resolveServeConfig)({
559
776
  env: process.env,
560
- homeDirOverride: takeFlagValue(args, "--home"),
777
+ homeDirOverride: homeOverride,
561
778
  statePathOverride: takeFlagValue(args, "--state"),
562
779
  socketPathOverride: takeFlagValue(args, "--socket"),
563
780
  portOverride: port,
564
781
  });
782
+ const daemonPaths = (0, paths_1.resolveDaemonPaths)(process.env, homeOverride);
783
+ const logLevel = (0, logging_1.parseLogLevel)(takeFlagValue(args, "--log-level") ?? process.env.AGENTINBOX_LOG_LEVEL);
784
+ const logger = new logging_1.JsonLogger(logLevel, "agentinbox");
565
785
  const store = await store_1.AgentInboxStore.open(serveConfig.dbPath);
566
786
  let service;
567
787
  const adapters = new adapters_1.AdapterRegistry(store, async (input) => service.appendSourceEvent(input), {
568
788
  homeDir: serveConfig.homeDir,
569
789
  });
570
- service = new service_1.AgentInboxService(store, adapters);
790
+ service = new service_1.AgentInboxService(store, adapters, undefined, undefined, undefined, undefined, undefined, logger.child("service"));
571
791
  const server = (0, http_1.createServer)(service);
572
792
  await adapters.start();
573
793
  await service.start();
574
794
  const controlServer = await (0, control_server_1.startControlServer)(server, serveConfig.transport);
575
- const daemonPaths = (0, paths_1.resolveDaemonPaths)(process.env, takeFlagValue(args, "--home"));
576
795
  if (serveConfig.transport.kind === "socket") {
577
796
  (0, daemon_1.writePidFile)(daemonPaths.pidPath, process.pid);
578
797
  }
798
+ (0, daemon_1.writeDaemonMetadata)(daemonPaths.metadataPath, { logLevel });
799
+ logger.info("daemon.ready", {
800
+ homeDir: serveConfig.homeDir,
801
+ dbPath: serveConfig.dbPath,
802
+ transport: controlServer.info,
803
+ logLevel,
804
+ });
579
805
  console.log((0, util_1.jsonResponse)({
580
806
  ok: true,
581
807
  homeDir: serveConfig.homeDir,
@@ -590,6 +816,7 @@ async function runServe(args) {
590
816
  if (serveConfig.transport.kind === "socket") {
591
817
  (0, daemon_1.removePidFile)(daemonPaths.pidPath);
592
818
  }
819
+ (0, daemon_1.removePidFile)(daemonPaths.metadataPath);
593
820
  process.exit(0);
594
821
  });
595
822
  };
@@ -603,6 +830,7 @@ async function runDaemon(args) {
603
830
  homeDirOverride: takeFlagValue(args, "--home"),
604
831
  socketPathOverride: takeFlagValue(args, "--socket"),
605
832
  baseUrlOverride: takeFlagValue(args, "--url"),
833
+ logLevelOverride: (0, logging_1.parseLogLevel)(takeFlagValue(args, "--log-level") ?? process.env.AGENTINBOX_LOG_LEVEL),
606
834
  };
607
835
  if (action === "start") {
608
836
  const result = await (0, daemon_1.startDaemon)(options);
@@ -888,41 +1116,63 @@ Commands:
888
1116
  serve: `agentinbox serve
889
1117
 
890
1118
  Usage:
891
- agentinbox serve [--home ~/.agentinbox] [--socket ~/.agentinbox/agentinbox.sock]
1119
+ agentinbox serve [--home ~/.agentinbox] [--socket ~/.agentinbox/agentinbox.sock] [--log-level error|warn|info|debug|trace]
892
1120
  agentinbox serve --port 4747 [--state ~/.agentinbox/agentinbox.sqlite]
893
1121
  `,
894
1122
  daemon: `agentinbox daemon
895
1123
 
896
1124
  Usage:
897
- agentinbox daemon start [--home ~/.agentinbox] [--socket ~/.agentinbox/agentinbox.sock]
1125
+ agentinbox daemon start [--home ~/.agentinbox] [--socket ~/.agentinbox/agentinbox.sock] [--log-level error|warn|info|debug|trace]
898
1126
  agentinbox daemon stop [--home ~/.agentinbox] [--socket ~/.agentinbox/agentinbox.sock]
899
1127
  agentinbox daemon status [--home ~/.agentinbox] [--socket ~/.agentinbox/agentinbox.sock]
1128
+ `,
1129
+ host: `agentinbox host
1130
+
1131
+ Usage:
1132
+ agentinbox host add <hostType> <hostKey> [--config-json JSON] [--config-ref REF]
1133
+ agentinbox host list
1134
+ agentinbox host show <hostId>
1135
+ agentinbox host schema <hostId>
1136
+ `,
1137
+ stream: `agentinbox stream
1138
+
1139
+ Usage:
1140
+ agentinbox stream add <hostId> <streamKind> <streamKey> [--config-json JSON] [--config-ref REF]
1141
+ agentinbox stream list
1142
+ agentinbox stream show <streamId>
1143
+ agentinbox stream update <streamId> [--config-json JSON] [--config-ref REF | --clear-config-ref]
1144
+ agentinbox stream remove <streamId> [--with-subscriptions]
1145
+ agentinbox stream pause <streamId>
1146
+ agentinbox stream resume <streamId>
1147
+ agentinbox stream schema <streamId>
1148
+ agentinbox stream schema preview <sourceKind|sourceType> [--config-json JSON] [--config-ref REF]
1149
+ agentinbox stream poll <streamId>
1150
+ agentinbox stream event <streamId> --native-id ID --event EVENT [--occurred-at ISO8601] [--metadata-json JSON] [--payload-json JSON]
900
1151
  `,
901
1152
  source: `agentinbox source
902
1153
 
903
1154
  Usage:
904
- agentinbox source add <type> <sourceKey> [--config-json JSON] [--config-ref REF]
1155
+ agentinbox source add <hostId> <streamKind> <streamKey> [--config-json JSON] [--config-ref REF]
905
1156
  agentinbox source list
906
1157
  agentinbox source show <sourceId>
907
1158
  agentinbox source update <sourceId> [--config-json JSON] [--config-ref REF | --clear-config-ref]
908
1159
  agentinbox source remove <sourceId> [--with-subscriptions]
909
1160
  agentinbox source pause <remoteSourceId>
910
1161
  agentinbox source resume <remoteSourceId>
911
- agentinbox source schema <sourceId|sourceType>
912
- agentinbox source schema preview <sourceKind|sourceType> [--config-json JSON] [--config-ref REF]
1162
+ agentinbox source schema <sourceId>
913
1163
  agentinbox source poll <sourceId>
914
1164
  agentinbox source event <sourceId> --native-id ID --event EVENT [--occurred-at ISO8601] [--metadata-json JSON] [--payload-json JSON]
915
1165
  `,
916
1166
  agent: `agentinbox agent
917
1167
 
918
1168
  Usage:
919
- agentinbox agent register [--agent-id ID] [--force-rebind] [--notify-lease-ms N]
1169
+ agentinbox agent register [--agent-id ID] [--force-rebind] [--notify-lease-ms N] [--min-unacked-items N]
920
1170
  agentinbox agent list
921
1171
  agentinbox agent current
922
1172
  agentinbox agent show <agentId>
923
1173
  agentinbox agent remove <agentId>
924
1174
  agentinbox agent resume <agentId>
925
- agentinbox agent target add webhook <agentId> --url URL [--activation-mode MODE] [--notify-lease-ms N]
1175
+ agentinbox agent target add webhook <agentId> --url URL [--activation-mode MODE] [--notify-lease-ms N] [--min-unacked-items N]
926
1176
  agentinbox agent target list <agentId>
927
1177
  agentinbox agent target remove <agentId> <targetId>
928
1178
  agentinbox agent target resume <agentId> <targetId>
@@ -952,16 +1202,20 @@ Usage:
952
1202
  Usage:
953
1203
  agentinbox inbox list
954
1204
  agentinbox inbox show <agentId>
955
- agentinbox inbox read [--agent-id ID] [--after-item ID] [--include-acked]
1205
+ agentinbox inbox read [--agent-id ID] [--after-entry ID] [--include-acked]
956
1206
  agentinbox inbox send --agent-id ID --message TEXT [--sender SENDER]
957
- agentinbox inbox watch [--agent-id ID] [--after-item ID] [--include-acked] [--heartbeat-ms N]
958
- agentinbox inbox ack [--agent-id ID] (--through <itemId> | --item <itemId> | --all)
1207
+ agentinbox inbox watch [--agent-id ID] [--after-entry ID] [--include-acked] [--heartbeat-ms N]
1208
+ agentinbox inbox ack [--agent-id ID] (--through <entryId> | --entry <entryId> | --all)
1209
+ agentinbox inbox policy show [--agent-id ID]
1210
+ agentinbox inbox policy set [--agent-id ID] [--enabled|--disabled] [--window-ms N] [--max-items N] [--max-thread-age-ms N]
959
1211
  agentinbox inbox compact <agentId>
960
1212
  `,
961
1213
  deliver: `agentinbox deliver
962
1214
 
963
1215
  Usage:
964
- agentinbox deliver send --provider PROVIDER --surface SURFACE --target TARGET [--kind KIND] [--payload-json JSON]
1216
+ agentinbox deliver send --provider PROVIDER --surface SURFACE --target TARGET [--source-id SOURCE_ID] [--kind KIND] [--payload-json JSON]
1217
+ agentinbox deliver actions (--handle-json JSON | --provider PROVIDER --surface SURFACE --target TARGET) [--source-id SOURCE_ID]
1218
+ agentinbox deliver invoke (--handle-json JSON | --provider PROVIDER --surface SURFACE --target TARGET) --operation NAME --input-json JSON [--source-id SOURCE_ID]
965
1219
  `,
966
1220
  status: `agentinbox status
967
1221
 
@@ -19,8 +19,8 @@ class AgentInboxClient {
19
19
  }
20
20
  watchInbox(agentId, options = {}) {
21
21
  const query = new URLSearchParams();
22
- if (options.afterItemId) {
23
- query.set("after_item_id", options.afterItemId);
22
+ if (options.afterEntryId) {
23
+ query.set("after_entry_id", options.afterEntryId);
24
24
  }
25
25
  if (options.includeAcked) {
26
26
  query.set("include_acked", "true");