cc-hindsight 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,7 +39,9 @@ them from the first message.
39
39
 
40
40
  All the evidence of what you *should* have said is already on disk. Claude Code
41
41
  saves every session as JSONL under `~/.claude/projects/`; kiro-cli keeps its
42
- own store under `~/.kiro/sessions/cli`. Plenty of tools read that data for
42
+ own store under `~/.kiro/sessions` (both the flat `cli/<uuid>.jsonl` layout and
43
+ the newer per-session `<hash>/sess_<uuid>/messages.jsonl` layout). Plenty of
44
+ tools read that data for
43
45
  dashboards and transcripts. **Nobody closes the loop from history back to
44
46
  better prompting.**
45
47
 
@@ -101,7 +103,9 @@ history the same way. Every command takes `--source claude|kiro|auto` (default
101
103
  `auto`: read whichever stores exist) and `--kiro-dir` / `KIRO_CONFIG_DIR`
102
104
  (default `~/.kiro`, parallel to `--claude-dir`). A machine with both stores
103
105
  merges them into one library; the manifest tags each session's `origin` and the
104
- export summary breaks the count down (`9 claude + 3 kiro`).
106
+ export summary breaks the count down (`9 claude + 3 kiro`). The kiro backend
107
+ reads both on-disk store layouts (the flat v2 store and the newer v3 per-session
108
+ store), preferring the v3 copy when a session was migrated into both.
105
109
 
106
110
  `distill --runner claude|kiro|auto` chooses which CLI does the distilling —
107
111
  orthogonal to `--source`, so you can mine kiro history and distill with claude
package/dist/cli.js CHANGED
@@ -10,7 +10,7 @@ import { stripVTControlCharacters, styleText } from "node:util";
10
10
  import readline from "node:readline";
11
11
  import { spinner } from "@clack/prompts";
12
12
  //#region package.json
13
- var version = "1.3.1";
13
+ var version = "1.4.0";
14
14
  var description = "Mine your coding-agent session history (Claude Code, kiro-cli) into a oneshot prompt library and CLAUDE.md/AGENTS.md preferences. The prompt you'd write if you knew then what you know now.";
15
15
  //#endregion
16
16
  //#region src/commands/_shared.ts
@@ -1294,7 +1294,7 @@ const defaultIo = {
1294
1294
  spawn: defaultSpawn
1295
1295
  };
1296
1296
  /** Whitespace-trim and cap a string for an error/report snippet. */
1297
- function snippet$2(s, max = 500) {
1297
+ function snippet$3(s, max = 500) {
1298
1298
  const t = s.trim();
1299
1299
  return t.length > max ? `${t.slice(0, max)}…` : t;
1300
1300
  }
@@ -1471,7 +1471,7 @@ function extractResult(result) {
1471
1471
  try {
1472
1472
  parsed = JSON.parse(result.stdout);
1473
1473
  } catch {
1474
- const detail = snippet$2(result.stdout || result.stderr) || "no output";
1474
+ const detail = snippet$3(result.stdout || result.stderr) || "no output";
1475
1475
  if (result.code !== 0) throw new AgentRunnerError("cli-error", `claude exited ${result.code}: ${detail}`, {
1476
1476
  stderr: result.stderr,
1477
1477
  output: result.stdout
@@ -1479,20 +1479,20 @@ function extractResult(result) {
1479
1479
  throw new RetryableError(`could not parse claude JSON envelope: ${detail}`);
1480
1480
  }
1481
1481
  const envelope = selectEnvelope(parsed);
1482
- if (!envelope) throw new RetryableError(`claude verbose stream carried no 'result' event: ${snippet$2(result.stdout) || "empty array"}`);
1482
+ if (!envelope) throw new RetryableError(`claude verbose stream carried no 'result' event: ${snippet$3(result.stdout) || "empty array"}`);
1483
1483
  if (envelope.is_error) throw new AgentRunnerError("cli-error", `claude reported an error: ${typeof envelope.result === "string" ? envelope.result : "unknown error"}`, {
1484
1484
  stderr: result.stderr,
1485
1485
  output: result.stdout
1486
1486
  });
1487
1487
  const r = envelope.result;
1488
- if (r === null || r === void 0) throw new RetryableError(`claude envelope missing a 'result' field: ${snippet$2(result.stdout, 200) || "no output"}`);
1488
+ if (r === null || r === void 0) throw new RetryableError(`claude envelope missing a 'result' field: ${snippet$3(result.stdout, 200) || "no output"}`);
1489
1489
  if (typeof r === "object") return r;
1490
1490
  if (typeof r === "string") {
1491
1491
  const jsonText = stripFence(r);
1492
1492
  try {
1493
1493
  return JSON.parse(jsonText);
1494
1494
  } catch {
1495
- throw new RetryableError(`claude result was not valid JSON: ${snippet$2(r)}`);
1495
+ throw new RetryableError(`claude result was not valid JSON: ${snippet$3(r)}`);
1496
1496
  }
1497
1497
  }
1498
1498
  throw new RetryableError(`unexpected claude result type: ${typeof r}`);
@@ -2461,11 +2461,11 @@ function recoverSteeringText(text) {
2461
2461
  * SessionSource law holds.
2462
2462
  */
2463
2463
  function steeringFromToolResults(data) {
2464
- const content = isRecord$1(data) ? data.content : void 0;
2464
+ const content = isRecord$2(data) ? data.content : void 0;
2465
2465
  if (!Array.isArray(content)) return [];
2466
2466
  const out = [];
2467
2467
  for (const block of content) {
2468
- if (!isRecord$1(block) || block.kind !== "text" || typeof block.data !== "string") continue;
2468
+ if (!isRecord$2(block) || block.kind !== "text" || typeof block.data !== "string") continue;
2469
2469
  const recovered = recoverSteeringText(block.data.trim());
2470
2470
  if (recovered !== null) out.push(recovered);
2471
2471
  }
@@ -2492,17 +2492,17 @@ const KIRO_AUTOMATION_FIRST_LINES = [
2492
2492
  "You are a memory consolidation agent",
2493
2493
  "You are generating contextual prompt suggestions"
2494
2494
  ];
2495
- function isRecord$1(value) {
2495
+ function isRecord$2(value) {
2496
2496
  return typeof value === "object" && value !== null && !Array.isArray(value);
2497
2497
  }
2498
2498
  /** Collapse whitespace and cap at 120 chars for a Drop snippet. */
2499
- function snippet$1(text) {
2499
+ function snippet$2(text) {
2500
2500
  const oneLine = text.replace(/\s+/g, " ").trim();
2501
2501
  return oneLine.length > 120 ? `${oneLine.slice(0, 117)}...` : oneLine;
2502
2502
  }
2503
2503
  /** Normalize kiro's unix-seconds timestamp into an ISO-8601 UTC string. */
2504
2504
  function normalizeTimestamp(meta) {
2505
- if (!isRecord$1(meta)) return "";
2505
+ if (!isRecord$2(meta)) return "";
2506
2506
  const ts = meta.timestamp;
2507
2507
  if (typeof ts !== "number" || !Number.isFinite(ts)) return "";
2508
2508
  return (/* @__PURE__ */ new Date(ts * 1e3)).toISOString();
@@ -2521,19 +2521,19 @@ function normalizeTimestamp(meta) {
2521
2521
  * paths produce byte-identical human text (the SessionSource law).
2522
2522
  */
2523
2523
  function promptText(data, drops, ts) {
2524
- if (!isRecord$1(data)) return null;
2524
+ if (!isRecord$2(data)) return null;
2525
2525
  const content = data.content;
2526
2526
  if (!Array.isArray(content)) return null;
2527
2527
  const pieces = [];
2528
2528
  for (const block of content) {
2529
- if (!isRecord$1(block)) continue;
2529
+ if (!isRecord$2(block)) continue;
2530
2530
  if (block.kind !== "text") {
2531
2531
  if (block.kind === "image") pieces.push("[image pasted]");
2532
2532
  else {
2533
2533
  const raw = typeof block.data === "string" ? block.data : JSON.stringify(block.data ?? "");
2534
2534
  drops.push({
2535
2535
  reason: `K11: unknown block kind (${String(block.kind)})`,
2536
- snippet: snippet$1(raw ?? ""),
2536
+ snippet: snippet$2(raw ?? ""),
2537
2537
  timestamp: ts || void 0
2538
2538
  });
2539
2539
  }
@@ -2544,7 +2544,7 @@ function promptText(data, drops, ts) {
2544
2544
  if (text === "") {
2545
2545
  drops.push({
2546
2546
  reason: "K6: empty piece",
2547
- snippet: snippet$1(raw),
2547
+ snippet: snippet$2(raw),
2548
2548
  timestamp: ts || void 0
2549
2549
  });
2550
2550
  continue;
@@ -2557,7 +2557,7 @@ function promptText(data, drops, ts) {
2557
2557
  if (text.startsWith("<")) {
2558
2558
  drops.push({
2559
2559
  reason: "K6: machine block (leading <)",
2560
- snippet: snippet$1(text),
2560
+ snippet: snippet$2(text),
2561
2561
  timestamp: ts || void 0
2562
2562
  });
2563
2563
  continue;
@@ -2565,7 +2565,7 @@ function promptText(data, drops, ts) {
2565
2565
  if (BRACKET_MARKERS.some((m) => text.startsWith(m))) {
2566
2566
  drops.push({
2567
2567
  reason: "K6: bracket marker",
2568
- snippet: snippet$1(text),
2568
+ snippet: snippet$2(text),
2569
2569
  timestamp: ts || void 0
2570
2570
  });
2571
2571
  continue;
@@ -2573,7 +2573,7 @@ function promptText(data, drops, ts) {
2573
2573
  if (KIRO_HARNESS_NUDGES.some((m) => text.startsWith(m))) {
2574
2574
  drops.push({
2575
2575
  reason: "K6: harness nudge",
2576
- snippet: snippet$1(text),
2576
+ snippet: snippet$2(text),
2577
2577
  timestamp: ts || void 0
2578
2578
  });
2579
2579
  continue;
@@ -2584,12 +2584,12 @@ function promptText(data, drops, ts) {
2584
2584
  }
2585
2585
  /** Buffer an `AssistantMessage`'s text blocks into one assistant timeline event. */
2586
2586
  function assistantText(data) {
2587
- if (!isRecord$1(data)) return "";
2587
+ if (!isRecord$2(data)) return "";
2588
2588
  const content = data.content;
2589
2589
  if (!Array.isArray(content)) return "";
2590
2590
  const parts = [];
2591
2591
  for (const block of content) {
2592
- if (!isRecord$1(block)) continue;
2592
+ if (!isRecord$2(block)) continue;
2593
2593
  if (block.kind === "text" && typeof block.data === "string") parts.push(block.data);
2594
2594
  }
2595
2595
  return parts.join("\n").trim();
@@ -2619,15 +2619,15 @@ function extractKiroMessages(lines) {
2619
2619
  badLines++;
2620
2620
  continue;
2621
2621
  }
2622
- if (!isRecord$1(parsed)) {
2622
+ if (!isRecord$2(parsed)) {
2623
2623
  badLines++;
2624
2624
  continue;
2625
2625
  }
2626
2626
  const data = parsed.data;
2627
2627
  if (parsed.kind === "Compaction") {
2628
- const snapshot = isRecord$1(data) ? data.messages_snapshot : void 0;
2628
+ const snapshot = isRecord$2(data) ? data.messages_snapshot : void 0;
2629
2629
  if (Array.isArray(snapshot)) for (const item of snapshot) {
2630
- if (!isRecord$1(item) || item.role !== "user") continue;
2630
+ if (!isRecord$2(item) || item.role !== "user") continue;
2631
2631
  const ts = normalizeTimestamp(item.meta);
2632
2632
  const text = promptText(item, scratchDrops, ts);
2633
2633
  if (text !== null) snapshotPrompts.push({
@@ -2638,7 +2638,7 @@ function extractKiroMessages(lines) {
2638
2638
  continue;
2639
2639
  }
2640
2640
  if (parsed.kind === "ToolResults") {
2641
- const ts = normalizeTimestamp(isRecord$1(data) ? data.meta : void 0);
2641
+ const ts = normalizeTimestamp(isRecord$2(data) ? data.meta : void 0);
2642
2642
  for (const steered of steeringFromToolResults(data)) {
2643
2643
  messages.push({
2644
2644
  timestamp: ts,
@@ -2649,7 +2649,7 @@ function extractKiroMessages(lines) {
2649
2649
  continue;
2650
2650
  }
2651
2651
  if (parsed.kind !== "Prompt") continue;
2652
- const ts = normalizeTimestamp(isRecord$1(data) ? data.meta : void 0);
2652
+ const ts = normalizeTimestamp(isRecord$2(data) ? data.meta : void 0);
2653
2653
  const text = promptText(data, drops, ts);
2654
2654
  if (text !== null) {
2655
2655
  messages.push({
@@ -2661,7 +2661,7 @@ function extractKiroMessages(lines) {
2661
2661
  }
2662
2662
  for (const snap of snapshotPrompts) if (!liveKeys.has(`${snap.ts}\u0000${snap.text}`)) drops.push({
2663
2663
  reason: "K12: snapshot-only prompt",
2664
- snippet: snippet$1(snap.text),
2664
+ snippet: snippet$2(snap.text),
2665
2665
  timestamp: snap.ts || void 0
2666
2666
  });
2667
2667
  return {
@@ -2689,11 +2689,11 @@ function kiroTimeline(lines) {
2689
2689
  } catch {
2690
2690
  continue;
2691
2691
  }
2692
- if (!isRecord$1(parsed)) continue;
2692
+ if (!isRecord$2(parsed)) continue;
2693
2693
  const kind = parsed.kind;
2694
2694
  const data = parsed.data;
2695
2695
  if (kind === "Prompt") {
2696
- const ts = normalizeTimestamp(isRecord$1(data) ? data.meta : void 0);
2696
+ const ts = normalizeTimestamp(isRecord$2(data) ? data.meta : void 0);
2697
2697
  const text = promptText(data, scratchDrops, ts);
2698
2698
  if (text !== null) events.push({
2699
2699
  kind: "human",
@@ -2708,7 +2708,7 @@ function kiroTimeline(lines) {
2708
2708
  text
2709
2709
  });
2710
2710
  } else if (kind === "ToolResults") {
2711
- const ts = normalizeTimestamp(isRecord$1(data) ? data.meta : void 0);
2711
+ const ts = normalizeTimestamp(isRecord$2(data) ? data.meta : void 0);
2712
2712
  for (const steered of steeringFromToolResults(data)) events.push({
2713
2713
  kind: "human",
2714
2714
  timestamp: ts,
@@ -2732,10 +2732,10 @@ function firstPromptText(lines) {
2732
2732
  } catch {
2733
2733
  continue;
2734
2734
  }
2735
- if (!isRecord$1(parsed) || parsed.kind !== "Prompt") continue;
2735
+ if (!isRecord$2(parsed) || parsed.kind !== "Prompt") continue;
2736
2736
  const data = parsed.data;
2737
- if (!isRecord$1(data) || !Array.isArray(data.content)) continue;
2738
- for (const block of data.content) if (isRecord$1(block) && block.kind === "text" && typeof block.data === "string") {
2737
+ if (!isRecord$2(data) || !Array.isArray(data.content)) continue;
2738
+ for (const block of data.content) if (isRecord$2(block) && block.kind === "text" && typeof block.data === "string") {
2739
2739
  const t = block.data.trim();
2740
2740
  if (t !== "") return t;
2741
2741
  }
@@ -2865,7 +2865,7 @@ async function spawnAndParse(bin, args, input, timeoutMs, cwd, env, cost) {
2865
2865
  });
2866
2866
  const text = cleanKiroStdout(result.stdout);
2867
2867
  if (text === "") {
2868
- if (result.code !== 0) throw new AgentRunnerError("cli-error", `kiro-cli exited ${result.code}: ${snippet$2(result.stderr) || "no output"}`, {
2868
+ if (result.code !== 0) throw new AgentRunnerError("cli-error", `kiro-cli exited ${result.code}: ${snippet$3(result.stderr) || "no output"}`, {
2869
2869
  stderr: result.stderr,
2870
2870
  output: result.stdout
2871
2871
  });
@@ -2878,14 +2878,14 @@ async function spawnAndParse(bin, args, input, timeoutMs, cwd, env, cost) {
2878
2878
  output: result.stdout
2879
2879
  });
2880
2880
  }
2881
- if (result.code !== 0) throw new AgentRunnerError("cli-error", `kiro-cli exited ${result.code}: ${snippet$2(text)}`, {
2881
+ if (result.code !== 0) throw new AgentRunnerError("cli-error", `kiro-cli exited ${result.code}: ${snippet$3(text)}`, {
2882
2882
  stderr: result.stderr,
2883
2883
  output: result.stdout
2884
2884
  });
2885
2885
  try {
2886
2886
  return JSON.parse(stripFence(text));
2887
2887
  } catch {
2888
- throw new RetryableError(`kiro-cli output was not valid JSON: ${snippet$2(text)}`);
2888
+ throw new RetryableError(`kiro-cli output was not valid JSON: ${snippet$3(text)}`);
2889
2889
  }
2890
2890
  }
2891
2891
  throw new AgentRunnerError("cli-error", "kiro-cli produced no usable output", {
@@ -3241,11 +3241,11 @@ function disambiguateShortNames(projects) {
3241
3241
  const INTERRUPTION_MARKERS = /* @__PURE__ */ new Set(["[Request interrupted by user]", "[Request interrupted by user for tool use]"]);
3242
3242
  /** R5: tool-rejection boilerplate marker; the human's follow-up is AFTER it. */
3243
3243
  const TOOL_REJECTION_MARKER = "the user said:";
3244
- function isRecord(value) {
3244
+ function isRecord$1(value) {
3245
3245
  return typeof value === "object" && value !== null && !Array.isArray(value);
3246
3246
  }
3247
3247
  /** Collapse whitespace and cap at 120 chars for a Drop snippet. */
3248
- function snippet(text) {
3248
+ function snippet$1(text) {
3249
3249
  const oneLine = text.replace(/\s+/g, " ").trim();
3250
3250
  return oneLine.length > 120 ? `${oneLine.slice(0, 117)}...` : oneLine;
3251
3251
  }
@@ -3286,7 +3286,7 @@ function cleanPiece(raw, pieces, drops, ts) {
3286
3286
  if (text === "") {
3287
3287
  drops.push({
3288
3288
  reason: "R6: empty piece",
3289
- snippet: snippet(raw),
3289
+ snippet: snippet$1(raw),
3290
3290
  timestamp: ts
3291
3291
  });
3292
3292
  return;
@@ -3294,7 +3294,7 @@ function cleanPiece(raw, pieces, drops, ts) {
3294
3294
  if (text.startsWith("<")) {
3295
3295
  drops.push({
3296
3296
  reason: "R6: machine block (leading <)",
3297
- snippet: snippet(text),
3297
+ snippet: snippet$1(text),
3298
3298
  timestamp: ts
3299
3299
  });
3300
3300
  return;
@@ -3302,7 +3302,7 @@ function cleanPiece(raw, pieces, drops, ts) {
3302
3302
  if (INTERRUPTION_MARKERS.has(text)) {
3303
3303
  drops.push({
3304
3304
  reason: "R6: interruption marker",
3305
- snippet: snippet(text),
3305
+ snippet: snippet$1(text),
3306
3306
  timestamp: ts
3307
3307
  });
3308
3308
  return;
@@ -3313,7 +3313,7 @@ function cleanPiece(raw, pieces, drops, ts) {
3313
3313
  function toolResultText(block) {
3314
3314
  const content = block.content;
3315
3315
  if (typeof content === "string") return content;
3316
- if (Array.isArray(content)) return content.filter((b) => isRecord(b) && b.type === "text").map((b) => typeof b.text === "string" ? b.text : "").join("\n");
3316
+ if (Array.isArray(content)) return content.filter((b) => isRecord$1(b) && b.type === "text").map((b) => typeof b.text === "string" ? b.text : "").join("\n");
3317
3317
  return "";
3318
3318
  }
3319
3319
  /**
@@ -3328,12 +3328,12 @@ function toolResultText(block) {
3328
3328
  */
3329
3329
  function extractDecisions(entry) {
3330
3330
  const result = entry.toolUseResult;
3331
- if (!isRecord(result)) return [];
3331
+ if (!isRecord$1(result)) return [];
3332
3332
  const questions = result.questions;
3333
3333
  if (!Array.isArray(questions)) return [];
3334
3334
  const lines = [];
3335
3335
  for (const q of questions) {
3336
- if (!isRecord(q)) continue;
3336
+ if (!isRecord$1(q)) continue;
3337
3337
  const question = typeof q.question === "string" ? q.question.trim() : "";
3338
3338
  let answer = "";
3339
3339
  if (typeof q.answer === "string") answer = q.answer.trim();
@@ -3384,7 +3384,7 @@ function rejectReason(entry) {
3384
3384
  */
3385
3385
  function collectAttachment(entry, pieces, drops, ts) {
3386
3386
  const att = entry.attachment;
3387
- if (isRecord(att) && att.type === "queued_command" && isRecord(att.origin) && att.origin.kind === "human" && att.commandMode === "prompt") {
3387
+ if (isRecord$1(att) && att.type === "queued_command" && isRecord$1(att.origin) && att.origin.kind === "human" && att.commandMode === "prompt") {
3388
3388
  cleanPiece(typeof att.prompt === "string" ? att.prompt : typeof att.text === "string" ? att.text : "", pieces, drops, ts);
3389
3389
  return;
3390
3390
  }
@@ -3406,7 +3406,7 @@ function collectAttachment(entry, pieces, drops, ts) {
3406
3406
  */
3407
3407
  function collectUserContent(entry, pieces, drops, ts) {
3408
3408
  const message = entry.message;
3409
- if (!isRecord(message)) return;
3409
+ if (!isRecord$1(message)) return;
3410
3410
  const content = message.content;
3411
3411
  if (typeof content === "string") {
3412
3412
  cleanPiece(content, pieces, drops, ts);
@@ -3414,7 +3414,7 @@ function collectUserContent(entry, pieces, drops, ts) {
3414
3414
  }
3415
3415
  if (!Array.isArray(content)) return;
3416
3416
  for (const block of content) {
3417
- if (!isRecord(block)) continue;
3417
+ if (!isRecord$1(block)) continue;
3418
3418
  if (block.type === "text") cleanPiece(typeof block.text === "string" ? block.text : "", pieces, drops, ts);
3419
3419
  else if (block.type === "image" || block.type === "document") pieces.push("[image pasted]");
3420
3420
  else if (block.type === "tool_result") {
@@ -3427,21 +3427,21 @@ function collectUserContent(entry, pieces, drops, ts) {
3427
3427
  /** Best-effort content excerpt of a rejected entry for its Drop snippet. */
3428
3428
  function entrySnippet(entry) {
3429
3429
  const message = entry.message;
3430
- if (isRecord(message)) {
3430
+ if (isRecord$1(message)) {
3431
3431
  const content = message.content;
3432
- if (typeof content === "string") return snippet(content);
3432
+ if (typeof content === "string") return snippet$1(content);
3433
3433
  if (Array.isArray(content)) {
3434
- const joined = content.filter((b) => isRecord(b) && b.type === "text").map((b) => typeof b.text === "string" ? b.text : "").join(" ");
3435
- if (joined.trim() !== "") return snippet(joined);
3434
+ const joined = content.filter((b) => isRecord$1(b) && b.type === "text").map((b) => typeof b.text === "string" ? b.text : "").join(" ");
3435
+ if (joined.trim() !== "") return snippet$1(joined);
3436
3436
  }
3437
3437
  }
3438
3438
  const att = entry.attachment;
3439
- if (isRecord(att)) {
3440
- if (typeof att.prompt === "string") return snippet(att.prompt);
3441
- if (typeof att.text === "string") return snippet(att.text);
3442
- if (typeof att.type === "string") return snippet(`<attachment ${att.type}>`);
3439
+ if (isRecord$1(att)) {
3440
+ if (typeof att.prompt === "string") return snippet$1(att.prompt);
3441
+ if (typeof att.text === "string") return snippet$1(att.text);
3442
+ if (typeof att.type === "string") return snippet$1(`<attachment ${att.type}>`);
3443
3443
  }
3444
- return snippet(JSON.stringify(entry));
3444
+ return snippet$1(JSON.stringify(entry));
3445
3445
  }
3446
3446
  /**
3447
3447
  * Extract human-authored messages from one session's raw JSONL lines.
@@ -3466,7 +3466,7 @@ function extractMessages(lines) {
3466
3466
  badLines++;
3467
3467
  continue;
3468
3468
  }
3469
- if (!isRecord(parsed)) {
3469
+ if (!isRecord$1(parsed)) {
3470
3470
  badLines++;
3471
3471
  continue;
3472
3472
  }
@@ -3524,12 +3524,12 @@ function humanEntryText(entry, drops, ts) {
3524
3524
  * multiple questions are newline-joined.
3525
3525
  */
3526
3526
  function renderQuestion(input) {
3527
- if (!isRecord(input)) return "";
3527
+ if (!isRecord$1(input)) return "";
3528
3528
  const questions = input.questions;
3529
3529
  if (!Array.isArray(questions)) return "";
3530
3530
  const lines = [];
3531
3531
  for (const q of questions) {
3532
- if (!isRecord(q)) continue;
3532
+ if (!isRecord$1(q)) continue;
3533
3533
  const question = typeof q.question === "string" ? q.question.trim() : "";
3534
3534
  if (question === "") continue;
3535
3535
  const labels = [];
@@ -3537,7 +3537,7 @@ function renderQuestion(input) {
3537
3537
  for (const opt of q.options) if (typeof opt === "string") {
3538
3538
  const label = opt.trim();
3539
3539
  if (label !== "") labels.push(label);
3540
- } else if (isRecord(opt) && typeof opt.label === "string") {
3540
+ } else if (isRecord$1(opt) && typeof opt.label === "string") {
3541
3541
  const label = opt.label.trim();
3542
3542
  if (label !== "") labels.push(label);
3543
3543
  }
@@ -3561,7 +3561,7 @@ function renderQuestion(input) {
3561
3561
  */
3562
3562
  function assistantEvents(entry, ts) {
3563
3563
  const message = entry.message;
3564
- if (!isRecord(message)) return [];
3564
+ if (!isRecord$1(message)) return [];
3565
3565
  const content = message.content;
3566
3566
  const events = [];
3567
3567
  if (typeof content === "string") {
@@ -3585,13 +3585,13 @@ function assistantEvents(entry, ts) {
3585
3585
  buffer = [];
3586
3586
  };
3587
3587
  for (const block of content) {
3588
- if (!isRecord(block)) continue;
3588
+ if (!isRecord$1(block)) continue;
3589
3589
  if (block.type === "text") {
3590
3590
  if (typeof block.text === "string") buffer.push(block.text);
3591
3591
  } else if (block.type === "tool_use") {
3592
3592
  if (block.name === "ExitPlanMode") {
3593
3593
  flush();
3594
- const plan = isRecord(block.input) && typeof block.input.plan === "string" ? block.input.plan : "";
3594
+ const plan = isRecord$1(block.input) && typeof block.input.plan === "string" ? block.input.plan : "";
3595
3595
  events.push({
3596
3596
  kind: "plan",
3597
3597
  timestamp: ts,
@@ -3633,7 +3633,7 @@ function extractTimeline(lines) {
3633
3633
  } catch {
3634
3634
  continue;
3635
3635
  }
3636
- if (!isRecord(parsed)) continue;
3636
+ if (!isRecord$1(parsed)) continue;
3637
3637
  const entry = parsed;
3638
3638
  const ts = typeof entry.timestamp === "string" ? entry.timestamp : "";
3639
3639
  if (rejectReason(entry) !== null) continue;
@@ -3662,6 +3662,131 @@ function claudeSource(claudeDir) {
3662
3662
  };
3663
3663
  }
3664
3664
  //#endregion
3665
+ //#region src/sources/kiro/discover-v3.ts
3666
+ /**
3667
+ * sources/kiro/discover-v3.ts: enumerate kiro-cli v3 ("Sol" harness) sessions.
3668
+ *
3669
+ * The v3 store is a per-session tree (contrast the flat v2 store in discover.ts):
3670
+ *
3671
+ * <kiroDir>/sessions/<workspaceHash>/<sessionDir>/
3672
+ * messages.jsonl the {id, timestamp, payload} event log (parsed by extract-v3)
3673
+ * session.json metadata: id, title, agentMode, workspacePaths, status, parentSessionId
3674
+ * snapshots/ filesystem checkpoints (ignored)
3675
+ * sub-executions/ subagent transcripts (same line format; never surfaced as sessions)
3676
+ *
3677
+ * <sessionDir> is `sess_<uuid>` (v3-native) or `cli_<uuid>_<suffix>` (a session that
3678
+ * also has a flat v2 `cli/<uuid>.jsonl`; the source dedupes those, preferring v3).
3679
+ * Project identity is `session.json.workspacePaths[0]` (fallback `rootPaths[0]`),
3680
+ * exact like the v2 cwd. Only `messages.jsonl` at a session-dir root marks a session,
3681
+ * so snapshots and sub-executions are skipped without a deep walk.
3682
+ *
3683
+ * A session's human `.history` companion is written under the flat store, as
3684
+ * `cli/sess_<uuid>.history` (sess dirs) or `cli/<uuid>.history` (cli dirs). This
3685
+ * module surfaces both the presence signal (per session) and the key set
3686
+ * ({@link kiroV3SessionKeys}) so countOrphanHistories does not mis-flag those as orphans.
3687
+ */
3688
+ const SESSIONS_DIR = "sessions";
3689
+ /** The flat v2 store lives at sessions/cli; it is not a v3 workspace-hash dir. */
3690
+ const V2_FLAT_SUBDIR = "cli";
3691
+ const MESSAGES_FILE = "messages.jsonl";
3692
+ const SESSION_META_FILE = "session.json";
3693
+ /** Extract the bare session uuid from a v3 dir basename (`sess_<uuid>` / `cli_<uuid>_<suffix>`). */
3694
+ function coreUuid(stem) {
3695
+ return /(?:sess|cli)_([0-9a-fA-F-]{36})/.exec(stem)?.[1] ?? stem;
3696
+ }
3697
+ /** Stems of `.history` files under the flat store, used to detect a v3 session's human signal. */
3698
+ function historyStems(kiroDir) {
3699
+ const dir = path.join(kiroDir, SESSIONS_DIR, V2_FLAT_SUBDIR);
3700
+ try {
3701
+ const stems = fs.readdirSync(dir).filter((f) => f.endsWith(".history")).map((f) => f.slice(0, -8));
3702
+ return new Set(stems);
3703
+ } catch {
3704
+ return /* @__PURE__ */ new Set();
3705
+ }
3706
+ }
3707
+ /** Read + parse a v3 `session.json`; tolerant, missing/corrupt yields an empty meta. */
3708
+ function readV3Meta(sessionDir, hasHistory) {
3709
+ try {
3710
+ const parsed = JSON.parse(fs.readFileSync(path.join(sessionDir, SESSION_META_FILE), "utf8"));
3711
+ const paths = [parsed.workspacePaths, parsed.rootPaths].find(Array.isArray);
3712
+ return {
3713
+ cwd: typeof paths?.[0] === "string" ? paths[0] : void 0,
3714
+ title: typeof parsed.title === "string" ? parsed.title : void 0,
3715
+ parentSessionId: typeof parsed.parentSessionId === "string" ? parsed.parentSessionId : void 0,
3716
+ sessionCreatedReason: typeof parsed.createdReason === "string" ? parsed.createdReason : void 0,
3717
+ hasHistory
3718
+ };
3719
+ } catch {
3720
+ return { hasHistory };
3721
+ }
3722
+ }
3723
+ /**
3724
+ * Collect every v3 session as a flat {@link KiroSessionInfo} list (ungrouped; the
3725
+ * source groups v2+v3 together by cwd). `file` is `<sessionDir>.jsonl` so the
3726
+ * exporter's `file.replace(/\.jsonl$/, "")` yields a unique, meaningful session id.
3727
+ * A missing store yields []; unreadable session dirs are skipped, never fatal.
3728
+ */
3729
+ function collectKiroV3Sessions(kiroDir, opts = {}) {
3730
+ const root = path.join(kiroDir, SESSIONS_DIR);
3731
+ let hashDirs;
3732
+ try {
3733
+ hashDirs = fs.readdirSync(root, { withFileTypes: true });
3734
+ } catch {
3735
+ return [];
3736
+ }
3737
+ const countEntries = opts.countEntries ?? true;
3738
+ const stems = historyStems(kiroDir);
3739
+ const sessions = [];
3740
+ for (const hashDir of hashDirs) {
3741
+ if (!hashDir.isDirectory() || hashDir.name === V2_FLAT_SUBDIR) continue;
3742
+ const hashPath = path.join(root, hashDir.name);
3743
+ let subdirs;
3744
+ try {
3745
+ subdirs = fs.readdirSync(hashPath, { withFileTypes: true });
3746
+ } catch {
3747
+ continue;
3748
+ }
3749
+ for (const sd of subdirs) {
3750
+ if (!sd.isDirectory()) continue;
3751
+ const messagesPath = path.join(hashPath, sd.name, MESSAGES_FILE);
3752
+ let stat;
3753
+ try {
3754
+ stat = fs.statSync(messagesPath);
3755
+ } catch {
3756
+ continue;
3757
+ }
3758
+ if (!stat.isFile()) continue;
3759
+ const hasHistory = stems.has(sd.name) || stems.has(coreUuid(sd.name));
3760
+ sessions.push({
3761
+ file: `${sd.name}.jsonl`,
3762
+ path: messagesPath,
3763
+ entryCount: countEntries ? countFileEntries(messagesPath) : 0,
3764
+ mtime: stat.mtime,
3765
+ meta: readV3Meta(path.join(hashPath, sd.name), hasHistory)
3766
+ });
3767
+ }
3768
+ }
3769
+ return sessions;
3770
+ }
3771
+ /**
3772
+ * The identifiers a v3 session is known by: its dir basename AND its bare uuid.
3773
+ * Used to (a) dedupe a v2 flat session whose uuid also has a v3 dir, and (b) keep
3774
+ * countOrphanHistories from mis-flagging `cli/sess_<uuid>.history` as an orphan.
3775
+ */
3776
+ function kiroV3SessionKeys(kiroDir) {
3777
+ const keys = /* @__PURE__ */ new Set();
3778
+ for (const s of collectKiroV3Sessions(kiroDir, { countEntries: false })) {
3779
+ const stem = s.file.replace(/\.jsonl$/, "");
3780
+ keys.add(stem);
3781
+ keys.add(coreUuid(stem));
3782
+ }
3783
+ return keys;
3784
+ }
3785
+ /** True when at least one v3 session exists under `<kiroDir>/sessions`. */
3786
+ function kiroV3StoreExists(kiroDir) {
3787
+ return collectKiroV3Sessions(kiroDir, { countEntries: false }).length > 0;
3788
+ }
3789
+ //#endregion
3665
3790
  //#region src/sources/kiro/discover.ts
3666
3791
  /**
3667
3792
  * sources/kiro/discover.ts — enumerate kiro-cli sessions.
@@ -3746,25 +3871,16 @@ function countOrphanHistories(kiroDir) {
3746
3871
  if (dirent.name.endsWith(".jsonl")) transcripts.add(dirent.name.replace(/\.jsonl$/, ""));
3747
3872
  else if (dirent.name.endsWith(".history")) histories.push(dirent.name.replace(/\.history$/, ""));
3748
3873
  }
3749
- return histories.filter((stem) => !transcripts.has(stem)).length;
3874
+ const v3Keys = kiroV3SessionKeys(kiroDir);
3875
+ return histories.filter((stem) => !transcripts.has(stem) && !v3Keys.has(stem)).length;
3750
3876
  }
3751
3877
  /**
3752
- * Enumerate every kiro session under `<kiroDir>/sessions/cli`, grouped into
3753
- * projects by metadata `cwd`.
3754
- *
3755
- * - Only top-level `<uuid>.jsonl` files are sessions; `.json`/`.history`/`.lock`
3756
- * companions and `<uuid>/` tasks-sidecar subdirs are ignored for discovery.
3757
- * - A missing sessions dir yields an empty array (never throws) — a machine
3758
- * that never ran kiro is not an error.
3759
- * - `.history` presence is recorded per session (a human-typed-here signal the
3760
- * extractor's classify pass uses).
3761
- * - Project short name = `basename(cwd)`, deduplicated deterministically; a
3762
- * session whose metadata lacks a cwd lands in an "unknown" project.
3763
- *
3764
- * Result is sorted by short name for stable ordering; sessions within a project
3765
- * are newest-first (tie-break on file name), mirroring the Claude discoverer.
3878
+ * Collect every flat v2 session under `<kiroDir>/sessions/cli` as an ungrouped
3879
+ * {@link KiroSessionInfo} list. A missing store yields []; unreadable session
3880
+ * files are skipped, never fatal. The kiro source concatenates these with the v3
3881
+ * sessions (discover-v3) and groups the union once via {@link groupKiroSessionsByCwd}.
3766
3882
  */
3767
- function discoverKiroSessions(kiroDir, opts = {}) {
3883
+ function collectKiroV2Sessions(kiroDir, opts = {}) {
3768
3884
  const sessionsRoot = path.join(kiroDir, KIRO_SESSIONS_SUBDIR);
3769
3885
  const countEntriesOpt = opts.countEntries ?? true;
3770
3886
  let dirents;
@@ -3773,7 +3889,7 @@ function discoverKiroSessions(kiroDir, opts = {}) {
3773
3889
  } catch {
3774
3890
  return [];
3775
3891
  }
3776
- const byCwd = /* @__PURE__ */ new Map();
3892
+ const sessions = [];
3777
3893
  for (const dirent of dirents) {
3778
3894
  if (!dirent.isFile()) continue;
3779
3895
  if (!dirent.name.endsWith(".jsonl")) continue;
@@ -3786,33 +3902,47 @@ function discoverKiroSessions(kiroDir, opts = {}) {
3786
3902
  }
3787
3903
  const stem = dirent.name.replace(/\.jsonl$/, "");
3788
3904
  const meta = readMeta(path.join(sessionsRoot, `${stem}.json`), fs.existsSync(path.join(sessionsRoot, `${stem}.history`)));
3789
- const cwd = meta.cwd ?? "";
3790
- const session = {
3905
+ sessions.push({
3791
3906
  file: dirent.name,
3792
3907
  path: filePath,
3793
3908
  entryCount: countEntriesOpt ? countFileEntries(filePath) : 0,
3794
3909
  mtime: stat.mtime,
3795
3910
  meta
3796
- };
3911
+ });
3912
+ }
3913
+ return sessions;
3914
+ }
3915
+ /**
3916
+ * Group a flat list of kiro sessions (v2 and/or v3) into projects by metadata
3917
+ * `cwd`. Sessions within a project are newest-first (tie-break on file name);
3918
+ * projects are sorted by short name, and short-name collisions (two different
3919
+ * cwds whose basename is identical) are deduped deterministically. Shared by the
3920
+ * v2 discoverer and the merged v2+v3 discover in the source, so a cwd that holds
3921
+ * both a v2 and a v3 session becomes ONE project, not two.
3922
+ */
3923
+ function groupKiroSessionsByCwd(sessions) {
3924
+ const byCwd = /* @__PURE__ */ new Map();
3925
+ for (const session of sessions) {
3926
+ const cwd = session.meta.cwd ?? "";
3797
3927
  const list = byCwd.get(cwd);
3798
3928
  if (list) list.push(session);
3799
3929
  else byCwd.set(cwd, [session]);
3800
3930
  }
3801
3931
  const projects = [];
3802
- for (const [cwd, sessions] of byCwd) {
3803
- sessions.sort((a, b) => {
3932
+ for (const [cwd, group] of byCwd) {
3933
+ group.sort((a, b) => {
3804
3934
  const diff = b.mtime.getTime() - a.mtime.getTime();
3805
3935
  return diff !== 0 ? diff : a.file.localeCompare(b.file);
3806
3936
  });
3807
3937
  const decodedPath = cwd || "unknown";
3808
3938
  const shortName = cwd ? path.basename(cwd) || cwd : "unknown";
3809
- const entryTotal = sessions.reduce((sum, s) => sum + s.entryCount, 0);
3810
- const latestMtime = sessions.length > 0 ? sessions[0]?.mtime : void 0;
3939
+ const entryTotal = group.reduce((sum, s) => sum + s.entryCount, 0);
3940
+ const latestMtime = group.length > 0 ? group[0]?.mtime : void 0;
3811
3941
  projects.push({
3812
3942
  dirName: cwd || "unknown",
3813
3943
  decodedPath,
3814
3944
  shortName,
3815
- sessions,
3945
+ sessions: group,
3816
3946
  entryTotal,
3817
3947
  latestMtime
3818
3948
  });
@@ -3828,34 +3958,264 @@ function discoverKiroSessions(kiroDir, opts = {}) {
3828
3958
  return projects;
3829
3959
  }
3830
3960
  //#endregion
3961
+ //#region src/sources/kiro/extract-v3.ts
3962
+ /**
3963
+ * sources/kiro/extract-v3.ts: the kiro-cli v3 ("Sol" harness) extractor.
3964
+ *
3965
+ * v3's `messages.jsonl` is one `{id, timestamp, payload}` JSON object per line;
3966
+ * `payload.type` discriminates. Only `user` entries carry the human's verbatim
3967
+ * text; `assistant` entries are the machine side (`operationType` "Say" is spoken
3968
+ * dialogue, "Reasoning" is internal thinking). Everything else (`tool_call`,
3969
+ * `tool_result`, `turn_start`/`turn_end`, `usage_summary`, `session_metadata`,
3970
+ * `session_event`, `session_start`, `steering_inclusion`, `sub_agent_*`) is
3971
+ * machine bookkeeping.
3972
+ *
3973
+ * Contrast the v2 extractor (extract.ts): v2 lines are `{version, kind, data}`
3974
+ * with `Prompt`/`AssistantMessage`/`ToolResults`, unix-seconds timestamps, and
3975
+ * `Prompt.data.content[]` text blocks that need per-piece machine-marker drops
3976
+ * (K6) and live-steering recovery (K14). v3 is simpler: `user.content` is a
3977
+ * single verbatim string, the timestamp is ISO-8601 in-band, and mid-run
3978
+ * steering arrives as an ordinary `user` entry (no envelope). So the per-piece
3979
+ * K6/K14 machinery does not apply; the only extraction drop is an empty body.
3980
+ *
3981
+ * As everywhere, parsing is tolerant: unknown `payload.type`s and fields are
3982
+ * ignored, and a corrupt line is counted in `badLines` rather than aborting.
3983
+ * The session-level human-vs-automation gate is {@link classifyKiroV3Session}.
3984
+ */
3985
+ function isRecord(value) {
3986
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3987
+ }
3988
+ /** Collapse whitespace and cap at 120 chars for a Drop snippet. */
3989
+ function snippet(text) {
3990
+ const oneLine = text.replace(/\s+/g, " ").trim();
3991
+ return oneLine.length > 120 ? `${oneLine.slice(0, 117)}...` : oneLine;
3992
+ }
3993
+ /** The payload of one v3 line, or undefined when the line is not a v3 record. */
3994
+ function payloadOf(parsed) {
3995
+ if (!isRecord(parsed)) return void 0;
3996
+ const p = parsed.payload;
3997
+ return isRecord(p) ? p : void 0;
3998
+ }
3999
+ /**
4000
+ * Detect whether a session's lines are the v3 store format. A v3 line is a
4001
+ * record with a `payload` object; a v2 line has top-level `kind`/`data` and no
4002
+ * `payload`. Decided on the FIRST parseable line (the stores never interleave),
4003
+ * defaulting to v2 when nothing parses (harmless: the v2 extractor is equally
4004
+ * tolerant of an empty/corrupt file).
4005
+ */
4006
+ function detectKiroFormat(lines) {
4007
+ for (const line of lines) {
4008
+ if (line.trim() === "") continue;
4009
+ let parsed;
4010
+ try {
4011
+ parsed = JSON.parse(line);
4012
+ } catch {
4013
+ continue;
4014
+ }
4015
+ if (!isRecord(parsed)) continue;
4016
+ return isRecord(parsed.payload) ? "v3" : "v2";
4017
+ }
4018
+ return "v2";
4019
+ }
4020
+ /** The verbatim human text of a `user` entry, or null when its body is empty. */
4021
+ function userText(payload) {
4022
+ const content = payload.content;
4023
+ if (typeof content !== "string") return null;
4024
+ const text = content.trim();
4025
+ return text === "" ? null : text;
4026
+ }
4027
+ /** The spoken text of an `assistant` `Say` entry (buffered as one timeline turn). */
4028
+ function assistantSay(payload) {
4029
+ if (payload.operationType !== "Say") return "";
4030
+ return typeof payload.content === "string" ? payload.content.trim() : "";
4031
+ }
4032
+ /**
4033
+ * Extract human-authored messages from one v3 session's raw JSONL lines. Only
4034
+ * `user` entries are candidates; an empty body is recorded as an observable Drop
4035
+ * (fidelity contract) rather than vanishing. Timestamps are the line's in-band
4036
+ * ISO-8601 `timestamp` ("" when absent, tolerated as on the v2 path).
4037
+ */
4038
+ function extractKiroV3Messages(lines) {
4039
+ const messages = [];
4040
+ const drops = [];
4041
+ let badLines = 0;
4042
+ for (const line of lines) {
4043
+ if (line.trim() === "") continue;
4044
+ let parsed;
4045
+ try {
4046
+ parsed = JSON.parse(line);
4047
+ } catch {
4048
+ badLines++;
4049
+ continue;
4050
+ }
4051
+ const payload = payloadOf(parsed);
4052
+ if (payload === void 0 || payload.type !== "user") continue;
4053
+ const ts = isRecord(parsed) && typeof parsed.timestamp === "string" ? parsed.timestamp : "";
4054
+ const text = userText(payload);
4055
+ if (text === null) {
4056
+ const raw = typeof payload.content === "string" ? payload.content : "";
4057
+ drops.push({
4058
+ reason: "V3: empty user content",
4059
+ snippet: snippet(raw),
4060
+ timestamp: ts || void 0
4061
+ });
4062
+ continue;
4063
+ }
4064
+ messages.push({
4065
+ timestamp: ts,
4066
+ text
4067
+ });
4068
+ }
4069
+ return {
4070
+ messages,
4071
+ drops,
4072
+ badLines
4073
+ };
4074
+ }
4075
+ /**
4076
+ * Build a v3 session's linear timeline: `human` turns from `user` entries (via
4077
+ * the SAME {@link userText} the exporter uses, so human turns align 1:1 with the
4078
+ * corpus, the SessionSource law), and `assistant` turns from `Say` entries.
4079
+ * `Reasoning` is omitted (parity with the v2 timeline skipping thinking blocks).
4080
+ *
4081
+ * No `boundary` event is emitted: no compaction/clear entry has been observed in
4082
+ * the v3 store. If kiro adds one, extend this with a fixture first rather than
4083
+ * guessing its shape.
4084
+ */
4085
+ function kiroV3Timeline(lines) {
4086
+ const events = [];
4087
+ for (const line of lines) {
4088
+ if (line.trim() === "") continue;
4089
+ let parsed;
4090
+ try {
4091
+ parsed = JSON.parse(line);
4092
+ } catch {
4093
+ continue;
4094
+ }
4095
+ const payload = payloadOf(parsed);
4096
+ if (!payload) continue;
4097
+ const ts = isRecord(parsed) && typeof parsed.timestamp === "string" ? parsed.timestamp : "";
4098
+ if (payload.type === "user") {
4099
+ const text = userText(payload);
4100
+ if (text !== null) events.push({
4101
+ kind: "human",
4102
+ timestamp: ts,
4103
+ text
4104
+ });
4105
+ } else if (payload.type === "assistant") {
4106
+ const text = assistantSay(payload);
4107
+ if (text !== "") events.push({
4108
+ kind: "assistant",
4109
+ timestamp: ts,
4110
+ text
4111
+ });
4112
+ }
4113
+ }
4114
+ return events;
4115
+ }
4116
+ /** First non-empty `user` text of a v3 session, for the automation-marker checks. */
4117
+ function firstUserPromptV3(lines) {
4118
+ for (const line of lines) {
4119
+ if (line.trim() === "") continue;
4120
+ let parsed;
4121
+ try {
4122
+ parsed = JSON.parse(line);
4123
+ } catch {
4124
+ continue;
4125
+ }
4126
+ const payload = payloadOf(parsed);
4127
+ if (payload === void 0 || payload.type !== "user") continue;
4128
+ const text = userText(payload);
4129
+ if (text !== null) return text;
4130
+ }
4131
+ return null;
4132
+ }
4133
+ /**
4134
+ * V3 session-level human-vs-automation classification, recall-oriented, mirroring
4135
+ * the v2 K2 precedence with v3-appropriate signals:
4136
+ *
4137
+ * 1. first user prompt begins with the cc-hindsight distill sentinel → EXCLUDE
4138
+ * (self-recognition, absolute; see K13);
4139
+ * 2. a `.history` companion exists (a human typed here) → INCLUDE;
4140
+ * 3. first user prompt is an automation marker (`[AGENT SYSTEM PROMPT]`, an
4141
+ * automation-agent boilerplate first line, or a lone harness nudge) → EXCLUDE;
4142
+ * 4. else INCLUDE (recall-oriented default).
4143
+ *
4144
+ * Unlike v2, `parentSessionId` is NOT an exclusion signal: a top-level v3 session
4145
+ * dir with a parent link is a human FORK, and true subagents live under
4146
+ * `sub-executions/` and are never enumerated as sessions.
4147
+ */
4148
+ function classifyKiroV3Session(meta, firstPrompt) {
4149
+ if (firstPrompt?.startsWith("[cc-hindsight distill]")) return {
4150
+ include: false,
4151
+ reason: "K13: cc-hindsight distill session (self-recognition)"
4152
+ };
4153
+ if (meta.hasHistory) return {
4154
+ include: true,
4155
+ reason: "V3: .history present (human typed here)"
4156
+ };
4157
+ if (firstPrompt) {
4158
+ if (firstPrompt.startsWith("[AGENT SYSTEM PROMPT]")) return {
4159
+ include: false,
4160
+ reason: "V3: [AGENT SYSTEM PROMPT] first prompt"
4161
+ };
4162
+ if (KIRO_AUTOMATION_FIRST_LINES.some((m) => firstPrompt.startsWith(m))) return {
4163
+ include: false,
4164
+ reason: "V3: automation-agent boilerplate first prompt"
4165
+ };
4166
+ if (KIRO_HARNESS_NUDGES.some((m) => firstPrompt.startsWith(m))) return {
4167
+ include: false,
4168
+ reason: "V3: harness-nudge-only session"
4169
+ };
4170
+ }
4171
+ return {
4172
+ include: true,
4173
+ reason: "V3: recall-oriented default (no automation markers)"
4174
+ };
4175
+ }
4176
+ /** Classify from raw lines (reads the first user prompt itself). */
4177
+ function classifyKiroV3Lines(meta, lines) {
4178
+ return classifyKiroV3Session(meta, firstUserPromptV3(lines));
4179
+ }
4180
+ //#endregion
3831
4181
  //#region src/sources/kiro/index.ts
3832
4182
  /**
3833
- * sources/kiro/index.ts — the kiro-cli backend as a SessionSource.
4183
+ * sources/kiro/index.ts: the kiro-cli backend as a SessionSource.
3834
4184
  *
3835
4185
  * Binds a kiro config dir (default `~/.kiro`) to the discover/extract/timeline
3836
- * functions. Unlike Claude, kiro classifies human-vs-automation at the SESSION
3837
- * level (K2) — so this source exposes `classify`, wiring the discovery metadata
3838
- * (`.history` presence, parent link) to the extractor's classifier by reading
3839
- * the session's own first prompt.
4186
+ * functions, spanning BOTH on-disk stores: the flat v2 store
4187
+ * (`sessions/cli/<uuid>.jsonl`, `{version,kind,data}`) and the v3 per-session
4188
+ * store (`sessions/<hash>/<sessionDir>/messages.jsonl`, `{id,timestamp,payload}`).
4189
+ * Discovery merges the two and prefers v3 when a session exists in both (the
4190
+ * `cli_<uuid>` migration case); extract/timeline/classify sniff each session's
4191
+ * format from its lines and dispatch. Kiro classifies human-vs-automation at the
4192
+ * SESSION level, so this source exposes `classify`, wiring discovery metadata
4193
+ * (`.history` presence, parent link) to the per-format classifier.
3840
4194
  */
3841
4195
  /** Construct the kiro-cli source bound to a config directory. */
3842
4196
  function kiroSource(kiroDir) {
3843
4197
  const metaByPath = /* @__PURE__ */ new Map();
3844
- let discoverCache = null;
4198
+ let discovered = false;
3845
4199
  const discover = (opts) => {
3846
- const projects = discoverKiroSessions(kiroDir, opts);
4200
+ const v3 = collectKiroV3Sessions(kiroDir, opts);
4201
+ const v3Ids = new Set(v3.map((s) => coreUuid(s.file.replace(/\.jsonl$/, ""))));
4202
+ const projects = groupKiroSessionsByCwd([...collectKiroV2Sessions(kiroDir, opts).filter((s) => !v3Ids.has(s.file.replace(/\.jsonl$/, ""))), ...v3]);
3847
4203
  metaByPath.clear();
3848
4204
  for (const project of projects) for (const session of project.sessions) metaByPath.set(session.path, session.meta);
3849
- discoverCache = projects;
4205
+ discovered = true;
3850
4206
  return projects;
3851
4207
  };
3852
4208
  return {
3853
4209
  name: "kiro",
3854
4210
  discover,
3855
- extract: extractKiroMessages,
3856
- timeline: kiroTimeline,
4211
+ extract(lines) {
4212
+ return detectKiroFormat(lines) === "v3" ? extractKiroV3Messages(lines) : extractKiroMessages(lines);
4213
+ },
4214
+ timeline(lines) {
4215
+ return detectKiroFormat(lines) === "v3" ? kiroV3Timeline(lines) : kiroTimeline(lines);
4216
+ },
3857
4217
  classify(session) {
3858
- if (discoverCache === null) discover({ countEntries: false });
4218
+ if (!discovered) discover({ countEntries: false });
3859
4219
  const meta = metaByPath.get(session.path);
3860
4220
  if (!meta) return void 0;
3861
4221
  let lines;
@@ -3864,7 +4224,7 @@ function kiroSource(kiroDir) {
3864
4224
  } catch {
3865
4225
  return;
3866
4226
  }
3867
- return classifyKiroLines(meta, lines).include ? "interactive" : "automation";
4227
+ return (detectKiroFormat(lines) === "v3" ? classifyKiroV3Lines(meta, lines) : classifyKiroLines(meta, lines)).include ? "interactive" : "automation";
3868
4228
  }
3869
4229
  };
3870
4230
  }
@@ -3878,13 +4238,16 @@ function claudeStoreExists(claudeDir) {
3878
4238
  return false;
3879
4239
  }
3880
4240
  }
3881
- /** True when a kiro store exists (a `sessions/cli` dir under kiroDir). */
4241
+ /**
4242
+ * True when a kiro store exists: the flat v2 `sessions/cli` dir, OR at least one
4243
+ * v3 per-session dir under `sessions/<hash>/`. A machine on the newer kiro-cli
4244
+ * may have only the v3 store, so both are probed.
4245
+ */
3882
4246
  function kiroStoreExists(kiroDir) {
3883
4247
  try {
3884
- return fs.statSync(path.join(kiroDir, KIRO_SESSIONS_SUBDIR)).isDirectory();
3885
- } catch {
3886
- return false;
3887
- }
4248
+ if (fs.statSync(path.join(kiroDir, KIRO_SESSIONS_SUBDIR)).isDirectory()) return true;
4249
+ } catch {}
4250
+ return kiroV3StoreExists(kiroDir);
3888
4251
  }
3889
4252
  /** Parse/validate a raw `--source` flag value; defaults to `auto`. */
3890
4253
  function parseSourceMode(raw) {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "cc-hindsight",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "cc-hindsight",
9
- "version": "1.3.1",
9
+ "version": "1.4.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@clack/prompts": "1.7.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-hindsight",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "Mine your coding-agent session history (Claude Code, kiro-cli) into a oneshot prompt library and CLAUDE.md/AGENTS.md preferences. The prompt you'd write if you knew then what you know now.",
5
5
  "type": "module",
6
6
  "author": "Aditya Singhal (https://adityasinghal.com)",