@agentmonitors/cli 0.3.1 → 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 +108 -86
- package/dist/index.cjs.map +1 -1
- package/package.json +4 -4
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.
|
|
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.
|
|
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();
|
|
@@ -34569,6 +34569,96 @@ function spawnDetachedDaemon(options2) {
|
|
|
34569
34569
|
child.unref();
|
|
34570
34570
|
}
|
|
34571
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
|
+
|
|
34572
34662
|
// src/commands/session.ts
|
|
34573
34663
|
var sessionCommand = new Command("session").description(
|
|
34574
34664
|
"Manage agent sessions tracked by AgentMon"
|
|
@@ -34644,9 +34734,10 @@ sessionCommand.command("list").description("List known agent sessions").option("
|
|
|
34644
34734
|
sessionCommand.command("start").description(
|
|
34645
34735
|
"Lazy-boot the project daemon (if needed) and register this session"
|
|
34646
34736
|
).action(async () => {
|
|
34647
|
-
const
|
|
34648
|
-
const hostSessionId =
|
|
34737
|
+
const payload = await readHookPayload();
|
|
34738
|
+
const hostSessionId = payload.session_id;
|
|
34649
34739
|
if (!hostSessionId) return;
|
|
34740
|
+
const workspacePath = payload.cwd ?? process.env["CLAUDE_PROJECT_DIR"] ?? process.cwd();
|
|
34650
34741
|
const state = readLocalState(workspacePath);
|
|
34651
34742
|
if (!state.enabled) return;
|
|
34652
34743
|
const paths = workspacePaths(workspacePath);
|
|
@@ -34677,22 +34768,32 @@ sessionCommand.command("start").description(
|
|
|
34677
34768
|
}
|
|
34678
34769
|
writeLocalState(workspacePath, { ...state, socket, db });
|
|
34679
34770
|
try {
|
|
34680
|
-
await openSessionClient(
|
|
34771
|
+
const opened = await openSessionClient(
|
|
34681
34772
|
claudeCodeAdapter.createSessionInput({
|
|
34682
34773
|
hostSessionId,
|
|
34683
34774
|
workspacePath
|
|
34684
34775
|
}),
|
|
34685
34776
|
socket
|
|
34686
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
|
+
}
|
|
34687
34787
|
} catch (error2) {
|
|
34688
34788
|
const message = error2 instanceof Error ? error2.message : String(error2);
|
|
34689
34789
|
reportError(message, false);
|
|
34690
34790
|
}
|
|
34691
34791
|
});
|
|
34692
34792
|
sessionCommand.command("end").description("Deregister this session (lets the idle daemon reap itself)").action(async () => {
|
|
34693
|
-
const
|
|
34694
|
-
const hostSessionId =
|
|
34793
|
+
const payload = await readHookPayload();
|
|
34794
|
+
const hostSessionId = payload.session_id;
|
|
34695
34795
|
if (!hostSessionId) return;
|
|
34796
|
+
const workspacePath = payload.cwd ?? process.env["CLAUDE_PROJECT_DIR"] ?? process.cwd();
|
|
34696
34797
|
const state = readLocalState(workspacePath);
|
|
34697
34798
|
if (!state.enabled || !state.socket) return;
|
|
34698
34799
|
const socket = resolveSocketPath(state.socket);
|
|
@@ -34777,55 +34878,6 @@ eventsCommand.command("ack").description("Acknowledge one or more events for a s
|
|
|
34777
34878
|
|
|
34778
34879
|
// src/commands/hook.ts
|
|
34779
34880
|
init_cjs_shims();
|
|
34780
|
-
|
|
34781
|
-
// src/hook-deliver-render.ts
|
|
34782
|
-
init_cjs_shims();
|
|
34783
|
-
var MAX_ADDITIONAL_CONTEXT = 4e3;
|
|
34784
|
-
var TRUNCATION_MARKER = "\n\n[truncated \u2014 more monitor updates are pending; run `agentmonitors events list --unread` to see the rest]";
|
|
34785
|
-
function sanitize(value) {
|
|
34786
|
-
let out = "";
|
|
34787
|
-
for (const ch of value) {
|
|
34788
|
-
const code = ch.codePointAt(0) ?? 0;
|
|
34789
|
-
const isControl = code < 32 && ch !== "\n" && ch !== " " || code >= 127 && code <= 159;
|
|
34790
|
-
if (!isControl) out += ch;
|
|
34791
|
-
}
|
|
34792
|
-
return out;
|
|
34793
|
-
}
|
|
34794
|
-
function truncateForCap(value, cap) {
|
|
34795
|
-
if (value.length <= cap) return value;
|
|
34796
|
-
const budget = Math.max(0, cap - TRUNCATION_MARKER.length);
|
|
34797
|
-
let out = "";
|
|
34798
|
-
for (const ch of value) {
|
|
34799
|
-
if (out.length + ch.length > budget) break;
|
|
34800
|
-
out += ch;
|
|
34801
|
-
}
|
|
34802
|
-
return out + TRUNCATION_MARKER;
|
|
34803
|
-
}
|
|
34804
|
-
function renderHookDelivery(claim, hookEventName) {
|
|
34805
|
-
if (!claim || claim.events.length === 0) return null;
|
|
34806
|
-
const leadLine = "AgentMon: monitored changes are pending \u2014 consider handling them before continuing.";
|
|
34807
|
-
const blocks = claim.events.map((e) => {
|
|
34808
|
-
const id = sanitize(e.monitorId);
|
|
34809
|
-
const urgency = sanitize(e.urgency);
|
|
34810
|
-
const title = sanitize(e.title);
|
|
34811
|
-
const body = sanitize(e.body);
|
|
34812
|
-
return `### ${id} (${urgency})
|
|
34813
|
-
${title}
|
|
34814
|
-
|
|
34815
|
-
${body}`;
|
|
34816
|
-
});
|
|
34817
|
-
const full = [leadLine, "", ...blocks].join("\n");
|
|
34818
|
-
const additionalContext = truncateForCap(full, MAX_ADDITIONAL_CONTEXT);
|
|
34819
|
-
return {
|
|
34820
|
-
continue: true,
|
|
34821
|
-
hookSpecificOutput: {
|
|
34822
|
-
hookEventName,
|
|
34823
|
-
additionalContext
|
|
34824
|
-
}
|
|
34825
|
-
};
|
|
34826
|
-
}
|
|
34827
|
-
|
|
34828
|
-
// src/commands/hook.ts
|
|
34829
34881
|
var hookCommand = new Command("hook").description(
|
|
34830
34882
|
"Claim hook-delivery payloads from the runtime"
|
|
34831
34883
|
);
|
|
@@ -34867,36 +34919,6 @@ function lifecycleForEvent(hookEventName) {
|
|
|
34867
34919
|
return void 0;
|
|
34868
34920
|
}
|
|
34869
34921
|
}
|
|
34870
|
-
async function readHookPayload() {
|
|
34871
|
-
const stdin = process.stdin;
|
|
34872
|
-
if (stdin.isTTY) return {};
|
|
34873
|
-
const raw = await new Promise((resolve) => {
|
|
34874
|
-
let data = "";
|
|
34875
|
-
let settled = false;
|
|
34876
|
-
const finish = () => {
|
|
34877
|
-
if (settled) return;
|
|
34878
|
-
settled = true;
|
|
34879
|
-
resolve(data);
|
|
34880
|
-
};
|
|
34881
|
-
stdin.setEncoding("utf8");
|
|
34882
|
-
stdin.on("data", (chunk) => {
|
|
34883
|
-
data += chunk;
|
|
34884
|
-
});
|
|
34885
|
-
stdin.on("end", finish);
|
|
34886
|
-
stdin.on("error", finish);
|
|
34887
|
-
});
|
|
34888
|
-
const trimmed = raw.trim();
|
|
34889
|
-
if (trimmed === "") return {};
|
|
34890
|
-
try {
|
|
34891
|
-
const parsed = JSON.parse(trimmed);
|
|
34892
|
-
if (typeof parsed === "object" && parsed !== null) {
|
|
34893
|
-
return parsed;
|
|
34894
|
-
}
|
|
34895
|
-
return {};
|
|
34896
|
-
} catch {
|
|
34897
|
-
return {};
|
|
34898
|
-
}
|
|
34899
|
-
}
|
|
34900
34922
|
hookCommand.command("deliver").description(
|
|
34901
34923
|
"Claim pending events and emit advisory hook context at a turn boundary"
|
|
34902
34924
|
).addOption(
|