very-happy-cli 0.2.102 → 0.2.103

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 (33) hide show
  1. package/dist/{AcpBackend-C1nF06ZR.mjs → AcpBackend-C8CgzRI_.mjs} +1 -1
  2. package/dist/{AcpBackend-CpKkdwIL.cjs → AcpBackend-Zt10QM8S.cjs} +1 -1
  3. package/dist/{AcpSessionManager-BDad8lK3.mjs → AcpSessionManager-BAinHcHh.mjs} +1 -1
  4. package/dist/{AcpSessionManager-DjWIwGTR.cjs → AcpSessionManager-D_iGrEbD.cjs} +1 -1
  5. package/dist/{config-BlTfR0KA.mjs → config-11py0X-q.mjs} +2 -2
  6. package/dist/{config-DSF29tTS.cjs → config-CG4aqDiu.cjs} +2 -2
  7. package/dist/{index-DjYlt3fw.mjs → index-B9SnF1mG.mjs} +2 -2
  8. package/dist/{index-yLIv8JPD.cjs → index-B_soRPsA.cjs} +4 -4
  9. package/dist/{index-CPC-a5lH.mjs → index-BjDfS9DT.mjs} +5 -5
  10. package/dist/{index-D_2eCeep.cjs → index-CimI2p1M.cjs} +26 -20
  11. package/dist/{index-CF3rNFlZ.mjs → index-Dnma0J5k.mjs} +22 -16
  12. package/dist/{index-C8HuYyZq.cjs → index-VvPyRTet.cjs} +2 -2
  13. package/dist/index.cjs +2 -2
  14. package/dist/index.mjs +2 -2
  15. package/dist/{installTerminalHooks-BVMhXRZO.cjs → installTerminalHooks-BP9uu1Xn.cjs} +2 -2
  16. package/dist/{installTerminalHooks-DAR3YEo3.mjs → installTerminalHooks-UL5Zfif6.mjs} +2 -2
  17. package/dist/lib.cjs +1 -1
  18. package/dist/lib.d.cts +17 -0
  19. package/dist/lib.d.mts +17 -0
  20. package/dist/lib.mjs +1 -1
  21. package/dist/{mcp--I-Uz_wH.mjs → mcp-CxepBrGm.mjs} +2 -2
  22. package/dist/{mcp-LCZtdhF0.cjs → mcp-mX6g7PpH.cjs} +2 -2
  23. package/dist/{runGemini-Crna_6uM.cjs → runGemini-BPAUC7TY.cjs} +4 -4
  24. package/dist/{runGemini-cLR7rfj6.mjs → runGemini-Cxa0Tj_7.mjs} +4 -4
  25. package/dist/{runOpenClaw-C1u9xEH7.mjs → runOpenClaw-DMAn3-Hq.mjs} +3 -3
  26. package/dist/{runOpenClaw-CWjOCdWg.cjs → runOpenClaw-QJ8YzPvo.cjs} +3 -3
  27. package/dist/{send-CufsYMXq.cjs → send-CwRV7cbV.cjs} +2 -2
  28. package/dist/{send-BtQ9qf_z.mjs → send-D6NLQaYt.mjs} +2 -2
  29. package/dist/{spawn-rdb0uM9R.mjs → spawn-DIW1I72G.mjs} +2 -2
  30. package/dist/{spawn-DPllkoUN.cjs → spawn-Db22DkVT.cjs} +2 -2
  31. package/dist/{types-B3Dnzv_q.mjs → types-D9ORBxOD.mjs} +326 -105
  32. package/dist/{types-7-mfp-j5.cjs → types-DKO60j29.cjs} +328 -105
  33. package/package.json +7 -7
@@ -29,7 +29,7 @@ import { SandboxManager } from '@anthropic-ai/sandbox-runtime';
29
29
  import { Expo } from 'expo-server-sdk';
30
30
 
31
31
  var name = "very-happy-cli";
32
- var version = "0.2.102";
32
+ var version = "0.2.103";
33
33
  var description = "Remote multi-agent workspace CLI with deep Claude integration, native terminal streaming, and self-hosting.";
34
34
  var author = "Kirill Dubovitskiy";
35
35
  var contributors = [
@@ -142,12 +142,12 @@ var dependencies = {
142
142
  zod: "^4.0.0"
143
143
  };
144
144
  var optionalDependencies = {
145
- "very-happy-tools-arm64-darwin": "0.2.102",
146
- "very-happy-tools-x64-darwin": "0.2.102",
147
- "very-happy-tools-arm64-linux": "0.2.102",
148
- "very-happy-tools-x64-linux": "0.2.102",
149
- "very-happy-tools-arm64-win32": "0.2.102",
150
- "very-happy-tools-x64-win32": "0.2.102"
145
+ "very-happy-tools-arm64-darwin": "0.2.103",
146
+ "very-happy-tools-x64-darwin": "0.2.103",
147
+ "very-happy-tools-arm64-linux": "0.2.103",
148
+ "very-happy-tools-x64-linux": "0.2.103",
149
+ "very-happy-tools-arm64-win32": "0.2.103",
150
+ "very-happy-tools-x64-win32": "0.2.103"
151
151
  };
152
152
  var devDependencies = {
153
153
  "@slopus/happy-wire": "workspace:*",
@@ -1105,6 +1105,15 @@ z$1.object({
1105
1105
  /** B-282: `kill-terminal` honours `alsoAttached`. */
1106
1106
  killAttached: z$1.boolean().optional()
1107
1107
  }).optional(),
1108
+ /**
1109
+ * B-290 capability flag: this daemon answers `claude-list-history` (import a
1110
+ * Claude Code conversation that was never started through very-happy).
1111
+ * Same trust rule (`detectedAt >= startedAt`).
1112
+ */
1113
+ claudeHistory: z$1.object({
1114
+ rpcAvailable: z$1.boolean(),
1115
+ detectedAt: z$1.number()
1116
+ }).optional(),
1108
1117
  /** Relay-owned CLI compatibility/update policy last checked by this daemon. */
1109
1118
  cliUpdate: CliUpdateStateSchema.optional(),
1110
1119
  /**
@@ -2094,102 +2103,66 @@ function registerCommonHandlers(rpcHandlerManager, workingDirectory) {
2094
2103
  }
2095
2104
 
2096
2105
  const PRICING = {
2097
- // --- Claude 4 & Future Models ---
2098
- "claude-4.5-opus": {
2099
- input: 5,
2100
- output: 25,
2101
- cache_write: 6.25,
2102
- cache_read: 0.5
2103
- },
2104
- "claude-4.1-opus": {
2105
- input: 15,
2106
- output: 75,
2107
- cache_write: 18.75,
2108
- cache_read: 1.5
2109
- },
2110
- "claude-4-opus": {
2111
- input: 15,
2112
- output: 75,
2113
- cache_write: 18.75,
2114
- cache_read: 1.5
2115
- },
2116
- "claude-4.5-sonnet": {
2117
- input: 3,
2118
- output: 15,
2119
- cache_write: 3.75,
2120
- cache_read: 0.3
2121
- },
2122
- "claude-4-sonnet": {
2123
- input: 3,
2124
- output: 15,
2125
- cache_write: 3.75,
2126
- cache_read: 0.3
2127
- },
2128
- "claude-4.5-haiku": {
2129
- input: 1,
2130
- output: 5,
2131
- cache_write: 1.25,
2132
- cache_read: 0.1
2133
- },
2106
+ // --- Claude Fable / Mythos (same tier, same price) ---
2107
+ "claude-fable-5-1": { input: 10, output: 50, cache_write: 12.5, cache_read: 0.25 },
2108
+ "claude-fable-5": { input: 10, output: 50, cache_write: 12.5, cache_read: 1 },
2109
+ "claude-mythos-5-1": { input: 10, output: 50, cache_write: 12.5, cache_read: 0.25 },
2110
+ "claude-mythos-5": { input: 10, output: 50, cache_write: 12.5, cache_read: 1 },
2111
+ // --- Claude 5 ---
2112
+ "claude-opus-5": { input: 5, output: 25, cache_write: 6.25, cache_read: 0.5 },
2113
+ "claude-sonnet-5": { input: 2, output: 10, cache_write: 2.5, cache_read: 0.2 },
2114
+ // --- Claude 4.x ---
2115
+ "claude-opus-4-8": { input: 5, output: 25, cache_write: 6.25, cache_read: 0.5 },
2116
+ "claude-opus-4-7": { input: 5, output: 25, cache_write: 6.25, cache_read: 0.5 },
2117
+ "claude-opus-4-6": { input: 5, output: 25, cache_write: 6.25, cache_read: 0.5 },
2118
+ "claude-opus-4-5": { input: 5, output: 25, cache_write: 6.25, cache_read: 0.5 },
2119
+ "claude-opus-4-1": { input: 15, output: 75, cache_write: 18.75, cache_read: 1.5 },
2120
+ "claude-opus-4": { input: 15, output: 75, cache_write: 18.75, cache_read: 1.5 },
2121
+ "claude-sonnet-4-6": { input: 3, output: 15, cache_write: 3.75, cache_read: 0.3 },
2122
+ "claude-sonnet-4-5": { input: 3, output: 15, cache_write: 3.75, cache_read: 0.3 },
2123
+ "claude-sonnet-4": { input: 3, output: 15, cache_write: 3.75, cache_read: 0.3 },
2124
+ "claude-haiku-4-5": { input: 1, output: 5, cache_write: 1.25, cache_read: 0.1 },
2134
2125
  // --- Legacy / Claude 3 ---
2135
- "claude-3-opus-20240229": {
2136
- input: 15,
2137
- output: 75,
2138
- cache_write: 18.75,
2139
- cache_read: 1.5
2140
- },
2141
- "claude-3-sonnet-20240229": {
2142
- input: 3,
2143
- output: 15,
2144
- cache_write: 3.75,
2145
- cache_read: 0.3
2146
- },
2147
- "claude-3-5-sonnet-20240620": {
2148
- input: 3,
2149
- output: 15,
2150
- cache_write: 3.75,
2151
- cache_read: 0.3
2152
- },
2153
- // New Sonnet 3.5 updated model
2154
- "claude-3-5-sonnet-20241022": {
2155
- input: 3,
2156
- output: 15,
2157
- cache_write: 3.75,
2158
- cache_read: 0.3
2159
- },
2160
- "claude-3-haiku-20240307": {
2161
- input: 0.25,
2162
- output: 1.25,
2163
- cache_write: 0.3125,
2164
- cache_read: 0.025
2165
- },
2166
- "claude-3-5-haiku-20241022": {
2167
- input: 0.8,
2168
- output: 4,
2169
- cache_write: 1,
2170
- // Approx based on 1.25x rule usually or custom
2171
- cache_read: 0.08
2172
- }
2126
+ "claude-3-opus-20240229": { input: 15, output: 75, cache_write: 18.75, cache_read: 1.5 },
2127
+ "claude-3-sonnet-20240229": { input: 3, output: 15, cache_write: 3.75, cache_read: 0.3 },
2128
+ "claude-3-5-sonnet-20240620": { input: 3, output: 15, cache_write: 3.75, cache_read: 0.3 },
2129
+ "claude-3-5-sonnet-20241022": { input: 3, output: 15, cache_write: 3.75, cache_read: 0.3 },
2130
+ "claude-3-7-sonnet-20250219": { input: 3, output: 15, cache_write: 3.75, cache_read: 0.3 },
2131
+ "claude-3-haiku-20240307": { input: 0.25, output: 1.25, cache_write: 0.3125, cache_read: 0.025 },
2132
+ "claude-3-5-haiku-20241022": { input: 0.8, output: 4, cache_write: 1, cache_read: 0.08 }
2133
+ };
2134
+ const DEFAULT_MODEL = "claude-opus-5";
2135
+ const FAMILY_DEFAULTS = {
2136
+ fable: "claude-fable-5-1",
2137
+ // Project Glasswing counterpart of Fable: same tier, same published rates.
2138
+ mythos: "claude-mythos-5-1",
2139
+ opus: "claude-opus-5",
2140
+ sonnet: "claude-sonnet-5",
2141
+ haiku: "claude-haiku-4-5"
2173
2142
  };
2174
- const DEFAULT_MODEL = "claude-3-5-sonnet-20241022";
2143
+ function resolvePricingKey(modelId) {
2144
+ if (!modelId) return DEFAULT_MODEL;
2145
+ const raw = modelId.trim().toLowerCase();
2146
+ if (raw in PRICING) return raw;
2147
+ const id = raw.replace(/\[1m\]$/, "");
2148
+ if (id in PRICING) return id;
2149
+ const family = ["fable", "mythos", "opus", "sonnet", "haiku"].find((f) => id.includes(f));
2150
+ if (!family) return DEFAULT_MODEL;
2151
+ const version = id.match(/(?:^|[^0-9])(\d)(?:[-._](\d))?(?:[^0-9]|$)/);
2152
+ const major = version ? version[1] : null;
2153
+ const minor = version && version[2] ? version[2] : null;
2154
+ const key = major ? `claude-${family}-${major}${minor ? `-${minor}` : ""}` : null;
2155
+ if (key && key in PRICING) return key;
2156
+ if (major === "3" && family !== "fable" && family !== "mythos") {
2157
+ if (family === "opus") return "claude-3-opus-20240229";
2158
+ if (family === "haiku") return minor === "5" ? "claude-3-5-haiku-20241022" : "claude-3-haiku-20240307";
2159
+ if (minor === "7") return "claude-3-7-sonnet-20250219";
2160
+ return minor === "5" ? "claude-3-5-sonnet-20241022" : "claude-3-sonnet-20240229";
2161
+ }
2162
+ return FAMILY_DEFAULTS[family];
2163
+ }
2175
2164
  function calculateCost(usage, modelId) {
2176
- let pricing = PRICING[modelId];
2177
- if (!pricing) {
2178
- if (modelId?.includes("opus")) {
2179
- if (modelId.includes("4.5")) pricing = PRICING["claude-4.5-opus"];
2180
- else if (modelId.includes("4.1")) pricing = PRICING["claude-4.1-opus"];
2181
- else if (modelId.includes("4")) pricing = PRICING["claude-4-opus"];
2182
- else pricing = PRICING["claude-3-opus-20240229"];
2183
- } else if (modelId?.includes("sonnet")) {
2184
- if (modelId.includes("4.5")) pricing = PRICING["claude-4.5-sonnet"];
2185
- else if (modelId.includes("4")) pricing = PRICING["claude-4-sonnet"];
2186
- else pricing = PRICING["claude-3-5-sonnet-20241022"];
2187
- } else if (modelId?.includes("haiku")) {
2188
- if (modelId.includes("4.5")) pricing = PRICING["claude-4.5-haiku"];
2189
- else if (modelId.includes("3.5")) pricing = PRICING["claude-3-5-haiku-20241022"];
2190
- else pricing = PRICING["claude-3-haiku-20240307"];
2191
- } else pricing = PRICING[DEFAULT_MODEL];
2192
- }
2165
+ const pricing = PRICING[resolvePricingKey(modelId)];
2193
2166
  const inputCost = usage.input_tokens / 1e6 * pricing.input;
2194
2167
  const outputCost = usage.output_tokens / 1e6 * pricing.output;
2195
2168
  const cacheWriteCost = (usage.cache_creation_input_tokens || 0) / 1e6 * pricing.cache_write;
@@ -4034,6 +4007,7 @@ function summarizeSpawnSessionForLog(value) {
4034
4007
  environmentVariableNames: Object.keys(environmentVariables).sort(),
4035
4008
  resumesClaude: typeof input.resumeClaudeSessionId === "string" && input.resumeClaudeSessionId.length > 0,
4036
4009
  resumesCodex: typeof input.resumeCodexThreadId === "string" && input.resumeCodexThreadId.length > 0,
4010
+ importsClaude: typeof input.importedFromClaudeSessionId === "string" && input.importedFromClaudeSessionId.length > 0,
4037
4011
  forceNew: input.forceNew === true,
4038
4012
  ...typeof input.permissionMode === "string" ? { permissionMode: input.permissionMode } : {}
4039
4013
  };
@@ -4983,10 +4957,15 @@ function scrubTmuxClientEnv(env) {
4983
4957
  return env;
4984
4958
  }
4985
4959
 
4960
+ function getClaudeConfigDir() {
4961
+ return process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude");
4962
+ }
4963
+ function getClaudeProjectsRoot() {
4964
+ return join(getClaudeConfigDir(), "projects");
4965
+ }
4986
4966
  function getProjectPath(workingDirectory) {
4987
4967
  const projectId = resolve$1(workingDirectory).replace(/[^a-zA-Z0-9-]/g, "-");
4988
- const claudeConfigDir = process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude");
4989
- return join(claudeConfigDir, "projects", projectId);
4968
+ return join(getClaudeProjectsRoot(), projectId);
4990
4969
  }
4991
4970
 
4992
4971
  var xtermHeadless = {};
@@ -12569,6 +12548,182 @@ function detectResumeSupport(happyHomeDir = configuration.happyHomeDir) {
12569
12548
  };
12570
12549
  }
12571
12550
 
12551
+ const TITLE_PROMPT_PREFIX = "Summarize the SPECIFIC topic/request of this message into a 3-6 word title";
12552
+ const BOARD_ANALYZER_PROMPT_PREFIX = "You are a status analyzer for a task board of coding-agent sessions.";
12553
+ const VERY_HAPPY_ONE_SHOT_PROMPT_PREFIXES = [
12554
+ TITLE_PROMPT_PREFIX,
12555
+ BOARD_ANALYZER_PROMPT_PREFIX
12556
+ ];
12557
+ function isVeryHappyOneShotPrompt(firstPrompt) {
12558
+ const text = firstPrompt.trimStart();
12559
+ return VERY_HAPPY_ONE_SHOT_PROMPT_PREFIXES.some((prefix) => text.startsWith(prefix));
12560
+ }
12561
+
12562
+ const UUID_RE$1 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
12563
+ async function listClaudeProjectDirs(projectsRoot) {
12564
+ let names;
12565
+ try {
12566
+ names = await readdir$1(projectsRoot);
12567
+ } catch (error) {
12568
+ if (error.code === "ENOENT") return [];
12569
+ throw error;
12570
+ }
12571
+ const dirs = [];
12572
+ for (const name of names) {
12573
+ const full = join(projectsRoot, name);
12574
+ try {
12575
+ if ((await stat$1(full)).isDirectory()) dirs.push(full);
12576
+ } catch {
12577
+ }
12578
+ }
12579
+ return dirs;
12580
+ }
12581
+ async function collectCandidates(projectDirs, exclude) {
12582
+ const out = [];
12583
+ for (const dir of projectDirs) {
12584
+ let names;
12585
+ try {
12586
+ names = await readdir$1(dir);
12587
+ } catch {
12588
+ continue;
12589
+ }
12590
+ for (const name of names) {
12591
+ if (!name.endsWith(".jsonl")) continue;
12592
+ const id = name.slice(0, -".jsonl".length);
12593
+ if (!UUID_RE$1.test(id) || exclude.has(id.toLowerCase())) continue;
12594
+ const path = join(dir, name);
12595
+ try {
12596
+ const s = await stat$1(path);
12597
+ if (!s.isFile() || s.size === 0) continue;
12598
+ out.push({ path, id, updatedAt: s.mtimeMs, sizeBytes: s.size });
12599
+ } catch {
12600
+ }
12601
+ }
12602
+ }
12603
+ out.sort((a, b) => b.updatedAt - a.updatedAt);
12604
+ const seen = /* @__PURE__ */ new Set();
12605
+ return out.filter((c) => {
12606
+ const key = c.id.toLowerCase();
12607
+ if (seen.has(key)) return false;
12608
+ seen.add(key);
12609
+ return true;
12610
+ });
12611
+ }
12612
+ async function readHead(path, bytes) {
12613
+ const fh = await open(path, "r");
12614
+ try {
12615
+ const buffer = Buffer.alloc(bytes);
12616
+ const { bytesRead } = await fh.read(buffer, 0, bytes, 0);
12617
+ return buffer.subarray(0, bytesRead).toString("utf-8");
12618
+ } finally {
12619
+ await fh.close();
12620
+ }
12621
+ }
12622
+ function oneLine(text, max) {
12623
+ const collapsed = text.replace(/\s+/g, " ").trim();
12624
+ return collapsed.length > max ? `${collapsed.slice(0, max - 1)}\u2026` : collapsed;
12625
+ }
12626
+ function parseTimestamp(raw) {
12627
+ if (typeof raw === "number" && Number.isFinite(raw)) return raw;
12628
+ if (typeof raw === "string") {
12629
+ const t = Date.parse(raw);
12630
+ if (Number.isFinite(t)) return t;
12631
+ }
12632
+ return null;
12633
+ }
12634
+ function parseClaudeHistoryHead(head, promptChars) {
12635
+ let cwd;
12636
+ let firstPrompt;
12637
+ let summary;
12638
+ let startedAt = null;
12639
+ let entrypoint;
12640
+ let gitBranch;
12641
+ let version;
12642
+ const lines = head.split("\n");
12643
+ for (const line of lines) {
12644
+ if (line.length === 0) continue;
12645
+ let parsed;
12646
+ try {
12647
+ parsed = JSON.parse(line);
12648
+ } catch {
12649
+ continue;
12650
+ }
12651
+ if (!parsed || typeof parsed !== "object") continue;
12652
+ if (parsed.type === "summary" && typeof parsed.summary === "string" && !summary) {
12653
+ const s = oneLine(parsed.summary, promptChars);
12654
+ if (s) summary = s;
12655
+ continue;
12656
+ }
12657
+ if (typeof parsed.cwd === "string" && parsed.cwd && !cwd) cwd = parsed.cwd;
12658
+ if (typeof parsed.entrypoint === "string" && parsed.entrypoint && !entrypoint) entrypoint = parsed.entrypoint;
12659
+ if (typeof parsed.gitBranch === "string" && parsed.gitBranch && !gitBranch) gitBranch = parsed.gitBranch;
12660
+ if (typeof parsed.version === "string" && parsed.version && !version) version = parsed.version;
12661
+ if (startedAt === null) startedAt = parseTimestamp(parsed.timestamp);
12662
+ if (!firstPrompt && parsed.type === "user" && !parsed.isSidechain) {
12663
+ const content = parsed.message?.content;
12664
+ let text = null;
12665
+ if (typeof content === "string") {
12666
+ text = content;
12667
+ } else if (Array.isArray(content)) {
12668
+ const block = content.find((b) => b && b.type === "text" && typeof b.text === "string");
12669
+ if (block) text = block.text;
12670
+ }
12671
+ if (text) {
12672
+ if (isVeryHappyOneShotPrompt(text)) return null;
12673
+ const cleaned = oneLine(stripHarnessTags(text), promptChars);
12674
+ if (cleaned) firstPrompt = cleaned;
12675
+ }
12676
+ }
12677
+ if (cwd && firstPrompt && summary !== void 0 && startedAt !== null) break;
12678
+ }
12679
+ if (!cwd) return null;
12680
+ if (!firstPrompt && !summary) return null;
12681
+ return {
12682
+ cwd,
12683
+ firstPrompt: firstPrompt ?? summary ?? "",
12684
+ ...summary ? { summary } : {},
12685
+ startedAt: startedAt ?? 0,
12686
+ ...entrypoint ? { entrypoint } : {},
12687
+ ...gitBranch ? { gitBranch } : {},
12688
+ ...version ? { version } : {}
12689
+ };
12690
+ }
12691
+ function stripHarnessTags(text) {
12692
+ return text.replace(/<(system-reminder|task-notification|command-message|command-name|command-args|local-command-stdout|local-command-caveat)>[\s\S]*?<\/\1>/g, " ").replace(/<\/?(system-reminder|task-notification)>/g, " ");
12693
+ }
12694
+ async function listClaudeSessionHistory(options) {
12695
+ const limit = Math.max(1, Math.min(options.limit ?? 60, 500));
12696
+ const headBytes = Math.max(4096, options.headBytes ?? 64 * 1024);
12697
+ const promptChars = Math.max(20, options.promptChars ?? 200);
12698
+ const exclude = new Set(Array.from(options.exclude ?? [], (id) => id.toLowerCase()));
12699
+ const candidates = await collectCandidates(options.projectDirs, exclude);
12700
+ const entries = [];
12701
+ let scanned = 0;
12702
+ let truncated = false;
12703
+ for (const candidate of candidates) {
12704
+ if (entries.length >= limit) {
12705
+ truncated = true;
12706
+ break;
12707
+ }
12708
+ scanned += 1;
12709
+ let head;
12710
+ try {
12711
+ head = await readHead(candidate.path, headBytes);
12712
+ } catch {
12713
+ continue;
12714
+ }
12715
+ const parsed = parseClaudeHistoryHead(head, promptChars);
12716
+ if (!parsed) continue;
12717
+ entries.push({
12718
+ claudeSessionId: candidate.id.toLowerCase(),
12719
+ updatedAt: Math.round(candidate.updatedAt),
12720
+ sizeBytes: candidate.sizeBytes,
12721
+ ...parsed
12722
+ });
12723
+ }
12724
+ return { entries, truncated, scanned };
12725
+ }
12726
+
12572
12727
  class ForkTruncateUuidNotFoundError extends Error {
12573
12728
  constructor(cutAfterUuid, sourcePath) {
12574
12729
  super(`Truncation UUID ${cutAfterUuid} not found in ${sourcePath}`);
@@ -12593,6 +12748,16 @@ function isUserPrompt(parsed) {
12593
12748
  const content = parsed.message?.content;
12594
12749
  return typeof content === "string";
12595
12750
  }
12751
+ async function discardForkedSession(projectDir, claudeSessionId) {
12752
+ try {
12753
+ await unlink$1(jsonlPath(projectDir, claudeSessionId));
12754
+ logger.debug(`[CLAUDE FORK] Discarded unused fork ${claudeSessionId}`);
12755
+ } catch (error) {
12756
+ if (error.code !== "ENOENT") {
12757
+ logger.debug(`[CLAUDE FORK] Failed to discard fork ${claudeSessionId}:`, error);
12758
+ }
12759
+ }
12760
+ }
12596
12761
  async function forkSession(projectDir, sourceClaudeSessionId) {
12597
12762
  const newId = randomUUID$1();
12598
12763
  const src = jsonlPath(projectDir, sourceClaudeSessionId);
@@ -14189,12 +14354,12 @@ class ApiMachineClient {
14189
14354
  this.stopSessionHandler = stopSession;
14190
14355
  this.listTrackedSessionIds = listTrackedSessionIds ?? null;
14191
14356
  this.rpcHandlerManager.registerHandler("spawn-happy-session", async (params) => {
14192
- const { directory, sessionId, machineId, approvedNewDirectoryCreation, agent, environmentVariables, token, resumeClaudeSessionId, resumeCodexThreadId, parentSessionId, forkedFromMessageId, variant, forceNew, permissionMode } = params || {};
14357
+ const { directory, sessionId, machineId, approvedNewDirectoryCreation, agent, environmentVariables, token, resumeClaudeSessionId, resumeCodexThreadId, parentSessionId, forkedFromMessageId, importedFromClaudeSessionId, variant, forceNew, permissionMode } = params || {};
14193
14358
  logger.debug("[API MACHINE] Spawning session:", summarizeSpawnSessionForLog(params));
14194
14359
  if (!directory && variant !== "assistant") {
14195
14360
  throw new Error("Directory is required");
14196
14361
  }
14197
- const result = await spawnSession({ directory: directory || "", sessionId, machineId, approvedNewDirectoryCreation, agent, environmentVariables, token, resumeClaudeSessionId, resumeCodexThreadId, parentSessionId, forkedFromMessageId, variant: variant === "assistant" ? "assistant" : void 0, forceNew: forceNew === true, permissionMode: typeof permissionMode === "string" ? permissionMode : void 0 });
14362
+ const result = await spawnSession({ directory: directory || "", sessionId, machineId, approvedNewDirectoryCreation, agent, environmentVariables, token, resumeClaudeSessionId, resumeCodexThreadId, parentSessionId, forkedFromMessageId, importedFromClaudeSessionId: typeof importedFromClaudeSessionId === "string" ? importedFromClaudeSessionId : void 0, variant: variant === "assistant" ? "assistant" : void 0, forceNew: forceNew === true, permissionMode: typeof permissionMode === "string" ? permissionMode : void 0 });
14198
14363
  switch (result.type) {
14199
14364
  case "success":
14200
14365
  logger.debug(`[API MACHINE] Spawned session ${result.sessionId}`);
@@ -14206,6 +14371,46 @@ class ApiMachineClient {
14206
14371
  throw new Error(result.errorMessage);
14207
14372
  }
14208
14373
  });
14374
+ this.rpcHandlerManager.registerHandler("claude-import-session", async (params) => {
14375
+ const { directory, claudeSessionId, approvedNewDirectoryCreation, permissionMode } = params || {};
14376
+ if (typeof directory !== "string" || directory.length === 0) {
14377
+ throw new Error("directory is required");
14378
+ }
14379
+ if (typeof claudeSessionId !== "string" || !UUID_RE.test(claudeSessionId)) {
14380
+ throw new Error("claudeSessionId must be a valid UUID");
14381
+ }
14382
+ const projectDir = getProjectPath(directory);
14383
+ let newClaudeSessionId;
14384
+ try {
14385
+ newClaudeSessionId = await forkSession(projectDir, claudeSessionId);
14386
+ } catch (error) {
14387
+ if (error instanceof ForkSourceMissingError) {
14388
+ throw new Error("Claude session file not found on this machine");
14389
+ }
14390
+ throw error;
14391
+ }
14392
+ let result;
14393
+ try {
14394
+ result = await spawnSession({
14395
+ directory,
14396
+ machineId: this.machine.id,
14397
+ approvedNewDirectoryCreation: approvedNewDirectoryCreation === true,
14398
+ agent: "claude",
14399
+ resumeClaudeSessionId: newClaudeSessionId,
14400
+ importedFromClaudeSessionId: claudeSessionId,
14401
+ permissionMode: typeof permissionMode === "string" ? permissionMode : void 0
14402
+ });
14403
+ } catch (error) {
14404
+ await discardForkedSession(projectDir, newClaudeSessionId);
14405
+ throw error;
14406
+ }
14407
+ if (result.type !== "success") {
14408
+ await discardForkedSession(projectDir, newClaudeSessionId);
14409
+ return result;
14410
+ }
14411
+ logger.debug(`[API MACHINE] Imported Claude conversation ${claudeSessionId} as session ${result.sessionId}`);
14412
+ return { type: "success", sessionId: result.sessionId, newClaudeSessionId };
14413
+ });
14209
14414
  this.syncResumeSessionRpcRegistration();
14210
14415
  this.syncRestartSessionRpcRegistration();
14211
14416
  this.rpcHandlerManager.registerHandler("open-terminal", async (params) => {
@@ -14397,6 +14602,20 @@ class ApiMachineClient {
14397
14602
  throw error;
14398
14603
  }
14399
14604
  });
14605
+ this.rpcHandlerManager.registerHandler("claude-list-history", async (params) => {
14606
+ const { directory, limit, exclude } = params || {};
14607
+ if (directory !== void 0 && (typeof directory !== "string" || directory.length === 0)) {
14608
+ throw new Error("directory must be a non-empty string when provided");
14609
+ }
14610
+ const projectDirs = typeof directory === "string" ? [getProjectPath(directory)] : await listClaudeProjectDirs(getClaudeProjectsRoot());
14611
+ const excludeIds = Array.isArray(exclude) ? exclude.filter((id) => typeof id === "string" && UUID_RE.test(id)) : [];
14612
+ const result = await listClaudeSessionHistory({
14613
+ projectDirs,
14614
+ limit: typeof limit === "number" && Number.isFinite(limit) ? Math.max(1, Math.min(Math.floor(limit), 200)) : 60,
14615
+ exclude: excludeIds
14616
+ });
14617
+ return { type: "success", ...result };
14618
+ });
14400
14619
  this.rpcHandlerManager.registerHandler("codex-fork-thread", async (params) => {
14401
14620
  const directory = requireNonEmptyString(params?.directory, "directory");
14402
14621
  const codexThreadId = requireNonEmptyString(params?.codexThreadId, "codexThreadId");
@@ -14694,6 +14913,8 @@ class ApiMachineClient {
14694
14913
  terminalRestore: { rpcAvailable: true, detectedAt: now },
14695
14914
  // B-273 capability flag (same restamp discipline).
14696
14915
  tmuxSessions: { rpcAvailable: true, detectedAt: now, killAttached: true },
14916
+ // B-290 capability flag: `claude-list-history` (same restamp discipline).
14917
+ claudeHistory: { rpcAvailable: true, detectedAt: now },
14697
14918
  // B-084: closed records survive daemon restarts (persisted
14698
14919
  // in closed-terminals.json), so the connect snapshot ships
14699
14920
  // them too — not just the incremental pushes.
@@ -16035,4 +16256,4 @@ const RawJSONLinesSchema = z$1.discriminatedUnion("type", [
16035
16256
  }).passthrough()
16036
16257
  ]);
16037
16258
 
16038
- export { detectResumeSupport as $, ApiClient as A, deriveLocalCliUpdateSummary as B, updateSettings as C, encodeBase64Url as D, decodeBase64 as E, writeCredentialsLegacy as F, writeCredentialsDataKey as G, readCredentialsForConfiguredRelay as H, InvalidateSync as I, encrypt as J, isClaudeSessionId as K, getLocalHappyAgentCredentialPath as L, MAX_CHAT_ATTACHMENT_SOURCE_BYTES as M, readLocalHappyAgentCredentials as N, decryptWithDataKey as O, decryptLegacy as P, extractCompleteLines as Q, RawJSONLinesSchema as R, decideBackfill as S, parseTerminalHookPayload as T, tmuxArgs as U, scrubTmuxClientEnv as V, decideMirrorBinding as W, MIRROR_BACKFILL_LINES_DEFAULT as X, persistSession as Y, mirrorLineKey as Z, mirrorLocalId as _, ApiSessionClient as a, detectCLIAvailability as a0, acquireDaemonLock as a1, summarizeSpawnSessionForLog as a2, deletePersistedSessions as a3, shellescape as a4, decrypt as a5, writeDaemonState as a6, writeSettings as a7, fetchCliUpdateState as a8, resolveCliUpdateCheckInterval as a9, DEFAULT_CLI_UPDATE_CHECK_INTERVAL_MS as aa, releaseDaemonLock as ab, isValidSessionId as ac, listVhTerminals as ad, isValidTerminalId as ae, readVhTerminal as af, sendToVhTerminal as ag, startOfflineReconnection as ah, clearCredentials as ai, clearMachineId as aj, SandboxConfigSchema as ak, CodexAppServerClient as al, getLatestDaemonLog as am, persistence as an, api as ao, createEnvelope as b, configuration as c, contentLogMetadata as d, errorLogMetadata as e, packageJson as f, delay as g, connectionState as h, readSettings as i, encodeBase64 as j, ensurePrivateDirectorySync as k, logger as l, hardenPrivateFileSync as m, readDaemonState as n, clearDaemonState as o, projectPath as p, getProjectPath as q, readPersistedSessions as r, initializeSandbox as s, wrapCommand as t, AsyncLock as u, ensurePrivateDirectory as v, writePrivateFileSync as w, hardenPrivateFile as x, readCredentials as y, credentialRelayProblem as z };
16259
+ export { detectResumeSupport as $, ApiClient as A, deriveLocalCliUpdateSummary as B, updateSettings as C, encodeBase64Url as D, decodeBase64 as E, writeCredentialsLegacy as F, writeCredentialsDataKey as G, readCredentialsForConfiguredRelay as H, InvalidateSync as I, encrypt as J, isClaudeSessionId as K, getLocalHappyAgentCredentialPath as L, MAX_CHAT_ATTACHMENT_SOURCE_BYTES as M, readLocalHappyAgentCredentials as N, decryptWithDataKey as O, decryptLegacy as P, extractCompleteLines as Q, RawJSONLinesSchema as R, decideBackfill as S, parseTerminalHookPayload as T, tmuxArgs as U, scrubTmuxClientEnv as V, decideMirrorBinding as W, MIRROR_BACKFILL_LINES_DEFAULT as X, persistSession as Y, mirrorLineKey as Z, mirrorLocalId as _, ApiSessionClient as a, detectCLIAvailability as a0, acquireDaemonLock as a1, summarizeSpawnSessionForLog as a2, deletePersistedSessions as a3, shellescape as a4, decrypt as a5, writeDaemonState as a6, writeSettings as a7, fetchCliUpdateState as a8, resolveCliUpdateCheckInterval as a9, DEFAULT_CLI_UPDATE_CHECK_INTERVAL_MS as aa, releaseDaemonLock as ab, isValidSessionId as ac, listVhTerminals as ad, isValidTerminalId as ae, readVhTerminal as af, sendToVhTerminal as ag, TITLE_PROMPT_PREFIX as ah, BOARD_ANALYZER_PROMPT_PREFIX as ai, startOfflineReconnection as aj, clearCredentials as ak, clearMachineId as al, SandboxConfigSchema as am, CodexAppServerClient as an, getLatestDaemonLog as ao, persistence as ap, api as aq, createEnvelope as b, configuration as c, contentLogMetadata as d, errorLogMetadata as e, packageJson as f, delay as g, connectionState as h, readSettings as i, encodeBase64 as j, ensurePrivateDirectorySync as k, logger as l, hardenPrivateFileSync as m, readDaemonState as n, clearDaemonState as o, projectPath as p, getProjectPath as q, readPersistedSessions as r, initializeSandbox as s, wrapCommand as t, AsyncLock as u, ensurePrivateDirectory as v, writePrivateFileSync as w, hardenPrivateFile as x, readCredentials as y, credentialRelayProblem as z };