@marver-design/marver 0.27.2 → 0.28.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 (64) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/README.md +4 -2
  3. package/dist/{anchor-check-gkxkPAIv.mjs → anchor-check-PHUOFj1N.mjs} +1 -1
  4. package/dist/{audio-Dw1lfMdb.mjs → audio-DX4POHAj.mjs} +39 -4
  5. package/dist/{boards-BqUqKNW8.mjs → boards-BeWtjGUM.mjs} +49 -4
  6. package/dist/boards-EH2onUXM.mjs +995 -0
  7. package/dist/{build-VgNg4rr8.mjs → build-BsAyLMT1.mjs} +7 -5
  8. package/dist/{capture-vadKjuCo.mjs → capture-DdZ6xgoz.mjs} +92 -30
  9. package/dist/cli.mjs +37 -16
  10. package/dist/{comments-YEU1Zhv9.mjs → comments-CrBHPEQl.mjs} +2 -2
  11. package/dist/config-BezZTiov.mjs +182 -0
  12. package/dist/conn-BMiHS42T.mjs +222 -0
  13. package/dist/connectors-MR9d-EBP.mjs +290 -0
  14. package/dist/{context-Ccjrhr1J.mjs → context-BUnFiyA3.mjs} +2 -2
  15. package/dist/{daemon-Dc9AH0M3.mjs → daemon-C5dg2R-V.mjs} +2187 -182
  16. package/dist/{dev-ri6nAlRp.mjs → dev-D7YS7iT2.mjs} +22 -11
  17. package/dist/{init-W0nxR1OY.mjs → init-WE5lQkQL.mjs} +7 -2
  18. package/dist/jam-Cj5gBvwD.mjs +373 -0
  19. package/dist/{link-CdTgn94Y.mjs → link-BFFRgrMt.mjs} +3 -3
  20. package/dist/listener-DdLEM79A.mjs +80 -0
  21. package/dist/{manifest-aFyDmL8C.mjs → manifest-DPZ3WNg_.mjs} +1 -1
  22. package/dist/{marks-BF9pNEgH.mjs → marks-Dyn6tmjp.mjs} +3 -3
  23. package/dist/{marks-CnCCfAbD.mjs → marks-Kmdab_5w.mjs} +2 -2
  24. package/dist/{perf-DkAUFT6W.mjs → perf-Cn5LiRaY.mjs} +3 -3
  25. package/dist/{perf-jam-BaH3Lg0m.mjs → perf-jam-QxD_UnzN.mjs} +1 -1
  26. package/dist/permit-DDa6wqOs.mjs +187 -0
  27. package/dist/{plugin-B8UghYuF.mjs → plugin-C_0yb-Fq.mjs} +365 -518
  28. package/dist/{poster-BNgafWMK.mjs → poster-DHi6I1fO.mjs} +1 -1
  29. package/dist/{publish-bakes-38Nja78p.mjs → publish-bakes-r4PEZuPl.mjs} +2 -2
  30. package/dist/{queue-CAM_vNmX.mjs → queue-c-6aTHEz.mjs} +164 -25
  31. package/dist/{recover-B8AiI29B.mjs → recover-nrLEVLyJ.mjs} +1 -1
  32. package/dist/{session-BAaJsK5c.mjs → session-DyVE7cCk.mjs} +1 -1
  33. package/dist/{shot-Ch24tiMO.mjs → shot-BrRtqaiS.mjs} +7 -6
  34. package/dist/{shot-CMQgMVZm.mjs → shot-DBWN8hPP.mjs} +1 -1
  35. package/dist/sizes-wjXDev3b.mjs +139 -0
  36. package/dist/speech-worker.mjs +23 -3
  37. package/dist/transport-C5FnY9ni.mjs +203 -0
  38. package/dist/{work-Bxz-ObF3.mjs → work-BYWD_1Zf.mjs} +3 -3
  39. package/dist/{work-CNhFF9pU.mjs → work-DJxH7cCX.mjs} +1 -1
  40. package/docs/jam-session.md +39 -14
  41. package/docs/live-jam.md +92 -10
  42. package/package.json +1 -1
  43. package/src/client/shell/JamSurface.tsx +56 -21
  44. package/src/client/shell/icons.tsx +1 -0
  45. package/src/client/shell/jam-capture.ts +97 -22
  46. package/src/client/shell/jam-keys.ts +32 -6
  47. package/src/client/shell/jam-lane.tsx +14 -5
  48. package/src/client/shell/jam-lines.ts +66 -9
  49. package/src/client/shell/jam-panel.tsx +55 -3
  50. package/src/client/shell/jam-queue.ts +50 -8
  51. package/src/client/shell/jam-session.tsx +53 -4
  52. package/src/client/shell/jam-surface-parts.tsx +6 -3
  53. package/src/client/shell/jam-ui.tsx +6 -1
  54. package/src/client/shell/jam-voice-wait.ts +21 -0
  55. package/src/client/shell/jam-voice.ts +14 -5
  56. package/src/client/shell/styles.css +27 -11
  57. package/src/client/shell/tidy.ts +3 -2
  58. package/src/shared/approval.ts +20 -0
  59. package/src/shared/events.ts +1 -1
  60. package/templates/AGENTS-embedded.md +28 -1
  61. package/templates/AGENTS-studio.md +28 -1
  62. package/templates/instructions/boards.md +7 -1
  63. package/templates/instructions/jam.md +90 -0
  64. package/dist/boards-BHKP5yhI.mjs +0 -342
@@ -1,7 +1,8 @@
1
1
  import { i as PKG, r as NAME } from "./cli.mjs";
2
2
  import { a as notePrefer, c as ranDevBefore, f as startedWhere, i as marverHome, m as runIdentity, o as originOf, p as stopPrefer, s as place, t as forgetDevTraces } from "./slots-CFNnegCc.mjs";
3
3
  import { t as detectHost } from "./detect-C0wpaePX.mjs";
4
- import { a as installedVersion, f as loadConfig, n as tailwind3Css, r as tailwind4Plugin, t as marverPlugin } from "./plugin-B8UghYuF.mjs";
4
+ import { n as loadConfig } from "./config-BezZTiov.mjs";
5
+ import { a as installedVersion, n as tailwind3Css, r as tailwind4Plugin, t as marverPlugin } from "./plugin-C_0yb-Fq.mjs";
5
6
  import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, watch, writeSync } from "node:fs";
6
7
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
7
8
  import { fileURLToPath } from "node:url";
@@ -986,7 +987,7 @@ async function boot(root, opts, instance, t, ctx) {
986
987
  const port = claim.port;
987
988
  const origin = originOf(server.httpServer?.address()) ?? `http://localhost:${port}`;
988
989
  claim.ready(origin);
989
- const { workActivity, writeDevInfo, removeDevInfo, boardsShowing, onBoardsChanged, nextActivitySeq } = await import("./work-CNhFF9pU.mjs").then((n) => n.o);
990
+ const { workActivity, writeDevInfo, removeDevInfo, boardsShowing, onBoardsChanged, nextActivitySeq } = await import("./work-DJxH7cCX.mjs").then((n) => n.o);
990
991
  t.claim(() => removeDevInfo(root, instance));
991
992
  writeDevInfo(root, port, instance);
992
993
  await opts.at?.("published");
@@ -1018,7 +1019,7 @@ async function boot(root, opts, instance, t, ctx) {
1018
1019
  if (fromConfig !== void 0 && !placed.fellBackFrom) console.log(` this canvas keeps its own port (${fromConfig} in design/config.ts); remove it to use the slots\n`);
1019
1020
  setTimeout(async () => {
1020
1021
  try {
1021
- await (await import("./shot-Ch24tiMO.mjs").then((n) => n.u)).sweepGhosts((m) => console.log(` ${m}`));
1022
+ await (await import("./shot-BrRtqaiS.mjs").then((n) => n.u)).sweepGhosts((m) => console.log(` ${m}`));
1022
1023
  } catch {}
1023
1024
  }, 0);
1024
1025
  try {
@@ -1032,7 +1033,7 @@ async function boot(root, opts, instance, t, ctx) {
1032
1033
  } catch {}
1033
1034
  try {
1034
1035
  if (!existsSync(join(root, "context"))) {
1035
- const n = (await import("./manifest-aFyDmL8C.mjs").then((n) => n.i)).statusBoards(root).length;
1036
+ const n = (await import("./manifest-DPZ3WNg_.mjs").then((n) => n.i)).statusBoards(root).length;
1036
1037
  if (n) console.log(` ${n} feature/project board${n === 1 ? "" : "s"}, no context/ - every status reads Backlog. To start it, tell your agent: "Set up our context."\n`);
1037
1038
  }
1038
1039
  } catch {}
@@ -1099,8 +1100,8 @@ async function boot(root, opts, instance, t, ctx) {
1099
1100
  } catch {}
1100
1101
  }
1101
1102
  if (config.jam) {
1102
- const { startJam } = await import("./daemon-Dc9AH0M3.mjs");
1103
- const { checkAnchor } = await import("./anchor-check-gkxkPAIv.mjs");
1103
+ const { startJam } = await import("./daemon-C5dg2R-V.mjs");
1104
+ const { checkAnchor } = await import("./anchor-check-PHUOFj1N.mjs");
1104
1105
  const jam = startJam(root, config.jam, (m) => console.log(m), (board) => server.ws.send("sh:jam-comment", { board }), (frameId, target, others, look) => checkAnchor({
1105
1106
  root,
1106
1107
  viewports: config.viewports,
@@ -1119,7 +1120,7 @@ async function boot(root, opts, instance, t, ctx) {
1119
1120
  }, 60);
1120
1121
  };
1121
1122
  })(), async (frameId, theme, entry, size) => {
1122
- const { shootFrame } = await import("./shot-Ch24tiMO.mjs").then((n) => n.u);
1123
+ const { shootFrame } = await import("./shot-BrRtqaiS.mjs").then((n) => n.u);
1123
1124
  const r = await shootFrame({
1124
1125
  root,
1125
1126
  viewports: config.viewports,
@@ -1129,7 +1130,7 @@ async function boot(root, opts, instance, t, ctx) {
1129
1130
  ...size ? { size } : {}
1130
1131
  });
1131
1132
  if (!r.ok) return null;
1132
- const { addPicture } = await import("./capture-vadKjuCo.mjs").then((n) => n.i);
1133
+ const { addPicture } = await import("./capture-DdZ6xgoz.mjs").then((n) => n.i);
1133
1134
  return addPicture(root, r.path, {
1134
1135
  frame: frameId,
1135
1136
  ...entry,
@@ -1138,9 +1139,19 @@ async function boot(root, opts, instance, t, ctx) {
1138
1139
  }, watch$1.add);
1139
1140
  if (jam) {
1140
1141
  t.defer(() => jam.stop());
1141
- const { createSpeech, speechLive } = await import("./audio-Dw1lfMdb.mjs");
1142
- const { appendTalk } = await import("./session-BAaJsK5c.mjs").then((n) => n.s);
1143
- const { logJam } = await import("./perf-jam-BaH3Lg0m.mjs").then((n) => n.n);
1142
+ if (config.jam.session !== false) try {
1143
+ const { ensureConnectors, connectorLine } = await import("./connectors-MR9d-EBP.mjs");
1144
+ const { jamLive } = await import("./live-Cgzsicwi.mjs");
1145
+ const results = ensureConnectors(root);
1146
+ jamLive.connectors = results;
1147
+ const line = connectorLine(results);
1148
+ if (line) console.log(line);
1149
+ } catch (err) {
1150
+ console.log(` jam: could not connect sessions - ${err.message}`);
1151
+ }
1152
+ const { createSpeech, speechLive } = await import("./audio-DX4POHAj.mjs");
1153
+ const { appendTalk } = await import("./session-DyVE7cCk.mjs").then((n) => n.s);
1154
+ const { logJam } = await import("./perf-jam-QxD_UnzN.mjs").then((n) => n.n);
1144
1155
  const speech = createSpeech({
1145
1156
  onTalk: (t) => appendTalk(root, t.session, t.words),
1146
1157
  onTiming: (t) => logJam(root, {
@@ -1,11 +1,12 @@
1
1
  import { r as NAME } from "./cli.mjs";
2
- import { n as addFolders, s as listBoardFiles } from "./boards-BHKP5yhI.mjs";
2
+ import { c as listBoardFiles, n as addFolders } from "./boards-EH2onUXM.mjs";
3
3
  import { C as KIND_FOLDERS, x as FOLDER_MODULES } from "./board-tree-BXR8dw4b.mjs";
4
- import { s as scanFrames, u as writeManifest } from "./manifest-aFyDmL8C.mjs";
4
+ import { s as scanFrames, u as writeManifest } from "./manifest-DPZ3WNg_.mjs";
5
5
  import { r as detectAgent } from "./agent-BsieQGTD.mjs";
6
6
  import { MANAGED_PREFIX, enumerateInstructionTemplates, hashBody, pkgDir } from "./managed-HwHVNI3h.mjs";
7
7
  import { t as writeManaged } from "./managed-write-Bo-oPc-i.mjs";
8
8
  import { n as readJson, t as detectHost } from "./detect-C0wpaePX.mjs";
9
+ import { connectorLine, ensureConnectors } from "./connectors-MR9d-EBP.mjs";
9
10
  import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
10
11
  import { basename, dirname, join, relative } from "node:path";
11
12
  //#region src/cli/init.ts
@@ -264,6 +265,10 @@ function init(root, opts) {
264
265
  if (!existsSync(join(root, "context"))) console.log(`\n note: no context/ yet - feature and project boards read Backlog until there is one, and nothing records what shipped. To start it, tell your agent: "Set up our context." (design/instructions/context.md)`);
265
266
  if (!jamAgent) console.log(`\n note: Live Jam found no agent CLI on PATH (claude, codex, cursor, droid, opencode, grok, or pi) - install one and it arms itself on the next \`${NAME} dev\`.`);
266
267
  else if (created.includes("design/config.ts")) console.log(`\n Live Jam is on (${jamAgent}): tag @${NAME} in a canvas comment and your agent does the work, then replies in the thread.`);
268
+ if (jamAgent) try {
269
+ const line = connectorLine(ensureConnectors(root));
270
+ if (line) console.log(`\n${line}`);
271
+ } catch {}
267
272
  console.log(`\n next: npx ${NAME} dev (or: npx ${NAME} canvas - same thing; it prints its link: a free slot, localhost:4805-4824, usually the same one next time)\n`);
268
273
  if (!noApp(host) && created.includes("design/config.ts")) console.log(` then, to your agent: "Read design/AGENTS.md. This is our first session - follow design/instructions/welcome.md."\n`);
269
274
  }
@@ -0,0 +1,373 @@
1
+ import { r as NAME } from "./cli.mjs";
2
+ import { _ as readPrefs, d as offersText, g as readOffers, h as readConn, i as connId, l as listConns, p as pidAlive, s as endConn, u as offersFile, v as unlike, y as upsertConn } from "./conn-BMiHS42T.mjs";
3
+ import { request } from "./transport-C5FnY9ni.mjs";
4
+ import { existsSync, readFileSync, realpathSync, statSync, watch } from "node:fs";
5
+ import { dirname, isAbsolute, join, resolve } from "node:path";
6
+ import { createConnection } from "node:net";
7
+ import { execFileSync } from "node:child_process";
8
+ //#region src/cli/jam.ts
9
+ /**
10
+ * `marver jam` - Live Jam from a coding-agent session (spec 29b).
11
+ *
12
+ * jam next | say <handle> <words> | progress <handle> | done <handle> --file <f> | release <handle> | status | mute
13
+ * what a session runs when Marver Jam wakes it: take a run, work on it, hand the result back
14
+ * jam hook <claude|codex|cursor> <start|prompt|stop|end> run by the tools' hooks, never by hand
15
+ * jam listen Claude Code's listener, started by its hooks
16
+ * jam permit the permission tool of a background Claude Code run
17
+ *
18
+ * The session's commands reach the daemon through files (transport.ts) - a sandbox that blocks
19
+ * localhost cannot stop them. A hook never fails its host: an error prints nothing and exits 0.
20
+ */
21
+ /** The repo a hook or a session works in: the nearest folder above `from` with a design/ that marver made. */
22
+ function marverRoot(from) {
23
+ let at = resolve(from);
24
+ for (;;) {
25
+ if ([
26
+ "config.ts",
27
+ "scenes",
28
+ ".local"
29
+ ].some((x) => existsSync(join(at, "design", x)))) try {
30
+ return realpathSync(at);
31
+ } catch {
32
+ return at;
33
+ }
34
+ const up = dirname(at);
35
+ if (up === at) return null;
36
+ at = up;
37
+ }
38
+ }
39
+ /** Jam is off for this repo's sessions (`jam: false`, `jam.session: false`), or for this process. */
40
+ async function sessionsOff(root, env) {
41
+ if (env.MARVER_JAM_BACKGROUND === "1" || env.MARVER_JAM === "off") return true;
42
+ try {
43
+ const { loadConfig } = await import("./config-BezZTiov.mjs").then((n) => n.t);
44
+ const cfg = await loadConfig(root);
45
+ return !cfg.jam || cfg.jam.session === false;
46
+ } catch {
47
+ return true;
48
+ }
49
+ }
50
+ const readStdin = async () => {
51
+ if (process.stdin.isTTY) return {};
52
+ const chunks = [];
53
+ let to;
54
+ const done = new Promise((res) => {
55
+ process.stdin.on("data", (c) => chunks.push(c));
56
+ process.stdin.on("end", () => res());
57
+ process.stdin.on("error", () => res());
58
+ });
59
+ await Promise.race([done, new Promise((r) => {
60
+ to = setTimeout(r, 2e3);
61
+ })]);
62
+ clearTimeout(to);
63
+ try {
64
+ const o = JSON.parse(Buffer.concat(chunks).toString("utf8") || "{}");
65
+ return o && typeof o === "object" ? o : {};
66
+ } catch {
67
+ return {};
68
+ }
69
+ };
70
+ /** The nearest ancestor process whose command is `name` (Codex runs its hooks through a shell). */
71
+ function ancestor(name, from = process.ppid) {
72
+ let pid = from;
73
+ for (let i = 0; i < 8 && pid > 1; i++) {
74
+ let line;
75
+ try {
76
+ line = execFileSync("ps", [
77
+ "-o",
78
+ "ppid=,comm=",
79
+ "-p",
80
+ String(pid)
81
+ ], {
82
+ encoding: "utf8",
83
+ timeout: 2e3
84
+ }).trim();
85
+ } catch {
86
+ return;
87
+ }
88
+ const m = /^(\d+)\s+(.*)$/.exec(line);
89
+ if (!m) return void 0;
90
+ if (name.test(m[2].split("/").pop() ?? "")) return pid;
91
+ pid = Number(m[1]);
92
+ }
93
+ }
94
+ const CONNECTED_LINE = (as) => `This session is connected to Marver's Live Jam: the owner's requests from the design canvas (their @marver tags and voice captures) come to you as "Live Jam: ... new request" - take each with \`npx ${NAME} jam next${as ? ` --as ${as}` : ""}\` (design/AGENTS.md, "Live Jam").`;
95
+ /** `jam hook <agent> <event>`: register, mark busy or idle, answer in the tool's own words. Prints
96
+ * nothing and exits 0 on anything unexpected - a hook must never break its host. */
97
+ async function hookCommand(agent, event, rootOpt) {
98
+ try {
99
+ if (process.env.MARVER_JAM_BACKGROUND === "1" || process.env.GROK_HOOK_EVENT) return;
100
+ const out = await hook(agent, event, await readStdin(), process.env, Date.now(), rootOpt);
101
+ if (out) process.stdout.write(JSON.stringify(out));
102
+ } catch {}
103
+ }
104
+ /** Is this hook input from the tool the entry was written for? Cursor runs Claude Code's hooks, Grok runs
105
+ * both Claude Code's and Cursor's - and either may have inherited a Claude Code session's variables, so the
106
+ * input's own shape decides, before anything else is looked at. */
107
+ function ownHost(agent, input, env) {
108
+ if (env.GROK_HOOK_EVENT || typeof input.hookEventName === "string") return false;
109
+ const cursor = typeof input.cursor_version === "string";
110
+ if (agent === "cursor") return cursor && typeof (input.session_id ?? input.conversation_id) === "string";
111
+ if (cursor || typeof input.hook_event_name !== "string" || typeof input.session_id !== "string") return false;
112
+ return agent === "claude" ? !!env.CLAUDE_CODE_MESSAGING_SOCKET : agent === "codex";
113
+ }
114
+ /** The repo a hook speaks for: its `--root`, else the session's folder, else here. */
115
+ const hookRoot = (input, rootOpt) => {
116
+ if (rootOpt) return marverRoot(rootOpt);
117
+ return marverRoot(typeof input.cwd === "string" && isAbsolute(input.cwd) ? input.cwd : Array.isArray(input.workspace_roots) && typeof input.workspace_roots[0] === "string" ? input.workspace_roots[0] : process.cwd());
118
+ };
119
+ /** The hook itself, pure enough to test: what it writes is the connection, what it returns is the answer. */
120
+ async function hook(agent, event, input, env, now = Date.now(), rootOpt) {
121
+ if (env.MARVER_JAM_BACKGROUND === "1") return null;
122
+ if (!ownHost(agent, input, env)) return null;
123
+ if (agent === "claude" && event !== "end") return null;
124
+ const session = String(input.session_id ?? input.conversation_id ?? "");
125
+ const root = hookRoot(input, rootOpt);
126
+ if (!session || !root) return null;
127
+ const id = connId(agent, session);
128
+ if (event === "end") {
129
+ endConn(root, id);
130
+ return null;
131
+ }
132
+ if (await sessionsOff(root, env) || readPrefs(root).off?.[agent]) {
133
+ endConn(root, id);
134
+ return null;
135
+ }
136
+ if (agent === "codex") {
137
+ const start = event === "start";
138
+ const was = readConn(root, id);
139
+ const pid = start || !was?.pid || was.ended ? ancestor(/^codex/) : was.pid;
140
+ const c = upsertConn(root, "codex", session, {
141
+ pid,
142
+ cwd: root,
143
+ mode: typeof input.permission_mode === "string" ? input.permission_mode : void 0,
144
+ busy: event === "prompt"
145
+ }, now, !was || !!was.ended || !!pid && was.pid !== pid);
146
+ const offers = readOffers(root, id);
147
+ const text = offers ? offersText(offers) : "";
148
+ if (start) return { hookSpecificOutput: {
149
+ hookEventName: "SessionStart",
150
+ additionalContext: CONNECTED_LINE()
151
+ } };
152
+ if (event === "prompt") return text ? { hookSpecificOutput: {
153
+ hookEventName: "UserPromptSubmit",
154
+ additionalContext: text
155
+ } } : null;
156
+ if (event === "stop" && offers && text && offers.gen > (c.acted ?? 0)) {
157
+ upsertConn(root, "codex", session, {
158
+ acted: offers.gen,
159
+ busy: true
160
+ }, now);
161
+ return {
162
+ decision: "block",
163
+ reason: text
164
+ };
165
+ }
166
+ return null;
167
+ }
168
+ if (input.is_background_agent === true) return null;
169
+ const composer = typeof input.composer_mode === "string" ? input.composer_mode : void 0;
170
+ const c = upsertConn(root, "cursor", session, {
171
+ cwd: root,
172
+ busy: event === "prompt",
173
+ ...composer ? { composer } : {}
174
+ }, now, event === "start" || !!readConn(root, id)?.ended);
175
+ const offers = readOffers(root, id);
176
+ const text = offers ? offersText(offers, c.id) : "";
177
+ if (event === "start") return { additional_context: CONNECTED_LINE(c.id) };
178
+ if (event === "prompt") return { continue: true };
179
+ if (event === "stop" && offers && text && offers.gen > (c.acted ?? 0)) {
180
+ upsertConn(root, "cursor", session, {
181
+ acted: offers.gen,
182
+ busy: true
183
+ }, now);
184
+ return { followup_message: text };
185
+ }
186
+ return null;
187
+ }
188
+ /** One listener per Claude Code process (spec 29b, Part 5): registers the session, wakes it through
189
+ * its inbox when runs are offered, and exits with it. Started by both hooks; a second start hands
190
+ * over the current session id and exits. It posts the line the canvas wrote, word for word - an upgrade
191
+ * under it changes nothing it says, so it never restarts itself. */
192
+ async function listenCommand(rootOpt) {
193
+ const env = process.env;
194
+ if (env.MARVER_JAM_BACKGROUND === "1" || env.GROK_HOOK_EVENT || env.CLAUDE_CODE_ENTRYPOINT && env.CLAUDE_CODE_ENTRYPOINT !== "cli") return;
195
+ const input = await readStdin().catch(() => ({}));
196
+ if (!ownHost("claude", input, env)) return;
197
+ const sock = env.CLAUDE_CODE_MESSAGING_SOCKET, token = env.CLAUDE_CODE_MESSAGING_TOKEN, claudePid = Number(env.CLAUDE_PID);
198
+ if (!token || !Number.isInteger(claudePid) || claudePid <= 1) return;
199
+ const session = String(input.session_id);
200
+ const root = hookRoot(input, rootOpt);
201
+ if (!root || await sessionsOff(root, env) || readPrefs(root).off?.claude) return;
202
+ const { claimListener, readListener, writeListener, releaseListener } = await import("./listener-DdLEM79A.mjs");
203
+ const mode = typeof input.permission_mode === "string" ? input.permission_mode : void 0;
204
+ const held = readListener(root, claudePid);
205
+ if (held && held.pid !== process.pid && pidAlive(held.pid)) {
206
+ if (held.session !== session || mode && held.mode !== mode) writeListener(root, claudePid, {
207
+ ...held,
208
+ session,
209
+ ...mode ? { mode } : {}
210
+ });
211
+ return;
212
+ }
213
+ if (!claimListener(root, claudePid, {
214
+ pid: process.pid,
215
+ session,
216
+ ...mode ? { mode } : {}
217
+ })) return;
218
+ const parent = process.ppid;
219
+ let current = session;
220
+ const prev = readConn(root, connId("claude", current));
221
+ let conn = upsertConn(root, "claude", current, {
222
+ pid: claudePid,
223
+ cwd: root,
224
+ mode,
225
+ busy: false
226
+ }, Date.now(), !prev || prev.pid !== claudePid || !!prev.ended);
227
+ let posted = 0;
228
+ /** Post one message to the session's inbox: true once it is written (a failure is tried again next look). */
229
+ const post = (text) => new Promise((res) => {
230
+ const c = createConnection(sock);
231
+ let ok = false;
232
+ const end = () => {
233
+ try {
234
+ c.destroy();
235
+ } catch {}
236
+ res(ok);
237
+ };
238
+ c.on("connect", () => {
239
+ c.write(JSON.stringify({
240
+ type: "auth",
241
+ token
242
+ }) + "\n");
243
+ c.write(JSON.stringify({
244
+ type: "user",
245
+ message: {
246
+ role: "user",
247
+ content: text
248
+ }
249
+ }) + "\n", (err) => {
250
+ ok = !err;
251
+ setTimeout(end, 500);
252
+ });
253
+ });
254
+ c.on("error", end);
255
+ setTimeout(end, 5e3);
256
+ });
257
+ const quit = (over) => {
258
+ if (over) endConn(root, conn.id, conn.inc);
259
+ releaseListener(root, claudePid, process.pid);
260
+ process.exit(0);
261
+ };
262
+ process.on("SIGTERM", () => quit(!pidAlive(claudePid)));
263
+ process.on("SIGINT", () => quit(!pidAlive(claudePid)));
264
+ process.on("SIGHUP", () => quit(!pidAlive(claudePid)));
265
+ let delivered = "";
266
+ const look = async () => {
267
+ if (!pidAlive(claudePid) || process.ppid !== parent || !existsSync(join(root, "design")) || readPrefs(root).off?.claude) return quit(!pidAlive(claudePid) || !!readPrefs(root).off?.claude);
268
+ const l = readListener(root, claudePid);
269
+ if (l && l.pid !== process.pid) return quit(false);
270
+ if (l && (l.session !== current || l.mode !== conn.mode)) {
271
+ if (l.session !== current) {
272
+ endConn(root, conn.id, conn.inc);
273
+ current = l.session;
274
+ posted = 0;
275
+ }
276
+ conn = upsertConn(root, "claude", current, {
277
+ pid: claudePid,
278
+ cwd: root,
279
+ mode: l.mode,
280
+ busy: false
281
+ }, Date.now(), l.session !== conn.session);
282
+ }
283
+ const now = readConn(root, conn.id);
284
+ if (!now || now.inc !== conn.inc) conn = upsertConn(root, "claude", current, {
285
+ pid: claudePid,
286
+ cwd: root,
287
+ mode: conn.mode,
288
+ busy: false
289
+ }, Date.now(), true);
290
+ const o = readOffers(root, conn.id);
291
+ if (!o || o.gen <= posted) return;
292
+ const text = unlike(o.n || o.stop?.length || o.resume?.length ? o.line ?? offersText(o) : "", delivered);
293
+ if (!text || await post(text)) {
294
+ posted = o.gen;
295
+ if (text) delivered = text;
296
+ }
297
+ };
298
+ let busy = false;
299
+ const tick = () => {
300
+ if (busy) return;
301
+ busy = true;
302
+ look().catch(() => {}).finally(() => {
303
+ busy = false;
304
+ });
305
+ };
306
+ try {
307
+ watch(dirname(offersFile(root, conn.id)), { persistent: false }, tick);
308
+ } catch {}
309
+ setInterval(tick, 1e3);
310
+ }
311
+ /** This session's own connection: by its tool's session id, or `--as` (Cursor) - never "whichever". */
312
+ function ownConn(root, env, as) {
313
+ if (as) {
314
+ const c = readConn(root, as);
315
+ if (!c) throw new Error(`no connected session ${as} - it may have ended`);
316
+ return c;
317
+ }
318
+ const tries = [["claude", env.CLAUDE_CODE_SESSION_ID], ["codex", env.CODEX_THREAD_ID]];
319
+ for (const [agent, session] of tries) {
320
+ if (!session) continue;
321
+ const c = readConn(root, connId(agent, session));
322
+ if (c) return c;
323
+ }
324
+ if (env.CLAUDE_CODE_SESSION_ID || env.CODEX_THREAD_ID) throw new Error("this session is not connected to the canvas yet - it connects at its next message (or start a Jam session on the canvas)");
325
+ const cursor = listConns(root).filter((c) => c.agent === "cursor");
326
+ throw new Error(cursor.length ? "name your connection: --as <id>, as the Live Jam message said" : "run this from the coding-agent session Live Jam woke");
327
+ }
328
+ async function jamCommand(root, action, args, opts) {
329
+ if (![
330
+ "next",
331
+ "say",
332
+ "progress",
333
+ "done",
334
+ "release",
335
+ "status",
336
+ "mute"
337
+ ].includes(action)) throw new Error(`unknown jam action "${action}" - next, say, progress, done, release, status or mute`);
338
+ const conn = ownConn(root, process.env, opts.as);
339
+ const a = {};
340
+ if ([
341
+ "say",
342
+ "progress",
343
+ "done",
344
+ "release"
345
+ ].includes(action)) {
346
+ if (!args[0]) throw new Error(`name the run: jam ${action} <handle>`);
347
+ a.handle = args[0];
348
+ }
349
+ if (action === "say") {
350
+ a.text = args.slice(1).join(" ").trim();
351
+ if (!a.text) throw new Error("say what: jam say <handle> \"On it - ...\"");
352
+ }
353
+ if (action === "done") {
354
+ let text = "";
355
+ if (opts.file) {
356
+ const f = resolve(root, opts.file);
357
+ if (!statSync(f).isFile()) throw new Error(`${opts.file} is not a file`);
358
+ text = readFileSync(f, "utf8");
359
+ } else if (!process.stdin.isTTY) text = readFileSync(0, "utf8");
360
+ if (!text.trim()) throw new Error("hand back the final message: jam done <handle> --file <file> (the marver-reply blocks)");
361
+ if (text.length > 4e5) throw new Error("the final message is too long - the replies go in marver-reply blocks, not the work itself");
362
+ a.text = text;
363
+ }
364
+ const r = await request(root, conn, action, a, action === "done" ? 12e4 : 3e4);
365
+ if (opts.json) {
366
+ console.log(JSON.stringify(r, null, 1));
367
+ return;
368
+ }
369
+ if (r.ok === false) throw new Error(String(r.error ?? "refused"));
370
+ if (typeof r.text === "string") console.log(r.text);
371
+ }
372
+ //#endregion
373
+ export { hookCommand, jamCommand, listenCommand, marverRoot, ownConn };
@@ -1,8 +1,8 @@
1
1
  import { r as NAME } from "./cli.mjs";
2
- import { d as readMembership, i as checkBoardsDir, p as unplacedHint, s as listBoardFiles } from "./boards-BHKP5yhI.mjs";
2
+ import { _ as unplacedHint, a as checkBoardsDir, c as listBoardFiles, p as readMembership } from "./boards-EH2onUXM.mjs";
3
3
  import { f as isBoardName } from "./board-tree-BXR8dw4b.mjs";
4
- import { s as scanFrames } from "./manifest-aFyDmL8C.mjs";
5
- import { i as readDevInfo } from "./work-CNhFF9pU.mjs";
4
+ import { s as scanFrames } from "./manifest-DPZ3WNg_.mjs";
5
+ import { i as readDevInfo } from "./work-DJxH7cCX.mjs";
6
6
  import { join } from "node:path";
7
7
  //#region src/cli/link.ts
8
8
  /**
@@ -0,0 +1,80 @@
1
+ import { c as jamDir, p as pidAlive, x as writeAtomic } from "./conn-BMiHS42T.mjs";
2
+ import { mkdirSync, readFileSync, rmSync, rmdirSync, statSync, writeFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ //#region src/server/jam/listener.ts
5
+ /**
6
+ * The Claude Code listener's lock (spec 29b, Part 5): one listener per Claude Code process, at
7
+ * design/.local/jam/listen/<CLAUDE_PID>.json. A second start finds it alive and hands over the current
8
+ * session id (a new prompt, /clear, compaction, a resume); a lock whose listener is gone is taken over.
9
+ * S29-5b's lesson: without it, the wake-up's own prompt hook starts a second listener, and a third.
10
+ *
11
+ * Taking over a dead listener's lock happens under a reclaim lock of its own (created exclusively), and
12
+ * only after reading the lock again under it - so two starts that both saw it stale never both win.
13
+ */
14
+ const listenerFile = (root, claudePid) => join(jamDir(root), "listen", `${claudePid}.json`);
15
+ function readListener(root, claudePid) {
16
+ try {
17
+ const l = JSON.parse(readFileSync(listenerFile(root, claudePid), "utf8"));
18
+ return Number.isInteger(l?.pid) && typeof l.session === "string" ? l : null;
19
+ } catch {
20
+ return null;
21
+ }
22
+ }
23
+ /** Hand over a new session id or mode - only to the listener that holds the lock now. */
24
+ function writeListener(root, claudePid, l) {
25
+ if (readListener(root, claudePid)?.pid !== l.pid) return;
26
+ writeAtomic(listenerFile(root, claudePid), JSON.stringify(l));
27
+ }
28
+ /** Is the lock held by nobody alive? A lock that cannot be read and is not new (a start that crashed mid-write) is. */
29
+ function stale(file, held) {
30
+ if (held) return !pidAlive(held.pid);
31
+ try {
32
+ return Date.now() - statSync(file).mtimeMs > 5e3;
33
+ } catch {
34
+ return true;
35
+ }
36
+ }
37
+ /** Take the lock: created exclusively when there is none; a dead one replaced only under the reclaim lock. */
38
+ function claimListener(root, claudePid, l) {
39
+ const file = listenerFile(root, claudePid);
40
+ mkdirSync(join(jamDir(root), "listen"), {
41
+ recursive: true,
42
+ mode: 448
43
+ });
44
+ const create = () => {
45
+ try {
46
+ writeFileSync(file, JSON.stringify(l), {
47
+ flag: "wx",
48
+ mode: 384
49
+ });
50
+ return true;
51
+ } catch {
52
+ return false;
53
+ }
54
+ };
55
+ if (create()) return true;
56
+ if (!stale(file, readListener(root, claudePid))) return false;
57
+ const reclaim = `${file}.reclaim`;
58
+ try {
59
+ mkdirSync(reclaim);
60
+ } catch {
61
+ try {
62
+ if (Date.now() - statSync(reclaim).mtimeMs > 1e4) rmdirSync(reclaim);
63
+ } catch {}
64
+ return false;
65
+ }
66
+ try {
67
+ if (!stale(file, readListener(root, claudePid))) return false;
68
+ rmSync(file, { force: true });
69
+ return create();
70
+ } finally {
71
+ try {
72
+ rmdirSync(reclaim);
73
+ } catch {}
74
+ }
75
+ }
76
+ function releaseListener(root, claudePid, pid) {
77
+ if (readListener(root, claudePid)?.pid === pid) rmSync(listenerFile(root, claudePid), { force: true });
78
+ }
79
+ //#endregion
80
+ export { claimListener, readListener, releaseListener, writeListener };
@@ -1,6 +1,6 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
2
  import { i as PKG, n as CONTENT_WIDTH } from "./cli.mjs";
3
- import { a as checkRealDirs, f as readRegistry, h as hash, i as checkBoardsDir, r as boardFields, s as listBoardFiles } from "./boards-BHKP5yhI.mjs";
3
+ import { a as checkBoardsDir, c as listBoardFiles, m as readRegistry, o as checkRealDirs, r as boardFields, y as hash } from "./boards-EH2onUXM.mjs";
4
4
  import { A as resolveType, D as readReason, E as readCapability, O as readStatusWord, S as HAS_STATUS, a as buildTree, b as DECISIONS, f as isBoardName, g as readTitle, h as readDescription, o as flatten, s as folderEntries } from "./board-tree-BXR8dw4b.mjs";
5
5
  import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
6
6
  import { join, relative, sep } from "node:path";
@@ -1,8 +1,8 @@
1
- import { s as scanFrames } from "./manifest-aFyDmL8C.mjs";
1
+ import { s as scanFrames } from "./manifest-DPZ3WNg_.mjs";
2
2
  import { r as replay, t as asks } from "./events-CLH4ijKP.mjs";
3
3
  import { a as readLog, i as listBoards } from "./comments-0BSbb04K.mjs";
4
- import { o as projectMarks } from "./marks-CnCCfAbD.mjs";
5
- import { answers } from "./queue-CAM_vNmX.mjs";
4
+ import { o as projectMarks } from "./marks-Kmdab_5w.mjs";
5
+ import { answers } from "./queue-c-6aTHEz.mjs";
6
6
  import { join } from "node:path";
7
7
  //#region src/shared/marks.ts
8
8
  const isNew = (m, id) => !!m && (m.changed[id] ?? 0) > (m.seen[id] ?? 0);
@@ -1,7 +1,7 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
- import { a as checkRealDirs, h as hash, i as checkBoardsDir, s as listBoardFiles } from "./boards-BHKP5yhI.mjs";
2
+ import { a as checkBoardsDir, c as listBoardFiles, o as checkRealDirs, y as hash } from "./boards-EH2onUXM.mjs";
3
3
  import { l as framesOn } from "./board-tree-BXR8dw4b.mjs";
4
- import { a as noteFileFor } from "./manifest-aFyDmL8C.mjs";
4
+ import { a as noteFileFor } from "./manifest-DPZ3WNg_.mjs";
5
5
  import { t as imports } from "./imports-WBSnnHLb.mjs";
6
6
  import { existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
7
7
  import { dirname, join, relative, sep } from "node:path";
@@ -1,8 +1,8 @@
1
- import { i as checkBoardsDir, r as boardFields, s as listBoardFiles } from "./boards-BHKP5yhI.mjs";
1
+ import { a as checkBoardsDir, c as listBoardFiles, r as boardFields } from "./boards-EH2onUXM.mjs";
2
2
  import { f as isBoardName, p as labelOf } from "./board-tree-BXR8dw4b.mjs";
3
- import { i as readDevInfo } from "./work-CNhFF9pU.mjs";
3
+ import { i as readDevInfo } from "./work-DJxH7cCX.mjs";
4
4
  import { h as workspaceId, i as marverHome } from "./slots-CFNnegCc.mjs";
5
- import { d as readRuns, l as readPage, r as readJam, u as readReloads } from "./perf-jam-BaH3Lg0m.mjs";
5
+ import { d as readRuns, l as readPage, r as readJam, u as readReloads } from "./perf-jam-QxD_UnzN.mjs";
6
6
  import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
7
7
  import { join } from "node:path";
8
8
  import { homedir } from "node:os";
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
- import { a as checkRealDirs } from "./boards-BHKP5yhI.mjs";
2
+ import { o as checkRealDirs } from "./boards-EH2onUXM.mjs";
3
3
  import { appendFileSync, chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, statSync, writeFileSync } from "node:fs";
4
4
  import { basename, join } from "node:path";
5
5
  import { appendFile, readFile, stat, writeFile } from "node:fs/promises";