@marver-design/marver 0.27.0 → 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 (111) hide show
  1. package/CHANGELOG.md +195 -0
  2. package/README.md +9 -4
  3. package/dist/{anchor-check-ChdDqL5z.mjs → anchor-check-PHUOFj1N.mjs} +1 -1
  4. package/dist/{audio-Dw1lfMdb.mjs → audio-DX4POHAj.mjs} +39 -4
  5. package/dist/{board-tree-DRioF94d.mjs → board-tree-BXR8dw4b.mjs} +3 -1
  6. package/dist/{boards-DlTcpF47.mjs → boards-BeWtjGUM.mjs} +50 -5
  7. package/dist/boards-EH2onUXM.mjs +995 -0
  8. package/dist/{build-DZnFysGU.mjs → build-BsAyLMT1.mjs} +9 -22
  9. package/dist/{capture-vadKjuCo.mjs → capture-DdZ6xgoz.mjs} +92 -30
  10. package/dist/cli.mjs +56 -21
  11. package/dist/{collab-Dxg2trOK.mjs → collab-BEAcXrBb.mjs} +1 -1
  12. package/dist/{comments-DxOkCSNE.mjs → comments-CrBHPEQl.mjs} +4 -4
  13. package/dist/config-BezZTiov.mjs +182 -0
  14. package/dist/conn-BMiHS42T.mjs +222 -0
  15. package/dist/connectors-MR9d-EBP.mjs +290 -0
  16. package/dist/{context-HQ4Giw58.mjs → context-BUnFiyA3.mjs} +3 -3
  17. package/dist/{daemon-BSA0lV8d.mjs → daemon-C5dg2R-V.mjs} +2188 -183
  18. package/dist/{dev-eQJhWsqg.mjs → dev-D7YS7iT2.mjs} +25 -14
  19. package/dist/{init-COD0x48i.mjs → init-WE5lQkQL.mjs} +8 -3
  20. package/dist/jam-Cj5gBvwD.mjs +373 -0
  21. package/dist/{link-DDXZVGtv.mjs → link-BFFRgrMt.mjs} +4 -4
  22. package/dist/listener-DdLEM79A.mjs +80 -0
  23. package/dist/{ls-D7O1G505.mjs → ls-BZ5TAtd5.mjs} +1 -1
  24. package/dist/{manifest-Nl3KSVOk.mjs → manifest-DPZ3WNg_.mjs} +2 -2
  25. package/dist/{marks-CWM3WJjc.mjs → marks-Dyn6tmjp.mjs} +3 -3
  26. package/dist/{marks-CKgzucHZ.mjs → marks-Kmdab_5w.mjs} +3 -3
  27. package/dist/{marver-id-gate-BjF6v4bT.mjs → marver-id-gate-D-R0hSt_.mjs} +1 -1
  28. package/dist/perf-Cn5LiRaY.mjs +1319 -0
  29. package/dist/perf-jam-QxD_UnzN.mjs +635 -0
  30. package/dist/permit-DDa6wqOs.mjs +187 -0
  31. package/dist/plugin-C_0yb-Fq.mjs +5089 -0
  32. package/dist/{poster-Bx83ZYVK.mjs → poster-DHi6I1fO.mjs} +1 -1
  33. package/dist/{profile-Bh5Y5zpW.mjs → profile-jIS6BcAs.mjs} +1 -1
  34. package/dist/{publish-bakes-aljgm45S.mjs → publish-bakes-r4PEZuPl.mjs} +3 -3
  35. package/dist/{queue-CAM_vNmX.mjs → queue-c-6aTHEz.mjs} +164 -25
  36. package/dist/{recover-t9Pno3u9.mjs → recover-nrLEVLyJ.mjs} +2 -2
  37. package/dist/{serve-C8rVheYk.mjs → serve-Dp3nHstu.mjs} +3 -3
  38. package/dist/{session-BAaJsK5c.mjs → session-DyVE7cCk.mjs} +1 -1
  39. package/dist/{share-W5H3BNvP.mjs → share-Ce4tP7ji.mjs} +1 -1
  40. package/dist/{shot-LFhC-WYD.mjs → shot-BrRtqaiS.mjs} +34 -8
  41. package/dist/{shot-DoHLl6ig.mjs → shot-DBWN8hPP.mjs} +1 -1
  42. package/dist/sizes-wjXDev3b.mjs +139 -0
  43. package/dist/{slots-DCDo3N0x.mjs → slots-CFNnegCc.mjs} +8 -1
  44. package/dist/speech-worker.mjs +23 -3
  45. package/dist/{sync-BQVlHZpx.mjs → sync-CQdGARJ9.mjs} +1 -1
  46. package/dist/transport-C5FnY9ni.mjs +203 -0
  47. package/dist/{work-BroFwnup.mjs → work-BYWD_1Zf.mjs} +3 -3
  48. package/dist/{work-Bp1p39kq.mjs → work-DJxH7cCX.mjs} +1 -1
  49. package/docs/jam-session.md +42 -16
  50. package/docs/live-jam.md +92 -10
  51. package/docs/performance.md +197 -35
  52. package/package.json +1 -1
  53. package/src/client/content/video.tsx +10 -2
  54. package/src/client/shell/App.tsx +10 -3
  55. package/src/client/shell/Comments.tsx +5 -3
  56. package/src/client/shell/ContextMenu.tsx +5 -3
  57. package/src/client/shell/JamSurface.tsx +56 -21
  58. package/src/client/shell/LockedApp.tsx +3 -0
  59. package/src/client/shell/Play.tsx +4 -2
  60. package/src/client/shell/Tip.tsx +3 -1
  61. package/src/client/shell/api.ts +47 -20
  62. package/src/client/shell/app-bridge.ts +254 -0
  63. package/src/client/shell/app-perf.ts +92 -0
  64. package/src/client/shell/canvas/Canvas.tsx +115 -22
  65. package/src/client/shell/canvas/FrameNode.tsx +10 -6
  66. package/src/client/shell/canvas/admission.ts +23 -8
  67. package/src/client/shell/canvas/ctl.ts +6 -0
  68. package/src/client/shell/canvas/sleep.ts +57 -17
  69. package/src/client/shell/canvas/updates.ts +2 -1
  70. package/src/client/shell/icons.tsx +1 -0
  71. package/src/client/shell/inset.ts +44 -0
  72. package/src/client/shell/jam-capture.ts +113 -33
  73. package/src/client/shell/jam-keys.ts +40 -9
  74. package/src/client/shell/jam-lane.tsx +14 -5
  75. package/src/client/shell/jam-lines.ts +66 -9
  76. package/src/client/shell/jam-panel.tsx +61 -6
  77. package/src/client/shell/jam-queue.ts +50 -8
  78. package/src/client/shell/jam-session.tsx +53 -4
  79. package/src/client/shell/jam-surface-parts.tsx +6 -3
  80. package/src/client/shell/jam-ui.tsx +6 -1
  81. package/src/client/shell/jam-voice-wait.ts +21 -0
  82. package/src/client/shell/jam-voice.ts +62 -15
  83. package/src/client/shell/main.tsx +14 -1
  84. package/src/client/shell/marks-ui.tsx +5 -3
  85. package/src/client/shell/marver-app.ts +21 -0
  86. package/src/client/shell/perf-run-probe.ts +34 -0
  87. package/src/client/shell/perf-run.ts +70 -0
  88. package/src/client/shell/perf.ts +11 -0
  89. package/src/client/shell/recorder.ts +45 -3
  90. package/src/client/shell/store.ts +52 -24
  91. package/src/client/shell/styles.css +65 -17
  92. package/src/client/shell/tidy.ts +3 -2
  93. package/src/client/shell/unsaved.ts +81 -0
  94. package/src/client/shell/whiteout-probes.ts +141 -0
  95. package/src/shared/app-api.ts +205 -0
  96. package/src/shared/app-perf.ts +308 -0
  97. package/src/shared/approval.ts +20 -0
  98. package/src/shared/events.ts +1 -1
  99. package/src/shared/logo-sniff.ts +86 -0
  100. package/src/shared/machine.ts +132 -0
  101. package/src/shared/perf-run.ts +177 -0
  102. package/templates/AGENTS-embedded.md +31 -1
  103. package/templates/AGENTS-studio.md +31 -1
  104. package/templates/instructions/boards.md +10 -2
  105. package/templates/instructions/jam.md +90 -0
  106. package/dist/bake-DM_uWgAA.mjs +0 -786
  107. package/dist/boards-CGg6piKF.mjs +0 -342
  108. package/dist/perf-BWzQwZqj.mjs +0 -369
  109. package/dist/perf-BoDSkbEb.mjs +0 -429
  110. package/dist/perf-jam-D55U3FZK.mjs +0 -242
  111. package/dist/plugin-C-E7omsh.mjs +0 -2762
@@ -0,0 +1,182 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
+ import { h as readDescription } from "./board-tree-BXR8dw4b.mjs";
3
+ import { i as onPath, n as AGENT_NAMES, r as detectAgent, t as AGENT_BIN } from "./agent-BsieQGTD.mjs";
4
+ import { existsSync } from "node:fs";
5
+ import { join } from "node:path";
6
+ import { pathToFileURL } from "node:url";
7
+ //#region src/server/config.ts
8
+ var config_exports = /* @__PURE__ */ __exportAll({
9
+ DEFAULTS: () => DEFAULTS,
10
+ loadConfig: () => loadConfig
11
+ });
12
+ const DEFAULTS = {
13
+ mode: "studio",
14
+ theme: null,
15
+ viewports: {
16
+ mobile: {
17
+ width: 390,
18
+ height: 844
19
+ },
20
+ tablet: {
21
+ width: 768,
22
+ height: 1024
23
+ },
24
+ laptop: {
25
+ width: 1280,
26
+ height: 800
27
+ },
28
+ monitor: {
29
+ width: 1920,
30
+ height: 1080
31
+ }
32
+ },
33
+ themes: ["light", "dark"],
34
+ port: 5199,
35
+ zoomSpeed: 1,
36
+ share: { branding: true }
37
+ };
38
+ /** Load design/config.ts via native TS import (Node >= 22.18). Missing or broken fields fall back to defaults. */
39
+ async function loadConfig(root) {
40
+ const file = join(root, "design", "config.ts");
41
+ if (!existsSync(file)) return {
42
+ ...DEFAULTS,
43
+ ...jamFields(void 0)
44
+ };
45
+ try {
46
+ const user = (await import(`${pathToFileURL(file).href}?t=${Date.now()}`)).default ?? {};
47
+ return {
48
+ ...DEFAULTS,
49
+ ...user,
50
+ viewports: validViewports(user.viewports) ?? DEFAULTS.viewports,
51
+ themes: Array.isArray(user.themes) && user.themes.length ? user.themes.map(String) : DEFAULTS.themes,
52
+ port: validPort(user.port) ?? DEFAULTS.port,
53
+ zoomSpeed: validZoom(user.zoomSpeed) ?? DEFAULTS.zoomSpeed,
54
+ description: readDescription(user.description),
55
+ share: {
56
+ branding: user.share?.branding !== false,
57
+ name: typeof user.share?.name === "string" ? user.share.name : void 0,
58
+ logo: typeof user.share?.logo === "string" ? user.share.logo : void 0,
59
+ frontDoor: user.share?.frontDoor !== false && user.share?.front_door !== false,
60
+ notify: user.share?.notify !== false
61
+ },
62
+ ...jamFields(user.jam)
63
+ };
64
+ } catch (err) {
65
+ console.error(`[marver] design/config.ts failed to load, using defaults and leaving Live Jam OFF:\n ${err.message}`);
66
+ return {
67
+ ...DEFAULTS,
68
+ jamOff: "unreadable"
69
+ };
70
+ }
71
+ }
72
+ const validDim = (n) => typeof n === "number" && Number.isFinite(n) && n >= 1 && n <= 2e4;
73
+ function validPort(n) {
74
+ return typeof n === "number" && Number.isInteger(n) && n > 0 && n < 65536 ? n : null;
75
+ }
76
+ function validZoom(n) {
77
+ return typeof n === "number" && Number.isFinite(n) && n >= .1 && n <= 10 ? n : null;
78
+ }
79
+ /** Six frames at once is what a jam actually feels like - at 3, half of a multi-frame
80
+ * ask sat waiting on the other half while the human watched. */
81
+ const DEFAULT_CONCURRENCY = 6;
82
+ /** A config value, printable in a warning. Never throws - a formatter that can crash inside an
83
+ * error path (JSON.stringify does, on a BigInt) turns a clear message into a mystery. */
84
+ const show = (v) => {
85
+ try {
86
+ return JSON.stringify(v) ?? String(v);
87
+ } catch {
88
+ return String(v);
89
+ }
90
+ };
91
+ /** A `{...}` written by hand, not a Date/Map/class instance that merely types as "object". */
92
+ const plainObject = (v) => {
93
+ if (!v || typeof v !== "object") return false;
94
+ const proto = Object.getPrototypeOf(v);
95
+ return proto === Object.prototype || proto === null;
96
+ };
97
+ /** The agent to arm with - or, when the human NAMED one we cannot use, why not (said once,
98
+ * here, because a bad `jam.agent` is a config-file error like any other).
99
+ *
100
+ * A named agent is never quietly swapped for another: running a different tool than the one
101
+ * asked for is worse than not running. Nor is one armed that cannot be spawned - that would
102
+ * claim every @marver mention, fail it, and never retry. */
103
+ function resolveAgent(named) {
104
+ if (named === void 0) return detectAgent() ?? "no-agent";
105
+ if (typeof named !== "string" || !Object.hasOwn(AGENT_BIN, named)) {
106
+ console.warn(`[marver] design/config.ts: jam.agent ${show(named)} is not an agent marver can spawn - Live Jam is off. Use ${AGENT_NAMES}.`);
107
+ return "bad-agent";
108
+ }
109
+ const agent = named;
110
+ if (!onPath(AGENT_BIN[agent])) {
111
+ console.warn(`[marver] design/config.ts names jam.agent "${agent}", but \`${AGENT_BIN[agent]}\` is not on PATH - Live Jam is off until it is installed.`);
112
+ return "bad-agent";
113
+ }
114
+ return agent;
115
+ }
116
+ /** Resolve the jam block. Live Jam is ON by default: an absent or partial `jam` resolves
117
+ * to whatever agent CLI this machine has, so a fresh workspace jams with nothing
118
+ * configured and an old one needs no re-init. `jam: false` is the off switch. */
119
+ function resolveJam(v) {
120
+ if (v === false) return "opted-out";
121
+ const shape = v === void 0 || v === true ? {} : typeof v === "string" ? { agent: v } : plainObject(v) ? v : null;
122
+ if (!shape) {
123
+ console.warn(`[marver] design/config.ts: jam must be false, an agent name, or an options object - got ${show(v)}. Live Jam is off.`);
124
+ return "bad-agent";
125
+ }
126
+ const j = shape;
127
+ const agent = resolveAgent(j.agent);
128
+ if (agent === "no-agent" || agent === "bad-agent") return agent;
129
+ const c = j.concurrency;
130
+ const pick = (key, v, ok, fallback, want) => {
131
+ if (v === void 0) return fallback;
132
+ if (ok(v)) return v;
133
+ console.warn(`[marver] design/config.ts: jam.${key} must be ${want} - got ${show(v)}. Using ${JSON.stringify(fallback)}.`);
134
+ return fallback;
135
+ };
136
+ const bool = (v) => typeof v === "boolean";
137
+ return {
138
+ agent,
139
+ concurrency: typeof c === "number" && Number.isInteger(c) && c >= 1 && c <= 16 ? c : DEFAULT_CONCURRENCY,
140
+ subagents: j.subagents !== false,
141
+ proactive: j.proactive === true,
142
+ chime: pick("chime", j.chime, bool, true, "true or false"),
143
+ capture: pick("capture", j.capture, (v) => v === "confirm" || v === "at-once", "confirm", `'confirm' or 'at-once'`),
144
+ loc: pick("loc", j.loc, bool, true, "true or false"),
145
+ names: pick("names", j.names, bool, true, "true or false"),
146
+ runner: pick("runner", j.runner, (v) => v === "auto" || v === "session" || v === "background", "auto", `'auto', 'session' or 'background'`),
147
+ session: pick("session", j.session, bool, true, "true or false"),
148
+ context: pick("context", j.context, (v) => v === "fork" || v === "fresh", "fork", `'fork' or 'fresh'`),
149
+ mcp: pick("mcp", j.mcp, bool, true, "true or false"),
150
+ skills: pick("skills", j.skills, bool, true, "true or false"),
151
+ others: pick("others", j.others, bool, false, "true or false"),
152
+ ...((sm) => sm === void 0 ? {} : { sessionMax: sm })(pick("sessionMax", j.sessionMax, (v) => typeof v === "number" && Number.isInteger(v) && v >= 1 && v <= 8, void 0, "a whole number from 1 to 8"))
153
+ };
154
+ }
155
+ /** Exactly one of `jam` (armed) or `jamOff` (why not) - so the dev server can speak up about
156
+ * the one off-state nothing has reported yet, and stay quiet about the rest. BOTH keys are
157
+ * always written: these spread over the user's own `jam`, and a raw `jam: false` reaching the
158
+ * server as config would arm the daemon against a truthy object check. */
159
+ function jamFields(v) {
160
+ const r = resolveJam(v);
161
+ return typeof r === "string" ? {
162
+ jam: void 0,
163
+ jamOff: r
164
+ } : {
165
+ jam: r,
166
+ jamOff: void 0
167
+ };
168
+ }
169
+ function validViewports(v) {
170
+ if (!v || typeof v !== "object") return null;
171
+ const out = {};
172
+ for (const [k, val] of Object.entries(v)) {
173
+ const vp = val;
174
+ if (validDim(vp?.width) && validDim(vp?.height)) out[k] = {
175
+ width: Math.round(vp.width),
176
+ height: Math.round(vp.height)
177
+ };
178
+ }
179
+ return Object.keys(out).length ? out : null;
180
+ }
181
+ //#endregion
182
+ export { loadConfig as n, config_exports as t };
@@ -0,0 +1,222 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
+ import { r as NAME } from "./cli.mjs";
3
+ import { chmodSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import { createHash, randomBytes } from "node:crypto";
6
+ //#region src/server/jam/conn.ts
7
+ /**
8
+ * The sessions connected to this repo (spec 29b, Part 3): one file per connection under
9
+ * design/.local/jam/conn/, written by the hooks (`marver jam hook`, `marver jam listen`) and read by
10
+ * the daemon. A connection is one Claude Code, Codex or Cursor session that can take Jam runs.
11
+ *
12
+ * Also the small shared state beside them: the offers file the daemon writes for each connection
13
+ * (what the Claude Code listener and the Stop hooks read), and this machine's Jam preferences (the
14
+ * start sheet's switches).
15
+ *
16
+ * Kept free of heavy imports: the hooks load this on every session start and every prompt.
17
+ */
18
+ var conn_exports = /* @__PURE__ */ __exportAll({
19
+ CONN_AGENTS: () => CONN_AGENTS,
20
+ CURSOR_SILENT_MS: () => CURSOR_SILENT_MS,
21
+ alive: () => alive,
22
+ closeConn: () => closeConn,
23
+ connDir: () => connDir,
24
+ connFile: () => connFile,
25
+ connId: () => connId,
26
+ eligible: () => eligible,
27
+ endConn: () => endConn,
28
+ jamDir: () => jamDir,
29
+ listConns: () => listConns,
30
+ offersFile: () => offersFile,
31
+ offersText: () => offersText,
32
+ patchConn: () => patchConn,
33
+ pidAlive: () => pidAlive,
34
+ pingLine: () => pingLine,
35
+ prefsFile: () => prefsFile,
36
+ readConn: () => readConn,
37
+ readOffers: () => readOffers,
38
+ readPrefs: () => readPrefs,
39
+ unlike: () => unlike,
40
+ upsertConn: () => upsertConn,
41
+ validConnId: () => validConnId,
42
+ writeAtomic: () => writeAtomic,
43
+ writeOffers: () => writeOffers,
44
+ writePrefs: () => writePrefs
45
+ });
46
+ const CONN_AGENTS = [
47
+ "claude",
48
+ "codex",
49
+ "cursor"
50
+ ];
51
+ const jamDir = (root) => join(root, "design", ".local", "jam");
52
+ const connDir = (root) => join(jamDir(root), "conn");
53
+ const connFile = (root, id) => join(connDir(root), `${id}.json`);
54
+ const offersFile = (root, id) => join(connDir(root), `${id}.offers`);
55
+ const prefsFile = (root) => join(jamDir(root), "prefs.json");
56
+ const CONN_ID = /^(claude|codex|cursor)-[0-9a-f]{12}$/;
57
+ const validConnId = (id) => typeof id === "string" && CONN_ID.test(id);
58
+ const connId = (agent, session) => `${agent}-${createHash("sha256").update(session).digest("hex").slice(0, 12)}`;
59
+ /** A Cursor session not heard from in this long is gone (Cursor has no process to look at). */
60
+ const CURSOR_SILENT_MS = 216e5;
61
+ /** Write a file whole or not at all: a reader never sees half of it. */
62
+ function writeAtomic(file, text, mode = 384) {
63
+ const tmp = `${file}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
64
+ writeFileSync(tmp, text, { mode });
65
+ try {
66
+ renameSync(tmp, file);
67
+ } catch (err) {
68
+ rmSync(tmp, { force: true });
69
+ throw err;
70
+ }
71
+ }
72
+ const ensureDir = (dir) => {
73
+ mkdirSync(dir, {
74
+ recursive: true,
75
+ mode: 448
76
+ });
77
+ try {
78
+ chmodSync(dir, 448);
79
+ } catch {}
80
+ };
81
+ function readConn(root, id) {
82
+ if (!validConnId(id)) return null;
83
+ try {
84
+ const c = JSON.parse(readFileSync(connFile(root, id), "utf8"));
85
+ return c && c.v === 1 && c.id === id && typeof c.key === "string" && typeof c.inc === "string" && CONN_AGENTS.includes(c.agent) ? c : null;
86
+ } catch {
87
+ return null;
88
+ }
89
+ }
90
+ function listConns(root) {
91
+ let names;
92
+ try {
93
+ names = readdirSync(connDir(root));
94
+ } catch {
95
+ return [];
96
+ }
97
+ return names.filter((n) => n.endsWith(".json")).map((n) => readConn(root, n.slice(0, -5))).filter((c) => !!c);
98
+ }
99
+ /** Register (or refresh) a session's connection. A refresh keeps its incarnation and key - the capability
100
+ * its commands sign with; `fresh` (a session starting, a listener taking over) begins a new incarnation with a
101
+ * new key, so nothing the last one held still signs. An ended connection comes back only fresh. */
102
+ function upsertConn(root, agent, session, patch, now = Date.now(), fresh = false) {
103
+ ensureDir(connDir(root));
104
+ const id = connId(agent, session);
105
+ const was0 = readConn(root, id);
106
+ const was = was0 && !fresh && !was0.ended ? was0 : null;
107
+ const known = Object.fromEntries(Object.entries(patch).filter(([, v]) => v !== void 0));
108
+ const c = {
109
+ ...was ?? {
110
+ cwd: root,
111
+ busy: false,
112
+ since: now,
113
+ key: randomBytes(32).toString("hex"),
114
+ inc: randomBytes(6).toString("hex")
115
+ },
116
+ ...known,
117
+ v: 1,
118
+ id,
119
+ agent,
120
+ session,
121
+ seen: now,
122
+ ...was ? {} : {
123
+ ended: void 0,
124
+ muted: void 0,
125
+ acted: was0?.acted
126
+ }
127
+ };
128
+ writeAtomic(connFile(root, id), JSON.stringify(c));
129
+ return c;
130
+ }
131
+ /** Change a live registration in place - that incarnation only, never one that ended, never a new one. */
132
+ function patchConn(root, id, inc, patch) {
133
+ const c = readConn(root, id);
134
+ if (!c || c.ended || c.inc !== inc) return false;
135
+ writeAtomic(connFile(root, id), JSON.stringify({
136
+ ...c,
137
+ ...patch,
138
+ seen: Date.now()
139
+ }));
140
+ return true;
141
+ }
142
+ /** A session ended (its end hook, its listener exiting): marked, not removed - a run it held is reconciled first;
143
+ * the daemon removes it once nothing depends on it. `inc`: only that incarnation (a resumed one stays). */
144
+ function endConn(root, id, inc) {
145
+ const c = readConn(root, id);
146
+ if (!c || c.ended || inc && c.inc !== inc) return;
147
+ writeAtomic(connFile(root, id), JSON.stringify({
148
+ ...c,
149
+ ended: true,
150
+ seen: Date.now()
151
+ }));
152
+ }
153
+ /** Remove a connection for good: its file and its offers go. */
154
+ function closeConn(root, id) {
155
+ if (!validConnId(id)) return;
156
+ rmSync(connFile(root, id), { force: true });
157
+ rmSync(offersFile(root, id), { force: true });
158
+ }
159
+ const pidAlive = (pid) => {
160
+ if (!pid || !Number.isInteger(pid) || pid <= 1) return false;
161
+ try {
162
+ process.kill(pid, 0);
163
+ return true;
164
+ } catch (err) {
165
+ return err.code === "EPERM";
166
+ }
167
+ };
168
+ const alive = (c, now = Date.now()) => !c.ended && (c.agent === "cursor" ? now - c.seen < 216e5 : pidAlive(c.pid));
169
+ /** Can this session take Jam work now? (The selection and the runner choice come after.) */
170
+ const eligible = (c, now = Date.now()) => alive(c, now) && !c.muted && c.mode !== "plan" && (c.agent !== "cursor" || !c.composer || c.composer === "agent");
171
+ const STOP_LINE = (handles, as) => `Live Jam: the owner moved ${handles.join(", ")} elsewhere - stop working on ${handles.length === 1 ? "it" : "them"} (a subagent of yours on ${handles.length === 1 ? "it" : "one"}: stop that subagent first, or tell it to stop and release it itself) and run ${handles.map((h) => `\`npx ${NAME} jam release ${h}${as ? ` --as ${as}` : ""}\``).join(", ")}.`;
172
+ const RESUME_LINE = (handles, as) => `Live Jam: the owner gave ${handles.join(", ")} back to you - carry on (a subagent of yours on ${handles.length === 1 ? "it" : "one"}: tell it to), and run ${handles.map((h) => `\`npx ${NAME} jam progress ${h}${as ? ` --as ${as}` : ""}\``).join(", ")}.`;
173
+ const READY_LINE = (n, as, latest) => `Live Jam: ${n === 1 ? "new request" : `${n} new requests`} from your Marver canvas${latest ? ` - ${n === 1 ? "" : "newest "}"${latest.title}" (${latest.id}${latest.overlaps ? `, overlaps your run ${latest.overlaps}` : ""})` : ""} - run \`npx ${NAME} jam next${as ? ` --as ${as}` : ""}\`${n === 1 ? "" : " for each"}.`;
174
+ /** What a session is told of its offers: the ready line, then any run it must let go or may carry on with. */
175
+ const offersText = (o, as) => [
176
+ o.n > 0 ? READY_LINE(o.n, as, o.latest) : "",
177
+ o.stop?.length ? STOP_LINE(o.stop, as) : "",
178
+ o.resume?.length ? RESUME_LINE(o.resume, as) : ""
179
+ ].filter(Boolean).join(" ");
180
+ /** `text`, unless it is the line posted before it - then that line's "(again)" count, one more. Claude Code drops a
181
+ * message identical to the one before it from the same sender, so the listener checks what it actually posted. */
182
+ function unlike(text, prev) {
183
+ if (!text || text !== prev) return text;
184
+ const m = /^(.*) \(again(?: ×(\d+))?\)$/s.exec(text);
185
+ const times = m ? Number(m[2] ?? 1) + 1 : 1;
186
+ return `${m ? m[1] : text} (again${times > 1 ? ` ×${times}` : ""})`;
187
+ }
188
+ /** The listener's line for a new gen: `offersText`, ending "(again)" when it reads as the line before it did (a run
189
+ * offered back, a second "give it back") - Claude Code drops a message identical to the one before it. */
190
+ function pingLine(o, prev) {
191
+ const text = offersText(o);
192
+ const m = /^(.*) \(again(?: ×(\d+))?\)$/s.exec(prev ?? "");
193
+ const times = (m ? m[1] : prev) === text ? Number(m?.[2] ?? (m ? 1 : 0)) + 1 : 0;
194
+ return times ? `${text} (again${times > 1 ? ` ×${times}` : ""})` : text;
195
+ }
196
+ function writeOffers(root, id, o) {
197
+ if (!validConnId(id)) return;
198
+ ensureDir(connDir(root));
199
+ writeAtomic(offersFile(root, id), JSON.stringify(o));
200
+ }
201
+ function readOffers(root, id) {
202
+ try {
203
+ const o = JSON.parse(readFileSync(offersFile(root, id), "utf8"));
204
+ return Number.isInteger(o?.n) && Number.isInteger(o?.gen) ? o : null;
205
+ } catch {
206
+ return null;
207
+ }
208
+ }
209
+ function readPrefs(root) {
210
+ try {
211
+ const p = JSON.parse(readFileSync(prefsFile(root), "utf8"));
212
+ return p && typeof p === "object" && !Array.isArray(p) ? p : {};
213
+ } catch {
214
+ return {};
215
+ }
216
+ }
217
+ function writePrefs(root, p) {
218
+ ensureDir(jamDir(root));
219
+ writeAtomic(prefsFile(root), JSON.stringify(p, null, 1));
220
+ }
221
+ //#endregion
222
+ export { writePrefs as C, writeOffers as S, readPrefs as _, conn_exports as a, validConnId as b, jamDir as c, offersText as d, patchConn as f, readOffers as g, readConn as h, connId as i, listConns as l, pingLine as m, closeConn as n, eligible as o, pidAlive as p, connDir as r, endConn as s, alive as t, offersFile as u, unlike as v, writeAtomic as x, upsertConn as y };
@@ -0,0 +1,290 @@
1
+ import { i as onPath } from "./agent-BsieQGTD.mjs";
2
+ import { C as writePrefs, _ as readPrefs, c as jamDir, x as writeAtomic } from "./conn-BMiHS42T.mjs";
3
+ import { existsSync, mkdirSync, readFileSync, statSync } from "node:fs";
4
+ import { dirname, isAbsolute, join } from "node:path";
5
+ import { spawnSync } from "node:child_process";
6
+ //#region src/server/jam/connectors.ts
7
+ /**
8
+ * Connectors (spec 29b, Part 2): the hooks that connect Claude Code, Codex and Cursor sessions in this
9
+ * repo to Live Jam - written by `marver init`, by `marver dev` at boot, and when a Jam session starts.
10
+ * The owner never writes them; they are what makes starting a Jam session the one switch.
11
+ *
12
+ * Every entry runs one command, `<repo>/node_modules/.bin/marver jam hook|listen ...`. The merge only
13
+ * ever touches Marver's own entries (recognised by that command), keeps every other key and hook, and
14
+ * leaves alone a file that does not parse, a file git tracks, and an entry the owner removed by hand.
15
+ */
16
+ /** Marver's own hook commands - how an entry is recognised as ours, whatever path it was written with. */
17
+ const OURS = /\bmarver(?:\.mjs)?["']?\s+jam\s+(?:hook|listen)\b/;
18
+ const FILES = {
19
+ claude: ".claude/settings.local.json",
20
+ codex: ".codex/hooks.json",
21
+ cursor: ".cursor/hooks.json"
22
+ };
23
+ /** The CLIs (and app) whose presence means the owner uses that tool here. */
24
+ const BINS = {
25
+ claude: ["claude"],
26
+ codex: ["codex"],
27
+ cursor: ["cursor-agent", "cursor"]
28
+ };
29
+ /** The marver the hooks run: the repo's own install (fast, no network). */
30
+ const hookBin = (root) => {
31
+ const bin = join(root, "node_modules", ".bin", "marver");
32
+ return existsSync(bin) ? bin : null;
33
+ };
34
+ const q = (s) => `"${s.replace(/(["\\$`])/g, "\\$1")}"`;
35
+ /** Every event's handlers, as Claude Code and Codex nest them: `hooks[event] = [{ matcher?, hooks: [handler] }]`. */
36
+ function mergeNested(file, want) {
37
+ const hooks = file.hooks && typeof file.hooks === "object" && !Array.isArray(file.hooks) ? { ...file.hooks } : {};
38
+ for (const ev of Object.keys(hooks)) {
39
+ if (!Array.isArray(hooks[ev])) continue;
40
+ hooks[ev] = hooks[ev].map((g) => g && Array.isArray(g.hooks) ? {
41
+ ...g,
42
+ hooks: g.hooks.filter((h) => !(typeof h?.command === "string" && OURS.test(h.command)))
43
+ } : g).filter((g) => !(g && Array.isArray(g.hooks) && g.hooks.length === 0));
44
+ if (!hooks[ev].length) delete hooks[ev];
45
+ }
46
+ for (const [ev, handlers] of Object.entries(want)) hooks[ev] = [...Array.isArray(hooks[ev]) ? hooks[ev] : [], { hooks: handlers }];
47
+ return {
48
+ ...file,
49
+ hooks
50
+ };
51
+ }
52
+ /** Cursor's flat shape: `hooks[event] = [{ command, ... }]`, with `version: 1`. */
53
+ function mergeFlat(file, want) {
54
+ const hooks = file.hooks && typeof file.hooks === "object" && !Array.isArray(file.hooks) ? { ...file.hooks } : {};
55
+ for (const ev of Object.keys(hooks)) {
56
+ if (!Array.isArray(hooks[ev])) continue;
57
+ hooks[ev] = hooks[ev].filter((h) => !(typeof h?.command === "string" && OURS.test(h.command)));
58
+ if (!hooks[ev].length) delete hooks[ev];
59
+ }
60
+ for (const [ev, entries] of Object.entries(want)) hooks[ev] = [...Array.isArray(hooks[ev]) ? hooks[ev] : [], ...entries];
61
+ return {
62
+ version: 1,
63
+ ...file,
64
+ hooks
65
+ };
66
+ }
67
+ /** Is any entry of ours in this file? (Each command looked at as written - in JSON its quotes are escaped.) */
68
+ const hasOurs = (file) => {
69
+ const cmds = [];
70
+ const walk = (v) => {
71
+ if (Array.isArray(v)) v.forEach(walk);
72
+ else if (v && typeof v === "object") for (const [k, x] of Object.entries(v)) if (k === "command" && typeof x === "string") cmds.push(x);
73
+ else walk(x);
74
+ };
75
+ walk(file.hooks);
76
+ return cmds.some((c) => OURS.test(c));
77
+ };
78
+ /** What each tool's file should hold, for this repo's marver. */
79
+ function wanted(agent, bin, root) {
80
+ const r = ` --root ${q(root)}`;
81
+ if (agent === "claude") {
82
+ const listen = {
83
+ type: "command",
84
+ command: `${q(bin)} jam listen${r}`,
85
+ async: true
86
+ };
87
+ return { nested: {
88
+ SessionStart: [listen],
89
+ UserPromptSubmit: [listen],
90
+ SessionEnd: [{
91
+ type: "command",
92
+ command: `${q(bin)} jam hook claude end${r}`,
93
+ timeout: 10
94
+ }]
95
+ } };
96
+ }
97
+ if (agent === "codex") {
98
+ const h = (ev) => ({
99
+ type: "command",
100
+ command: `${q(bin)} jam hook codex ${ev}${r}`,
101
+ timeout: 10
102
+ });
103
+ return { nested: {
104
+ SessionStart: [h("start")],
105
+ UserPromptSubmit: [h("prompt")],
106
+ Stop: [h("stop")],
107
+ SessionEnd: [h("end")]
108
+ } };
109
+ }
110
+ const h = (ev, extra = {}) => ({
111
+ command: `${q(bin)} jam hook cursor ${ev}${r}`,
112
+ timeout: 10,
113
+ ...extra
114
+ });
115
+ return { flat: {
116
+ sessionStart: [h("start")],
117
+ beforeSubmitPrompt: [h("prompt")],
118
+ stop: [h("stop", { loop_limit: 20 })],
119
+ sessionEnd: [h("end")]
120
+ } };
121
+ }
122
+ const git = (root, args) => spawnSync("git", [
123
+ "-C",
124
+ root,
125
+ ...args
126
+ ], {
127
+ encoding: "utf8",
128
+ timeout: 5e3
129
+ });
130
+ const inGit = (root) => git(root, ["rev-parse", "--git-dir"]).status === 0;
131
+ const tracked = (root, rel) => inGit(root) && git(root, [
132
+ "ls-files",
133
+ "--error-unmatch",
134
+ "--",
135
+ rel
136
+ ]).status === 0;
137
+ const ignored = (root, rel) => git(root, [
138
+ "check-ignore",
139
+ "-q",
140
+ "--",
141
+ rel
142
+ ]).status === 0;
143
+ /** Keep `rel` out of commits without touching a committed file: .git/info/exclude is local. */
144
+ function exclude(root, rel) {
145
+ if (!inGit(root) || ignored(root, rel)) return;
146
+ const r = git(root, [
147
+ "rev-parse",
148
+ "--git-path",
149
+ "info/exclude"
150
+ ]);
151
+ if (r.status !== 0) return;
152
+ const p = r.stdout.trim();
153
+ const file = isAbsolute(p) ? p : join(root, p);
154
+ const line = `/${rel.split("\\").join("/")}`;
155
+ let text = "";
156
+ try {
157
+ text = readFileSync(file, "utf8");
158
+ } catch {}
159
+ if (text.split("\n").some((l) => l.trim() === line)) return;
160
+ mkdirSync(dirname(file), { recursive: true });
161
+ writeAtomic(file, `${text}${text && !text.endsWith("\n") ? "\n" : ""}# marver: Live Jam's local hooks\n${line}\n`, 420);
162
+ }
163
+ const recordFile = (root) => join(jamDir(root), "connectors.json");
164
+ const readInstalled = (root) => {
165
+ try {
166
+ return JSON.parse(readFileSync(recordFile(root), "utf8"));
167
+ } catch {
168
+ return {};
169
+ }
170
+ };
171
+ const writeInstalled = (root, r) => {
172
+ mkdirSync(jamDir(root), {
173
+ recursive: true,
174
+ mode: 448
175
+ });
176
+ writeAtomic(recordFile(root), JSON.stringify(r, null, 1));
177
+ };
178
+ /** Is this tool used on this Mac (its CLI on PATH, or - Cursor - its app)? */
179
+ function present(agent, env = process.env) {
180
+ if (BINS[agent].some((b) => onPath(b, env))) return true;
181
+ return agent === "cursor" && existsSync("/Applications/Cursor.app");
182
+ }
183
+ /**
184
+ * Write the connectors this repo is missing. `force` (the start sheet turning a tool back on) writes
185
+ * one the owner had removed. Never throws: each tool's result says what happened.
186
+ */
187
+ function ensureConnectors(root, opts = {}) {
188
+ const env = opts.env ?? process.env;
189
+ const agents = opts.agents ?? [
190
+ "claude",
191
+ "codex",
192
+ "cursor"
193
+ ].filter((a) => present(a, env));
194
+ const bin = opts.bin === void 0 ? hookBin(root) : opts.bin;
195
+ const prefs = readPrefs(root);
196
+ const installed = readInstalled(root);
197
+ const out = [];
198
+ if (opts.force?.some((a) => prefs.off?.[a])) {
199
+ for (const a of opts.force) delete prefs.off?.[a];
200
+ try {
201
+ writePrefs(root, prefs);
202
+ } catch {}
203
+ }
204
+ for (const agent of agents) {
205
+ const rel = FILES[agent];
206
+ const file = join(root, rel);
207
+ const res = (state, note) => out.push({
208
+ agent,
209
+ file: rel,
210
+ state,
211
+ ...note ? { note } : {}
212
+ });
213
+ try {
214
+ if (prefs.off?.[agent] && !opts.force?.includes(agent)) {
215
+ res("off");
216
+ continue;
217
+ }
218
+ if (!bin) {
219
+ res("no-bin", "marver is not installed in this repo (node_modules/.bin/marver)");
220
+ continue;
221
+ }
222
+ let cur = {};
223
+ if (existsSync(file)) {
224
+ if (!statSync(file).isFile()) {
225
+ res("unreadable", `${rel} is not a file`);
226
+ continue;
227
+ }
228
+ try {
229
+ cur = JSON.parse(readFileSync(file, "utf8") || "{}");
230
+ } catch {
231
+ res("unreadable", `${rel} does not parse - left as it is`);
232
+ continue;
233
+ }
234
+ if (!cur || typeof cur !== "object" || Array.isArray(cur)) {
235
+ res("unreadable", `${rel} is not a JSON object - left as it is`);
236
+ continue;
237
+ }
238
+ }
239
+ if (tracked(root, rel)) {
240
+ res("tracked", `${rel} is committed to git - Marver never changes a committed file`);
241
+ continue;
242
+ }
243
+ if (installed[agent] && (!existsSync(file) || !hasOurs(cur)) && !opts.force?.includes(agent)) {
244
+ res("removed");
245
+ continue;
246
+ }
247
+ const w = wanted(agent, bin, root);
248
+ const next = w.nested ? mergeNested(cur, w.nested) : mergeFlat(cur, w.flat);
249
+ if (JSON.stringify(next) === JSON.stringify(cur)) {
250
+ exclude(root, rel);
251
+ res("present");
252
+ continue;
253
+ }
254
+ mkdirSync(dirname(file), { recursive: true });
255
+ writeAtomic(file, JSON.stringify(next, null, 2) + "\n", 420);
256
+ exclude(root, rel);
257
+ installed[agent] = {
258
+ file: rel,
259
+ at: Date.now()
260
+ };
261
+ res("installed");
262
+ } catch (err) {
263
+ res("failed", err.message);
264
+ }
265
+ }
266
+ try {
267
+ writeInstalled(root, installed);
268
+ } catch {}
269
+ return out;
270
+ }
271
+ /** One line for the dev server and init: what the connectors did, or nothing worth saying. */
272
+ function connectorLine(results) {
273
+ const name = {
274
+ claude: "Claude Code",
275
+ codex: "Codex",
276
+ cursor: "Cursor"
277
+ };
278
+ const made = results.filter((r) => r.state === "installed").map((r) => name[r.agent]);
279
+ const skipped = results.filter((r) => [
280
+ "tracked",
281
+ "unreadable",
282
+ "failed"
283
+ ].includes(r.state));
284
+ const parts = [];
285
+ if (made.length) parts.push(`jam: connected ${made.join(", ")} sessions in this repo - their hooks are in ${results.filter((r) => r.state === "installed").map((r) => r.file).join(", ")} (local, never committed)${results.some((r) => r.state === "installed" && r.agent === "codex") ? "; Codex asks you to trust them once (/hooks)" : ""}`);
286
+ for (const s of skipped) parts.push(`jam: ${name[s.agent]} not connected - ${s.note ?? s.state}`);
287
+ return parts.length ? parts.map((p) => ` ${p}`).join("\n") : null;
288
+ }
289
+ //#endregion
290
+ export { connectorLine, ensureConnectors, hookBin, present };