@agentmonitors/cli 0.3.0 → 0.3.2

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.
package/dist/index.cjs CHANGED
@@ -33,10 +33,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
33
33
  mod
34
34
  ));
35
35
 
36
- // ../../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.57.7_@types+node@22.19.15__postcss@8.5.8_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/cjs_shims.js
36
+ // ../../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.57.7_@types+node@22.19.15__jiti@2.7.0_postcss@8.5.8_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/cjs_shims.js
37
37
  var getImportMetaUrl, importMetaUrl;
38
38
  var init_cjs_shims = __esm({
39
- "../../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.57.7_@types+node@22.19.15__postcss@8.5.8_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/cjs_shims.js"() {
39
+ "../../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.57.7_@types+node@22.19.15__jiti@2.7.0_postcss@8.5.8_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/cjs_shims.js"() {
40
40
  "use strict";
41
41
  getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
42
42
  importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
@@ -13851,6 +13851,9 @@ var require_dist = __commonJS({
13851
13851
 
13852
13852
  // src/index.ts
13853
13853
  init_cjs_shims();
13854
+ var import_node_fs6 = require("fs");
13855
+ var import_node_path9 = require("path");
13856
+ var import_node_url4 = require("url");
13854
13857
 
13855
13858
  // ../../node_modules/.pnpm/commander@14.0.3/node_modules/commander/esm.mjs
13856
13859
  init_cjs_shims();
@@ -26276,7 +26279,7 @@ function sql(strings, ...params) {
26276
26279
  return new SQL([new StringChunk(str2)]);
26277
26280
  }
26278
26281
  sql2.raw = raw;
26279
- function join(chunks, separator) {
26282
+ function join2(chunks, separator) {
26280
26283
  const result = [];
26281
26284
  for (const [i, chunk] of chunks.entries()) {
26282
26285
  if (i > 0 && separator !== void 0) {
@@ -26286,7 +26289,7 @@ function sql(strings, ...params) {
26286
26289
  }
26287
26290
  return new SQL(result);
26288
26291
  }
26289
- sql2.join = join;
26292
+ sql2.join = join2;
26290
26293
  function identifier(value) {
26291
26294
  return new Name(value);
26292
26295
  }
@@ -28734,7 +28737,7 @@ var SQLiteSelectQueryBuilderBase = class extends TypedQueryBuilder {
28734
28737
  const baseTableName = this.tableName;
28735
28738
  const tableName = getTableLikeName(table);
28736
28739
  for (const item of extractUsedTable(table)) this.usedTables.add(item);
28737
- if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) {
28740
+ if (typeof tableName === "string" && this.config.joins?.some((join2) => join2.alias === tableName)) {
28738
28741
  throw new Error(`Alias "${tableName}" is already used in this query`);
28739
28742
  }
28740
28743
  if (!this.isPartialSelect) {
@@ -29594,7 +29597,7 @@ var SQLiteUpdateBase = class extends QueryPromise {
29594
29597
  createJoin(joinType) {
29595
29598
  return (table, on) => {
29596
29599
  const tableName = getTableLikeName(table);
29597
- if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) {
29600
+ if (typeof tableName === "string" && this.config.joins.some((join2) => join2.alias === tableName)) {
29598
29601
  throw new Error(`Alias "${tableName}" is already used in this query`);
29599
29602
  }
29600
29603
  if (typeof on === "function") {
@@ -34566,6 +34569,96 @@ function spawnDetachedDaemon(options2) {
34566
34569
  child.unref();
34567
34570
  }
34568
34571
 
34572
+ // src/hook-payload.ts
34573
+ init_cjs_shims();
34574
+ async function readHookPayload() {
34575
+ const stdin = process.stdin;
34576
+ if (stdin.isTTY) return {};
34577
+ const raw = await new Promise((resolve) => {
34578
+ let data = "";
34579
+ let settled = false;
34580
+ const finish = () => {
34581
+ if (settled) return;
34582
+ settled = true;
34583
+ resolve(data);
34584
+ };
34585
+ stdin.setEncoding("utf8");
34586
+ stdin.on("data", (chunk) => {
34587
+ data += chunk;
34588
+ });
34589
+ stdin.on("end", finish);
34590
+ stdin.on("error", finish);
34591
+ });
34592
+ const trimmed = raw.trim();
34593
+ if (trimmed === "") return {};
34594
+ try {
34595
+ const parsed = JSON.parse(trimmed);
34596
+ if (typeof parsed !== "object" || parsed === null) return {};
34597
+ const record2 = parsed;
34598
+ const pickString = (key) => {
34599
+ const value = record2[key];
34600
+ return typeof value === "string" ? value : void 0;
34601
+ };
34602
+ const payload = {};
34603
+ const sessionId = pickString("session_id");
34604
+ if (sessionId !== void 0) payload.session_id = sessionId;
34605
+ const eventName = pickString("hook_event_name");
34606
+ if (eventName !== void 0) payload.hook_event_name = eventName;
34607
+ const cwd = pickString("cwd");
34608
+ if (cwd !== void 0) payload.cwd = cwd;
34609
+ return payload;
34610
+ } catch {
34611
+ return {};
34612
+ }
34613
+ }
34614
+
34615
+ // src/hook-deliver-render.ts
34616
+ init_cjs_shims();
34617
+ var MAX_ADDITIONAL_CONTEXT = 4e3;
34618
+ var TRUNCATION_MARKER = "\n\n[truncated \u2014 more monitor updates are pending; run `agentmonitors events list --unread` to see the rest]";
34619
+ function sanitize(value) {
34620
+ let out = "";
34621
+ for (const ch of value) {
34622
+ const code = ch.codePointAt(0) ?? 0;
34623
+ const isControl = code < 32 && ch !== "\n" && ch !== " " || code >= 127 && code <= 159;
34624
+ if (!isControl) out += ch;
34625
+ }
34626
+ return out;
34627
+ }
34628
+ function truncateForCap(value, cap) {
34629
+ if (value.length <= cap) return value;
34630
+ const budget = Math.max(0, cap - TRUNCATION_MARKER.length);
34631
+ let out = "";
34632
+ for (const ch of value) {
34633
+ if (out.length + ch.length > budget) break;
34634
+ out += ch;
34635
+ }
34636
+ return out + TRUNCATION_MARKER;
34637
+ }
34638
+ function renderHookDelivery(claim, hookEventName) {
34639
+ if (!claim || claim.events.length === 0) return null;
34640
+ const leadLine = "AgentMon: monitored changes are pending \u2014 consider handling them before continuing.";
34641
+ const blocks = claim.events.map((e) => {
34642
+ const id = sanitize(e.monitorId);
34643
+ const urgency = sanitize(e.urgency);
34644
+ const title = sanitize(e.title);
34645
+ const body = sanitize(e.body);
34646
+ return `### ${id} (${urgency})
34647
+ ${title}
34648
+
34649
+ ${body}`;
34650
+ });
34651
+ const full = [leadLine, "", ...blocks].join("\n");
34652
+ const additionalContext = truncateForCap(full, MAX_ADDITIONAL_CONTEXT);
34653
+ return {
34654
+ continue: true,
34655
+ hookSpecificOutput: {
34656
+ hookEventName,
34657
+ additionalContext
34658
+ }
34659
+ };
34660
+ }
34661
+
34569
34662
  // src/commands/session.ts
34570
34663
  var sessionCommand = new Command("session").description(
34571
34664
  "Manage agent sessions tracked by AgentMon"
@@ -34641,9 +34734,10 @@ sessionCommand.command("list").description("List known agent sessions").option("
34641
34734
  sessionCommand.command("start").description(
34642
34735
  "Lazy-boot the project daemon (if needed) and register this session"
34643
34736
  ).action(async () => {
34644
- const workspacePath = process.env["CLAUDE_PROJECT_DIR"] ?? process.cwd();
34645
- const hostSessionId = process.env["CLAUDE_CODE_SESSION_ID"];
34737
+ const payload = await readHookPayload();
34738
+ const hostSessionId = payload.session_id;
34646
34739
  if (!hostSessionId) return;
34740
+ const workspacePath = payload.cwd ?? process.env["CLAUDE_PROJECT_DIR"] ?? process.cwd();
34647
34741
  const state = readLocalState(workspacePath);
34648
34742
  if (!state.enabled) return;
34649
34743
  const paths = workspacePaths(workspacePath);
@@ -34674,22 +34768,32 @@ sessionCommand.command("start").description(
34674
34768
  }
34675
34769
  writeLocalState(workspacePath, { ...state, socket, db });
34676
34770
  try {
34677
- await openSessionClient(
34771
+ const opened = await openSessionClient(
34678
34772
  claudeCodeAdapter.createSessionInput({
34679
34773
  hostSessionId,
34680
34774
  workspacePath
34681
34775
  }),
34682
34776
  socket
34683
34777
  );
34778
+ const claim = await claimDeliveryClient(
34779
+ opened.id,
34780
+ "post-compact",
34781
+ socket
34782
+ );
34783
+ const delivery = renderHookDelivery(claim, "SessionStart");
34784
+ if (delivery !== null) {
34785
+ process.stdout.write(JSON.stringify(delivery));
34786
+ }
34684
34787
  } catch (error2) {
34685
34788
  const message = error2 instanceof Error ? error2.message : String(error2);
34686
34789
  reportError(message, false);
34687
34790
  }
34688
34791
  });
34689
34792
  sessionCommand.command("end").description("Deregister this session (lets the idle daemon reap itself)").action(async () => {
34690
- const workspacePath = process.env["CLAUDE_PROJECT_DIR"] ?? process.cwd();
34691
- const hostSessionId = process.env["CLAUDE_CODE_SESSION_ID"];
34793
+ const payload = await readHookPayload();
34794
+ const hostSessionId = payload.session_id;
34692
34795
  if (!hostSessionId) return;
34796
+ const workspacePath = payload.cwd ?? process.env["CLAUDE_PROJECT_DIR"] ?? process.cwd();
34693
34797
  const state = readLocalState(workspacePath);
34694
34798
  if (!state.enabled || !state.socket) return;
34695
34799
  const socket = resolveSocketPath(state.socket);
@@ -34774,55 +34878,6 @@ eventsCommand.command("ack").description("Acknowledge one or more events for a s
34774
34878
 
34775
34879
  // src/commands/hook.ts
34776
34880
  init_cjs_shims();
34777
-
34778
- // src/hook-deliver-render.ts
34779
- init_cjs_shims();
34780
- var MAX_ADDITIONAL_CONTEXT = 4e3;
34781
- var TRUNCATION_MARKER = "\n\n[truncated \u2014 more monitor updates are pending; run `agentmonitors events list --unread` to see the rest]";
34782
- function sanitize(value) {
34783
- let out = "";
34784
- for (const ch of value) {
34785
- const code = ch.codePointAt(0) ?? 0;
34786
- const isControl = code < 32 && ch !== "\n" && ch !== " " || code >= 127 && code <= 159;
34787
- if (!isControl) out += ch;
34788
- }
34789
- return out;
34790
- }
34791
- function truncateForCap(value, cap) {
34792
- if (value.length <= cap) return value;
34793
- const budget = Math.max(0, cap - TRUNCATION_MARKER.length);
34794
- let out = "";
34795
- for (const ch of value) {
34796
- if (out.length + ch.length > budget) break;
34797
- out += ch;
34798
- }
34799
- return out + TRUNCATION_MARKER;
34800
- }
34801
- function renderHookDelivery(claim, hookEventName) {
34802
- if (!claim || claim.events.length === 0) return null;
34803
- const leadLine = "AgentMon: monitored changes are pending \u2014 consider handling them before continuing.";
34804
- const blocks = claim.events.map((e) => {
34805
- const id = sanitize(e.monitorId);
34806
- const urgency = sanitize(e.urgency);
34807
- const title = sanitize(e.title);
34808
- const body = sanitize(e.body);
34809
- return `### ${id} (${urgency})
34810
- ${title}
34811
-
34812
- ${body}`;
34813
- });
34814
- const full = [leadLine, "", ...blocks].join("\n");
34815
- const additionalContext = truncateForCap(full, MAX_ADDITIONAL_CONTEXT);
34816
- return {
34817
- continue: true,
34818
- hookSpecificOutput: {
34819
- hookEventName,
34820
- additionalContext
34821
- }
34822
- };
34823
- }
34824
-
34825
- // src/commands/hook.ts
34826
34881
  var hookCommand = new Command("hook").description(
34827
34882
  "Claim hook-delivery payloads from the runtime"
34828
34883
  );
@@ -34864,36 +34919,6 @@ function lifecycleForEvent(hookEventName) {
34864
34919
  return void 0;
34865
34920
  }
34866
34921
  }
34867
- async function readHookPayload() {
34868
- const stdin = process.stdin;
34869
- if (stdin.isTTY) return {};
34870
- const raw = await new Promise((resolve) => {
34871
- let data = "";
34872
- let settled = false;
34873
- const finish = () => {
34874
- if (settled) return;
34875
- settled = true;
34876
- resolve(data);
34877
- };
34878
- stdin.setEncoding("utf8");
34879
- stdin.on("data", (chunk) => {
34880
- data += chunk;
34881
- });
34882
- stdin.on("end", finish);
34883
- stdin.on("error", finish);
34884
- });
34885
- const trimmed = raw.trim();
34886
- if (trimmed === "") return {};
34887
- try {
34888
- const parsed = JSON.parse(trimmed);
34889
- if (typeof parsed === "object" && parsed !== null) {
34890
- return parsed;
34891
- }
34892
- return {};
34893
- } catch {
34894
- return {};
34895
- }
34896
- }
34897
34922
  hookCommand.command("deliver").description(
34898
34923
  "Claim pending events and emit advisory hook context at a turn boundary"
34899
34924
  ).addOption(
@@ -42386,8 +42411,19 @@ async function runChannelServe(options2) {
42386
42411
  }
42387
42412
 
42388
42413
  // src/index.ts
42414
+ function getVersion() {
42415
+ try {
42416
+ const dir = (0, import_node_path9.dirname)((0, import_node_url4.fileURLToPath)(importMetaUrl));
42417
+ const pkg = JSON.parse(
42418
+ (0, import_node_fs6.readFileSync)((0, import_node_path9.join)(dir, "..", "package.json"), "utf8")
42419
+ );
42420
+ return typeof pkg.version === "string" ? pkg.version : "0.0.0";
42421
+ } catch {
42422
+ return "0.0.0";
42423
+ }
42424
+ }
42389
42425
  var program2 = new Command();
42390
- program2.name("agentmonitors").description("Durable observation and inbox delivery for AI agents").version("0.0.0");
42426
+ program2.name("agentmonitors").description("Durable observation and inbox delivery for AI agents").version(getVersion());
42391
42427
  program2.addCommand(initCommand);
42392
42428
  program2.addCommand(validateCommand);
42393
42429
  program2.addCommand(scanCommand);