@paradow/ledge 0.4.0 → 0.5.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.
- package/dist/cli/{attach-IKK5XQGC.js → attach-CUKFTN63.js} +6 -6
- package/dist/cli/bridge-R6DKTSYF.js +60 -0
- package/dist/cli/{chunk-34DHZSGH.js → chunk-5HVWJTTJ.js} +1 -1
- package/dist/cli/{chunk-XDRYMOVF.js → chunk-HGNMPXXR.js} +40 -14
- package/dist/cli/chunk-IUBEGKBP.js +6 -0
- package/dist/cli/chunk-OLLQBK6N.js +41 -0
- package/dist/cli/{chunk-6ZTCETRG.js → chunk-P2SHPHAN.js} +13 -2
- package/dist/cli/{chunk-ZPR4LCDM.js → chunk-QHDPDZOJ.js} +9 -9
- package/dist/cli/{chunk-5OJZV5MV.js → chunk-SMA4Z3N2.js} +9 -5
- package/dist/cli/{chunk-B73JDPSW.js → chunk-U4A4XKDM.js} +2 -13
- package/dist/cli/{chunk-DMV5VW4Q.js → chunk-XZMLFV6H.js} +2 -4
- package/dist/cli/{chunk-YT4T7DL2.js → chunk-Y4ODVTTN.js} +133 -59
- package/dist/cli/{daemon-2KHF4XUC.js → daemon-6UFCIFQF.js} +667 -113
- package/dist/cli/{hook-QH44D3JC.js → hook-KFSK75QH.js} +62 -20
- package/dist/cli/index.js +14 -8
- package/dist/cli/{launch-CPNM5RX7.js → launch-YKYPT6BU.js} +6 -6
- package/dist/cli/{setup-KUWSQLVG.js → setup-EXA6OG5W.js} +3 -2
- package/dist/cli/{status-E2VZMTAF.js → status-I7FHW6ZM.js} +2 -2
- package/dist/cli/{uninstall-5GHUYN7P.js → uninstall-34TVL5BP.js} +3 -2
- package/dist/cli/{version-J6BW646U.js → version-IWGIZJJV.js} +1 -1
- package/package.json +1 -1
- package/dist/cli/chunk-Y74YLRHP.js +0 -6
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
2
|
QUESTION_TOOLS
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SMA4Z3N2.js";
|
|
4
4
|
import {
|
|
5
5
|
CODEX_ENV_VAR,
|
|
6
|
-
CODEX_HOOK_VAR
|
|
6
|
+
CODEX_HOOK_VAR
|
|
7
|
+
} from "./chunk-U4A4XKDM.js";
|
|
8
|
+
import {
|
|
7
9
|
log
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-6ZTCETRG.js";
|
|
10
|
+
} from "./chunk-P2SHPHAN.js";
|
|
10
11
|
import {
|
|
11
12
|
connect
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-5HVWJTTJ.js";
|
|
14
|
+
import "./chunk-Y4ODVTTN.js";
|
|
14
15
|
|
|
15
16
|
// src/cli/hook.ts
|
|
16
17
|
import { readFileSync, openSync, fstatSync, readSync, closeSync } from "fs";
|
|
17
18
|
import { basename, join } from "path";
|
|
18
19
|
var str = (v) => typeof v === "string" ? v : void 0;
|
|
19
20
|
var PROMPT_MAX = 500;
|
|
21
|
+
var handBack = (t) => t.startsWith('<agent-message from="');
|
|
20
22
|
var promptText = (p) => {
|
|
21
23
|
const t = str(p.prompt)?.trim();
|
|
22
|
-
return t ? { text: t.slice(0, PROMPT_MAX) } : {};
|
|
24
|
+
return t ? { text: t.slice(0, handBack(t) ? INPUT_MAX : PROMPT_MAX) } : {};
|
|
23
25
|
};
|
|
24
26
|
function describeTool(tool, input) {
|
|
25
27
|
const i = input && typeof input === "object" ? input : {};
|
|
@@ -40,6 +42,29 @@ function lastReply(p) {
|
|
|
40
42
|
|
|
41
43
|
[\u2026]` : text;
|
|
42
44
|
}
|
|
45
|
+
var INPUT_MAX = 8e3;
|
|
46
|
+
function trimInput(input) {
|
|
47
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) return void 0;
|
|
48
|
+
const trim = (v) => typeof v === "string" ? v.slice(0, INPUT_MAX) : Array.isArray(v) ? v.map(trim) : v && typeof v === "object" ? Object.fromEntries(Object.entries(v).map(([k, x]) => [k, trim(x)])) : v;
|
|
49
|
+
return trim(input);
|
|
50
|
+
}
|
|
51
|
+
function toolOutput(response) {
|
|
52
|
+
if (response === null || response === void 0) return void 0;
|
|
53
|
+
let text;
|
|
54
|
+
if (typeof response === "string") text = response;
|
|
55
|
+
else if (Array.isArray(response)) text = response.map((b) => str(b?.text) ?? "").filter(Boolean).join("\n");
|
|
56
|
+
else if (typeof response === "object" && ("stdout" in response || "stderr" in response)) {
|
|
57
|
+
const r = response;
|
|
58
|
+
text = [str(r.stdout), str(r.stderr)].filter(Boolean).join("\n");
|
|
59
|
+
} else {
|
|
60
|
+
try {
|
|
61
|
+
text = JSON.stringify(response);
|
|
62
|
+
} catch {
|
|
63
|
+
text = String(response);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return text.slice(0, REPLY_MAX);
|
|
67
|
+
}
|
|
43
68
|
var NON_TERMINAL_END_REASONS = /* @__PURE__ */ new Set(["clear", "resume"]);
|
|
44
69
|
function mapClaudeHook(eventName, payload, at) {
|
|
45
70
|
return mapHook("claude", eventName, payload, at);
|
|
@@ -89,18 +114,29 @@ function mapEvent(eventName, p, at, launched) {
|
|
|
89
114
|
const tool = str(p.tool_name);
|
|
90
115
|
const agentId = str(p.agent_id) || void 0;
|
|
91
116
|
const base = { at, source: "hook", ...agentId ? { helperId: agentId } : {} };
|
|
117
|
+
const toolUseId = str(p.tool_use_id) || void 0;
|
|
118
|
+
const toolInput = trimInput(p.tool_input);
|
|
119
|
+
const call = { ...toolUseId ? { toolUseId } : {}, ...toolInput ? { toolInput } : {} };
|
|
120
|
+
const transcript = str(p.transcript_path) ? { transcriptPath: str(p.transcript_path) } : {};
|
|
121
|
+
const duration = typeof p.duration_ms === "number" && p.duration_ms >= 0 ? { durationMs: p.duration_ms } : {};
|
|
92
122
|
switch (eventName) {
|
|
93
123
|
case "SubagentStart":
|
|
94
124
|
case "SubagentStop": {
|
|
95
125
|
if (!agentId) return null;
|
|
96
126
|
const type = str(p.agent_type) || void 0;
|
|
97
127
|
const task = eventName === "SubagentStart" ? (str(p.description) || str(p.prompt))?.split("\n")[0] : void 0;
|
|
98
|
-
|
|
128
|
+
const report = eventName === "SubagentStop" ? lastReply(p) : void 0;
|
|
129
|
+
const agentTranscript = eventName === "SubagentStop" && str(p.agent_transcript_path) ? { transcriptPath: str(p.agent_transcript_path) } : {};
|
|
130
|
+
return { name: eventName, ...base, ...type ? { tool: type } : {}, ...task ? { text: task } : {}, ...report ? { text: report } : {}, ...agentTranscript };
|
|
131
|
+
}
|
|
132
|
+
case "PostToolUse": {
|
|
133
|
+
const output = toolOutput(p.tool_response);
|
|
134
|
+
return { name: "PostToolUse", ...base, tool, ...call, ...output !== void 0 ? { output } : {}, ...duration };
|
|
135
|
+
}
|
|
136
|
+
case "PostToolUseFailure": {
|
|
137
|
+
const error = str(p.error) || void 0;
|
|
138
|
+
return { name: "PostToolUseFailure", ...base, tool, ...call, ...error ? { error } : {}, ...duration, ...p.is_interrupt === true ? { interrupt: true } : {} };
|
|
99
139
|
}
|
|
100
|
-
case "PostToolUse":
|
|
101
|
-
return { name: "PostToolUse", ...base, tool };
|
|
102
|
-
case "PostToolUseFailure":
|
|
103
|
-
return { name: "PostToolUseFailure", ...base, tool, ...p.is_interrupt === true ? { interrupt: true } : {} };
|
|
104
140
|
case "StopFailure": {
|
|
105
141
|
const error = str(p.error);
|
|
106
142
|
const details = str(p.error_details);
|
|
@@ -113,25 +149,27 @@ function mapEvent(eventName, p, at, launched) {
|
|
|
113
149
|
case "SessionStart":
|
|
114
150
|
return { name: "SessionStart", ...base };
|
|
115
151
|
case "UserPromptSubmit":
|
|
116
|
-
return { name: "UserPromptSubmit", ...base, ...promptText(p) };
|
|
152
|
+
return { name: "UserPromptSubmit", ...base, ...promptText(p), ...transcript };
|
|
117
153
|
case "Stop": {
|
|
118
154
|
const text = lastReply(p);
|
|
119
|
-
return { name: "Stop", ...base, ...text ? { text } : {} };
|
|
155
|
+
return { name: "Stop", ...base, ...text ? { text } : {}, ...transcript };
|
|
120
156
|
}
|
|
121
157
|
case "SessionEnd":
|
|
122
158
|
if (launched) return null;
|
|
123
159
|
if (NON_TERMINAL_END_REASONS.has(str(p.reason) ?? "")) return null;
|
|
124
160
|
return { name: "SessionEnd", ...base, exitCode: null };
|
|
125
161
|
case "PermissionRequest":
|
|
126
|
-
return { name: "PermissionRequest", ...base, tool, text: describeTool(tool, p.tool_input) };
|
|
162
|
+
return { name: "PermissionRequest", ...base, tool, text: describeTool(tool, p.tool_input), ...call, ...transcript };
|
|
127
163
|
case "PreToolUse": {
|
|
128
164
|
if (tool && QUESTION_TOOLS.has(tool)) {
|
|
129
165
|
const qs = p.tool_input?.questions ?? [];
|
|
130
166
|
const q = qs[0];
|
|
131
|
-
const
|
|
132
|
-
|
|
167
|
+
const opts = (q?.options ?? []).filter((o) => !!str(o.label));
|
|
168
|
+
const options = opts.map((o) => str(o.label));
|
|
169
|
+
const optionDetails = opts.map((o) => str(o.description)?.trim() ?? "");
|
|
170
|
+
return { name: "PreToolUse", ...base, tool, text: str(q?.question) ?? "", options, ...optionDetails.some(Boolean) ? { optionDetails } : {}, ...call, ...transcript };
|
|
133
171
|
}
|
|
134
|
-
return { name: "PreToolUse", ...base, tool, text: describeTool(tool, p.tool_input) };
|
|
172
|
+
return { name: "PreToolUse", ...base, tool, text: describeTool(tool, p.tool_input), ...call, ...transcript };
|
|
135
173
|
}
|
|
136
174
|
case "Notification": {
|
|
137
175
|
const type = str(p.notification_type) ?? "";
|
|
@@ -219,6 +257,7 @@ function mapCursorHelperEvent(eventName, p, at, helperId) {
|
|
|
219
257
|
}
|
|
220
258
|
function mapCursorEvent(eventName, p, at, launched, transcript) {
|
|
221
259
|
const { name: tool, input } = unwrapTool(str(p.tool_name), p.tool_input);
|
|
260
|
+
const toolInput = p.tool_input ? trimInput(input) : void 0;
|
|
222
261
|
const base = { at, source: "hook" };
|
|
223
262
|
switch (eventName) {
|
|
224
263
|
case "sessionStart":
|
|
@@ -234,9 +273,9 @@ function mapCursorEvent(eventName, p, at, launched, transcript) {
|
|
|
234
273
|
return { name: "PreToolUse", ...base, tool, text: describeCursorTool(input) };
|
|
235
274
|
}
|
|
236
275
|
case "postToolUse":
|
|
237
|
-
return { name: "PostToolUse", ...base, tool };
|
|
276
|
+
return { name: "PostToolUse", ...base, tool, ...toolInput ? { toolInput } : {} };
|
|
238
277
|
case "postToolUseFailure":
|
|
239
|
-
return { name: "PostToolUseFailure", ...base, tool, ...p.is_interrupt === true ? { interrupt: true } : {} };
|
|
278
|
+
return { name: "PostToolUseFailure", ...base, tool, ...toolInput ? { toolInput } : {}, ...p.is_interrupt === true ? { interrupt: true } : {} };
|
|
240
279
|
case "stop":
|
|
241
280
|
if (str(p.status) === "error") return { name: "StopFailure", ...base };
|
|
242
281
|
return { name: "Stop", ...base };
|
|
@@ -276,6 +315,7 @@ async function runHook(eventName, stdin, opts = {}) {
|
|
|
276
315
|
}
|
|
277
316
|
}
|
|
278
317
|
export {
|
|
318
|
+
INPUT_MAX,
|
|
279
319
|
REPLY_MAX,
|
|
280
320
|
codexLedgeId,
|
|
281
321
|
cursorReply,
|
|
@@ -284,5 +324,7 @@ export {
|
|
|
284
324
|
mapHook,
|
|
285
325
|
readTranscript,
|
|
286
326
|
runHook,
|
|
327
|
+
toolOutput,
|
|
328
|
+
trimInput,
|
|
287
329
|
underCodexDaemon
|
|
288
330
|
};
|
package/dist/cli/index.js
CHANGED
|
@@ -8,6 +8,7 @@ ledge hook [codex|cursor] <Event> receive a hook (rea
|
|
|
8
8
|
ledge setup install hooks and ~/.ledge
|
|
9
9
|
ledge uninstall [--purge] remove hooks, service and link (--purge: ~/.ledge too)
|
|
10
10
|
ledge status list sessions
|
|
11
|
+
ledge bridge exchange Ledge messages over SSH stdio
|
|
11
12
|
ledge --version print the installed version`;
|
|
12
13
|
async function hookMain(args) {
|
|
13
14
|
const tool = args[0] === "codex" || args[0] === "cursor" ? args[0] : void 0;
|
|
@@ -15,7 +16,7 @@ async function hookMain(args) {
|
|
|
15
16
|
try {
|
|
16
17
|
const chunks = [];
|
|
17
18
|
for await (const c of process.stdin) chunks.push(c);
|
|
18
|
-
const { runHook } = await import("./hook-
|
|
19
|
+
const { runHook } = await import("./hook-KFSK75QH.js");
|
|
19
20
|
await runHook(event, Buffer.concat(chunks).toString("utf8"), { tool });
|
|
20
21
|
} catch {
|
|
21
22
|
}
|
|
@@ -25,7 +26,7 @@ async function main(argv) {
|
|
|
25
26
|
const [cmd, ...rest] = argv;
|
|
26
27
|
switch (cmd) {
|
|
27
28
|
case "daemon": {
|
|
28
|
-
const { startDaemon } = await import("./daemon-
|
|
29
|
+
const { startDaemon } = await import("./daemon-6UFCIFQF.js");
|
|
29
30
|
await startDaemon();
|
|
30
31
|
await new Promise(() => {
|
|
31
32
|
});
|
|
@@ -33,34 +34,39 @@ async function main(argv) {
|
|
|
33
34
|
}
|
|
34
35
|
case "--version":
|
|
35
36
|
case "version": {
|
|
36
|
-
const { LEDGE_VERSION } = await import("./version-
|
|
37
|
+
const { LEDGE_VERSION } = await import("./version-IWGIZJJV.js");
|
|
37
38
|
console.log(LEDGE_VERSION);
|
|
38
39
|
return 0;
|
|
39
40
|
}
|
|
40
41
|
case "setup": {
|
|
41
|
-
const { runSetup } = await import("./setup-
|
|
42
|
+
const { runSetup } = await import("./setup-EXA6OG5W.js");
|
|
42
43
|
for (const l of await runSetup()) console.log(l);
|
|
43
44
|
return 0;
|
|
44
45
|
}
|
|
45
46
|
case "uninstall": {
|
|
46
|
-
const { runUninstall } = await import("./uninstall-
|
|
47
|
+
const { runUninstall } = await import("./uninstall-34TVL5BP.js");
|
|
47
48
|
const r = await runUninstall({ purge: rest.includes("--purge") });
|
|
48
49
|
for (const l of r.lines) console.log(l);
|
|
49
50
|
return r.ok ? 0 : 1;
|
|
50
51
|
}
|
|
51
52
|
case "status": {
|
|
52
|
-
const { printStatus } = await import("./status-
|
|
53
|
+
const { printStatus } = await import("./status-I7FHW6ZM.js");
|
|
53
54
|
console.log(await printStatus());
|
|
54
55
|
return 0;
|
|
55
56
|
}
|
|
57
|
+
case "bridge": {
|
|
58
|
+
const { bridge } = await import("./bridge-R6DKTSYF.js");
|
|
59
|
+
await bridge();
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
56
62
|
case "claude":
|
|
57
63
|
case "codex":
|
|
58
64
|
case "cursor": {
|
|
59
|
-
const { launch } = await import("./launch-
|
|
65
|
+
const { launch } = await import("./launch-YKYPT6BU.js");
|
|
60
66
|
return launch(cmd, rest);
|
|
61
67
|
}
|
|
62
68
|
case "attach": {
|
|
63
|
-
const { attach } = await import("./attach-
|
|
69
|
+
const { attach } = await import("./attach-CUKFTN63.js");
|
|
64
70
|
return attach(rest[0] ?? "");
|
|
65
71
|
}
|
|
66
72
|
default:
|
|
@@ -5,15 +5,15 @@ import {
|
|
|
5
5
|
ensureDaemon,
|
|
6
6
|
launch,
|
|
7
7
|
parseLaunchArgs
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-DMV5VW4Q.js";
|
|
8
|
+
} from "./chunk-QHDPDZOJ.js";
|
|
10
9
|
import {
|
|
11
10
|
agentEnv,
|
|
12
11
|
exitFile
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
16
|
-
import "./chunk-
|
|
12
|
+
} from "./chunk-U4A4XKDM.js";
|
|
13
|
+
import "./chunk-XZMLFV6H.js";
|
|
14
|
+
import "./chunk-P2SHPHAN.js";
|
|
15
|
+
import "./chunk-5HVWJTTJ.js";
|
|
16
|
+
import "./chunk-Y4ODVTTN.js";
|
|
17
17
|
export {
|
|
18
18
|
DaemonError,
|
|
19
19
|
agentEnv,
|
|
@@ -13,8 +13,9 @@ import {
|
|
|
13
13
|
runSetup,
|
|
14
14
|
stopDetachedDaemon,
|
|
15
15
|
systemdUnit
|
|
16
|
-
} from "./chunk-
|
|
17
|
-
import "./chunk-
|
|
16
|
+
} from "./chunk-HGNMPXXR.js";
|
|
17
|
+
import "./chunk-XZMLFV6H.js";
|
|
18
|
+
import "./chunk-P2SHPHAN.js";
|
|
18
19
|
export {
|
|
19
20
|
CLAUDE_EVENTS,
|
|
20
21
|
CODEX_EVENTS,
|
|
@@ -2,10 +2,11 @@ import {
|
|
|
2
2
|
SERVICE,
|
|
3
3
|
execRunner,
|
|
4
4
|
stopDetachedDaemon
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-HGNMPXXR.js";
|
|
6
|
+
import "./chunk-XZMLFV6H.js";
|
|
6
7
|
import {
|
|
7
8
|
paths
|
|
8
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-P2SHPHAN.js";
|
|
9
10
|
|
|
10
11
|
// src/cli/uninstall.ts
|
|
11
12
|
import { readFile, writeFile, rename, rm, lstat, realpath } from "fs/promises";
|
package/package.json
CHANGED